home *** CD-ROM | disk | FTP | other *** search
/ Dr. CD ROM (Annual Premium Edition) / premium.zip / premium / IBMOS2_2 / PCD221.ZIP / PCD.CMD < prev    next >
OS/2 REXX Batch file  |  1993-10-18  |  5KB  |  201 lines

  1. /***********************************
  2.  *  Paddy's Change Directory v2.21 *
  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.     
  89.     devices=SysDriveMap()
  90.     wordnum=1
  91.     scaned=0
  92.  
  93.     device=subword(devices, wordnum, 1)
  94.  
  95.     do while (\(device=""))
  96.       bla=SysFileTree(device'\', 'dirs', 'DSO')
  97.       bla=SysFileDelete(index)
  98.  
  99.       do i=1 to dirs.0
  100.         bla=lineout(index, dirs.i)
  101.         if (bla=1) then do
  102.           say "Error generating "index". Program terminated."
  103.           exit
  104.         end
  105.       end
  106.       wordnum=wordnum+1
  107.       scaned=scaned+i
  108.       device=subword(devices, wordnum, 1)
  109.     end
  110.  
  111.     say scaned" Directories scaned."
  112.   end
  113.  
  114.   when (arg1="MD") & (\(arg2="")) then do
  115.     say "Making Directory "arg2"..."
  116.     bla=SysMkDir(arg2)
  117.     if (\(bla=0)) then
  118.       say "It's not possible to create "arg2" (Error="bla")."
  119.     else do
  120.       bla=SysFileTree(arg2, 'dirs', 'DO')
  121.  
  122.       bla=lineout(index, dirs.1)
  123.       if (bla=1) then do
  124.         say "Error updating "index". Program terminated."
  125.       exit
  126.       end
  127.     end
  128.   end
  129.  
  130.   when (arg1="RD") & (\(arg2="")) then do
  131.     say "Deleting Directory "arg2"..."
  132.     bla=SysFileTree(arg2, 'dirs', 'DO')
  133.     if ((\(bla=0)) | (dirs.0=0)) then do
  134.       say "Directory "arg2" does not exist. Program terminated."
  135.       exit
  136.     end
  137.     
  138.     bla=SysRmDir(arg2)
  139.     if (\(bla=0)) then do
  140.       say "It's not possible to remove "arg2" (Error="bla"). Program terminated."
  141.       exit
  142.     end
  143.  
  144.     bla=SysFileSearch(dirs.1, index, 'lines', 'CN')
  145.     if (\(bla=0)) then do
  146.       say "Error updating "index". Program terminated."
  147.       exit
  148.     end
  149.     
  150.     line=subword(lines.1, 1, 1)
  151.     bla=SysFileDelete(indext)
  152.         
  153.     i=1
  154.     do while (lines(index))
  155.       bla=linein(index)
  156.       if (bla='BLA') then do
  157.         say "Error reading "index". Program terminated."
  158.         exit
  159.       end
  160.  
  161.       if (\(i=line)) then do
  162.         bla=lineout(indext, bla)
  163.         if (bla=1) then do
  164.           say "Error generating new "index". Program terminated."
  165.           exit
  166.         end
  167.       end
  168.       i=i+1         
  169.     end
  170.   bla=stream(index, "c", "close")
  171.   bla=stream(indext, "c", "close")
  172.  
  173.   "@copy "indext index '2>nul >nul'
  174.  
  175.   bla=SysFileDelete(indext)
  176.   end
  177.  
  178.   when (\(arg1 = "")) then do
  179.     '@cd "'arg1'" 2> nul'
  180.     if (\(rc=0)) then do
  181.       "@"pcdcmp index arg1 "2>"outpath
  182.       bla=linein(outpath)
  183.       if (\(bla="")) then do
  184.         drive=substr(bla, 1, 2)
  185.         "@"drive
  186.         '@cd "'bla'" 2> nul'
  187.         if (\(rc=0)) then do
  188.           say "Error changing to "bla". Program terminated."
  189.           exit
  190.         end
  191.       end
  192.       bla=stream(outpath, "c", "close")
  193.       bla=SysFileDelete(outpath)
  194.     end
  195.   end
  196.  
  197.   otherwise
  198.   "@"pcdcmp "copyright"
  199. end
  200. exit
  201.