home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / unshar.umc < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  4.7 KB

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