home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / tagbet.zip / VIEWIT.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-09  |  8KB  |  296 lines

  1. /*example extern-file of OffTag 1.1
  2.   Parameters :
  3.     Com-Handle         File-Handle of an open Com-Port (This is a number)
  4.     NodeNo             for which Node this Script is launched
  5.     filename           Fully qualified and in Quotes (e.g.  "c:\x\HEYYOU.ZIP")
  6.  
  7. */
  8. parse upper arg comhandle nodeno '"' filename '.' ext '"'
  9.  
  10. nodeno=strip(nodeno)
  11. comhandle=strip(comhandle)
  12.  
  13. /*SIGNAL ON SYNTAX NAME usergone */ /* if remote & user hangsup, goto usergone. */
  14.  
  15. CALL init                      /* register extensions with REXX */
  16.  
  17. fnamepos=0
  18. startsig=""
  19. stopsig=""
  20. unpack=""
  21.  
  22. call readpaths
  23.  
  24. ziplist="@"zippath" -l"
  25. zipstartsig=" ------"
  26. zipstopsig=" ------"
  27. zipfname=28
  28. unzip="@"zippath" -x -j -o "
  29.  
  30. arjlist="@"arjpath" l"
  31. unarj="@"arjpath" e "
  32. arjfname=1
  33. arjstartsig="------------"
  34. arjstopsig= "------------"
  35.  
  36. lzhlist="@"lhpath" l /o"
  37. unlzh="@"lhpath" x /o "
  38. lzhfname=22
  39. lzhstartsig="  -------- "
  40. lzhstopsig= "  -------- "
  41.  
  42. tempdir=temppath
  43.  
  44. /***********************/
  45.  
  46. screenlines=23
  47. listlines=screenlines-2
  48.  
  49. /***********************/
  50.  
  51. savedir=directory()
  52. nowdir=directory(tempdir)
  53. if translate(nowdir)<>translate(tempdir) then do
  54.   say "Wrong Temp-Directory"
  55.   exit
  56. end
  57.  
  58. tempfile="viewit"nodeno".tmp"
  59.  
  60. rc = RxAnsiInit()              /* Set up ANSI variables */
  61.  
  62. if (Comhandle <>'') & (Comhandle<>0) then do        /* If remote user */
  63.   rc = RxMode(MIXED,Comhandle) /* set mode to mixed */
  64.   local=0
  65. end
  66. else local=1
  67.  
  68. CRLF='0d'x'0a'x
  69.  
  70.  
  71. ok=1
  72. rc=Statusline("Gathering archive data. Please Wait...")
  73. select
  74.   when ext="ARJ" then do
  75.       arjlist filename ">"tempfile
  76.       fnamepos=arjfname
  77.       startsig=arjstartsig
  78.       stopsig=arjstopsig
  79.       unpack=unarj
  80.     end
  81.   when ext="ZIP" then do
  82.       ziplist filename ">"tempfile
  83.       fnamepos=zipfname
  84.       startsig=zipstartsig
  85.       stopsig=zipstopsig
  86.       unpack=unzip
  87.     end
  88.   when ext="LZH" then do
  89.       lzhlist filename ">"tempfile
  90.       fnamepos=lzhfname
  91.       startsig=lzhstartsig
  92.       stopsig=lzhstopsig
  93.       unpack=unlzh
  94.     end
  95.   otherwise do
  96.     rc=DumpFile(filename"."ext)
  97.     ok=0
  98.   end
  99. end
  100.  
  101. if ok=1 then do
  102.   scrline=0
  103.   if startsig<>"" then
  104.     show=0
  105.   else
  106.     show=1
  107.   key=""
  108.   do while Lines(tempfile)>0 & Key<>ESCAPE & pos(translate(key),Xrange('A','Z'))=0
  109.     line=substr(linein(tempfile),1,77)
  110.     if stopsig<>"" & substr(line,1,length(stopsig))=stopsig then show=0
  111.     if show then do
  112.       rc=RxPutChars(RED""d2c(c2d('A')+scrline)" "CYAN""line""CRLF)
  113.       scrline=scrline+1
  114.       fname.scrline=word(substr(line,fnamepos,77),1)
  115.     end
  116.     if startsig<>"" & substr(line,1,length(startsig))=startsig then show=1
  117.     if scrline>=listlines then do
  118.       rc=BottomLine("Press A-Z to View File or Esc for Exit. ENTER continues.")
  119.       do until key=ENTER |  key=ESCAPE | pos(translate(key),Xrange('A','Z'))>0
  120.         key=RxGetChar()
  121.         if key=ENTER then do
  122.           rc=StatusLine("Listing archive "filename)
  123.           scrline=0
  124.         end
  125.       end
  126.     end
  127.   end
  128.   rc=lineout(tempfile)
  129.   if scrline<>0 & key<>ESCAPE & pos(translate(key),Xrange('A','Z'))=0 then do
  130.     do until key=ENTER |  key=ESCAPE | pos(translate(key),Xrange('A','Z'))>0
  131.       rc=BottomLine("Press A-Z to View File. ENTER or ESC returns.")
  132.       key=RxGetChar()
  133.     end
  134.   end
  135.  
  136.   keypos=pos(translate(key),xrange('A','Z')) /*check for View-File command*/
  137.  
  138.   if keypos>0 & keypos<=scrline then do
  139.     rc=StatusLine("Unpacking Filename : "fname.keypos)
  140.     name=filespec("Name",fname.keypos)
  141.     "@if exist "name" del "name
  142.     unpack" "filename" "fname.keypos
  143.     call dumpfile name
  144.     "@if exist "name" del "name
  145.   end
  146.   "@if exist "tempfile" del "tempfile
  147.   rc=directory(savedir)
  148. end
  149. /*else do
  150.   rc=BottomLine("Press any key to return to OffTag")
  151.   key=RxGetChar()
  152. end*/
  153. rc=BottomLine("Returning to OffTag, stand by...")
  154. exit
  155.  
  156. /**************************/
  157. dumpfile:
  158. parse arg fname
  159.  
  160. buffer=""
  161. maxbufflen=100
  162.  
  163. if fname<>"" then do
  164.   rc=StatusLine("Displaying File "fname)
  165.   line=0
  166.   eof=0
  167.   reply=""
  168.   do while reply<>"Q" & eof=0
  169.     if dumpline(fname)=0 then eof=1
  170.     line=line+1
  171.     if eof then do
  172.       rc=BottomLine("End of File: Press any key to Quit")
  173.       key=RxGetChar()
  174.     end
  175.     else
  176.       if line>=listlines then do
  177.         rc=BottomLine("Press Q to quit, any other Key continues.")
  178.         reply=Translate(RxGetChar())
  179.         line=0
  180.         if reply<>"Q" then
  181.           rc=StatusLine("Displaying File "fname)
  182.       end
  183.   end
  184.   rc=lineout(fname)
  185. end
  186. else say "No Parameter passed"
  187. return 0
  188.  
  189. /*************/
  190. dumpline:
  191. parse arg name
  192.  
  193. if (length(buffer)>0) | (chars(name)>0) then do
  194.   buffer=buffer""Charin(name,,maxbufflen-length(buffer))
  195.   nextcr=pos('0D'x,buffer)
  196.   if (nextcr=0) | (nextcr>80) then
  197.     nextcr=80
  198.   else
  199.     if substr(buffer,nextcr+1,1)='0A'x then
  200.       buffer=delstr(buffer,nextcr+1,1)
  201.   rc=RxPutChars(translate(substr(buffer,1,nextcr-1),,Xrange('00'x,'1F'x),'.')""CRLF)
  202.   buffer=delstr(buffer,1,nextcr)
  203.   if (length(buffer)>0) | (chars(name)>0) then
  204.     return 1
  205.   else
  206.     return 0
  207. end
  208. else return 0
  209.  
  210. /**************************/
  211. statusline:
  212.   parse arg title
  213.   rc=RxGoto(1,1)
  214.   if length(title)>76 then title=left(title,76)"..."
  215.   leftfillup=40-trunc(length(title)/2)
  216.   rc=RxPutChars(INTENSE""CYAN""ON_BLUE""CLS)
  217.   rc=RxPutChars(YELLOW""ON_Red""left("",leftfillup)""title""left("",79-leftfillup-length(title)))
  218.   rc=RxPutChars(CRLF""CYAN""ON_BLUE)
  219. return 0
  220.  
  221. /**************************/
  222. bottomline:
  223.   parse arg title
  224.   rc=RxGoto(screenlines,1)
  225.   if length(title)>76 then title=left(title,76)"..."
  226.   leftfillup=40-trunc(length(title)/2)
  227.   rc=RxPutChars(YELLOW""ON_RED""left("",leftfillup)""title""left("",79-leftfillup-length(title)))
  228.   rc=RxGoto(screenlines,1)
  229. return 0
  230.  
  231. /**************************/
  232. readpaths:
  233.   pathfile="FILEPATH.CFG"
  234.   zippath="unzip"
  235.   arjpath="unarj"
  236.   lhpath="lh"
  237.   temppath="c:\spool"
  238.   bbspath="c:\max"
  239.   offtagpath="c:\max\tagger"
  240.   do while lines(pathfile)
  241.     pathfileline=linein(pathfile)
  242.     pathfilekeyword=translate(word(pathfileline,1))
  243.     pathfileinfo=word(pathfileline,2)
  244.     select
  245.       when pathfilekeyword="UNPACK-ZIP" then do
  246.           zippath=pathfileinfo
  247.         end
  248.       when pathfilekeyword="UNPACK-ARJ" then do
  249.           arjpath=pathfileinfo
  250.         end
  251.       when pathfilekeyword="UNPACK-LH" then do
  252.           lhpath=pathfileinfo
  253.         end
  254.       when pathfilekeyword="TEMPDIR" then do
  255.           temppath=pathfileinfo
  256.         end
  257.       when pathfilekeyword="BBSDIR" then do
  258.           bbspath=pathfileinfo
  259.         end
  260.       when pathfilekeyword="OFFTAGDIR" then do
  261.           offtagpath=pathfileinfo
  262.         end
  263.       otherwise
  264.     end
  265.   end
  266.   rc=lineout(pathfile)
  267.   return 0
  268.  
  269.  
  270. /* --------------------------------------------------------------------- */
  271. /* Register all the functions to REXX                                    */
  272. /* --------------------------------------------------------------------- */
  273. init:
  274. CALL RxFuncAdd 'RXANSIINIT','RXANSI','RXANSIINIT'
  275. CALL RxFuncAdd 'RXGOTO',    'RXANSI','RXGOTO'
  276. CALL RxFuncAdd 'RXMODE',    'RXANSI','RXMODE'
  277. CALL RxFuncAdd 'RXLINE',    'RXANSI','RXLINE'
  278. CALL RxFuncAdd 'RXLINETYPE','RXANSI','RXLINETYPE'
  279. CALL RxFuncAdd 'RXBOX',     'RXANSI','RXBOX'
  280. CALL RxFuncAdd 'RXGETCHAR', 'RXANSI','RXGETCHAR'
  281. CALL RxFuncAdd 'RXGETCHARS','RXANSI','RXGETCHARS'
  282. CALL RxFuncAdd 'RXPUTCHARS','RXANSI','RXPUTCHARS'
  283. RETURN
  284.  
  285. /* --------------------------------------------------------------------- */
  286. /* Remote user has hung up - tell host and quit                          */
  287. /* --------------------------------------------------------------------- */
  288. usergone:
  289.   IF lastkey = 'USER GONE' THEN
  290.      say 'User gone'
  291.   ELSE
  292.      SAY 'Bug in your Rexx procedure'
  293.   rc=directory(savedir)
  294.   Exit
  295.  
  296.