home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / norskdata / ndkuti.pas < prev    next >
Pascal/Delphi Source File  |  2020-01-01  |  27KB  |  691 lines

  1. (*     tab p;
  2.  *
  3.  *      Kermit utilities 
  4.  *      
  5.  *      Low-level IO, ++
  6.  *      To be INCLUDE'd by main program.
  7.  *
  8.  *)
  9.  
  10.     function    PackToCh ( pType : PacketType ): char;
  11.     var     RetVal : char;
  12.     begin
  13.         case pType of
  14.             DataPack    :   RetVal := 'D';
  15.             ACKPack     :   RetVal := 'Y';
  16.             NAKPack     :   RetVal := 'N';
  17.             SInitPack   :   RetVal := 'S';
  18.             BrkPack     :   RetVal := 'B';
  19.             FHeadPack   :   RetVal := 'F';
  20.             EOFPack     :   RetVal := 'Z';
  21.             ErrPack     :   RetVal := 'E';
  22.             NoChangePack,
  23.             TimOutPack,
  24.             IllPack,
  25.             ChkIllPack  :   RetVal := ' ';
  26.         end;
  27.         PackToCh := RetVal;
  28.     end;
  29.  
  30.     function  ChToPack( ch : char ): PacketType;
  31.     begin
  32.         if not ( ch in LegalPackets ) then
  33.         begin
  34.             if Debug then begin
  35.                 DbgWrite ( 'Illegal packet type : $' );
  36.                 DbgChar ( ch );
  37.                 DbgNL;
  38.             end;
  39.             ChToPack := IllPack;
  40.         end
  41.         else
  42.         begin
  43.             case ch of
  44.                 'D' :   ChToPack := DataPack;
  45.                 'Y' :   ChToPack := AckPack;
  46.                 'N' :   ChToPack := NakPack;
  47.                 'S' :   ChToPack := SinitPack;
  48.                 'B' :   ChToPack := BrkPack;
  49.                 'F' :   ChToPack := FHeadPack;
  50.                 'Z' :   ChToPack := EOFPack;
  51.                 'E' :   ChToPack := ErrPack;
  52.             end;
  53.         end;
  54.     end;
  55.  
  56.  
  57.     procedure   SetInitPars( var Pack : Packet );
  58.         (*    Build SendInit packet   *)
  59.     begin
  60.         with Pack do
  61.         begin
  62.             if MaxPack=96 then
  63.             (* Max packet-length I can handle *)
  64.                 data(.MinString.) := ToChar( chr(0) )
  65.             else
  66.                 data(.MinString.) := ToChar( chr(MaxPack) );
  67.             data(.MinString + 1.) := ToChar( chr(MyTime)  );
  68.             (* When I want to be timed out    *)
  69.             data(.MinString + 2.) := ToChar( chr(MyPad)   );
  70.             (* How much padding I need        *)
  71.             data(.MinString + 3.) := ctl   ( chr(MyPChar) );
  72.             (* My padding character           *)
  73.             data(.MinString + 4.) := ToChar( chr(MyEoln)  );
  74.             (* End-of-line I want             *)
  75.             data(.MinString + 5.) :=             MyQuote   ;
  76.             (* control-quote char I send      *)
  77.             if not HasSw8Off then
  78.                 data(.MinString + 6.) :=         My8Quote
  79.                 (* 8-bit-quote char I send        *)
  80.             else
  81.                 data(.MinString + 6.) :=         'N';
  82.                 (* No 8-bit quoting               *)
  83.             count:= ToChar( chr( 7 + 3 ) );
  84.             ptype:= PackToCh( SInitPack );
  85.         end;
  86.     end;
  87.  
  88.     procedure   ReadPars ( VAR Pack : Packet );
  89.         (*  Set parameters according to Pack (Which is SendInit or 
  90.             Acknowledge packet)
  91.             and build the corresponding Acknowledge packet *)
  92.     VAR len,i   : integer;
  93.         Sending, Receiving : Boolean;
  94.     begin
  95.         with Pack do 
  96.         begin
  97.             Sending     := (ChToPack(Ptype) = ACKPack);
  98.             Receiving   := (ChToPack(Ptype) = SInitPack);
  99.             if not( Sending or Receiving ) then
  100.             begin
  101.                 CurrState := ABORT;
  102.                 if Debug then begin
  103.                     DbgWrite(
  104.                     ' Attempted ReadPars from non-SendInit packet - Failed!$' );
  105.                     DbgNL;
  106.                 end;
  107.             end
  108.             else
  109.             begin
  110.                 len := ord( UnChar( count ) ) - 3;
  111.                 for i := len to MaxString do        (* treat absent data and *)
  112.                     Data(.i.) := ' ';               (* blank data alike      *)
  113.  
  114. (* Packet size:  max. & default is 94 (or is it 96?), reply with MaxPack *)
  115.  
  116.                 i := MinString;
  117.                 if UnChar( Data(.i.) ) = chr(0) then
  118.                     SendPSize := 96         (* Default packet size *)
  119.                 else
  120.                     SendPSize := ord ( UnChar ( Data(.i.) ) );
  121.  
  122. (* If we are receiving, tell other Kermit about our max. packet length *)
  123.  
  124.                 if MaxPack=96 then
  125.                     data(.i.) := ToChar( chr(0) )
  126.                 else
  127.                     data(.i.) := ToChar( chr(MaxPack) );
  128.  
  129. (*  Seconds before timeout:  Default is no timeout, reply with MyTime *)
  130.  
  131.                 i := MinString + 1;
  132.                 TimeOut := ord ( UnChar ( Data(.i.) ) );
  133.                 data(.i.) := ToChar( chr(MyTime)  );
  134.  
  135. (*  Number of pad characters:  Default is no padding, reply with MyPad *)
  136.  
  137.                 i := MinString + 2;
  138.                 NPad := ord ( UnChar ( Data(.i.) ) );
  139.                 data(.i.) := ToChar( chr(MyPad) );
  140.  
  141. (*  Pad character:  Default is ASCII NUL, reply with MyPadChar *)
  142.  
  143.                 i := MinString + 3;
  144.                 if ( NPad = 0 ) or ( UnChar(Data(.i.))=chr(0) ) then
  145.                     PadChar := chr(0)
  146.                 else
  147.                     PadChar := Ctl ( Data(.i.) ) ;
  148.                 data(.i.) := ctl( chr(MyPChar) );
  149.  
  150. (*  End-of-line character:  Default is ASCII CR, reply with MyEOLN  *)
  151.  
  152.                 i := MinString + 4;
  153.                 if UnChar(Data(.i.))=chr(0) then
  154.                     Eol   := chr(13)
  155.                 else
  156.                     Eol   := UnChar ( Data(.i.) ) ;
  157.                 data(.i.) := ToChar( chr(MyEoln)  );
  158.  
  159. (*  Control-quote character: Is suggested by the sender and must be accepted
  160.  * by the receiver. Default is '#' if nothing is said (a blank field).
  161.  *)
  162.                 i := MinString + 5;
  163.                 if Receiving then begin
  164.                     if UnChar(data(.i.))=chr(0) then
  165.                         Quote := '#'
  166.                     else
  167.                         Quote := data(.i.);
  168.                     if not (Quote in OkQuote) then begin
  169.                         Currstate := ABORT;
  170.                         if Debug then begin
  171.                             DbgWrite(
  172. ' Sender proposing illegal quote-character - Failed!$');
  173.                             DbgNL;
  174.                         end;
  175.                     end;
  176.                 end;
  177.  
  178. (* Now compute set of valid 8-bits quotes *)
  179.  
  180.                 Ok8Quote := OkQuote - (.Quote.);
  181. (*
  182. 8-bit quoting negotiation: The sender may say
  183.   N  -- I will not do 8-bit-quoting
  184.   Y  -- I agree to 8-bit-quoting, you suggest which character
  185.   &  -- I want to do 8-b-q using this character (could be some other).
  186.  
  187. Kermit-ND will reply as follows:
  188. sender      Kermit-ND/USE-8=OFF     Kermit-ND/USE-8=AUTO
  189.   N             N                       N
  190.   Y             N                       &
  191.   &             N                       Y
  192.  SP             N                       N
  193. ill.            abort                   abort
  194.  
  195. When Kermit-ND is sending its Send-Init packet said '&' if USE-8 is AUTO,
  196. and 'N' otherwise. The reply to this may be
  197.  
  198. Kermit-ND       Other Kermit
  199.   N                 various ... 8-b-q must not be done anyhow.
  200.   &                 N ... 8-b-q may not be done.
  201.                     Y OK, we use '&'.
  202.                     & OK (though not correct acc. to protocol manual), use '&'.
  203.  
  204. *)
  205.  
  206.                 i := MinString + 6;
  207.                 if Receiving then
  208.                     case HasSw8Off of
  209.                         TRUE:
  210.                             begin
  211.                                 Use8Quote := FALSE;
  212.                                 data(.i.) := 'N';
  213.                                 if not
  214.                                     (data(.i.) in(Ok8Quote + (.'N','Y',' '.)))
  215.                                 then
  216.                                     if Debug then
  217.                                     begin
  218.                                         DbgWrite(
  219.                                     ' (bad 8-bit-quote proposal from sender)$');
  220.                                         DbgNL;
  221.                                     end;
  222.                             end;
  223.                         FALSE:  (* Auto *)
  224.                             begin
  225.                                 if data(.i.) = ' ' then data(.i.) := 'N';
  226.                                 if data(.i.) = 'N' then
  227.                                     Use8Quote := FALSE
  228.                                 else if data(.i.) = 'Y' then
  229.                                 begin
  230.                                     Bit8Quote := My8Quote;
  231.                                     data(.i.) := My8Quote;
  232.                                     Use8Quote := TRUE;
  233.                                 end
  234.                                 else if data(.I.) in Ok8Quote then
  235.                                 begin
  236.                                     Bit8Quote := data(.i.);
  237.                                     Use8Quote := TRUE;
  238.                                     data(.i.) := 'Y';
  239.                                 end
  240.                                 else if Debug then
  241.                                 begin
  242.                                     Use8Quote := FALSE;
  243.                                     DbgWrite
  244.                                 (' (bad 8-bit-quote proposal from sender)$');
  245.                                     DbgNL;
  246.                                 end;
  247.                             end;
  248.                     end
  249.                 else if Sending then
  250.                     case HasSw8Off of
  251.                         TRUE:   (* Means we said 'N' in our SendInit packet *)
  252.                             begin
  253.                                 Use8Quote := FALSE;
  254.                                 if not( data(.i.) in (.' ','N'.)) then
  255.                                     if Debug then
  256.                                     begin
  257.                                         DbgWrite(
  258.                                 ' (silly 8-bit-quote reply from receiver)$');
  259.                                         DbgNL;
  260.                                     end;
  261.                             end;
  262.                         FALSE:  (* We said '&' *)
  263.                             begin
  264.                                 if
  265.                                 (data(.i.) = My8Quote) or (data(.i.) = 'Y')
  266.                                 then begin
  267.                                     Use8Quote := TRUE;
  268.                                     Bit8Quote := My8Quote;
  269.                                 end
  270.                                 else if data(.i.) in (.' ','N'.) then
  271.                                     Use8Quote := FALSE
  272.                                 else if Debug then
  273.                                 begin
  274.                                     Use8Quote := FALSE;
  275.                                     DbgWrite(
  276.                                 ' (silly 8-bit-quote reply from receiver)$');
  277.                                     DbgNL;
  278.                                 end;
  279.                             end;
  280.                     end;
  281.  
  282. (* Checksum type :  Default is 1-character checksum.
  283.  * No other supported by Kermit-ND.
  284.  *)
  285.                 i := MinString + 7;
  286.                 Data(.i.) := '1';
  287.  
  288. (* Repeat prefix :  No default, not (yet) supported. *)
  289.  
  290.                 Data(.MinString + 8.) := ' ';
  291.  
  292.                 Count := ToChar ( chr( 9 + 3 ) );
  293.                 Ptype := PackToCh ( ACKPack );
  294.             end;
  295.         end;
  296.     end;
  297.  
  298. (* -- Packet level I/O   *)
  299. (*$t- *)
  300.     procedure   WritePacket ( VAR  data : EqRecord;
  301.                                    odev : integer );
  302.     (* procedure to do the actual O, assume packet is OK *)
  303.     var     i,j,k : integer;
  304.     begin
  305.         k := ord ( UnChar ( data.Pack.count ) );
  306.         Data.Pack.data(.k - 2 + MinString.) := chr(0);
  307.         (* Number of bytes to output: *)
  308.         i := 4 + k - 3;
  309.         NChSent := NChSent + i + NPad;
  310.         (* compute number of 8-bytes to output: *)
  311.         i := i div 8;
  312.         for j := 0 to i do
  313.             m8out ( ODev , Data.IntArr(.j*4.));
  314.         outbt ( ODev , eol );
  315.     end;
  316. (*$t+ *)
  317.  
  318.     procedure   SendPacket ( sptype : PacketType;
  319.                              num    : integer;
  320.                              len    : integer;
  321.                          VAR data   : Packet;
  322.                              odev   : integer );
  323.  
  324.     (* build header, calculate checksum and send packet on output-device *)
  325.     var     i, chksum : integer;
  326.             DirtPtr   : EqPtr;
  327.  
  328.         function    Addr ( VAR Data : Packet ):EqPtr; extern;
  329.  
  330.     begin   (* SendPacket *)
  331.         with data do begin
  332.             mark := SOH;
  333.             for i := 1 to NPad do
  334.                 outbt ( odev , PadChar );
  335.             if len>=0 then  (* is there valid data? *)
  336.                 count := ToChar ( chr ( len + 3 ) ) 
  337.             else
  338.                 len   := ord ( UnChar ( count ) ) - 3 ;
  339.             chksum := ord ( count );
  340.             if num>=0 then
  341.                 seq := ToChar ( chr ( num ) );
  342.             chksum := chksum + ord ( seq );
  343.             if sptype<>NoChangePack then
  344.                 ptype := PackToCh( sptype );
  345.             chksum := chksum + ord ( ptype );
  346.             for i := MinString to ( MinString + len - 1 ) do
  347.                 (* accumulate checksum *)
  348.                 chksum := chksum + ord ( data(.i.) );
  349.             data(.MinString + len.) := MakeCheck ( chksum );
  350.         end;  (* with *)
  351. (*$t- *)
  352.         DirtPtr := Addr ( data );
  353.         WritePacket ( DirtPtr^, odev );
  354. (*$t+ *)
  355.         if Debug then
  356.             DbgShowPacket ( data );
  357.     end;
  358.  
  359.  
  360.     function    ReadPacket (    var num  : integer;
  361.                                 var len  : integer;
  362.                                 var data : Packet;
  363.                                 idev     : integer  ): PacketType;
  364.  
  365.     label   99;         (* where to jump to abort function *)
  366.  
  367.     (* read a packet and return seq. number, data packet and length *)
  368.     var     chksum,NumPoll,i        : integer;
  369.             done,ReSynch            : boolean;
  370.             ch                      : char;
  371.             PType                   : PacketType;
  372.             InpSize,Expect          : integer;
  373.  
  374.         function Poll( NumChar : integer ) : integer;
  375.         (* Wait until input buffer contains at least
  376.            min (Expect,NumChar) characters,
  377.            or time out when max. time (NumPoll decremented to zero).
  378.            Jump to label 99 when timed out. *)
  379.         VAR i,j:  integer;
  380.         begin
  381.             I:= 0;
  382.             if NumChar>Expect then
  383.                 NumChar := Expect;
  384.             if ( TimeOut>0 ) and not DisableTimeOut then
  385.                                         (* TimeOut=0 ==> never time out *)
  386.             repeat
  387.                 j := I;
  388.                 I := Isize ( idev );
  389.                 if I < NumChar then
  390.                 begin
  391.                     xhold( BUnits, ( Del20Chars * (NumChar-I) ) div 20 + 1 );
  392.                     NumPoll := NumPoll - (NumChar-I);
  393.                     if NumPoll<=0 then begin
  394.                         ReadPacket := TimOutPack;
  395.                         if Debug then begin
  396.                             DbgWrite( 'Timed out waiting for packet!$');
  397.                             DbgNL;
  398.                         end;
  399.                         goto 99;
  400.                     end;
  401.                 end;
  402.             until ( I >= NumChar );
  403.             Poll := I ;
  404.             Expect := Expect - I ;
  405.         end;
  406.  
  407.     begin
  408.         NumPoll := TimeOut*50 div Del20Chars;
  409.         (*  Max. number of polls before timeout *)
  410.         Expect  := MAXINT;
  411.         (*  Expects unlimited number of chars. *)
  412.  
  413.         repeat   
  414.             InpSize := Poll(1) - 1 ;    (* Quit if timeout *)
  415.             ch := inbt ( idev ) ;
  416.             NChRcvd := NChRcvd + 1L;
  417.         until (ch = SOH);
  418.  
  419.         if ch = SOH then begin
  420.             data.mark := ch;
  421.             done := false;
  422.             while not done do
  423.             begin
  424.                 if InpSize=0 then
  425.                     InpSize := Poll(1);
  426.                 InpSize := InpSize - 1;
  427.                 ch := inbt ( idev );
  428.                 NChRcvd := NChRcvd + 1L;
  429.                 if ch <> SOH then   (* resynch on SOH *)
  430.                 begin
  431.                     chksum := ord ( ch );
  432.                     Expect := ord( UnChar ( ch ) );     (* Rest of packet *)
  433.                     len    := Expect - 3;
  434.                     data.count := ch;
  435.                     InpSize := Poll( Chunk ) - 1;
  436.                     ch := inbt ( idev );
  437.                     NChRcvd := NChRcvd + 1L;
  438.                     if ch <> SOH then   (* resynch on SOH *)
  439.                     begin
  440.                         chksum := chksum + ord ( ch );
  441.                         num := ord( UnChar ( ch ) );
  442.                         data.seq := ch;
  443.                         InpSize := InpSize - 1;
  444.                         ch := inbt ( idev );
  445.                         NChRcvd := NChRcvd + 1L;
  446.                         if ch <> SOH then   (* resynch on SOH *)
  447.                         begin
  448.                             chksum := chksum + ord ( ch );
  449.                             ReadPacket := ChToPack ( ch );
  450.                             data.ptype := ch;
  451.                             i := MinString;
  452.                             ReSynch := FALSE;
  453.                             while not ((i > (len + MinString - 1 ))
  454.                                         or ReSynch) do begin
  455.                                 if InpSize=0 then begin
  456.                                     InpSize := Poll( Chunk );
  457.                                 end;
  458.                                 InpSize := InpSize - 1;
  459.                                 ch := inbt ( idev );
  460.                                 NChRcvd := NChRcvd + 1L;
  461.                                 ReSynch := ch=SOH;
  462.                                 if not ReSynch then
  463.                                 begin
  464.                                     chksum := chksum + ord ( ch );
  465.                                     data.data(.i.) := ch;
  466.                                 end;
  467.                                 i := i + 1;
  468.                             end;
  469.                             if not ReSynch then
  470.                             begin
  471.                                 if InpSize=0 then
  472.                                     InpSize := Poll(1);
  473.                                 InpSize := InpSize - 1;
  474.                                 ch := inbt ( idev );
  475.                                 NChRcvd := NChRcvd + 1L;
  476.                                 if ( MakeCheck ( chksum ) <> ch )
  477.                                    and ( ch <> SOH )
  478.                                 then
  479.                                     ReadPacket := ChkIllPack;
  480.                                 done := ch <> SOH;
  481.                             end;
  482.                         end;
  483.                     end;
  484.                 end;
  485.             end;
  486.             if Debug then
  487.                 DbgShowPacket( data );
  488.         end;
  489. 99:     ;                   (* jump to 99 after timeout *)
  490.     end;
  491.  
  492.     procedure   FillBuffer (    var data      : Packet;
  493.                                 var infile    : ByteFile );
  494.     var     ch : Byte;
  495.             i  : integer;
  496.             NRead : integer;    (* Number of characters read from file *)
  497.             Quote8 , CtrlChar : boolean;
  498.     begin
  499.         i := MinString;
  500.         NRead := 0;
  501.         with data do begin
  502.             if not eof ( infile ) then
  503.             begin
  504.                  repeat
  505.                     read ( infile , ch );
  506.                     NRead := NRead + 1;
  507.                     Quote8 := ( ch >= 128 ) and Use8Quote;
  508.                     if Quote8 then
  509.                     begin
  510.                         (* quote for eight bit: *)
  511.                         data(.i.) := Bit8Quote;
  512.                         i := i + 1;
  513.                     end;
  514.                     (* strip off 8'th bit. On ND-version - unconditional *)
  515.                     (* Other machines may include in test above *)
  516.                     ch := iand ( ch , 127 );
  517.                     CtrlChar := ( ch < ord ( ' ' ) ) or
  518.                                 ( ch = 127 ) or           (* del *)
  519.                                 ( chr ( ch ) = Quote ) or
  520.                                 ( ( chr( ch ) = Bit8Quote) and Use8Quote ) ;
  521.                     if CtrlChar then
  522.                     begin
  523.                         if    ( ch < ord ( ' ' ) )
  524.                            or ( ch = 127 ) then
  525.                             (* real control character *)
  526.                             ch := ord ( ctl ( chr ( ch ) ) );
  527.                         data(.i.) := Quote;
  528.                         i := i + 1;
  529.                     end;
  530.                     data(.i.) := chr ( ch );
  531.                     i := i + 1;
  532.                 until eof ( infile ) or ( i + 9 - MinString >= SendPSize );
  533.                     (* Put count field = len of data + 3, i = len of data + 1 *)
  534.                 count := ToChar ( chr ( i + 3 - MinString ) );
  535.             end
  536.             else
  537.                 count := ToChar ( chr ( 0 ) );
  538.  
  539. (*          if  chr( iand( ord(seq), 127 )  )
  540.                 IN (. ToChar(chr(0))..ToChar(chr(63)) .) then
  541. *)
  542.         (* update sequence number - if it vas a valid one in the first place *)
  543. (*              seq := ToChar( chr( ( ord( UnChar( seq ) ) + 1 ) mod 64 ) );
  544. *)
  545.             ptype := PackToCh( DataPack );
  546.         end;    (* with *)
  547.         NChFile := NChFile + NRead;
  548.     end;
  549.  
  550.     procedure   EmptyBuffer (   var OutFile : bytefile;
  551.                                 var data    : Packet );
  552.     var     i,
  553.             NChar,      (* Number of characters in packet *)
  554.             NWritten    (* Number of characters actually written to file *)
  555.                 : integer;
  556.             CtrlChar, Quote8 : boolean;
  557.             ch : char;
  558.             Scr : Byte;
  559.     begin
  560.         i := MinString;
  561.         NWritten := 0;
  562.         with data do
  563.         begin
  564.                 (* Calculate number of data-characters in "data": *)
  565.             NChar := ord( UnChar ( count ) ) - 4 - MinString;
  566.             while i <= NChar do
  567.             begin
  568.                 ch := data(.i.);
  569.                 Quote8 := Use8Quote and ( ch = Bit8Quote );
  570.                 if Quote8 then
  571.                 begin
  572.                     i := i + 1;
  573.                     ch := data(.i.);
  574.                 end;
  575.                 CtrlChar := ch = MyQuote;
  576.                 if CtrlChar then
  577.                 begin
  578.                     i := i + 1;
  579.                     ch := data(.i.);
  580.                     if ch <> MyQuote then
  581.                         if not Use8Quote then ch := ctl(ch)
  582.                         else if ch <> Bit8Quote then ch := ctl(ch);
  583.                     (* else character is a quoted quote(!) *)
  584.                 end;
  585.                 if Quote8 then
  586.                     Scr := ior ( ord ( ch ) , 128 )
  587.                 else
  588.                     Scr := ord ( ch );
  589.                 write ( OutFile , Scr );
  590.                 NWritten := NWritten + 1;
  591.                 i := i + 1;
  592.             end;
  593.         end; (* with *)
  594.         NChFile := NChFile + NWritten;
  595.     end;
  596.  
  597.  
  598.     procedure SendACK( num, odev : integer );
  599.     VAR dummy : Packet;
  600.     begin
  601.         SendPacket( ACKPack,
  602.                     num,
  603.                     0,
  604.                     dummy,
  605.                     odev );
  606.     end;
  607.  
  608.     procedure SendNAK( num, odev : integer );
  609.     VAR dummy : Packet;
  610.     begin
  611.         SendPacket( NAKPack,
  612.                     num,
  613.                     0,
  614.                     dummy,
  615.                     odev );
  616.     end;
  617.  
  618.     procedure SendBrk( odev : integer );
  619.     VAR dummy : Packet;
  620.     begin
  621.         SendPacket( BrkPack,
  622.                     0,
  623.                     0,
  624.                     dummy,
  625.                     odev );
  626.     end;
  627.  
  628.  
  629.     procedure InitializeKermit;
  630.     (*  Abstract:
  631.         This procedure initializes various global Kermit variables:
  632.         "Constants", Transmission parameters, Kermit state variables.
  633.         NB!  This procedure is to be called only ONCE during the run!  *)
  634.     
  635.     begin
  636.     (* Ought to have been constants,               *)
  637.     (* but there are no such constants in PASCAL...*)
  638.         xhold(BUnits,0);    (* Dummy hold - ND dependent *)
  639.         SOH             :=  chr(1);
  640.         LegalPackets    :=  (. 'D','Y','N','S','B','F','Z','E'.);
  641.     
  642. (* Then some useful character sets :  NB! they are recomputed by ReadPars *)
  643. (* This is the set which the set of control characters is mapped into
  644.                 by the Ctl function *)
  645.         CtlMapping  :=  (. ctl( chr(0) )..ctl( pred(' ') ), ctl( chr(127) ) .);
  646.  
  647. (*  Valid control quote characters, i.e all printable characters
  648.                 which Ctl does not map a control character into *)
  649.         OkQuote     :=  (.'!'..'~'.) - CtlMapping;
  650. (*  Valid 8-bit quote characters, i.e. same as for quote, except
  651.                 SPACE is not valid but 'Y' is (=default), and of course
  652.                 the character that is chosen as control quote is not valid *)
  653.         Ok8Quote    :=  OkQuote - (.'#'.) + (.'Y'.);
  654.     
  655. (* Kermit parameters:  must be defined to enable first packet to get through *)
  656.         SendPSize       :=  96;         (* - max. packet size           *)
  657.         TimeOut         :=  0;          (* - no timeout                 *)
  658.         NPad            :=  0;          (* - no padding                 *)
  659.         PadChar         :=  chr(0);     (* - ASCII NUL as padchar       *)
  660.         Eol             :=  chr(13);    (* - carriage return as eol     *)
  661.         Quote           :=  '#';        (* - sharp as control quote     *)
  662.         Bit8Quote       :=  '&';        (* - ampersand as 8-bit quote   *)
  663.         Use8Quote       :=  FALSE;      (* - 8-bit quoting disabled     *)
  664.         HasSw8Off       :=  FALSE;      (* -"- has not been switched off*)
  665.     
  666.         LocalKermit     :=  FALSE;      (* This frog is born a remote kermit *)
  667.         Idev            :=  1;
  668.         Odev            :=  1;
  669.     
  670.         DisableTimOut   :=  FALSE;      (* Allow partner to enable timeout *)
  671.     
  672.         FileWarning     :=  FALSE;      (* Overwrite existing files initially *)
  673.     
  674.         CurrState       :=  Complete;   (* Avoid starting out in a bad state *)
  675.         N               :=  0;          (* Start out with packet zero *)
  676.         NumTry          :=  0;
  677.         OldTry          :=  0;
  678.         MaxTry          := 16;          (* Retries before giving up *)
  679.         Delay           :=  5;          (* Default delay            *)
  680.                                         (* before sending/receiving *)
  681.     
  682.         RTSet           := false;
  683.         STSet           := false;
  684.         DbgConnected    := false;
  685.         Debug           := false;
  686.         HasDone         := false;       (* No transaction has been done yet *)
  687.  
  688.         InitVocab; (* Initialize command vocabulary *)
  689.     end; (* InitializeKermit *)
  690. 
  691.