home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / readsum.zip / SORTSUM.CMD < prev    next >
OS/2 REXX Batch file  |  1994-12-18  |  5KB  |  147 lines

  1. /* rexx */
  2. /*
  3. Date: 12/17/94 - version 1
  4. Author: Jamie Hoglund
  5. Contact: jhoglund@cscns.com
  6.          70244,3234@compuserve.com
  7. Script: 1/3
  8.  
  9.  use this script to sort and pre-process summary files created
  10.  by the uqwk offline reader program.
  11.  
  12.  This script and MakeSel.CMD are Non-interactive, therefore, they may 
  13.  safely be "Detached". This is why there are 3 seperate scripts, and not
  14.  1 main script.
  15.  
  16.  
  17. -------------------------------------------------------------------------
  18.          Note: Configuration can be done by editing this file.
  19.                Use your editors "Search" function to search for
  20.                lines that have the string: "@CFG" in them.
  21. -------------------------------------------------------------------------
  22.  
  23.  Adjust SortPgm as needed for your system,
  24.  
  25.  This isn't effecient code, it'll take a while to run...
  26.   Note: The OS/2 default sort program can only handle
  27.        files 63k in size, you may need a differen't sort
  28.        program than the default if you intend to work with
  29.        larger files.
  30.  
  31. Dll's required: None!
  32.  
  33. Bugs:
  34.   Very large summaries, summaries containing more than 10 newsgroups
  35.   tend to confuse the display program.
  36.  
  37.                         --File Formats--
  38. GroupFil: Seek position ^ Tagged ^ Newsgroup name CRLF
  39.  
  40. Seek Position is the file position the subject lines begin at.
  41.  
  42. Tagged is a string of "0", The length of this string = the number of
  43.   Articles. Any position in the string that is "1" = Tagged article:
  44.   Length("00010010") = 8 articles, fourth & seventh article is tagged.
  45.   Length("001000000") = 9 articles, Article #3 is tagged.
  46.  
  47.   The purpose of this is to store the tag pointers, for re-starting the
  48.   Program, you don't have to re-tag the subjects, (Other utilities
  49.   that auto-tag/untag  articles can use this)
  50.  
  51. Newsgroup name = The actual name for the newsgroup.
  52.  
  53. SortFil: NewsgroupNumber \0x0FE Article Subject(Re\0xFD:) \0x0FE Article number
  54.  
  55. \0x0FE ■ = 254 separates group number from group name
  56.   The purpose of translating delimiters is two-fold, The newsgroup Number
  57.   is used to tell the sort program to sort in newsgroup order, and as a
  58.   relation to the newsgroup name.
  59.  
  60. \0x0FD ² = 253 Used to denote that this is a "Re: subject
  61.   The Purpose of mangling the "Re: " is for the sort program. (otherwise all
  62.   the RE:'s are sorted under 'R') Please Note that Re appears at the end of 
  63.   the Subject line.
  64.  
  65. Newsgroup Number is a five digit number, preceeded by zero's.
  66. This is for the sort program.
  67.       
  68. */
  69.  
  70. /* Configuration information */
  71. TempFil = "tempFil.tmp"     /* Temporary file                    @CFG*/
  72. SortFil = "SortFil.Tmp"     /* this is the sorted output file    @CFG*/
  73. SortPgm = "sort"            /* _program_ used to sort text files @CFG*/
  74. GroupFil  = "Groups.Tmp"    /* file containing current groups    @CFG*/
  75.  
  76. Buf = Arg(1)
  77. Parse Var Buf Infil OutFil Garbage
  78.  
  79. /* display help screen */
  80. If Length(Infil) = 0 then
  81.   Signal helpme
  82.  
  83. Say "Organizing file, this can take a while, please wait..."
  84.  
  85. /* Delete old files */
  86. IF LENGTH(STREAM(TempFil,"C","QUERY EXISTS")) > 0 then
  87.  '@DEL 'TempFil                  /* OS Dependent          @CFG */
  88. IF LENGTH(STREAM(GroupFil,"C","QUERY EXISTS")) > 0 then
  89.  '@DEL 'GroupFil                 /* OS Dependent          @CFG */
  90. IF LENGTH(STREAM(SortFil,"C","QUERY EXISTS")) > 0 then
  91.  '@DEL 'SortFil                  /* OS Dependent          @CFG */
  92.  
  93.  
  94. /* Mangle the file, for the sort program */
  95. Grp = 0
  96. Do until Lines(Infil) = 0
  97.    Buf = Linein(Infil)
  98.    If Length(Buf) = 0 then
  99.      Iterate
  100.    if Left(Buf,1) = "*" then do  /* put group name in groups. array */
  101.        Grp = Grp + 1
  102.        Groups.Grp = buf
  103.        Articles.1.grp = 0
  104.        Articles.2.grp = "0"Stream(TempFil,"C","seek") /* get seek position */
  105.        Iterate
  106.    end  
  107.    Buf = Translate(Buf," :",": ")
  108.    Parse var buf Num Data 
  109.    If Translate(Word(Data,1)) = "RE" then do  /* handle Re: subjects */
  110.      Parse var Data R Data
  111.      Data = Data":Re"D2C(253)" "
  112.    end
  113. /* replace spaces with an unlikely 8-bit byte, for later parse */
  114.  Call LineOut TempFil,Right(Grp,5,"0")||D2C(254)||Translate(Data,": "," :")||D2C(254)||Num
  115.  Articles.1.Grp = Articles.1.Grp + 1
  116. end 
  117.  
  118. /* sort the file, format is GroupNumber,Subject,MessageNumber */
  119. '@'SortPgm' <'TempFil' >'SortFil  /* OS dependent command @CFG */
  120.  Call Stream TempFil,"C","Close"
  121. '@del 'TempFil                    /* OS Dependent command @CFG */
  122.  
  123. /* output a list of groups 
  124. SeekPosition ^ Number of lines ^ newsgroup name
  125. */
  126. DO I = 1 to Grp
  127.    /* tagged is a string of 0's representing the tagged articles. */
  128.    tagged = COPIES("0",articles.1.i)
  129.    Buf = Articles.2.I" "Tagged" "STRIP(TRANSLATE(Groups.I," ","*"))
  130.    Call Lineout GroupFil,Buf
  131. end 
  132. Call Stream GroupFil,"C","Close"
  133. Exit
  134.  
  135. exit
  136. HelpMe:
  137. Say ""
  138. Say "Use this script to sort [process] summary files created by uqwk"
  139. SAy ""
  140. SAy "Usage:"
  141. SAy "Sortsum Summary "
  142. Say ""
  143. Say "Summary - File generated by Uqwk"
  144. SAy ""
  145. exit
  146.  
  147.