home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 1 / AACD01.ISO / SearchCDs < prev    next >
Text File  |  1999-09-02  |  17KB  |  492 lines

  1. /*
  2. SearchCDs - Searches index files of Amiga Active CDs,
  3.             Aminet CDs and Aminet Online files
  4. $VER: SearchCDs 1.3 (16.8.99) (c) Neil Bothwick, Wirenet
  5. */
  6.  
  7. /* ;;; Initialise */
  8. options results
  9. signal on error
  10. VerStr = sourceline(4)
  11. VerStr = subword(VerStr,2,words(VerStr) - 4)
  12. Title   = 'SearchCDs'
  13. GuiPort = upper(Title)
  14. PrgPort = GuiPort'-PRG'
  15. WinTitle = 'Amiga Active CD Search'
  16. qt = '22'x
  17. CurrentDir = pragma('D')
  18. parse var CurrentDir CDname ':' .
  19. if left(CDName,4) ~= 'AACD' then CDname = 'AACD01'
  20. select
  21.     when right(CurrentDir,6) = 'Aminet' then DefSearch = 'Aminet Online'
  22.     when right(CurrentDir,3) = 'CDs' then DefSearch = 'Aminet CDs'
  23.     when right(CurrentDir,4) = 'Sets' then DefSearch = 'Aminet Sets'
  24.     otherwise DefSearch = 'Amiga Active CDs'
  25.     end
  26. ;;;
  27. /* ;;; Set index variables and ensure all necessary files are available */
  28. address command
  29. if ~exists('C:FlashFind') then 'copy 'CDname':C/FlashFind C: clone quiet'
  30. if exists('ENVARC:AACD/AACDIndex') then AACDPath = AddPart(GetVar('AACD/AACDIndex'),'')
  31. else AACDPath = CDname':CDTools/indices/'
  32. if exists('ENVARC:AACD/AminetCDIndex') then AminetCDPath = AddPart(GetVar('AACD/AminetCDIndex'),'')
  33. else AminetCDPath = CDname':AACD/CDROM/AminetCDs/CDs'
  34. if exists('ENVARC:AACD/AminetSetIndex') then AminetSetPath = AddPart(GetVar('AACD/AminetSetIndex'),'')
  35. else AminetSetPath = CDname':AACD/CDROM/AminetCDs/Sets/'
  36. if exists('ENVARC:AACD/AminetIndex') then AminetPath = AddPart(GetVar('AACD/AminetIndex'),'')
  37. else AminetPath = CDname':AACD/Online/Aminet/'
  38. OutFile = 'T:SearchCDs.results'
  39. ;;;
  40. /* ;;; Define MUI variables */
  41. MUIA_List_Quiet                   = 0x8042d8c7
  42. MUIM_List_Select                  = 0x804252d8
  43. MUIV_List_Select_All              = -2
  44. MUIV_List_Select_On               = 1
  45. MUIV_List_Select_Ask              = 3
  46. MUIA_List_First                   = 0x804238d4
  47. MUIM_List_Remove                  = 0x8042647e
  48. MUIV_List_Remove_Selected         = -3
  49. MUIA_List_Entries                 = 0x80421654
  50. MUIA_List_Quiet                   = 0x8042d8c7
  51. MUIA_Listview_MultiSelect         = 0x80427e08
  52. MUIV_Listview_MultiSelect_Default = 1
  53. MUIA_Gauge_Current                = 0x8042f0dd
  54. MUIA_Gauge_Divide                 = 0x8042d8df
  55. MUIA_Gauge_Horiz                  = 0x804232dd
  56. MUIA_Gauge_InfoText               = 0x8042bf15
  57. MUIA_Gauge_Max                    = 0x8042bcdb
  58. MUIA_Group_Columns                = 0x8042f416
  59. MUIA_Menuitem_Shortcut            = 0x80422030
  60. MUIA_Application_Active           = 0x804260ab
  61. MUIA_Application_Author           = 0x80424842
  62. MUIA_Application_Copyright        = 0x8042ef4d
  63. MUIA_Application_Description      = 0x80421fc6
  64. MUIA_Application_HelpFile         = 0x804293f4
  65. MUIA_Application_Iconified        = 0x8042a07f
  66. MUIA_Application_Title            = 0x804281b8
  67. MUIA_Application_Version          = 0x8042b33f
  68. MUIA_Application_Sleep            = 0x80425711
  69. MUIM_Application_AboutMUI         = 0x8042d21d
  70. TRUE = 1
  71. FALSE = 0
  72. ;;;
  73. /* ;;; Load libraries */
  74. call LoadLib('rexxsupport.library')
  75. call LoadLib('rexxdossupport.library')
  76. call LoadLib('rexxreqtools.library')
  77. ;;;
  78. /* ;;; Open arexx port and GUI */
  79. thisport = openport(PrgPort)
  80. if thisport = 0 then exit
  81. address(GuiPort)
  82. window id MAIN port PrgPort command 'QUIT' title '"'WinTitle'"'
  83.     group id ALL
  84.         group horiz attrs MUIA_Group_Columns 2
  85.             label double 'Search string'
  86.             string id SCSTR help '"Enter a string to search for"' /*content 'test'*/
  87.             label double 'CDs to search'
  88.             cycle id CDTYP port PrgPort command 'RESCAN' help '"Which types of CD do\nyou wish to search?"' labels 'Amiga Active CDs,Aminet CDs,Aminet Sets,Aminet Online'
  89.             label double 'Output format'
  90.             cycle id OPFMT help '"Choose the output format"' labels 'HTML,Text'
  91.             endgroup
  92.  
  93.         list id CDLST attrs MUIA_Listview_MultiSelect MUIV_Listview_MultiSelect_Default help '"Select the CDs to search"'
  94.         group id BTNS horiz
  95.             button id GO  port PrgPort command 'SEARCH' help '"Start the search"' label 'Search'
  96.             button id ALL port PrgPort command 'ALL' help '"Select all CDs in the list"' label 'Select All'
  97.             button id ESC port PrgPort command 'QUIT' '"Exit without searching"' label 'Cancel'
  98.             endgroup
  99.         gauge id PROGR attrs MUIA_Gauge_Horiz MUIA_Gauge_InfoText '' help '"Shows the progress of the search"' label ''
  100.         endgroup
  101.     menu id PROJM label 'Project'
  102.         item id ABOUT port PrgPort command 'ABOUT' MUIA_Menuitem_Shortcut '?' label 'About'
  103.         item id MUI   port PrgPort command 'ABOUTMUI' label 'About MUI...'
  104.         item id QUITM port PrgPort command 'QUIT'  MUIA_Menuitem_Shortcut 'Q' label 'Quit'
  105.         endmenu
  106.     endwindow
  107.  
  108. cycle id CDTYP label DefSearch
  109. call LoadList()
  110. 'application' MUIA_Application_Version '$VER: SearchCD 1.2 (15.4.99)'
  111. 'application' MUIA_Application_Author 'Neil Bothwick'
  112. 'application' MUIA_Application_Copyright '© 1998 by Neil Bothwick, Wirenet'
  113. 'application' MUIA_Application_Title 'SearchCD'
  114. 'application' MUIA_Application_Description 'Search AACD, and Aminet index files'
  115. /*'application' MUIA_Application_Description 'Search AACD and Aminet index files'*/
  116. ;;;
  117. /* ;;; Main loop */
  118. do forever
  119.     call waitpkt(PrgPort)
  120.     packet = getpkt(PrgPort)
  121.     if packet = '0000 0000'x then iterate
  122.     cmd = getarg(packet)
  123.     call reply(packet,0)
  124.     select
  125.     ;;;
  126. ;;;     /* Search */
  127.         when cmd = 'SEARCH' then do
  128.             'list id CDLST attrs' MUIA_List_Quiet TRUE
  129.             'application' MUIA_Application_Sleep TRUE
  130.             /* Get search string */
  131.             'string id SCSTR'
  132.             SearchStr = result
  133.             /* Get list of CDs to search */
  134.             drop CDs.
  135.             i = 0
  136.             do forever
  137.                  list id CDLST
  138.                  if result = '' then break
  139.                  i = i + 1
  140.                  CDs.i = result
  141.                  end
  142.             CDs.0 = i
  143.             select
  144.                 when SearchStr = '' then call ShowMsg('You must specify a string to search for')
  145.                 when CDs.0 = 0 then call ShowMsg('You must select at least one index to search')
  146.                 otherwise call Search()
  147.                 end
  148.             'application' MUIA_Application_Sleep FALSE
  149.             'list id CDLST attrs' MUIA_List_Quiet FALSE
  150.             end
  151. ;;;
  152. ;;;     /* Select All */
  153.         when cmd = 'ALL' then do
  154.             'method id CDLST' MUIM_List_Select MUIV_List_Select_All MUIV_List_Select_On
  155.             end
  156. ;;;
  157. ;;;     /* Rescan */
  158.         when cmd = 'RESCAN' then call LoadList()
  159. ;;;
  160. ;;;     /* About */
  161.         when cmd = 'ABOUT' then call ShowMsg(VerStr||'0a'x||'Programmed using MUIrexx')
  162.         when cmd = 'ABOUTMUI' then 'method ' MUIM_Application_AboutMUI 0
  163. ;;;
  164. ;;;     /* Cancel */
  165.         otherwise call CleanUp()
  166.         end
  167.     end
  168. ;;;
  169. /* ;;; Subroutines */
  170. ;;;
  171. /* ;;; Load a library */
  172. LoadLib:
  173.     parse arg library
  174.     if show('L',library) then return
  175.     if ~exists('LIBS:'library) then address command 'copy 'CDname':libs/'library 'LIBS: clone quiet'
  176.     if ~addlib(library,0,-30,0) then call ExitMsg('Failed to load' library||'0a'x||'Make sure you have run InitCD')
  177.     return
  178. ;;;
  179. /* ;;; Show a message in a requester */
  180. ShowMsg:
  181.     parse arg msg
  182.     oldaddr = address()
  183.     address(GuiPort)
  184.     'request id MAIN title "'WinTitle'" gadgets "OK" string' msg
  185.     choice = result
  186.     address(oldaddr)
  187.     return choice
  188. ;;;
  189. /* ;;; Exit with a requester */
  190. ExitMsg:
  191.     parse arg msg
  192.     call ShowMsg(msg)
  193.     call Cleanup()
  194.     return
  195. ;;;
  196. /* ;;; Cleanup and exit */
  197. CleanUp:
  198.     call delete(OutFile'#?')
  199.     address(GuiPort)
  200.     'QUIT'
  201.     exit
  202. ;;;
  203. /* ;;; Search CDs */
  204. Search:
  205. 'cycle id OPFMT'
  206. Format = result
  207.     call delete(OutFile)
  208.     'gauge id PROGR attrs' MUIA_Gauge_Max CDs.0 MUIA_Gauge_InfoText '%ld/'CDs.0
  209.     do i = 1 to CDs.0
  210.         'gauge id PROGR attrs' MUIA_Gauge_Current i
  211.         select
  212.             when Source = 'Aminet CDs' then address command 'echo "*NAMINET'right(CDs.i,2)':" >>'OutFile
  213.             /*when Source = 'Aminet Sets' then address command 'echo "*NAminetSet'right(CDs.i,1)':" >>'OutFile*/
  214.             when Format = 'Text' then NH = ''
  215.             otherwise NH = 'NH'
  216.             end
  217.         signal off error
  218.         address command 'FlashFind >>'OutFile AddPart(IndexPath,CDs.i) '"'SearchStr'" NOPREFS QUIET' NH
  219.         signal on error
  220.         end
  221. ;;;
  222. /* ;;; Show matches or warn if none */
  223. if word(statef(OutFile),2) = 0 then do
  224.     call ShowMsg('No matches found for "'SearchStr'"')
  225.     return
  226.     end
  227. if ~open(res,OutFile,'R') then do
  228.     call ShowMsg('File open failure')
  229.     return
  230.     end
  231. if ~open(out,OutFile'1','W') then do
  232.     call ShowMsg('File open failure')
  233.     return
  234.     end
  235.  
  236. select
  237. ;;;
  238.     /* ;;; Show Text */
  239.     when Format = 'Text' then do
  240.         if Source ='Aminet CDs' then do
  241.             /* Format output */
  242.             'gauge id PROGR attrs' MUIA_Gauge_Max word(statef(OutFile),2) MUIA_Gauge_InfoText '"Processing search results"'
  243.             BytesDone = 0
  244.             call readln(res)
  245.             do until eof(res)
  246.                 CDTitle = readln(res)
  247.                 select
  248.                     when CDTitle = 'AMINET01:' then CDTitle = 'AMINET_0693:'
  249.                     when CDTitle = 'AMINET02:' then CDTitle = 'AMINET_0294:'
  250.                     when CDTitle = 'AMINET03:' then CDTitle = 'AMINET_0794:'
  251.                     when substr(CDTitle,7,1) = '0' then CDTitle = compress(CDTitle,'0')
  252.                     otherwise nop
  253.                     end
  254.                 line = readln(res)
  255.                 do while ~eof(res) & line ~= ''
  256.                     BytesDone = BytesDone + length(line) + 1
  257.                     if left(line,1) ~= '|' then do
  258.                         parse var line name =19 path =30 .
  259.                         name = strip(name)
  260.                         path = CDTitle'Aminet/'strip(path)'/'name
  261.                         line = left(name'                                    ',33)||path
  262.                         call writeln(out,line)
  263.                         'gauge id PROGR attrs' MUIA_Gauge_Current BytesDone
  264.                         end
  265.                     line = readln(res)
  266.                     end
  267.                 end
  268.             end
  269.         else do
  270.             call close(out)
  271.             call delete(OutFile'1')
  272.             call rename(OutFile,OutFile'1')
  273.             end
  274.  
  275.         call close(res)
  276.         call close(out)
  277.         address command 'Multiview' OutFile'1'
  278.         call delete(OutFile'1')
  279.         end
  280.     ;;;
  281.     /* ;;; Show HTML */
  282.     when Format = 'HTML' then do
  283.         /* Find AWeb's arexx port or start it if not running */
  284.         ports = show('P')
  285.         portpos = pos('AWEB.',ports)
  286.         if portpos > 0 then AWebPort = word(substr(ports,portpos),1)
  287.         else do
  288.             address command 'Run >NIL: 'CDName':AACD/WebSites/AWeb3/AWebDemo config Amigactive'
  289.             AWebPort = 'AWEB.1'
  290.             end
  291.  
  292.         /* Open output file and write headers */
  293.         call writeln(out,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">')
  294.         call writeln(out,'<html><head><title>Search results</title></head><body bgcolor=white>')
  295.         call writeln(out,'<h3 align=center>Result of searching 'Source' for "<font color=red>'SearchStr'</font>"</h3>')
  296.         call writeln(out,'<table width="100%">')
  297.  
  298.         /* Process output into HTML */
  299.         'gauge id PROGR attrs' MUIA_Gauge_Max word(statef(OutFile),2) MUIA_Gauge_InfoText '"Processing search results"'
  300.         BytesDone = 0
  301.         select
  302.             when pos(Source,'Amiga Active CDs') > 0 then do
  303.                 /* Format output */
  304.                 do until eof(res)
  305.                     line = readln(res)
  306.                     BytesDone = BytesDone + length(line) + 1
  307.                     if line = '' then iterate
  308.                     parse var line name =34 path
  309.                     name = strip(name)
  310.                     line = '<tr><td>'name'<td><a href="x-aweb:rexx/'left(path,pos(':',path))'CDTools/S/ShowDir 'PathPart(path)'">'path'</a>'
  311.                     call writeln(out,line)
  312.                     'gauge id PROGR attrs' MUIA_Gauge_Current BytesDone
  313.                     end
  314.                 end
  315.             when Source = 'Aminet CDs' then do
  316.                 /* Format output */
  317.                 call readln(res)
  318.                 do until eof(res)
  319.                     CDTitle = readln(res)
  320.                     line = readln(res)
  321.                     select
  322.                         when CDTitle = 'AMINET01:' then do
  323.                             CDTitle = 'AMINET_0693:'
  324.                             parsecmd = "name='';size=line;desc=''"
  325.                             end
  326.                         when CDTitle = 'AMINET02:' then do
  327.                             CDTitle = 'AMINET_0294:'
  328.                             parsecmd = 'parse var line name =22 path =33 size =37 age =38 desc'
  329.                             end
  330.                         when CDTitle = 'AMINET03:' then do
  331.                             CDTitle = 'AMINET_0794:'
  332.                             parsecmd = 'parse var line name =22 path =33 size =37 age =38 desc'
  333.                             end
  334.                         when CDTitle = 'AMINET04:' then do
  335.                             CDTitle = 'AMINET4:'
  336.                             parsecmd = 'parse var line name =22 path =33 size =37 age =38 desc'
  337.                             end
  338.                         when substr(CDTitle,7,1) = '0' then do
  339.                             parsecmd = 'parse var line name =20 path =31 size =37 age =40 desc'
  340.                             CDTitle = compress(CDTitle,'0')
  341.                             end
  342.                         otherwise parsecmd = 'parse var line name =20 path =31 size =37 age =40 desc'
  343.                         end
  344.  
  345.                     do while ~eof(res) & line ~= ''
  346.                         BytesDone = BytesDone + length(line) + 1
  347.                         if left(line,1) ~= '|' then do
  348.                             /*parse var line name =19 path =30 size +5 age +5 desc*/
  349.                             interpret parsecmd
  350.                             name = strip(name)
  351.                             path = CDTitle'Aminet/'strip(path)'/'name
  352.                             readme = left(path,lastpos('.',path))'readme'
  353.                             line = '<tr valign=top><td><a href="x-aweb:rexx/'CDName':CDTools/S/Extract.awebrx 'path'">'name'<td align=right>'strip(size)'<td><a href="file://localhost/'readme'">'desc'</a>'
  354.                             call writeln(out,line)
  355.                             'gauge id PROGR attrs' MUIA_Gauge_Current BytesDone
  356.                             end
  357.                         line = readln(res)
  358.                         end
  359.                     end
  360.                 end
  361.             when Source = 'Aminet Sets' then do
  362.                 /* Format output */
  363.                 call readln(res)
  364.                 do until eof(res)
  365.                     line = readln(res)
  366.                     BytesDone = BytesDone + length(line) + 1
  367.                     if left(line,1) = '|' then iterate
  368.                     parse var line name =20 path +11 size +5 age +4 CD +2 x +1 desc
  369.                     name = strip(name)
  370.                     path = 'AminetSet'CD':Aminet/'strip(path)'/'name
  371.                     readme = left(path,lastpos('.',path))'readme'
  372.                     line = '<tr><td><a href="x-aweb:rexx/'CDName':CDTools/S/Extract.awebrx 'path'">'name'<td align=right>'strip(size)'<td><a href="file://localhost/'readme'">'desc'</a>'
  373.                     call writeln(out,line)
  374.                     'gauge id PROGR attrs' MUIA_Gauge_Current BytesDone
  375.                     end
  376.                 end
  377.             when Source = 'Aminet Online' then do
  378.                 /* Format output */
  379.                 call writeln(out,'<th>Name<th>Size<th>Age<th>Description')
  380.                 do until eof(res)
  381.                     line = readln(res)
  382.                     BytesDone = BytesDone + length(line) + 1
  383.                     if line = '' | left(line,1) = '|' then iterate
  384.                     parse var line name =20 path +11 size +5 age +3 x +1 desc
  385.                     name = strip(name)
  386.                     path = 'ftp://uk.aminet.net/pub/aminet/'strip(path)'/'name
  387.                     readme = left(path,lastpos('.',path))'readme'
  388.                     line = '<tr><td><a href="'path'">'name'<td align=right>'strip(size)'<td align=right>'strip(age)'<td><a href="'readme'">'desc'</a>'
  389.                     call writeln(out,line)
  390.                     'gauge id PROGR attrs' MUIA_Gauge_Current BytesDone
  391.                     end
  392.                 call writeln(out,'<tr><td align=center colspan=4><p><hr><p><h5>The age is given in weeks since the date of this index ('date('N',word(statef(AddPart(IndexPath,'INDEX')),5),'I')')</h5>')
  393.                 end
  394.             otherwise call ShowMsg('Not done this bit yet')
  395.             end
  396.         call writeln(out,'</table></body></html>')
  397.         call close(res)
  398.         call close(out)
  399.  
  400.         /* Load HTML */
  401.         address command 'waitforport' AWebPort
  402.         if RC > 0 then call ExitMsg('Unable to start AWeb')
  403.         /*call delete(OutFile)*/
  404.         call delete(OutFile'.html')
  405.         call rename(OutFile'1',OutFile'.html')
  406.         address(AWebPort)
  407.         'open file://localhost/'OutFile'.html reload'
  408.         'screentofront'
  409.         'window tofront'
  410.  
  411.         end
  412.     ;;;
  413.     /* ;;; Show amigaguide */
  414.     when Format = 'AmigaGuide' then do
  415.         call ShowMsg('Not done this bit yet')
  416.         end
  417.     otherwise do
  418.         call ShowMsg('Not done this bit yet')
  419.         call close(res)
  420.         call close(out)
  421.         return
  422.         end
  423.     end
  424. call close(res)
  425. call close(out)
  426.  
  427. address(GuiPort)
  428. 'gauge id PROGR attrs' MUIA_Gauge_Current 0 MUIA_Gauge_InfoText '""'
  429. return
  430. ;;;
  431. /* ;;; List CDs for searching */
  432. LoadList:
  433.     address(GuiPort)
  434.     'list id CDLST attrs' MUIA_List_Quiet TRUE
  435.     'application' MUIA_Application_Sleep TRUE
  436.     /* Clear list */
  437.     'method id CDLST' MUIM_List_Select MUIV_List_Select_All MUIV_List_Select_On
  438.     'method id CDLST' MUIM_List_Remove MUIV_List_Remove_Selected
  439.     /* Create index list */
  440.     'cycle id CDTYP'
  441.     Source = result
  442.     address command
  443.     call delete(OutFile)
  444.     call delete(OutFile'1')
  445.     select
  446.         when Source = 'Amiga Active CDs' then do
  447.             IndexPath = AACDPath
  448.             'list' IndexPath 'pat AACD?? lformat "%N" to' OutFile
  449.             end
  450.         when Source = 'Aminet CDs' then do
  451.             IndexPath = AminetCDPath
  452.             'list' IndexPath 'pat Index?? lformat "%N" to' OutFile
  453.             end
  454.         when Source = 'Aminet Sets' then do
  455.             IndexPath = AminetSetPath
  456.             'list' IndexPath 'pat Set? lformat "%N" to' OutFile
  457.             end
  458.         when Source = 'Aminet Online' then do
  459.             IndexPath = AminetPath
  460.             if ~open(dirs,AddPart(IndexPath,'dirlist'),'R') then 'echo >'OutFile'1 "Unable to open index list"'
  461.             else do until eof(dirs)
  462.                 'echo >>'OutFile'1 "'readln(dirs)'"'
  463.                 end
  464.             end
  465.         otherwise nop
  466.         end
  467.     if exists(OutFile) then 'sort' OutFile OutFile'1'
  468.  
  469.     /* Display list */
  470.     address(GuiPort)
  471.     if ~open(listfile,OutFile'1','R') then call ExitMsg('Error reading file')
  472.     do while ~eof(listfile)
  473.         line = readln(listfile)
  474.         if line > '' then 'list id CDLST insert string' line
  475.         end
  476.     call close(listfile)
  477.     'application' MUIA_Application_Sleep FALSE
  478.     'list id CDLST attrs' MUIA_List_Quiet FALSE
  479.     return
  480. ;;;
  481. /* ;;; Error handler */
  482. Error:
  483.     oldaddress = address()
  484.     address(GuiPort)
  485.     call ShowMsg('Error' RC 'in line' sigl)
  486.     address(oldaddress)
  487.     if RC = 5 then return
  488.     call Cleanup()
  489.     return
  490. ;;;
  491.  
  492.