home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / fiasco_2.1 / databases / pd-disks / readfish.rexx < prev    next >
OS/2 REXX Batch file  |  1996-06-29  |  9KB  |  425 lines

  1. /* ReadFish.rexx
  2.  * Copyright © 1995-1996 Nils Bandener
  3.  * $VER: ReadFish_rexx 5.7 (29.6.96)
  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. Signal on Syntax
  19. Signal on Halt
  20. Signal on Break_C
  21. Signal on Failure
  22.  
  23. F_LockGUI
  24.  
  25. tab = X2C("09")
  26. status = "None"
  27. verstat = "None"
  28. format = "None"
  29. notabs = 1
  30. desc = ""
  31. prog = ""
  32. vers = ""
  33. auth = ""
  34. disk = ""
  35. series = ""
  36.  
  37. F_RequestFile '"Contents"' Title '"Select contents file"' NoIcons    /* Have to use
  38.                                                          * the single
  39.                                                          * Quotes, because
  40.                                                          * ARexx would
  41.                                                          * swallow the
  42.                                                          * double quotes
  43.                                                          */
  44.  
  45. if rc = 0 then do
  46.  
  47.     fishfile = result
  48.  
  49.     if Open("cont", fishfile, "read") then do
  50.  
  51.         do while ~eof("cont") & status ~= "End"
  52.  
  53.             line = ReadLn("cont")
  54.  
  55.             if Length(Compress(line,"~-=*")) < 5 then line = Compress(line,"~-=*")
  56.  
  57.             if Abbrev(line,"This is disk") then do
  58.  
  59.                 /*
  60.                  *  Start of Fish contents file
  61.                  */
  62.  
  63.                 head = line
  64.  
  65.                 disk = Word(head,Find(Upper(head),"DISK")+1)
  66.  
  67.                 format = "Fish"
  68.  
  69.                 status = "Disk"
  70.  
  71.                 if subword(line, 5, 6) = "of the freely distributable AMIGA software" then do
  72.  
  73.                     series = "Fish Disk"
  74.  
  75.                 end
  76.                 else do
  77.  
  78.                     series = ""
  79.  
  80.                 end
  81.  
  82.             end
  83.             else if Abbrev(line,"CONTENTS") then do
  84.  
  85.                 head = line
  86.  
  87.                 disk = Word(head,Find(Upper(head),"DISK")+1)
  88.  
  89.                 status = "Disk"
  90.  
  91.                 series = ""
  92.  
  93.             end
  94.             else if Abbrev(line,"Below is a listing") then do
  95.  
  96.                 /*
  97.                  *  Ignore this line
  98.                  */
  99.  
  100.                 nop
  101.  
  102.             end
  103.             else if Abbrev(line,"Ausgabe:") then do
  104.  
  105.                 issue = Word(line,2)
  106.  
  107.                 line = ReadLn("cont")
  108.  
  109.                 format = "AmigaMag"
  110.                 disk = issue || "," || Word(line,2)
  111.  
  112.                 status = "Disk"
  113.             end
  114.             else if Abbrev(line,"Programm:") & format = "AmigaMag" then do
  115.  
  116.                 /*
  117.                  *  if there is already a description,
  118.                  *  send it to Fiasco
  119.                  */
  120.  
  121.                 if status = "Program" then call DumpRecord
  122.  
  123.                 prog = Word(line,2)
  124.  
  125.                 status = "Program"
  126.                 verstat = "Done"
  127.  
  128.                 /*
  129.                  *  read additional information
  130.                  */
  131.  
  132.                 /* Rubrik */
  133.                 line = ReadLn("cont")
  134.                 /* Version */
  135.                 line = ReadLn("cont")
  136.                 vers = SubWord(line,2)
  137.                 /* Update */
  138.                 line = ReadLn("cont")
  139.                 line = ReadLn("cont")
  140.             end
  141.             else if Length(line) <= 1 then do
  142.  
  143.                 /*
  144.                  *  An empty line is interpreted as the end
  145.                  *  of a program description
  146.                  */
  147.  
  148.                 if status = "Program" then do
  149.  
  150.                     call DumpRecord
  151.  
  152.                     status = "Disk"
  153.                 end
  154.             end
  155.             else if Pos(tab,line) ~= 0 then do
  156.  
  157.                 /*
  158.                  *  The file contains tabs
  159.                  */
  160.  
  161.                 notabs = 0
  162.  
  163.                 if status = "Disk" & format = "Fish" then do
  164.                     /* Read first line */
  165.  
  166.                     status = "Program"
  167.                     verstat = "None"
  168.  
  169.                     prog = Left(line,Pos(tab,line)-1)
  170.  
  171.                     if length(prog) <= 1 then do
  172.  
  173.                         status = "End"
  174.  
  175.                     end
  176.  
  177.                 end
  178.                 if status = "Program" then do
  179.  
  180.                     /*
  181.                      *  Filter tabs
  182.                      */
  183.  
  184.                     txt = SubStr(line,Lastpos(tab,line)+1)
  185.  
  186.                     /*
  187.                      *  Parse the line
  188.                      */
  189.  
  190.                     call ParseDesc
  191.  
  192.                 end
  193.             end
  194.  
  195.             else if notabs = 1 then do
  196.  
  197.                 /*
  198.                  *  The file does not contain tabs
  199.                  */
  200.  
  201.                 if status = "Disk" & Left(line,3) ~= "   " then do
  202.  
  203.                     /*
  204.                      *  Read first line
  205.                      */
  206.  
  207.                     status = "Program"
  208.                     verstat = "None"
  209.  
  210.                     prog = Word(line,1)
  211.                     line = DelWord(line,1,1)
  212.  
  213.                     /*
  214.                      *  If program string is empty, stop processing
  215.                      */
  216.  
  217.                     if length(prog) <= 1 then do
  218.  
  219.                         status = "End"
  220.  
  221.                     end
  222.  
  223.                     /*
  224.                      *  Fall through the next if, if status = "program"
  225.                      */
  226.  
  227.                 end
  228.                 if status = "Program" then do
  229.  
  230.                     txt = Strip(line)
  231.  
  232.                     /*
  233.                      *  Parse the line
  234.                      */
  235.  
  236.                     call ParseDesc
  237.                 end
  238.  
  239.             end
  240.             else do
  241.  
  242.                 if status = "Program" then do
  243.  
  244.                     call DumpRecord
  245.  
  246.                     status = "Disk"
  247.  
  248.                 end
  249.             end
  250.         end
  251.  
  252.         if status = "Program" then do
  253.  
  254.             call DumpRecord
  255.  
  256.         end
  257.  
  258.         call Close("cont")
  259.     end
  260.     else F_RequestChoice '"Could not open ' || fishfile || '"' '"Ok"'
  261.  
  262. end
  263.  
  264. F_UnlockGUI
  265.  
  266. exit
  267.  
  268. /*
  269.  *  ParseDesc takes an already pre-processed line and reads
  270.  *  information such as version and author from it.
  271.  */
  272.  
  273. ParseDesc:
  274.  
  275.     if Abbrev(txt,"Author") | Abbrev(txt,"Autor") then do
  276.  
  277.         /*
  278.          *  Remember author of program
  279.          */
  280.  
  281.         auth = SubWord(txt,2)
  282.  
  283.     end
  284.     else do
  285.  
  286.         if verstat = "NextLine" then do
  287.  
  288.             /*
  289.              *  Read version string.
  290.              *  Version keyword was the last word in the
  291.              *  previous line. Thus, the first word in this
  292.              *  line must be the version.
  293.              */
  294.  
  295.             vers = Word(txt,1)
  296.             vers = Strip(vers,"T",D2C(44))
  297.             vers = Strip(vers,"T",".")
  298.             vers = Strip(vers,"T",",")
  299.             txt = DelWord(txt,1,1)
  300.             verstat = "Done"
  301.         end
  302.         else if verstat = "None" then do
  303.  
  304.             /*
  305.              *  Look for word "Version". Word after that
  306.              *  is used as version.
  307.              */
  308.  
  309.             verpos = Find(txt,"Version")
  310.  
  311.             if verpos ~= 0 then do
  312.  
  313.                 vers = Word(txt,verpos+1)
  314.  
  315.                 if vers = "" then do
  316.  
  317.                     /*
  318.                      *  If there is no version, try it in the
  319.                      *  next line
  320.                      */
  321.  
  322.                     verstat = "NextLine"
  323.  
  324.                     /*
  325.                      *  Delete word "version"
  326.                      */
  327.  
  328.                     txt = DelWord(txt,verpos,1)
  329.                 end
  330.                 else do
  331.  
  332.                     vers = Strip(vers,"T",".")
  333.                     vers = Strip(vers,"T",",")
  334.  
  335.                     /*
  336.                      *  Stop searching for version strings
  337.                      */
  338.  
  339.                     verstat = "Done"
  340.  
  341.                     /*
  342.                      *  Delete word "version"
  343.                      */
  344.  
  345.                     txt = DelWord(txt,verpos,2)
  346.                 end
  347.             end
  348.         end
  349.  
  350.         Desc = Desc || " " || txt
  351.  
  352.     end
  353.  
  354. return
  355.  
  356. /*
  357.  *  DumpRecord writes the information about the program which is
  358.  *  contained in ARexx vars to a Fiasco record
  359.  */
  360.  
  361. DumpRecord:
  362.  
  363.     if series = "" then do
  364.  
  365.         F_RequestString 'Title "Read Fish" Text "What is the name*nof the PD library?"'
  366.  
  367.         if rc = 0 then do
  368.  
  369.             series = result
  370.  
  371.         end
  372.         else do
  373.  
  374.             series = "???"
  375.  
  376.         end
  377.     end
  378.  
  379.     if disk ~= "" & prog ~= "" & desc ~= "" then do
  380.  
  381.         /*
  382.          *  Send data to Fiasco
  383.          */
  384.  
  385.         F_AddRecord
  386.         F_SetFieldCont "DiskNumber" disk
  387.         F_SetFieldCont "ProgramName" prog
  388.         F_SetFieldCont "Desc" desc
  389.         F_SetFieldCont "Library" series
  390.  
  391.         if vers ~= "" & symbol("vers") = "VAR" then F_SetFieldCont "Version" vers
  392.         if auth ~= "" & symbol("auth") = "VAR" then F_SetFieldCont "Author" auth
  393.  
  394.     end
  395.  
  396.     /*
  397.      *  Clean up
  398.      */
  399.  
  400.     prog = ""
  401.     desc = ""
  402.     vers = ""
  403.     auth = ""
  404.  
  405.     verstat = "None"
  406.  
  407. return
  408.  
  409. syntax:
  410. failure:
  411.  
  412. say "Error" rc "in line" sigl ":" errortext(rc)
  413.  
  414. halt:
  415. break_c:
  416. say "Enter to continue"
  417.  
  418. pull dummy
  419.  
  420. F_UnlockGUI
  421.  
  422. exit
  423.  
  424.  
  425.