home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ncr9800 / ckvmai.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  15KB  |  335 lines

  1. #ifndef MCS_FLAG
  2. char     *versio = "IVS-Kermit, 4E(072) 06 June 90";
  3. #else
  4. char     *versio = "MCS-Kermit, 4E(072) 06 June 90";
  5. #endif
  6.  
  7. /*  C K V M A I  --  V-Kermit Main program  */
  8.  
  9. /**********************************************************************
  10. *                                                                     *
  11. * IVS / MCS-Kermit REL 2                                              *
  12. * source code                                                         *
  13. *                                                                     *
  14. * Change History:                                                     *
  15. *                                                                     *
  16. *                1. Modify C-Kermit(4E) source code to                *
  17. *                   produce new module for MCS/IVS-Kermit             *
  18. *                   ORIGINAL RELEASE                                  *
  19. *                   June 22, 1990                                     *
  20. *                                                                     *
  21. *                                                                     *
  22. ***********************************************************************/
  23.  
  24.  
  25. /*
  26.  4E, add long packet support, plus changes for Apollo and Data General
  27.  support from SAS Institute, and for Macintosh from Planning Research Corp,
  28.  plus several important bug fixes.
  29.  
  30.  Author: Frank da Cruz (fdc@cunixc.cc.columbia.edu, FDCCU@CUVMA.BITNET),
  31.  Columbia University Center for Computing Activities.
  32.  First released January 1985.
  33.  Copyright (C) 1985, 1989, Trustees of Columbia University in the City of New
  34.  York.  Permission is granted to any individual or institution to use, copy, or
  35.  redistribute this software so long as it is not sold for profit, provided this
  36.  copyright notice is retained.
  37.  
  38.  The Kermit file transfer protocol was developed at Columbia University.
  39.  It is named after Kermit the Frog, star of the television series THE
  40.  MUPPET SHOW; the name is used by permission of Henson Associates, Inc.
  41.  "Kermit" is also Celtic for "free".
  42.  
  43.  Thanks to Herm Fischer of Encino CA for extensive contributions to version 4,
  44.  and to the following people for their contributions over the years:
  45.  
  46.    Larry Afrin, Clemson U
  47.    Robert Andersson, Oslo, Norway
  48.    Stan Barber, Rice U
  49.    Charles Brooks, EDN
  50.    Mike Brown, Purdue U
  51.    Bill Catchings, formerly of CUCCA
  52.    Bob Cattani, Columbia U CS Dept
  53.    Howard Chu, U of Michigan
  54.    Bill Coalson, McDonnell Douglas
  55.    Alan Crosswell, CUCCA
  56.    Jeff Damens, formerly of CUCCA
  57.    Joe R. Doupnik, Utah State U
  58.    Glenn Everhart, RCA Labs
  59.    Carl Fongheiser, CWRU
  60.    John Gilmore, UC Berkeley
  61.    Yekta Gursel, MIT
  62.    Jim Guyton, Rand Corp
  63.    Stan Hanks, Rice U.
  64.    Ken Harrenstein, SRI
  65.    Chuck Hedrick, Rutgers U
  66.    Ron Heiby, Motorola Micromputer Division
  67.    Steve Hemminger, Tektronix
  68.    Randy Huntziger, NLM
  69.    Phil Julian, SAS Institute
  70.    Jim Knutson, U of Texas at Austin
  71.    John Kunze, UC Berkeley
  72.    David Lawyer, UC Irvine
  73.    S.O. Lidie, Lehigh U
  74.    Chris Maio, Columbia U CS Dept
  75.    Leslie Mikesall, American Farm Bureau
  76.    Martin Minow, DEC
  77.    Ray Moody, Purdue U
  78.    Tony Movshon, NYU
  79.    Dan Murphy, ???
  80.    Jim Noble, Planning Research Corporation
  81.    Paul Placeway, Ohio State U
  82.    Ken Poulton, HP Labs
  83.    Frank Prindle, NADC
  84.    Anton Rang, ???
  85.    Scott Ribe, ???
  86.    Jack Rouse, SAS Institute
  87.    Stew Rubenstein, Harvard
  88.    Dan Schullman, DEC
  89.    Gordon Scott, Micro Focus, Newbury UK
  90.    David Sizeland, U of London Medical School
  91.    Bradley Smith, UCLA
  92.    Andy Tanenbaum, THE, Netherlands
  93.    Markku Toijala, Helsinki U of Technology
  94.    Dave Tweten, AMES-NAS
  95.    Walter Underwood, Ford Aerospace
  96.    Pieter Van Der Linden, Centre Mondial (Paris)
  97.    Wayne Van Pelt, GE/CRD
  98.    Mark Vasoll & Gregg Wonderly, Oklahoma State University
  99.    Stephen Walton, Ametek Computer
  100.    Lauren Weinstein
  101.    Joachim Wiesel, U of Karlsruhe
  102.    Dave Woolley, CAP Communication Systems, London
  103.    John Zeeff, Ann Arbor, MI
  104.    Paul E. Gladden, NCR Corp., E&M San Diego
  105.    Darrell Edwards, NCR Corp., E&M San Diego
  106.    Paul Shaffer, NCR Corp., E&M San Diego
  107.  and many others.
  108. */
  109.  
  110. #include "ckcsym.h"
  111. #include "ckcker.h"
  112. #include "ckcdeb.h"
  113.  
  114. #ifdef MCS_FLAG
  115. #include "mcs_defs_h"
  116. #endif
  117.  
  118. char  *hlptxt="VRX Kermit Commands Supported: GET, SEND FINISH\r\n\0";
  119.  
  120. char  *srvtxt = "\r\n Kermit-VRX server starting. \r\n\0";
  121.  
  122. /* Declarations for Send-Init Parameters */
  123.  
  124. int     spsiz = DSPSIZ,             /* Biggest packet size we can send */
  125. spsizf = 0,                         /* Flag to override what you ask for */
  126. rpsiz = DRPSIZ,                     /* Biggest we want to receive */
  127. urpsiz = DRPSIZ,                    /* User-requested rpsiz */
  128. maxrps = MAXRP,                     /* Maximum incoming long packet size */
  129. maxsps = MAXSP,                     /* Maximum outbound l.p. size */
  130. maxtry = MAXTRY,                    /* Maximum retries per packet */
  131. wsize = 1,                          /* Window size */
  132. timint = DMYTIM,                    /* Timeout interval I use */
  133. rtimo = URTIME,                     /* Timeout I want you to use */
  134. timef = 0,                          /* Flag to override what you ask */
  135. npad = MYPADN,                      /* How much padding to send */
  136. mypadn = MYPADN,                    /* How much padding to ask for */
  137. bctr = 1,                           /* Block check type requested */
  138. bctu = 1,                           /* Block check type used */
  139. ebq =  MYEBQ,                       /* 8th bit prefix */
  140. ebqflg = 0,                         /* 8th-bit quoting flag */
  141. rqf = -1,                           /* Flag used in 8bq negotiation */
  142. rq = 0,                             /* Received 8bq bid */
  143. sq = 'Y',                           /* Sent 8bq bid */
  144. rpt = 0,                            /* Repeat count */
  145. rptq = MYRPTQ,                      /* Repeat prefix */
  146. rptflg = 0;                         /* Repeat processing flag */
  147.  
  148. int     capas = 10,                 /* Position of Capabilities */
  149. atcapb = 8,                         /* Attribute capability */
  150. atcapr = 0,                         /*  requested */
  151. atcapu = 0,                         /*  used */
  152. swcapb = 4,                         /* Sliding Window capability */
  153. swcapr = 0,                         /*  requested */
  154. swcapu = 0,                         /*  used */
  155. lpcapb = 2,                         /* Long Packet capability */
  156. lpcapr = 1,                         /*  requested */
  157. lpcapu = 0;                         /*  used */
  158.  
  159. CHAR padch = SNDPADC,                /* Padding character to send */
  160. mypadc = MYPADC,                    /* Padding character to ask for */
  161. seol = MYEOL,                       /* End-Of-Line character to send */
  162. eol = LF,                           /* End-Of-Line character to look for */
  163. ctlq = CTLQ,                        /* Control prefix in incoming data */
  164. myctlq = CTLQ;                      /* Outbound control character prefix */
  165.  
  166.  
  167. /* Packet-related variables */
  168.  
  169. int     pktnum = 0,                 /* Current packet number */
  170. prvpkt = -1,                        /* Previous packet number */
  171. sndtyp,                             /* Type of packet just sent */
  172. rsn,                                /* Received packet sequence number */
  173. rln,                                /* Received packet length */
  174. size,                               /* Current size of output pkt data */
  175. osize,                              /* Previous output packet data size */
  176. maxsize,                            /* Max size for building data field */
  177. spktl = 0;                          /* Length packet being sent */
  178.  
  179. CHAR sndpkt[MAXSP+100],             /* Entire packet being sent */
  180. recpkt[MAXRP+200],                  /* Packet most recently received */
  181. *rdatap,                            /* Pointer to received packet data */
  182. data[MAXSP+4],                      /* Packet data buffer */
  183. srvcmd[MAXRP+4],                    /* Where to decode server command */
  184. *srvptr,                            /* Pointer to above */
  185. mystch = SOH,                       /* Outbound packet-start character */
  186. stchr = SOH;                        /* Incoming packet-start character */
  187.  
  188. /* File-related variables */
  189.  
  190. CHAR filnam[50];                        /* Name of current file. */
  191.  
  192. int     nfils;                              /* Number of files in file group */
  193. long     fsize;                             /* Size of current file */
  194.  
  195. /* Communication line variables */
  196.  
  197. CHAR ttname[50];                        /* Name of communication line. */
  198.  
  199. int     parity,                     /* Parity specified, 0,'e','o',etc */
  200. flow,                               /* Flow control, 1 = xon/xoff */
  201. speed = -1,                         /* Line speed */
  202. turn = 0,                           /* Line turnaround handshake flag */
  203. turnch = XON,                       /* Line turnaround character */
  204. duplex = 0,                         /* Duplex, full by default */
  205. escape = 034,                       /* Escape character for connect */
  206. delay = DDELAY,                     /* Initial delay before sending */
  207. mdmtyp = 0;                         /* Modem type (initially none)  */
  208.  
  209. int     tlevel = -1;                    /* Take-file command level */
  210.  
  211. /* Statistics variables */
  212.  
  213. long     filcnt,            /* Number of files in transaction */
  214. flci,                       /* Characters from line, current file */
  215. flco,                       /* Chars to line, current file  */
  216. tlci,                       /* Chars from line in transaction */
  217. tlco,                       /* Chars to line in transaction */
  218. ffc,                        /* Chars to/from current file */
  219. tfc;                        /* Chars to/from files in transaction */
  220.  
  221. int     tsecs;              /* Seconds for transaction */
  222.  
  223. /* Flags */
  224.  
  225. int     deblog = 0,                 /* Flag for debug logging */
  226. pktlog = 0,                         /* Flag for packet logging */
  227. seslog = 0,                         /* Session logging */
  228. tralog = 0,                         /* Transaction logging */
  229. displa = 0,                         /* File transfer display on/off */
  230. stdouf = 0,                         /* Flag for output to stdout */
  231. xflg   = 0,                         /* Flag for X instead of F packet */
  232. hcflg  = 0,                         /* Doing Host command */
  233. fncnv  = 1,                         /* Flag for file name conversion */
  234. binary = 0,                         /* Flag for binary file */
  235. savmod = 0,                         /* Saved file mode */
  236. cmask  = 0177,                      /* Connect byte mask */
  237. fmask  = 0377,                      /* File byte mask */
  238. /* warn   = 0,                      Flag for file warning */
  239. quiet  = 0,                         /* Be quiet during file transfer */
  240. local  = 0,                         /* Flag for external tty vs stdout */
  241. server = 0,                         /* Flag for being a server */
  242. cnflg  = 0,                         /* Connect after transaction */
  243. cxseen = 0,                         /* Flag for cancelling a file */
  244. czseen = 0,                         /* Flag for cancelling file group */
  245. send_id = 1,         /* Flag for keeping id-fields in SPUR files */
  246. recv_id = 1,         /* Flag for keeping id-fields in SPUR files */
  247. send_num = 1,        /* Flag for keeping line numbers in SPUR files */
  248. recv_num = 1,        /* Flag for keeping line numbers in SPUR files */
  249. send_renum = 0,      /* Flag for renumbering line numbers in SPUR files */
  250. recv_renum = 0,      /* Flag for renumbering line numbers in SPUR files */
  251. send_addnum = 0,
  252. recv_addnum = 0,
  253. keep = 0;                           /* Keep incomplete files */
  254.  
  255. /* Variables passed from command parser to protocol module */
  256.  
  257. char     parser();                          /* The parser itself */
  258. char     sstate  = 0;                       /* Starting state for automaton */
  259. char     *cmarg  = "";                      /* Pointer to command data */
  260. char     *cmarg2 = "";                      /* Pointer to 2nd command data */
  261. char     **cmlist;                          /* Pointer to file list in argv */
  262.  
  263. /* Miscellaneous */
  264.  
  265. char     **xargv;                           /* Global copies of argv */
  266. int     xargc;                             /* and argc  */
  267.  
  268. extern char     *dftty;                 /* Default tty name from ckx???.c */
  269. extern int     dfloc;                   /* Default location: remote/local */
  270. extern int     dfprty;                  /* Default parity */
  271. extern int     dfflow;                  /* Default flow control */
  272.  
  273. /*  M A I N  --  C-Kermit main program  */
  274.  
  275. main(argc, argv)
  276. int     argc;
  277. char     **argv;
  278. {
  279.  
  280.      char     *strcpy();
  281. #ifdef MCS_FLAG
  282.      char     status[3];
  283. #endif
  284.  
  285.      /* Do some initialization */
  286.  
  287. #ifdef MCS_FLAG
  288.      mcs_enable("r",QUEUENAME,status);
  289.      mcs_enable("w",QUEUENAME,status);
  290. #endif
  291.      xargc = argc;                       /* Make global copies of argc */
  292.      xargv = argv;                       /* ...and argv. */
  293.      sstate = 0;                         /* No default start state. */
  294.      strcpy(ttname, dftty);               /* Set up default tty name. */
  295.      local = dfloc;                      /* And whether it's local
  296.                                             or remote.            */
  297.      parity = dfprty;                    /* Set initial parity, */
  298.      flow = dfflow;                      /* and flow control. */
  299.      if (sysinit() < 0)
  300.           doexit(BAD_EXIT); /* And system-dependent things. */
  301.  
  302.      /*** attempt to take ini file before doing command line ***/
  303.  
  304.      cmdini();                           /* Sets tlevel */
  305.      while (tlevel > -1) {               /* Execute init file. */
  306.           sstate = parser();              /* Loop getting commands. */
  307.           if (sstate)
  308.                proto();            /* Enter protocol if requested. */
  309.      }
  310.  
  311.      /* Look for a UNIX-style command line... */
  312.  
  313.      if (argc > 1) {                     /* Command line arguments? */
  314.           sstate = cmdlin();              /* Yes, parse. */
  315.           if (sstate) {
  316.                proto();                    /* Take any requested action,
  317.                                               then */
  318.                if (!quiet)
  319.                     conoll("");     /* put cursor back at left margin, */
  320.                if (cnflg)
  321.                     conect();        /* connect if requested, */
  322.                doexit(GOOD_EXIT);          /* and then exit with status 0. */
  323.           }
  324.      }
  325.  
  326.      /* If no action requested on command line, enter interactive parser */
  327.  
  328.      herald();                           /* Display program herald. */
  329.      while (1) {                          /* Loop getting commands. */
  330.           sstate = parser();
  331.           if (sstate)
  332.                proto();            /* Enter protocol if requested. */
  333.      }
  334. }
  335.