home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / unshar.uemacs < prev    next >
Text File  |  1989-03-04  |  4KB  |  130 lines

  1. Newsgroups: comp.sources.misc
  2. Subject: v06i047: meunshar, a MicroEmacs macro to split shar files
  3. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Reply-To: saj@chinet.chi.il.us.UUCP (Stephen Jacobs)
  5.  
  6. Posting-number: Volume 6, Issue 47
  7. Submitted-by: saj@chinet.chi.il.us.UUCP (Stephen Jacobs)
  8. Archive-name: unshar.uemacs
  9.  
  10. This submission is a macro to split up shell archives (shar files) using
  11. Daniel Lawrence's MicroEMACS.  It will be useful on systems which do not
  12. have UNIX's features of here-documents (ie: take the rest of this file as
  13. stdin until you match the thing after '<<') and flexible file naming.  I
  14. developed it on an Atari ST under the Mark Williams shell 'msh'; it should
  15. also be useful under MS-DOS.  It works on archives which use sed to remove
  16. a pad character at the start of each line; it does not work on archives 
  17. which use cat to split them without such manipulations.  The names of the
  18. files created must be unique in the first 12 characters.
  19.  
  20. To use this macro, enter the shar file into MicroEMACS, then type Meta-X
  21. (this is usually escape key followed by unshifted x): this will give a
  22. command line.  Type 'execute-file' followed by a space: this will cause
  23. the program to prompt for a file to execute.  Type the name the following
  24. macro is stored under, followed by <return>.  If all goes well, this will
  25. split the archive into sections, each in its own buffer named with the 
  26. first 12 characters of its intended filename.  Much of the non-file matter
  27. in the archive will be in a buffer named 'head%mattr' and the lines that 
  28. were used as item separaters will be in a buffer named 'sep%markers'.  The
  29. user must cycle through the buffers, saving to file names or not as (s)he
  30. sees fit.
  31.  
  32. Some old or hand-made archives may not be unpacked properly by this macro.
  33. Versions of MicroEMACS earlier than 3.9 may not handle this macro properly
  34. (I haven't tried).
  35.  
  36. Atari and ST are trademarks of Atari Corp.,  UNIX is a trademark of AT&T
  37. and MS-DOS is a trademark of Microsoft Corp.  The macro begins AFTER 
  38. (not including) the 'cut here' line.  I believe it would be contrary to
  39. the spirit of this posting to package it as a shell archive.
  40.  
  41. [Given the nature of the posting, it makes the most sense to load it directly
  42. into your copy of microEmacs anyway....  ++bsa]
  43.  
  44. x---------------------------------cut here----------------------------------x
  45. beginning-of-file
  46. add-mode "magic"
  47. add-mode "exact"
  48. set %original $cbufname
  49. *sect%loop
  50.     search-forward "^sed"
  51.     search-forward "<<"
  52.     kill-to-end-of-line
  53.     select-buffer "sep%markers"
  54.     yank
  55.     beginning-of-line
  56.     set-mark
  57.     !while &equal &ascii #sep%markers 32    ;Loop strips leading blanks
  58.         previous-line
  59.         delete-next-character
  60.     !endwhile
  61.     exchange-point-and-mark
  62.     !if &equal &ascii #sep%markers 34    ;remove enclosing quotes
  63.         previous-line
  64.         delete-next-character
  65.         end-of-line
  66.         delete-previous-character
  67.     !else
  68.         previous-line
  69.         !if &equal &ascii #sep%markers 39    ;remove enclosing
  70.             previous-line            ;apostrophes
  71.             delete-next-character
  72.             end-of-line
  73.             delete-previous-character
  74.         !endif
  75.     !endif
  76.     beginning-of-line
  77.     set-mark        ; Next 5 lines escape risky MAGIC special chars
  78.     replace-string "\" "\\"
  79.     exchange-point-and-mark
  80.     set-mark
  81.     replace-string "*" "\*"
  82.     exchange-point-and-mark
  83.     select-buffer %original
  84.     delete-previous-character
  85.     delete-previous-character
  86.     backward-character            ;This and following loop 
  87.     !while &equal &ascii #$cbufname 32    ;strip trailing blanks
  88.         backward-character        ;from destination buffer
  89.         delete-previous-character    ;name--they'd be used 
  90.         backward-character        ;otherwise, causing trouble
  91.     !endwhile
  92.     search-reverse ">"
  93.     delete-next-character
  94.     set-mark
  95.     !while &equal &ascii #%original 32    ;Loop strips leading blanks
  96.         exchange-point-and-mark        ;same as trailing blanks
  97.         delete-next-character
  98.         set-mark
  99.     !endwhile
  100.     exchange-point-and-mark
  101.     set %destbuf &left #$cbufname 12    ;Long buffer names troublesome
  102.     previous-line
  103.     set-mark
  104.     beginning-of-file
  105.     kill-region
  106.     select-buffer head%mattr
  107.     yank
  108.     select-buffer %original
  109.     search-forward "s/"
  110.     kill-region
  111.     search-forward "/"
  112.     backward-character
  113.     kill-to-end-of-line
  114.     beginning-of-line
  115.     set-mark
  116.     set $search &cat "^" #sep%markers
  117.     hunt-forward
  118.     beginning-of-line
  119.     kill-region
  120.     select-buffer %destbuf
  121.     add-mode "magic"
  122.     yank
  123.     beginning-of-file
  124.     set-mark
  125.     set $search #$cbufname        ;Note that this advances cursor 1 line
  126.     kill-region
  127.     replace-string $search ""
  128.     select-buffer %original
  129. !goto sect%loop
  130.