home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / lilith.zip / m2kerm.mod < prev    next >
Text File  |  1988-08-16  |  5KB  |  213 lines

  1. IMPLEMENTATION MODULE M2Kermit;
  2. (************************************************************************)
  3. (* This is the main body of the Modula-2 Kermit version. It reads a     *)
  4. (* command line and interprets it                                       *)
  5. (* written:            08.10.85     Matthias Aebi                       *)
  6. (* last modification:  26.02.86     Matthias Aebi                       *)
  7. (************************************************************************)
  8.  
  9. FROM InOut     IMPORT WriteString, WriteLn, Write;
  10. FROM KermMisc  IMPORT ClrScr, ReadString;
  11. FROM KermDir   IMPORT Dir;
  12. FROM KermFini  IMPORT Finish;
  13. FROM KermDel   IMPORT Delete;
  14. FROM KermGet   IMPORT Get;
  15. FROM KermHelp  IMPORT Help;
  16. FROM KermParam IMPORT LPrompt;
  17. FROM KermRecv  IMPORT Receive;
  18. FROM KermSend  IMPORT Send;
  19. FROM KermSet   IMPORT Set;
  20. FROM KermServ  IMPORT Server;
  21. FROM KermShow  IMPORT Show;
  22. FROM KermTerm  IMPORT Term;
  23. FROM KermType  IMPORT Type;
  24. FROM KermVers  IMPORT Version;
  25.  
  26. VAR
  27.     cmd  : ARRAY [0..31] OF CHAR;
  28.  
  29. (************************************************************************)
  30.                               PROCEDURE GetCmdLine;
  31. (************************************************************************)
  32. VAR
  33.     line : ARRAY [0..63] OF CHAR;
  34.     i    : CARDINAL;
  35.     j    : CARDINAL;
  36.  
  37. BEGIN
  38.     REPEAT
  39.  
  40.         WriteLn;
  41.         WriteString(LPrompt);
  42.         Write(">");
  43.         ReadString(line);
  44.  
  45.         i := 0;
  46.         j := 0;
  47.  
  48.         (* parse cmd line, find parameters *)
  49.         WHILE (line[i] # 0C) AND (line[i] = " ") DO  (* skip blanks *)
  50.             INC(i);
  51.         END;
  52.  
  53.         j := 0;
  54.         WHILE (line[i] # 0C) AND (line[i] # " ") DO   (* move cmd *)
  55.             IF (line[i] >= "a") AND (line[i] <= "z")
  56.             THEN
  57.                 line[i] := CAP(line[i]);
  58.             END;
  59.  
  60.             cmd[j] := line[i];
  61.             INC(j);
  62.             INC(i);
  63.         END;
  64.         cmd[j] := 0C;
  65.  
  66.         WHILE (line[i] # 0C) AND (line[i] = " ") DO  (* skip blanks *)
  67.             INC(i);
  68.         END;
  69.  
  70.         j := 0;
  71.         WHILE (line[i] # 0C) AND (line[i] # " ") DO   (* move Param1 *)
  72.             Param1[j] := line[i];
  73.             INC(j);
  74.             INC(i);
  75.         END;
  76.         Param1[j] := 0C;
  77.  
  78.         WHILE (line[i] # 0C) AND (line[i] = " ") DO  (* skip blanks *)
  79.             INC(i);
  80.         END;
  81.  
  82.  
  83.         j := 0;
  84.         WHILE line[i] # 0C  DO   (* move Param2 (rest of line) *)
  85.             Param2[j] := line[i];
  86.             INC(j);
  87.             INC(i);
  88.         END;
  89.         Param2[j] := 0C;
  90.  
  91.     UNTIL cmd[0] <> 0C;
  92.  
  93. END GetCmdLine;
  94.  
  95.  
  96. (************************************************************************)
  97.                       PROCEDURE ExecCmd(): BOOLEAN;
  98. (************************************************************************)
  99. VAR
  100.     knownCmd : BOOLEAN;
  101.  
  102. BEGIN
  103.     knownCmd := TRUE;
  104.  
  105.     CASE cmd[0] OF
  106.         "B": (* Bye *)
  107.             Finish("L");
  108.             RETURN TRUE; |
  109.  
  110.         "C": (* Connect *)
  111.             Term; |
  112.  
  113.         "D":
  114.             CASE cmd[1] OF
  115.                 "I":
  116.                     Dir; |
  117.  
  118.                 "E":
  119.                     Delete;
  120.  
  121.                 ELSE
  122.                     knownCmd := FALSE;
  123.  
  124.             END; |
  125.  
  126.         "E": (* Exit *)
  127.             RETURN TRUE; |
  128.  
  129.         "F": (* Finish *)
  130.             Finish("F"); |
  131.  
  132.         "G":
  133.             Get; |
  134.  
  135.         "H","?":
  136.             Help; |
  137.  
  138.         "L": (* Logout *)
  139.             Finish("L"); |
  140.  
  141.         "Q": (* Quit *)
  142.             RETURN TRUE; |
  143.  
  144.         "R":
  145.             Receive; |
  146.  
  147.         "S":
  148.             CASE cmd[1] OF
  149.                 "E":
  150.                     CASE cmd[2] OF
  151.                         "N":
  152.                             Send; |
  153.  
  154.                         "T":
  155.                             Set; |
  156.  
  157.                         "R":
  158.                             IF Server()
  159.                             THEN
  160.                                 RETURN TRUE; (* got logout command *)
  161.                             END;
  162.  
  163.                         ELSE
  164.                             knownCmd := FALSE;
  165.  
  166.                     END; |
  167.  
  168.                 "H":
  169.                     Show;
  170.  
  171.                 ELSE
  172.                     knownCmd := FALSE;
  173.  
  174.             END; |
  175.  
  176.         "T":
  177.             Type; |
  178.  
  179.         "V":
  180.             Version;
  181.  
  182.         ELSE
  183.             knownCmd := FALSE;
  184.     END;
  185.  
  186.     IF (NOT knownCmd) AND (cmd[0] <> 0C)
  187.     THEN
  188.         WriteLn;
  189.         WriteString("Unknown or ambigous command. "); WriteLn;
  190.         WriteString("For a list of commands type 'Help'"); WriteLn;
  191.     END;
  192.     RETURN FALSE;
  193. END ExecCmd;
  194.  
  195.  
  196. (************************************************************************)
  197.                              (* Main Program *)
  198. (************************************************************************)
  199. BEGIN
  200.     ClrScr;
  201.     WriteLn;
  202.     WriteString(VersionStr);
  203.     WriteLn;
  204.     WriteString("For a list of commands type 'Help'");
  205.     WriteLn;
  206.     WriteLn;
  207.  
  208.     REPEAT
  209.         GetCmdLine;
  210.     UNTIL ExecCmd();
  211.     ClrScr;
  212. END M2Kermit.
  213.