BSD 4_4_Lite2 development
[unix-history] / usr / src / contrib / kermit-5A.188 / ckcmai.c
CommitLineData
d81f5d5d
C
1#ifndef MAC
2char *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*/
7char *versio = "Mac Kermit 0.99(188) Pre-ALPHA, 23 Nov 92";
8#endif /* MAC */
9long 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 */
20int 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\f
315#ifndef NOSERVER
316/* Text message definitions.. each should be 256 chars long, or less. */
317#ifdef MAC
318char *hlptxt = "\r\
319Mac 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
330char *hlptxt = "C-Kermit Server Commands:\n\
331\n\
332GET filespec, SEND filespec, FINISH, BYE, REMOTE HELP\n\
333\n\0";
334#else
335#ifdef OS2
336char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
337\n\
338GET files REMOTE CD [dir] REMOTE DIRECTORY [files]\n\
339SEND files REMOTE SPACE [dir] REMOTE HOST command\n\
340FINISH REMOTE DELETE files REMOTE TYPE files\n\
341BYE REMOTE HELP REMOTE SET parameter value\n\
342\n\0";
343#else
344#ifdef MINIX
345char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
346GET SEND BYE FINISH REMOTE: CD DEL DIR HELP HOST SET SPACE TYPE WHO\n\0";
347#else
348#ifdef VMS
349char *hlptxt = "C-Kermit Server REMOTE Commands:\r\n\
350\r\n\
351GET files REMOTE CD [dir] REMOTE DIRECTORY [files]\r\n\
352SEND files REMOTE SPACE [dir] REMOTE HOST command\r\n\
353MAIL files REMOTE DELETE files REMOTE WHO [user]\r\n\
354BYE REMOTE PRINT files REMOTE TYPE files\r\n\
355FINISH REMOTE HELP REMOTE SET parameter value\r\n\
356\0";
357#else
358#ifdef datageneral
359char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
360\n\
361GET files REMOTE CD [dir] REMOTE DIRECTORY [filespec]\n\
362SEND files REMOTE SPACE [dir] REMOTE HOST command\n\
363BYE REMOTE TYPE file REMOTE DELETE files\n\
364FINISH REMOTE WHO REMOTE SET\n\
365\0";
366#else
367char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
368\n\
369GET files REMOTE CD [dir] REMOTE DIRECTORY [files]\n\
370SEND files REMOTE SPACE [dir] REMOTE HOST command\n\
371MAIL files REMOTE DELETE files REMOTE WHO [user]\n\
372BYE REMOTE PRINT files REMOTE TYPE files\n\
373FINISH 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
383char *srvtxt = "\r\n\
384Entering server mode.\r\n\0";
385#else
386#ifdef OSK
387char *srvtxt = "\r\l\
388Entering server mode. If your local Kermit software is menu driven, use\r\l\
389the menus to send commands to the server. Otherwise, enter the escape\r\l\
390sequence to return to your local Kermit prompt and issue commands from\r\l\
391there. Use SEND and GET for file transfer. Use REMOTE HELP for a list of\r\l\
392other available services. Use BYE or FINISH to end server mode.\r\l\0";
393#else /* UNIX, VMS, AOS/VS, and all others */
394char *srvtxt = "\r\n\
395Entering server mode. If your local Kermit software is menu driven, use\r\n\
396the menus to send commands to the server. Otherwise, enter the escape\r\n\
397sequence to return to your local Kermit prompt and issue commands from\r\n\
398there. Use SEND and GET for file transfer. Use REMOTE HELP for a list of\r\n\
399other available services. Use BYE or FINISH to end server mode.\r\n\0";
400#endif /* OSK */
401#endif /* MINIX */
402#else /* server mode disabled */
403char *srvtxt = "";
404#endif /* NOSERVER */
405\f
406/* Declarations for Send-Init Parameters */
407
408int 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
454int 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
470int 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
487CHAR 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
494struct zattr iattr; /* Incoming file attributes */
495
496/* File related variables, mainly for the benefit of VAX/VMS */
497
498int fblksiz = DBLKSIZ; /* File blocksize */
499int frecl = DLRECL; /* File record length */
500int frecfm = XYFF_S; /* File record format (default = stream) */
501int forg = XYFO_S; /* File organization (sequential) */
502int fcctrl = XYFP_N; /* File carriage control (ctrl chars) */
503
504#ifdef VMS
505/* VMS labeled file options */
506int lf_opts = LBL_NAM;
507#else
508int lf_opts = 0;
509#endif /* VMS */
510
511/* Packet-related variables */
512
513int 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
525CHAR
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\f
544/* File-related variables */
545
546char filnam[257]; /* Name of current file. */
547char cmdfil[80]; /* Application file name. */
548
549int nfils = 0; /* Number of files in file group */
550long fsize; /* Size of current file */
551int wildxpand = 0; /* Who expands wildcards */
552int clfils = 0; /* Flag for command-line files */
553int stayflg = 0; /* Flag for "stay", i.e. "-S" */
554
555/* Communication line variables */
556
557char ttname[80]; /* Name of communication line. */
558
559#ifdef MAC
560int connected = 0; /* true if connected */
561int startconnected; /* initial state of connected */
562#endif /* MAC */
563
564long speed = -1L; /* Line speed */
565
566int 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
622long 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
631int tsecs = 0; /* Seconds for transaction */
632int fsecs = 0; /* Per-file timer */
633
634/* Flags */
635
636int 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 */
671char *clcmds = NULL; /* Pointer to command-line commands */
672#endif /* NOSPL */
673
674CHAR sstate = (CHAR) 0; /* Starting state for automaton */
675CHAR zstate = (CHAR) 0; /* For remembering sstate */
676char *cmarg = ""; /* Pointer to command data */
677char *cmarg2 = ""; /* Pointer to 2nd command data */
678char **cmlist; /* Pointer to file list in argv */
679\f
680/* Flags for the ENABLE and DISABLE commands */
681
682int en_cwd = 1; /* CD/CWD */
683int en_del = 1; /* DELETE */
684int en_dir = 1; /* DIRECTORY */
685int en_fin = 1; /* FINISH/BYE */
686int en_get = 1; /* GET */
687#ifndef NOPUSH
688int en_hos = 1; /* HOST enabled */
689#else
690int en_hos = 0; /* HOST disabled */
691#endif /* NOPUSH */
692int en_sen = 1; /* SEND */
693int en_set = 1; /* SET */
694int en_spa = 1; /* SPACE */
695int en_typ = 1; /* TYPE */
696int en_who = 1; /* WHO */
697#ifdef datageneral
698/* Data General AOS/VS can't do this */
699int en_bye = 0; /* BYE */
700#else
701int en_bye = 1; /* BYE */
702#endif /* datageneral */
703\f
704/* Miscellaneous */
705
706char **xargv; /* Global copies of argv */
707int xargc; /* and argc */
708int xargs; /* an immutable copy of argc */
709char *xarg0; /* and of argv[0] */
710
711extern char *dftty; /* Default tty name from ck?tio.c */
712extern int dfloc; /* Default location: remote/local */
713extern int dfprty; /* Default parity */
714extern 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. */
722char zinbuffer[INBUFSIZE], zoutbuffer[OBUFSIZE];
723#endif
724char *zinptr, *zoutptr;
725int zincnt, zoutcnt;
726
727_PROTOTYP( int getiobs, (void) );
728\f
729/* M A I N -- C-Kermit main program */
730
731#ifndef NOCCTRAP
732#include <setjmp.h>
733extern 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 */
741int
742ckcmai(argc,argv) int argc; char **argv;
743#else
744#ifdef MAC
745int main (void)
746#else
747int
748main(argc,argv) int argc; char **argv;
749#endif /* MAC */
750#endif /* aegis */
751{
752#ifdef datageneral
753short *pfha = 016000000036; /* Get around LANG_RT problem -- */
754*pfha = (short) 0; /* No user protection fault handler */
755#endif /* datageneral */
756
757/* Do some initialization */
758
759 if (sysinit() < 0) /* System-dependent initialization. */
760 fatal("Can't initialize!");
761 connoi(); /* Console interrupts off */
762#ifndef MAC
763 xargc = xargs = argc; /* Make global copies of argc */
764 xargv = argv; /* ...and argv. */
765 xarg0 = argv[0];
766#endif /* MAC */
767 sstate = 0; /* No default start state. */
768#ifdef DYNAMIC
769 if (getiobs() < 0)
770 fatal("Can't allocate i/o buffers!");
771#endif /* DYNAMIC */
772 ckhost(myhost,MYHOSTL); /* Name of local host */
773 strcpy(ttname,dftty); /* Set up default tty name. */
774 local = dfloc; /* And whether it's local or remote. */
775 parity = dfprty; /* Set initial parity, */
776 flow = dfflow; /* and flow control. */
777 if (local) if (ttopen(ttname,&local,0,0) < 0) { /* If default tty line */
778 printf("%s: Can't open device\n",ttname); /* is external, open it */
779 local = 0; /* now... */
780 strcpy(ttname,CTTNAM);
781 }
782 speed = ttgspd(); /* Get transmission speed. */
783
784#ifdef SUNX25
785 initpad(); /* Initialize X.25 PAD */
786#endif /* SUNX25 */
787
788 if (inibufs(SBSIZ,RBSIZ) < 0) /* Allocate packet buffers */
789 fatal("Can't allocate packet buffers!");
790
791#ifndef NOICP
792#ifdef MAC
793 cmdini();
794#else /* Not MAC */
795/* Attempt to take ini file before doing command line */
796
797 *cmdfil = '\0'; /* Assume no command file. */
798 prescan(); /* But first check for -y option */
799
800#ifndef NOCCTRAP
801 setint(); /* Set up interrupts */
802 if (setjmp(cmjbuf)) { /* Control-C trap returns to here. */
803#ifdef GEMDOS
804 cc_clean(); /* Atari: Clean up after ^C-trap. */
805#endif /* GEMDOS */
806 doexit(GOOD_EXIT,-1); /* Exit with good status. */
807 } else {
808#endif /* NOCCTRAP */
809 cmdini(); /* Sets tlevel */
810 while (tlevel > -1) { /* Execute init file. */
811 sstate = parser(0); /* Loop getting commands. */
812 if (sstate) proto(); /* Enter protocol if requested. */
813 }
814#ifndef NOCCTRAP
815 }
816#endif /* NOCCTRAP */
817
818/*
819 In UNIX there are two ways to invoke Kermit with a cmdfile:
820 (1) From the kermit command line, e.g. "kermit cmdfile [ options... ]"
821 argv[0] = "kermit"
822 argv[1] = "cmdfile"
823 (2) By executing a cmdfile whose first line is like "#!/path/kermit"
824 argv[0] = "/path/kermit" (sometimes just "kermit")
825 argv[1] = "/path/cmdfile"
826*/
827 if (argc > 1) {
828 if (*argv[1] != '-') {
829 if (zchki(argv[1]) > 0) {
830 strcpy(cmdfil,argv[1]);
831 }
832 }
833 }
834 if (*cmdfil) { /* If we got one, */
835 dotake(cmdfil); /* execute it */
836 while (tlevel > -1) { /* until it runs out. */
837 sstate = parser(1); /* Loop getting commands. */
838 if (sstate) proto(); /* Enter protocol if requested. */
839 }
840 }
841 *cmdfil = '\0'; /* Done, nullify the file name */
842#endif /* MAC */
843#endif /* NOICP */
844
845#ifndef NOCMDL
846/* Look for a UNIX-style command line... */
847
848 if (argc > 1) { /* Command line arguments? */
849 sstate = cmdlin(); /* Yes, parse. */
850 zstate = sstate; /* Remember sstate around protocol */
851 if (cflg) conect(); /* Connect first if requested */
852 if (sstate) {
853 if (displa) concb((char)escape); /* (for console "interrupts") */
854#ifndef NOCCTRAP
855 setint(); /* Set up interrupts */
856 if (setjmp(cmjbuf)) { /* Control-C trap returns to here. */
857#ifdef GEMDOS
858 cc_clean();
859#endif /* GEMDOS */
860 if (cnflg) conect(); /* connect again if requested, */
861 } else {
862#endif /* NOCCTRAP */
863 proto(); /* Take any requested action, then */
864 if (!quiet) /* put cursor back at left margin, */
865 conoll("");
866 if (cnflg) conect(); /* connect if requested, */
867#ifndef NOCCTRAP
868 }
869#endif /* NOCCTRAP */
870 }
871/*
872 If interactive commands were given on the command line (using the
873 -C "command, command, ..." option), assign them to a macro called
874 "cl_commands", then execute the macro and leave it defined for
875 subsequent re-execution if desired.
876*/
877#ifndef NOSPL
878 if (clcmds) { /* Check for -C commands */
879 int x;
880 x = addmac("cl_commands",clcmds); /* Put macro in table */
881 if (x > -1) { /* If successful, */
882 dodo(x,NULL); /* set up for macro execution */
883 while (maclvl > -1) { /* Loop getting macro commands. */
884 sstate = parser(1);
885 if (sstate) proto(); /* Enter protocol if requested. */
886 }
887 }
888 }
889#endif /* NOSPL */
890#ifndef NOICP
891/*
892 If a command-line action argument was given and -S ("stay") was not given,
893 exit now.
894*/
895 if ((cflg || cnflg || zstate) && !stayflg)
896#endif /* NOICP */
897 doexit(GOOD_EXIT,xitsta); /* exit with good status */
898 }
899#endif /* NOCMDL */
900
901#ifdef NOICP /* No interactive command parser */
902 else {
903#ifndef NOCMDL
904 usage(); /* Command-line-only version */
905 doexit(BAD_EXIT,-1);
906#else /* Neither one! */
907 doexit(BAD_EXIT,-1);
908#endif /* NOCMDL */
909 }
910#else /* not NOICP */
911/*
912 If no action requested on command line, or if -S ("stay") was included,
913 enter the interactive command parser.
914*/
915 herald(); /* Display program herald. */
916
917#ifndef NOCCTRAP /* If not no Control-C trap */
918ccagain:
919 if (setjmp(cmjbuf)) { /* Control-C trap returns to here. */
920#ifdef GEMDOS
921 cc_clean();
922#endif /* GEMDOS */
923 fixcmd(); /* Pop command stacks, etc. */
924 debug(F100,"ckcmai got interrupt","",0);
925 goto ccagain; /* set up trap again. */
926 } else {
927 debug(F100,"ckcmai setting interrupt trap","",0);
928 setint(); /* Set up command interrupt traps */
929 }
930#else /* NOCCTRAP */
931 setint(); /* Set up command interrupt traps */
932#endif /* NOCCTRAP */
933
934#ifdef MAC
935 while (1) {
936 extern char *lfiles; /* fake pointer cast */
937
938 if (connected) {
939 debug(F100, "main: calling macparser", "", 0);
940 sstate = newparser(1, 1, 0L);
941
942 /* ignore null command state */
943 if (sstate == 'n')
944 sstate = '\0';
945
946 if (sstate)
947 proto();
948 }
949 else {
950 /*
951 * process take files the finder gave us.
952 */
953 if ((tlevel == -1) && lfiles)
954 startlfile();
955
956 debug(F100, "main: calling parser", "", 0);
957 sstate = parser(0);
958 if (sstate == 'c') /* if MAC connect */
959 sstate = 0;
960 if (sstate)
961 proto();
962 }
963 }
964#else /* Not MAC */
965
966/*
967 Running from an application file, or a command filename was
968 specified on the command line.
969*/
970 if (*cmdfil) dotake(cmdfil); /* Command file spec'd on cmd line */
971 while(1) { /* Loop getting commands. */
972 sstate = parser(0);
973 if (sstate) proto(); /* Enter protocol if requested. */
974 }
975#endif /* MAC */
976#endif /* NOICP */
977}
978
979#ifdef DYNAMIC
980/* Allocate file i/o buffers */
981
982char *zinbuffer, *zoutbuffer;
983
984int
985getiobs() {
986 zinbuffer = (char *)malloc(INBUFSIZE);
987 if (!zinbuffer) return(-1);
988 zoutbuffer = (char *)malloc(OBUFSIZE);
989 if (!zoutbuffer) return(-1);
990 debug(F100,"getiobs ok","",0);
991 return(0);
992}
993#endif /* DYNAMIC */