home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / fat.cmd next >
OS/2 REXX Batch file  |  1999-04-29  |  3KB  |  168 lines

  1. /* Converting all files to FAT name rules */
  2. /* (c) K. Gebhardt, 1997 - 1999 */
  3.  
  4. '@echo off'
  5.  
  6. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  7. call SysLoadFuncs
  8.  
  9. 'SETLOCAL'
  10. 'SET DELDIR='
  11.  
  12.  
  13. /* The sed script ... */
  14. fatsed = directory() || "\fat.sed";
  15.  
  16.  
  17. /* Load the file fat.sed ... */
  18. call LoadFatSed
  19.  
  20.  
  21. /* Find all sub directories ... */
  22. call SysFileTree "*",subdirs,'DSO'
  23.  
  24. /* Rename the directories ... */
  25. call MaybeRenameDirs
  26.  
  27.  
  28. /* Find all sub directories and patch the files. */
  29. call SysFileTree "*",subdirs,'DSO'
  30.  
  31. call PatchScriptFiles "."
  32.  
  33. do i = 1 to subdirs.0
  34.   call PatchScriptFiles subdirs.i
  35. end
  36.  
  37. exit
  38.  
  39.  
  40.  
  41. LoadFatSed: procedure expose fatsed oldname. newname.
  42.  
  43. rc = stream(fatsed,'C','open read');
  44.  
  45. if (rc <> 'READY:') then
  46.   do
  47.     rc = stream(fatsed,'C','open read');
  48.  
  49.     if (rc <> 'READY:') then
  50.       do
  51.     say 'error: Cannot open' fatsed || '!'
  52.     exit;
  53.       end
  54.   end
  55.  
  56. cnt = 0;
  57.  
  58. do while(lines(fatsed))
  59.   line = linein(fatsed);
  60.  
  61.   if (line <> '') then
  62.     do
  63.       parse var line 's/' old '/' new '/g'
  64.  
  65.       cnt = cnt+1;
  66.       oldname.cnt = old;
  67.       newname.cnt = new;
  68.     end
  69. end
  70.  
  71. oldname.0 = cnt;
  72. newname.0 = cnt;
  73.  
  74. rc = stream(fatsed,'C','close');
  75. return;
  76.  
  77.  
  78.  
  79. FindName: procedure expose oldname.
  80. parse arg name
  81.  
  82. do i = 1 to oldname.0
  83.   if (filespec('n',name) == oldname.i) then return i;
  84. end
  85.  
  86. return 0;
  87.  
  88.  
  89.  
  90. DirDepth: procedure
  91. parse arg dirname
  92.  
  93. depth = 0;
  94.  
  95. p = pos("\",dirname);
  96.  
  97. do while (p > 0)
  98.   depth = depth+1;
  99.   p = pos("\",dirname,p+1);
  100. end
  101.  
  102. return depth;
  103.  
  104.  
  105.  
  106. MaybeRenameDirs: procedure expose subdirs. oldname. newname.
  107.  
  108. maxDepth = 0;
  109.  
  110. do i = 1 to subdirs.0
  111.   depth.i = DirDepth(subdirs.i)
  112.   if (depth.i > maxDepth) then maxDepth = depth.i
  113. end
  114.  
  115. do j = maxDepth to 0 by -1
  116.   do i = 1 to subdirs.0
  117.     if (depth.i == j) then
  118.       do
  119.     p = FindName(subdirs.i);
  120.  
  121.     if (p > 0) then
  122.       do
  123.         say 'info: renaming' subdirs.i 'to' newname.p
  124.         'ren' subdirs.i newname.p
  125.       end
  126.       end
  127.   end
  128. end
  129.  
  130. return;
  131.  
  132.  
  133.  
  134. PatchScriptFiles: procedure expose fatsed oldname. newname.
  135. parse arg dirname
  136.  
  137. say '*** Entering' dirname
  138. olddir = directory(dirname);
  139.  
  140. call SysFileTree "*.m",scripts,"FO"
  141.  
  142. do i = 1 to scripts.0
  143.   scrName = filespec("n",scripts.i);
  144.   octName = substr(scripts.i,1,length(scripts.i)-2);
  145.  
  146.   p = FindName(octname);
  147.  
  148.   if (p == 0) then
  149.     do
  150.       tmpname = scrName || ".tmp";
  151.  
  152.       say 'info: patching' scrName
  153.       'ren' scrName tmpname
  154.       'sed -f' fatsed tmpname '>' scrName
  155.       'del' tmpname '>NUL'
  156.     end
  157.   else
  158.     do
  159.       say 'info: patching' scrName 'and renaming to' newname.p || ".m"
  160.       'sed -f' fatsed scrName '>' newname.p || ".m"
  161.       'del' scrName '>NUL'
  162.     end
  163. end
  164.  
  165. say '*** Leaving' dirname
  166. call directory olddir
  167. return
  168.