Annotation of researchv10dc/lbin/kermit/ckcmai.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.