home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / gkermit68k.tar.gz / gkermit68.tar / gkermit68 / gproto.c < prev    next >
C/C++ Source or Header  |  2002-03-12  |  12KB  |  365 lines

  1.  
  2. /* WARNING -- This C source program generated by gwart preprocessor. */
  3. /* Do not edit this file; edit the gwart-format source file instead, */
  4. /* and then run it through gwart to produce a new C source file.     */
  5.  
  6. /* G P R O T O  --  Protocol module for gkermit  */             /* -*-C-*- */
  7.  
  8. /*
  9.   Author:
  10.     Frank da Cruz
  11.     The Kermit Project
  12.     Columbia University
  13.     612 West 115th Street
  14.     New York NY 10025-7799  USA
  15.     http://www.columbia.edu/kermit/
  16.     kermit@columbia.edu
  17.  
  18.   Copyright (C) 1999,
  19.   The Trustees of Columbia University in the City of New York.
  20.  
  21.   This program is free software; you can redistribute it and/or modify
  22.   it under the terms of the GNU General Public License as published by
  23.   the Free Software Foundation; either version 2 of the License, or
  24.   (at your option) any later version.
  25.  
  26.   This program is distributed in the hope that it will be useful,
  27.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29.   GNU General Public License for more details.
  30.  
  31.   You should have received a copy of the GNU General Public License
  32.   along with this program; if not, write to the Free Software
  33.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  34. */
  35. #include <stdio.h>
  36. #include "gkermit.h"
  37.  
  38. _MYPROTOTYPE( int closof, (void) );    /* Close output file */
  39. _MYPROTOTYPE( VOID errpkt, (char *) );    /* Send Error packet */
  40.  
  41. extern char * xdata, *rdatap, **cmlist, *cmarg, *rpar(), filnam[];
  42. extern int start, bctu, bctr, delay, cx, cz, failure, attributes, datalen;
  43. extern int streamok, streaming, timint;
  44. extern FILE * db;
  45.  
  46. static int x;
  47.  
  48. static VOID
  49. stremon() {
  50.                 /* Start streaming if negotiated */
  51.     x = 0;
  52.     if (streamok > 0) {
  53.     streaming = 1;
  54.     timint = 0;
  55.     }
  56. }
  57.  
  58. /* Declare gwart states (like lex) */
  59.  
  60. #define ssini 1
  61. #define ssfil 2
  62. #define ssdat 3
  63. #define ssatt 4
  64. #define sseot 5
  65. #define sseof 6
  66. #define sipkt 7
  67. #define srini 8
  68. #define srfil 9
  69. #define srdat 10
  70. #define sratt 11
  71.  
  72. /* Packets are read by the input() function, which returns the packet type */
  73. /* that serves as the input to the state machine, which follows... */
  74.  
  75.  
  76. #define BEGIN state =
  77.  
  78. int state = 0;
  79.  
  80. int
  81. gwart()
  82. {
  83.     int c,actno;
  84.     extern short tbl[];
  85.     while (1) {
  86.     c = input() - 32;
  87.     if (c < 0 || c > 95) c = 0;
  88.     if ((actno = tbl[c + state*96]) != -1)
  89.         switch(actno) {
  90. case 1:
  91.     {                    /* Start state for Send. */
  92.     tinit();                /* Initialize transaction. */
  93.     if (sinit('S') < 0) { errpkt("sinit"); } /* Build and send the S packet. */
  94.     else BEGIN ssini;
  95. }
  96.     break;
  97. case 2:
  98.     {                /* Receive ACK to I packet */
  99.     spar(rdatap);            /* Set parameters from it */
  100.     bctu = bctr;            /* Switch to negotiated block check */
  101.     if (gnfile() > 0) {            /* Is there a file to send? */
  102.         if (sfile() < 0) {        /* Yes, open it, send F packet, */
  103.         errpkt("sfile");
  104.     } else {            /* No error */
  105.         stremon();
  106.         BEGIN ssfil;
  107.     }
  108.     } else {                /* No files to send, */
  109.         if (seot() < 0) { errpkt("seot"); } /* so send EOT packet. */
  110.         else BEGIN sseot;
  111.     }
  112. }
  113.     break;
  114. case 3:
  115.     {                /* Receive ACK to File header packet */
  116.     if (attributes) {            /* If attributes negotiated */
  117.     if (sattr() < 0) {        /* Send file attributes */
  118.         errpkt("sattr");
  119.     } else
  120.       BEGIN ssatt;
  121.     } else if ((x = sdata()) == 0) {    /* Otherwise send first Data packet */
  122.     if (seof("") < 0) {        /* Empty file - send EOF */
  123.         errpkt("seof");
  124.     } else {
  125.         BEGIN sseof;
  126.     }
  127.     } else if (x < 0) {            /* Error */
  128.     errpkt("sdata");
  129.     } else {                /* OK - switch to Data state */
  130.     BEGIN ssdat;
  131.     }
  132. }
  133.     break;
  134. case 4:
  135.     {                /* Receive ACK to Attribute packet */
  136.     if (*rdatap == 'N') {        /* Check for refusal */
  137.     seof("D");
  138.     BEGIN sseof;
  139.     } else if ((x = sdata()) == 0) {    /* Otherwise send first Data packet */
  140.     if (seof("") < 0) {        /* Empty file - send EOF */
  141.         errpkt("seof");
  142.     } else {
  143.         BEGIN sseof;
  144.     }
  145.     } else if (x < 0) {            /* Error */
  146.     errpkt("sdata");
  147.     } else {                /* OK - switch to Data state */
  148.     BEGIN ssdat;
  149.     }
  150. }
  151.     break;
  152. case 5:
  153.     {                /* Receive ACK to Data packet */
  154.     if (*rdatap == 'X')            /* Check for file cancellation */
  155.       cx = 1;
  156.     else if (*rdatap == 'Z')        /* Check for batch cancellation */
  157.       cz = 1;
  158.     if ((x = sdata()) == 0) {        /* Send data packet if data left. */
  159.     if (seof((cx | cz) ? "D" : "") < 0) { /* If not, send Z packet */
  160.         errpkt("seof");
  161.     } else {
  162.         BEGIN sseof;
  163.     }
  164.     } else if (x < 0)            /* Fatal error sending data */
  165.       errpkt("sdata");
  166. }
  167.     break;
  168. case 6:
  169.     {                /* Receive ACK to EOF */
  170.     if (gnfile() > 0) {            /* Get next file from list */
  171.     if (sfile() > 0)
  172.       BEGIN ssfil;
  173.     else { errpkt("sfile"); }
  174.     } else {                /* No more files */
  175.     seot();                /* Send EOT */
  176.     BEGIN sseot;
  177.     }
  178. }
  179.     break;
  180. case 7:
  181.     { return(failure); }
  182.     break;
  183. case 8:
  184.     { tinit(); rinit(); BEGIN srini; }
  185.     break;
  186. case 9:
  187.     {                /* Receive S packet */
  188.     spar(rdatap);            /* Set parameters from it */
  189.     ack1(rpar());            /* ACK with our parameters */
  190.     bctu = bctr;            /* Switch to negotiated block check */
  191.     stremon();
  192.     BEGIN srfil;            /* Wait for file or EOT */
  193. }
  194.     break;
  195. case 10:
  196.     { ack(); return(failure); }
  197.     break;
  198. case 11:
  199.     {                /* Receive File header packet */
  200.     if (rcvfil() < 0) {
  201.     errpkt("rcvfil");
  202.     } else {
  203.     encstr(filnam);
  204.     ack1(xdata);
  205.     stremon();
  206.     BEGIN sratt;
  207.     }
  208. }
  209.     break;
  210. case 12:
  211.     {                /* Receive Attribute packet */
  212.     if (gattr(rdatap) == 0) {
  213.     ack();
  214.     } else {
  215.     ack1("\"");
  216.     }
  217. }
  218.     break;
  219. case 13:
  220.     {                /* Receive first Data packet */
  221.     if (decode(datalen) < 0) {
  222.     errpkt("Packet decoding error");
  223.     } else {
  224.     ack();
  225.     BEGIN srdat;
  226.     }
  227. }
  228.     break;
  229. case 14:
  230.     {                /* Empty file */
  231.     if (*rdatap == 'D')            /* Check for Discard directive */
  232.       cx = 1;
  233.     if (closof() < 0) {            /* Close the output file */
  234.     errpkt("closof");
  235.     } else {
  236.     ack();                /* Send ACK */
  237.     BEGIN srfil;            /* Wait for another file or EOT */
  238.     }
  239. }
  240.     break;
  241. case 15:
  242.     {                /* Receive Data packet */
  243.     if (decode(datalen) < 0)
  244.       errpkt("Packet decoding error");
  245.     else
  246.       ack();
  247. }
  248.     break;
  249. case 16:
  250.     {                /* Receive EOF packet */
  251.     if (*rdatap == 'D')            /* Check for Discard directive */
  252.       cx = 1;
  253.     if (closof() < 0) {            /* Close the output file */
  254.     errpkt("closof");
  255.     } else {
  256.     ack();                /* Send ACK */
  257.     BEGIN srfil;            /* Wait for another file or EOT */
  258.     }
  259. }
  260.     break;
  261. case 17:
  262.     {                    /* Start state for Get */
  263.     tinit();                /* Initialize transaction */
  264.     ginit();                /* Initialize Get */
  265.     sinit('I');                /* Send I packet */
  266.     BEGIN sipkt;
  267. }
  268.     break;
  269. case 18:
  270.     {                /* Receive ACK for I packet */
  271.     spar(rdatap);            /* Set parameters from it */
  272.     if (scmd('R',cmarg) < 0)        /* Send GET packet file filespec */
  273.       errpkt("scmd");
  274.     else
  275.       BEGIN srini;            /* Wait for S packet */
  276. }
  277.     break;
  278. case 19:
  279.     { return(failure = 1); }
  280.     break;
  281. case 20:
  282.     { errpkt("Unknown packet type"); }
  283.     break;
  284.  
  285.         }
  286.     }
  287. }
  288.  
  289. short tbl[] = {
  290.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  291.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  292.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  293.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  294.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  295.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  296.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  297.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  298.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  299.  20, 20, 20, 20, 20, 20, 20, 20, 20,  2, 20, 20, 20, 20, 20, 20,
  300.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  301.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  302.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  303.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  304.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  305.  20, 20, 20, 20, 20, 20, 20, 20, 20,  3, 20, 20, 20, 20, 20, 20,
  306.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  307.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  308.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  309.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  310.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  311.  20, 20, 20, 20, 20, 20, 20, 20, 20,  5, 20, 20, 20, 20, 20, 20,
  312.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  313.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  314.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  315.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  316.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  317.  20, 20, 20, 20, 20, 20, 20, 20, 20,  4, 20, 20, 20, 20, 20, 20,
  318.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  319.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  320.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  321.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  322.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  323.  20, 20, 20, 20, 20, 20, 20, 20, 20,  7, 20, 20, 20, 20, 20, 20,
  324.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  325.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  326.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  327.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  328.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  329.  20, 20, 20, 20, 20, 20, 20, 20, 20,  6, 20, 20, 20, 20, 20, 20,
  330.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  331.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  332.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  333.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  334.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  335.  20, 20, 20, 20, 20, 20, 20, 20, 20, 18, 20, 20, 20, 20, 20, 20,
  336.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  337.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  338.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  339.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  340.  20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  341.  20, 20, 20,  9, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  342.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  343.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  344.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  345.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  346.  20, 20, 10, 20, 20, 19, 11, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  347.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  348.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  349.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  350.  -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  351.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  352.  20, 20, 20, 20, 15, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  353.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 16, 20, 20, 20, 20, 20,
  354.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  355.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  356.   0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  357.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  358.  20, 12, 20, 20, 13, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  359.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 14, 20, 20, 20, 20, 20,
  360.  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  361.  20, 20, 17,  1, 20, 20,  8, 20, 20, 20, 20, 20, 20, 20, 20,20
  362. };
  363.  
  364.  
  365.