home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / comm / Fido / Spot / Rexx / UU-Retriever.spot < prev    next >
Text File  |  1994-04-26  |  6KB  |  198 lines

  1.  
  2. /*
  3. -----------------------------------------------------------------------------
  4. UU-Retriever
  5.  
  6. This script written by Jan Van Overbeke
  7.  
  8. This script needs UUDecode V37.22 (or later if arguments are compatible).
  9.  
  10. Any remarks to Jan Van Overbeke, Fido: 2:292/603.29
  11. Let me know if your script ends faulty, or you have trouble with this script
  12. Giving me a clear description of what you did and what compu you have
  13. -----------------------------------------------------------------------------
  14. */
  15.  
  16. /* ---      This is a file-intensive script.      --- */
  17. /* ---  I learned that open(), close(), writeln() --- */
  18. /* ---          Must be perceded by CALL          --- */
  19. /* ---  Like: call writeln(outputter)             --- */
  20. /* ---  and:  temp=readln(inputter)               --- */
  21. /* -------------------------------------------------- */
  22.  
  23. /* ---               Never use '0a'x               --- */
  24. /* --- That would get your requesters into trouble --- */
  25. /* --------------------------------------------------- */
  26. CR='0d'x
  27. options results
  28. address SPOT
  29. call addlib('rexxsupport.library',0,-30)
  30.  
  31. /* --- Put up a credits-requester --- */
  32. /* ---------------------------------- */
  33. tell='UU-Retriever'CR'Version 1.0'CR||CR
  34. tell=tell'Retrieves a file from UUEncoded messages'CR
  35. tell=tell'Multiple messages when created by UU-Writer'CR
  36. tell=tell'Compatible with every other if 1 message'CR||CR
  37. tell=tell'UU-Retriever & UU-Writer: Written by'CR
  38. tell=tell'Jan Van Overbeke, 2:292/603.29'
  39. 'requestnotify PROMPT "'tell'" CENTER'
  40.  
  41. /* ---     Do some checking first.    --- */
  42. /* ---   checking is very important   --- */
  43. /* --- so everyone can use the script --- */
  44. /* -------------------------------------- */
  45. if ~exists('c:UUDecode') then do
  46.     'requestnotify PROMPT "Could not find c:UUDecode (V37.22)"'
  47.     exit
  48.     end
  49. if ~exists('c:delete') then do
  50.     'requestnotify PROMPT "Could not find c:Delete"'
  51.     exit
  52.     end
  53. if ~exists('c:join') then do
  54.     'requestnotify PROMPT "Could not find c:Join"'
  55.     exit
  56.     end
  57. if ~exists('c:Rename') then do
  58.     'requestnotify PROMPT "Could not find c:Rename"'
  59.     exit
  60.     end
  61.  
  62. /* --- The area list is NOT the right place --- */
  63. /* ---          to use this script          --- */
  64. /* -------------------------------------------- */
  65. 'isarealist'
  66. if RC=0 then do
  67.     'requestnotify PROMPT "Cannot UU-Retrieve in area-list!"'
  68.     exit
  69.     end
  70.  
  71. /* --- Let's see if the message we're in is UU-Written. --- */
  72. /* -------------------------------------------------------- */
  73. saveascii 't:TEMP-ENCODED' overwrite noheader noorigin
  74. call open(inputter,'t:TEMP-ENCODED','R')
  75. goon=1
  76. do while goon
  77.     readed=readln(inputter)
  78.     if eof(inputter) then do
  79.         'requestnotify PROMPT "Seems like this message is not UU-written."'
  80.         call close(inputter)
  81.         address command 'c:delete >nil: t:part1'
  82.         exit
  83.         end
  84.     if pos('begin',readed)~=0 & datatype(word(readed,2))='NUM' then do
  85.         goon=0
  86.         file=word(readed,3)
  87.         end
  88.     end
  89. call close(inputter)
  90.  
  91. /* --- The message is UU-Written =:*] --- */
  92. /* ---  Now get info out of SUBJECT   --- */
  93. /* -------------------------------------- */
  94. 'getsubject'
  95. original=word(result,1)
  96. result=word(result,2)
  97. splitnr=right(result,length(result)-lastpos('/',result))
  98. if datatype(splitnr)~='NUM' then splitnr=1
  99.  
  100. /* ---     Let's check if all messages are there.    --- */
  101. /* ---    And meanwhile save them into a BIG file    --- */
  102. /* --- like first command, SPOT will append the text --- */
  103. /* ----------------------------------------------------- */
  104. if splitnr>1 then do
  105.     do t=2 to splitnr
  106.         'nextmessage'
  107.         'getsubject'
  108.         if result~=original' 't'/'splitnr then do
  109.             tell="Problem while reading messages!"CR
  110.             tell=tell"Conflict between subjects"CR
  111.             tell=tell"Subjects are wrong, or a message is missing"
  112.             'requestnotify PROMPT "'tell'" CENTER'
  113.             address command 'c:delete >nil: t:TEMP-ENCODED'
  114.             exit
  115.             end
  116.         saveascii 't:TEMP-ENCODED' noheader
  117.         end
  118.     end
  119.  
  120. /* --- Request a path&file to save to --- */
  121. /* -------------------------------------- */
  122. help=lastpos('/',original)
  123. if help=0 then help=pos(':',original)
  124. if help=0 then path='spot:'
  125.           else path=delstr(original,help+1)
  126. if ~exists(path) then path='spot:'
  127. goon=1
  128. do while goon
  129.     'requestfile TITLE "Pick a file 2 save" PATH "'path'" FILE "'file'"'
  130.     if RC=5 then exit
  131.     filename=result
  132.     goon=0
  133.     if exists(filename) then do
  134.         'requestresponse PROMPT "Overwrite?" GADGETS "Yes|No"'
  135.         if RC=1 then address command 'c:delete >nil: "'filename'"'
  136.                 else goon=1
  137.         end
  138.     end
  139. help=lastpos('/',filename)
  140. if help=0 then help=pos(':',filename)
  141. if help=0 then do
  142.             path='spot:'
  143.             file2=filename
  144.             end
  145.       else do
  146.           path=delstr(filename,help+1)
  147.           file2=delstr(filename,1,help)
  148.           end
  149.  
  150. /* ---  Get TEMP-ENCODED back to an original UU-Encoded file  --- */
  151. /* --- The encoded part begins after the unpair (->nmr) lines --- */
  152. /* -------------------------------------------------------------- */
  153. if splitnr>1 then do
  154. call open(inputter,'t:TEMP-ENCODED','R')
  155. call open(outputter,'t:FULLY-ENCODED','W')
  156. call writeln(outputter,'')
  157. numolines=0
  158. do while ~eof(inputter)
  159.     line=readln(inputter)
  160.     if pos('-----------------------',line)>0
  161.         then numolines=numolines+1
  162.         else do
  163.             if ~(numolines/2=trunc(numolines/2)) & line ~=''
  164.                 then call writeln(outputter,line)
  165.             end
  166.     end
  167. call writeln(outputter,'')
  168. call close(inputter)
  169. call close(outputter)
  170. address command 'c:delete >nil: t:TEMP-ENCODED'
  171. end
  172. else address command 'c:rename >nil: t:TEMP-ENCODED as t:FULLY-ENCODED'
  173.  
  174. /* --- Start UU-Decoding here --- */
  175. /* --- Routine taken from:    --- */
  176. /* --- ++ Francois Helsen     --- */
  177. /* --- ++ David Nouls         --- */
  178. /* ---                        --- */
  179. /* --- Dunno what it means    --- */
  180. /* ------------------------------ */
  181. olddir=pragma('d',path)
  182. address command 'c:UUDecode >nil: from t:FULLY-ENCODED'
  183. call pragma('d',olddir)
  184. address command 'c:delete >nil: t:FULLY-ENCODED'
  185. if (path||file~=path||file2) then
  186.      address command 'c:rename >nil: "'path||file'" as "'path||file2'"'
  187.  
  188. /* --- Finished. --- */
  189. /* ----------------- */
  190. tell='Finished.'
  191. 'requestnotify PROMPT "'tell'" CENTER'
  192. exit
  193.  
  194.  
  195.  
  196.  
  197.  
  198.