home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 14 / AACD14.ISO / CDTools / S / MakeIndex < prev    next >
Text File  |  1999-09-23  |  6KB  |  189 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='Y'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = GetVar('AACD')
  20.  
  21. /* Clear icon position */
  22. ';nopos' Volume':disk nodd'
  23. /* Delete trashcan */
  24. ';delete >NIL: 'Volume':Trashcan all force'
  25. ';delete >NIL: 'Volume':T all force'
  26.  
  27. /* defines and such */
  28.         /* GREP CALL */
  29. GREPCALL = "grep"
  30.         /* GREP HELP CALL */
  31. GREPHELP = "grep -h"
  32.         /* Where's the CD index? */
  33. IDXLOC = Volume':CDTools/indices/'Volume
  34.         /* Where's the finished guide to go to?*/
  35. outfile = Volume':CDTools/Docs.guide'
  36.         /* Path to MultiView */
  37. MView = Volume':System/Utilities/MultiView'
  38.         /* Extensions to search for */
  39. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  40.  
  41. if buildidx='Y' then do
  42.     /* NB the column format is important for the sort fuction later */
  43.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  44.     'delete >NIL:' IDXLOC
  45.     'list ' Volume':~(html|images|System|Trashcan|S|T) all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  46.     ';list ' Volume':AACD all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  47.     ';list ' Volume':AACD/~(WWW) all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  48.     ';list' Volume':AACD/WWW all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  49.     end
  50.  
  51. grepfile = "t:grepoutput." || Pragma("i")
  52. agfile = "t:grepguide." || Pragma("i")
  53. CR      = d2c(10)
  54. TAB     = d2c(9)
  55.  
  56. /* setup the output file - we need this first so we can show errors in it */
  57. IF Open(agfp,agfile,'w') = 0 THEN DO
  58.         SAY "Couldn't create amigaguide file ("||agfile||")"
  59.         EXIT 20
  60.         END
  61.  
  62. call writeln(agfp,'@DATABASE "CD docs"')
  63. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  64. call writeln(agfp,'')
  65. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  66. call writeln(agfp,'')
  67.  
  68. /* Put a search button (needs searchguide in the CDs path) */
  69. if SGUIDE='Y' then do
  70. call writeln(agfp,'@{" Search " SYSTEM "RUN 'Volume':CDTools/SearchGuide/SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  71. call writeln(agfp,'')
  72. end
  73.  
  74. SIGNAL ON FAILURE
  75. ADDRESS COMMAND
  76. 'delete >NIL:' grepfile
  77. do until Extensions = ''
  78.     parse var Extensions ext '|' Extensions
  79.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  80.     end
  81. 'rename' grepfile ' to ' grepfile||'.old'
  82. 'sort' grepfile||'.old' grepfile 'colstart 37'
  83. SIGNAL OFF FAILURE
  84.  
  85. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  86.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  87.         END
  88.  
  89. /*************************************************************************
  90. **  Format of Grep output
  91. **  =====================
  92. **
  93. **HTMLit!.guide                 AACD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  94. **DemosOfTheWorld.guide         AACD4:AACD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  95. **mc12.guide                    AACD4:AACD/Demos/Malevolent_Creations/mc12.guide
  96. **iml-Feb71.guide               AACD4:AACD/Graphics/Imagine/iml-Feb71.guide
  97. **Dust.guide                    AACD4:AACD/Graphics/Imagine/Dust/Docs/Dust.guide
  98. **DustEnglish.guide             AACD4:AACD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  99. **IM_Organizer.guide            AACD4:AACD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  100. **TextureStudio.guide           AACD4:AACD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  101. **ncFTPevents.guide             AACD4:AACD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  102. **
  103. ****************************************************************************/
  104.  
  105. line = ReadLn(grepfp)
  106. IF EOF(grepfp) THEN DO
  107.         call close(grepfp)
  108.         say 'No files found'
  109.         exit 10
  110.         END
  111.  
  112.  
  113.         CALL Pragma('W','n')            /* turn off dos requesters */
  114.  
  115. DO WHILE ~EOF(grepfp)
  116.         /* START BY LOOKING FOR FILENAMES */
  117.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  118.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  119.         if right(currentfile,5) ='guide' then
  120.         do
  121.             node='/main'
  122.             action='link "'
  123.         end
  124.         else
  125.         do
  126.             node=''
  127.             action='system "'MView' '
  128.         end
  129.         endif
  130.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  131.         line = ReadLn(grepfp)
  132.                 END
  133.  
  134. call WriteLn(agfp,'@ENDNODE')
  135.  
  136. call Close(grepfp)
  137. call Close(agfp)
  138.  
  139.        CALL Pragma('W','w')            /* turn dos requesters back on */
  140.  
  141. address command
  142. 'copy' agfile outfile
  143. 'delete >NIL:' grepfile
  144. 'delete >NIL:' grepfile||'.old'
  145. 'delete >NIL:' agfile
  146.  
  147. EXIT
  148.  
  149. FAILURE:
  150. ERROR:
  151.         errRC = RC
  152.         CALL Close(grepfp)
  153.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  154.         EXIT
  155.  
  156. /***************************************************/
  157. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  158.  
  159.         ErrorText = arg(1)
  160.         ErrorFile = arg(2)
  161.  
  162.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  163.         call writeln(agfp,ErrorText)
  164.         call writeln(agfp,' ')
  165.  
  166.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  167.                 call writeln(agfp,"Response:")
  168.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  169.                 Open('errorfp',ErrorFile,'r')
  170.                 DO WHILE ~EOF('errorfp')
  171.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  172.                         END
  173.                 call close('errorfp')
  174.                 END
  175.  
  176.         call writeln(agfp,"")
  177.         call writeln(agfp,"Current Path:")
  178.         call writeln(agfp,"    "||Pragma("D"))
  179.         call writeln(agfp,'@ENDNODE')
  180.  
  181.         call close(agfp)
  182.  
  183.         IF Exists(grepfile) THEN Delete(grepfile)
  184.         Delete(agfile)
  185.  
  186.         EXIT 20
  187. RETURN
  188.  
  189.