{$A+,B-,D-,E-,F-,I+,L-,N-,O-,R+,S+,V-}
{$IFDEF VER60}
  {$G-,X-}
{$ENDIF}
{$IFDEF VER70}
  {$G-,P-,Q-,T-,X-,Y-}
{$ENDIF}
{$M 1024, 0, 0}

program GUS_WriteConfig;    { Append or update configuration }
                            { information to or in GUS.EXE    for v1.95 !!!  }
uses DOS;

type
    FNameStr = string[12];

    ArcType = (ARC, ARp, ARJ, DWC, HA,  HAP, HPK, HYP, LZH,
               PAK, RAR, SQZ, UC2, ZIP, ZOO);
    ArcCmds = (Extract, Replace, Display, Test, Contents);

    ArcData = record
                Ext : string[3];
                Prog: FNameStr;
                Cmd : array [ArcCmds] of string[10];
                Pth,
                Pwd : string[5];
              end;

    ArcCfg  = record
                Marker  : longint;
                VirDet  : record
                           Prog: FNameStr;
                           Cmd : string[20];
                          end;
                ArcTable: array [ArcType] of ArcData;
              end;

const
    GUSname     = 'GUS.EXE';
    CfgMarker   = $C3535547;       {'GUS'+chr(195)}
    Unsupported = '**********';
    ArcInfo     : ArcCfg
    = (Marker   : CfgMarker;
       VirDet   : (  Prog: 'SCAN    .EXE'; Cmd: '. /NOMEM            ');
                                          {      ^^^^^^^^ scan CURRENT dir for viruses! }
       ArcTable :                         {     Extract       Replace       Display       Test          Contents    }
       ((Ext: 'ARC'; Prog: 'PKUNPAK .EXE'; Cmd:('-n        ', '-r        ', '-c        ', '-t        ', '-v        ');
                                           Pth: Unsupported;
                                           Pwd: 'g    '     ),
        (Ext: 'A7+'; Prog: 'XARC    .EXE'; Cmd:('          ', '/o        ', Unsupported , Unsupported , Unsupported );
                                           Pth: Unsupported;
                                           Pwd: '/g   '     ),
        (Ext: 'ARJ'; Prog: 'ARJ     .EXE'; Cmd:('e -uy     ', 'e -y      ', 'p         ', 't         ', 'l         ');
                                           Pth: '<x   '    ;
                                           Pwd: ' -g  '     ),
        (Ext: 'DWC'; Prog: 'DWC     .EXE'; Cmd:('xow       ', 'xw        ', 'p         ', 't         ', 'v         ');
                                           Pth: 'r    '    ;
                                           Pwd: 'g    '     ),
        (Ext: 'HA '; Prog: 'HA      .EXE'; Cmd:('et        ', 'ety       ', Unsupported , 't         ', 'l         ');
                                           Pth: '<x   '    ;
                                           Pwd: Unsupported ),
        (Ext: 'HAP'; Prog: 'PAH     .EXE'; Cmd:('e         ', 'e         ', Unsupported , Unsupported , 'l         ');
                                           Pth: Unsupported;
                                           Pwd: Unsupported ),
        (Ext: 'HPK'; Prog: 'HPACK   .EXE'; Cmd:('x -on     ', 'x -oa     ', 'p         ', 't         ', 'v         ');
                                           Pth: ' -da '    ;
                                           Pwd: ' -c  '     ),
        (Ext: 'HYP'; Prog: 'HYPER   .EXE'; Cmd:('-x        ', '-xo       ', Unsupported , Unsupported , '-v        ');
                                           Pth: 'p    '    ;
                                           Pwd: Unsupported ),
        (Ext: 'LZH'; Prog: 'LHA     .EXE'; Cmd:('e /m+     ', 'e /m+c+   ', 'p /m+     ', 't /m+     ', 'l         ');
                                           Pth: 'x+   '    ;
                                           Pwd: Unsupported ),
        (Ext: 'PAK'; Prog: 'PAK     .EXE'; Cmd:('e/WO      ', 'e/WA      ', 'p         ', 't         ', 'l         ');
                                           Pth: '/PATH'    ;
                                           Pwd: '/g=  '     ),
        (Ext: 'RAR'; Prog: 'UNRAR   .EXE'; Cmd:('e -u      ', 'e -o+     ', 'p         ', 't         ', 'l         ');
                                           Pth: '<x   '    ;
                                           Pwd: ' -p  '     ),
        (Ext: 'SQZ'; Prog: 'SQZ     .EXE'; Cmd:('e /o0     ', 'e /o1     ', 'p         ', 't         ', 'l         ');
                                           Pth: '<x   '    ;
                                           Pwd: Unsupported ),
        (Ext: 'UC2'; Prog: 'UC      .EXE'; Cmd:('E         ', 'E -F      ', '$PRF      ', 'T         ', 'V         ');
                                           Pth: ' -S  '    ;
                                           Pwd: Unsupported ),
        (Ext: 'ZIP'; Prog: 'PKUNZIP .EXE'; Cmd:('-n        ', '-o        ', '-c        ', '-t        ', '-v        ');
                                           Pth: ' -d  '    ;
                                           Pwd: ' -s  '     ),
        (Ext: 'ZOO'; Prog: 'ZOO     .EXE'; Cmd:('e:O       ', 'e:OS      ', 'e:p       ', 'e:N       ', 'lC        ');
                                           Pth: '//   '    ;
                                           Pwd: Unsupported )
       )   {NOTE: if the first character of an option string is a '<', then it means that the following letter
           should REPLACE the first letter of the command string and not be added to it like the other options.}
      );

var
    CfgData : ArcCfg;
    GUSfile : file;


procedure ReadData (var F   : file;
                    var Data: ArcCfg);
 begin
  {$I-} reset(F, 1); {$I+}
  if IOresult <> 0
   then begin
         writeln('Can''t open ', GUSname);
         Halt(1);
        end;
  {$I-} seek(F, filesize(F)-sizeof(ArcCfg)); {$I+}
  if IOresult <> 0
   then begin
         writeln('Problem: cannot seek to byte location ', filesize(F), ' - ', sizeof(ArcCfg));
         Halt(1);
        end;
  {$I-} BlockRead(F, Data, sizeof(ArcCfg)); {$I+}
  if IOresult <> 0
   then begin
         writeln('Problem: cannot read ', sizeof(ArcCfg), ' bytes in ', GUSname, ' at offset ', filepos(F));
         Halt(1);
        end;
  close(F);
  writeln('Reading configuration information from ', GUSname)
 end; {ReadData}


procedure AppendData (var F   : file;
                      var Data: ArcCfg);
 begin
  Data.Marker:=CfgMarker;
  reset(F, 1);
  seek(F, filesize(F));
  BlockWrite(F, Data, sizeof(ArcCfg));
  close(F);
  writeln('Appending configuration information to ', GUSname)
 end; {AppendData}


procedure UpdateData (var F   : file;
                      var Data: ArcCfg);
 begin
  Data.Marker:=CfgMarker;
  reset(F, 1);
  seek(F, filesize(F)-sizeof(ArcCfg));
  BlockWrite(F, Data, sizeof(ArcCfg));
  close(F);
  writeln('Updating configuration information in ', GUSname)
 end; {UpdateData}

begin {=MAIN=}
 assign(GUSfile, GUSname);
 ReadData(GUSfile, CfgData);
 if CfgData.Marker = CfgMarker
  then UpdateData(GUSfile, ArcInfo)
  else AppendData(GUSfile, ArcInfo)
end.
