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

  1. /*Get Id gets the Filedescription out of archives
  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. /*************************************************************/
  18. /* Adjust this, if you change the file-id file in tagger.cfg */
  19. /*************************************************************/
  20. fileid="FILEID.TXT"
  21.  
  22. fnamepos=0
  23. startsig=""
  24. stopsig=""
  25. unpack=""
  26.  
  27. idnames=3
  28. idname.1="FILE_ID.GER"
  29. idname.2="FILE_ID.DIZ"
  30. idname.3="FEATURES.DOC"
  31.  
  32. call readpaths
  33.  
  34. ziplist="@"zippath" -l"
  35. zipstartsig=" ------"
  36. zipstopsig=" ------"
  37. zipfname=28
  38. unzip="@"zippath" -x -j -o "
  39.  
  40. arjlist="@"arjpath" l"
  41. unarj="@"arjpath" e "
  42. arjfname=1
  43. arjstartsig="------------"
  44. arjstopsig= "------------"
  45.  
  46. lzhlist="@"lhpath" l /o"
  47. unlzh="@"lhpath" x /o "
  48. lzhfname=22
  49. lzhstartsig="  -------- "
  50. lzhstopsig= "  -------- "
  51.  
  52. tempdir=temppath
  53.  
  54.  
  55. /***********************/
  56.  
  57. screenlines=23
  58. listlines=screenlines-2
  59.  
  60. /***********************/
  61. "@if exist "fileid" del "fileid
  62.  
  63. savedir=directory()
  64. nowdir=directory(tempdir)
  65. if translate(nowdir)<>translate(tempdir) then do
  66.   say "Wrong Temp-Directory"
  67.   exit
  68. end
  69.  
  70. tempfile="getid"nodeno".tmp"
  71.  
  72. rc = RxAnsiInit()              /* Set up ANSI variables */
  73. if (Comhandle <>'') & (Comhandle<>0) then do        /* If remote user */
  74.   rc = RxMode(MIXED,Comhandle) /* set mode to mixed */
  75.   local=0
  76. end
  77. else local=1
  78.  
  79. CRLF='0d'x'0a'x
  80.  
  81.  
  82. ok=1
  83. rc=Statusline("Gathering archive data. Please Wait...")
  84. select
  85.   when ext="ARJ" then do
  86.       arjlist filename ">"tempfile
  87.       fnamepos=arjfname
  88.       startsig=arjstartsig
  89.       stopsig=arjstopsig
  90.       unpack=unarj
  91.     end
  92.   when ext="ZIP" then do
  93.       ziplist filename ">"tempfile
  94.       fnamepos=zipfname
  95.       startsig=zipstartsig
  96.       stopsig=zipstopsig
  97.       unpack=unzip
  98.     end
  99.   when ext="LZH" then do
  100.       lzhlist filename ">"tempfile
  101.       fnamepos=lzhfname
  102.       startsig=lzhstartsig
  103.       stopsig=lzhstopsig
  104.       unpack=unlzh
  105.     end
  106.   otherwise do
  107.     rc=BottomLine("Archive-Type not supported.")
  108.     key=RxGetChar()
  109.     ok=0
  110.   end
  111. end
  112.  
  113. filenum=0
  114. if ok=1 then do
  115.   if startsig<>"" then
  116.     show=0
  117.   else
  118.     show=1
  119.   key=""
  120.   do while Lines(tempfile)>0
  121.     line=substr(linein(tempfile),1,77)
  122.     if stopsig<>"" & substr(line,1,length(stopsig))=stopsig then show=0
  123.     if show then do
  124.       fname=word(substr(line,fnamepos,77),1)
  125.       if fname<>"" then do
  126.         do i=1 to idnames
  127.           if translate(idname.i)=translate(filespec("Name",fname)) then do
  128.             filenum=filenum+1
  129.             files.filenum=fname
  130.           end
  131.         end
  132.       end
  133.     end
  134.     if startsig<>"" & substr(line,1,length(startsig))=startsig then show=1
  135.   end
  136.   rc=lineout(tempfile)
  137.  
  138.   if filenum>0 then do
  139.     i=1
  140.     do until i>filenum
  141.       rc=StatusLine("Unpacking Filename : "files.i)
  142.  
  143.       name=filespec("Name",files.i)
  144.       "@if exist "name" del "name
  145.       unpack" "filename" "files.i
  146.       call dumpfile name
  147.  
  148.       rc=BottomLine("Take this file as File-Description ? (Yes/No/ESC)")
  149.       do until key="Y" | key="N" | key="ESCAPE"
  150.         key=translate(RxGetChar())
  151.       end
  152.       if key="Y" then do
  153.         i=filenum /*end loop after this*/
  154.         "@copy "name" "savedir"\"fileid
  155.       end
  156.       if key="ESCAPE" then i=filenum /*end loop*/
  157.  
  158.       "@if exist "name" del "name
  159.       i=i+1
  160.     end
  161.   end
  162.   else do
  163.     rc=BottomLine("None of the defined description filenames has been found.")
  164.     key=RxGetChar()
  165.   end
  166. end
  167. "@if exist "tempfile" del "tempfile
  168. rc=directory(savedir)
  169. rc=BottomLine("Returning to OffTag")
  170. exit
  171.  
  172. /**************************/
  173. dumpfile:
  174. parse arg fname
  175.  
  176. buffer=""
  177. maxbufflen=100
  178.  
  179. if fname<>"" then do
  180.   rc=StatusLine("Displaying File "fname)
  181.   line=0
  182.   eof=0
  183.   do while eof=0
  184.     if dumpline(fname)=0 then eof=1
  185.     line=line+1
  186.     if line>=listlines then eof=1
  187.   end
  188.   rc=lineout(fname)
  189. end
  190. else say "No Parameter passed"
  191. return 0
  192.  
  193. /*************/
  194. dumpline:
  195. parse arg name
  196.  
  197. if (length(buffer)>0) | (chars(name)>0) then do
  198.   buffer=buffer""Charin(name,,maxbufflen-length(buffer))
  199.   nextcr=pos('0D'x,buffer)
  200.   if (nextcr=0) | (nextcr>80) then
  201.     nextcr=80
  202.   else
  203.     if substr(buffer,nextcr+1,1)='0A'x then
  204.       buffer=delstr(buffer,nextcr+1,1)
  205.   rc=RxPutChars(translate(substr(buffer,1,nextcr-1),,Xrange('00'x,'1F'x),'.')""CRLF)
  206.   buffer=delstr(buffer,1,nextcr)
  207.   if (length(buffer)>0) | (chars(name)>0) then
  208.     return 1
  209.   else
  210.     return 0
  211. end
  212. else return 0
  213.  
  214. /**************************/
  215. statusline:
  216.   parse arg title
  217.   rc=RxGoto(1,1)
  218.   if length(title)>76 then title=left(title,76)"..."
  219.   leftfillup=40-trunc(length(title)/2)
  220.   rc=RxPutChars(INTENSE""CYAN""ON_BLUE""CLS)
  221.   rc=RxPutChars(YELLOW""ON_Red""left("",leftfillup)""title""left("",79-leftfillup-length(title)))
  222.   rc=RxPutChars(CRLF""CYAN""ON_BLUE)
  223. return 0
  224.  
  225. /**************************/
  226. bottomline:
  227.   parse arg title
  228.   rc=RxGoto(screenlines,1)
  229.   if length(title)>76 then title=left(title,76)"..."
  230.   leftfillup=40-trunc(length(title)/2)
  231.   rc=RxPutChars(YELLOW""ON_RED""left("",leftfillup)""title""left("",79-leftfillup-length(title)))
  232.   rc=RxGoto(screenlines,1)
  233. return 0
  234.  
  235. /**************************/
  236. readpaths:
  237.   pathfile="FILEPATH.CFG"
  238.   zippath="unzip"
  239.   arjpath="unarj"
  240.   lhpath="lh"
  241.   temppath="c:\spool"
  242.   bbspath="c:\max"
  243.   offtagpath="c:\max\tagger"
  244.   do while lines(pathfile)
  245.     pathfileline=linein(pathfile)
  246.     pathfilekeyword=translate(word(pathfileline,1))
  247.     pathfileinfo=word(pathfileline,2)
  248.     select
  249.       when pathfilekeyword="UNPACK-ZIP" then do
  250.           zippath=pathfileinfo
  251.         end
  252.       when pathfilekeyword="UNPACK-ARJ" then do
  253.           arjpath=pathfileinfo
  254.         end
  255.       when pathfilekeyword="UNPACK-LH" then do
  256.           lhpath=pathfileinfo
  257.         end
  258.       when pathfilekeyword="TEMPDIR" then do
  259.           temppath=pathfileinfo
  260.         end
  261.       when pathfilekeyword="BBSDIR" then do
  262.           bbspath=pathfileinfo
  263.         end
  264.       when pathfilekeyword="OFFTAGDIR" then do
  265.           offtagpath=pathfileinfo
  266.         end
  267.       otherwise
  268.     end
  269.   end
  270.   rc=lineout(pathfile)
  271.   return 0
  272.  
  273.  
  274. /* --------------------------------------------------------------------- */
  275. /* Register all the functions to REXX                                    */
  276. /* --------------------------------------------------------------------- */
  277. init:
  278. CALL RxFuncAdd 'RXANSIINIT','RXANSI','RXANSIINIT'
  279. CALL RxFuncAdd 'RXGOTO',    'RXANSI','RXGOTO'
  280. CALL RxFuncAdd 'RXMODE',    'RXANSI','RXMODE'
  281. CALL RxFuncAdd 'RXLINE',    'RXANSI','RXLINE'
  282. CALL RxFuncAdd 'RXLINETYPE','RXANSI','RXLINETYPE'
  283. CALL RxFuncAdd 'RXBOX',     'RXANSI','RXBOX'
  284. CALL RxFuncAdd 'RXGETCHAR', 'RXANSI','RXGETCHAR'
  285. CALL RxFuncAdd 'RXGETCHARS','RXANSI','RXGETCHARS'
  286. CALL RxFuncAdd 'RXPUTCHARS','RXANSI','RXPUTCHARS'
  287. RETURN
  288.  
  289. /* --------------------------------------------------------------------- */
  290. /* Remote user has hung up - tell host and quit                          */
  291. /* --------------------------------------------------------------------- */
  292. usergone:
  293.   IF lastkey = 'USER GONE' THEN
  294.      say 'User gone'
  295.   ELSE
  296.      SAY 'Bug in your Rexx procedure'
  297.   rc=directory(savedir)
  298.   Exit
  299.  
  300.