home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / wkermit.zip / lckmain.c < prev    next >
C/C++ Source or Header  |  1985-11-11  |  8KB  |  218 lines

  1.  char *versio = "PC-DOS C-Kermit, file transfer module, 4LC(001) 27 July 85.\n\
  2.   Jan A. van der Eijk, NUS Corporation, 26 June 85.";
  3.  
  4. /*  C K C M A I  --  C-Kermit Main program  */
  5.  
  6. /*
  7.  Authors: Frank da Cruz, Bill Catchings, Jeff Damens;
  8.  Columbia University Center for Computing Activities, 1984-85.
  9.  Copyright (C) 1985, Trustees of Columbia University in the City of New York.
  10.  Permission is granted to any individual or institution to use, copy, or
  11.  redistribute this software so long as it is not sold for profit, provided this
  12.  copyright notice is retained.
  13. */
  14. /*
  15.  The Kermit file transfer protocol was developed at Columbia University.
  16.  It is named after Kermit the Frog, star of the television series THE
  17.  MUPPET SHOW; the name is used by permission of Henson Associates, Inc.
  18.  "Kermit" is also Celtic for "free".
  19. */
  20. /*
  21.  Thanks to Herm Fischer of Encino, CA, for extensive contributions to
  22.  version 4, and to the following people for their contributions over the years:
  23.  
  24.    Larry Afrin, Clemson U
  25.    Charles Brooks, EDN
  26.    Bob Cattani & Chris Maio, 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.    Martin Minow, DEC
  36.    Tony Movshon, NYU
  37.    Ken Poulton, HP Labs
  38.    Frank Prindle, NADC
  39.    Stew Rubenstein, Harvard
  40.    Dan Schullman, DEC
  41.    Bradley Smith, UCLA
  42.    Dave Tweten, AMES-NAS
  43.    Walter Underwood, Ford Aerospace
  44.    Pieter Van Der Linden, Centre Mondial (Paris)
  45.    Mark Vasoll & Gregg Wonderly, Oklahoma State University
  46.    Lauren Weinstein, Vortex
  47.  
  48.  and many others.
  49. */
  50.  
  51. #include "lckerm.h"
  52. #include "lckdeb.h"
  53. #include "asiports.h"         /* JAV, NUS  use for Greenleaf COM libs */
  54. #include "stdios.h"           /* JAV, NUS special Greenleaf and Lattice header *
  55.  
  56. /* Declarations for Send-Init Parameters */
  57.  
  58. int spsiz = DSPSIZ,            /* Biggest packet size we can send */
  59.     rpsiz = DRPSIZ,            /* Biggest we want to receive */
  60.     timint = DMYTIM,            /* Timeout interval I use */
  61.     rtimo = URTIME,            /* Timeout I want you to use */
  62.     timef = 0,                /* Flag to override what you ask */
  63.     npad = MYPADN,            /* How much padding to send */
  64.     mypadn = MYPADN,            /* How much padding to ask for */
  65.     chklen = 1,             /* Length of block check */
  66.     bctr = 3,                /* Block check type requested */
  67.     bctu = 1,                /* Block check type used */
  68.     ebq =  MYEBQ,            /* 8th bit prefix */
  69.     ebqflg = 0,             /* 8th-bit quoting flag */
  70.     rpt = 0,                /* Repeat count */
  71.     rptq = MYRPTQ,            /* Repeat prefix */
  72.     rptflg = 0,             /* Repeat processing flag */
  73.     capas = MYCAPA;            /* Capabilities */
  74.  
  75. char padch = MYPADC,            /* Padding character to send */
  76.     mypadc = MYPADC,            /* Padding character to ask for */
  77.     seol = MYEOL,            /* End-Of-Line character to send */
  78.     eol = MYEOL,            /* End-Of-Line character to look for */
  79.     ctlq = CTLQ,            /* Control prefix in incoming data */
  80.     myctlq = CTLQ;            /* Outbound control character prefix */
  81.     wndmax = 31;            /* Maximum window size for table */
  82.     wndsiz = 31;            /* Window size I want */
  83.  
  84. /* Packet-related variables */
  85.  
  86. int pktnum = 0,             /* Current packet number */
  87.     prvpkt = -1,            /* Previous packet number */
  88.     sndtyp,                /* Type of packet just sent */
  89.     size,                /* Current size of output pkt data */
  90.     osize,                /* Previous output packet data size */
  91.     maxsize,                /* Max size for building data field */
  92.     spktl;                /* Length packet being sent */
  93.  
  94. char sndpkt[MAXPACK*2],         /* Entire packet being sent */
  95.     recpkt[RBUFL+2],            /* Packet most recently received */
  96.     data[MAXPACK+4],            /* Packet data buffer */
  97.     srvcmd[MAXPACK*2],            /* Where to decode server command */
  98.     *srvptr,                /* Pointer to above */
  99.     mystch = SOH,            /* Outbound packet-start character */
  100.     stchr = SOH;            /* Incoming packet-start character */
  101.  
  102. /* File-related variables */
  103.  
  104. char filnam[50];            /* Name of current file. */
  105. char fildat[20];            /* File creation date */
  106.  
  107. int nfils;                /* Number of files in file group */
  108. long fsize;                /* Size of current file */
  109.  
  110. /* Communication line variables */
  111.  
  112. char ttname[50];            /* Name of communication line. */
  113.  
  114. int parity,                /* Parity specified, 0,'e','o',etc */
  115.     flow,                /* Flow control, 1 = xon/xoff */
  116.     speed = 1200,            /* Line speed */
  117.     turn = 0,                /* Line turnaround handshake flag */
  118.     turnch = XON,            /* Line turnaround character */
  119.     duplex = 0,             /* Duplex, full by default */
  120.     escape = 034,            /* Escape character for connect */
  121.     delay = DDELAY,            /* Initial delay before sending */
  122.     cdetect = FALSE,            /* Carrier detect not required */
  123.     mdmtyp = 0;             /* Modem type (initially none)    */
  124.  
  125.  
  126. /* Statistics variables */
  127.  
  128. long filcnt,            /* Number of files in transaction */
  129.     flci,            /* Characters from line, current file */
  130.     flco,            /* Chars to line, current file    */
  131.     tlci,            /* Chars from line in transaction */
  132.     tlco,            /* Chars to line in transaction */
  133.     ffc,            /* Chars to/from current file */
  134.     tfc;            /* Chars to/from files in transaction */
  135.  
  136. /* Flags */
  137.  
  138. int deblog = 0,             /* Flag for debug logging */
  139.     pktlog = 0,             /* Flag for packet logging */
  140.     seslog = 0,             /* Session logging */
  141.     tralog = 0,             /* Transaction logging */
  142.     displa = 0,             /* File transfer display on/off */
  143.     stdouf = 0,             /* Flag for output to stdout */
  144.     xflg   = 0,             /* Flag for X instead of F packet */
  145.     hcflg  = 0,             /* Doing Host command */
  146.     fncnv  = 1,             /* Flag for file name conversion */
  147.     binary = 1,             /* Flag for binary file */
  148.     warn   = 1,             /* Flag for file warning */
  149.     quiet  = 0,             /* Be quiet during file transfer */
  150.     local  = 0,             /* Flag for external tty vs stdout */
  151.     server = 0,             /* Flag for being a server */
  152.     cnflg  = 0,             /* Connect after transaction */
  153.     cxseen = 0,             /* Flag for cancelling a file */
  154.     czseen = 0;             /* Flag for cancelling file group */
  155.     filatr = 0;             /* Flag for sending file attributes */
  156.     nxtcas = 1;             /* Flag for sending next attribute */
  157.     capflg = 0;             /* Which capas are supported */
  158.     sldwnd = 0;             /* Flag for sliding window support */
  159.     window = 0;             /* Flag for windowing state */
  160.  
  161. /* Variables passed from command parser to protocol module */
  162.  
  163. char parser();                /* The parser itself */
  164. char sstate  = 0;            /* Starting state for automaton */
  165. char *cmarg  = "";                      /* Pointer to command data */
  166. char *cmarg2 = "";                      /* Pointer to 2nd command data */
  167. char **cmlist;                /* Pointer to file list in argv */
  168.  
  169. /* Miscellaneous */
  170.  
  171. char **xargv;                /* Global copies of argv */
  172. int  xargc;                /* and argc  */
  173.  
  174. extern char *dftty;            /* Default tty name from ckx???.c */
  175. extern int dfloc;            /* Default location: remote/local */
  176. extern int dfprty;            /* Default parity */
  177. extern int dfflow;            /* Default flow control */
  178.  
  179.  
  180.  
  181. /*  M A I N  --  C-Kermit main program    */
  182.  
  183. main(argc,argv) int argc; char **argv; {
  184.  
  185.     char *strcpy();
  186.     char *ptr;
  187.  
  188. /* Do some initialization */
  189.  
  190.     xargc = argc;            /* Make global copies of argc */
  191.     xargv = argv;            /* ...and argv. */
  192.     while (--xargc > 0) {        /* Go through command line words */
  193.     xargv++;            /* and low case it all */
  194.     ptr = *xargv;
  195.     for ( ; *ptr != '\0';*ptr++) {
  196.      *ptr = tolower(*ptr);
  197.     }
  198.     }
  199.     xargc = argc;
  200.     xargv = argv;
  201.     sstate = 0;             /* No default start state. */
  202.     strcpy(ttname,dftty);        /* Set up default tty name. */
  203.     local = dfloc;            /* And whether it's local or remote. */
  204.     flow = dfflow;            /* and flow control. */
  205.  
  206. /* Look for a UNIX-style command line... */
  207.  
  208.     if (argc > 1) {            /* Command line arguments? */
  209.     sstate = cmdlin();        /* Yes, parse. */
  210.     if (sstate) {
  211.         proto();            /* Take any requested action    */
  212.         doexit(GOOD_EXIT);        /* and then exit with status 0. */
  213.     }
  214.     }  else { usage(); }
  215.  
  216. }
  217.  
  218.