home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / minix1 / mxcmai.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  11KB  |  243 lines

  1. char *versio = "C-Kermit, 4D(061) 8 Sep 86";
  2.  
  3. /*  C K C M A I  --  C-Kermit Main program  */
  4.  
  5. /*
  6.  Authors: Frank da Cruz, Bill Catchings, Jeff Damens;
  7.  Columbia University Center for Computing Activities, 1984-86.
  8.  Copyright (C) 1986, Trustees of Columbia University in the City of New York.
  9.  Permission is granted to any individual or institution to use, copy, or
  10.  redistribute this software so long as it is not sold for profit, provided this
  11.  copyright notice is retained.
  12. */
  13. /*
  14.  The Kermit file transfer protocol was developed at Columbia University.
  15.  It is named after Kermit the Frog, star of the television series THE
  16.  MUPPET SHOW; the name is used by permission of Henson Associates, Inc.
  17.  "Kermit" is also Celtic for "free".
  18. */
  19. /*
  20.  Thanks to Herm Fischer of Encino CA for extensive contributions to version 4,
  21.  and to the following people for their contributions over the years:
  22.  
  23.    Larry Afrin, Clemson U
  24.    Stan Barber, Rice U
  25.    Charles Brooks, EDN
  26.    Bob Cattani, Columbia CS Dept
  27.    Alan Crosswell, CUCCA
  28.    Carl Fongheiser, CWRU
  29.    Yekta Gursel, MIT
  30.    Jim Guyton, Rand Corp
  31.    Stan Hanks, Rice U.
  32.    Ken Harrenstein, SRI
  33.    Steve Hemminger, Tektronix
  34.    Randy Huntziger, NLM
  35.    Chris Maio, Columbia CS Dept
  36.    Martin Minow, DEC
  37.    Tony Movshon, NYU
  38.    Ken Poulton, HP Labs
  39.    Frank Prindle, NADC
  40.    Jack Rouse, SAS Institute
  41.    Stew Rubenstein, Harvard
  42.    Dan Schullman, DEC
  43.    Bradley Smith, UCLA
  44.    Dave Tweten, AMES-NAS
  45.    Walter Underwood, Ford Aerospace
  46.    Pieter Van Der Linden, Centre Mondial (Paris)
  47.    Mark Vasoll & Gregg Wonderly, Oklahoma State University
  48.    Lauren Weinstein
  49.  
  50.  and many others.
  51. */
  52.  
  53. #include "ckcker.h"
  54. #include "ckcdeb.h"
  55.  
  56. /* Text message definitions.. each should be 256 chars long, or less. */
  57. #ifdef MAC
  58. char *hlptxt = "C-Kermit Server Commands:\n\
  59. \n\
  60. GET filespec, SEND filespec, FINISH, REMOTE HELP\n\
  61. \n\0";
  62. #else
  63. #ifdef AMIGA
  64. char *hlptxt = "C-Kermit Server Commands:\n\
  65. \n\
  66. GET filespec, SEND filespec, FINISH, BYE, REMOTE HELP\n\
  67. \n\0";
  68. #else
  69. char *hlptxt = "C-Kermit Server Commands Supported:\n\
  70. \n\
  71. SEND filespec         GET filespec      FINISH      BYE\n\
  72. \n\
  73. REMOTE commands:\n\
  74. \n\
  75. SPACE [directory]     CWD [directory]   HOST command    HELP\n\
  76. DIRECTORY [filespec]  DELETE filespec   TYPE filespec   WHO [user]\n\
  77. \n\0";
  78. #endif
  79. #endif
  80. char *srvtxt = "\r\n\
  81. C-Kermit server starting.  Return to your local machine by typing\r\n\
  82. its escape sequence for closing the connection, and issue further\r\n\
  83. commands from there.  To shut down the C-Kermit server, issue the\r\n\
  84. FINISH or BYE command and then reconnect.\n\
  85. \r\n\0";
  86.  
  87. /* Declarations for Send-Init Parameters */
  88.  
  89. int spsiz = DSPSIZ,                     /* Biggest packet size we can send */
  90.     spsizf = 0,                         /* Flag to override what you ask for */
  91.     rpsiz = DRPSIZ,                     /* Biggest we want to receive */
  92.     timint = DMYTIM,                    /* Timeout interval I use */
  93.     rtimo = URTIME,                     /* Timeout I want you to use */
  94.     timef = 0,                          /* Flag to override what you ask */
  95.     npad = MYPADN,                      /* How much padding to send */
  96.     mypadn = MYPADN,                    /* How much padding to ask for */
  97.     chklen = 1,                         /* Length of block check */
  98.     bctr = 1,                           /* Block check type requested */
  99.     bctu = 1,                           /* Block check type used */
  100.     ebq =  MYEBQ,                       /* 8th bit prefix */
  101.     ebqflg = 0,                         /* 8th-bit quoting flag */
  102.     rpt = 0,                            /* Repeat count */
  103.     rptq = MYRPTQ,                      /* Repeat prefix */
  104.     rptflg = 0,                         /* Repeat processing flag */
  105.     capas = 0;                          /* Capabilities */
  106.  
  107. CHAR padch = MYPADC,                    /* Padding character to send */
  108.     mypadc = MYPADC,                    /* Padding character to ask for */
  109.     seol = MYEOL,                       /* End-Of-Line character to send */
  110.     eol = MYEOL,                        /* End-Of-Line character to look for */
  111.     ctlq = CTLQ,                        /* Control prefix in incoming data */
  112.     myctlq = CTLQ;                      /* Outbound control character prefix */
  113.  
  114.  
  115. /* Packet-related variables */
  116.  
  117. int pktnum = 0,                         /* Current packet number */
  118.     prvpkt = -1,                        /* Previous packet number */
  119.     sndtyp,                             /* Type of packet just sent */
  120.     size,                               /* Current size of output pkt data */
  121.     osize,                              /* Previous output packet data size */
  122.     maxsize,                            /* Max size for building data field */
  123.     spktl;                              /* Length packet being sent */
  124.  
  125. CHAR sndpkt[MAXPACK*2],                 /* Entire packet being sent */
  126.     recpkt[RBUFL],                      /* Packet most recently received */
  127.     data[MAXPACK+4],                    /* Packet data buffer */
  128.     srvcmd[MAXPACK*2],                  /* Where to decode server command */
  129.     *srvptr,                            /* Pointer to above */
  130.     mystch = SOH,                       /* Outbound packet-start character */
  131.     stchr = SOH;                        /* Incoming packet-start character */
  132.  
  133. /* File-related variables */
  134.  
  135. CHAR filnam[50];                        /* Name of current file. */
  136.  
  137. int nfils;                              /* Number of files in file group */
  138. long fsize;                             /* Size of current file */
  139.  
  140. /* Communication line variables */
  141.  
  142. CHAR ttname[50];                        /* Name of communication line. */
  143.  
  144. int parity,                             /* Parity specified, 0,'e','o',etc */
  145.     flow,                               /* Flow control, 1 = xon/xoff */
  146.     speed = -1,                         /* Line speed */
  147.     turn = 0,                           /* Line turnaround handshake flag */
  148.     turnch = XON,                       /* Line turnaround character */
  149.     duplex = 0,                         /* Duplex, full by default */
  150.     escape = 034,                       /* Escape character for connect */
  151.     delay = DDELAY,                     /* Initial delay before sending */
  152.     mdmtyp = 0;                         /* Modem type (initially none)  */
  153.  
  154.  
  155. /* Statistics variables */
  156.  
  157. long filcnt,                    /* Number of files in transaction */
  158.     flci,                       /* Characters from line, current file */
  159.     flco,                       /* Chars to line, current file  */
  160.     tlci,                       /* Chars from line in transaction */
  161.     tlco,                       /* Chars to line in transaction */
  162.     ffc,                        /* Chars to/from current file */
  163.     tfc;                        /* Chars to/from files in transaction */
  164.  
  165. int tsecs;                      /* Seconds for transaction */
  166.  
  167. /* Flags */
  168.  
  169. int deblog = 0,                         /* Flag for debug logging */
  170.     pktlog = 0,                         /* Flag for packet logging */
  171.     seslog = 0,                         /* Session logging */
  172.     tralog = 0,                         /* Transaction logging */
  173.     displa = 0,                         /* File transfer display on/off */
  174.     stdouf = 0,                         /* Flag for output to stdout */
  175.     xflg   = 0,                         /* Flag for X instead of F packet */
  176.     hcflg  = 0,                         /* Doing Host command */
  177.     fncnv  = 1,                         /* Flag for file name conversion */
  178.     binary = 0,                         /* Flag for binary file */
  179.     savmod = 0,                         /* Saved file mode */
  180.     warn   = 0,                         /* Flag for file warning */
  181.     quiet  = 0,                         /* Be quiet during file transfer */
  182.     local  = 0,                         /* Flag for external tty vs stdout */
  183.     server = 0,                         /* Flag for being a server */
  184.     cnflg  = 0,                         /* Connect after transaction */
  185.     cxseen = 0,                         /* Flag for cancelling a file */
  186.     czseen = 0,                         /* Flag for cancelling file group */
  187.     keep = 0;                           /* Keep incomplete files */
  188.  
  189. /* Variables passed from command parser to protocol module */
  190.  
  191. char parser();                          /* The parser itself */
  192. char sstate  = 0;                       /* Starting state for automaton */
  193. char *cmarg  = "";                      /* Pointer to command data */
  194. char *cmarg2 = "";                      /* Pointer to 2nd command data */
  195. char **cmlist;                          /* Pointer to file list in argv */
  196.  
  197. /* Miscellaneous */
  198.  
  199. char **xargv;                           /* Global copies of argv */
  200. int  xargc;                             /* and argc  */
  201.  
  202. extern char *dftty;                     /* Default tty name from ckx???.c */
  203. extern int dfloc;                       /* Default location: remote/local */
  204. extern int dfprty;                      /* Default parity */
  205. extern int dfflow;                      /* Default flow control */
  206.  
  207. /*  M A I N  --  C-Kermit main program  */
  208.  
  209. main(argc,argv) int argc; char **argv; {
  210.  
  211.     char *strcpy();
  212.  
  213. /* Do some initialization */
  214.  
  215.     xargc = argc;                       /* Make global copies of argc */
  216.     xargv = argv;                       /* ...and argv. */
  217.     sstate = 0;                         /* No default start state. */
  218.     strcpy(ttname,dftty);               /* Set up default tty name. */
  219.     local = dfloc;                      /* And whether it's local or remote. */
  220.     parity = dfprty;                    /* Set initial parity, */
  221.     flow = dfflow;                      /* and flow control. */
  222.     if (sysinit() < 0) doexit(BAD_EXIT); /* And system-dependent things. */
  223.  
  224. /* Look for a UNIX-style command line... */
  225.  
  226.     if (argc > 1) {                     /* Command line arguments? */
  227.         sstate = cmdlin();              /* Yes, parse. */
  228.         if (sstate) {
  229.             proto();                    /* Take any requested action, then */
  230.             if (!quiet) conoll("");     /* put cursor back at left margin, */
  231.             if (cnflg) conect();        /* connect if requested, */
  232.             doexit(GOOD_EXIT);          /* and then exit with status 0. */
  233.         }
  234.     }
  235.  
  236. /* If no action requested on command line, enter interactive parser */
  237.  
  238.     cmdini();                           /* Initialize command parser */
  239.     while(sstate = parser()) {          /* Loop getting commands. */
  240.         if (sstate) proto();            /* Enter protocol if requested. */
  241.     }
  242. }
  243.