home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 1 / amigaformatcd01.iso / pd / database / fiasco_1.1 / databases / faqs / searchfaqs.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-04-30  |  6.4 KB  |  266 lines

  1. /* SearchFaqs.rexx
  2.  * Copyright © 1995-1996 Nils Bandener
  3.  * Requires "Most" by Uwe Röhm
  4.  * Tested with Most v1.56
  5.  * $VER: searchfaqs.rexx 3.5 (18.1.96)
  6.  */
  7.  
  8. Options Results
  9. Address FIASCO
  10.  
  11. Signal on Syntax
  12. Signal on Halt
  13. Signal on Break_C
  14. Signal on Failure
  15.  
  16. F_LockGUI
  17.  
  18. Say "Search for:"
  19. Pull pat
  20.  
  21. Say "Start at record no.:"
  22. Pull start
  23.  
  24. F_RequestChoice '"Which records do you want to be searched?"' '"All|Marked only"'
  25.  
  26. if Result = 0 then
  27.     Monly = 1
  28. else
  29.     Monly = 0
  30.  
  31. F_RequestChoice '"Write Results to File?"' '"Yes|No"'
  32.  
  33. if Result = 1 then
  34.     WriteFile = 1
  35. else
  36.     WriteFile = 0
  37.  
  38. if WriteFile = 1 then do
  39.  
  40.     F_RequestFile Savemode
  41.  
  42.     if rc ~= 0 then do
  43.  
  44.         F_UnlockGUI
  45.  
  46.         exit
  47.  
  48.     end
  49.  
  50.     FName = Result
  51.  
  52.     if ~Open("o", FName, "write") then do
  53.  
  54.         F_RequestChoice '"Couldn`t open file"' '"Cancel"'
  55.  
  56.         F_UnlockGUI
  57.  
  58.         exit
  59.  
  60.     end
  61.  
  62. end
  63.  
  64. F_RequestChoice '"Interactive Searching?"' '"Yes|No"'
  65.  
  66. if Result = 1 then
  67.     Interact = 1
  68. else
  69.     Interact = 0
  70.  
  71. F_CountRecs
  72. num = Result
  73.  
  74. say "Searching... (Ctrl-C for break)"
  75.  
  76. /* F_SetStatus "Searching..." */
  77.  
  78. if start > num then start = 1
  79. if start < 1 then start = 1
  80.  
  81. do i = start to num
  82.  
  83.    Address FIASCO
  84.  
  85.    /* F_Progress i num */
  86.  
  87.    F_GotoRec i
  88.  
  89.    F_IsMarked i
  90.  
  91.    if (Monly = 1 & rc = 0) | (Monly = 0) then do
  92.  
  93.        F_GetFieldCont "File"
  94.        file = Result
  95.  
  96.        Address Command 'search >t:found' '"' || file || '"' '"' || pat '"'
  97.  
  98.        if rc = 0 then do
  99.  
  100.            if open("f", "t:found", "read") then do
  101.  
  102.                 if ~eof("f") then do
  103.  
  104.                     say "*****" file ":"
  105.                     if Writefile = 1 then call writeln("o", "*****" file ":")
  106.  
  107.                     /* If SkipAd = 1, no Requester will be put up */
  108.  
  109.                     skipad = 0
  110.  
  111.                     do while ~eof("f")
  112.  
  113.                         ln = readln("f")
  114.  
  115.                         say ln
  116.  
  117.                         if Writefile = 1 then call writeln("o", ln)
  118.  
  119.                         if interact = 1 & skipad = 0 then do
  120.  
  121.                             Parse var ln Line Rest
  122.  
  123.                             if length(line) > 0 then do
  124.  
  125.                                 Address FIASCO
  126.  
  127.                                 rest = compress(rest, '"*')
  128.                                 if length(rest) > 75 then rest = left(rest, 75)
  129.  
  130.                                 F_RequestChoice '"Found Pattern in File*n' || file || '*nLine ' || Line || '*n' || Rest || '"' '"Display|Next occurence|Next file|Break"'
  131.  
  132.                                 if Result = 1 then do
  133.  
  134.                                     found = 0
  135.                                     retry = 0
  136.  
  137.                                     do while found = 0
  138.  
  139.                                         retry = retry + 1
  140.  
  141.                                         if ~show(ports, "MOST.0") then do
  142.  
  143.                                             address command
  144.                                             "run most" file
  145.                                             "sys:rexxc/waitforport MOST.0"
  146.                                         end
  147.  
  148.                                         if show(ports, "MOST.0") then do
  149.  
  150.                                             Address MOST.0
  151.  
  152.                                             GetFileList
  153.                                             FileList = Result
  154.  
  155.                                             k = 1
  156.  
  157.                                             do while k <= words(FileList) & found = 0
  158.  
  159.                                                 filepos = lastpos("/", file)
  160.                                                 if filepos = 0 then filepos = lastpos(":", file)
  161.                                                 if filepos ~= 0 then filepos = filepos + 1
  162.  
  163.                                                 if upper(word(FileList, k)) = upper(substr(file,filepos)) then do
  164.  
  165.                                                     found = 1
  166.  
  167.                                                     /* Skip Strings like 1/1 */
  168.                                                     if pos("/", word(FileList, k + 1)) ~= 0 then k = k + 1
  169.  
  170.                                                     host = word(FileList, k + 1)
  171.  
  172.                                                     Interpret "Address" host
  173.                                                     tofront
  174.  
  175.                                                 end
  176.  
  177.                                                 k = k + 2
  178.                                             end
  179.  
  180.                                             if found = 0 then do
  181.  
  182.                                                 if retry = 1 then do
  183.                                                     address command
  184.  
  185.                                                     "run sys:rexxc/rx runmost" file
  186.                                                 end
  187.                                                 else if retry = 2 | retry = 3 then do
  188.                                                     address command
  189.  
  190.                                                     wait 1 sec
  191.                                                 end
  192.                                                 else break
  193.  
  194.                                             end
  195.                                         end
  196.                                     end
  197.  
  198.                                     if found = 1 then do
  199.  
  200.                                         Interpret "Address" host
  201.  
  202.                                         goto 'line' line
  203.                                     end
  204.                                 end
  205.                                 else if Result = 3 then do
  206.  
  207.                                     skipad = 1
  208.  
  209.                                 end
  210.                                 else if Result = 0 then do
  211.  
  212.                                     call close("f")
  213.  
  214.                                     if Writefile = 1 then call close("o")
  215.  
  216.                                     Address FIASCO
  217.  
  218.                                     F_UnlockGUI
  219.  
  220.                                     F_ResetStatus
  221.  
  222.                                     exit
  223.  
  224.                                 end
  225.                             end
  226.                         end
  227.  
  228.                     end
  229.                 end
  230.  
  231.                 call close("f")
  232.  
  233.            end
  234.         end
  235.    end
  236. end
  237.  
  238. if Writefile = 1 then do
  239.  
  240.     call close("o")
  241.  
  242. end
  243.  
  244. F_UnlockGUI
  245. F_ResetStatus
  246.  
  247. exit
  248.  
  249. Syntax:
  250. Failure:
  251. say "Error" rc "in line" sigl ":" errortext(rc)
  252. say file pat
  253.  
  254. Halt:
  255. Break_C:
  256.  
  257. Address FIASCO
  258.  
  259. F_UnlockGUI
  260. F_ResetStatus
  261.  
  262. say "Break"
  263.  
  264. exit
  265.  
  266.