home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / old / ckermit5a188 / ckcmai.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  36KB  |  997 lines

  1. #ifndef MAC
  2. char *versio = "C-Kermit 5A(188), 23 Nov 92"; /* Version herald. */
  3. #else
  4. /*
  5.   For Macintosh, also remember to change the Mac-specific version in ckmkr2.r.
  6. */
  7. char *versio = "Mac Kermit 0.99(188) Pre-ALPHA, 23 Nov 92";
  8. #endif /* MAC */
  9. long vernum = 501188L;
  10. /*
  11.   String and numeric version numbers, keep these three in sync!
  12.   First digit of vermum = major version, i.e. 5.
  13.   Second 2 digits of vernum: 00 = no minor version, 01 = A, 02 = B, etc.
  14.   Last three digits are edit number. 
  15. */
  16. #ifndef VERWHO
  17. /* Change verwho in following line, or with -DVERWHO=x in makefile CFLAGS. */
  18. #define VERWHO 0
  19. #endif /* VERWHO */
  20. int verwho = VERWHO; /* Who produced this version, 0 = Columbia University */
  21. /*
  22.   IMPORTANT: If you are working on your own private version of C-Kermit, please
  23.   include some special notation, like your site name or your initials, in the
  24.   "versio" string, e.g. "5A(182)-XXX", and use a nonzero code for the "verwho"
  25.   variable (e.g. in the USA use your zip code).  Unless we stick to this
  26.   discipline, divergent copies of C-Kermit will begin to appear that are
  27.   intistinguishable from each other, which is a big support issue.  Also, if
  28.   you have edited C-Kermit and made copies available to others, please add
  29.   appropriate text to the BUG command (ckuus6.c, function dobug()).
  30. */
  31. #define CKCMAI
  32.  
  33. /*  C K C M A I  --  C-Kermit Main program  */
  34.  
  35. /*
  36.   Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  37.   Columbia University Center for Computing Activities.
  38.  
  39.   COPYRIGHT NOTICE:
  40.  
  41.   Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
  42.   York.  Permission is granted to any individual or institution to use this
  43.   software as long as it is not sold for profit.  This copyright notice must be
  44.   retained.  This software may not be included in commercial products without
  45.   written permission of Columbia University.
  46.  
  47.   DOCUMENTATION:
  48.  
  49.   "Using C-Kermit" by Frank da Cruz and Christine M. Gianone,
  50.   Digital Press, Burlington, MA, USA.  Publication date: Winter 1992.
  51.   Order Number: EY-J896E-DP
  52.   Digital Press ISBN: 1-55558-108-0
  53.   Prentice Hall ISBN: 0-13-037490-3
  54.  
  55.   DISCLAIMER:
  56.  
  57.   The C-Kermit software is provided in source code form by Kermit Development
  58.   and Distribution, Columbia University.  The software is provided "as is;" no
  59.   other warranty is provided, express or implied, including without
  60.   limitations, any implied warranty of merchantability or implied warranty of
  61.   fitness for a particular purpose.
  62.  
  63.   Neither Columbia University nor any of the contributors to the C-Kermit
  64.   development effort, including, but not limited to, AT&T, Digital Equipment
  65.   Corporation, Data General Corporation, or International Business Machines
  66.   Corporation, warrant C-Kermit software or documentation in any way.  In
  67.   addition, neither the authors of any Kermit programs, publications or
  68.   documentation, nor Columbia University nor any contributing institutions or
  69.   individuals acknowledge any liability resulting from program or
  70.   documentation errors.
  71.  
  72.   ACKNOWLEDGMENTS:
  73.  
  74.   The Kermit file transfer protocol was developed at the Columbia University
  75.   Center for Computing Activities (CUCCA).  It is named after Kermit the Frog,
  76.   star of the television series THE MUPPET SHOW; the name is used by permission
  77.   of Henson Associates, Inc.
  78.  
  79.   Thanks to at least the following people for their contributions to this
  80.   program over the years, and apologies to anybody I missed:
  81.  
  82.    Chris Adie, Edinburgh U, Scotland (OS/2 support)
  83.    Robert Adsett, University of Waterloo, Canada
  84.    Larry Afrin, Clemson U
  85.    Greg Andrews, Telebit Corp
  86.    Barry Archer, U of Missouri
  87.    Robert Andersson, International Systems A/S, Oslo, Norway
  88.    Chris Armstrong, Brookhaven National Lab (OS/2)
  89.    William Bader, Software Consulting Services, Nazareth, PA
  90.    Fuat Baran, CUCCA
  91.    Stan Barber, Rice U
  92.    Jim Barbour, U of Colorado
  93.    Donn Baumgartner, Dell
  94.    Nelson Beebe, U of Utah
  95.    Karl Berry, UMB
  96.    Dean W Bettinger, SUNY
  97.    Gary Bilkus
  98.    Marc Boucher, U of Montreal
  99.    Charles Brooks, EDN
  100.    Bob Brown
  101.    Mike Brown, Purdue U
  102.    Jack Bryans, California State U at Long Beach
  103.    Mark Buda, DEC (VAX/VMS)
  104.    Fernando Cabral, Padrao IX, Brasilia, Brazil
  105.    Bjorn Carlsson, Stockholm University Computer Centre QZ, Sweden
  106.    Bill Catchings, formerly of CUCCA
  107.    Bob Cattani, Columbia U CS Dept
  108.    Davide Cervone, Rochester University
  109.    Seth Chaiklin, Denmark
  110.    John Chandler, Harvard U / Smithsonian Astronomical Observatory
  111.    John L Chmielewski, AT&T, Lisle, IL
  112.    Howard Chu, U of Michigan
  113.    Bill Coalson, McDonnell Douglas
  114.    Bertie Coopersmith, London, UK
  115.    Chet Creider, University of Western Ontario, Canada
  116.    Alan Crosswell, CUCCA
  117.    Jeff Damens, formerly of CUCCA
  118.    Mark Davies, Bath U, UK
  119.    S. Dezawa, Fujifilm, Japan
  120.    Joe R. Doupnik, Utah State U
  121.    Frank Dreano (Honeywell)
  122.    John Dunlap, University of Washington
  123.    David Dyck, John Fluke Mfg Co.
  124.    Stefaan A. Eeckels, Eurokom, Luxembourg
  125.    Paul Eggert, Twin Sun, Inc., El Segundo, CA
  126.    Bernie Eiben, DEC
  127.    Kristoffer Eriksson, Peridot Konsult AB, Oerebro, Sweden
  128.    John R. Evans, IRS, Kansas City
  129.    Glenn Everhart, RCA Labs
  130.    Charlie Finan, Cray Research
  131.    Herm Fischer, Encino, CA (extensive contributions to version 4.0)
  132.    Carl Fongheiser, CWRU
  133.    Marcello Frutig, Catholic University, Sao Paulo, Brazil (X.25 support)
  134.    Hirofumi Fujii, Japan Nat'l Lab for High Energy Physics, Tokyo (Kanji)
  135.    Chuck Fuller, Westinghouse Corporate Computer Services
  136.    Andy Fyfe, Caltech
  137.    Christine M. Gianone, CUCCA
  138.    John Gilmore, UC Berkeley
  139.    German Goldszmidt, IBM
  140.    Alistair Gorman, New Zealand
  141.    Richard Gration, ADFA, Australia
  142.    Chris Green, Essex U, UK
  143.    Alan Grieg, Dundee Tech, Scotland, UK
  144.    Yekta Gursel, MIT
  145.    Jim Guyton, Rand Corp
  146.    Michael Haertel
  147.    Bob Hain, UMN
  148.    Marion Hakanson, ORST
  149.    John Hamilston, Iowa State U
  150.    Simon Hania, Netherlands
  151.    Stan Hanks, Rice U.
  152.    Ken Harrenstein, SRI
  153.    Eugenia Harris, Data General (AOS/VS)
  154.    David Harrison, Kingston Warren Corp
  155.    James Harvey, Indiana/Purdue U (VMS)
  156.    Rob Healey
  157.    Chuck Hedrick, Rutgers U
  158.    Ron Heiby, Technical Systems Division, Motorola Computer Group
  159.    Steve Hemminger, Tektronix
  160.    Christian Hemsing, RWTH Aachen, Germany (OS-9)
  161.    Andrew Herbert, Monash Univ, Australia
  162.    Mike Hickey, ITI
  163.    R E Hill
  164.    Bill Homer, Cray Research
  165.    Ray Hunter, The Wollongong Group
  166.    Randy Huntziger, National Library of Medicine
  167.    Larry Jacobs, Transarc
  168.    Steve Jenkins, Lancaster University, UK
  169.    Dave Johnson, Gradient Technologies
  170.    Mark B Johnson, Apple Computer
  171.    Eric F Jones, AT&T
  172.    Luke Jones, AT&T
  173.    Peter Jones, U of Quebec Montreal
  174.    Phil Julian, SAS Institute
  175.    Peter Kabal, U of Quebec
  176.    Mic Kaczmarczik, U of Texas at Austin
  177.    Sergey Kartashoff, Inst. of Precise Mechanics & Computer Equipment, Moscow
  178.    Howie Kaye, CUCCA
  179.    Rob Kedoin, Linotype Co, Hauppauge, NY (OS/2)
  180.    Mark Kennedy, IBM
  181.    Terry Kennedy, St Peter's College, Jersey City, NJ (VAX/VMS, 2.11 BSD)
  182.    Douglas Kingston, morgan.com
  183.    Tom Kloos, Sequent Computer Systems
  184.    Jim Knutson, U of Texas at Austin
  185.    Scott Kramer, SRI International, Menlo Park, CA
  186.    David Kricker, Encore Computer
  187.    Thomas Krueger, UWM
  188.    Bo Kullmar, Central Bank of Sweden, Kista
  189.    R. Brad Kummer, AT&T Bell Labs, Atlanta, GA
  190.    John Kunze, UC Berkeley
  191.    Bob Larson, USC (OS-9)
  192.    Bert Laverman, Groningen U, Netherlands
  193.    Steve Layton
  194.    David Lawyer, UC Irvine
  195.    David LeVine, National Semiconductor Corporation
  196.    S.O. Lidie, Lehigh U
  197.    Tor Lillqvist, Helsinki University, Finland
  198.    Dean Long
  199.    Kevin Lowey, U of Saskatchewan (OS/2)
  200.    Andy Lowry, Columbia University
  201.    David MacKenzie, Environmental Defense Fund, University of Maryland
  202.    John Mackin, University of Sidney, Australia
  203.    Martin Maclaren, Bath U, UK
  204.    Chris Maio, Columbia U CS Dept
  205.    Fulvio Marino, Olivetti, Ivrea, Italy
  206.    Peter Mauzey, AT&T
  207.    Tye McQueen, Utah State U
  208.    Ted Medin
  209.    Hellmuth Michaelis, Hanseatischer Computerservice GmbH, Hamburg, Germany
  210.    Leslie Mikesell, American Farm Bureau
  211.    Martin Minow, DEC (VAX/VMS)
  212.    Pawan Mistra, Bellcore
  213.    Ken Mizialko, IBM, Manassas, VA
  214.    Ray Moody, Purdue U
  215.    Bruce J Moore, Allen-Bradley Co, Highland Heights, OH (Atari ST)
  216.    Steve Morley, Convex
  217.    Peter Mossel, Columbia University
  218.    Tony Movshon, NYU
  219.    Lou Muccioli, Swanson Analysis Systems
  220.    Dan Murphy
  221.    Gary Mussar
  222.    John Nall, FSU
  223.    Jack Nelson, University of Pittsburgh
  224.    Jim Noble, Planning Research Corporation (Macintosh)
  225.    Ian O'Brien, Bath U, UK
  226.    John Owens
  227.    Michael Pins, Iowa Computer Aided Engineering Network
  228.    Andre' Pirard, University of Liege, Belgium
  229.    Paul Placeway, Ohio State U (Macintosh & more)
  230.    Piet W. Plomp, ICCE, Groningen University, Netherlands
  231.    Ken Poulton, HP Labs
  232.    Manfred Prange, Oakland U
  233.    Christopher Pratt, APV Baker, UK
  234.    Frank Prindle, NADC
  235.    Tony Querubin, U of Hawaii
  236.    Anton Rang
  237.    Scott Ribe
  238.    Alan Robiette, Oxford University, UK
  239.    Michel Robitaille, U of Montreal (Mac)
  240.    Kai Uwe Rommel, Technische Universitaet Muenchen (OS/2)
  241.    Larry Rosenman (Amiga)
  242.    Jay Rouman, U of Michigan
  243.    Jack Rouse, SAS Institute (Data General and/or Apollo)
  244.    Stew Rubenstein, Harvard U (VAX/VMS)
  245.    Bill Schilit, Columbia University
  246.    Michael Schmidt, U of Paderborn, Germany
  247.    Eric Schnoebelen, Convex
  248.    Benn Schreiber, DEC
  249.    Dan Schullman, DEC (modems, DIAL command, etc)
  250.    John Schultz, 3M
  251.    Steven Schultz, Contel (PDP-11)
  252.    APPP Scorer, Leeds Polytechnic, UK
  253.    Gordon Scott, Micro Focus, Newbury UK
  254.    Gisbert W. Selke, WIdO, Bonn, Germany
  255.    David Sizeland, U of London Medical School
  256.    Fridrik Skulason, Iceland
  257.    Dave Slate
  258.    Bradley Smith, UCLA
  259.    Richard S Smith, Cal State
  260.    Ryan Stanisfer, UNT
  261.    Bertil Stenstroem, Stockholm University Computer Centre (QZ), Sweden
  262.    James Sturdevant, CAP GEMENI AMERICA, Minneapolis
  263.    Peter Svanberg, Royal Techn. HS, Sweden
  264.    James R. Swenson, Accu-Weather, Inc.
  265.    Andy Tanenbaum, Vrije U, Amsterdam, Netherlands
  266.    Markku Toijala, Helsinki U of Technology
  267.    Rick Troxel, NIH
  268.    Warren Tucker, Tridom Corp, Mountain Park, GA
  269.    Dave Tweten, AMES-NAS
  270.    G Uddeborg, Sweden
  271.    Walter Underwood, Ford Aerospace
  272.    Pieter Van Der Linden, Centre Mondial, Paris
  273.    Ge van Geldorp, Netherlands
  274.    Fred van Kempen, MINIX User Group, Voorhout, Netherlands
  275.    Wayne Van Pelt, GE/CRD
  276.    Mark Vasoll, Oklahoma State U (V7 UNIX)
  277.    Konstantin Vinogradov, ICSTI, Moscow
  278.    Paul Vixie, DEC
  279.    Dimitri Vulis, CUNY
  280.    Roger Wallace, Raytheon
  281.    Stephen Walton, Calif State U, Northridge (Amiga)
  282.    Jamie Watson, Adasoft, Switzerland (RS/6000)
  283.    Rick Watson, U of Texas (Macintosh)
  284.    Robert Weiner, Programming Plus, New York City
  285.    Lauren Weinstein, Vortex Technlogy
  286.    David Wexelblat, AT&T
  287.    Joachim Wiesel, U of Karlsruhe
  288.    Lon Willett, U of Utah
  289.    Michael Williams, UCLA
  290.    Nate Williams, U of Montana
  291.    David Wilson
  292.    Patrick Wolfe, Kuck & Associates, Inc.
  293.    Gregg Wonderly, Oklahoma State U (V7 UNIX)
  294.    Farrell Woods, Concurrent (formerly Masscomp)
  295.    Dave Woolley, CAP Communication Systems, London
  296.    Jack Woolley, SCT Corp
  297.    Frank Wortner
  298.    Ken Yap, U of Rochester
  299.    John Zeeff, Ann Arbor, MI
  300. */
  301. /*
  302.   ckcsym.h is used for for defining symbols that normally would be defined
  303.   using -D or -d on the cc command line, for use with compilers that don't
  304.   support this feature.
  305. */
  306. #include "ckcsym.h"
  307. #include "ckcasc.h"            /* ASCII character symbols */
  308. #include "ckcdeb.h"            /* Debug & other symbols */
  309. #include "ckcker.h"            /* Kermit symbols */
  310. #include "ckcnet.h"            /* Network symbols */
  311. #ifndef NOSPL
  312. #include "ckuusr.h"
  313. #endif /* NOSPL */
  314.  
  315. #ifndef NOSERVER
  316. /* Text message definitions.. each should be 256 chars long, or less. */
  317. #ifdef MAC
  318. char *hlptxt = "\r\
  319. Mac Kermit Server Commands:\r\
  320. \r\
  321.     BYE\r\
  322.     FINISH\r\
  323.     GET filespec\r\
  324.     REMOTE CD directory\r\
  325.     REMOTE HELP\r\
  326.     SEND filespec\r\
  327. \r\0";
  328. #else
  329. #ifdef AMIGA
  330. char *hlptxt = "C-Kermit Server Commands:\n\
  331. \n\
  332. GET filespec, SEND filespec, FINISH, BYE, REMOTE HELP\n\
  333. \n\0";
  334. #else
  335. #ifdef OS2
  336. char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
  337. \n\
  338. GET files  REMOTE CD [dir]     REMOTE DIRECTORY [files]\n\
  339. SEND files REMOTE SPACE [dir]  REMOTE HOST command\n\
  340. FINISH     REMOTE DELETE files REMOTE TYPE files\n\
  341. BYE        REMOTE HELP         REMOTE SET parameter value\n\
  342. \n\0";
  343. #else
  344. #ifdef MINIX
  345. char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
  346. GET SEND BYE FINISH REMOTE: CD DEL DIR HELP HOST SET SPACE TYPE WHO\n\0";
  347. #else
  348. #ifdef VMS
  349. char *hlptxt = "C-Kermit Server REMOTE Commands:\r\n\
  350. \r\n\
  351. GET files  REMOTE CD [dir]     REMOTE DIRECTORY [files]\r\n\
  352. SEND files REMOTE SPACE [dir]  REMOTE HOST command\r\n\
  353. MAIL files REMOTE DELETE files REMOTE WHO [user]\r\n\
  354. BYE        REMOTE PRINT files  REMOTE TYPE files\r\n\
  355. FINISH     REMOTE HELP         REMOTE SET parameter value\r\n\
  356. \0";
  357. #else
  358. #ifdef datageneral
  359. char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
  360. \n\
  361. GET files  REMOTE CD [dir]     REMOTE DIRECTORY [filespec]\n\
  362. SEND files REMOTE SPACE [dir]  REMOTE HOST command\n\
  363. BYE        REMOTE TYPE file    REMOTE DELETE files\n\
  364. FINISH     REMOTE WHO          REMOTE SET\n\
  365. \0";
  366. #else
  367. char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
  368. \n\
  369. GET files  REMOTE CD [dir]     REMOTE DIRECTORY [files]\n\
  370. SEND files REMOTE SPACE [dir]  REMOTE HOST command\n\
  371. MAIL files REMOTE DELETE files REMOTE WHO [user]\n\
  372. BYE        REMOTE PRINT files  REMOTE TYPE files\n\
  373. FINISH     REMOTE HELP         REMOTE SET parameter value\n\
  374. \n\0";
  375. #endif
  376. #endif
  377. #endif
  378. #endif
  379. #endif
  380. #endif
  381.  
  382. #ifdef MINIX
  383. char *srvtxt = "\r\n\
  384. Entering server mode.\r\n\0";
  385. #else
  386. #ifdef OSK
  387. char *srvtxt = "\r\l\
  388. Entering server mode.  If your local Kermit software is menu driven, use\r\l\
  389. the menus to send commands to the server.  Otherwise, enter the escape\r\l\
  390. sequence to return to your local Kermit prompt and issue commands from\r\l\
  391. there.  Use SEND and GET for file transfer.  Use REMOTE HELP for a list of\r\l\
  392. other available services.  Use BYE or FINISH to end server mode.\r\l\0";
  393. #else /* UNIX, VMS, AOS/VS, and all others */
  394. char *srvtxt = "\r\n\
  395. Entering server mode.  If your local Kermit software is menu driven, use\r\n\
  396. the menus to send commands to the server.  Otherwise, enter the escape\r\n\
  397. sequence to return to your local Kermit prompt and issue commands from\r\n\
  398. there.  Use SEND and GET for file transfer.  Use REMOTE HELP for a list of\r\n\
  399. other available services.  Use BYE or FINISH to end server mode.\r\n\0";
  400. #endif /* OSK */
  401. #endif /* MINIX */
  402. #else  /* server mode disabled */
  403. char *srvtxt = "";
  404. #endif /* NOSERVER */
  405.  
  406. /* Declarations for Send-Init Parameters */
  407.  
  408. int spsiz = DSPSIZ,                     /* Current packet size to send */
  409.     spmax = DSPSIZ,            /* Biggest packet size we can send */
  410.     spsizr = DSPSIZ,            /* Send-packet size requested */
  411.     spsizf = 0,                         /* Flag to override size negotiation */
  412.     rpsiz = DRPSIZ,                     /* Biggest we want to receive */
  413.     urpsiz = DRPSIZ,            /* User-requested receive pkt size */
  414.     maxrps = MAXRP,            /* Maximum incoming long packet size */
  415.     maxsps = MAXSP,            /* Maximum outbound l.p. size */
  416.     maxtry = MAXTRY,            /* Maximum retries per packet */
  417.     wslots = 1,                /* Window size currently in use */
  418.     wslotr = 1,                /* Window size from SET WINDOW */
  419.     wslotn = 1,                /* Window size negotiated in S-pkt */
  420.     timeouts = 0,            /* For statistics reporting */
  421.     spackets = 0,            /*  ... */
  422.     rpackets = 0,            /*  ... */
  423.     retrans = 0,            /*  ... */
  424.     crunched = 0,            /*  ... */
  425.     wmax = 0,                /*  ... */
  426.     wcur = 0,                /*  ... */
  427.     srvdis = 0,                /* Server file xfer display */
  428.     srvtim = DSRVTIM,            /* Server command wait timeout */
  429. /*
  430.   timint is the timeout interval I use when waiting for a packet.
  431.   pkttim is the SET RECEIVE TIMEOUT value, sent to the other Kermit.
  432.   rtimo is the SET SEND TIMEOUT value.  rtimo is the initial value of
  433.   timint.  timint is changed by the value in the incoming negotiation
  434.   packet unless a SET SEND TIMEOUT command was given.
  435. */
  436.     timint = DMYTIM,                    /* Timeout interval I use */
  437.     pkttim = URTIME,            /* Timeout I want you to use */
  438.     rtimo = DMYTIM,            /* Normal packet wait timeout */
  439.     timef = 0,                          /* Flag to override what you ask */
  440.     npad = MYPADN,                      /* How much padding to send */
  441.     mypadn = MYPADN,                    /* How much padding to ask for */
  442.     bctr = 1,                           /* Block check type requested */
  443.     bctu = 1,                           /* Block check type used */
  444.     bctl = 1,                /* Block check length */
  445.     ebq =  MYEBQ,                       /* 8th bit prefix */
  446.     ebqflg = 0,                         /* 8th-bit quoting flag */
  447.     rqf = -1,                /* Flag used in 8bq negotiation */
  448.     rq = 0,                /* Received 8bq bid */
  449.     sq = 'Y',                /* Sent 8bq bid */
  450.     rpt = 0,                            /* Repeat count */
  451.     rptq = MYRPTQ,                      /* Repeat prefix */
  452.     rptflg = 0;                         /* Repeat processing flag */
  453.  
  454. int capas = 9,                /* Position of Capabilities */
  455.     atcapb = 8,                /* Attribute capability */
  456.     atcapr = 1,                /*  requested */
  457.     atcapu = 0,                /*  used */
  458.     swcapb = 4,                /* Sliding Window capability */
  459.     swcapr = 1,                /*  requested (allowed) */
  460.     swcapu = 0,                /*  used */
  461.     lpcapb = 2,                /* Long Packet capability */
  462.     lpcapr = 1,                /*  requested */
  463.     lpcapu = 0,                /*  used */
  464.     lscapb = 32,            /* Locking Shift capability */
  465.     lscapr = 1,                /*  requested by default */
  466.     lscapu = 0;                /*  used */
  467.  
  468. /* Flags for whether to use particular attributes */
  469.  
  470. int atenci = 1,                /* Encoding in */
  471.     atenco = 1,                /* Encoding out */
  472.     atdati = 1,                /* Date in */
  473.     atdato = 1,                /* Date out */
  474.     atdisi = 1,                /* Disposition in/out */
  475.     atdiso = 1,
  476.     atleni = 1,                /* Length in/out (both kinds) */
  477.     atleno = 1,
  478.     atblki = 1,                /* Blocksize in/out */
  479.     atblko = 1,
  480.     attypi = 1,                /* File type in/out */
  481.     attypo = 1,
  482.     atsidi = 1,                /* System ID in/out */
  483.     atsido = 1,
  484.     atsysi = 1,                   /* System-dependent parameters in/out */
  485.     atsyso = 1;
  486.  
  487. CHAR padch = MYPADC,                    /* Padding character to send */
  488.     mypadc = MYPADC,                    /* Padding character to ask for */
  489.     seol = MYEOL,                       /* End-Of-Line character to send */
  490.     eol = MYEOL,                        /* End-Of-Line character to look for */
  491.     ctlq = CTLQ,                        /* Control prefix in incoming data */
  492.     myctlq = CTLQ;                      /* Outbound control character prefix */
  493.  
  494. struct zattr iattr;            /* Incoming file attributes */
  495.  
  496. /* File related variables, mainly for the benefit of VAX/VMS */
  497.  
  498. int fblksiz = DBLKSIZ;        /* File blocksize */
  499. int frecl = DLRECL;        /* File record length */
  500. int frecfm = XYFF_S;        /* File record format (default = stream) */
  501. int forg = XYFO_S;        /* File organization (sequential) */
  502. int fcctrl = XYFP_N;        /* File carriage control (ctrl chars) */
  503.  
  504. #ifdef VMS
  505. /* VMS labeled file options */
  506. int lf_opts = LBL_NAM;
  507. #else
  508. int lf_opts = 0;
  509. #endif /* VMS */
  510.  
  511. /* Packet-related variables */
  512.  
  513. int pktnum = 0,                         /* Current packet number */
  514.     sndtyp = 0,                /* Type of packet just sent */
  515.     rsn,                /* Received packet sequence number */
  516.     rln,                /* Received packet length */
  517.     size,                               /* Current size of output pkt data */
  518.     osize,                              /* Previous output packet data size */
  519.     maxsize,                            /* Max size for building data field */
  520.     spktl = 0,                /* Length packet being sent */
  521.     rpktl = 0,                /* Length of packet just received */
  522.     rprintf,                /* REMOTE PRINT flag */
  523.     rmailf;                /* MAIL flag */
  524.  
  525. CHAR
  526. #ifdef NO_MORE  /* Buffers used before sliding windows... */
  527.     sndpkt[MAXSP+100],            /* Entire packet being sent */
  528.     recpkt[MAXRP+200],            /* Packet most recently received */
  529.     data[MAXSP+4],            /* Packet data buffer */
  530. #endif
  531. #ifdef DYNAMIC
  532.     *srvcmd = (CHAR *)0,        /* Where to decode server command */
  533. #else
  534.     srvcmd[MAXRP+4],                    /* Where to decode server command */
  535. #endif
  536.     padbuf[95],                /* Buffer for send-padding */
  537.     *recpkt,
  538.     *rdatap,                /* Pointer to received packet data */
  539.     *data = (CHAR *)0,            /* Pointer to send-packet data */
  540.     *srvptr,                            /* Pointer to srvcmd */
  541.     mystch = SOH,                       /* Outbound packet-start character */
  542.     stchr = SOH;                        /* Incoming packet-start character */
  543.  
  544. /* File-related variables */
  545.  
  546. char filnam[257];                       /* Name of current file. */
  547. char cmdfil[80];            /* Application file name. */
  548.  
  549. int nfils = 0;                /* Number of files in file group */
  550. long fsize;                             /* Size of current file */
  551. int wildxpand = 0;            /* Who expands wildcards */
  552. int clfils = 0;                /* Flag for command-line files */
  553. int stayflg = 0;            /* Flag for "stay", i.e. "-S" */
  554.  
  555. /* Communication line variables */
  556.  
  557. char ttname[80];                        /* Name of communication line. */
  558.  
  559. #ifdef MAC
  560. int connected = 0;            /* true if connected */
  561. int startconnected;            /* initial state of connected */
  562. #endif /* MAC */
  563.  
  564. long speed = -1L;            /* Line speed */
  565.  
  566. int parity,                             /* Parity specified, 0,'e','o',etc */
  567.     autopar = 0,            /* Automatic parity change flag */
  568.     sosi = 0,                /* Shift-In/Out flag */
  569.     flow,                               /* Flow control */
  570.     turn = 0,                           /* Line turnaround handshake flag */
  571.     turnch = XON,                       /* Line turnaround character */
  572.     duplex = 0,                         /* Duplex, full by default */
  573.     escape = DFESC,            /* Escape character for connect */
  574.     delay = DDELAY,                     /* Initial delay before sending */
  575.     tnlm = 0,                /* Terminal newline mode */
  576.     mdmtyp = 0;                         /* Modem type (initially none)  */
  577.  
  578. /* Networks for SET HOST */
  579.  
  580. #define MYHOSTL 100
  581.     char myhost[MYHOSTL];        /* Local host name */
  582.     int network = 0;            /* Network vs tty connection */
  583. #ifdef OS2
  584. /* For now, DECnet is the only type supported by OS/2 */
  585.     int nettype = NET_DEC;
  586. #else
  587.     int nettype = NET_TCPB;        /* Assume TCP/IP (BSD sockets) */
  588. #endif /* OS2 */
  589.  
  590. #ifdef SUNX25
  591.     extern initpad();
  592.     int revcall = 0;            /* X.25 reverse call not selected */
  593.     int closgr  = -1;        /* X.25 closed user group not selected */
  594.     int cudata = 0;        /* X.25 call user data not specified */
  595.     char udata[MAXCUDATA];    /* X.25 call user data */
  596. #endif /* SUNX25 */
  597.  
  598. /* Other recent additions */
  599.  
  600.     int tlevel = -1;            /* Take-file command level */
  601. #ifndef NOSPL
  602.     extern int cmdlvl;            /* Command level */
  603.     extern int maclvl;            /* Macro invocation level */
  604. #endif /* NOSPL */
  605.     int carrier = CAR_AUT;        /* Pay attention to carrier signal */
  606.     int cdtimo = 0;            /* Carrier wait timeout */
  607.     int xitsta = GOOD_EXIT;        /* Program exit status */
  608. #ifdef VMS                /* Default filename collision action */
  609.     int fncact = XYFX_X;        /* REPLACE for VAX/VMS */
  610. #else
  611.     int fncact = XYFX_B;        /* BACKUP for everybody else */
  612. #endif /* VMS */
  613.     int bgset = -1;            /* BACKGROUND mode set explicitly */
  614. #ifdef UNIX
  615.     int suspend = DFSUSP;        /* Whether SUSPEND command, etc, */
  616. #else                    /* is to be allowed. */
  617.     int suspend = 0;
  618. #endif /* UNIX */
  619.  
  620. /* Statistics variables */
  621.  
  622. long filcnt,                    /* Number of files in transaction */
  623.     flci,                       /* Characters from line, current file */
  624.     flco,                       /* Chars to line, current file  */
  625.     tlci,                       /* Chars from line in transaction */
  626.     tlco,                       /* Chars to line in transaction */
  627.     ffc,                        /* Chars to/from current file */
  628.     tfc,                        /* Chars to/from files in transaction */
  629.     rptn;            /* Repeated characters compressed */
  630.  
  631. int tsecs = 0;                  /* Seconds for transaction */
  632. int fsecs = 0;            /* Per-file timer */
  633.  
  634. /* Flags */
  635.  
  636. int deblog = 0,                         /* Flag for debug logging */
  637.     debses = 0,                /* Flag for DEBUG SESSION */
  638.     pktlog = 0,                         /* Flag for packet logging */
  639.     seslog = 0,                         /* Session logging */
  640.     tralog = 0,                         /* Transaction logging */
  641.     displa = 0,                         /* File transfer display on/off */
  642.     stdouf = 0,                         /* Flag for output to stdout */
  643.     stdinf = 0,                /* Flag for input from stdin */
  644.     xflg   = 0,                         /* Flag for X instead of F packet */
  645.     hcflg  = 0,                         /* Doing Host command */
  646.     fncnv  = 1,                         /* Flag for file name conversion */
  647.     binary = 0,                         /* Flag for binary file */
  648.     savmod = 0,                         /* Saved file mode (whole session) */
  649.     bsave  = 0,                /* Saved file mode (per file) */
  650.     bsavef = 0,                /* Flag if bsave was used. */
  651.     cmask  = 0177,            /* Connect byte mask */
  652.     fmask  = 0377,            /* File byte mask */
  653.     warn   = 0,                         /* Flag for file warning */
  654.     quiet  = 0,                         /* Be quiet during file transfer */
  655.     local  = 0,                         /* Flag for external tty vs stdout */
  656.     server = 0,                         /* Flag for being a server */
  657.     cflg   = 0,                /* Connect before transaction */
  658.     cnflg  = 0,                         /* Connect after transaction */
  659.     cxseen = 0,                         /* Flag for cancelling a file */
  660.     czseen = 0,                         /* Flag for cancelling file group */
  661.     discard = 0,            /* Flag for file to be discarded */
  662.     keep = 0,                           /* Keep incomplete files */
  663.     unkcs = 1,                /* Keep file w/unknown character set */
  664.     nakstate = 0,            /* In a state where we can send NAKs */
  665.     dblchar = -1;            /* Character to double when sending */
  666.  
  667. /* Variables passed from command parser to protocol module */
  668.  
  669. #ifndef NOSPL
  670. _PROTOTYP( int parser, (int) );         /* The parser itself */
  671. char *clcmds = NULL;            /* Pointer to command-line commands */
  672. #endif /* NOSPL */
  673.  
  674. CHAR sstate  = (CHAR) 0;                /* Starting state for automaton */
  675. CHAR zstate  = (CHAR) 0;        /* For remembering sstate */
  676. char *cmarg  = "";                      /* Pointer to command data */
  677. char *cmarg2 = "";                      /* Pointer to 2nd command data */
  678. char **cmlist;                          /* Pointer to file list in argv */
  679.  
  680. /* Flags for the ENABLE and DISABLE commands */
  681.  
  682. int en_cwd = 1;                /* CD/CWD */
  683. int en_del = 1;                /* DELETE */
  684. int en_dir = 1;                /* DIRECTORY */
  685. int en_fin = 1;                /* FINISH/BYE */
  686. int en_get = 1;                /* GET */
  687. #ifndef NOPUSH
  688. int en_hos = 1;                /* HOST enabled */
  689. #else
  690. int en_hos = 0;                /* HOST disabled */
  691. #endif /* NOPUSH */
  692. int en_sen = 1;                /* SEND */
  693. int en_set = 1;                /* SET */
  694. int en_spa = 1;                /* SPACE */
  695. int en_typ = 1;                /* TYPE */
  696. int en_who = 1;                /* WHO */
  697. #ifdef datageneral
  698. /* Data General AOS/VS can't do this */
  699. int en_bye = 0;                /* BYE */
  700. #else
  701. int en_bye = 1;                /* BYE */
  702. #endif /* datageneral */
  703.  
  704. /* Miscellaneous */
  705.  
  706. char **xargv;                           /* Global copies of argv */
  707. int  xargc;                             /* and argc  */
  708. int xargs;                /* an immutable copy of argc */
  709. char *xarg0;                /* and of argv[0] */
  710.  
  711. extern char *dftty;                     /* Default tty name from ck?tio.c */
  712. extern int dfloc;                       /* Default location: remote/local */
  713. extern int dfprty;                      /* Default parity */
  714. extern int dfflow;                      /* Default flow control */
  715.  
  716. /*
  717.   Buffered file input and output buffers.  See getpkt() in ckcfns.c
  718.   and zoutdump() in the system-dependent file i/o module (usually ck?fio.c).
  719. */
  720. #ifndef DYNAMIC
  721. /* Now we allocate them dynamically, see getiobs() below. */
  722. char zinbuffer[INBUFSIZE], zoutbuffer[OBUFSIZE];
  723. #endif
  724. char *zinptr, *zoutptr;
  725. int zincnt, zoutcnt;
  726.  
  727. _PROTOTYP( int getiobs, (void) );
  728.  
  729. /*  M A I N  --  C-Kermit main program  */
  730.  
  731. #ifndef NOCCTRAP
  732. #include <setjmp.h>
  733. extern jmp_buf cmjbuf;
  734. #ifdef GEMDOS                /* Special for Atari ST */
  735.     cc_clean();
  736. #endif /* GEMDOS */
  737. #endif /* NOCCTRAP */
  738.  
  739. #ifdef aegis
  740. /* On the Apollo, intercept main to insert a cleanup handler */
  741. int
  742. ckcmai(argc,argv) int argc; char **argv;
  743. #else
  744. #ifdef MAC
  745. int
  746. main (void)
  747. #else
  748. VOID
  749. main(argc,argv) int argc; char **argv;
  750. #endif /* MAC */
  751. #endif /* aegis */
  752. {
  753. #ifdef datageneral
  754. short *pfha = 016000000036;             /* Get around LANG_RT problem -- */
  755. *pfha = (short) 0;                      /* No user protection fault handler */
  756. #endif /* datageneral */
  757.   
  758. /* Do some initialization */
  759.  
  760.     if (sysinit() < 0)            /* System-dependent initialization. */
  761.       fatal("Can't initialize!");
  762.     connoi();                /* Console interrupts off */
  763. #ifndef MAC
  764.     xargc = xargs = argc;        /* Make global copies of argc */
  765.     xargv = argv;                       /* ...and argv. */
  766.     xarg0 = argv[0];
  767. #endif /* MAC */
  768.     sstate = 0;                         /* No default start state. */
  769. #ifdef DYNAMIC
  770.     if (getiobs() < 0) 
  771.       fatal("Can't allocate i/o buffers!");
  772. #endif /* DYNAMIC */
  773.     ckhost(myhost,MYHOSTL);        /* Name of local host */
  774.     strcpy(ttname,dftty);               /* Set up default tty name. */
  775.     local = dfloc;                      /* And whether it's local or remote. */
  776.     parity = dfprty;                    /* Set initial parity, */
  777.     flow = dfflow;                      /* and flow control. */
  778.     if (local) if (ttopen(ttname,&local,0,0) < 0) { /* If default tty line */
  779. #ifndef OS2
  780.     printf("%s: Can't open device\n",ttname);   /* is external, open it */
  781. #endif /* OS2 */
  782.     local = 0;                        /* now... */
  783.     strcpy(ttname,CTTNAM);
  784.     }
  785.     speed = ttgspd();            /* Get transmission speed. */
  786.  
  787. #ifdef SUNX25
  788.     initpad();                          /* Initialize X.25 PAD */
  789. #endif /* SUNX25 */
  790.  
  791.     if (inibufs(SBSIZ,RBSIZ) < 0)    /* Allocate packet buffers */
  792.       fatal("Can't allocate packet buffers!");
  793.  
  794. #ifndef NOICP
  795. #ifdef MAC
  796.     cmdini();
  797. #else /* Not MAC */
  798. /* Attempt to take ini file before doing command line */
  799.  
  800.     *cmdfil = '\0';            /* Assume no command file. */
  801.     prescan();                /* But first check for -y option */
  802.  
  803. #ifndef NOCCTRAP
  804.     setint();                /* Set up interrupts */
  805.     if (setjmp(cmjbuf)) {        /* Control-C trap returns to here. */
  806. #ifdef GEMDOS
  807.     cc_clean();            /* Atari: Clean up after ^C-trap. */
  808. #endif /* GEMDOS */
  809.     doexit(GOOD_EXIT,-1);        /* Exit with good status. */
  810.     } else {
  811. #endif /* NOCCTRAP */
  812.     cmdini();            /* Sets tlevel */
  813.     while (tlevel > -1) {        /* Execute init file. */
  814.         sstate = parser(0);        /* Loop getting commands. */
  815.         if (sstate) proto();    /* Enter protocol if requested. */
  816.     }
  817. #ifndef NOCCTRAP
  818.     }
  819. #endif /* NOCCTRAP */
  820.  
  821. /*
  822.   In UNIX there are two ways to invoke Kermit with a cmdfile:
  823.   (1) From the kermit command line, e.g. "kermit cmdfile [ options... ]"
  824.       argv[0] = "kermit"
  825.       argv[1] = "cmdfile"
  826.   (2) By executing a cmdfile whose first line is like "#!/path/kermit"
  827.       argv[0] = "/path/kermit" (sometimes just "kermit")
  828.       argv[1] = "/path/cmdfile"
  829. */
  830.     if (argc > 1) {
  831.     if (*argv[1] != '-') {
  832.         if (zchki(argv[1]) > 0) {
  833.         strcpy(cmdfil,argv[1]);
  834.         }
  835.     }
  836.     }
  837.     if (*cmdfil) {            /* If we got one, */
  838.     dotake(cmdfil);            /* execute it */
  839.     while (tlevel > -1) {        /* until it runs out. */
  840.         sstate = parser(1);        /* Loop getting commands. */
  841.         if (sstate) proto();    /* Enter protocol if requested. */
  842.     }
  843.     }
  844.     *cmdfil = '\0';            /* Done, nullify the file name */
  845. #endif /* MAC */
  846. #endif /* NOICP */
  847.  
  848. #ifndef NOCMDL
  849. /* Look for a UNIX-style command line... */
  850.  
  851.     if (argc > 1) {                     /* Command line arguments? */
  852.         sstate = cmdlin();              /* Yes, parse. */
  853.     zstate = sstate;        /* Remember sstate around protocol */
  854.     if (cflg) conect();        /* Connect first if requested */
  855.         if (sstate) {
  856.         if (displa) concb((char)escape); /* (for console "interrupts") */
  857. #ifndef NOCCTRAP
  858.         setint();            /* Set up interrupts */
  859.         if (setjmp(cmjbuf)) {    /* Control-C trap returns to here. */
  860. #ifdef GEMDOS
  861.         cc_clean();
  862. #endif /* GEMDOS */
  863.         if (cnflg) conect();    /* connect again if requested, */
  864.         } else {
  865. #endif /* NOCCTRAP */
  866.         proto();        /* Take any requested action, then */
  867.         if (!quiet)        /* put cursor back at left margin, */
  868.           conoll("");
  869.         if (cnflg) conect();    /* connect if requested, */
  870. #ifndef NOCCTRAP
  871.         }
  872. #endif /* NOCCTRAP */
  873.     }
  874. /*
  875.   If interactive commands were given on the command line (using the
  876.   -C "command, command, ..." option), assign them to a macro called
  877.   "cl_commands", then execute the macro and leave it defined for
  878.   subsequent re-execution if desired.
  879. */
  880. #ifndef NOSPL
  881.     if (clcmds) {            /* Check for -C commands */
  882.         int x;
  883.         x = addmac("cl_commands",clcmds); /* Put macro in table */
  884.         if (x > -1) {        /* If successful, */
  885.         dodo(x,NULL);        /* set up for macro execution */
  886.         while (maclvl > -1) {    /* Loop getting macro commands. */
  887.             sstate = parser(1);
  888.             if (sstate) proto(); /* Enter protocol if requested. */
  889.         }
  890.         }
  891.     }
  892. #endif /* NOSPL */
  893. #ifndef NOICP
  894. /*
  895.   If a command-line action argument was given and -S ("stay") was not given,
  896.   exit now.
  897. */
  898.     if ((cflg || cnflg || zstate) && !stayflg)
  899. #endif /* NOICP */
  900.       doexit(GOOD_EXIT,xitsta); /* exit with good status */
  901.     }
  902. #endif /* NOCMDL */
  903.  
  904. #ifdef NOICP                /* No interactive command parser */
  905.     else {
  906. #ifndef NOCMDL
  907.     usage();            /* Command-line-only version */
  908.     doexit(BAD_EXIT,-1);
  909. #else                    /* Neither one! */
  910.     doexit(BAD_EXIT,-1);
  911. #endif /* NOCMDL */
  912.     }
  913. #else /* not NOICP */
  914. /*
  915.   If no action requested on command line, or if -S ("stay") was included,
  916.   enter the interactive command parser.
  917. */
  918.     herald();                /* Display program herald. */
  919.  
  920. #ifndef NOCCTRAP            /* If not no Control-C trap */
  921. ccagain:
  922.     if (setjmp(cmjbuf)) {        /* Control-C trap returns to here. */
  923. #ifdef GEMDOS
  924.     cc_clean();
  925. #endif /* GEMDOS */
  926.     fixcmd();            /* Pop command stacks, etc. */
  927.     debug(F100,"ckcmai got interrupt","",0);
  928.     goto ccagain;            /* set up trap again. */
  929.     } else {
  930.     debug(F100,"ckcmai setting interrupt trap","",0);
  931.     setint();            /* Set up command interrupt traps */
  932.     }
  933. #else /* NOCCTRAP */
  934.     setint();                /* Set up command interrupt traps */
  935. #endif /* NOCCTRAP */
  936.  
  937. #ifdef MAC
  938.     while (1) {
  939.     extern char *lfiles;        /* fake pointer cast */
  940.  
  941.     if (connected) {
  942.         debug(F100, "main: calling macparser", "", 0);
  943.         sstate = newparser(1, 1, 0L);
  944.  
  945.         /* ignore null command state */
  946.         if (sstate == 'n')
  947.         sstate = '\0';
  948.  
  949.         if (sstate)
  950.         proto();
  951.     }
  952.     else {
  953.         /*
  954.          * process take files the finder gave us.
  955.          */
  956.         if ((tlevel == -1) && lfiles)
  957.         startlfile();
  958.  
  959.         debug(F100, "main: calling parser", "", 0);
  960.         sstate = parser(0);
  961.         if (sstate == 'c')        /* if MAC connect */
  962.         sstate = 0;
  963.         if (sstate)
  964.         proto();
  965.     }
  966.     }
  967. #else /* Not MAC */
  968.  
  969. /*
  970.   Running from an application file, or a command filename was
  971.   specified on the command line.
  972. */
  973.     if (*cmdfil) dotake(cmdfil);    /* Command file spec'd on cmd line */
  974.     while(1) {                /* Loop getting commands. */
  975.     sstate = parser(0);
  976.         if (sstate) proto();            /* Enter protocol if requested. */
  977.     }
  978. #endif /* MAC */
  979. #endif /* NOICP */
  980. }
  981.  
  982. #ifdef DYNAMIC
  983. /* Allocate file i/o buffers */
  984.  
  985. char *zinbuffer, *zoutbuffer;
  986.  
  987. int
  988. getiobs() {
  989.     zinbuffer = (char *)malloc(INBUFSIZE);
  990.     if (!zinbuffer) return(-1);
  991.     zoutbuffer = (char *)malloc(OBUFSIZE);
  992.     if (!zoutbuffer) return(-1);    
  993.     debug(F100,"getiobs ok","",0);
  994.     return(0);
  995. }
  996. #endif /* DYNAMIC */
  997.