home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 1 / amigaformatcd01.iso / pd / database / fiasco_1.1 / databases / pd-disks / readfish.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1996-04-30  |  8.1 KB  |  239 lines

  1. /* ReadFish.rexx
  2.  * Copyright © 1995 Nils Bandener
  3.  * $VER: ReadFish_rexx 3.1 (6.12.95)
  4.  */
  5.  
  6. /* This script is able to read the "Contents-Files" of PD-disks and
  7.  * create an record for each program in the database in this
  8.  * directory. It is also able to read several Files, which have been
  9.  * joined together. Currently these formats are supported:
  10.  * - Fred Fish (and compatible)
  11.  * - SaarAG
  12.  * - Amiga-Magazin PD
  13.  */
  14.  
  15. Options Results
  16. Address FIASCO
  17.  
  18. tab = X2C("09")
  19. status = "None"
  20. verstat = "None"
  21. format = "None"
  22. notabs = 1
  23.  
  24. F_RequestFile Title '"Select contents file"' NoIcons    /* Have to use
  25.                                                          * the single
  26.                                                          * Quotes, because
  27.                                                          * ARexx would
  28.                                                          * swallow the
  29.                                                          * double quotes
  30.                                                          */
  31.  
  32. if rc = 0 then do
  33.  
  34.     fishfile = result
  35.  
  36.     if Open("cont",fishfile,"read") then do
  37.  
  38.         do while ~eof("cont") & status ~= "End"
  39.  
  40.             line = ReadLn("cont")
  41.  
  42.  
  43.             if Length(Compress(line,"~-=*")) < 5 then line = Compress(line,"~-=*")
  44.  
  45.             if Abbrev(line,"This is disk") then do
  46.  
  47.                 head = line
  48.  
  49.                 disk = Word(head,Find(Upper(head),"DISK")+1)
  50.  
  51.                 format = "Fish"
  52.  
  53.                 status = "Disk"
  54.  
  55.             end
  56.             else if Abbrev(line,"CONTENTS") then do
  57.  
  58.                 head = line
  59.  
  60.                 disk = Word(head,Find(Upper(head),"DISK")+1)
  61.  
  62.                 status = "Disk"
  63.  
  64.             end
  65.             else if Abbrev(line,"Below is a listing") then do
  66.                 nop
  67.             end
  68.             else if Abbrev(line,"Ausgabe:") then do
  69.                 issue = Word(line,2)
  70.                 say issue
  71.                 line = ReadLn("cont")
  72.                 format = "AmigaMag"
  73.                 disk = issue || "," || Word(line,2)
  74.                 say disk
  75.                 status = "Disk"
  76.             end
  77.             else if Abbrev(line,"Programm:") & format = "AmigaMag" then do
  78.                 prog = Word(line,2)
  79.                 status = "Program"
  80.                 findex = 1
  81.                 verstat = "Done"
  82.                 F_AddRecord
  83.                 F_SetFieldCont "DiskNumber" disk
  84.                 F_SetFieldCont "ProgramName" prog
  85.                 /* Rubrik */
  86.                 line = ReadLn("cont")
  87.                 /* Version */
  88.                 line = ReadLn("cont")
  89.                 ver = SubWord(line,2)
  90.                 if ver ~= "" then F_SetFieldCont "Version" ver
  91.                 /* Update */
  92.                 line = ReadLn("cont")
  93.                 line = ReadLn("cont")
  94.             end
  95.             else if Length(line) <= 1 then do
  96.                 if status = "Program" then status = "Disk"
  97.             end
  98.             else if Pos(tab,line) ~= 0 then do
  99.                 notabs = 0
  100.                 if status = "Disk" & format = "Fish" then do
  101.                     /* Read first line */
  102.  
  103.                     status = "Program"
  104.                     findex = 1
  105.                     verstat = "None"
  106.  
  107.                     prog = Left(line,Pos(tab,line)-1)
  108.  
  109.                     if length(prog) <= 1 then do
  110.                         status = "End"
  111.                     end
  112.                     else do
  113.                         F_AddRecord
  114.                         F_SetFieldCont "DiskNumber" disk
  115.                         F_SetFieldCont "ProgramName" prog
  116.  
  117.                         /* Fall through the next if */
  118.                     end
  119.                 end
  120.                 if status = "Program" then do
  121.  
  122.                     /* Unfortunately Fiasco cannot handle multi-line
  123.                      * String-Fields. For this reason, several fields
  124.                      * are used.
  125.                      */
  126.  
  127.                     txt = SubStr(line,Lastpos(tab,line)+1)
  128.  
  129.                     if Abbrev(txt,"Author") | Abbrev(txt,"Autor") then do
  130.                         F_SetFieldCont "Author" SubWord(txt,2)
  131.                     end
  132.                     else do
  133.                         if verstat = "NextLine" then do
  134.                             ver = Word(txt,1)
  135.                             ver = Strip(ver,"T",D2C(44))
  136.                             ver = Strip(ver,"T",".")
  137.                             txt = DelWord(txt,1,1)
  138.                             F_SetFieldCont "Version" ver
  139.                             verstat = "Done"
  140.                         end
  141.                         else if verstat = "None" then do
  142.                             verpos = Find(txt,"Version")
  143.                             if verpos ~= 0 then do
  144.                                 ver = Word(txt,verpos+1)
  145.                                 if ver = "" then do
  146.                                     verstat = "NextLine"
  147.                                     txt = DelWord(txt,verpos,1)
  148.                                 end
  149.                                 else do
  150.                                     verstat = "Done"
  151.                                     txt = DelWord(txt,verpos,2)
  152.                                     F_SetFieldCont "Version" ver
  153.                                 end
  154.                             end
  155.                         end
  156.                         if findex <= 5 then F_SetFieldCont "Desc"||findex txt
  157.                         findex = findex + 1
  158.                     end
  159.                 end
  160.             end
  161.             /* Handling of Texts without tabs */
  162.             else if notabs = 1 then do
  163.                 if status = "Disk" & Left(line,3) ~= "   " then do
  164.                     /* Read first line */
  165.  
  166.                     status = "Program"
  167.                     findex = 1
  168.                     verstat = "None"
  169.  
  170.                     prog = Word(line,1)
  171.                     line = DelWord(line,1,1)
  172.  
  173.                     if length(prog) <= 1 then do
  174.                         status = "End"
  175.                     end
  176.                     else do
  177.                         F_AddRecord
  178.                         F_SetFieldCont "DiskNumber" disk
  179.                         F_SetFieldCont "ProgramName" prog
  180.  
  181.                         /* Fall through the next if */
  182.                     end
  183.                 end
  184.                 if status = "Program" then do
  185.  
  186.                     /* Unfortunately Fiasco cannot handle multi-line
  187.                      * String-Fields. For this reason, several fields
  188.                      * are used.
  189.                      */
  190.  
  191.                     txt = Strip(line)
  192.  
  193.                     if Abbrev(txt,"Author") | Abbrev(txt,"Autor") then do
  194.                         F_SetFieldCont "Author" SubWord(txt,2)
  195.                     end
  196.                     else do
  197.                         if verstat = "NextLine" then do
  198.                             ver = Word(txt,1)
  199.                             ver = Strip(ver,"T",D2C(44))
  200.                             ver = Strip(ver,"T",".")
  201.                             txt = DelWord(txt,1,1)
  202.                             F_SetFieldCont "Version" ver
  203.                             verstat = "Done"
  204.                         end
  205.                         else if verstat = "None" then do
  206.                             verpos = Find(txt,"Version")
  207.                             if verpos ~= 0 then do
  208.                                 ver = Word(txt,verpos+1)
  209.                                 if ver = "" then do
  210.                                     verstat = "NextLine"
  211.                                     txt = DelWord(txt,verpos,1)
  212.                                 end
  213.                                 else do
  214.                                     verstat = "Done"
  215.                                     txt = DelWord(txt,verpos,2)
  216.                                     F_SetFieldCont "Version" ver
  217.                                 end
  218.                             end
  219.                         end
  220.                         if findex <= 5 then F_SetFieldCont "Desc"||findex txt
  221.                         findex = findex + 1
  222.                     end
  223.                 end
  224.  
  225.             end
  226.             else do
  227.                 if status = "Program" then status = "Disk"
  228.             end
  229.         end
  230.  
  231.         dummy = Close("cont")
  232.     end
  233.     else say "Couldn`t open file"
  234.  
  235.     dummy = Close("f")
  236.     Address Command "delete >NIL: t:fish"
  237. end
  238.  
  239.