home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / pcd231.zip / PCD.CMD < prev    next >
OS/2 REXX Batch file  |  1993-11-07  |  5KB  |  212 lines

  1. /***********************************
  2.  *  Paddy's Change Directory v2.31 *
  3.  ***********************************/
  4.  
  5.  
  6. parse arg arg1 arg2
  7.  
  8. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  9. call SysLoadFuncs
  10.  
  11. parse upper var arg1 arg1 bla
  12.  
  13.  
  14.  
  15. err=0
  16. pcdcmp=SysIni(, 'PCD', 'pcdcmp')
  17. if (pcdcmp='ERROR:') then err=err+1
  18. index=SysIni(, 'PCD', 'index')
  19. if (index='ERROR:') then err=err+1
  20. indext=SysIni(, 'PCD', 'indext')
  21. if (indext='ERROR:') then err=err+1
  22. outpath=SysIni(, 'PCD', 'outpath')
  23. if (outpath='ERROR:') then err=err+1
  24.  
  25. if ((\(err=0)) | (arg1 = "/INIT")) then do
  26.   say "You have to initialize PCD."
  27.   say "Enter the path of pcdcmp.exe (e.g. d:\tools\pcd)"
  28.   pull pcdcmp
  29.   helppath=pcdcmp
  30.   pcdcmp=pcdcmp"\pcdcmp.exe"
  31.   bla=charin(pcdcmp, 1, 1)
  32.   blabla=stream(pcdcmp, "c", "close")
  33.   if (bla='') then do
  34.     say "Path "helppath" is illegal. Program terminated."
  35.     exit
  36.   end
  37.  
  38.   say "Enter the path of the indexfile of PCD (e.g. c:)"
  39.   pull index
  40.   bla=SysFileTree(index, 'dirs', 'DO')
  41.   if (dirs.0=0) then do
  42.     say "Path "index" is illegal. Program terminated."
  43.     exit
  44.   end
  45.  
  46.   say "Enter the path of the temporary indexfile (e.g. c:)"
  47.   pull indext
  48.   bla=SysFileTree(indext, 'dirs', 'DO')
  49.   if (dirs.0=0) then do
  50.     say "Path "indext" is illegal. Program terminated."
  51.     exit
  52.   end
  53.  
  54.   say "Enter the path of the temporary file of pcdcmp.exe (e.g. c:)"
  55.   pull outpath
  56.   bla=SysFileTree(outpath, 'dirs', 'DO')
  57.   if (dirs.0=0) then do
  58.     say "Path "outpath" is illegal. Program terminated."
  59.     exit
  60.   end
  61.  
  62.   index=index"\pcd.idx"
  63.   indext=indext"\pcd.tmp"
  64.   outpath=outpath"\pcd-path.tmp"
  65.  
  66.   SysIni(, 'PCD')
  67.   SysIni(, 'PCD', 'pcdcmp', pcdcmp)
  68.   SysIni(, 'PCD', 'index', index)
  69.   SysIni(, 'PCD', 'indext', indext)
  70.   SysIni(, 'PCD', 'outpath', outpath)
  71.  
  72.   say
  73.   say "OS2.INI updated."
  74.  
  75.   exit
  76. end
  77.  
  78.  
  79. select
  80.   when arg1 = "/CLEAR" then do
  81.     SysIni(, 'PCD')
  82.     say
  83.     say "PCD entries in OS2.INI deleted."
  84.     exit
  85.   end
  86.  
  87.   when arg1 = "/SCAN" then do
  88.     if (arg2="") then
  89.       devices=SysDriveMap()
  90.     else do
  91.       do while (\(arg2==""))
  92.         if (devices=="DEVICES") then
  93.           devices=substr(arg2, 1, 1)": "
  94.         else
  95.           devices=devices""substr(arg2, 1, 1)": "
  96.         arg2=substr(arg2, 2)
  97.       end
  98.       devices=translate(delstr(devices,length(devices)))
  99.     end
  100.  
  101.     wordnum=1
  102.     scanned=0
  103.  
  104.     device=subword(devices, wordnum, 1)
  105.  
  106.     do while (\(device=""))
  107.       bla=SysFileTree(device'\', 'dirs', 'DSO')
  108.       bla=SysFileDelete(index)
  109.  
  110.       do i=1 to dirs.0
  111.         bla=lineout(index, dirs.i)
  112.         if (bla=1) then do
  113.           say "Error generating "index". Program terminated."
  114.           exit
  115.         end
  116.       end
  117.       wordnum=wordnum+1
  118.       scanned=scanned+i-1
  119.       device=subword(devices, wordnum, 1)
  120.     end
  121.  
  122.     say scanned" directories scanned. ("devices")"
  123.   end
  124.  
  125.   when (arg1="MD") & (\(arg2="")) then do
  126.     say "Making Directory "arg2"..."
  127.     bla=SysMkDir(arg2)
  128.     if (\(bla=0)) then
  129.       say "It's not possible to create "arg2" (Error="bla")."
  130.     else do
  131.       bla=SysFileTree(arg2, 'dirs', 'DO')
  132.  
  133.       bla=lineout(index, dirs.1)
  134.       if (bla=1) then do
  135.         say "Error updating "index". Program terminated."
  136.       exit
  137.       end
  138.     end
  139.   end
  140.  
  141.   when (arg1="RD") & (\(arg2="")) then do
  142.     say "Removing Directory "arg2"..."
  143.     bla=SysFileTree(arg2, 'dirs', 'DO')
  144.     if ((\(bla=0)) | (dirs.0=0)) then do
  145.       say "Directory "arg2" does not exist. Program terminated."
  146.       exit
  147.     end
  148.     
  149.     bla=SysRmDir(arg2)
  150.     if (\(bla=0)) then do
  151.       say "It's not possible to remove "arg2" (Error="bla"). Program terminated."
  152.       exit
  153.     end
  154.  
  155.     bla=SysFileSearch(dirs.1, index, 'lines', 'CN')
  156.     if (\(bla=0)) then do
  157.       say "Error updating "index". Program terminated."
  158.       exit
  159.     end
  160.     
  161.     line=subword(lines.1, 1, 1)
  162.     bla=SysFileDelete(indext)
  163.         
  164.     i=1
  165.     do while (lines(index))
  166.       bla=linein(index)
  167.       if (bla='BLA') then do
  168.         say "Error reading "index". Program terminated."
  169.         exit
  170.       end
  171.  
  172.       if (\(i=line)) then do
  173.         bla=lineout(indext, bla)
  174.         if (bla=1) then do
  175.           say "Error generating new "index". Program terminated."
  176.           exit
  177.         end
  178.       end
  179.       i=i+1         
  180.     end
  181.   bla=stream(index, "c", "close")
  182.   bla=stream(indext, "c", "close")
  183.  
  184.   "@copy "indext index '2>nul >nul'
  185.  
  186.   bla=SysFileDelete(indext)
  187.   end
  188.  
  189.   when (\(arg1 = "")) then do
  190.     '@cd "'arg1'" 2> nul'
  191.     if (\(rc=0)) then do
  192.       "@"pcdcmp index arg1 translate(arg2) "2>"outpath
  193.       bla=linein(outpath)
  194.       if (\(bla="")) then do
  195.         drive=substr(bla, 1, 2)
  196.         "@"drive
  197.         '@cd "'bla'" 2> nul'
  198.         if (\(rc=0)) then do
  199.           say "Error changing to "bla". Program terminated."
  200.           exit
  201.         end
  202.       end
  203.       bla=stream(outpath, "c", "close")
  204.       bla=SysFileDelete(outpath)
  205.     end
  206.   end
  207.  
  208.   otherwise
  209.   "@"pcdcmp "copyright"
  210. end
  211. exit
  212.