home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / NCD.ZIP / VCD.CMD < prev    next >
OS/2 REXX Batch file  |  1993-01-28  |  7KB  |  183 lines

  1. /* ================================================================== */
  2. /* REXX VCD - A Norton Change Directory Utility for OS/2              */
  3. /* Copyright (c) 1992 Larry Wasserman.  All Rights Reserved.          */
  4. /* CompuServe  [76666,1043]                                           */
  5. /*                                                                    */
  6. /* Usage : VCD [ [/R] | [partial last node] ]                         */
  7. /* ================================================================== */
  8. SAY 'VCD ver 1.0 Copyright 1993 L. Wasserman'
  9. '@echo off'
  10. PARSE UPPER ARG var1;
  11. var1 = STRIP(var1);
  12.  
  13. /* ================================================================== */
  14. /* Check to see if all REXX utility functions have been Loaded        */
  15. /* ================================================================== */
  16. IF 0 < RxFuncQuery('SysLoadFuncs') THEN 
  17.    DO
  18.       CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'; 
  19.       CALL SysLoadFuncs; 
  20.    END;
  21. /* ================================================================== */
  22. /* Load the Virtual REXX utility functions                            */
  23. /* ================================================================== */
  24. CALL RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  25. initcode = VInit();
  26. IF initcode = 'ERROR' THEN
  27.    SIGNAL bailout;
  28. SIGNAL ON FAILURE NAME bailout
  29. SIGNAL ON HALT NAME bailout
  30. SIGNAL ON SYNTAX NAME bailout
  31. /* ================================================================== */
  32. /* Check to see if this is just a rebuild                             */
  33. /* ================================================================== */
  34. IF COMPARE(var1, '/R') = 0 THEN
  35.    DO
  36.       CALL REBUILD_TREE '\REXTREE.NCD';
  37.       SIGNAL bailout;
  38.    END
  39. /* ================================================================== */
  40. /* If REXTREE.NCD does not exist, rebuild it and open it at the top   */
  41. /* ================================================================== */
  42. myfile = STREAM('\REXTREE.NCD', 'C', 'QUERY EXISTS');
  43. IF LENGTH(myfile) = 0 THEN
  44.    DO
  45.      myfile = '\REXTREE.NCD';
  46.      CALL REBUILD_TREE myfile;
  47.      LINEIN(myfile,1,0);
  48.    END
  49.  
  50. /* ================================================================== */
  51. /* Read the Directory Tree. If the <arglen> characters of the last    */
  52. /* node = the var1 parameter, enter the entire path in an array       */
  53. /* ================================================================== */
  54. dups = 1;
  55. arglen = LENGTH(var1);
  56. DO WHILE LINES(myfile) > 0
  57.    dirpath = LINEIN(myfile);
  58.    IF arglen = 0 THEN
  59.       DO
  60.          dir.dups = dirpath;
  61.          dups = dups + 1;
  62.       END
  63.    ELSE   
  64.       DO
  65.          len = LENGTH(dirpath);
  66.          x = LASTPOS('\',dirpath);
  67.          str = RIGHT(dirpath, len - x);
  68.          strcmp = LEFT(str,arglen);
  69.          IF COMPARE(var1, strcmp) = 0 THEN 
  70.             DO
  71.                dir.dups = dirpath;
  72.                dups = dups + 1;
  73.             END
  74.       END
  75. END
  76. dups = dups - 1;
  77.  
  78. /* =================================================================== */
  79. /* If no matches were found, tell the user                             */
  80. /* =================================================================== */
  81. IF dups = 0 THEN
  82.    DO
  83.    msg.0 = 1
  84.    msg.1 = ' Directory matching 'var1 'does not exist '
  85.    CALL VDialogPos 50, 50
  86.    rb = VMsgBox('VCD', msg, 1)
  87.    SIGNAL bailout;
  88.    END
  89. /* =================================================================== */
  90. /* If only one match was found, go directly to it                      */
  91. /* =================================================================== */
  92. IF dups = 1 THEN
  93.    DO
  94.       cdstring = dir.1;
  95.       SIGNAL SWITCH;
  96.    END
  97.  
  98. /* =================================================================== */
  99. /* Show the list of duplicate matches, and find out which one to CD    */
  100. /* =================================================================== */
  101. list.0 = dups
  102. DO i = 1 to dups
  103.    list.i = dir.i;
  104.    END
  105. list.vstring = list.1          /* default selection */
  106. CALL VDialogPos 50, 0
  107. button = VListBox('Select a Directory', list, 40, 8, 3)
  108. IF button = 'CANCEL' THEN
  109.    SIGNAL bailout
  110. cdstring = list.vstring
  111.  
  112. /* ================================================================== */
  113. /* CD to the new directory, and exit                                  */
  114. /* ================================================================== */
  115. SWITCH:;
  116. '@CD' cdstring;
  117.  
  118. BAILOUT:;
  119. CALL VExit;
  120. EXIT;
  121.  
  122. REBUILD_TREE:PROCEDURE
  123. ARG myfile
  124.  
  125. SAY '';
  126. rc = CHAROUT(STDOUT, '   Building Directory Tree ');
  127.  
  128. /* =================================================================== */
  129. /* Get the list of directories on the current disk                     */
  130. /* =================================================================== */
  131. IF SysFileTree('\*.*', 'dirlst', 'DSO') > 0 THEN
  132.    DO
  133.       SAY 'Not enough memory to read the directory tree...terminating';
  134.       SIGNAL bailout;
  135.    END
  136.  
  137. /* ================================================================== */
  138. /* Sort the list of directories                                       */
  139. /* ================================================================== */
  140. iLo = 1; iHi = dirlst.0;
  141. DO FOREVER;
  142.    IF iLo > iHi THEN LEAVE;
  143.    i = iLo;
  144.    cLo = SUBSTR(dirlst.iLo,3,LENGTH(dirlst.iLo)-2)
  145.    cHi = SUBSTR(dirlst.iHi,3,LENGTH(dirlst.iHi)-2)
  146.    DO FOREVER;
  147.       IF i > iHi THEN LEAVE;
  148.       cX = SUBSTR(dirlst.i,3,LENGTH(dirlst.i)-2)
  149.       iSwap = 0;
  150.       IF cX < cLo THEN DO;
  151.          iSwap = 1;
  152.          cExch = dirlst.i; dirlst.i = dirlst.iLo; dirlst.iLo = cExch;
  153.          cLo = SUBSTR(dirlst.iLo,3,LENGTH(dirlst.iLo)-2)
  154.          cX  = SUBSTR(dirlst.i,3,LENGTH(dirlst.i)-2)
  155.       end;
  156.       IF cX > cHi THEN do;
  157.          iSwap = 1;
  158.          cExch = dirlst.i; dirlst.i = dirlst.iHi; dirlst.iHi = cExch;
  159.          cHi = SUBSTR(dirlst.iHi,3,LENGTH(dirlst.iHi)-2)
  160.          cX  = SUBSTR(dirlst.i,3,LENGTH(dirlst.i)-2)
  161.       end;
  162.       IF iSwap < 1 THEN i = i+1;
  163.    end;
  164.    iLo = iLo+1; iHi = iHi-1;
  165.    rc = CHAROUT(STDOUT, '.');
  166. end;
  167. SAY '';
  168.  
  169. /* =================================================================== */
  170. /* Open (or create) the REXTREE.NCD file and write it                  */
  171. /* =================================================================== */
  172. CALL LINEOUT myfile, dirlst.1, 1;  /* opens file and overwrites first line */
  173. DO i = 2 to dirlst.0
  174.    CALL LINEOUT myfile, dirlst.i;
  175.    IF RESULT = 1 THEN
  176.       DO
  177.          SAY 'Unable to write treefile...terminating';
  178.          SIGNAL bailout;
  179.       END
  180. END
  181. rc = LINEOUT(myfile);    /* closes file */
  182. RETURN;
  183.