home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / rexxtag2.zip / Tag.Frx < prev   
Text File  |  1996-01-23  |  7KB  |  195 lines

  1. /* * *
  2.  *
  3.  *    Simple Tagline Adder      v1.32\F - 1996-01-23
  4.       FleetStreet version (ask me for the standalone version)
  5.  
  6.       (c) Copyright 1995, Peter Karlsson, 2:204/137.5 @ Fidonet       *
  7.                                                                       *
  8.                                                                   * * */
  9.  
  10. /* Versions: 1.0 (1995-06-15)
  11.              1.1 (1995-06-28) Added "Q" option, uses #0 for brag
  12.              1.2 (1995-07-17) Removed bug when searching for tagline
  13.              1.3 (1995-10-29) Now the bug when searching should be gone :)
  14.              1.31(1995-11-02) Well, it should now.......
  15.              1.32(1996-01-23) I hate the searching bug                     */
  16.  
  17. version = '1.32'
  18.  
  19. /*TRACE ?I*/
  20.  
  21. SIGNAL ON HALT NAME Exit
  22.  
  23. /* Change these parameters to suite your setup */
  24.  
  25. Indexfile = 'd:\modem\darkwing\INDEX.FIL'       /* Tagline index file */
  26. Taglinefile = 'd:\modem\darkwing\TAGLINE.LST'   /* Tagline list file */
  27.  
  28. IF FSCls() = 'NoMonitor' THEN
  29. DO
  30.   CALL RxFuncAdd 'RxMessageBox', 'RexxUtil', 'RxMessageBox'
  31.   CALL RxMessageBox 'You must run this script with an open monitor windows', 'No monitor window', 'OK', 'ERROR'
  32.   EXIT 3
  33. END
  34.  
  35. CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  36. CALL RxFuncAdd 'SysCls', 'RexxUtil', 'SysCls'
  37.  
  38. IF STREAM(Taglinefile, 'C', 'QUERY EXISTS') = '' THEN
  39. DO
  40.   SAY 'The specified tagline file ' || Taglinefile || ' could not be found.'
  41.   SAY
  42.   SAY 'Please check the setup'
  43.   EXIT 1
  44. END
  45.  
  46. TagfSize = STREAM(Taglinefile, 'C', 'QUERY SIZE')
  47.  
  48. IF STREAM(Indexfile, 'C', 'QUERY EXISTS') = '' THEN
  49. DO
  50.   SAY 'The specified tagline index file ' || Indexfile || ' could not be found.'
  51.   SupposedSize = -1
  52. END
  53. ELSE
  54. DO
  55.   IF STREAM(Indexfile, 'C', 'OPEN READ') \= 'READY:' THEN
  56.   DO
  57.     SAY 'ERROR: Could not open index file ' || Indexfile || '.'
  58.     SAY
  59.     SAY 'File may be locked by another process.'
  60.     EXIT 2
  61.   END
  62.   SupposedSize = LINEIN(Indexfile)        /* Read supposed size of tagfile */
  63. END
  64.  
  65. If SupposedSize \= TagfSize THEN        /* Supposed size do not match actual */
  66. DO
  67.   SAY 'Tagline index is not accurate, building new index'
  68.   CALL STREAM Indexfile, 'C', 'CLOSE'
  69.   IF SupposedSize \= -1 THEN
  70.     IF SysFileDelete(Indexfile) \= 0 THEN
  71.     DO
  72.       SAY 'ERROR: Could not delete the index file ' || Indexfile || '.'
  73.       SAY
  74.       SAY 'File may be locked by another process.'
  75.       EXIT 2
  76.     END
  77.   IF STREAM(Taglinefile, 'C', 'OPEN READ') \= 'READY:' THEN
  78.   DO
  79.     SAY 'ERROR: Could not open tagline file ' || Taglinefile || '.'
  80.     SAY
  81.     SAY 'File may be locked by another process.'
  82.     EXIT 2
  83.   END
  84.   Lines = 1
  85.   SAY 'Building index, please wait. This may take a while.'
  86.   DO WHILE LINES(Taglinefile)
  87.     Index.Lines = TagfSize - CHARS(Taglinefile) /* Index to line */
  88.     Data = LINEIN(Taglinefile)
  89.     IF LEFT(Data, 1) \= ';' & STRIP(Data) \= '' THEN Lines = Lines + 1
  90.   END
  91.   CALL STREAM Taglinefile, 'C', 'CLOSE'
  92.   IF STREAM(Indexfile, 'C', 'OPEN WRITE') \= 'READY:' THEN
  93.   DO
  94.     SAY 'ERROR: Could not create new index file ' || Indexfile || '.'
  95.     SAY
  96.     SAY 'File may be locked by another process.'
  97.     EXIT 2
  98.   END
  99.   CALL LINEOUT Indexfile, TagfSize      /* Save current filesize */
  100.   CALL LINEOUT Indexfile, Lines         /* Save number of lines */
  101.   DO print = 1 TO Lines-1
  102.     CALL LINEOUT Indexfile, Index.print  /* Save indexes */
  103.   END
  104.   CALL STREAM Indexfile, 'C', 'CLOSE'
  105. END
  106. ELSE
  107. DO                                      /* Read the correct index */
  108.   SAY 'Reading index, please wait. This may take a while.'
  109.   Lines = LINEIN(Indexfile)
  110.   DO read = 1 TO Lines-1
  111.     Index.read = LINEIN(Indexfile)
  112.   END read
  113.   CALL STREAM Indexfile, 'C', 'CLOSE'
  114. END
  115. Index.Lines = TagfSize
  116. SAY
  117. SAY 'Tagline file has ' || Lines-1 || ' entries.'
  118. IF STREAM(Taglinefile, 'C', 'OPEN READ') \= 'READY:' THEN
  119. DO
  120.   SAY 'ERROR: Could not open tagline file ' || Taglinefile || '.'
  121.   SAY
  122.   SAY 'File may be locked by another process.'
  123.   EXIT 2
  124. END
  125. satisfied = 'N'
  126. number = RANDOM(Lines-1)                /* Starting random tagline */
  127. CALL FsCls                              /* Clear window */
  128. SAY 'Tagline selector. Press [Y] when you are satisfied, [N] if not. [-] will get'
  129. SAY 'the previous tagline, [+] the next. [#] Lets you enter a number and [O] seeks'
  130. SAY 'for a word after the current tagline. [Q] to not add a tagline.'
  131. SAY
  132. SAY '==============================================================================='
  133. DO UNTIL (satisfied = 'Y' | satisfied = 'Q')
  134.   IF number = 0 THEN
  135.   DO
  136.     Tagline = 'Brought to you by TAG.FRX v' || version || ' (c) 1995 Peter Karlsson'
  137.     CALL STREAM Taglinefile, 'C', 'SEEK =' || (Index.1)+1       /* Position */
  138.   END
  139.   ELSE
  140.   DO
  141.     CALL STREAM Taglinefile, 'C', 'SEEK =' || (Index.number)+1  /* Position */
  142.     Tagline = LINEIN(Taglinefile)       /* Read the tagline */
  143.   END
  144.   SAY number || ': ' || Tagline
  145.   satisfied = ''
  146.   DO UNTIL satisfied = 'Y' | satisfied = 'N' | satisfied = '-' | satisfied = '+' | satisfied = 'O' | satisfied = '#'
  147.     PULL satisfied
  148.   END
  149.   IF satisfied = 'N' THEN number = RANDOM(Lines-1)      /* New random select */
  150.   IF satisfied = '+' THEN number = number + 1           /* Previous tagline */
  151.   IF satisfied = '-' THEN number = number - 1           /* Next tagline */
  152.   IF satisfied = '#' THEN
  153.   DO
  154.     SAY '[#] Jump to which tagline? ( 0-' || Lines-1 ')'
  155.     PULL number                         /* Select tagline by number */
  156.   END
  157.   IF satisfied = 'O' THEN
  158.   DO
  159.     SAY '[O] Search for what word?'
  160.     PULL word
  161.     nextnumb = number + 1
  162.     CALL STREAM Taglinefile, 'C', 'SEEK =' || (Index.nextnumb)+1 /* Position */
  163.     DO search = number+1 TO Lines-1     /* Search subsequent lines for tagline */
  164.       Tagline = TRANSLATE(LINEIN(Taglinefile))
  165.       IF POS(word, Tagline) \= 0 THEN LEAVE
  166.     END search
  167.     IF search = Lines THEN              /* The loop did run until end */
  168.       SAY 'Could not find the word "' || word || '"!'
  169.     ELSE
  170.       number = search                   /* Select the found tagline */
  171.   END
  172. END
  173. CALL STREAM Taglinefile, 'C', 'CLOSE'   /* Close it, we have read the tagline */
  174. If satisfied = 'Q' THEN EXIT
  175. DROP Index.                             /* We do not need the indexes anymore */
  176. Tearline = 0
  177. DO search = 1 TO FleetMsg.Text.0        /* Search for a tear line */
  178.   IF LEFT(FleetMsg.Text.search, 4) = '--- ' THEN
  179.     Tearline = search
  180. END search
  181. IF Tearline = 0 THEN                    /* No tearline */
  182.   FleetMsg.Text.search = '... ' || Tagline
  183. ELSE
  184. DO                                      /* Tearline was found */
  185.   DO move = (FleetMsg.Text.0)+1 TO Tearline BY -1       /* Move text down */
  186.     from = move - 1
  187.     FleetMsg.Text.move = FleetMsg.Text.from
  188.   END move
  189.   FleetMsg.Text.Tearline = '... ' || Tagline    /* Insert tagline */
  190. END
  191. FleetMsg.Text.0 = (FleetMsg.Text.0) + 1
  192. CALL FsSetText('FleetMsg.Text')
  193. Exit:
  194. SAY 'Finished'
  195.