home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / perqa / kermitparms.pas < prev    next >
Pascal/Delphi Source File  |  2020-01-01  |  9KB  |  244 lines

  1. MODULE KermitParms ;
  2.  
  3. (* Deal with various Kermit Parameters: Set and Show *)
  4. (* 29-Nov-83 Allow eight bit file transfer [pgt001] *)
  5.  
  6.  
  7. EXPORTS
  8.  
  9.  
  10. PROCEDURE SetParameters ;
  11. PROCEDURE DoShow ;
  12.  
  13.  
  14.  
  15.  
  16. PRIVATE
  17.  
  18. IMPORTS KermitGlobals   FROM KermitGlobals ;
  19. IMPORTS RS232Baud       FROM RS232Baud ;
  20. IMPORTS CmdParse        FROM CmdParse ;
  21. IMPORTS PopCmdParse     FROM PopCmdParse ;
  22. IMPORTS PopUp           FROM PopUp ;
  23. IMPORTS Perq_String     FROM Perq_String ;
  24.  
  25.  
  26. PROCEDURE SetParameters ;
  27.    (* Set Kermit flags and other communications features -pt*)
  28.    VAR
  29.       id, parm: String ; (* SET identifier and (possible) parameter *)
  30.       switch, parmsw: Boolean ; (* Switch flags for feature and parameter *)
  31.       index: Integer ; (* Command index *)
  32.  
  33.    PROCEDURE DoBaudRate( NewRate: String ) ;
  34.       (* Try to set a new baud rate for the RS232 port *)
  35.       CONST
  36.          InputEnable = True ; (* Enable RS232 input *)
  37.  
  38.       HANDLER BadBaudRate ;
  39.          BEGIN (*-BadBaudRate-*)
  40.             Writeln('?Bad baud rate given: ', NewRate) ;
  41.             EXIT( DoBaudRate )
  42.          END ; (*-BadBaudRate-*)
  43.  
  44.       BEGIN (*-DoBaudRate-*)
  45.          IF (NewRate = '') THEN Writeln('%No value for SET SPEED')
  46.          ELSE
  47.             BEGIN
  48.                (* set the rate *)
  49.                SetBaud( NewRate, InputEnabled) ;
  50.                (* Here if that was successful, save the new rate *)
  51.                BaudRate := NewRate
  52.             END
  53.       END ; (*-DoBaudRate-*)
  54.  
  55.    FUNCTION MkOctal( src: String ): Integer ;
  56.       (* convert the octal number in the source string into a number *)
  57.       VAR
  58.          i, sum: Integer ; (* index and summation value *)
  59.          ok: Boolean ;     (* loop control *)
  60.       BEGIN (*-MkOctal-*)
  61.          ok := True ;  i := 1 ;  sum := 0 ;
  62.          WHILE ok DO
  63.             IF NOT (src[i] IN ['0'..'7']) THEN ok := False (* reached non-octal *)
  64.             ELSE
  65.                BEGIN
  66.                   sum := sum*8 + Ord(src[i]) - #60 ;
  67.                   i := i + 1 ;
  68.                   ok := (i <= Length(src)) (* exit test *)
  69.                END ;
  70.          MkOctal := sum
  71.       END ; (*-MkOctal-*)
  72.  
  73.    PROCEDURE DoEscChr( OctalStr: String ) ;
  74.       (* try to set a new CONNECT escape character *)
  75.       (* OctalStr contains the string representation of the octal number *)
  76.       VAR
  77.          val: Integer ; (* The escape character's ordinal *)
  78.       BEGIN (*-DoEscChr-*)
  79.          IF (OctalStr = '') THEN
  80.             Writeln('?SET ESCAPE requires an octal number')
  81.          ELSE
  82.             IF (OctalStr[1] IN ['0'..'7']) THEN
  83.                BEGIN
  84.                   val := MkOctal( OctalStr ) ; (* Get the value *)
  85.                   IF (val = 0) OR (val > #037) THEN
  86.                      Writeln('%Illegal ESCAPE character value: ', val:1:8)
  87.                   ELSE
  88.                      BEGIN
  89.                         (* set the character and its printable version *)
  90.                         EscapeChr := Chr( val ) ;
  91.                         EscPrint  := Chr( val + #100 )
  92.                      END
  93.                END (* octal digit *)
  94.             ELSE
  95.                Writeln('?Non-Octal digit in SET ESCAPE parameter')
  96.       END ; (*DoEscChr-*)
  97.  
  98.    PROCEDURE DoOnOff(VAR flag: Boolean) ;
  99.       (*)
  100.        * For the set feature with menu index <index> see if <parm> is
  101.        * either ON or OFF. If so, set <flag> to True or False, resp.
  102.        * Otherwise write error message and leave <flag> alone.
  103.       (*)
  104.       VAR
  105.          val: Integer ; (* Value of table search ON/OFF *)
  106.       BEGIN (*-DoOnOff-*)
  107.  
  108.          ConvUpper( parm ) ;  (* MUST be upper case *)
  109.  
  110.          IF (parm = '') THEN val := 3  (* not ON/OFF *)
  111.          ELSE
  112.             val := UniqueCmdIndex(parm, OnOff, 2) ;
  113.  
  114.          CASE  val  OF
  115.             1: flag := True ;   (* ON  *)
  116.             2: flag := False ;  (* OFF *)
  117.             3: Writeln('%SET ', SetMenu^.Cmd[index], ' requires ON or OFF') ;
  118.             4: Writeln('%Ambiguous ON or OFF in SET ', SetMenu^.Cmd[index] )
  119.          END ; (* case *)
  120.  
  121.       END ; (*-DoOnOff-*)
  122.  
  123.    PROCEDURE SetHelp ;
  124.       (* Provide help information for the command SET ?     *)
  125.       BEGIN (*-SetHelp-*)
  126.          Writeln ;
  127.          Writeln('The following features are available with the SET command :') ;
  128.          Writeln ;
  129.          Writeln('SPEED <rate>       Change the PERQ''s line speed') ;
  130.          Writeln('DEBUG ON|OFF       Print debug information') ;
  131.          Writeln('ESCAPE <octal>     Change the CONNECT escape character') ;
  132.          Writeln('WARNING ON|OFF     Give warning when overwriting existing files') ;
  133.          Writeln('LOCAL ON|OFF       Echo CONNECT typein locally') ;
  134.          Writeln('VERBOSE ON|OFF     Display Kermit''s actions') ;
  135.          Writeln('EIGHT-BIT ON|OFF   Allow eight bit file transfer');(*[pgt001]*)
  136.          Writeln
  137.       END ; (*-SetHelp-*)
  138.  
  139.    BEGIN (*-SetParameter-*)
  140.       (* If the command line is empty, prompt user *)
  141.       IF (CmdLine = '') THEN
  142.          BEGIN
  143.             Write('Kermit-SET', PromptChar) ;
  144.             Readln( CmdLine )
  145.          END ;
  146.  
  147.       (* get the first identifier from the line *)
  148.       dumCh := NextIDString( CmdLine, id, switch ) ;
  149.       (* and a possible parameter *)
  150.       dumCh := NextIDString( CmdLine, parm, parmsw ) ;
  151.  
  152.       IF (id = '') THEN (* nothing - return *)
  153.       ELSE
  154.          IF switch OR parmsw THEN Writeln('%SET does not take switches')
  155.          ELSE
  156.             IF (id[1] = '?') THEN SetHelp
  157.             ELSE
  158.                BEGIN
  159.  
  160.                   index := PopUniqueCmdIndex(id, RECAST(SetMenu, pNameDesc) ) ;
  161.                   (* What was the command ? *)
  162.                   CASE  index  OF
  163.                      1: DoBaudRate( parm ) ;         (* SPEED *)
  164.                      2: DoOnOff( debug ) ;           (* DEBUG *)
  165.                      3: DoEscChr( parm ) ;           (* ESCAPE *)
  166.                      4: DoOnOff( FileWarning ) ;     (* WARNING *)
  167.                      5: DoOnOff( HalfDuplex ) ;      (* LOCAL *)
  168.                      6: DoOnOff( Verbosity ) ;       (* VERBOSE *)
  169.                      7: DoOnOff( EightBitFile ) ;    (* EIGHT-BIT [pgt001]*)
  170.                      8: Writeln('%Not a SET feature: ', id) ;
  171.                      9: Writeln('%Ambiguous SET feature: ', id)
  172.                   END ; (* case *)
  173.                END (* else *)
  174.  
  175.    END ; (*-SetParameter-*)
  176.  
  177.  
  178.  
  179. PROCEDURE DoShow ;
  180.    (* Show the Kermit flags and parameters *)
  181.    VAR
  182.       flag: ARRAY [Boolean] OF String[3] ;  (* OF or OFF *)
  183.       id: String ;   (* identifier *)
  184.       switch: Boolean ;  (* SHOW /xxx    flag *)
  185.       i: Integer ;   (* Index *)
  186.  
  187.    PROCEDURE Feature( index: Integer ) ;
  188.       (* write a single feature - Index into SetMenu *)
  189.       BEGIN (*-Index-*)
  190.          CASE  index  OF
  191.             1: Writeln('Baud rate  ', BaudRate) ;
  192.             2: Writeln('Debug      ', flag[debug]) ;
  193.             3: Writeln('Escape chr ^', EscPrint,'     (Octal ', Ord(EscapeChr):1:8, ')') ;
  194.             4: Writeln('Warning    ', flag[FileWarning]) ;
  195.             5: Writeln('Local      ', flag[HalfDuplex]) ;
  196.             6: Writeln('Verbose    ', flag[Verbosity]) ;
  197.             7: Writeln('Eight-Bit  ', flag[EightBitFile])  (*[pgt001]*)
  198.             END  (* case *)
  199.       END ; (*-Feature-*)
  200.  
  201.    BEGIN (*-DoShow-*)
  202.  
  203.       Writeln ;
  204.       flag[True] := 'ON' ;
  205.       flag[False]:= 'OFF' ;
  206.  
  207.       (* get the show feature *)
  208.       dumCh := NextIDString(CmdLine, id, switch) ;
  209.       IF (id = '') THEN id := 'ALL' ; (* Default *)
  210.  
  211.       IF switch THEN
  212.          Writeln('%SHOW does not take switches')
  213.       ELSE
  214.       IF (id[1] = '?') THEN (* simple help *)
  215.          BEGIN
  216.             Writeln('One of the following :-') ;
  217.             WITH  SetMenu^  DO
  218.                FOR i := 1 TO ShowCount DO (* include 'ALL' *)
  219.                   Writeln( Cmd[i] )
  220.          END
  221.       ELSE (* find feature's index *)
  222.          BEGIN
  223.             (* add 'ALL' to the search *)
  224.             SetMenu^.numcmds := ShowCount ;
  225.             i := PopUniqueCmdIndex( id, RECAST(SetMenu, pNameDesc) ) ;
  226.             SetMenu^.numcmds := SetCount ;
  227.  
  228.             IF (i <= SetCount) THEN Feature( i )
  229.             ELSE
  230.                IF (i = ShowCount) THEN
  231.                   BEGIN
  232.                      FOR i := 1 TO SetCount DO Feature(i)
  233.                   END
  234.                ELSE
  235.                   IF (i = ShowNot) THEN
  236.                      Writeln('?Not a SHOW parameter: ', id)
  237.                   ELSE
  238.                      IF (i = ShowAmbig) THEN
  239.                         Writeln('%Ambiguous SHOW parameter: ', id)
  240.          END ; (* else *)
  241.       Writeln
  242.    END . (*-DoShow-*)
  243.  
  244.