home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / bclean.zip / bclean.cmd
OS/2 REXX Batch file  |  1995-10-06  |  6KB  |  174 lines

  1. /* Yes FOLKS!  This is ReXX ! */
  2.  
  3. /* This batch file 'cleans' Binkley style outbound,         */
  4. /* removes empty NN.PNT and empty Outbound.ZZZ dirs, where  */
  5. /* ZZZ are any hexadecimal numbers, and NN must be eight    */
  6. /* digit long hexadecimal number.                           */
  7. /*                                                          */
  8. /* Author:                                                  */
  9. /* Radim Kolar             Fidonet: 2:423/66.111            */
  10. /*                         Dark side of Avalon              */
  11. /*                                                          */
  12. /* Errorlevels:                                             */
  13. /*       0 success                                          */
  14. /*       2 home directory doesn't exists                    */
  15. /*       3 out of memory                                    */
  16. /*      10 bad arguments count                              */
  17. /*                                                          */
  18. /* Version 0.30.011 FREEWARE                                */
  19. /*                                                          */
  20. /* Rev. history:                                            */
  21. /*                                                          */
  22. /* 08/08/95        development started                      */
  23. /* 10/08/95        0.10.000 done, first working version     */
  24. /*                 limitations: don't check .PNT dirs for   */
  25. /*                              hexadecimal numbers in name */
  26. /* 17/08/95        0.11.006 done, added help text           */
  27. /* 20/08/95        0.20 done, fixed very stupid bug in      */
  28. /*                 loading and unloading RexxUtil.Dll       */
  29. /*                 0.21   improved Dll (re)loading code     */
  30. /*                 0.30   check *.PNT directories, if dir   */
  31. /*                          name is valid (hexnumbers)      */
  32. /*                        also corrected error, when home   */ 
  33. /*                          dir was root                    */
  34. /*                        improved docs                     */
  35. /*                        Limitations: None                 */
  36. /*  I hope, that this is final version                      */              
  37.           
  38. Version='Version 0.30.011'
  39. Progname='REXX Binkley Outbound cleaner'
  40. Copyright='Copyright (C) Radim Kolar 1995. (Fidonet 2:423/66.111)'
  41. Copyright2='This program is free to use without any modifications only.'
  42.  
  43. START:
  44. select
  45.   when 0=RXFuncQuery('SysDropFuncs') then udrop=0
  46.   when 0=RxFuncAdd("SysLoadFuncs", "RexxUtil", "SysLoadFuncs") then udrop=1
  47.   otherwise
  48.   /* something may be wrong, reload all Package */
  49.   say 'Reloading REXXUtil Package.'
  50.   RXFuncDrop("SysLoadFuncs")
  51.   RxFuncAdd("SysLoadFuncs", "RexxUtil", "SysLoadFuncs")
  52.   call SysLoadFuncs;
  53.   udrop=0
  54. end
  55.  
  56. if udrop=1 then call SysLoadFuncs
  57.  
  58. parse upper arg home dname
  59.  
  60. say Progname
  61. say Version
  62. say Copyright
  63. say Copyright2
  64. say
  65.  
  66. /* parse test */
  67.  
  68. if (length(home)=0)|(length(dname)=0)|(POS(' ',dname)>0) then call helptext;
  69. tst=directory(home)
  70. if (length(tst)=0) then do
  71.    say 'Directory: 'home' does not exists.'
  72.    call cleanup 2
  73.    end
  74.  
  75. /* scan for Outbound.ZZZ and process them */
  76.  
  77. rc=SysFileTree(dname'*','list','DO')
  78. if rc=2 then do
  79.  say 'Not enough memory'
  80.  call cleanup 3
  81.  end
  82. do i=1 to list.0
  83.   if pos('\',home)=length(home) then
  84.     call BOClean substr(list.i,length(tst)+1,length(list.i)-length(tst))
  85.                                 else
  86.     call BOClean substr(list.i,length(tst)+2,length(list.i)-length(tst)-1)
  87.  
  88. end
  89.  
  90. /* End of Main part */
  91.  
  92. say
  93. say 'bclean.cmd' Version 'done.'
  94.  
  95. call cleanup 0
  96.  
  97. /* Procedures BEGINS */
  98.  
  99. helptext: procedure expose udrop
  100.   say 'Bclean.cmd cleans your binkley-style outbound directory tree.'
  101.   say 'Bclean works in 4 steps.'
  102.   say '1) if OUTBOUND.ZZZ has good name (ZZZ=hex number), bclean goes in.'
  103.   say '2) removes all empty AAA.PNT directories.'
  104.   say '   where AAA is 8-digit long hexadecimal number.'
  105.   say '3) repeats steps 1 and 2, until all OUTBOUND.* dirs are checked.'
  106.   say '4) removes all empty OUTBOUND.ZZZ directories, where ZZZ is any hexadecimal'
  107.   say '   number.'
  108.   say
  109.   say 'Bclean.cmd requires two parameters:'
  110.   say 'first parameter is name of ''root'' binkley directory, directory where'
  111.   say '  primary binkley outbound resides in.'
  112.   say '2nd is name of outbound.ZZZ directories (without .ZZZ extension)'
  113.   say 
  114.   say 'Example:'
  115.   say 'Your primary binkley outbound directory is E:\T-MAIL\OUTBOUND'
  116.   say 'then simply run:'
  117.   say '  bclean.cmd e:\t-mail outbound'
  118.   call cleanup 10
  119. return
  120.  
  121. cleanup: procedure expose udrop
  122.    arg n
  123.    if udrop=1 then call SysDropFuncs
  124.    exit n
  125. return
  126.  
  127. testname: procedure
  128.    arg name
  129.    a=pos('.',name)
  130.    if a=0 then return 1
  131.    do i=a+1 to length(name)
  132.      if POS(substr(name,i,1),'0123456789ABCDEF')=0 then return 0
  133.    end
  134. return 1
  135.  
  136. testpnt: procedure
  137.    arg name
  138.    a=pos('.',name)
  139.    if a\=9 then return 0 /* short of long directory name */
  140.    do i=1 to 8
  141.      if POS(substr(name,i,1),'0123456789ABCDEF')=0 then return 0
  142.    end
  143.    call SysRmDir name
  144. return 1
  145.  
  146.  
  147. /* if name is Good, Clean it! */
  148. BOClean: procedure
  149.    arg dir
  150.    if testname(dir)=1 then do
  151.                             tmpdir=directory()
  152.                             call directory(dir)
  153.                             tst=directory()
  154.                             say 'Processing 'tst
  155.                             call PNTdel dir,tst
  156.                             call directory(tmpdir)
  157.                             if pos('.',dir)>0 then call SysRmDir dir
  158.                            end
  159.  
  160. return
  161.  
  162. /* removes all *.PNT in dir */
  163. PNTdel: procedure
  164. arg dir,tst
  165.  rc=SysFileTree('*.PNT','list','DO')
  166.  if rc=2 then do
  167.    say 'Not enough memory'
  168.    call cleanup 3
  169.  end
  170. do i=1 to list.0
  171.   call testpnt substr(list.i,length(tst)+2,length(list.i)-length(tst)-1) 
  172. end
  173.  
  174. return