/* ParseCISLib.rexx */
/* Parse TAPCIS library files. This must be run from CLI as a synchonous MFF
macro.  MFF has problems with many AREXX fuctions in native mode.  MFF
must be running an a CISLIB type database must be open
*/

/* constants */

/* For use with WHAP */
LibPrompt  = 'LIB'

/* For use with TAPCIS */
/* LibPrompt  = 'DL' */

DefaultDir = 'RAM:'

options results
 
/* lock to mff */

address mff_server1 lock
if rc~=0 THEN DO
  SAY 'NO LOCK ON MFF!'
  EXIT 10
END
ADDRESS VALUE RESULT

/* If you are using a separate database for each ForUm you could elimate
the FORUM field from the database and omit all references to it in this
program */
string_request 'What Library are you cataloging(AMIGAT, etc)?'

Forum = result

/* we need the  ARP library for this */


if ~show('L',"rexxarplib.library") then DO
   if ~addlib('rexxarplib.library',0,-30,0) then DO
      say 'support library not available!'
      EXIT 0
   end
end


/* bring up the cheath file requestor */

 
ParseFile = getfile(20, 20,DefaultDir,,"Choose File to parse",)

   if length(ParseFile) < 1 then DO
     result =  postmsg(50,50,"No option specified.",)
     result =  postmsg()
   END



IF Open(infile,ParseFile,'READ') THEN 

DO WHILE ~EOF(infile)
   str = ReadLn(infile)

   PARSE VAR str a b c 
   IF (a = LibPrompt) THEN Lib = strip(b);
   PARSE VAR str '[' usernum ']'

   IF ~(usernum = '') THEN DO
      /* okay, we got a file description */
      str = ReadLn(infile)
      PARSE VAR str name '/' type date size DownLoads
      IF length(name) > 10 THEN
          /* file type not specified, probably text */
          PARSE VAR str name date size DownLoads
      /* skip a line */
      DO FOR 2
         str = strip(readln(infile)) 
      END
      /* Get Keywords */
      PARSE VAR str junk Keywords
      Keywords = strip(Keywords)
      DO WHILE ~(str='')
         str = readln(infile)
         str = strip(str)
         keywords = keywords str
      END

      descr = strip(readln(infile))
      DO UNTIL (str='')
         str = readln(infile)
         str = strip(str)
         descr = descr || '0A'x || str
      END

      /* Change date format to YY.MM.DD so MFF can sort on it */

      PARSE VAR date day '-' month '-' year
      SELECT
        WHEN month = 'Jul' THEN mm = 07
        WHEN month = 'Aug' THEN mm = 08
        WHEN month = 'Sep' THEN mm = 09
        WHEN month = 'Oct' THEN mm = 10
        WHEN month = 'Nov' THEN mm = 11
        WHEN month = 'Dec' THEN mm = 12
        WHEN month = 'Jan' THEN mm = 01
        WHEN month = 'Feb' THEN mm = 02
        WHEN month = 'Mar' THEN mm = 03
        WHEN month = 'Apr' THEN mm = 04
        WHEN month = 'May' THEN mm = 05
        WHEN month = 'Jun' THEN mm = 06
        OTHERWISE mM = 0
      END

      date = year || '.' || mm || '.' || day
      /* assign values to database record */
      get_blank Rec
      Rec.1.value = name
      Rec.2.value = date
      Rec.3.value = size
      Rec.4.value = usernum
      Rec.5.value = descr
      Rec.6.value = forum
      Rec.7.value = Lib
      Rec.8.value = Keywords
      add Rec
   END

END
close(inFile)

save_database quietly

/* DISCONNECT FROM MFF */
UNLOCK

EXIT
