home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / perqb / pq2par.pas < prev    next >
Pascal/Delphi Source File  |  2020-01-01  |  42KB  |  1,322 lines

  1. module KermitParameters;
  2.  
  3. exports
  4.  
  5. imports KermitGlobals from KermitGlobals;
  6. imports MenuUtils from MenuUtils;
  7. imports FileDefs from FileDefs;
  8.  
  9. const   MaxParts     =   30;
  10.  
  11. { NBNBNB!! These type definitions MUST ALWAYS correspond to the 
  12.   sequence of the menu items in the Kermit.MENU file }
  13. type    
  14.  
  15.         MainCommType =  (NoMainComm,
  16.                          MainHelp,
  17.                          MainSend,
  18.                          MainReceive, 
  19.                          MainGet,
  20.                          MainExit,
  21.                          MainQuit,
  22.                          MainPush,
  23.                          MainTake,
  24.                          MainConnect,
  25.                          MainBye,
  26.                          MainFinish,
  27.                          MainRemote,
  28.                          MainLocal,
  29.                          MainServer,
  30.                          MainSet,
  31.                          MainShow,
  32.                          MainStatus,
  33.                          MainUsage,
  34.                          MainNotFound,
  35.                          MainNotUnique,
  36.                          MainEmptyLine,
  37.                          MainSwitch,
  38.                          MainIllegChar);
  39.  
  40.         TermCommType =  (NoTermComm,
  41.                          TermHelp,
  42.                          TermQuit,
  43.                          TermSetBaud, 
  44.                          TermSetStop,
  45.                          TermSetParity,
  46.                          TermSaveFile,
  47.                          TermOnSave,
  48.                          TermOffSave,
  49.                          TermOnXonXoff,
  50.                          TermOffXonXoff);
  51.  
  52.         SetCommType =   (NoSetComm,
  53.                          SetHelp,
  54.                          SetBaud,
  55.                          SetParity,
  56.                          SetStop,
  57.                          SetSend,
  58.                          SetReceive,
  59.                          SetFileHeader,
  60.                          Set8BitQuote,
  61.                          SetUse8BitQuote,
  62.                          SetRepFix,
  63.                          SetUseRepFix,
  64.                          SetFileWarning,
  65.                          SetRetry,
  66.                          SetLogFile,
  67.                          SetLog,
  68.                          SetDebugging,                         
  69.                          SetBreakTime,
  70.                          SetEscape,
  71.                          SetNotFound,
  72.                          SetNotUnique,
  73.                          SetEmptyLine,
  74.                          SetSwitch,
  75.                          SetIllegChar);
  76.  
  77.         SendRecType =   (NoSendRec,
  78.                          SRHelp,
  79.                          SRPacketLength,
  80.                          SRCtlQuote,
  81.                          SRStartOfPacket,
  82.                          SRTimeOut,
  83.                          SREndOfLine,
  84.                          SRPadding,
  85.                          SRPadChar);
  86.  
  87.         FHeaderType =   (NoFHeader,
  88.                          FHHelp,
  89.                          FHNord,
  90.                          FHNoTrunc,
  91.                          FHTrunc,
  92.                          FHTrans);
  93.  
  94.         TransType   =   (NoTrans,
  95.                          TransHelp,
  96.                          TransLower,
  97.                          TransUpper,
  98.                          TransOff);
  99.         
  100.         RetryType   =   (NoRetryType,
  101.                          RetryHelp,
  102.                          RetryInitial,
  103.                          RetryPacket,
  104.                          RetryCommand);
  105.  
  106.         OnOffType   =   (NoOnOff,
  107.                          OnOffHelp,
  108.                          On,
  109.                          Off,
  110.                          OnOfNotFound,
  111.                          OnOfNotUnique,
  112.                          OnOfEmptyLine,
  113.                          OnOfSwitch,
  114.                          OnOfIllegChar);
  115.         
  116.         EmptyType   =   (NoEmpty,
  117.                          EmptyHelp,
  118.                          EmptyAndVoid,
  119.                          EmpNotFound,
  120.                          EmpNotUnique,
  121.                          EmptyLine,
  122.                          EmptySwitch,
  123.                          EmptyIllegChar);
  124.  
  125.         SpeedType   =   (NoSpeed,
  126.                          SpHelp,
  127.                          Sp110,
  128.                          Sp150,
  129.                          Sp300,
  130.                          Sp600,
  131.                          Sp1200,
  132.                          Sp2400,
  133.                          Sp4800,
  134.                          Sp9600,
  135.                          SpNotFound,
  136.                          SpNotUnique,
  137.                          SpEmptyLine,
  138.                          SpSwitch,
  139.                          SpIllegChar);
  140.  
  141.         ParityType  =   (NoParComm,
  142.                          ParHelp,
  143.                          NoKParity,
  144.                          EvenKParity,
  145.                          OddKParity,
  146.                          MarkKParity,
  147.                          SpaceKParity,
  148.                          ParNotFound,
  149.                          ParNotUnique,
  150.                          ParEmptyLine,
  151.                          ParSwitch,
  152.                          ParIllegChar);
  153.  
  154.  
  155.         StopType    =   (NoStopComm,
  156.                          StopHelp,
  157.                          SyncrCmd,
  158.                          Stop1Cmd,
  159.                          Stop1x5Cmd,
  160.                          Stop2Cmd,
  161.                          StopNotFound,
  162.                          StopNotUnique,
  163.                          StopEmptyLine,
  164.                          StopSwitch,
  165.                          StopIllegChar);
  166.  
  167.         TruncPart   =   1..MaxParts; 
  168.         TListType   =   array [TruncPart] of integer;
  169. const   
  170.         NMainComm   =   ord(MainNotFound)-1;
  171.         NTermComm   =   ord(TermOffXonXoff);
  172.         NSetComm    =   ord(SetNotFound)-1;
  173.         NOnOff      =   ord(OnOfNotFound)-1;
  174.         NSpeeds     =   ord(SpNotFound)-1;
  175.         NParityComm =   ord(ParNotFound)-1;
  176.         NStopComm   =   ord(StopNotFound)-1;
  177.         NEmptyComm  =   ord(EmpNotFound)-1;
  178.         
  179. var
  180.     RootMenu        :   pMenuEntry; { Pointer to root of menu structure }
  181.  
  182.     Parity          :   ParityType; { Current parity setting }
  183.     Baud            :   SpeedType;  { Current baud rate setting }
  184.     StopBits        :   StopType;   { Current number of stop bits }
  185.  
  186.     SendSOH         :   char;       { Start-Of-Packet to send }
  187.     SendPSize       :   integer;    { Packet size he wants }
  188.     SendTimeOut     :   integer;    { Time-out he wants }
  189.     SendNPad        :   integer;    { Number of padding-characters he wants }
  190.     SendPadChar     :   char;       { The padding character he wants }
  191.     SendEOL         :   char;       { The EOL he wants }
  192.     SendQuote       :   char;       { The Quote char he wants }
  193.  
  194.     RecSOH          :   char;       { Start-Of-Packet I want }
  195.     RecPSize        :   integer;    { Max packet size I can handle }
  196.     RecTimeOut      :   integer;    { time-out I want }
  197.     RecNPad         :   integer;    { Padding I want }
  198.     RecPadChar      :   char;       { Padchar I want }
  199.     RecEOL          :   char;       { End-Of-Line I propose }
  200.     RecQuote        :   char;       { Control quote I propose }
  201.  
  202.     Use8Quote       :   boolean;    { Is 8-bit quoting in use? }
  203.     Bit8Quote       :   char;       { 8-bit Quote character to be used }
  204.  
  205.     UseRepFix       :   boolean;    { Is repeat prefixing in use? }
  206.     RepFix          :   char;       { Repeat prefix to be used }
  207.  
  208.     NowUse8Quote,
  209.     NowUseRepFix    :   boolean;    { - enabled during this transfer?? }
  210.  
  211.     Debug           :   boolean;    { Enable debug output }
  212.     FileWarning     :   boolean;    { Avoid overwriting existing file if TRUE}
  213.     XonXoff         :   boolean;    { use XonXoff handshaking }
  214.     FileSave        :   boolean;    { Log terminal session to file }
  215.     SaveFile        :   PathName;
  216.  
  217.     Nord            :   boolean;    { Translate file names for NORD }
  218.     NumTrunc, 
  219.     OldTrunc        :   integer;    { Truncation list }
  220.     TruncList       :   TListType;
  221.     Translate       :   TransType;  { Case translation }
  222.  
  223.     MaxTryPack      :   Integer;    { Retry limits before giving up }  
  224.     MaxTryInit      :   Integer;
  225.     MaxTryComm      :   Integer;
  226.     
  227.     LongWait        :   Integer; 
  228.  
  229.     LocalKermit     :   boolean;    { Is this Kermit a local one? }
  230.     DisableTimOut   :   boolean;    { TRUE if timeout is disabled }
  231.     Idev,Odev       :   integer;    { Which devices to use for line }
  232.  
  233.     LegalPackets,                           { valid packet types }
  234.     CtlMapping,                             { Control character mapping }
  235.     OkQuote,                                { Valid quote characters }
  236.     Quotes          :   set of char;        { Quotes presently in use }
  237.  
  238.     EscKey          :   char;       { Char to type to escape CONNECT }
  239.  
  240.     procedure   SetInitPars( var Pack : Packet );
  241.     procedure   ReadPars ( VAR Pack : Packet );
  242.     procedure   InitParameters;
  243.     procedure   CleanupParameters;
  244.  
  245.     procedure   SetCommand( PList : pPListEntry );
  246.     procedure   ShowCommand( PList : pPListEntry );
  247.     procedure   StatusCommand;
  248.     
  249.     procedure   ShowKey( Ch : char );
  250.  
  251.  
  252. {================} private {=================}
  253.     
  254. imports KermitLineIO from KermitLineIO;
  255. imports KermitConnect from KermitConnect;
  256. imports IOErrors from IOErrors;
  257. imports IO_Unit from IO_Unit;
  258. imports IO_Others from IO_Others;
  259.     
  260.     exception NotInt;
  261.  
  262.     procedure EatSpaces( var S : String );
  263.     begin 
  264.         if S<>'' then
  265.             while (S[1]=' ') and (length(S)>1) do
  266.                 Delete( S, 1, 1);
  267.         if S=' ' then 
  268.             S := '';
  269.     end;
  270.  
  271.     function StrToInt( VAR S : String ):integer;
  272.     var I :integer;
  273.         done : boolean;
  274.     begin              
  275.         I := 0; 
  276.         done := false;
  277.         EatSpaces( S );
  278.         if S='' then 
  279.             raise NotInt
  280.         else begin
  281.             if not (S[1] in ['0'..'9']) then
  282.                 raise NotInt
  283.             else
  284.                 repeat
  285.                     if not (S[1] in ['0'..'9']) then
  286.                         done := true
  287.                     else begin
  288.                         I := I*10 + ord(S[1]) - ord('0');
  289.                         Delete( S, 1, 1);
  290.                         Done := S='';
  291.                     end;
  292.                 until done;
  293.         end;
  294.         StrToInt := I;
  295.     end;
  296.   
  297.     function CtrlChar( S:String ):integer;
  298.         
  299.         handler NotInt;
  300.         begin
  301.             CtrlChar := -1;
  302.             exit( CtrlChar );
  303.         end;
  304.  
  305.     var R : integer;
  306.     begin
  307.         if length( S )=0 then
  308.             R := -1
  309.         else 
  310.             if length( S )=1 then
  311.                 R := ord( S[1] )
  312.             else 
  313.                 if S[1]='#' then begin
  314.                     Delete( S, 1, 1);
  315.                     R := StrToInt( S );
  316.                 end else 
  317.                     if S[1]='^' then
  318.                         if S[2] in ['@'..'^'] then
  319.                             R := ord( Ctl(S[2]) )
  320.                         else
  321.                             R := -1;
  322.         CtrlChar := R;
  323.     end;
  324.  
  325.     procedure DoSetRetry( PList : pPListEntry );
  326.     var Val : integer;
  327.  
  328.         handler NotInt;
  329.         begin
  330.             writeln('Number of retries not numeric!');
  331.             exit( DoSetRetry );
  332.         end;
  333.  
  334.     begin
  335.         Val := StrToInt( PList^.NextPList^.Arg );
  336.         if not (Val in [1..30]) then
  337.             writeln('Illegal  number of retries!')
  338.         else
  339.             case recast( PList^.Selection, RetryType ) of
  340.             
  341.                 RetryInitial:   MaxTryInit := Val;
  342.                 RetryPacket:    MaxTryPack := Val;
  343.                 RetryCommand:   MaxTryComm := Val;
  344.                 otherwise:      ;
  345.             end;
  346.     end;
  347.  
  348.  
  349.     procedure SetPSize( Arg : String; var PSize : integer );
  350.     var Val : integer;
  351.  
  352.         handler NotInt;
  353.         begin
  354.             writeln('Packet length not numeric!');
  355.             exit( SetPSize );
  356.         end;
  357.  
  358.     begin
  359.         Val := StrToInt( Arg );
  360.         if not (Val in [10..94]) then
  361.             writeln( 'Illegal packet length!')
  362.         else
  363.             PSize := Val;
  364.     end;
  365.  
  366.  
  367.     procedure SetQuote( Arg : String; var Quote : char );
  368.     var Val : integer;
  369.     begin
  370.         Val := CtrlChar( Arg );
  371.         if Val=-1 then
  372.             writeln( 'Control quote ordinal value is not numeric!' )
  373.         else
  374.             if not ( chr(Val) in OkQuote ) then
  375.                 writeln( 'Illegal quote character')
  376.             else
  377.             if chr(Val) in Quotes then
  378.                 writeln( 'Character is already in use as another quote' )
  379.             else
  380.                 Quote := chr( Val );
  381.     end;
  382.  
  383.  
  384.     procedure SetSOH( Arg : String; var SOH : char );
  385.     var Val : integer;
  386.     begin
  387.         Val := CtrlChar( Arg );
  388.         if Val=-1 then
  389.             writeln( 'Start-of-packet ordinal value is not numeric!' )
  390.         else
  391.             if not ( Val in [0..31,127,128..159,255]) then
  392.                 writeln
  393.                     ('Start-of-packet character must be a control character!')
  394.             else
  395.                 SOH := chr( Val );
  396.     end;
  397.  
  398.         
  399.     procedure SetTimeOut( Arg : String; var TimeOut : integer );
  400.     var Val : integer;
  401.  
  402.         handler NotInt;
  403.         begin
  404.             writeln('Timeout interval not numeric!');
  405.             exit( SetTimeOut );
  406.         end;
  407.  
  408.     begin
  409.         if Arg='' then
  410.             TimeOut := 0
  411.         else begin
  412.             Val := StrToInt( Arg );
  413.             if not (Val in [0..94]) then
  414.                 writeln( 'Illegal timeout interval!')
  415.             else
  416.                 TimeOut := Val;
  417.         end;
  418.     end;
  419.  
  420.         
  421.     procedure SetEOL( Arg : String; var EOL : char );
  422.     var Val : integer;
  423.     begin
  424.         Val := CtrlChar( Arg );
  425.         if Val=-1 then
  426.             writeln( 'End-of-line ordinal value is not numeric!' )
  427.         else
  428.             EOL := chr( Val );
  429.     end;
  430.  
  431.         
  432.     procedure SetNPad( Arg : String; var NPad : integer );
  433.     var Val : integer;
  434.  
  435.         handler NotInt;
  436.         begin
  437.             writeln('Padding value not numeric!');
  438.             exit( SetNPad );
  439.         end;
  440.  
  441.     begin
  442.         Val := StrToInt( Arg );
  443.         if not (Val in [0..94]) then
  444.             writeln( 'Illegal padding value!')
  445.         else
  446.             NPad := Val;
  447.     end;
  448.  
  449.         
  450.     procedure SetPadChar( Arg : String; var PadChar : char );
  451.     var Val : integer;
  452.     begin
  453.         Val := CtrlChar( Arg );
  454.         if Val=-1 then
  455.             writeln( 'Pad character ordinal value is not numeric!' )
  456.         else
  457.             PadChar := chr( Val );
  458.     end;
  459.  
  460.  
  461.     procedure ShowKey( Ch : char );
  462.     begin
  463.         if Land( ord( Ch ), #200 ) <>0 then begin
  464.             write( 'CTRL-' );
  465.             ch := chr( land( ord( ch ), #177 ) );
  466.         end;
  467.         if Ch='' then write('OOPS') else
  468.         if Ch='' then write('INS') else
  469.         if Ch='    ' then write('TAB') else
  470.         if Ch='' then write('HELP') else
  471.         if Ch='' then write('DEL') else
  472.         if Ch='' then write('BACKSPACE') else begin
  473.             if Ch in ['A'..'Z'] then
  474.                 write( 'SHIFT-' );
  475.             write( Ch );
  476.         end;
  477.     end;
  478.  
  479.  
  480.     procedure SetEscChar( Arg : String );
  481.     var Val : integer;
  482.     begin
  483.         if Arg='' then begin
  484.             IOKeyClear;
  485.             write( 'Press the key which you want as escape character:' );
  486.             while IOCRead( KeyBoard, EscKey ) <> IOEIOC do ;
  487.             writeln;
  488.             write( 'Escape character set as: ');
  489.             ShowKey( EscKey );
  490.             writeln;
  491.         end else begin
  492.             Val := CtrlChar( Arg );
  493.             if Val=-1 then
  494.                 writeln( 'Escape character ordinal value is not numeric!')
  495.             else
  496.                 EscKey := chr( Val );
  497.         end;
  498.     end;
  499.             
  500.         
  501.     procedure DoSetSend( PList : pPListEntry );
  502.     var TempQuote : set of char;
  503.     begin
  504.         with PList^ do
  505.         case recast( Selection, SendRecType ) of
  506.             SRPacketLength: SetPSize( NextPList^.Arg, SendPSize );
  507.             SRCtlQuote:
  508.                 begin
  509.                     TempQuote := Quotes;     
  510.                     Quotes := [];   { SendQuote may be same as 8-bi or repeat }
  511.                     SetQuote( NextPList^.Arg, SendQuote );
  512.                     Quotes := TempQuote;
  513.                 end;      
  514.             SRStartOfPacket:SetSOH( NextPList^.Arg, SendSOH );
  515.             SRTimeOut:      SetTimeOut( NextPList^.Arg, SendTimeOut );
  516.             SREndOfLine:    SetEOL( NextPList^.Arg, SendEOL );
  517.             SRPadding:      SetNPad( NextPList^.Arg, SendNPad );
  518.             SRPadChar:      SetPadChar( NextPList^.Arg, SendPadChar );
  519.             otherwise:      ;
  520.         end;
  521.     end;
  522.  
  523.     procedure DoSetReceive( PList : pPListEntry );
  524.     begin
  525.         with PList^ do
  526.         case recast( Selection, SendRecType ) of
  527.             SRPacketLength: SetPSize( NextPList^.Arg, RecPSize );
  528.             SRCtlQuote:
  529.                 begin
  530.                     Quotes := Quotes - [RecQuote];      
  531.                     SetQuote( NextPList^.Arg, RecQuote );
  532.                     Quotes := Quotes + [RecQuote];
  533.                 end;
  534.             SRStartOfPacket:SetSOH( NextPList^.Arg, RecSOH );
  535.             SRTimeOut:      SetTimeOut( NextPList^.Arg, RecTimeOut );
  536.             otherwise:      ;
  537.         end;
  538.     end;
  539.  
  540.     procedure DoTruncation( PList : pPListEntry );
  541.     var NewTrunc : integer;
  542.         NewTList : TListType;
  543.         
  544.         handler NotInt;
  545.         begin
  546.             writeln('Truncation value must be an integer!');
  547.             exit( DoTruncation );
  548.         end;
  549.  
  550.     begin
  551.         with PList^ do
  552.             if Arg='' then
  553.                 NumTrunc := OldTrunc
  554.             else begin
  555.                 NewTrunc := 0;
  556.                 EatSpaces( Arg );
  557.                 while Arg<>'' do begin
  558.                     NewTrunc := NewTrunc + 1;
  559.                     NewTList[NewTrunc] := StrToInt( Arg );
  560.                     EatSpaces( Arg );
  561.                     if Arg<>'' then
  562.                         if Arg[1]=',' then 
  563.                             Delete( Arg, 1, 1 );
  564.                      EatSpaces( Arg );
  565.                 end;
  566.                 NumTrunc := NewTrunc;
  567.                 OldTrunc := NewTrunc;
  568.                 TruncList := NewTList;
  569.             end;
  570.     end;
  571.  
  572.     procedure DoSetFHeader( PList : pPListEntry );
  573.     Const   NordWarning =   'Warning: NORD transformation is ON!';
  574.             AsLongAs    =   
  575.             'is temporarily active for as long as NORD is ON in any case!';
  576.     begin
  577.         with PList^ do
  578.         case recast( Selection, FHeaderType ) of
  579.             FHNord:
  580.                 Nord := recast( NextPList^.Selection, OnOffType) =On;
  581.             FHNoTrunc:
  582.                 begin
  583.                     OldTrunc := NumTrunc;
  584.                     NumTrunc := 0;
  585.                     if Nord then begin
  586.                         writeln( NordWarning );
  587.                         writeln('  NO-TRUNCATE ', AsLongAs );
  588.                         writeln;
  589.                     end;
  590.                 end;
  591.             FHTrunc:
  592.                 begin
  593.                     DoTruncation( NextPList );
  594.                     if Nord then begin
  595.                         writeln( NordWarning );
  596.                         write  ('  TRUNCATE will not take effect until');
  597.                         writeln(' NORD is turned OFF!');
  598.                         writeln;
  599.                     end;
  600.                 end;
  601.             FHTrans:
  602.                 begin
  603.                     Translate := recast( NextPList^.Selection, TransType );
  604.                     if Nord then begin
  605.                         writeln( NordWarning );
  606.                         writeln( '  CONVERT UPPER ', AsLongAs );
  607.                         writeln;
  608.                     end;
  609.                 end;    
  610.             otherwise: ;
  611.         end;
  612.     end;
  613.  
  614.     procedure DoSet8Quote( PList : pPListEntry );
  615.     var ch : char;
  616.     begin
  617.         Quotes := Quotes - [Bit8Quote];
  618.         if PList^.Arg='' then
  619.             Bit8Quote := '&'
  620.         else begin
  621.             ch := PList^.Arg[1];
  622.             if ch in OkQuote then begin
  623.                 if ch in Quotes then
  624.                     writeln
  625.                     ('Character is already in use as another quote' )
  626.                 else
  627.                     Bit8Quote := ch;
  628.             end
  629.             else
  630.                 writeln('Illegal quote character!');
  631.         end;
  632.         Quotes := Quotes + [Bit8Quote];
  633.     end;
  634.  
  635.     procedure DoSetRepFix( PList : pPListEntry );
  636.     var ch : char;
  637.     begin
  638.         Quotes := Quotes - [RepFix];
  639.         if PList^.Arg='' then
  640.             RepFix := '&'
  641.         else begin
  642.             ch := PList^.Arg[1];
  643.             if ch in OkQuote then begin
  644.                 if ch in Quotes then
  645.                     writeln
  646.                     ('Character is already in use as another quote' )
  647.                 else
  648.                     RepFix := ch;
  649.             end
  650.             else
  651.                 writeln('Illegal quote character!');
  652.         end;
  653.         Quotes := Quotes + [RepFix];
  654.     end;
  655.             
  656.     procedure   SetCommand( PList : pPListEntry );
  657.     var SetParm : SetCommType;
  658.     begin
  659.         SetParm := recast( PList^.Selection, SetCommType );
  660.         PList := PList^.NextPList;
  661.         
  662.         case SetParm of
  663.  
  664.             SetStop:
  665.                 begin
  666.                     StopBits := recast( PList^.Selection, StopType );
  667.                     RefreshStopBits;
  668.                 end;
  669.  
  670.             SetParity:
  671.                 begin
  672.                     Parity := recast( PList^.Selection, ParityType );
  673.                     RefreshParity;
  674.                 end;
  675.  
  676.             SetBaud:
  677.                 begin
  678.                     Baud := recast( PList^.Selection, SpeedType);
  679.                     RefreshBaud;
  680.                 end;
  681.  
  682.             SetFileWarning:
  683.                 begin
  684.                     FileWarning :=
  685.                         recast( PList^.Selection, OnOffType ) = On;
  686.                 end;
  687.  
  688.             SetLog:
  689.                 begin
  690.                     FileSave :=
  691.                         recast( PList^.Selection, OnOffType ) = On;
  692.                 end;
  693.             
  694.             SetLogFile:
  695.                 begin
  696.                     SetSaveFile( PList^.Arg );
  697.                 end;
  698.  
  699.             SetDebugging:
  700.                 begin
  701.                     Debug :=
  702.                         recast( PList^.Selection, OnOffType ) = On;
  703.                 end;
  704.             
  705.             SetSend:
  706.                 DoSetSend( PList );
  707.                 
  708.             SetReceive:
  709.                 DoSetReceive( PList );
  710.  
  711.             SetFileHeader:
  712.                 DoSetFHeader( PList );
  713.                 
  714.             Set8BitQuote:
  715.                 DoSet8Quote( PList );
  716.                 
  717.             SetUse8BitQuote:
  718.                 Use8Quote := recast( PList^.Selection, OnOffType ) = On;
  719.                 
  720.             SetRepFix:
  721.                 DoSetRepFix( PList );
  722.                 
  723.             SetUseRepFix:
  724.                 UseRepFix := recast( PList^.Selection, OnOffType ) = On;
  725.                 
  726.             SetRetry:
  727.                 DoSetRetry( PList );
  728.                 
  729.             SetBreakTime:
  730.                 writeln('Send break is not implemented!');
  731.  
  732.             SetEscape:
  733.                 SetEscChar( PList^.Arg );
  734.             
  735.             otherwise:
  736.                 writeln('Bad SET alternative: ', ord( SetParm ) );
  737.         end;
  738.     end;
  739.  
  740.     procedure ShowOnOff( OnValue : boolean );
  741.     begin
  742.         if OnValue then 
  743.             write('ON')
  744.         else
  745.             write('OFF');
  746.     end;
  747.  
  748.     procedure ShowStop;
  749.     begin
  750.         if StopBits=SyncrCmd then
  751.             writeln( 'SYNCHRONOUS mode, no stop bits' )
  752.         else begin
  753.             write('Number of STOP-BITS = ');
  754.             case StopBits of 
  755.                 Stop1Cmd:   writeln('1');
  756.                 Stop1x5Cmd: writeln('1.5');
  757.                 Stop2Cmd:   writeln('2');
  758.                 otherwise:  writeln('invalid, code: ',ord(StopBits));
  759.             end;
  760.         end;
  761.     end;
  762.  
  763.     procedure ShowParity;
  764.     begin
  765.         write( 'PARITY check/generation = ' );
  766.         case Parity of
  767.             NoKParity:      writeln('NONE');
  768.             EvenKParity:    writeln('EVEN');
  769.             OddKParity:     writeln('ODD');
  770.             MarkKParity:    writeln('MARK (1)');
  771.             SpaceKParity:   writeln('SPACE (0)');
  772.             otherwise:      writeln('invalid, code: ',ord(Parity));
  773.         end;
  774.     end;
  775.  
  776.     procedure ShowBaud;
  777.     begin
  778.         write( 'BAUDrate = ' );
  779.         case Baud of
  780.             SP110:      write('110');
  781.             SP150:      write('150');
  782.             SP300:      write('300');
  783.             SP600:      write('600');
  784.             SP1200:     write('1200');
  785.             SP2400:     write('2400');
  786.             SP4800:     write('4800');
  787.             SP9600:     write('9600');
  788.             otherwise:  writeln('invalid, code: ',ord(Baud));
  789.         end;
  790.         if Baud in [SP110..SP9600] then 
  791.             writeln(' bps');
  792.     end;
  793.     
  794.     procedure ShowFWarning;
  795.     begin
  796.         write( 'FILE-WARNING = ');
  797.         ShowOnOff( FileWarning );
  798.         writeln;
  799.     end;
  800.     
  801.     procedure ShowDebug;
  802.     begin
  803.         write( 'DEBUG output = ');
  804.         ShowOnOff( Debug );
  805.         writeln;
  806.     end;
  807.     
  808.     procedure ShowUse8Quote;
  809.     begin
  810.         write( 'USE-8-BIT-QUOTE = ');
  811.         if Use8Quote then
  812.             write('AUTO') 
  813.         else
  814.             write('OFF');
  815.         writeln;
  816.     end;
  817.  
  818.     procedure ShowUseRepFix;
  819.     begin
  820.         write( 'USE-REPEAT-PREFIX = ');
  821.         if UseRepFix then
  822.             write('AUTO') 
  823.         else
  824.             write('OFF');
  825.         writeln;
  826.     end;
  827.  
  828.     procedure ShowLog;
  829.     begin
  830.         write( 'LOG session to file = ' );
  831.         ShowOnOff( FileSave );
  832.         writeln;
  833.     end;
  834.  
  835.     procedure ShowLFile;
  836.     begin
  837.         if SaveFile='' then
  838.             writeln('No log file active')
  839.         else
  840.             writeln('LOG-FILE = ',SaveFile);
  841.     end;
  842.  
  843.     procedure DisplayChar( Ch : Char );
  844.     var Ch1 : char;
  845.     begin
  846.         Ch1 := Chr( LAnd( Ord( Ch ), #177 ) );
  847.         if ch1<' ' then 
  848.             write( 'Ctrl-', Ctl( Ch1 ) )
  849.         else
  850.             if ord(Ch1)=177 then
  851.                 write( 'DEL' )
  852.             else
  853.                 write('''',Ch1,'''');
  854.         if Ch<>Ch1 then write(' (Hi bit=1)');
  855.     end;
  856.  
  857.     procedure Show8Quote;
  858.     begin
  859.         write('8-BIT-QUOTE = ');
  860.         DisplayChar( Bit8Quote );
  861.         writeln;
  862.     end;
  863.  
  864.     procedure ShowRepFix;
  865.     begin
  866.         write('REPEAT-PREFIX = ');
  867.         DisplayChar( RepFix );
  868.         writeln;
  869.     end;
  870.  
  871.     procedure ShowEscChar;
  872.     begin
  873.         write('ESCAPE-CHARACTER = ');
  874.         ShowKey( EscKey );
  875.         writeln;
  876.     end;
  877.  
  878.     procedure ShowPSize( PSize : integer );
  879.     begin
  880.         writeln('  max. PACKET-LENGTH = ', PSize:2 );
  881.     end;
  882.     
  883.     procedure ShowTOut( TimeOut : integer );
  884.     begin
  885.         writeln('  TIME-OUT after ',TimeOut:2,' seconds');
  886.     end;
  887.  
  888.     procedure ShowQuote( Quote : char );
  889.     begin
  890.         writeln('  control QUOTE = ''',Quote,'''');
  891.     end;
  892.     
  893.     procedure ShowSOH( SOH : char );
  894.     begin
  895.         write('  START-OF-PACKET = ');
  896.         DisplayChar( SOH );
  897.         writeln;
  898.     end;
  899.     
  900.     procedure ShowEOL( EOL : char );
  901.     begin
  902.         write('  END-OF-LINE = ');
  903.         DisplayChar( EOL );
  904.         writeln;
  905.     end;
  906.  
  907.     procedure ShowPad( Padding : integer );
  908.     begin
  909.         writeln('  PADDING between packets = ', Padding:2,' characters');
  910.     end;
  911.  
  912.     procedure ShowPChar( PadChar : char );
  913.     begin
  914.         write('  PADCHAR = ');
  915.         DisplayChar( PadChar );
  916.         writeln;
  917.     end;
  918.  
  919.     procedure ShowSend;
  920.     begin
  921.         writeln( 'SEND parameters:');
  922.         ShowPSize(  SendPSize ); 
  923.         ShowTOut(   SendTimeOut );
  924.         ShowQuote(  SendQuote );
  925.         ShowSOH(    SendSOH );
  926.         ShowEOL(    SendEOL );
  927.         ShowPad(    SendNPad );
  928.         ShowPChar(  SendPadChar );
  929.     end;
  930.  
  931.     procedure ShowReceive;
  932.     begin
  933.         writeln( 'RECEIVE parameters:');
  934.         ShowPSize(  RecPSize );         
  935.         ShowTOut(   RecTimeOut );
  936.         ShowQuote(  RecQuote );
  937.         ShowSOH(    RecSOH );
  938.     end;
  939.  
  940.     procedure ShowFHeader;
  941.     var I : integer;
  942.     begin
  943.         writeln( 'FILE-HEADER transformations: ');
  944.         write(   '  NORD transformation = ');
  945.         if Nord then begin
  946.             writeln( '  ON');
  947.             writeln( '   (temporary NO-TRUNCATE and CONVERT UPPER)');
  948.         end else begin
  949.             writeln( '  OFF');
  950.             if NumTrunc=0 then 
  951.                 writeln('  NO-TRUNCATE of file name')
  952.             else begin
  953.                 write('  TRUNCATE file name ');
  954.                 write( TruncList[1]:1 );
  955.                 for i := 2 to NumTrunc do 
  956.                     write( ',', TruncList[I]:1 );
  957.                 writeln;
  958.             end;
  959.             if Translate=TransOff then 
  960.                 writeln('  CONVERT OFF')
  961.             else begin
  962.                 write('  CONVERT file name into ');
  963.                 case Translate of
  964.                     TransUpper:
  965.                         writeln('UPPER case');
  966.                     TransLower:
  967.                         writeln('LOWER case');
  968.                     otherwise:
  969.                         writeln('<illegal parameter value>');
  970.                 end;
  971.             end;
  972.         end;
  973.     end;
  974.                     
  975.     procedure ShowRetry;
  976.     begin
  977.         writeln( 'RETRY limits:');
  978.         writeln( '  INITIAL-CONNECTION = ',MaxTryInit:2);
  979.         writeln( '  PACKET             = ',MaxTryPack:2);
  980.         writeln( '  COMMANDS           = ',MaxTryComm:2);
  981.     end;
  982.  
  983.     procedure   ShowCommand( PList : pPListEntry );
  984.     var SetParm : SetCommType;
  985.     begin
  986.         SetParm := recast( PList^.Selection, SetCommType );
  987.         PList := PList^.NextPList;
  988.         
  989.         writeln;
  990.         case SetParm of
  991.  
  992.             SetStop:
  993.                 ShowStop;
  994.  
  995.             SetParity:
  996.                 ShowParity;
  997.  
  998.             SetBaud:
  999.                 ShowBaud;
  1000.  
  1001.             SetFileWarning:
  1002.                 ShowFWarning;
  1003.  
  1004.             SetLog:
  1005.                 ShowLog;
  1006.             
  1007.             SetLogFile:
  1008.                 ShowLFile;
  1009.  
  1010.             SetDebugging:
  1011.                 ShowDebug;
  1012.  
  1013.             SetSend:
  1014.                 ShowSend;
  1015.  
  1016.             SetReceive:
  1017.                 ShowReceive;
  1018.             
  1019.             SetFileHeader:
  1020.                 ShowFHeader;
  1021.     
  1022.             Set8BitQuote:
  1023.                 Show8Quote;
  1024.                 
  1025.             SetUse8BitQuote:
  1026.                 ShowUse8Quote;
  1027.  
  1028.             SetRepFix:
  1029.                 ShowRepFix;
  1030.                 
  1031.             SetUseRepFix:
  1032.                 ShowUseRepFix;
  1033.  
  1034.             SetRetry:
  1035.                 ShowRetry;
  1036.                 
  1037.             SetBreakTime:
  1038.                 writeln('Send break is not implemented!');
  1039.  
  1040.             SetEscape:
  1041.                 ShowEscChar;
  1042.  
  1043.             SetNotFound:
  1044.                 begin
  1045.                     ShowStop;
  1046.                     ShowParity;
  1047.                     ShowBaud;
  1048.                     ShowFWarning;
  1049.                     ShowLog;
  1050.                     ShowLFile;
  1051.                     ShowDebug;
  1052.                     ShowSend;
  1053.                     ShowReceive;
  1054.                     ShowFHeader;
  1055.                     Show8Quote;
  1056.                     ShowUse8Quote;
  1057.                     ShowRepFix;
  1058.                     ShowUseRepFix;
  1059.                     ShowRetry;
  1060.                     ShowEscChar;
  1061.                 end;
  1062.  
  1063.             otherwise:
  1064.                 writeln('Bad SHOW alternative: ', ord( SetParm ) );
  1065.         end;
  1066.         writeln;
  1067.     end;
  1068.  
  1069.     procedure   StatusCommand;
  1070.     begin
  1071.     end;
  1072.  
  1073.     procedure   SetInitPars( var Pack : Packet );
  1074.         {    Build SendInit packet   }
  1075.     var PackLen : integer;
  1076.     begin
  1077.         with Pack do
  1078.         begin 
  1079.             adjust( Data, 100 );
  1080.  
  1081.             data[1] := ToChar(chr(RecPSize  )); { Max. packet length I handle }
  1082.             data[2] := ToChar(chr(RecTimeOut)); { When I want to be timed out }
  1083.             data[3] := ToChar(chr(RecNPad   )); { How much padding I need     }
  1084.             data[4] := ctl   (chr(RecPadChar)); { My padding character        }
  1085.             data[5] := ToChar(chr(RecEOL)    ); { End-of-line I want          }
  1086.             data[6] :=            RecQuote    ; { control-quote char I want   }
  1087.             data[8]  := '1';                    { Only 1-char checksum        }
  1088.  
  1089.             if (not Use8Quote) or (Parity=NoKParity) then
  1090.                 data[7] :=  'N'                 { No need to use 8-bit quote  }
  1091.             else
  1092.                 data[7] :=        Bit8Quote   ; { 8-bit-quote char I want     }
  1093.  
  1094.             if not UseRepFix then
  1095.                 data[9] :=  ' '                 { Won't use repeat prefix     }
  1096.             else
  1097.                 data[9] :=        RepFix;       { Repeat prefix I want        }
  1098.             
  1099.             PackLen := 9;
  1100.             if Data[9]=' ' then begin
  1101.                 PackLen := 8;
  1102.                 if Data[8]='1' then begin
  1103.                     PackLen := 7;
  1104.                     if Data[7] in [' ','N'] then begin
  1105.                         PackLen := 6;
  1106.                     end;
  1107.                 end;
  1108.             end;  
  1109.             Count := ToChar ( chr( PackLen + 3 ) );
  1110.             adjust( Data, PackLen + 1 );
  1111.             ptype:= PackToCh( SInitPack );
  1112.         end;
  1113.     end;
  1114.  
  1115.     procedure   ReadPars ( VAR Pack : Packet );
  1116.         {  Set parameters according to Pack (Which is SendInit or 
  1117.             Acknowledge packet)
  1118.             and build the corresponding Acknowledge packet }
  1119.     VAR i,PackLen       : integer;
  1120.     begin
  1121.         with Pack do
  1122.         if not ( ChToPack(Ptype) IN [SInitPack,ACKPack] ) then
  1123.         begin
  1124.             CurrState := AbortAll;
  1125.             LocalError
  1126.                 ( '?Attempted to read parameters from non-send-init packet' );
  1127.         end 
  1128.         else
  1129.         begin
  1130.             adjust( Data, 100 ); 
  1131.             PackLen := ord( UnChar( count ) ) - 3;
  1132.             for i := PackLen + 1 to MaxString do
  1133.                 Data[i] := ' ';
  1134.  
  1135. { Don't have to agree on the following parameters }
  1136.             if UnChar( Data[1] ) = chr(0) then
  1137.                 SendPSize := 96
  1138.             else
  1139.                 SendPSize := ord ( UnChar ( Data[1] ) );
  1140.             data[1] := ToChar( chr( RecPSize ) );
  1141.  
  1142.             SendTimeOut := ord ( UnChar ( Data[2] ) );
  1143.             data[2] := ToChar( chr(RecTimeOut)  );
  1144.  
  1145. {            SendNPad := ord ( UnChar ( Data[3] ) );   }
  1146.             data[3] := ToChar( chr(RecNPad) );
  1147.  
  1148.             if UnChar(Data[4])=chr(0) then
  1149.                 SendPadChar := chr(0)
  1150.             else
  1151.                 SendPadChar := Ctl ( Data[4] ) ;
  1152.             data[4] := ctl( RecPadChar );
  1153.  
  1154.             if UnChar(Data[5])=chr(0) then
  1155.                 SendEOL   := chr(13)
  1156.             else
  1157.                 SendEOL   := UnChar ( Data[5] ) ;
  1158.             data[5] := ToChar( RecEOL );
  1159.  
  1160.             if UnChar(Data[5])=chr(0) then
  1161.                 SendQuote := '#'
  1162.             else
  1163.                 SendQuote := Data[6] ; 
  1164.             data[6] := RecQuote;
  1165.  
  1166. { On this one, we have to agree, else there will be no 8-bit quoting }
  1167.             if not ( (Data[7] in (OkQuote + ['Y'])) and Use8Quote ) then
  1168.             begin
  1169.                     { Default, if not acceptable 8-bit quote character }
  1170.                 NowUse8Quote := FALSE;
  1171.                 Data[7] := 'N';   { I agree NOT to do 8-bit quoting }
  1172.             end
  1173.             else
  1174.             begin
  1175.                 NowUse8Quote := TRUE;       { Only if this Kermit is sending: }
  1176.                 if Data[7]<>'Y' then        { 'Y' means my request to use     }
  1177.                     Bit8Quote := Data[7];   { 8-bit quoting is accepted       }
  1178.                                             { Else: use proposed quote char   }
  1179.                 Data[7] := 'Y';             { I agree to do 8-bit quoting     }
  1180.             end;
  1181.  
  1182. { Checksum type :  Default is 1-character checksum }
  1183.             Data[8] := '1'; { Not supporting 2 or 3-character checksums yet }
  1184.  
  1185. { Repeat prefix :  have to agree, else no repeat prefixing }
  1186.             if not ( (Data[9] in OkQuote) and UseRepFix ) then
  1187.             begin
  1188.                     { Default, if not acceptable repeat prefix }
  1189.                 NowUseRepFix := FALSE;
  1190.                 Data[9] := ' ';   { I won't do repeat prefixing }
  1191.             end
  1192.             else
  1193.             begin
  1194.                 NowUseRepFix := TRUE;       { repeat prefix is accepted       }
  1195.                 RepFix := Data[9];          { agree by returning same value   }
  1196.             end;
  1197.  
  1198.             if (Bit8Quote=SendQuote) and NowUse8Quote then begin
  1199.                 LocalError('?Cant send same 8-bit quote and control quote');
  1200.                 LocalError(' Denies 8-bit quoting!' );
  1201.                 Data[7] := ' ';
  1202.                 NowUse8Quote := false;
  1203.             end;
  1204.             if (RepFix=SendQuote) and NowUseRepFix then begin
  1205.                 LocalError('?Cant send same repeat prefix and control quote');
  1206.                 LocalError(' Denies repeat prefixing!');
  1207.                 Data[9] := ' ';
  1208.                 NowUseRepFix := false;
  1209.             end;
  1210.             if (RepFix=Bit8Quote) and NowUseRepFix and NowUse8Quote then
  1211.             begin
  1212.                 LocalError('?Cant send same repeat prefix and 8-bit quote');
  1213.                 LocalError(' Denies repeat prefixing!');
  1214.                 Data[9] := ' ';
  1215.                 NowUseRepFix := false;
  1216.             end;
  1217.  
  1218.             PackLen := 9;
  1219.             if Data[9]=' ' then begin
  1220.                 PackLen := 8;
  1221.                 if Data[8]='1' then begin
  1222.                     PackLen := 7;
  1223.                     if Data[7] in [' ','N'] then begin
  1224.                         PackLen := 6;
  1225.                     end;
  1226.                 end;
  1227.             end;  
  1228.             Count := ToChar ( chr( PackLen + 3 ) );
  1229.             adjust( Data, PackLen + 1 );
  1230.             Ptype := PackToCh ( ACKPack );
  1231.         end;
  1232.     end;
  1233.  
  1234.  
  1235.     procedure InitParameters;
  1236.     {  Abstract:
  1237.         This procedure initializes various global Kermit variables:
  1238.         "Constants", Transmission parameters, Kermit state variables.
  1239.         NB!  This procedure is to be called only ONCE during the run!  }
  1240.     
  1241.     begin
  1242.  
  1243.         SaveFile := '';
  1244.  
  1245.         LegalPackets    :=  ['D','Y','N','S','B','F','Z','E','R','C','G','X'];
  1246.  
  1247. { What I expect he will want }
  1248.  
  1249.         SendSOH         :=  chr(1);
  1250.         SendPSize       :=  94;         { - max. packet size           }
  1251.         SendTimeOut     :=  5;          { - 5 seconds timeout          }    
  1252.         SendNPad        :=  0;          { - no padding                 }
  1253.         SendPadChar     :=  chr(0);     { - ASCII NUL as padchar       }
  1254.         SendEOL         :=  chr(13);    { - carriage return as eol     }
  1255.         SendQuote       :=  '#';        { - sharp as control quote     }
  1256.  
  1257. { What I want from him (parameters which will be used when I send-initiate) }
  1258.  
  1259.         RecSOH          :=  chr(1);
  1260.         RecPSize        :=  59;         { for a Perq with standard buffersize }
  1261.         RecTimeOut      :=  5;          { time-out I want               }
  1262.         RecNPad         :=  0;          { Need no padding               }
  1263.         RecPadChar      :=  chr(0);
  1264.         RecEOL          :=  chr(13);    { Standard End-Of-Line          }
  1265.         RecQuote        :=  '#';        { Standard control quote        }
  1266.  
  1267. { What to do about 8-bit quoting }
  1268.         Use8Quote       :=  FALSE;      {  8-bit quoting disabled       }
  1269.         NowUse8Quote    :=  Use8Quote;
  1270.         Bit8Quote       :=  '&';
  1271.  
  1272.         UseRepFix       :=  FALSE;      {  Repeat prefixing disable     }
  1273.         NowUseRepFix    :=  UseRepFix;
  1274.         RepFix          :=  '~';
  1275.  
  1276.         LongWait        :=    4;        { Multiplication factor for TimeOut }
  1277.                      { during SendFileHeader (to allow for opening file) }
  1278.     
  1279.         LocalKermit     :=  FALSE;      { This frog is born a remote kermit }
  1280.         DisableTimOut   :=  FALSE;      { Allow partner to enable timeout }
  1281.         FileWarning     :=  TRUE;       { Do not write over existing files }
  1282.         FileSave        :=  FALSE;
  1283.         Debug           :=  FALSE;
  1284.  
  1285.         Nord            :=  FALSE;      { Not NORD transformation }
  1286.         TruncList[1]    :=  8;
  1287.         TruncList[2]    :=  3;
  1288.         NumTrunc        :=  2;          { Truncate file name 8+3 }
  1289.         OldTrunc        :=  NumTrunc;
  1290.         Translate       :=  TransUpper; { Translate file names to upper case }
  1291.    
  1292.         CurrState       :=  Complete;   { Avoid starting out in a bad state }
  1293.         N               :=  0;          { Start out with packet zero }
  1294.         NumTry          :=  0;
  1295.         OldTry          :=  0;
  1296.  
  1297.         MaxTryInit      :=  8;          { Retries before giving up }
  1298.         MaxTryPack      :=  5;
  1299.         MaxTryComm      :=  3;
  1300.  
  1301.         EscKey          :=  chr( ord(']')+128 );       { Control - ] }
  1302.  
  1303. { Then some useful character sets :  NB! they are recomputed by ReadPars }
  1304.             {  This is the set which the set of control characters is mapped
  1305.                 into by the Ctl function }
  1306.         CtlMapping :=  [ ctl( chr(  0) )..ctl( chr(    31) ), ctl( chr(127) ),
  1307.                          ctl( chr(128) )..ctl( chr(31+128) ), ctl( chr(255) )];
  1308.             {  Valid quote characters, i.e all printable characters
  1309.                 which Ctl does not map a control character into }
  1310.         OkQuote     :=  ['!'..'~'] - CtlMapping;
  1311.         
  1312.         Quotes      :=  [RecQuote, Bit8Quote, RepFix];
  1313.     
  1314.     end;
  1315.  
  1316. {=============================================================================}
  1317.  
  1318. procedure CleanupParameters;
  1319. begin
  1320.     SetSaveFile( '' );  { force close of previous SaveFile }
  1321. end.
  1322.