home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / me_cd25.zip / ME2MUTT.ZIP / PCSHAR.MUT < prev    next >
Lisp/Scheme  |  1992-11-09  |  3KB  |  124 lines

  1.   ;; C Durland    Public Domain
  2.  
  3. (include me2.h)
  4.  
  5. ;; Concat files that have been uuencoded and split.
  6. ;; Formats:
  7. ;;   File names: <base-name><n> where n is in [1,2,3,...]
  8. ;;     For example: foo.1, foo.2, etc.
  9. ;;   Each part:
  10. ;;     junk
  11. ;;     BEGIN--cut here--cut here
  12. ;;     the data
  13. ;;     END--cut here--cut here
  14. ;;     possibly more junk
  15. ;; Concats all the parts and uudecodes it.
  16.  
  17. (defun concat-pc-archive
  18. {
  19.   (int part)
  20.   (string base-name)
  21.  
  22.   (part 1)
  23.   (base-name (complete CC_FNAME 
  24.     "Archive base name (each part is in form <base-name><n>): "))
  25.   (switch-to-buffer base-name)(clear-buffer)
  26.  
  27.     ;; Strip off the headers and trailers and concat all the archive
  28.     ;;   parts.
  29.   (insert-file (concat base-name part))
  30.   (while TRUE
  31.   {
  32.     (search-forward "END--cut here--")(beginning-of-line)
  33.     (+= part 1)
  34.     (if (not (insert-file (concat base-name part))) (break))
  35.     (set-mark)
  36.     (search-forward "BEGIN--cut here--")
  37.     (forward-line 1)(delete-region)
  38.   })
  39.     ;; run the buffer though uudecode
  40.   (msg 'uudecoding "' base-name '"')
  41.   (beginning-of-buffer)(set-mark)(end-of-buffer)
  42.   (clear-bag CUT-BUFFER)(append-to-bag CUT-BUFFER APPEND-REGION)
  43.   (OS-filter "uudecode" CUT-BUFFER)
  44.     ;; remove the uuencoded buffer
  45.   (clear-bag CUT-BUFFER)(free-buffer -1)(update)
  46.   (msg (- part 1) " parts to archive " '"' base-name '"')
  47. })
  48.  
  49.   ;; BEGIN ---------------- foo: Part n of m ---------------
  50.   ;; END ------------------ foo: Part n of m ---------------
  51. (defun add-begin/end-lines-to-files
  52. {
  53.   (int part parts)
  54.   (string base-name)
  55.  
  56.   (base-name (complete CC_FNAME 
  57.     "Archive base name (each part is in form <base-name><n>): "))
  58.  
  59.   (parts (count-parts base-name))
  60.   (switch-to-buffer base-name)(clear-buffer)
  61.  
  62.   (insert-file (concat base-name part))
  63.   (for (part 1) (<= part parts) (+= part 1)
  64.   {
  65.     (read-file (concat base-name part))
  66.     (insert-text
  67.     "BEGIN ---- " base-name part " -- Part " part " of " parts " ----^J")
  68.     (end-of-buffer)
  69.     (insert-text
  70.     "END ---- " base-name part " -- Part " part " of " parts " ----")
  71.     (save-buffer)
  72.   })
  73.   (msg parts " parts of " base-name " munged")
  74. })
  75.  
  76.  
  77. (defun
  78.   count-parts (string base-name) HIDDEN
  79.   {
  80.     (int parts)
  81.  
  82.     (parts 0)
  83.     (while (file-exists (concat base-name (+= parts 1))) ())
  84.     (if (== 1 parts) { (msg "Bad name - no parts: " base-name)(halt) })
  85.     (- parts 1)
  86.   }
  87. )
  88.  
  89. (defun
  90.   convert-splits-to-name
  91.   {
  92.     (int j)
  93.     (string base-name fname newname)
  94.  
  95.     (base-name (complete CC_FNAME
  96.       "Base name (each part is in form <base-name>aa): "))
  97.     (newname (complete CC_FNAME
  98.       "New name (each part is in form <base-name>1): "))
  99.     (for (j 1)
  100.       (file-exists (fname
  101.         (concat base-name "a"        ;; xaa
  102.       (extract-elements "xabcdefghijklmnopqrstuvwxyz" j 1))))
  103.       (+= j 1)
  104.       (shell-command (msg "mv " fname " " newname j)))    ;; z1
  105.     (update)
  106.     (msg (- j 1) " parts renamed.")
  107.   }
  108. )
  109.  
  110. (defun
  111.   chop-chop
  112.   {
  113.     (string name)
  114.     (int split-size)
  115.  
  116.     (split-size (if (arg-flag) (arg-prefix) 820))
  117.     (name (complete CC_FNAME "Name of file to chop up: "))
  118.     (shell-command (msg "uuencode " name " " name " > " name ".uu"))
  119.     (shell-command (msg "split -" split-size " " name ".uu"))
  120.     (convert-splits-to-name "x" (concat name ".uu."))
  121.     (add-begin/end-lines-to-files (concat name ".uu."))
  122.   }
  123. )
  124.