home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / fasort.lzh / fasort.cmd < prev    next >
OS/2 REXX Batch file  |  1993-08-29  |  2KB  |  99 lines

  1. /*
  2.                              Fasort.cmd
  3.                              August 29, 1993
  4.                              Kim Bergman
  5.  
  6. File Areas Sort.
  7.  
  8. Alphabetizes lines in files.bbs.  Reads fasort.cfg to obtain a list of
  9. directories.  Each directory should have a files.bbs that needs occassional
  10. sorting.  Strips EOF too.
  11.  
  12. */
  13. "@echo off"
  14. say " "
  15.  
  16. arg nexdir switch
  17.  
  18. if nexdir="" then do
  19.    configfil="fasort.cfg"
  20.    j=lines(configfil)
  21.    if j=0 then do
  22.     say " "
  23.     say "Fasort.cmd error:  Can't read Fasort.cfg, aborting."
  24.     say " "
  25.     exit
  26.    end
  27.  
  28.    do while lines(configfil)>0
  29.     nexdir=linein(configfil)
  30.     if left(nexdir,1)<>"%" then do
  31.       call sortit nexdir
  32.     end
  33.    end /* do */
  34.    j=stream(configfil,c,"close")
  35. end
  36. else do
  37.    call sortit nexdir
  38. end  /* Do */
  39.  
  40. if nexdir<>"/N" & switch<>"/N" then fbp.exe
  41. say "Fasort.cmd done."
  42. exit
  43.  
  44. sortit:  procedure
  45.  
  46. /* Accepts the fullpathname to a directory containing a files.bbs as the
  47. only parameter, sorts the files.bbs into ascending order, strips EOF char 
  48. if exists */
  49.  
  50. arg profilnam       /* the path to the directory that has the files.bbs */
  51.  
  52. tempfile=profilnam||"\tempfile.txt"
  53. profilnam=profilnam||"\files.bbs"
  54. say "Sorting "||profilnam
  55.  
  56. j=lines(tempfile)
  57. if j>0 then do
  58.  j=stream(tempfile,c,"close")
  59.  del tempfile
  60. end
  61.  
  62. i=0
  63. j=lines(profilnam)
  64. do while j>0                     /* if file is not empty then read it into array  */
  65.   i=i+1
  66.   curlin.i=linein(profilnam)
  67.  j=lines(profilnam)
  68. end                                /*  while j>0 read file into array   */
  69.  
  70. j=stream(profilnam,c,"close")
  71.  
  72. /* sort the array with bubble sort */
  73. do until sorted="TRUE"
  74.  sorted="TRUE"
  75.   do k=1 to (i-1)
  76.    j=k+1
  77.    if curlin.k>curlin.j then do
  78.     temp=curlin.k
  79.     curlin.k=curlin.j
  80.     curlin.j=temp
  81.     sorted="FALSE"
  82.    end  /* if curlin.k>curlin.k+1  */
  83.   end /* do  k=1 to (i-1) */
  84. end                                 /* do until sorted=true */
  85.  
  86.  
  87. do k=1 to i
  88.  r=lineout(tempfile,curlin.k)
  89. end
  90.  
  91. r=stream(tempfile,c,"close")
  92. del profilnam
  93. ren tempfile files.bbs
  94.  
  95. return
  96.  
  97.  
  98.  
  99.