home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 115 / af115sub.adf / SystemGuides.lzx / DevGuide / Device_Search.rexx < prev    next >
OS/2 REXX Batch file  |  1998-06-03  |  7KB  |  281 lines

  1. /*
  2. **---------------------------------------
  3. ** 
  4. ** Device_Search.rexx V1.2 - 14.11.96
  5. **
  6. ** Search Devices.guide for keywords
  7. **
  8. ** © 1996 Heiko Schröder         e-mail: age@thepentagon.com
  9. ** You need LIBS: RexxTricks.library
  10. **
  11. ** Inspirations by Tassos Hadjithmomaoglou
  12. ** AMIL_Search.rexx V0.3  © 1995
  13. **
  14. **----------------------------------------
  15. ** $VER: Device_Search.rexx  V1.2 (14-Nov-96)
  16. **----------------------------------------
  17. **
  18. */
  19.  
  20. /*
  21. ** Path for Viewer
  22. **
  23. ** Enter here the full path of an AmigaGuide Viewer of your choice
  24. ** That's the only thing you should change
  25. */
  26.  
  27. Viewer = 'SYS:Utilities/MultiView'
  28.  
  29. /*
  30. ** Please don't change anything after this line
  31. **----------------------------------------------
  32. */
  33.  
  34. OPTIONS RESULTS
  35.  
  36. SIGNAL ON BREAK_C
  37. SIGNAL ON SYNTAX
  38.  
  39. TRUE=1
  40. FALSE=0
  41.  
  42. R="0A"X
  43. say "SearchIn»Devive.guide« V1.2 - © Heiko Schröder - 14.11.96 -"||R
  44. IF ~show('L',"rexxtricks.library") then do
  45.    IF ~addlib('rexxtricks.library',0,-30,0) then do
  46.       say "Sorry, but I need the rexxtricks.library in LIBS: ..."
  47.       say "Copy it from Libs-Drawer in this directory"
  48.       say "to your LIBS: directory."||R
  49.       SAY "Press »Return« to end."
  50.       PARSE PULL Keyword
  51.       exit
  52.       exit
  53.    end
  54. end
  55.  
  56. /*
  57. ** Check for Devices.guide in current directory 
  58. ** If Devices.guide is found then open it, else inform the user
  59. */
  60.  
  61. bool1=OPEN(AMIL_file,'Devices.guide',"R")
  62.  
  63. IF bool1 = FALSE THEN
  64. DO
  65.    SAY '"Devices.guide" wasn''t found in the current directory.'
  66.    SAY "Press »Return« to end."
  67.    PARSE PULL Keyword
  68.    EXIT
  69. END
  70. AMIL_Path = 'DevGuide:Devices.guide'
  71.  
  72. /*
  73. ** Check for argument, else ask for one
  74. */
  75.  
  76. PARSE ARG Keyword
  77.  
  78. IF Keyword = '' THEN
  79. DO
  80.    SAY 'Please input word to search for: (without wildcards) '
  81.    PARSE PULL Keyword
  82.    IF Keyword = '' THEN
  83.    DO
  84.       SAY 'Search abandoned !!!'
  85.       EXIT 0
  86.    END
  87. END
  88.  
  89. SAY d2c(11)||'Searching for "'Keyword'"...'
  90.  
  91. /*
  92. ** Initialize variables
  93. */
  94.  
  95. Counter = 0
  96. Node_Line = 0
  97. Keyword_Line = 0
  98. Node_Name = ''
  99. AMIL_Line = ''
  100.  
  101. /*
  102. ** Create the Device_Search.guide
  103. */
  104.  
  105. if exists("c:search") then do
  106.    address command "c:search >T:node search @node Devices.guide"
  107.    address command "c:search >T:word search "d2c(34)||Keyword||d2c(34)" Devices.guide"
  108. end
  109. else do
  110.    say "Sorry, but i need program »SEARCH« in the C: drawer!"||R
  111.    SAY "Press »Return« to end."
  112.    PARSE PULL Keyword
  113.    exit
  114. end
  115.  
  116. say "Creating the guide... Wait one second..."
  117.  
  118. open("test","T:word")
  119. a=readln("test")
  120. if eof("test") then call Ende
  121. close("test")
  122. ReadFile("T:node","liste")            /*Read the T:node in Stem-Variable*/
  123. ReadFile("T:word","wordl")            /*Read the T:word in Stem-Variable*/
  124.  
  125. if wordl.0="0" then
  126.    say "The "||Keyword||" was not found in Devices.guide!"
  127. else do
  128.    bool1=OPEN(Search_file,'T:Devices_Search.guide',W)
  129.  
  130.    WRITELN(Search_file,'@database Device_Search')
  131.    WRITELN(Search_file,'@node "Main" "Device_Search V1.2  - 14.11.96 - by Heiko Schröder"')
  132.    WRITELN(Search_file,'')
  133.    WRITELN(Search_file,' The word "@{fg fill}'Keyword'@{fg text}" was found in the following lines:')
  134.    WRITELN(Search_file,'')
  135.  
  136.    i=1
  137.    z=1
  138.    do while 1
  139.       ist1  = liste.i
  140.       ist   = Value(Compress(DelStr(ist1,7)))         /*Linenumber of @node*/
  141.       n=i+1
  142.       next1 = liste.n
  143.       next  = Value(Compress(DelStr(next1,7)))        /*Linenumber of next @node*/
  144.       zeile1= wordl.z
  145.       zeile = Value(Compress(DelStr(zeile1,7)))       /*Linenumber of Keyword*/
  146.  
  147.       if next=0 then next=zeile+1                     /*found KeyWord after last @node*/
  148.  
  149.       if ist>zeile then do                            /*found KeyWord before @node*/
  150.          z=z+1                                        /*next KeyWord*/
  151.       end
  152.  
  153.       if zeile>next then do                           /*found KeyWord after next @node*/
  154.          i=i+1                                        /*next @node*/
  155.       end
  156.  
  157.       if ist<=zeile & zeile<=next then do             /*KeyWord between two @node s*/
  158.          AMIL_Line = ist1                             /*read @node*/
  159.          s1 = DELSTR(DELSTR(AMIL_Line,1,7),1,7)
  160.          Node_Name = DELSTR(s1,INDEX((s1),'"'))
  161.          Node_Line = ist
  162.  
  163.          Search_Line = Delstr(zeile1,1,7)             /*read KeyWord*/
  164.          IF (LEFT(Search_Line,1) ~= '@') | (LEFT(Search_Line,2) = '@{') THEN
  165.          DO
  166.             Counter=Counter+1
  167.             Keyword_Line = zeile - Node_Line
  168.             wo=Index(Upper(Search_Line),Upper(KeyWord))
  169.             l=Length(Keyword)
  170.             vor=DelStr(Search_Line,wo)
  171.             nach=DelStr(Search_Line,1,wo+l-1)
  172.             AMIL_Search_Line = '@{"*" link "DevGuide:Devices.guide/'Node_Name'" 'Keyword_Line'} 'vor||'@{fg shine}'||KeyWord||'@{fg text}'||nach
  173.             WRITELN(Search_File,AMIL_Search_Line||R||COPIES('-',77))
  174.          END
  175.          z=z+1                                /*next KeyWord*/
  176.          if z>wordl.0 then leave              /*end, if no more KeyWord was found*/
  177.       end
  178.    end
  179. end
  180.  
  181. WRITELN(Search_file,"I have found "||Counter||" possibilities.")
  182.  
  183. WRITELN(Search_file,"@endnode")
  184.  
  185.  
  186. /*
  187. ** Close both files
  188. */
  189. bool1=CLOSE(AMIL_file)
  190. bool1=CLOSE(Search_file)
  191.  
  192. /*
  193. ** Check for Viewer or MultiView/AmigaGuide
  194. */
  195.  
  196. bool1 = EXISTS(Viewer)
  197. IF bool1 = FALSE THEN
  198. DO
  199.    SAY Viewer 'wasn''t found.'
  200.    SAY 'Trying MultiView/AmigaGuide...'
  201.    bool1 = EXISTS('SYS:Utilities/MultiView')
  202.    IF bool1 = FALSE THEN
  203.    DO
  204.       bool1 = EXISTS('SYS:Utilities/AmigaGuide')
  205.       IF bool1 = FALSE THEN
  206.       DO
  207.          SAY 'MultiView/AmigaGuide weren''t found in SYS:Utilities !!!'
  208.          EXIT
  209.       END
  210.       ELSE
  211.       DO
  212.          Viewer = 'SYS:Utilities/AmigaGuide'
  213.       END
  214.    END
  215.    ELSE
  216.    DO
  217.       Viewer = 'SYS:Utilities/MultiView'
  218.    END
  219. END
  220.  
  221. /*
  222. ** View the results from the search
  223. */
  224.  
  225. SAY 'Running 'Viewer'...'||R
  226. ADDRESS COMMAND 'Run >NIL: <NIL:' Viewer 'T:Devices_Search.guide'
  227. SAY "Press »Return« to end."
  228. PARSE PULL Keyword
  229. ADDRESS COMMAND 'Delete T:Devices_Search.guide QUIET'
  230. ADDRESS COMMAND 'Delete T:node QUIET'
  231. ADDRESS COMMAND 'Delete T:word QUIET'
  232. ADDRESS COMMAND 'Assign DevGuide: REMOVE'
  233.  
  234. EXIT 0
  235.  
  236. /*
  237. ** End of ARexx script
  238. */
  239. Ende:
  240.    say "Sorry, but »"||KeyWord||"« was not found."||R
  241.    close("test")
  242.     ADDRESS COMMAND 'Delete T:node QUIET'
  243.     ADDRESS COMMAND 'Delete T:word QUIET'
  244.    SAY "Press »Return« to end."
  245.    PARSE PULL Keyword
  246.    ADDRESS COMMAND 'Assign DevGuide: REMOVE'
  247.    EXIT
  248.  
  249. /*
  250. ** Handle the Error condition
  251. */
  252.  
  253. SYNTAX:
  254.     bool1=CLOSE(AMIL_file)
  255.     bool1=CLOSE(Search_file)
  256.     ADDRESS COMMAND 'Delete T:Devices_Search.guide QUIET'
  257.     ADDRESS COMMAND 'Delete T:node QUIET'
  258.     ADDRESS COMMAND 'Delete T:word QUIET'
  259.     SAY R||'Error at line' SIGL ':' ERRORTEXT(RC)
  260.     SAY 'Please report it to the author'||R
  261.    SAY "Press »Return« to end."
  262.    PARSE PULL Keyword
  263.    ADDRESS COMMAND 'Assign DevGuide: REMOVE'
  264.     EXIT
  265.  
  266. /*
  267. ** Handle the Control C command given by the user
  268. */
  269.  
  270. BREAK_C:
  271.     bool1=CLOSE(AMIL_file)
  272.     bool1=CLOSE(Search_file)
  273.     ADDRESS COMMAND 'Delete T:Devices_Search.guide QUIET'
  274.     ADDRESS COMMAND 'Delete T:node QUIET'
  275.     ADDRESS COMMAND 'Delete T:word QUIET'
  276.     SAY 'Search aborted...'||R
  277.    SAY "Press »Return« to end."
  278.    PARSE PULL Keyword
  279.    ADDRESS COMMAND 'Assign DevGuide: REMOVE'
  280.     EXIT
  281.