home *** CD-ROM | disk | FTP | other *** search
/ BBS 1 / BBS#1.iso / communic / availist.ha / AL_CFG.PAS next >
Pascal/Delphi Source File  |  1993-01-04  |  12KB  |  258 lines

  1. {*****************************************************************************
  2.  *                                                                           *
  3.  *                        AL_Cfg.Pas By Andrew Farmer                        *
  4.  *  Config File and Command Line Parseing Module for AvaiList Revision 1.10  *
  5.  *                                                                           *
  6.  *         Copyright 1989 by Andrew D. Farmer, All Rights Reserved.          *
  7.  *                                                                           *
  8.  *                                                                           *
  9.  *     Compiled using Turbo Pascal Version 5.0 By Borland International      *
  10.  *                                                                           *
  11.  *****************************************************************************}
  12.  
  13. Procedure Bad_Keyword (CLO : String);
  14. Begin
  15.   Report_Error('''' + CLO + ''' is an invalid Configuration File keyword, aborting.',1);
  16. End;
  17.  
  18. Procedure Bad_Option (CLO : String);
  19. Begin
  20.   Report_Error('''-' + CLO + ''' is an invalid Command Line Option, aborting.',1);
  21. End;
  22.  
  23. Procedure CONFIG_READ;
  24. Label 1, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, Translate;
  25. Begin
  26.   Assign(ReadCfg,ConfigFile);
  27.   SetTextBuf(ReadCfg,Buf);
  28.   {$I-} Reset(ReadCfg) {$I+} ;
  29.   OK := (IOResult = 0);
  30.   If Not OK then Exit;
  31.   Assign(StErr,'CON');
  32.   ReWrite(StErr);
  33.   Writeln(StErr,'Reading Configuration File ''',ConfigFile,'''...');
  34.   Writeln(StErr,'');
  35.   Close(StErr);
  36.   PathInc := 0;
  37.   PathCount := 0;
  38.   Repeat
  39.     Readln(ReadCfg,pr);
  40.     For n := 1 to length(pr) do
  41.     pr[n] := Upcase(pr[n]);
  42.     PR1 := Copy(Pr,1,1);
  43.     PR2 := Copy(Pr,1,15);
  44.     if (pr = '') or (PR1 = ' ') or (PR1 = ';') then Goto 1;
  45.     count := 0;
  46.     repeat
  47.       Count := Count + 1;
  48.       Ch := Copy(PR2,Count,1);
  49.     until (Ch = ' ') or (Count = Length(Pr));
  50.     If Count = Length(Pr) then
  51.     Begin
  52.       Count := Length(Pr);
  53.       Parm1 := Copy(Pr,1,count);
  54.       Parm2 := '';
  55.       Goto Translate;
  56.     End;
  57.     count := count - 1;
  58.     Parm1 := Copy(Pr,1,count);
  59.     count2 := count + 2;
  60.     PR3 := Copy(Pr,count2,Length(Pr));
  61.     If PR3 = '' then Parm2 := '';
  62.     If PR3 <> '' then
  63.     Begin
  64.       Count3 := 0;
  65.       repeat
  66.         Count3 := Count3 + 1;
  67.         Ch := Copy(PR3,Count3,1);
  68.       until Ch <> ' ';
  69.       count3 := count3 + count2;
  70.       count3 := count3 - 1;
  71.       Parm2 := Copy(Pr,count3,Length(Pr));
  72.     End;
  73.     Translate:
  74.     If Parm1 = 'AREA' then Begin Inc(PathInc); Paths[PathInc] := Parm2; Goto 1; End;
  75.     If Parm1 = 'ARCHIVE' then Begin DoArc := TRUE; ArcCmd := Parm2; Goto 1; End;
  76.     If Parm1 = 'BOXTYPE' then Begin BoxType := Parm2; Goto 1; End;
  77.     If Parm1 = 'NOCOMMENTS' then Begin StripCom := True; Goto 1; End;
  78.     If Parm1 = 'NODATE' then Begin NoDate := TRUE; Goto 1; End;
  79.     If Parm1 = 'EXTRA' then Begin ExiFile := Parm2; Goto 1; End;
  80.     If Parm1 = 'FLAGNEW' then Begin FlagNew := True; FlagString := Parm2; Goto 1; End;
  81.     If Parm1 = 'HEADER' then Begin HeadFile := Parm2; Goto 1; End;
  82.     If Parm1 = 'KILLORPHAN' then Begin KillOrphan := True; Goto 1; End;
  83.     If Parm1 = 'MOVE' then Begin MoveIt := TRUE; Goto 1; End;
  84.     If Parm1 = 'NEWFILE' then Begin DoNewList := True; FlagCheck := Parm2; Goto 1; End;
  85.     If Parm1 = 'OUTFILE' then Begin OutList := Parm2; Goto 1; End;
  86.     If Parm1 = 'QUIET' then Begin Quiet := True; Goto 1; End;
  87.     If Parm1 = 'SYSTEMBBS' then Begin DoOpus := True; OpusPath := Parm2; Goto 1; End;
  88.     If Parm1 = 'NOTOTAL' then Begin TotArea := False; Goto 1; End;
  89.     If Parm1 = 'FLAGCHAR' then Begin FlagChar := Parm2; Goto 1; End;
  90.     If Parm1 = 'DEBUG' then Begin Debug := True; Goto 1; End;
  91.     Bad_keyword(Parm1);
  92.     1:
  93.   Until Eof(ReadCfg);
  94.   Close(ReadCfg);
  95.   PathCount := PathInc;
  96.   PathInc := 0;
  97.   If ConfigFile = '' then goto 100;
  98.   If ExiFile = '' then goto 105;
  99.   If HeadFile = '' then goto 106;
  100.   If (ArcCmd <> '') AND (ArcCmd <> 'ARC') AND (ArcCmd <> 'DWC') AND (ArcCmd <> 'PKARC') AND
  101.   (ArcCmd <> 'PKPAK') AND (ArcCmd <> 'PAK') AND (ArcCmd <> 'ZOO') then Goto 101;
  102.   If (FlagNew = FALSE) AND (DoNewList = TRUE) then goto 102;
  103.   If (DoNewList = TRUE) AND (FlagCheck = '') then goto 103;
  104.   If (FlagNew = True) AND (FlagString <> '') then 
  105.   Begin
  106.     Val(FlagString,FlagDays,Code);
  107.     If Code <> 0 then Goto 104;
  108.   End;
  109.   If (BoxType <> '0') and (BoxType <> '1') and (BoxType <> '2') and (BoxType <> '3')  and (BoxType <> '4') then goto 107;
  110.   If FlagChar = '' then goto 108;
  111.   If OpusPath = '' then goto 109;
  112.   OpusPath := FExpand(OpusPath);
  113.   Exit;
  114.   100:
  115.   Report_Error('You MUST Provide a FileName following the INFOFILE keyword, aborting',1);
  116.   101:
  117.   Report_Error('The ARCHIVE keyword modifier ''' + ArcCmd + ''' is invalid, aborting',1);
  118.   102:
  119.   Report_Error('The NEWFILE keyword was selected without the the FLAGNEW keyword, aborting',1);
  120.   103:
  121.   Report_Error('You MUST Provide an Output FileName following the NEWFILE keyword, aborting',1);
  122.   104:
  123.   Report_Error('The FLAGNEW keyword was modified, but not with a valid interger, aborting',1);
  124.   105:
  125.   Report_Error('You MUST Provide an Input FileName following the EXTRA keyword, aborting',1);
  126.   106:
  127.   Report_Error('You MUST Provide an Input FileName following the HEADER keyword, aborting',1);
  128.   107:
  129.   Report_Error('The BOXTYPE keyword modifier ''' + BoxType + ''' is out of range, aborting',1);
  130.   108:
  131.   Report_Error('The FLAGCHAR keyword MUST be modified with a vaild ASCII character, aborting',1);
  132.   109:
  133.   Report_Error('The SYSTEMBBS keyword MUST be modified with a Drive\Directory\Path, aborting',1);
  134. End; {Procedure CONFIG_READ}
  135.  
  136. Procedure PRE_CMD_CHECK;
  137. Begin
  138.   ps := ParamStr(1);
  139.   For n := 1 to length(ps) do
  140.   ps[n] := Upcase(ps[n]);
  141.   pcheck := copy(ps,1,1);
  142.   pchk := Copy(ps,2,1);
  143.   Pstr := Copy(ps,3,length(ps));
  144.   if (pcheck <> '/') and (pcheck <> '-') then Exit;
  145.   If (Pchk = 'R') then If Pstr <> '' then ConfigFile := Pstr;
  146. End; {Procedure Pre_Cmd_Check}
  147.  
  148. Procedure COMMAND_LINE;
  149. Label 1, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113;
  150. Begin
  151.   If ParamCount > 15 then Goto 103;
  152.   If ParamCount = 0 then Goto 105;
  153.   ps := ParamStr(1);
  154.   For n := 1 to length(ps) do
  155.   ps[n] := Upcase(ps[n]);
  156.   pcheck := copy(ps,1,1);
  157.   pchk := Copy(ps,2,1);
  158.   if (pcheck <> '/') and (pcheck <> '-') then Goto 101;
  159.   If Pchk = 'R' then Exit;
  160.   CountParamStr := 0;
  161.   Repeat
  162.     CountParamStr := CountParamStr + 1;
  163.     ps := ParamStr(CountParamStr);
  164.     For n := 1 to length(ps) do
  165.     ps[n] := Upcase(ps[n]);
  166.     pcheck := copy(ps,1,1);
  167.     pchk := Copy(ps,2,1);
  168.     Pstr := Copy(ps,3,length(ps));
  169.     if (pcheck <> '/') and (pcheck <> '-') then Goto 101;
  170.     If Pchk = 'A' then Begin DoArc := TRUE; ArcCmd := Pstr; Goto 1; End;
  171.     If Pchk = 'B' then Begin BoxType := Pstr; Goto 1; End;
  172.     If Pchk = 'C' then Begin StripCom := True; Goto 1; End;
  173.     If Pchk = 'D' then Begin NoDate := TRUE; Goto 1; End;
  174.     If Pchk = 'E' then Begin ExiFile := Pstr; Goto 1; End;
  175.     If Pchk = 'F' then Begin FlagNew := True; FlagString := Pstr; Goto 1; End;
  176.     If Pchk = 'H' then Begin HeadFile := Pstr; Goto 1; End;
  177.     If Pchk = 'K' then Begin KillOrphan := True; Goto 1; End;
  178.     If Pchk = 'M' then Begin MoveIt := TRUE; Goto 1; End;
  179.     If Pchk = 'N' then Begin DoNewList := True; FlagCheck := Pstr; Goto 1; End;
  180.     If Pchk = 'O' then Begin OutList := Pstr; Goto 1; End;
  181.     If Pchk = 'Q' then Begin Quiet := True; Goto 1; End;
  182.     If Pchk = 'S' then Begin DoOpus := True; OpusPath := Pstr; Goto 1; End;
  183.     If Pchk = 'T' then Begin TotArea := False; Goto 1; End;
  184.     If Pchk = 'Z' then Begin FlagChar := Pstr; Goto 1; End;
  185.     Bad_Option(Pchk);
  186.     1:
  187.   Until CountParamStr = ParamCount;
  188.   If OutList = '' then goto 102;
  189.   If ConfigFile = '' then goto 108;
  190.   If ExiFile = '' then goto 109;
  191.   If HeadFile = '' then goto 110;
  192.   If (ArcCmd <> '') AND (ArcCmd <> 'ARC') AND (ArcCmd <> 'DWC') AND (ArcCmd <> 'PKARC') AND 
  193.   (ArcCmd <> 'PKPAK') AND (ArcCmd <> 'PAK') AND (ArcCmd <> 'ZOO') then Goto 104;
  194.   If (FlagNew = FALSE) AND (DoNewList = TRUE) then goto 106;
  195.   If (DoNewList = TRUE) AND (FlagCheck = '') then goto 107;
  196.   If (FlagNew = True) AND (FlagString <> '') then 
  197.   Begin
  198.     Val(FlagString,FlagDays,Code);
  199.     If Code <> 0 then Goto 100;
  200.   End;
  201.   If (BoxType <> '0') and (BoxType <> '1') and (BoxType <> '2') and (BoxType <> '3')  and (BoxType <> '4') then goto 111;
  202.   If FlagChar = '' then goto 112;
  203.   If OpusPath = '' then goto 113;
  204.   OpusPath := FExpand(OpusPath);
  205.   Exit;
  206.   100:
  207.   Report_Error('The F Parameter was modified, but not with a valid integer, aborting',1);
  208.   101:
  209.   Report_Error('ALL Command Line Options MUST be preceded with / or -, aborting',1);
  210.   102:
  211.   Report_Error('The -O Parameter MUST be present, and MUST be followed by a FileName, aborting',1);
  212.   103:
  213.   Report_Error('Too Many Command Line Options were used, aborting',1);
  214.   104:
  215.   Report_Error('The A Parameter value of ''' + ArcCmd + ''' is invalid, aborting',1);
  216.   105:
  217.   Assign(StErr,'CON');
  218.   ReWrite(StErr);
  219.   Writeln(StErr,'Usage: AvaiList <-R> or <-Ooutfile + your choice of optional switches>');
  220.   Writeln(StErr,'');
  221.   Writeln(StErr,' -A<arccmd> Causes Master/NewFile list to be Archived. See Docs re: ''arccmd''');
  222.   Writeln(StErr,' -B<boxtyp> Selects which BoxType to use in the lists. See Docs re: ''boxtyp''');
  223.   Writeln(StErr,' -C         Causes Files.Bbs comment lines to be striped from the Master List.');
  224.   Writeln(StErr,' -D         Causes each file''s Date Stamp NOT to be put into the List.');
  225.   Writeln(StErr,' -Efilespec Replace the default ''Extra Info'' file with one of your choice.');
  226.   Writeln(StErr,' -F<days>   Flag files that are new in past <days> days. Default is 7 days.');
  227.   Writeln(StErr,' -Hfilespec Replace the default ''Header'' file with one of your choice.');
  228.   Writeln(StErr,' -K         Kill Orphans. Do NOT show Missing/Offline files in the Master List.');
  229.   Writeln(StErr,' -M         When used with the -A command, causes File to be Moved to Archive.');
  230.   Writeln(StErr,' -Noutfile  With -F, causes a NewFile list to be created with the Master List.');
  231.   Writeln(StErr,' -Ooutfile  File for Master Output, outfile is a filename or a path + filename.');
  232.   Writeln(StErr,' -Q         Causes AvaiList to run Quietly, will not display Runtime settings.');
  233.   Writeln(StErr,' -R<config> Run from pre-set configfile settings only. Must be the First switch');
  234.   Writeln(StErr,' -Spath     Use Opus System.Bbs Files in directory <path> for the Path Info.');
  235.   Writeln(StErr,' -T         DO NOT total up files/bytes in EACH Area & report in Master List.');
  236.   Writeln(StErr,' -Z<char>   Use <char> to flag new files instead of using an asterix (*).');
  237.   Writeln(StErr,'');
  238.   Writeln(StErr,'Switches may be set in the Config File. Redirect output to produce Log Report.');
  239.   Close(StErr);
  240.   Halt(0);
  241.   106:
  242.   Report_Error('The N Parameter was selected without the presence of the F Parameter, aborting',1);
  243.   107:
  244.   Report_Error('You MUST Provide an Output FileName following the N Parameter, aborting',1);
  245.   108:
  246.   Report_Error('You MUST Provide an Input FileName following the P Parameter, aborting',1);
  247.   109:
  248.   Report_Error('You MUST Provide an Input FileName following the E Parameter, aborting',1);
  249.   110:
  250.   Report_Error('You MUST Provide an Input FileName following the H Parameter, aborting',1);
  251.   111:
  252.   Report_Error('The B Parameter value of ''' + BoxType + ''' is out of range, aborting',1);
  253.   112:
  254.   Report_Error('The Z Parameter MUST be modified with a vaild ASCII character, aborting',1);
  255.   113:
  256.   Report_Error('The S Parameter MUST be modified with a Drive\Directory\Path, aborting',1);
  257. End; {Procedure COMMAND_LINE}
  258.