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