home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / dirmap10.zip / dirmap.cmd next >
OS/2 REXX Batch file  |  1998-08-12  |  36KB  |  978 lines

  1. /* REXX - DIRMAP - Make a drive snapshot of files for browsing */
  2. /* 
  3.    (C) 1996/1998 by Oliver Heidelbach
  4.    Send bugs, comments etc. to: oheiabbd@zedat.fu-berlin.de
  5.    
  6.    History:
  7.    11.08.98 - Fixed a bug with the short links: when only full
  8.               qualified path(s) were given the current drive
  9.               was added to the link list anyway
  10.    09.08.98 - added drive short links if only one output file
  11.             - made file name in HTML header variable
  12.    20.05.98 - decided not to release this thingy without
  13.               the ability to process multiple file masks from
  14.               the command line.
  15.    19.05.98 - implemented javascript for all links
  16.             - made output acceptable for other eyes (somehow)
  17.             - added ability to handle file names with spaces
  18.               (not via the commandline, but internal if found)
  19.    18.05.98 - fixed a bug in title fetching: only html files
  20.               with lower case file extension were investigated
  21.    16.05.98 - fixed an severe bug I had no mind to
  22.               investigate over the last months
  23.    17.08.97 - made all language output variable
  24.    14.08.97 - added ability to have different output files
  25.               for each drive (option /2)
  26.             - added ability to have different output files
  27.               for each directory (option /3)
  28.    10.08.97 - added ability to skip certain drives
  29.    08.08.97 - beautified HTML output
  30.             - rediscovered this file on my disk and decided to
  31.               enhance it
  32.    15.03.96 - added ability to fetch title from html documents
  33.             - began writing dirmap
  34.  
  35. */
  36.  
  37. _initvars:
  38. version = 1.00
  39. loaded = 0; qset = 0; 
  40. crlf = '0d0a'x; yes = ''
  41. files = 0; dirs = 0; total = 0; skip = 0
  42. args. = ''; javascr = 0
  43. fileidx = 0; oldfidx = 0; fullspec = 0; skipdrive = 0
  44. actdrive = 'ACTDRV'; lastdrive = 'LASTDRV'
  45. lastdir = 'LASTDIR'; actdir = 'ACTDIR'
  46. drvfile = 'DRVFILE'; dirfile = 'DIRFILE'
  47. cdrom = ''; fmasks = ''
  48.  
  49. SIGNAL on halt name _userbreak    /* Install error handling on userbreak */
  50. /* SIGNAL on novalue */
  51.  
  52. _starttimer:
  53. CALL Time 'E'
  54.  
  55. _load:                         /* If not loaded, load RexxUtil functions */
  56. IF RxFuncQuery('SysLoadFuncs') <> 0 THEN DO
  57.    CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  58.    loaded = 1
  59. END
  60. CALL SysLoadFuncs
  61.  
  62. _checkenv:                         /* Fetch country code from os2sys.ini */
  63. lval = SysIni('User','PM_National','iCountry')
  64. IF Chk4Netscape() = 1 THEN javascr = 1
  65.  
  66. _getcommandline:                             /* Check if user wants help */
  67. PARSE ARG opt1
  68. IF opt1 = '/?' | opt1 = '-?' | opt1 = '' THEN SIGNAL _usage
  69. Call SetInput(lval)                /* If not, set input language strings */
  70.  
  71.                                 /* Parse command line input and seperate */
  72.                                          /* into options and other input */
  73. PARSE ARG cline
  74. n. = ''; i = 1
  75. DO while cline <> ''
  76.    PARSE var cline n.i cline
  77.    i = i + 1
  78. END
  79. n.0 = i - 1
  80.  
  81. opts. = ''; pars. = ''       /* Store options and other input into stems */
  82. j = 1; k = 1
  83. DO i = 1 to n.0            /* Know about dos-like and unix-like switches */
  84.    IF SubStr(n.i,1,1) = '/' | SubStr(n.i,1,1) = '-' THEN DO
  85.       opts.j = n.i; j = j + 1                                 /* Options */
  86. END
  87.    ELSE IF n.i <> '' THEN DO
  88.       pars.k = n.i; k = k + 1                             /* Other input */
  89.    END
  90. END
  91. opts.0 = j - 1      /* Store # of options and other input into stems too */
  92. pars.0 = k - 1
  93.  
  94. _checkoptions:                        /* Parse options to see what to do */
  95. unknown. = ''; root = 0; j = 0
  96. short = 0; all = 0; mid = 0; long = 0; 
  97. DO i = 1 to opts.0
  98.    IF Pos(args.1,opts.i,1) = 2 THEN short = 1       /* All in one file      */
  99.    ELSE IF Pos(args.0,opts.i,1) = 2 THEN all = 1    /* Scan all local drvs  */
  100.    ELSE IF Pos(args.2,opts.i,1) = 2 THEN mid = 1    /* Files per drive      */
  101.    ELSE IF Pos(args.3,opts.i,1) = 2 THEN long = 1   /* Files per directory  */
  102.    ELSE IF Pos(args.4,opts.i,1) = 2 THEN DO         /* Name of root file    */
  103.        root = 1
  104.        rfile = Substr(opts.i, 3, Length(opts.i))
  105.    END
  106.    ELSE IF Pos(args.5,opts.i,1) = 2 THEN DO         /* Drives not to scan   */
  107.        skip = 1
  108.        PARSE UPPER Value(Substr(opts.i, 3, Length(opts.i))) WITH skiplist
  109.    END
  110.    ELSE IF Pos('b',opts.i,1) = 2 THEN a = opts.i    /* xxxxxxxxxxxxxxxxxx   */
  111.    ELSE DO 
  112.       j = j + 1; unknown.j = opts.i
  113.    END
  114. END
  115.  
  116. unknown.0 = j
  117.  
  118. IF j > 0 THEN DO                      /* Tell user about unknown options */
  119.    SAY ''; CALL SetLangue 12; 
  120.    DO i = 1 to unknown.0
  121.       CALL CharOut,  unknown.i||' '
  122.    END
  123.    CALL CharOut, crlf
  124.    SIGNAL _usage
  125. END
  126. IF pars.0 = 0 THEN DO
  127.     SAY ''
  128.     CALL SetLangue 9
  129.     SIGNAL _usage
  130. END
  131.  
  132. _openfile:
  133. IF root <> 1 THEN
  134.     rootfile = 'dirmap.htm'
  135. ELSE
  136.     rootfile = rfile
  137.  
  138. CALL OpenFile(rootfile)
  139. CALL MakeHeader rootfile 'Dir Map'
  140. CALL SetLangue 4                              /* Write title to rootfile */
  141. CALL SetLangue 7                           /* Write subtitle to rootfile */
  142.  
  143. _getdrives:
  144. startdrive = 'C:'
  145. range = 'LOCAL'
  146. d. = ''; total = 0
  147. IF all = 1 THEN DO                                    /* Scan all drives */
  148.    ldrives = SysDriveMap(startdrive, range)
  149.    i = 1; d.0 = 0
  150.    DO while ldrives <> ''
  151.       PARSE var ldrives d.i ldrives
  152.       IF skip = 1 THEN        /* Reset stem if current drive in skiplist */
  153.           IF Pos(Substr(d.i,1,1), skiplist) > 0 THEN i = i - 1
  154.       i = i + 1
  155.    END
  156.    d.0 = i - 1              /* Store # of local drives present on system */
  157. END
  158. ELSE DO 
  159.    d.0 = 1
  160.    d.1 = SubStr(Directory(),1,2)         /* Determine current disk drive */
  161. END
  162.  
  163. SAY ''
  164. k = d.0
  165.  
  166. _getfiles:
  167. n = 0
  168. files.0 = 0
  169.  
  170. DO j = 1 to pars.0                               /* Process filemasks    */
  171.    DO i = 1 to d.0                               /* Process local drives */
  172.       IF d.i <> '' & Pos(d.i, cdrom, 1) = 0 THEN DO    /* but no CD-ROMS */
  173.      IF Pos(':',pars.j,1) = 2 THEN DO 
  174.         spec = pars.j                    /* Drive letter in filemask */
  175.         fullspec = 1
  176.         IF all <> 1 THEN DO               /* Get drive for diskusage */
  177.            drive = Translate(Left(pars.j,2)); noadd = 0
  178.            DO l = 1 to k            /* Is drive already in disklist? */
  179.           IF drive = d.l THEN noadd = 1
  180.            END
  181.            IF noadd <> 1 THEN DO 
  182.           k = k + 1; d.k = drive            /* If not in, add it */
  183.            END
  184.         END
  185.         CALL SetLangue 1; CALL CharOut, pars.j||crlf
  186.      END
  187.      ELSE DO 
  188.         IF Left(pars.j,1) \= '.' THEN 
  189.            spec = d.i || '\' || pars.j     /* Drive not in file mask */
  190.         ELSE spec = pars.j                 /* relative path . or ..  */
  191.         CALL SetLangue 1; CALL CharOut, pars.j
  192.         CALL SetLangue 2; CALL CharOut, d.i
  193.      END
  194.          IF SysFileTree(spec, 'searches', 'FS') <> 0 THEN DO 
  195.         CALL SetLangue 3; CALL CharOut, d.i||crlf
  196.      END
  197.          DO idx = 1 to searches.0    /* Store found items into the queue */
  198.             LINE = searches.idx
  199.             PARSE value LINE WITH x1 x2 x3 x4 x5
  200.  
  201.             /* Make a dummy file name entry in upper case     */
  202.             /* and without spaces to sort array by file name  */
  203.             /* Further split into path (x_tmp1) and file name */
  204.             /* (x_tmp2) to have it sorted correctly later     */
  205.             x_tmp = STRIP(x5)
  206.             IF Pos(' ', x_tmp) > 0 THEN
  207.                x_tmp = Translate(x_tmp, '*', ' ')
  208.             x_tmp = Translate(x_tmp)
  209.             x_tmp1 = SubStr(x_tmp, 1, LastPos('\', x_tmp))
  210.             x_tmp2 = Dbrleft(x_tmp, LastPos('\', x_tmp))
  211.             n = n + 1
  212.             files.n = x_tmp1||' '||x_tmp2||' '||x1||' '||x2||' '||x3||,
  213.              ' '||x4||' 'x5
  214.             files.0 = files.0 + 1
  215.          END
  216.          total = total + searches.0
  217.      IF fullspec = 1 THEN ITERATE j
  218.          CALL CharOut, ' ('Format(searches.0,5,0)')'||crlf
  219.       END
  220.    END
  221.    SAY ''
  222. END
  223. d.0 = k                                /* Update number of actual drives */
  224.  
  225.                                     /* Write used file masks to rootfile */
  226. DO i = 1 TO pars.0
  227.     fmasks = fmasks||'['pars.i'] '
  228. END
  229. CALL CharOut rootfile, fmasks||'</H3>'||crlf
  230. IF mid = 1 | long = 1 THEN
  231.     CALL CharOut rootfile, '<HR>'||crlf
  232.  
  233.                        /* Write drive links to rootfile if one file only */
  234. drvidx = 1
  235. IF fullspec = 1 THEN drvidx = 2
  236. IF mid  \= 1 & long \= 1 & d.0 > 1 THEN DO
  237.    DO i = drvidx to d.0
  238.    CALL CharOut, 'd.i: '||d.i
  239.        CALL SetLangue 24
  240.    END
  241.    CALL CharOut rootfile, crlf
  242. END
  243.  
  244.                   /* Sort stem of found files if more than one file mask */
  245. IF pars.0 > 1 THEN DO
  246.     SAY 'Now sorting...'
  247.     CALL qqsort 1, files.0
  248. END
  249.  
  250. _parsefilestem:     /* Tell the user what was found and how long it took */
  251. IF pars.0 > 0 THEN DO 
  252.    SAY ''; CALL CharOut, files.0; CALL SetLangue 5
  253.    CALL CharOut, 'in 'Format(Time('E'),,2); CALL SetLangue 6
  254. END
  255.  
  256. _writefiles:
  257. /* Scheme for output: (just in case you want to hack my code)
  258.  * - with opt. /1 everything goes into 'rootfile' (main overview)
  259.  * - with opt. /2 file entries found go into 'drvfile' (drives overview)
  260.  *   and drives found go into 'rootfile'
  261.  * - with opt. /3 file entries found go into 'dirfile' (dirs overview),
  262.  *   directories found go into 'drvfile' and drives found go
  263.  *   into 'rootfile'
  264.  *
  265.  * The part of next do-loop valid for all three options (default, mid
  266.  * and long) processes a file variable 'outfile', so you need to make 
  267.  * sure this variable is set to the appropriate output file *before* 
  268.  * writing to it.
  269.  *
  270.  */
  271.  
  272. drvidx = 0
  273. DO i = 1 to files.0
  274.                   /* Forget about the first both temp. entries inserted  */
  275.                   /* previously for sorting puposes and handle entries   */
  276.                   /* as if these would be directly in SysFileTree format */
  277.   PARSE value files.i WITH . . x1 x2 x3 x4 x5
  278.   /* say x1' 'x2' 'x3' 'x4' 'x5 */
  279.   it = STRIP(x5)
  280.   actdrive = substr(it,1, 2)
  281.  
  282.   IF Pos('R',x4,1)=4 THEN ITERATE     
  283.   IF x1 = '' & x2 = '' THEN DO 
  284.      SAY ''; ITERATE 
  285.   END
  286.   ELSE DO                             /* Handle files                    */
  287.      actdir = substr(it,1, LastPos('\',it))
  288.  
  289.                                       /* Current drive has changed       */
  290.      IF lastdrive <> actdrive THEN DO
  291.         CALL SetLangue 20
  292.         diridx = 0                 /* Reset directory index on new drive */
  293.         IF mid = 1 | long = 1 THEN DO
  294.              IF drvfile \= 'DRVFILE' THEN DO
  295.                  IF long = 1 THEN DO     /* Don't forget last file index */
  296.                      CALL CharOut drvfile, ' <I>['fileidx']</I><P>'crlf
  297.                      oldfidx = fileidx; fileidx = 0
  298.                  END
  299.                  CALL CharOut drvfile, '<P><HR>'
  300.                  CALL SetLangue 17
  301.                  CALL CharOut drvfile, crlf
  302.                  CALL MakeFooter drvfile
  303.              END
  304.              drvnam = substr(actdrive,1, 1)
  305.              drvfile = drvnam||'.htm'
  306.              CALL OpenFile(drvfile)
  307.              /* CALL MakeHeader drvfile 'Laufwerk 'actdrive */
  308.              CALL SetLangue 21
  309.              IF mid = 1 THEN DO
  310.                  CALL SetLangue 23
  311.                  CALL CharOut drvfile, fmasks||'</H3><HR>'||crlf
  312.              END
  313.              CALL SetLangue 17
  314.              CALL CharOut drvfile, '<HR><P>'crlf
  315.              CALL SetLangue 18
  316.         END
  317.         ELSE           
  318.              CALL CharOut rootfile, '<P><A Name="'||Translate(actdrive)||,
  319.               '"><HR></A>'
  320.      END
  321.  
  322.                                  /* Current directory has changed        */
  323.      IF lastdir <> actdir THEN DO
  324.         dirs = dirs + 1
  325.     IF long = 1 THEN DO
  326.             SAY actdir
  327.             IF dirfile \= 'DIRFILE' THEN DO
  328.                 CALL CharOut dirfile, '<P><HR>'
  329.                 CALL SetLangue 19
  330.                 CALL CharOut dirfile, crlf
  331.                 CALL MakeFooter dirfile
  332.                 oldfidx = fileidx; fileidx = 0
  333.                 IF diridx > 0 THEN
  334.                     CALL CharOut drvfile, ' <I>['oldfidx']</I></P>'crlf
  335.             END
  336.  
  337.             diridx = diridx + 1
  338.             dirfile = drvnam||diridx||'.htm'
  339.  
  340.             CALL OpenFile(dirfile)
  341.             CALL SetLangue 22
  342.             CALL CharOut dirfile, fmasks||'</H3><HR>'||crlf
  343.             CALL SetLangue 19
  344.             CALL CharOut dirfile, '<HR><P>'crlf
  345.             CALL SetLangue 15
  346.             outfile = dirfile
  347.         END
  348.         ELSE IF mid = 1 THEN
  349.             outfile = drvfile
  350.         ELSE
  351.             outfile = rootfile
  352.  
  353.         CALL CharOut outfile, '<H3>['actdir']</H3>'crlf
  354.      END
  355.  
  356.      itfname = Dbrleft(it, LastPos('\', it))
  357.      linkstat = x1' - 'x2' - 'x3' Bytes'
  358.  
  359.      it_upper = Translate(it)                /* Get title if HTML file */
  360.      IF Pos('.HTM', it_upper) > 0 THEN DO
  361.          title = GetTitle(it)
  362.          cleantitle = DelHtmlTags(title)
  363.      END
  364.      ELSE cleantitle = ''
  365.  
  366.      /* Replace all spaces in file name to let it look like one string */
  367.      IF Pos(' ', it) > 0 THEN DO
  368.         it = Translate(it, '*', ' ')
  369.         itfname = Translate(itfname, '*', ' ')
  370.      END
  371.  
  372.      IF long = 1 THEN fileidx = fileidx + 1
  373.      files = files + 1
  374.      CALL MakeLink outfile it linkstat itfname cleantitle 
  375.  
  376.   END
  377.   lastdrive = actdrive; lastdir = actdir
  378. END                           
  379.  
  380. _addhtmlfooter:
  381. IF long = 1 THEN DO                /* Don't forget very last file index */
  382.     CALL CharOut drvfile, ' <I>['fileidx']</I><P>'crlf
  383.     CALL CharOut drvfile, '<P><HR>'
  384.     CALL SetLangue 17
  385.     CALL CharOut drvfile, crlf
  386.     CALL MakeFooter drvfile
  387.     CALL CharOut dirfile, '<P><HR>'
  388.     CALL SetLangue 19
  389.     CALL CharOut dirfile, crlf
  390.     CALL MakeFooter dirfile
  391. END
  392. IF mid = 1 THEN DO
  393.     CALL CharOut drvfile, '<P><HR>'
  394.     CALL SetLangue 17
  395.     CALL CharOut drvfile, crlf
  396.     CALL MakeFooter drvfile
  397. END
  398. CALL MakeFooter rootfile
  399.  
  400. _getelapsedtime:        /* Tell user what happened and how long it took */
  401. IF pars.0 > 0 THEN DO 
  402.    SAY ''; CALL SetLangue 13; CALL CharOut, files
  403.    CALL SetLangue 14; CALL CharOut, dirs||crlf
  404.    CALL SetLangue 16; CALL Charout, Format(Time('E'),,2)
  405.    CALL SetLangue 6
  406. END
  407.  
  408. _housekeeping:
  409. SIGNAL _unload
  410.  
  411. _usage:                                    /* Output help text to screen */
  412. PARSE SOURCE . . filen                      /* Determine source filename */
  413. PARSE upper var filen fn'.'
  414. fn = dbrleft(fn, LastPos('\', fn))
  415. CALL SetUsage lval, fn, version
  416. SAY ''
  417. DO i = 1 to 12                                   /* Show all usage lines */
  418.    IF i = 2 | i = 4 | i = 10 THEN SAY ''            /* Insert blank line */
  419.    SAY Value('use'i)
  420. END
  421.  
  422. _unload:
  423. IF loaded = 1 THEN CALL SysDropFuncs
  424. EXIT 0                                            /* End of main routine */
  425.  
  426. _userbreak:
  427. SAY ''; SAY 'Bye bye...'
  428. SIGNAL _housekeeping
  429.  
  430. /*************************/
  431. /* Additional functions */
  432. /***********************/
  433.  
  434. /* Check whether Netscape is installed */
  435. Chk4Netscape:
  436. penv = Value('path', , 'OS2ENVIRONMENT')
  437. PARSE UPPER Value(penv) WITH npath
  438. IF Pos('NETSCAPE', npath) > 0 THEN
  439.     ns = 1
  440. ELSE
  441.     ns = 0
  442.  
  443. RETURN ns
  444.  
  445. MakeHeader:
  446.     PARSE ARG outfile title
  447.  
  448.     PARSE SOURCE . . filen
  449.     PARSE upper var filen fn'.'
  450.     fn = dbrleft(fn, LastPos('\', fn))
  451.  
  452.     CALL CHAROUT outfile, '<HTML> <HEAD>'crlf
  453.     CALL CHAROUT outfile, '<!-- File automatically generated by '||fn||' on '
  454.     CALL CHAROUT outfile, DATE()' at 'TIME('N')' -->'crlf
  455.     CALL CHAROUT outfile, '<TITLE>'title'</TITLE></HEAD><BODY',
  456.      'BGCOLOR="#FFFFFF">'crlf
  457. RETURN
  458.  
  459. MakeFooter:
  460.     ARG outfile
  461.     CALL CHAROUT outfile, '<HR>'crlf'[<I>'DATE() TIME('N')'</I>]'crlf
  462.     CALL CHAROUT outfile, '</BODY> </HTML>'crlf
  463.     CALL stream outfile,'c','close'
  464. RETURN
  465.  
  466. /* Make a link for current entry (file) */
  467. MakeLink: PROCEDURE EXPOSE javascr crlf
  468.     parse ARG outfile url jlink rstr title
  469.  
  470.     /* Put spaces in file name back where these belong */
  471.     IF Pos('*', url) > 0 THEN DO
  472.         url = Translate(url, ' ', '*')
  473.         rstr = Translate(rstr, ' ', '*')
  474.     END
  475.  
  476.     IF javascr = 1 THEN DO
  477.         j1 = ' onMouseOver="window.status='||"'"||jlink||" ';return true"||'" '
  478.         j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  479.         java1 = j1||j2
  480.         IF title <> '' THEN
  481.         CALL CHAROUT outfile, '<A'java1'HREF="file:///'url'">'title'</A>',
  482.              ' <I>['rstr']</I><BR>'
  483.         ELSE
  484.         CALL CHAROUT outfile, '<A'java1'HREF="file:///'url'">'url'</A><BR>'
  485.     END
  486.     ELSE DO
  487.         IF title <> '' THEN
  488.         CALL CHAROUT outfile, '<A HREF="file:///'url'">'title'</A>',
  489.              ' <I>['rstr', 'jlink']</I><BR>'
  490.         ELSE
  491.         CALL CHAROUT outfile, '<A HREF="file:///'url'">'url'</A>',
  492.              ' <I>['jlink']</I><BR>'
  493.     END
  494.     CALL CHAROUT outfile, crlf
  495. RETURN
  496.  
  497. /* Fetch title line from from file */
  498. GetTitle: PROCEDURE expose lval crlf
  499.    ARG htmlfile
  500.    titleline = ''
  501.    IF Stream(htmlfile,'c','query exists') = '' THEN DO
  502.       IF Pos('49',lval,1) = 1 THEN DO
  503.           SAY 'Kann Datei 'htmlfile' nicht finden.'
  504.           RETURN 'Datei nicht gefunden: 'htmlfile
  505.       ELSE DO
  506.           SAY 'File 'htmlfile' not found.'
  507.           RETURN 'File not found: 'htmlfile
  508.       END
  509.    END
  510.    IF Stream(htmlfile,'c','open read') \= 'READY:' THEN DO
  511.       CALL SetLangue 11
  512.       CALL CharOut, htmlfile||crlf
  513.       RETURN htmlfile
  514.    END
  515.    DO while Stream(htmlfile,'s') \= 'NOTREADY' 
  516.       line = LineIn(htmlfile)
  517.       PARSE UPPER VALUE(line) WITH buffer
  518.       buffer = STRIP(buffer)
  519.  
  520.       /* Title string on this line */
  521.       IF POS('<TITLE>', buffer) > 0 & Length(buffer) > 8 THEN DO
  522.           titleline = line
  523.           LEAVE
  524.       END
  525.       /* Title string probably on next line */
  526.       ELSE IF POS('<TITLE>', buffer) > 0 THEN DO
  527.           titleline = LineIn(htmlfile)
  528.           LEAVE
  529.       END
  530.  
  531.    END
  532.    CALL Stream htmlfile,'c','close'
  533. RETURN titleline
  534.  
  535. /* Delete HTML tags from input line */
  536. DelHtmlTags:
  537.    PARSE ARG line
  538.    DO while POS('<', line) > 0
  539.       p = POS('<', line)
  540.       q = POS('>', line, p)
  541.       IF q = 0 THEN
  542.          q = POS(' ', line, p)
  543.       IF p < q THEN
  544.         line = DELSTR(line,p,q - p + 1)
  545.       ELSE
  546.         line = DELSTR(line,p,length(line))
  547.    END
  548. RETURN line
  549.  
  550. /* Open a file and check whether it's accesible */
  551. OpenFile:
  552. parse arg file
  553. IF Stream(file,'c','query exists') <> '' THEN DO
  554.     CALL SetLangue 10
  555.     CALL CharOut, file
  556.     CALL SetLangue 8
  557.     rc = SysFileDelete(file)
  558.     CALL Rsp_SysFileDelete rc
  559. END
  560. IF Stream(file,'c','open') \= 'READY:' THEN DO
  561.     CALL SetLangue 11   
  562.     CALL CharOut, file||crlf
  563. END
  564. RETURN
  565.  
  566. /* ------------------------------------------------------------------ */
  567. /* function: quick sort routine                                       */
  568. /*                                                                    */
  569. /* call:     qqsort first_element, last_element                       */
  570. /*                                                                    */
  571. /* returns:  nothing                                                  */
  572. /*                                                                    */
  573. /* notes:    You must save the elements to sort in the stem "a."      */
  574. /*           a.0 must contain the number of elements in the stem.     */
  575. /*                                                                    */
  576. /*                                                                    */
  577. /* This function worked out of the box - I just have changed          */
  578. /* the name of the stem - and is directly taken from                  */
  579. /* Rexx Tips & Tricks (rxtt26.zip), Copyright (c) 1994 - 1997,        */
  580. /* by Bernd Schemmer <100104.613@compuserve.com>                      */
  581. /* (You'll find it on Hobbes (http://hobbes.nmsu.edu))                */
  582.  
  583. qqsort: procedure expose files.
  584.  
  585.   arg lf, re
  586.  
  587.   IF re -lf < 9 THEN
  588.     DO lf = lf TO re -1
  589.       m = lf
  590.       DO j = lf +1 TO re
  591.         IF files.j < files.m THEN
  592.           m = j
  593.       END
  594.       t = files.m; files.m = files.lf; files.lf = t
  595.    END
  596.    ELSE
  597.      DO
  598.        i = lf
  599.        j = re
  600.        k = (lf + re)%2
  601.        t = files.k
  602.        DO UNTIL i > j
  603.          DO WHILE files.i < t
  604.            i = i + 1
  605.          END
  606.          DO WHILE files.j > t
  607.            j = j - 1
  608.          END
  609.          IF i <= j THEN
  610.          DO
  611.            xchg = files.i
  612.            files.i = files.j
  613.            files.j = xchg
  614.            i = i + 1
  615.            j = j - 1
  616.          END
  617.       END
  618.       CALL qqsort lf, j
  619.       CALL qqsort i, re
  620.    END
  621.  
  622. RETURN
  623.  
  624. /********************************/
  625. /* Language specific functions */
  626. /******************************/
  627. /*
  628.  * Use these for your own language if it is neither german nor english.
  629.  * I suggest to replace the german and to leave the english language.
  630.  * Just change the country code and the appropriate output strings.
  631.  */
  632. /* Set input strings according to current country code                   */
  633. SetInput: PROCEDURE expose args. yes
  634.    PARSE ARG country
  635.    IF Pos('49',country,1) = 1 THEN DO
  636.        yes = 'J'
  637.        args.0 = 'a'; args.1 = '1'
  638.        args.2 = '2'; args.3 = '3'
  639.        args.4 = 'n'; args.5 = '-'
  640.        args.6 = 's'
  641.    END
  642.    ELSE DO
  643.        yes = 'Y'
  644.        args.0 = 'a'; args.1 = '1'
  645.        args.2 = '2'; args.3 = '3'
  646.        args.4 = 'n'; args.5 = '-'
  647.        args.6 = 's'
  648.    END
  649. RETURN
  650.  
  651. /* Set usage strings according to current country code                   */
  652. SetUsage:
  653.    PARSE ARG country, file, vers
  654.    IF Pos('49',country,1) = 1 THEN DO 
  655.       use1a = ' '||'1b5b376d'x||file vers
  656.       use1b = ' - Erstellen von Verzeichnisübersichten als HTML-Datei',
  657.               '1b5b306d'x
  658.       use1 = use1a||use1b
  659.       use2 = '   Aufruf:                                              '
  660.       use3 = '   'file' [/a /1 /2 /3 /n<map.htm> /-<def...>] <dateimaske> [...]'
  661.       use4 = '     /a: Alle Laufwerke durchsuchen                     '
  662.       use5 = '     /1: Eine HTML-Seite für alle Dateien (Standard)    '
  663.       use6 = '     /2: Eine HTML-Seite pro Laufwerk                   '
  664.       use7 = '     /3: Eine HTML-Seite pro Verzeichnis                '
  665.       use8 = '     /n: Name der Hauptseite (Standard: dirmap.htm)     '
  666.       use9 = '     /-: Laufwerke, die nicht durchsucht werden sollen  '
  667.      use10 = '   Beispiele:                                           '
  668.      use11 = '   'file' c:\netscape\cache\*.*htm?                         '
  669.      use12 = '   'file' /a /3 /-ij *.*htm? *.gif *.jp*g                   '
  670.    END
  671.    ELSE DO 
  672.       use1a = ' '||'1b5b376d'x||file vers
  673.       use1b = ' - compile directory overviews as HTML file '||'1b5b306d'x
  674.       use1 = use1a||use1b
  675.       use2 = '   Usage:'
  676.       use3 = '   'file' [/a /1 /2 /3 /n<map.htm> /-<def...>] <filemask> [...] '
  677.       use4 = '     /a: scan all disk drives                       '
  678.       use5 = '     /1: one HTML page for all files (default)      '
  679.       use6 = '     /2: one HTML page per drive                    '
  680.       use7 = '     /3: one HTML page per directory                '
  681.       use8 = '     /n: name of root page (default: dirmap.htm)    '
  682.       use9 = '     /-: drives which are not to be scanned         '
  683.      use10 = '   Examples:                                        '
  684.      use11 = '   'file' c:\netscape\cache\*.*htm?                     '
  685.      use12 = '   'file' /a /3 /-ij *.*htm? *.gif *.jp*g               '
  686.    END
  687. RETURN 
  688.  
  689. /* Output strings according to current country code                      */
  690. SetLangue: PROCEDURE expose lval crlf rootfile drvfile dirfile,
  691.             actdrive actdir javascr pars. d. i
  692.  
  693.    PARSE ARG out
  694.    IF Pos('49',lval,1) = 1 THEN DO 
  695.       SELECT 
  696.        WHEN out = 1 THEN 
  697.       CALL CharOut, 'Suche nach '
  698.        WHEN out = 2 THEN
  699.           CALL CharOut, ' auf Laufwerk '
  700.        WHEN out = 3 THEN
  701.           CALL CharOut, 'Fehler beim Zugriff auf Laufwerk '
  702.        WHEN out = 4 THEN
  703.           CALL CharOut rootfile, '<H1>Snapshot der vorhandenen',
  704.            'Dateien</H1>'||crlf
  705.        WHEN out = 5 THEN
  706.           CALL CharOut, ' Datei(en) gefunden '
  707.        WHEN out = 6 THEN
  708.           CALL CharOut, ' Sekunden.'||crlf
  709.        WHEN out = 7 THEN
  710.           CALL CharOut rootfile, '<H3>Verwendete Dateimaske(n): '
  711.        WHEN out = 8 THEN
  712.           CALL CharOut, ' wird überschrieben.'||crlf||crlf
  713.        WHEN out = 9 THEN
  714.           CALL CharOut, ' Keine Dateimaske angegeben.'||crlf
  715.        WHEN out = 10 THEN 
  716.       CALL CharOut, 'Datei existiert bereits: '
  717.        WHEN out = 11 THEN 
  718.       CALL CharOut, 'Fehler beim Öffnen von '
  719.        WHEN out = 12 THEN 
  720.       CALL CharOut, ' Unbekannte(r) Kommandozeilenschalter: '
  721.        WHEN out = 13 THEN 
  722.       CALL CharOut, 'Dateien: '
  723.        WHEN out = 14 THEN 
  724.       CALL CharOut, ' und Verzeichnisse: '
  725.        WHEN out = 15 THEN DO
  726.           IF javascr = 1 THEN DO
  727.               j1 = ' onMouseOver="window.status='||"'"||"Übersicht",
  728.               "der Dateien dieses Verzeichnisses"||" ';return true"||'" '
  729.               j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  730.               java1 = j1||j2
  731.               CALL CharOut drvfile, '<P><A'java1'HREF="'dirfile'">'actdir'</A>'
  732.           END
  733.           ELSE
  734.               CALL CharOut drvfile, '<P><A HREF="'dirfile'">'actdir'</A>'
  735.        END
  736.        WHEN out = 16 THEN
  737.       CALL CharOut, 'geschrieben in '
  738.        WHEN out = 17 THEN DO
  739.           IF javascr = 1 THEN DO
  740.               j1 = ' onMouseOver="window.status='||"'"||"Übersicht",
  741.               "der Laufwerke"||" ';return true"||'" '
  742.               j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  743.               java1 = j1||j2
  744.               CALL CharOut drvfile, '[<A'java1'HREF="'rootfile'">Zurück',
  745.                'zur Übersicht</A>]'
  746.           END
  747.           ELSE
  748.               CALL CharOut drvfile, '[<A HREF="'rootfile'">Zurück',
  749.                'zur Übersicht</A>]'
  750.        END
  751.        WHEN out = 18 THEN DO
  752.           IF javascr = 1 THEN DO
  753.              j1 = ' onMouseOver="window.status='||"'"||,
  754.               "Verzeichnisübersicht dieses Laufwerks",
  755.                ||" ';return true"||'" '
  756.              j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  757.              java1 = j1||j2
  758.              CALL CharOut rootfile, '<P><A'java1'HREF="'drvfile||,
  759.               '">Laufwerk 'actdrive'</A></P>'crlf
  760.           END
  761.           ELSE
  762.               CALL CharOut rootfile, '<P><A HREF="'drvfile'">Laufwerk',
  763.                actdrive'</A></P>'crlf
  764.        END
  765.        WHEN out = 19 THEN DO
  766.           IF javascr = 1 THEN DO
  767.              j1 = ' onMouseOver="window.status='||"'"||"Übersicht",
  768.              "der Laufwerke"||" ';return true"||'" '
  769.              j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  770.              java1 = j1||j2
  771.              j3 = ' onMouseOver="window.status='||"'"||,
  772.               "Verzeichnisübersicht dieses Laufwerks",
  773.                ||" ';return true"||'" '
  774.              j4 = 'onMouseOut="window.status='||"' '"||';return true" '
  775.              java2 = j3||j4
  776.              CALL CharOut dirfile, '[<A'java1' HREF="'rootfile'">Zurück',
  777.               'zur Übersicht</A>] [<A'java2' HREF="'drvfile||,
  778.               '">Zurück zum aktuellen Laufwerk</A>]'          
  779.           END
  780.           ELSE
  781.               CALL CharOut dirfile, '[<A HREF="'rootfile'">Zurück',
  782.                'zur Übersicht</A>] [<A HREF="'drvfile'">Zurück',
  783.                'zum aktuellen Laufwerk</A>]'
  784.        END
  785.        WHEN out = 20 THEN
  786.           CALL CharOut, crlf'Bearbeite Laufwerk 'actdrive||crlf
  787.        WHEN out = 21 THEN
  788.           CALL MakeHeader drvfile 'Laufwerk 'actdrive
  789.        WHEN out = 22 THEN
  790.           CALL MakeHeader dirfile 'Verzeichnis 'actdir
  791.        WHEN out = 23 THEN
  792.           CALL CharOut drvfile, '<H3>Verwendete Dateimaske(n): '
  793.        WHEN out = 24 THEN DO
  794.           IF javascr = 1 THEN DO
  795.               j1 = ' onMouseOver="window.status='||"'"||,
  796.                 "Gehe zu Laufwerk "||d.i||" ';return true"||'" '
  797.               j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  798.               java1 = j1||j2
  799.               CALL CharOut rootfile, '[<A'java1' HREF="#'||d.i||,
  800.                  '">Laufwerk '||d.i||'</A>] '
  801.           END
  802.           ELSE DO
  803.               CALL CharOut rootfile, '[<A HREF="#'||d.i||'">Laufwerk '||,
  804.                 d.i||'</A>] '
  805.           END
  806.        END 
  807.       END
  808.    END
  809.    ELSE DO 
  810.       SELECT 
  811.        WHEN out = 1 THEN
  812.           CALL CharOut, 'Searching for '
  813.        WHEN out = 2 THEN
  814.           CALL CharOut, ' on drive '
  815.        WHEN out = 3 THEN
  816.           CALL CharOut, 'Error accessing drive '
  817.        WHEN out = 4 THEN
  818.           CALL CharOut rootfile, '<H1>Snapshot of files found</H1>'||crlf
  819.        WHEN out = 5 THEN
  820.           CALL CharOut, ' file(s) found in '
  821.        WHEN out = 6 THEN
  822.           CALL CharOut, ' seconds.'||crlf
  823.        WHEN out = 7 THEN
  824.           CALL CharOut rootfile, '<H3>File mask(s) used: '
  825.        WHEN out = 8 THEN
  826.           CALL CharOut, ' will be overwritten.'||crlf||crlf
  827.        WHEN out = '9' THEN
  828.           CALL CharOut, ' No file mask given.'||crlf
  829.        WHEN out = '10' THEN 
  830.           CALL CharOut, 'File already exists: '
  831.        WHEN out = '11' THEN 
  832.       CALL CharOut, 'Error opening file '
  833.        WHEN out = '12' THEN 
  834.       CALL CharOut, ' Unknown commandline switch(es): '
  835.        WHEN out = '13' THEN 
  836.       CALL CharOut, 'Files: '
  837.        WHEN out = '14' THEN 
  838.       CALL CharOut, ' and directories: '
  839.        WHEN out = '15' THEN DO
  840.           IF javascr = 1 THEN DO
  841.               j1 = ' onMouseOver="window.status='||"'"||"Overview",
  842.               "of the files in this directory"||" ';return true"||'" '
  843.               j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  844.               java1 = j1||j2
  845.               CALL CharOut drvfile, '<P><A'java1'HREF="'dirfile'">'actdir'</A>'
  846.           END
  847.           ELSE
  848.               CALL CharOut drvfile, '<P><A HREF="'dirfile'">'actdir'</A>'
  849.        END
  850.        WHEN out = '16' THEN 
  851.       CALL CharOut, 'written in '
  852.        WHEN out = '17' THEN DO
  853.           IF javascr = 1 THEN DO
  854.               j1 = ' onMouseOver="window.status='||"'"||"Overview",
  855.               "of drives"||" ';return true"||'" '
  856.               j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  857.               java1 = j1||j2
  858.               CALL CharOut drvfile, '[<A'java1'HREF="'rootfile'">Back to',
  859.                'content overview</A>]'
  860.           END
  861.           ELSE
  862.               CALL CharOut drvfile, '[<A HREF="'rootfile'">Back to',
  863.                'content overview</A>]'
  864.        END
  865.        WHEN out = '18' THEN DO
  866.           IF javascr = 1 THEN DO
  867.              j1 = ' onMouseOver="window.status='||"'"||,
  868.               "Directory overview of this drive",
  869.                ||" ';return true"||'" '
  870.              j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  871.              java1 = j1||j2
  872.              CALL CharOut rootfile, '<P><A'java1'HREF="'drvfile||,
  873.               '">Drive 'actdrive'</A></P>'crlf
  874.           END
  875.           ELSE
  876.               CALL CharOut rootfile, '<P><A HREF="'drvfile'">Drive',
  877.                actdrive'</A></P>'crlf
  878.        END
  879.        WHEN out = '19' THEN DO
  880.           IF javascr = 1 THEN DO
  881.              j1 = ' onMouseOver="window.status='||"'"||"Overview",
  882.              "of drives"||" ';return true"||'" '
  883.              j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  884.              java1 = j1||j2
  885.              j3 = ' onMouseOver="window.status='||"'"||,
  886.               "Directory overview of this drive",
  887.                ||" ';return true"||'" '
  888.              j4 = 'onMouseOut="window.status='||"' '"||';return true" '
  889.              java2 = j3||j4
  890.              CALL CharOut dirfile, '[<A'java1' HREF="'rootfile'">Back to',
  891.               'content overview</A>] [<A'java2' HREF="'drvfile||,
  892.               '">Back to current drive</A>]'          
  893.           END
  894.           ELSE
  895.               CALL CharOut dirfile, '[<A HREF="'rootfile'">Back to',
  896.                'content overview</A>] [<A HREF="'drvfile'">Back to',
  897.                'current drive</A>]'
  898.        END
  899.        WHEN out = '20' THEN
  900.           CALL CharOut, crlf'Processing drive 'actdrive||crlf
  901.        WHEN out = '21' THEN
  902.           CALL MakeHeader drvfile 'Drive 'actdrive
  903.        WHEN out = '22' THEN
  904.           CALL MakeHeader dirfile 'Directory 'actdir
  905.        WHEN out = 23 THEN
  906.           CALL CharOut drvfile, '<H3>File mask(s) used: '
  907.        WHEN out = 24 THEN DO
  908.           IF javascr = 1 THEN DO
  909.               drive = substr(d.i,1,1)
  910.               j1 = ' onMouseOver="window.status='||"'"||,
  911.                 "Go to drive "||drive||" ';return true"||'" '
  912.               j2 = 'onMouseOut="window.status='||"' '"||';return true" '
  913.               java1 = j1||j2
  914.               CALL CharOut rootfile, '[<A'java1' HREF="#'||d.i||,
  915.                  '">drive '||d.i||'</A>] '
  916.           END
  917.           ELSE DO
  918.               CALL CharOut rootfile, '[<A HREF="#'||d.i||'">drive '||,
  919.                 d.i||'</A>] '
  920.           END
  921.        END
  922.       END 
  923.    END
  924. RETURN 
  925.  
  926. /* Puts return code from SysFileDelete into human language               */
  927. /* and chooses output depending on actual language code                  */
  928. Rsp_SysFileDelete: PROCEDURE expose lval
  929.    PARSE ARG ret_code
  930.    IF Pos('49',lval,1) = 1 THEN DO 
  931.       SELECT 
  932.        WHEN ret_code = 0 THEN RETURN 
  933.        WHEN ret_code = 2 THEN 
  934.           SAY 'Fehler. Datei nicht gefunden.'
  935.        WHEN ret_code = 3 THEN 
  936.           SAY 'Pfad bereits gelöscht. (Fehler. Pfad nicht gefunden)'
  937.        WHEN ret_code = 5 THEN 
  938.           SAY 'Fehler. Zugriff verweigert.'
  939.        WHEN ret_code = 26 THEN 
  940.           SAY 'Fehler. Kein DOS-Datenträger.'
  941.        WHEN ret_code = 32 THEN 
  942.           SAY 'Fehler. Konflikt bei gemeinsamem Zugriff.'
  943.        WHEN ret_code = 36 THEN 
  944.           SAY 'Fehler. Überlauf im Puffer für gemeinsamen Zugriff.'
  945.        WHEN ret_code = 87 THEN 
  946.           SAY 'Fehler. Ungültiger Parameter.'
  947.        WHEN ret_code = 206 THEN 
  948.           SAY 'Fehler. Dateiname oder -erweiterung zu lang.'
  949.        OTHERWISE SAY 'Unbekannter Fehler beim Löschen einer Datei.'
  950.       END
  951.       SAY ''
  952.    END
  953.    ELSE DO 
  954.       SELECT 
  955.        WHEN ret_code = 0 THEN RETURN 
  956.        WHEN ret_code = 2 THEN 
  957.           SAY 'Error. File not found.'
  958.        WHEN ret_code = 3 THEN 
  959.           SAY 'Path already deleted. (Error. Path not found.)'
  960.        WHEN ret_code = 5 THEN 
  961.           SAY 'Error. Access denied.'
  962.        WHEN ret_code = 26 THEN 
  963.           SAY 'Error. Not DOS disk.'
  964.        WHEN ret_code = 32 THEN 
  965.           SAY 'Error. Sharing violation.'
  966.        WHEN ret_code = 36 THEN 
  967.           SAY 'Error. Sharing buffer exceeded.'
  968.        WHEN ret_code = 87 THEN 
  969.           SAY 'Error. Invalid parameter'
  970.        WHEN ret_code = 206 THEN 
  971.           SAY 'Error. Filename exceeds range error'
  972.        OTHERWISE SAY 'Unknown error when deleting file.'
  973.       END
  974.       SAY ''
  975.    END
  976. RETURN
  977.   
  978.