source: trunk/third/kermit/ckcmai.c @ 10780

Revision 10780, 64.7 KB checked in by brlewis, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10779, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2  ckcsym.h is used for for defining symbols that normally would be defined
3  using -D or -d on the cc command line, for use with compilers that don't
4  support this feature.  Must be before any tests for preprocessor symbols.
5*/
6#include "ckcsym.h"
7
8char *ck_ver = "C-Kermit 6.0.192";      /* C-Kermit Version */
9#ifdef UNIX
10static char sccsid[] = "@(#)C-Kermit 6.0.192";
11#endif /* UNIX */
12
13#ifndef MAC
14#ifdef OS2
15#ifdef NT
16/* Version herald */
17char *versio = "Kermit-95 1.1.8, 21 Nov 96"; /* Version herald */
18long xvernum = 118L;
19#else /* NT */
20char *versio = "Kermit-95 for OS/2 1.1.8 Beta, 23 Nov 96"; /* Version harald */
21long xvernum = 118L;
22#endif /* NT */
23#else /* OS2 */
24char *versio = "C-Kermit 6.0.192, 6 Sep 96";
25long xvernum = 0L;
26#endif /* OS2 */
27#else
28/*
29  For Macintosh, also remember to change the Mac-specific version in ckmkr2.r.
30*/
31char *versio = "Mac Kermit 0.993 Pre-Alpha, 6 Sep 96";
32long xvernum = 993L;
33#endif /* MAC */
34
35long vernum = 600192L;
36/*
37  String and numeric version numbers, keep these three in sync!
38  First digit of vermum = major version, i.e. 5.
39  Second 2 digits of vernum: 00 = no minor version, 01 = A, 02 = B, etc.
40  Last three digits are edit number.
41*/
42#ifndef VERWHO
43/* Change verwho in following line, or with -DVERWHO=x in makefile CFLAGS. */
44#define VERWHO 0
45#endif /* VERWHO */
46int verwho = VERWHO; /* Who produced this version, 0 = Columbia University */
47/*
48  IMPORTANT: If you are working on your own private version of C-Kermit, please
49  include some special notation, like your site name or your initials, in the
50  "versio" string, e.g. "6.0.192-XXX", and use a nonzero code for the "verwho"
51  variable (e.g. in the USA use your zip code).  Unless we stick to this
52  discipline, divergent copies of C-Kermit will begin to appear that are
53  intistinguishable from each other, which is a big support issue.  Also, if
54  you have edited C-Kermit and made copies available to others, please add
55  appropriate text to the BUG command (ckuus6.c, function dobug()).
56*/
57#define CKCMAI
58
59/*  C K C M A I  --  C-Kermit Main program  */
60
61/*
62  Author: Frank da Cruz (fdc@columbia.edu),
63  Columbia University Academic Information Systems, New York City.
64
65COPYRIGHT NOTICE:
66*/
67
68char *copyright[] = {
69
70#ifdef pdp11
71"Copyright (C) 1985, 1996, Trustees of Columbia University, NYC.",
72"All rights reserved.",
73#else
74#ifdef OS2
75"Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New",
76"York.  All rights reserved.  This software is furnished under license",
77"and may not be reproduced without license to do so.  This copyright notice",
78"must not be removed, altered, or obscured.",
79#else
80"Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New",
81"York.  The C-Kermit software may not be, in whole or in part, licensed or",
82"sold for profit as a software product itself, nor may it be included in or",
83"distributed with commercial products or otherwise distributed by commercial",
84"concerns to their clients or customers without written permission of the",
85"Kermit Project, Columbia University.  This copyright notice must not be",
86"removed, altered, or obscured.",
87#endif /* OS2 */
88#endif /* pdp11 */
89#ifdef XYZ_INTERNAL
90" ",
91"Portions Copyright (C) 1995 Oy Online Solutions Ltd., Jyvaskyla, FINLAND\n",
92#endif /* XYZ_INTERNAL */
93#ifndef pdp11
94" ",
95"For further information, contact the Kermit Project, Columbia University,",
96"612 West 115th Street, New York NY 10025-7799, USA; phone +1 (212) 854 3703,",
97"fax +1 (212) 663 8202 or +1 (212) 662 6442, email kermit@columbia.edu,",
98"Web http://www.columbia.edu/kermit/.",
99#endif /* pdp11 */
100""};
101
102/*
103DOCUMENTATION:
104
105 "Using C-Kermit" by Frank da Cruz and Christine M. Gianone,
106  Digital Press / Butterworth-Heinemann, Woburn MA, USA.
107  Second edition (1997), ISBN 1-55558-164-1.
108  Order from Digital Press:    +1 (800) 366-2665
109  Or from Columbia University: +1 (212) 854-3703
110
111For Kermit 95, also:
112
113  "Kermit 95" by Christine M. Gianone and Frank da Cruz,
114  Manning Publications, Greenwich CT, USA (1996)
115  Order from Manning:          +1 (203) 629 2078
116  Or from Columbia University: +1 (212) 854-3703
117
118DISCLAIMER:
119
120  The C-Kermit software is provided in source code and/or binary form by
121  the Kermit Project, Academic Information Systems, Columbia University.
122  The software is provided "as is;" no other warranty is provided, express
123  or implied, including without limitations, any implied warranty of
124  merchantability or implied warranty of fitness for a particular purpose.
125
126  Neither Columbia University nor any of the contributors to C-Kermit's
127  development, including, but not limited to, Manning Software, Digital Press,
128  AT&T, Digital Equipment Corporation, Data General Corporation, or
129  International Business Machines Corporation, or any individuals affiliated
130  with those or other institutions, warrant C-Kermit software or documentation
131  in any way.  In addition, neither the authors of any Kermit programs,
132  publications or documentation, nor Columbia University nor any contributing
133  institutions or individuals acknowledge any liability resulting from program
134  or documentation errors.
135
136  Contributions made to C-Kermit by programmers outside of Columbia University
137  fall within the provisions of the foregoing copyrights, terms and
138  conditions, and disclaimers, and grant to the Kermit Project at Columbia
139  University a nonexclusive license to use the contributed code in any and
140  all Kermit software without restriction or obligation.
141
142ACKNOWLEDGMENTS:
143
144  The Kermit file transfer protocol was developed at the Columbia University
145  Center for Computing Activities (CUCCA), which was since renamed to Columbia
146  University Academic Information Systems (AcIS).  Kermit is named after
147  Kermit the Frog, star of the television series THE MUPPET SHOW; the name is
148  used by permission of Henson Associates, Inc.
149
150  Thanks to at least the following people for their contributions to this
151  program over the years, and apologies to anyone who was inadvertantly
152  omitted:
153
154   Chris Adie, Edinburgh U, Scotland (OS/2)
155   Robert Adsett, University of Waterloo, Canada
156   Larry Afrin, Clemson U
157   Jeffrey Altman, Columbia University
158   Greg Andrews, Telebit Corp
159   Barry Archer, U of Missouri
160   Robert Andersson, International Systems A/S, Oslo, Norway
161   Chris Armstrong, Brookhaven National Lab (OS/2)
162   William Bader, Software Consulting Services, Nazareth, PA
163   Fuat Baran, Columbia U
164   Stan Barber, Rice U
165   Jim Barbour, U of Colorado
166   Donn Baumgartner, Dell
167   Nelson Beebe, U of Utah
168   Karl Berry, UMB
169   Mark Berryman, SAIC
170   Dean W Bettinger, SUNY
171   Gary Bilkus
172   Peter Binderup, Denmark
173   David Bolen, Advanced Networks and Services, Inc.
174   Marc Boucher, U of Montreal
175   Charles Brooks, EDN
176   Bob Brown
177   Mike Brown, Purdue U
178   Jack Bryans, California State U at Long Beach
179   Mark Buda, DEC (VMS)
180   Fernando Cabral, Padrao iX, Brasilia
181   Bjorn Carlsson, Stockholm University Computer Centre QZ, Sweden
182   Bill Catchings, (formerly of) Columbia U
183   Bob Cattani, Columbia U CS Dept
184   Davide Cervone, Rochester U
185   Seth Chaiklin, Denmark
186   John Chandler, Harvard U / Smithsonian Astronomical Observatory
187   Bernard Chen, UCLA
188   Andrew A Chernov, RELCOM Team, Moscow
189   John L Chmielewski, AT&T, Lisle, IL
190   Howard Chu, U of Michigan
191   Bill Coalson, McDonnell Douglas
192   Bertie Coopersmith, London
193   Chet Creider, U of Western Ontario
194   Alan Crosswell, Columbia U
195   Jeff Damens, (formerly of) Columbia U
196   Mark Davies, Bath U, UK
197   Sin-itirou Dezawa, Fujifilm, Japan
198   Joe R. Doupnik, Utah State U
199   Frank Dreano, Honeywell
200   John Dunlap, U of Washington
201   Alex Dupuy, SMART.COM
202   David Dyck, John Fluke Mfg Co.
203   Stefaan A. Eeckels, Eurokom, Luxembourg
204   Paul Eggert, Twin Sun, Inc., El Segundo, CA
205   Bernie Eiben, DEC
206   Peter Eichhorn, Assyst International
207   Kristoffer Eriksson, Peridot Konsult AB, Oerebro, Sweden
208   John R. Evans, IRS, Kansas City
209   Glenn Everhart, RCA Labs
210   Charlie Finan, Cray Research
211   Herm Fischer, Encino, CA (extensive contributions to version 4.0)
212   Carl Fongheiser, CWRU
213   Mike Freeman, Bonneville Power Authority
214   Marcello Frutig, Catholic University, Sao Paulo, Brazil (X.25 support)
215   Hirofumi Fujii, Japan Nat'l Lab for High Energy Physics, Tokyo (Kanji)
216   Chuck Fuller, Westinghouse Corporate Computer Services
217   Andy Fyfe, Caltech
218   Christine M. Gianone, Columbia U
219   John Gilmore, UC Berkeley
220   Madhusudan Giyyarpuram, HP
221   Rainer Glaschick, Siemens AG, Paderborn
222   William H. Glass
223   German Goldszmidt, IBM
224   Chuck Goodhart, NASA
225   Alistair Gorman, New Zealand
226   Richard Gration, ADFA, Australia
227   Chris Green, Essex U, UK
228   Alan Grieg, Dundee Tech, Scotland
229   Yekta Gursel, MIT
230   Jim Guyton, Rand Corp
231   Michael Haertel
232   Bob Hain, UMN
233   Marion Hakanson, ORST
234   John Hamilston, Iowa State U
235   Simon Hania, Netherlands
236   Stan Hanks, Rice U.
237   Ken Harrenstein, SRI
238   Eugenia Harris, Data General (AOS/VS)
239   David Harrison, Kingston Warren Corp
240   James Harvey, Indiana/Purdue U (VMS)
241   Rob Healey
242   Chuck Hedrick, Rutgers U
243   Ron Heiby, Technical Systems Division, Motorola Computer Group
244   Steve Hemminger, Tektronix
245   Christian Hemsing, RWTH Aachen, Germany (OS-9)
246   Andrew Herbert, Monash Univ, Australia
247   Mike Hickey, ITI
248   Dan Hildebrand, QNX Software Systems Inc, Kanata, ON (QNX)
249   R E Hill
250   Bill Homer, Cray Research
251   Ray Hunter, The Wollongong Group
252   Randy Huntziger, National Library of Medicine
253   Larry Jacobs, Transarc
254   Steve Jenkins, Lancaster University, UK
255   Dave Johnson, Gradient Technologies
256   Mark B Johnson, Apple Computer
257   Jyke Jokinen, Tampere University of Technology, Finland (QNX)
258   Eric F Jones, AT&T
259   Luke Jones, AT&T
260   Peter Jones, U of Quebec Montreal
261   Phil Julian, SAS Institute
262   Peter Kabal, U of Quebec
263   Mic Kaczmarczik, U of Texas at Austin
264   Sergey Kartashoff, Inst. of Precise Mechanics & Computer Equipment, Moscow
265   Howie Kaye, Columbia U
266   Rob Kedoin, Linotype Co, Hauppauge, NY (OS/2)
267   Phil Keegstra
268   Mark Kennedy, IBM
269   Terry Kennedy, St Peter's College, Jersey City, NJ (VMS and more)
270   "Carlo Kid", Technical University of Delft, Netherlands
271   Tim Kientzle
272   Paul Kimoto, Cornell U
273   Douglas Kingston, morgan.com
274   Lawrence Kirby, Wiltshire, UK
275   Tom Kloos, Sequent Computer Systems
276   Jim Knutson, U of Texas at Austin
277   John T. Kohl (BSDI)
278   Scott Kramer, SRI International, Menlo Park, CA
279   John Kraynack, US Postal Service
280   David Kricker, Encore Computer
281   Thomas Krueger, UWM
282   Bo Kullmar, ABC Klubben, Stockholm, and Central Bank of Sweden, Kista
283   R. Brad Kummer, AT&T Bell Labs, Atlanta, GA
284   John Kunze, UC Berkeley
285   David Lane, BSSI / BellSouth (Stratus VOS, X.25)
286   Bob Larson, USC (OS-9)
287   Bert Laverman, Groningen U, Netherlands
288   Steve Layton
289   David Lawyer, UC Irvine
290   David LeVine, National Semiconductor Corporation
291   Daniel S. Lewart, UIUC
292   S.O. Lidie, Lehigh U
293   Tor Lillqvist, Helsinki U, Finland
294   David-Michael Lincke, U of St Gallen, Switzerland
295   Robert Lipe
296   Dean Long
297   Mike Long, Analog Devices, Norwood MA
298   Kevin Lowey, U of Saskatchewan (OS/2)
299   Andy Lowry, Columbia U
300   James Lummel, Caprica Telecomputing Resources (QNX)
301   David MacKenzie, Environmental Defense Fund, U of Maryland
302   John Mackin, University of Sidney, Australia
303   Martin Maclaren, Bath U, UK
304   Chris Maio, Columbia U CS Dept
305   Montserrat Mane, HP, Grenoble, France
306   Fulvio Marino, Olivetti, Ivrea, Italy
307   Arthur Marsh, dircsa.org.au
308   Peter Mauzey, AT&T
309   Tye McQueen, Utah State U
310   Ted Medin
311   Hellmuth Michaelis, Hanseatischer Computerservice GmbH, Hamburg, Germany
312   Leslie Mikesell, American Farm Bureau
313   Martin Minow, DEC (VMS)
314   Pawan Misra, Bellcore
315   Ken Mizialko, IBM, Manassas, VA
316   Ray Moody, Purdue U
317   Bruce J Moore, Allen-Bradley Co, Highland Heights, OH (Atari ST)
318   Steve Morley, Convex
319   Peter Mossel, Columbia U
320   Tony Movshon, NYU
321   Lou Muccioli, Swanson Analysis Systems
322   Dan Murphy
323   Neal P. Murphy, Harsof Systems, Wonder Lake IL
324   Gary Mussar
325   John Nall, FSU
326   Jack Nelson, U of Pittsburgh
327   Jim Noble, Planning Research Corporation (Macintosh)
328   Ian O'Brien, Bath U, UK
329   John Owens
330   Michael Pins, Iowa Computer Aided Engineering Network
331   Andre' Pirard, University of Liege, Belgium
332   Paul Placeway, Ohio State U
333   Piet W. Plomp, ICCE, Groningen University, Netherlands
334   Ken Poulton, HP Labs
335   Manfred Prange, Oakland U
336   Christopher Pratt, APV Baker, UK
337   Frank Prindle, NADC
338   Tony Querubin, U of Hawaii
339   Anton Rang
340   Scott Ribe
341   Alan Robiette, Oxford University, UK
342   Michel Robitaille, U of Montreal (Mac)
343   Huw Rogers, Schweizerische Kreditanstalt, Zuerich
344   Nigel Roles, Cambridge, England
345   Kai Uwe Rommel, Technische Universitaet Muenchen (OS/2)
346   Larry Rosenman (Amiga)
347   Jay Rouman, U of Michigan
348   Jack Rouse, SAS Institute (Data General and/or Apollo)
349   Stew Rubenstein, Harvard U (VMS)
350   John Santos, EG&H
351   Bill Schilit, Columbia U
352   Ulli Schlueter, RWTH Aachen, Germany (OS-9, etc)
353   Michael Schmidt, U of Paderborn, Germany
354   Eric Schnoebelen, Convex
355   Benn Schreiber, DEC
356   Dan Schullman, DEC (modems, DIAL command, etc)
357   John Schultz, 3M
358   Steven Schultz, Contel (PDP-11)
359   APPP Scorer, Leeds Polytechnic, UK
360   Gordon Scott, Micro Focus, Newbury UK
361   Gisbert W. Selke, WIdO, Bonn, Germany
362   David Singer, IBM Almaden Research Labs
363   David Sizeland, U of London Medical School
364   Fridrik Skulason, Iceland
365   Rick Sladkey (Linux)
366   Dave Slate
367   Bradley Smith, UCLA
368   Fred Smith, Merk
369   Richard S Smith, Cal State
370   Ryan Stanisfer, UNT
371   Bertil Stenstroem, Stockholm University Computer Centre (QZ), Sweden
372   James Sturdevant, CAP GEMENI AMERICA, Minneapolis
373   Peter Svanberg, Royal Techn. HS, Sweden
374   James R. Swenson, Accu-Weather, Inc.
375   Andy Tanenbaum, Vrije U, Amsterdam, Netherlands
376   Glen Thobe
377   Markku Toijala, Helsinki U of Technology
378   Teemu Torma, Helsinki U of Technology
379   Linus Torvalds, Helsinki
380   Rick Troxel, NIH
381   Warren Tucker, Tridom Corp, Mountain Park, GA
382   Dave Tweten, AMES-NAS
383   G Uddeborg, Sweden
384   Walter Underwood, Ford Aerospace
385   Pieter Van Der Linden, Centre Mondial, Paris
386   Ge van Geldorp, Netherlands
387   Fred van Kempen, MINIX User Group, Voorhout, Netherlands
388   Wayne Van Pelt, GE/CRD
389   Mark Vasoll, Oklahoma State U (V7 UNIX)
390   Konstantin Vinogradov, ICSTI, Moscow
391   Paul Vixie, DEC
392   Bernie Volz, Process Software
393   Eduard Vopicka, Prague University of Economics, Czech Republic
394   Dimitri Vulis, CUNY
395   Roger Wallace, Raytheon
396   Stephen Walton, Calif State U, Northridge (Amiga)
397   Jamie Watson, Adasoft, Switzerland (RS/6000)
398   Rick Watson, U of Texas (Macintosh)
399   Robert Weiner, Programming Plus, New York City
400   Lauren Weinstein, Vortex Technlogy
401   David Wexelblat, AT&T
402   Clark Wierda, Illuminati Online
403   Joachim Wiesel, U of Karlsruhe
404   Lon Willett, U of Utah
405   Michael Williams, UCLA
406   Nate Williams, U of Montana
407   David Wilson
408   Joellen Windsor, U of Arizona
409   Patrick Wolfe, Kuck & Associates, Inc.
410   Gregg Wonderly, Oklahoma State U (V7 UNIX)
411   Farrell Woods, Concurrent (formerly Masscomp)
412   Dave Woolley, CAP Communication Systems, London
413   Jack Woolley, SCT Corp
414   Frank Wortner
415   Ken Yap, formerly of U of Rochester
416   John Zeeff, Ann Arbor, MI */
417#include "ckcasc.h"                     /* ASCII character symbols */
418#include "ckcdeb.h"                     /* Debug & other symbols */
419#include "ckcker.h"                     /* Kermit symbols */
420#include "ckcnet.h"                     /* Network symbols */
421#ifndef NOSPL
422#include "ckuusr.h"
423#endif /* NOSPL */
424#ifdef OS2ONLY
425#define INCL_VIO                        /* Needed for ckocon.h */
426#include <os2.h>
427#endif /* OS2ONLY */
428#ifdef NT
429#include "ckntap.h"
430#endif /* NT */
431
432#ifndef NOSERVER
433/* Text message definitions.. each should be 256 chars long, or less. */
434#ifdef pdp11
435char *hlptxt = "PDP-11 C-Kermit Server - no help available.\n";
436#else
437#ifdef MAC
438char *hlptxt = "\r\
439Mac Kermit Server Commands:\r\
440\r\
441    BYE\r\
442    FINISH\r\
443    GET filespec\r\
444    REMOTE CD directory\r\
445    REMOTE HELP\r\
446    SEND filespec\r\
447\r\0";
448#else
449#ifdef AMIGA
450char *hlptxt = "Amiga C-Kermit server responds to:\n\
451\n\
452GET filespec, SEND filespec, FINISH, BYE, REMOTE HELP\n\
453\n\0";
454#else
455#ifdef OS2
456char *hlptxt = "Kermit server responds to:\r\n\
457\r\n\
458GET files      REMOTE CD [dir]         REMOTE DIRECTORY [files]\r\n\
459REGET files    REMOTE COPY [f1] [f2]   REMOTE HOST command\r\n\
460RETRIEVE files REMOTE PRINT files      REMOTE TYPE files\r\n\
461SEND files     REMOTE RENAME [f1] [f2] REMOTE SET parameter value\r\n\
462FINISH         REMOTE SPACE [dir]      REMOTE QUERY type variable\r\n\
463BYE            REMOTE DELETE files     REMOTE ASSIGN variable value\r\n\
464               REMOTE LOGIN user pswd  REMOTE HELP\r\n\
465\r\n\0";
466#else
467#ifdef MINIX
468char *hlptxt = "C-Kermit Server commands:\n\
469GET REGET SEND BYE FINISH REMOTE: CD DEL DIR HELP HOST SET SPACE TYPE WHO\n\0";
470#else
471#ifdef VMS
472char *hlptxt = "VMS C-Kermit server responds to:\r\n\
473\r\n\
474GET files      REMOTE CD [dir]     REMOTE DIRECTORY [files]\r\n\
475REGET files    REMOTE SPACE [dir]  REMOTE HOST command\r\n\
476RETRIEVE files REMOTE DELETE files REMOTE WHO [user]\r\n\
477SEND files     REMOTE PRINT files  REMOTE SET parameter value\r\n\
478MAIL files     REMOTE HELP         REMOTE QUERY type variable\r\n\
479BYE            REMOTE LOGIN        REMOTE ASSIGN variable value\r\n\
480FINISH         REMOTE TYPE files\r\n\
481\0";
482#else
483#ifdef datageneral
484char *hlptxt = "AOS/VS C-Kermit server responds to:\n\
485\n\
486GET files   REMOTE CD [dir]     REMOTE DIRECTORY [filespec]\n\
487REGET files REMOTE SPACE [dir]  REMOTE HOST command\n\
488SEND files  REMOTE TYPE file    REMOTE DELETE files\n\
489BYE         REMOTE WHO          REMOTE SET\n\
490FINISH      REMOTE LOGIN        REMOTE QUERY type variable\n\
491RETREIVE files                  REMOTE ASSIGN variable value\n\
492\0";
493#else
494#ifdef NOSPL
495char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
496\n\
497GET files      REMOTE CD [dir]     REMOTE DIRECTORY [files]\n\
498SEND files     REMOTE SPACE [dir]  REMOTE HOST command\n\
499MAIL files     REMOTE DELETE files REMOTE WHO [user]\n\
500RETRIEVE files REMOTE PRINT files  REMOTE TYPE files\n\
501FINISH         REMOTE HELP         REMOTE SET parameter value\n\
502BYE\n\
503\n\0";
504#else
505char *hlptxt = "C-Kermit Server REMOTE Commands:\n\
506\n\
507GET files      REMOTE CD [dir]     REMOTE HOST command\n\
508REGET files    REMOTE SPACE [dir]  REMOTE DIRECTORY [files]\n\
509RETRIEVE files REMOTE DELETE files REMOTE LOGIN user password\n\
510SEND files     REMOTE PRINT files  REMOTE SET parameter value\n\
511RESEND files   REMOTE TYPE files   REMOTE QUERY type variable\n\
512MAIL file user REMOTE WHO [user]   REMOTE ASSIGN variable value\n\
513FINISH, BYE    REMOTE HELP\n";
514#endif /* NOSPL */
515#endif /* datageneral */
516#endif /* VMS */
517#endif /* MINIX */
518#endif /* OS2 */
519#endif /* AMIGA */
520#endif /* MAC */
521#endif /* pdp11 */
522
523#ifdef MINIX
524char *srvtxt = "\r\n\
525Entering server mode.\r\n\0";
526#else
527#ifdef OLDMSG
528/*
529  It seems there was a large installation that was using C-Kermit 5A(165)
530  or thereabouts, which had deployed thousands of MS-DOS Kermit scripts in
531  scattered locations that looked for strings in the old server message,
532  which changed in 5A(183), August 1992.
533*/
534char *srvtxt = "\r\n\
535C-Kermit server starting.  Return to your local machine by typing\r\n\
536its escape sequence for closing the connection, and issue further\r\n\
537commands from there.  To shut down the C-Kermit server, issue the\r\n\
538FINISH or BYE command and then reconnect.\n\
539\r\n\0";
540#else
541#ifdef OSK
542char *srvtxt = "\r\012\
543Entering server mode.  If your local Kermit software is menu driven, use\r\012\
544the menus to send commands to the server.  Otherwise, enter the escape\r\012\
545sequence to return to your local Kermit prompt and issue commands from\r\012\
546there. Use SEND and GET for file transfer. Use REMOTE HELP for a list of\r\012\
547other available services.  Use BYE or FINISH to end server mode.\r\012\0";
548#else /* UNIX, VMS, AOS/VS, and all others */
549char *srvtxt = "\r\n\
550Entering server mode.  If your local Kermit software is menu driven, use\r\n\
551the menus to send commands to the server.  Otherwise, enter the escape\r\n\
552sequence to return to your local Kermit prompt and issue commands from\r\n\
553there.  Use SEND and GET for file transfer.  Use REMOTE HELP for a list of\r\n\
554other available services.  Use BYE or FINISH to end server mode.\r\n\0";
555#endif /* OSK */
556#endif /* OLDMSG */
557#endif /* MINIX */
558#else  /* server mode disabled */
559char *hlptxt = "";
560char *srvtxt = "";
561#endif /* NOSERVER */
562
563/* Declarations for Send-Init Parameters */
564
565struct ck_p ptab[NPROTOS] = {           /* Initialize the Kermit part ... */
566    "Kermit",
567    DRPSIZ,                             /* Receive packet size */
568    DSPSIZ,                             /* Send packet size */
569    0,                                  /* Send-packet-size-set flag */
570    DFWSIZ,                             /* Window size */
571
572#ifdef NEWDEFAULTS
573    PX_CAU,                             /* Control char unprefixing... */
574#else
575    PX_ALL,
576#endif /* NEWDEFAULTS */
577
578#ifdef VMS                              /* Default filename collision action */
579    XYFX_X,                             /* REPLACE for VAX/VMS */
580#else
581    XYFX_B,                             /* BACKUP for everybody else */
582#endif /* VMS */
583
584#ifdef OS2                              /* Flag for file name conversion */
585    XYFN_L,                             /* Literal for OS2 */
586#else
587    XYFN_C,                             /* Converted for others */
588#endif /* OS2 */
589
590    1,                          /* Send pathnames OFF (1 = strip) */
591    1,                          /* Receive pathnames OFF  (ditto) */
592    NULL,                       /* Host receive initiation string (binary) */
593    NULL,                       /* Host receive initiation string (text)   */
594    NULL,                       /* External protocol send command (binary) */
595    NULL,                       /* External protocol send command (text)   */
596    NULL,                       /* External protocol receive command (bin) */
597    NULL                        /* External protocol receive command (txt) */
598#ifdef CK_XYZ
599,
600    "XMODEM",  128,128,-1,-1,    -1,-1,-1,1,1,NULL,NULL,NULL,NULL,NULL,NULL,
601    "YMODEM",   -1, -1,-1,-1,    -1,-1,-1,1,1,NULL,NULL,NULL,NULL,NULL,NULL,
602    "YMODEM-g", -1, -1,-1,-1,    -1,-1,-1,1,1,NULL,NULL,NULL,NULL,NULL,NULL,
603    "ZMODEM",   -1, -1,-1,-1,PX_WIL,-1,-1,1,1,NULL,NULL,NULL,NULL,NULL,NULL,
604    "Other",    -1, -1,-1,-1,    -1,-1,-1,1,1,NULL,NULL,NULL,NULL,NULL,NULL
605#endif /* CK_XYZ */
606};
607
608int spsiz = DSPSIZ,                     /* Current packet size to send */
609    spmax = DSPSIZ,                     /* Biggest packet size we can send */
610    spsizr = DSPSIZ,                    /* Send-packet size requested */
611    spsizf = 0,                         /* Flag to override size negotiation */
612    rpsiz = DRPSIZ,                     /* Biggest we want to receive */
613    urpsiz = DRPSIZ,                    /* User-requested receive pkt size */
614    maxrps = MAXRP,                     /* Maximum incoming long packet size */
615    maxsps = MAXSP,                     /* Maximum outbound l.p. size */
616    maxtry = MAXTRY,                    /* Maximum retries per packet */
617    wslots = 1,                         /* Window size currently in use */
618    wslotr = DFWSIZ,                    /* Window size from SET WINDOW */
619    wslotn = 1,                         /* Window size negotiated in S-pkt */
620    timeouts = 0,                       /* For statistics reporting */
621    spackets = 0,                       /*  ... */
622    rpackets = 0,                       /*  ... */
623    retrans = 0,                        /*  ... */
624    crunched = 0,                       /*  ... */
625    wmax = 0,                           /*  ... */
626    wcur = 0,                           /*  ... */
627#ifdef OS2
628    srvidl = 0,                         /* Server idle timeout */
629#endif /* OS2 */
630    srvdis = 1,                         /* Server file xfer display */
631    srvtim = DSRVTIM,                   /* Server command wait timeout */
632/*
633  timint is the timeout interval I use when waiting for a packet.
634  pkttim is the SET RECEIVE TIMEOUT value, sent to the other Kermit.
635  rtimo is the SET SEND TIMEOUT value.  rtimo is the initial value of
636  timint.  timint is changed by the value in the incoming negotiation
637  packet unless a SET SEND TIMEOUT command was given.
638*/
639    timint = DMYTIM,                    /* Timeout interval I use */
640    pkttim = URTIME,                    /* Timeout I want you to use */
641    rtimo = DMYTIM,                     /* Normal packet wait timeout */
642    timef = 0,                          /* Flag to override what you ask */
643#ifdef CK_TIMERS
644    rttflg = 1,                         /* Use dynamic round-trip timers */
645#else
646    rttflg = 0,                         /* Use fixed timer */
647#endif /* CK_TIMERS */
648    mintime = 1,                        /* Minimum timeout */
649    maxtime = 0,                        /* Maximum timeout */
650
651    npad = MYPADN,                      /* How much padding to send */
652    mypadn = MYPADN,                    /* How much padding to ask for */
653    bctr = DFBCT,                       /* Block check type requested */
654    bctu = 1,                           /* Block check type used */
655    bctl = 1,                           /* Block check length */
656    ebq =  MYEBQ,                       /* 8th bit prefix */
657    ebqflg = 0,                         /* 8th-bit quoting flag */
658    rqf = -1,                           /* Flag used in 8bq negotiation */
659    rq = 0,                             /* Received 8bq bid */
660    sq = 'Y',                           /* Sent 8bq bid */
661    rpt = 0,                            /* Repeat count */
662    rptq = MYRPTQ,                      /* Repeat prefix */
663    rptflg = 0,                         /* Repeat processing flag */
664    rptena = 1,                         /* Repeat processing enabled */
665    xfrcan = 1,                         /* Transfer cancellation enabled */
666    xfrchr = 3,                         /* Transfer cancel char = Ctrl-C */
667    xfrnum = 3;                         /* Need three of them. */
668
669int epktflg = 0;                        /* E-PACKET command active */
670
671int capas  = 9,                         /* Position of Capabilities */
672    lpcapb = 2,                         /* Long Packet capability */
673    lpcapr = 1,                         /*  requested */
674    lpcapu = 0,                         /*  used */
675    swcapb = 4,                         /* Sliding Window capability */
676    swcapr = 1,                         /*  requested (allowed) */
677    swcapu = 0,                         /*  used */
678    atcapb = 8,                         /* Attribute capability */
679    atcapr = 1,                         /*  requested */
680    atcapu = 0,                         /*  used */
681    rscapb = 16,                        /* RESEND capability */
682    rscapr = 1,                         /*  requested by default */
683    rscapu = 0,                         /*  used */
684    lscapb = 32,                        /* Locking Shift capability */
685    lscapr = 1,                         /*  requested by default */
686    lscapu = 0;                         /*  used */
687
688/* Flags for whether to use particular attributes */
689
690int atenci = 1,                         /* Encoding in */
691    atenco = 1,                         /* Encoding out */
692    atdati = 1,                         /* Date in */
693    atdato = 1,                         /* Date out */
694    atdisi = 1,                         /* Disposition in/out */
695    atdiso = 1,
696    atleni = 1,                         /* Length in/out (both kinds) */
697    atleno = 1,
698    atblki = 1,                         /* Blocksize in/out */
699    atblko = 1,
700    attypi = 1,                         /* File type in/out */
701    attypo = 1,
702    atsidi = 1,                         /* System ID in/out */
703    atsido = 1,
704    atsysi = 1,                        /* System-dependent parameters in/out */
705    atsyso = 1;
706
707#ifdef STRATUS
708int atfrmi = 1,                         /* Format in/out */
709    atfrmo = 1,
710    atcrei = 1,                         /* Creator ID in/out */
711    atcreo = 1,
712    atacti = 1,                         /* Account in/out */
713    atacto = 1;
714#endif /* STRATUS */
715
716CHAR padch = MYPADC,                    /* Padding character to send */
717    mypadc = MYPADC,                    /* Padding character to ask for */
718    seol = MYEOL,                       /* End-Of-Line character to send */
719    eol = MYEOL,                        /* End-Of-Line character to look for */
720    ctlq = CTLQ,                        /* Control prefix in incoming data */
721    myctlq = CTLQ,                      /* Outbound control character prefix */
722    myrptq = MYRPTQ;                    /* Repeat prefix I want to use */
723
724int rptmin = 3;                         /* Repeat-count minimum */
725
726char whoareu[16] = { NUL, NUL };        /* System ID of other Kermit */
727int sysindex = -1;                      /* and index to its system ID struct */
728int myindex  = -1;
729char * cksysid =                        /* My system ID */
730#ifdef UNIX
731    "U1"
732#else
733#ifdef VMS
734    "D7"
735#else
736#ifdef OSK
737    "UD"
738#else
739#ifdef AMIGA
740    "L3"
741#else
742#ifdef MAC
743    "A3"
744#else
745#ifdef OS2
746#ifdef NT
747    "UN"
748#else /* NT */
749    "UO"
750#endif /* NT */
751#else /* OS2 */
752#ifdef datageneral
753    "F3"
754#else
755#ifdef GEMDOS
756    "K2"
757#else
758#ifdef STRATUS
759    "MV"
760#else
761    ""
762#endif /* STRATUS */
763#endif /* GEMDOS */
764#endif /* datageneral */
765#endif /* OS2 */
766#endif /* MAC */
767#endif /* AMIGA */
768#endif /* OSK */
769#endif /* VMS */
770#endif /* UNIX */
771    ;
772
773char uidbuf[64] = { NUL, NUL };
774
775struct zattr iattr;                     /* Incoming file attributes */
776
777/* File related variables, mainly for the benefit of (Open)VMS */
778
779#ifdef NLCHAR                           /* Text-file line terminator */
780CHAR feol = NLCHAR;
781#else
782CHAR feol = 0;
783#endif
784
785int fblksiz = DBLKSIZ;          /* File blocksize */
786int frecl = DLRECL;             /* File record length */
787int frecfm = XYFF_S;            /* File record format (default = stream) */
788int forg = XYFO_S;              /* File organization (sequential) */
789int fcctrl = XYFP_N;            /* File carriage control (ctrl chars) */
790
791#ifdef VMS
792/* VMS labeled file default options - name only. */
793int lf_opts = LBL_NAM;
794#else
795#ifdef OS2
796/* OS/2 labeled file default options, all attributes but archived. */
797unsigned long int lf_opts = LBL_EXT|LBL_HID|LBL_RO|LBL_SYS;
798#else
799int lf_opts = 0;
800#endif /* OS2 */
801#endif /* VMS */
802
803/* Packet-related variables */
804
805int pktnum = 0,                         /* Current packet number */
806    sndtyp = 0,                         /* Type of packet just sent */
807    rcvtyp = 0,                         /* Type of packet just received */
808    rsn,                                /* Received packet sequence number */
809    rln,                                /* Received packet length */
810    size,                               /* Current size of output pkt data */
811    osize,                              /* Previous output packet data size */
812    maxsize,                            /* Max size for building data field */
813    spktl = 0,                          /* Length packet being sent */
814    rpktl = 0,                          /* Length of packet just received */
815    pktpaus = 0,                        /* Interpacket pause interval, msec */
816    rprintf,                            /* REMOTE PRINT flag */
817    rmailf;                             /* MAIL flag */
818
819CHAR
820#ifdef pdp11
821    srvcmd[MAXRP+4],
822#else
823#ifdef DYNAMIC
824    *srvcmd = (CHAR *)0,                /* Where to decode server command */
825    *pktmsg = (CHAR *)0,                /* Packet error message */
826#else
827    srvcmd[MAXRP+4],
828    pktmsg[81],
829#endif /* DYNAMIC */
830#endif /* pdp11 */
831    padbuf[96],                         /* Buffer for send-padding */
832    *recpkt,
833    *rdatap,                            /* Pointer to received packet data */
834    *data = (CHAR *)0,                  /* Pointer to send-packet data */
835    *srvptr,                            /* Pointer to srvcmd */
836    mystch = SOH,                       /* Outbound packet-start character */
837    stchr = SOH;                        /* Incoming packet-start character */
838
839/* File-related variables */
840
841#ifndef NOMSEND                         /* Multiple SEND */
842struct filelist * filehead = NULL;
843struct filelist * filetail = NULL;
844struct filelist * filenext = NULL;
845int addlist = 0;
846#endif /* NOMSEND */
847
848char filnam[CKMAXPATH + 1];             /* Name of current file. */
849char cmdfil[CKMAXPATH + 1];             /* Application file name. */
850int cfilef = 0;                         /* Application file flag. */
851#ifndef NOSERVER
852int ngetpath = 0;                       /* GET search path */
853char * getpath[MAXGETPATH];
854char * x_user = NULL;                   /* Server login information */
855char * x_passwd = NULL;
856char * x_acct = NULL;
857int x_login = 0;                        /* Login required */
858int x_logged = 0;                       /* User is logged in */
859#endif /* NOSERVER */
860int nfils = 0;                          /* Number of files in file group */
861long fsize;                             /* Size of current file */
862int wildxpand = 0;                      /* Who expands wildcards */
863int clfils = 0;                         /* Flag for command-line files */
864int stayflg = 0;                        /* Flag for "stay", i.e. "-S" */
865
866/* Communication line variables */
867
868#ifdef BIGBUFOK
869char ttname[512];                       /* Name of communication device */
870#else
871#ifdef MAC
872char ttname[256];
873#else
874char ttname[80];
875#endif /* MAC */
876#endif /* BIGBUFOK */
877
878#ifdef MAC
879int connected = 0;                      /* True if connected */
880int startconnected;                     /* initial state of connected */
881#endif /* MAC */
882
883long speed = -1L;                       /* Line speed */
884
885int parity = DEFPAR,                    /* Parity specified, 0,'e','o',etc */
886    autopar = 0,                        /* Automatic parity change flag */
887    sosi = 0,                           /* Shift-In/Out flag */
888    flow = FLO_XONX,                    /* Flow control */
889    autoflow = 1,                       /* Automatic flow control */
890    turn = 0,                           /* Line turnaround handshake flag */
891    turnch = XON,                       /* Line turnaround character */
892    duplex = 0,                         /* Duplex, full by default */
893    escape = DFESC,                     /* Escape character for connect */
894    delay = DDELAY,                     /* Initial delay before sending */
895    tnlm = 0,                           /* Terminal newline mode */
896    mdmtyp = 0;                         /* Modem type (initially none)  */
897
898/* Networks for SET HOST */
899
900#define MYHOSTL 100
901    char myhost[MYHOSTL];               /* Local host name */
902    int network = 0;                    /* Network vs serial connection */
903
904#ifdef NETCONN
905#ifdef TCPSOCKET
906    int nettype = NET_TCPB;             /* Assume TCP/IP (BSD sockets) */
907#else
908#ifdef SUNX25
909    int nettype = NET_SX25;
910#else
911#ifdef STRATUSX25
912    int nettype = NET_VX25;
913#else
914#ifdef DECNET
915    int nettype = NET_DEC;
916#else
917#ifdef SUPERLAT
918    int nettype = NET_SLAT;
919#else
920    int nettype = NET_NONE;
921#endif /* SUPERLAT */
922#endif /* DECNET */
923#endif /* STRATUSX25 */
924#endif /* SUNX25 */
925#endif /* TCPSOCKET */
926#else
927    int nettype = NET_NONE;
928#endif /* NETCONN */
929
930#ifdef ANYX25
931    int revcall = 0;            /* X.25 reverse call not selected */
932    int closgr  = -1;           /* X.25 closed user group not selected */
933    int cudata = 0;             /* X.25 call user data not specified */
934    char udata[MAXCUDATA];      /* X.25 call user data */
935    CHAR padparms[MAXPADPARMS+1]; /* X.3 parameters */
936#endif /* ANYX25 */
937
938/* Other items */
939
940int isinterrupted = 0;                  /* Used in exception handling */
941extern int what;
942
943#ifdef NT
944extern int StartedFromDialer;
945#ifdef NTSIG
946extern int TlsIndex;
947#endif /* NTSIG */
948#ifdef NTASM
949unsigned long ESPToRestore ;            /* Ditto */
950#endif /* NTASM */
951#endif /* NT */
952
953#ifdef OS2PM
954int os2pm = 0;                          /* OS/2 Presentation Manager flag */
955#endif /* OS2PM */
956
957/* Terminal screen size, if known, -1 means unknown. */
958#ifdef OS2
959#include "ckocon.h"
960int tt_rows[VNUM] = {25,24,25,1};               /* Rows (height) */
961int tt_cols[VNUM] = {80,80,80,80};              /* Columns (width) */
962#else /* OS2 */
963int tt_rows = -1;                       /* Rows (height) */
964int tt_cols = -1;                       /* Columns (width) */
965#endif /* OS2 */
966int tt_escape = 1;                      /* Escaping back is enabled */
967
968#ifdef NETCONN
969extern int ttyfd, tn_exit;
970#endif /* NETCONN */
971    int exitonclose = 0;                /* Exit on close */
972
973    int tlevel = -1;                    /* Take-file command level */
974#ifdef NOLOCAL
975    int remonly = 1;                    /* Remote-mode-only advisory (-R) */
976#else
977    int remonly = 0;
978#endif /* NOLOCAL */
979
980#ifndef NOSPL
981    extern int cmdlvl;                  /* Command level */
982    extern int maclvl;                  /* Macro invocation level */
983#endif /* NOSPL */
984
985    int protocol  = PROTO_K;            /* File transfer protocol = Kermit */
986#ifdef NEWDEFAULTS
987    int prefixing = PX_CAU;
988#else
989    int prefixing = PX_ALL;
990#endif /* NEWDEFAULTS */
991    extern short ctlp[];                /* Control-prefix table */
992
993    int carrier = CAR_AUT;              /* Pay attention to carrier signal */
994    int cdtimo = 0;                     /* Carrier wait timeout */
995    int xitsta = GOOD_EXIT;             /* Program exit status */
996#ifdef VMS                              /* Default filename collision action */
997    int fncact = XYFX_X;                /* REPLACE for VAX/VMS */
998#else
999    int fncact = XYFX_B;                /* BACKUP for everybody else */
1000#endif /* VMS */
1001    int fncsav = -1;                    /* For saving & restoring the above */
1002    int bgset = -1;                     /* BACKGROUND mode set explicitly */
1003#ifdef UNIX
1004    int suspend = DFSUSP;               /* Whether SUSPEND command, etc, */
1005#else                                   /* is to be allowed. */
1006    int suspend = 0;
1007#endif /* UNIX */
1008
1009/* Statistics variables */
1010
1011long filcnt,                    /* Number of files in transaction */
1012    filrej,                     /* Number of files rejected in transaction */
1013    flci,                       /* Characters from line, current file */
1014    flco,                       /* Chars to line, current file  */
1015    tlci,                       /* Chars from line in transaction */
1016    tlco,                       /* Chars to line in transaction */
1017    ffc,                        /* Chars to/from current file */
1018    tfc,                        /* Chars to/from files in transaction */
1019    ccu,                        /* Control chars unprefixed in transaction */
1020    ccp,                        /* Control chars prefixed in transaction */
1021    rptn;                       /* Repeated characters compressed */
1022
1023int tsecs = 0;                  /* Seconds for transaction */
1024int fsecs = 0;                  /* Per-file timer */
1025
1026/* Flags */
1027
1028int deblog = 0,                         /* Flag for debug logging */
1029    debses = 0,                         /* Flag for DEBUG SESSION */
1030    pktlog = 0,                         /* Flag for packet logging */
1031    seslog = 0,                         /* Session logging */
1032    tralog = 0,                         /* Transaction logging */
1033    displa = 0,                         /* File transfer display on/off */
1034    stdouf = 0,                         /* Flag for output to stdout */
1035    stdinf = 0,                         /* Flag for input from stdin */
1036    xflg   = 0,                         /* Flag for X instead of F packet */
1037    hcflg  = 0,                         /* Doing Host command */
1038    dest   = DEST_D,                    /* Destination for packet data */
1039
1040/* If you change this, also see struct ptab above... */
1041
1042#ifdef OS2                              /* Flag for file name conversion */
1043    fncnv  = XYFN_L,                    /* Default is Literal in OS/2, */
1044    f_save = XYFN_L,                    /* (saved copy of same) */
1045#else
1046    fncnv  = XYFN_C,                    /* elsewhere Convert them */
1047    f_save = XYFN_C,                    /* (ditto) */
1048#endif /* OS2 */
1049    fnspath = 1,                        /* Send-file path 1 = strip */
1050    fnrpath = 1,                        /* Receive-file path 1 = strip */
1051
1052#ifdef NEWDEFAULTS
1053    binary = XYFT_B,                    /* Default file transfer mode */
1054    b_save = XYFT_B,                    /* Saved file mode */
1055#else
1056    binary = XYFT_T,                    /* Default file transfer mode */
1057    b_save = XYFT_T,                    /* Saved file mode */
1058#endif /* NEWDEFAULTS */
1059
1060#ifdef OS2
1061    cursor_save = -1,                   /* Cursor state */
1062#endif /* OS2 */
1063
1064    xfermode = XMODE_A,                 /* Transfer mode, manual or auto */
1065    sendmode = SM_SEND,                 /* Which type of SEND operation */
1066    slostart  = 1,                      /* Slow start (grow packet lengths) */
1067    cmask  = 0177,                      /* CONNECT (terminal) byte mask */
1068    fmask  = 0377,                      /* File byte mask */
1069    warn   = 0,                         /* Flag for file warning */
1070    quiet  = 0,                         /* Be quiet during file transfer */
1071    local  = 0,                         /* 1 = local mode, 0 = remote mode */
1072    server = 0,                         /* Flag for being a server */
1073    bye_active = 0,                     /* Flag for BYE command active */
1074    cflg   = 0,                         /* Connect before transaction */
1075    cnflg  = 0,                         /* Connect after transaction */
1076    cxseen = 0,                         /* Flag for cancelling a file */
1077    czseen = 0,                         /* Flag for cancelling file group */
1078    discard = 0,                        /* Flag for file to be discarded */
1079    keep = 1,                           /* Keep incomplete files */
1080    unkcs = 1,                          /* Keep file w/unknown character set */
1081    nakstate = 0,                       /* In a state where we can send NAKs */
1082    dblchar = -1,                       /* Character to double when sending */
1083    moving = 0;                         /* MOVE = send, then delete */
1084
1085long sendstart = 0L;                    /* SEND start position */
1086
1087/* Variables passed from command parser to protocol module */
1088
1089#ifndef NOSPL
1090#ifndef NOICP
1091_PROTOTYP( int parser, (int) );         /* The parser itself */
1092#ifdef CK_APC
1093_PROTOTYP( VOID apconect, (void) );
1094#endif /* CK_APC */
1095#endif /* NOICP */
1096#endif /* NOSPL */
1097char *clcmds = NULL;                    /* Pointer to command-line commands */
1098
1099#ifdef CK_CURSES
1100#ifndef OS2
1101#ifndef COHERENT
1102_PROTOTYP( VOID fxdinit, (void) );
1103#endif /* COHERENT */
1104#endif /* OS2 */
1105#endif /* CK_CURSES */
1106
1107CHAR sstate  = (CHAR) 0;                /* Starting state for automaton */
1108CHAR zstate  = (CHAR) 0;                /* For remembering sstate */
1109char *cmarg  = "";                      /* Pointer to command data */
1110char *cmarg2 = "";                      /* Pointer to 2nd command data */
1111char **cmlist;                          /* Pointer to file list in argv */
1112
1113int autodl =                            /* Autodownload */
1114#ifdef CK_AUTODL
1115#ifdef OS2
1116             1                          /* Enabled by default only in */
1117#else                                   /* terminal-emulating versions, */
1118             0                          /* disabled by default for others */
1119#endif /* OS2 */
1120#else
1121             0                          /* (or if not implemented). */
1122#endif /* CK_AUTODL */
1123              ;
1124
1125int remfile = 0, rempipe = 0, remappd = 0; /* REMOTE output redirection */
1126char * remdest = NULL;
1127char * printfile = NULL;                /* NULL if printer not redirected */
1128int printpipe = 0;                      /* For SET PRINTER */
1129
1130/*
1131  Server services:
1132   0 = disabled
1133   1 = enabled in local mode
1134   2 = enabled in remote mode
1135   3 = enabled in both local and remote modes
1136  only as initial (default) values.
1137*/
1138int en_cwd = 3;                         /* CD/CWD */
1139int en_cpy = 3;                         /* COPY   */
1140int en_del = 2;                         /* DELETE */
1141int en_dir = 3;                         /* DIRECTORY */
1142int en_fin = 3;                         /* FINISH */
1143int en_get = 3;                         /* GET */
1144int nopush = 0;                         /* PUSH enabled */
1145#ifndef NOPUSH
1146int en_hos = 2;                         /* HOST enabled */
1147#else
1148int en_hos = 0;                         /* HOST disabled */
1149#endif /* NOPUSH */
1150int en_ren = 3;                         /* RENAME */
1151int en_sen = 3;                         /* SEND */
1152int en_set = 3;                         /* SET */
1153int en_spa = 3;                         /* SPACE */
1154int en_typ = 3;                         /* TYPE */
1155int en_who = 3;                         /* WHO */
1156#ifdef datageneral
1157/* Data General AOS/VS can't do this */
1158int en_bye = 0;                         /* BYE */
1159#else
1160int en_bye = 2;                         /* PCs in local mode... */
1161#endif /* datageneral */
1162int en_asg = 3;                         /* ASSIGN */
1163int en_que = 3;                         /* QUERY */
1164int en_ret = 2;                         /* RETRIEVE */
1165int en_mai = 3;                         /* MAIL */
1166int en_pri = 3;                         /* PRINT */
1167
1168/* Miscellaneous */
1169
1170char **xargv;                           /* Global copies of argv */
1171int  xargc;                             /* and argc  */
1172int xargs;                              /* an immutable copy of argc */
1173char *xarg0;                            /* and of argv[0] */
1174char *pipedata;                         /* Pointer to -P (pipe) data */
1175
1176extern char *dftty;                     /* Default tty name from ck?tio.c */
1177extern int dfloc;                       /* Default location: remote/local */
1178extern int dfprty;                      /* Default parity */
1179extern int dfflow;                      /* Default flow control */
1180
1181/*
1182  Buffered file input and output buffers.  See getpkt() in ckcfns.c
1183  and zoutdump() in the system-dependent file i/o module (usually ck?fio.c).
1184*/
1185#ifndef DYNAMIC
1186/* Now we allocate them dynamically, see getiobs() below. */
1187char zinbuffer[INBUFSIZE], zoutbuffer[OBUFSIZE];
1188#endif /* DYNAMIC */
1189char *zinptr, *zoutptr;
1190int zincnt, zoutcnt;
1191
1192_PROTOTYP( int getiobs, (VOID) );
1193
1194/*  M A I N  --  C-Kermit main program  */
1195
1196#include <signal.h>
1197
1198#ifndef NOCCTRAP
1199#include <setjmp.h>
1200#include "ckcsig.h"
1201ckjmpbuf cmjbuf;
1202#ifdef GEMDOS                           /* Special for Atari ST */
1203cc_clean();                             /* This can't be right? */
1204#endif /* GEMDOS */
1205#endif /* NOCCTRAP */
1206
1207/*  C K I N D E X  --  C-Kermit's index function  */
1208/*
1209  We can't depend on C libraries to have one, so here is our own.
1210  Call with:
1211    s1 - String to look for.
1212    s2 - String to look in.
1213     t - Starting position in s2.
1214     r - 0 for left-to-right search, non-0 for right-to-left.
1215  icase  0 for case independence, non-0 if alphabetic case matters.
1216  Returns 0 if string not found, otherwise a 1-based result.
1217*/
1218int
1219ckindex(s1,s2,t,r,icase) char *s1, *s2; int t, r, icase; {
1220    int len1, len2, i, j, x;
1221    char * s;
1222    char * ss1 = NULL;
1223    char * ss2 = NULL;
1224
1225    if (!s1 || !s2) return(0);
1226    len1 = (int)strlen(s1);             /* length of string to look for */
1227    len2 = (int)strlen(s = s2);         /* length of string to look in */
1228
1229    if (len1 < 0) return(0);            /* paranoia */
1230    if (len2 < 0) return(0);
1231    j = len2 - len1;                    /* length difference */
1232    if (j < 0 || t > j) {               /* search string is longer */
1233        return(0);
1234    } else {                            /* Args are OK */
1235        s = s2 + t;                     /* Point to beginning of target */
1236        if (r == 0) {                   /* Index */
1237            for (i = 0; i <= (j - t); i++) { /* Now compare */
1238                x = icase ? strncmp(s1,s++,len1) : xxstrcmp(s1,s++,len1);
1239                if (!x)
1240                  return(i+1+t);
1241            }
1242        } else {                        /* Reverse Index */
1243            for (i = t; i > -1 && s >= s1; i--) { /* Compare */
1244                x = icase ? strncmp(s1,s--,len1) : xxstrcmp(s1,s--,len1);
1245                if (!x)
1246                  return(i+1);
1247            }
1248        }
1249        return(0);
1250    }
1251}
1252
1253/* Tell if a pathname is absolute (vs relative) */
1254/* This should be parceled out to each of the ck*fio.c modules... */
1255int
1256isabsolute(path) char * path; {
1257    int rc = 0;
1258    int x;
1259    if (!path)
1260      return(0);
1261    if (!*path)
1262      return(0);   
1263    x = (int) strlen(path);
1264    debug(F111,"isabsolute",path,x);
1265#ifdef VMS
1266    rc = 0;
1267    if (x = ckindex(":",path,1,0,0))
1268      if (x = ckindex("[",path,x,0,0))
1269        if (x = ckindex("]",path,x,0,0))
1270          rc = 1;
1271#else
1272#ifdef UNIX
1273    if (*path == '/' ||
1274#ifdef DTILDE
1275        *path == '~' ||
1276#endif /* DTILDE */
1277        *path == '.'
1278        )
1279      rc = 1;
1280#else
1281#ifdef OS2
1282    if (*path == '/' || *path == '\\' || *path == '.')
1283      rc = 1;
1284    else if (isalpha(*path) && x > 1)
1285      if (*(path+1) == ':')
1286        rc = 1;
1287#else
1288#ifdef AMIGA
1289    if (*path == '/' ||
1290#ifdef DTILDE
1291        *path == '~' ||
1292#endif /* DTILDE */
1293        *path == '.'
1294        )
1295      rc = 1;
1296#else
1297#ifdef OSK
1298    if (*path == '/' ||
1299#ifdef DTILDE
1300        *path == '~' ||
1301#endif /* DTILDE */
1302        *path == '.'
1303        )
1304      rc = 1;
1305#else
1306#ifdef datageneral
1307    if (*path == ':')
1308      rc = 1;
1309#else
1310#ifdef MAC
1311    rc = 0;                             /* Fill in later... */
1312#else
1313#ifdef STRATUS
1314    rc = 0;                             /* Fill in later... */     
1315#else
1316#ifdef GEMDOS
1317    if (*path == '/' || *path == '\\' || *path == '.')
1318      rc = 1;
1319    else if (isalpha(*path) && x > 1)
1320      if (*(path+1) == ':')
1321        rc = 1;
1322#endif /* GEMDOS */
1323#endif /* STRATUS */
1324#endif /* MAC */
1325#endif /* datageneral */
1326#endif /* OSK */
1327#endif /* AMIGA */
1328#endif /* OS2 */
1329#endif /* UNIX */
1330#endif /* VMS */
1331    debug(F111,"isabsolute returns","",rc);
1332    return(rc);
1333}
1334
1335/*  See if I have direct access to the keyboard  */
1336
1337int
1338is_a_tty(n) int n; {
1339#ifdef KUI
1340   return 1;
1341#else /* KUI */
1342#ifdef NT
1343    if (isWin95())
1344      return(1);
1345    else
1346      return(_isatty(n));
1347#else
1348    return(isatty(n));
1349#endif /* NT */
1350#endif /* KUI */
1351}
1352
1353/* Info associated with a system ID */
1354
1355struct sysdata sysidlist[] = {          /* Add others as needed... */
1356    "0",  "anonymous",    0, NUL,  0, 0, 0,
1357    "A1", "Apple II",     0, NUL,  0, 0, 3, /* fix this */
1358    "A3", "Macintosh",    1, ':',  0, 2, 1,
1359    "D7", "VMS",          0, ']',  1, 0, 0,
1360    "DA", "RSTS/E",       0, ']',  1, 0, 3, /* (i think...) */
1361    "DB", "RT11",         0, NUL,  1, 0, 3, /* (maybe...) */
1362    "F3", "AOS/VS",       1, ':',  0, 0, 2,
1363    "I1", "VM/CMS",       0, NUL,  0, 0, 0,
1364    "I2", "MVS/TSO",      0, NUL,  0, 0, 0,
1365    "I4", "MUSIC",        0, NUL,  0, 0, 0,
1366    "I7", "CICS",         0, NUL,  0, 0, 0,
1367    "I9", "MVS/ROSCOE",   0, NUL,  0, 0, 0,
1368    "K2", "Atari ST",     1, '\\', 1, 0, 3,
1369    "L3", "Amiga",        1, '/',  1, 0, 2,
1370    "MV", "Stratus VOS",  1, '>',  0, 1, 0,
1371    "N3", "Apollo Aegis", 1, '/',  0, 3, 2,
1372    "U1", "UNIX",         1, '/',  0, 3, 2,
1373    "U8", "MS-DOS",       1, '\\', 1, 0, 3,
1374    "UD", "OS-9",         1, '/',  0, 3, 2,
1375    "UN", "Windows-32",   1, '\\', 1, 2, 3,
1376    "UO", "OS/2",         1, '\\', 1, 2, 3
1377};
1378static int nxxsysids = (sizeof(sysidlist) / sizeof(struct sysdata));
1379
1380/* Given a Kermit system ID code, return the associated name string */
1381/* and some properties of the filenames... */
1382
1383char *
1384getsysid(s) char * s; {                 /* Get system-type name */
1385    int i;
1386    if (!s) return("");
1387    for (i = 0; i < nxxsysids; i++)
1388      if (!strcmp(sysidlist[i].sid_code,s))
1389        return(sysidlist[i].sid_name);
1390    return(s);
1391}
1392
1393int
1394getsysix(s) char *s; {                  /* Get system-type index */
1395    int i;
1396    if (!s) return(-1);
1397    for (i = 0; i < nxxsysids; i++)
1398      if (!strcmp(sysidlist[i].sid_code,s))
1399        return(i);
1400    return(-1);
1401}
1402
1403/* Initialize file transfer protocols */
1404
1405VOID
1406initproto(y, upbstr, uptstr, sndbstr, sndtstr, rcvbstr, rcvtstr)
1407    int y;
1408    char * upbstr, * uptstr, * sndbstr, * sndtstr, * rcvbstr, * rcvtstr;
1409/* initproto */ {
1410
1411    char * p;
1412    int n;
1413
1414    if (upbstr)                         /* Convert null strings */
1415      if (!*upbstr)                     /* to null pointers */
1416        upbstr = NULL;
1417
1418    if (uptstr)                         /* Convert null strings */
1419      if (!*uptstr)                     /* to null pointers */
1420        uptstr = NULL;
1421
1422    if (sndbstr)
1423      if (!*sndbstr)
1424        sndbstr = NULL;
1425
1426    if (sndtstr)
1427      if (!*sndtstr)
1428        sndtstr = NULL;
1429
1430    if (rcvbstr)
1431      if (!*rcvbstr)
1432        rcvbstr = NULL;
1433
1434    if (rcvtstr)
1435      if (!*rcvtstr)
1436        rcvtstr = NULL;
1437
1438    protocol = y;                       /* Set protocol */
1439
1440    if (ptab[protocol].rpktlen > -1)
1441      urpsiz = ptab[protocol].rpktlen;
1442    if (ptab[protocol].spktflg > -1)
1443      spsizf = ptab[protocol].spktflg;
1444    if (ptab[protocol].spktlen > -1) {
1445        spsiz = ptab[protocol].spktlen;
1446        if (spsizf)
1447          spsizr = spmax = spsiz;
1448    }
1449    if (ptab[protocol].winsize > -1)
1450      wslotr = ptab[protocol].winsize;
1451    if (ptab[protocol].prefix > -1)
1452      prefixing = ptab[protocol].prefix;
1453    if (ptab[protocol].fnca > -1)
1454      fncact  = ptab[protocol].fnca;
1455    if (ptab[protocol].fncn > -1)
1456      fncnv   = ptab[protocol].fncn;
1457    if (ptab[protocol].fnsp > -1)
1458      fnspath = ptab[protocol].fnsp;
1459    if (ptab[protocol].fnrp > -1)
1460      fnrpath = ptab[protocol].fnrp;
1461   
1462    makestr(&(ptab[protocol].h_b_init),upbstr);
1463    makestr(&(ptab[protocol].h_t_init),uptstr);
1464    makestr(&(ptab[protocol].p_b_scmd),sndbstr);
1465    makestr(&(ptab[protocol].p_t_scmd),sndtstr);
1466    makestr(&(ptab[protocol].p_b_rcmd),rcvbstr);
1467    makestr(&(ptab[protocol].p_t_rcmd),rcvtstr);
1468}
1469
1470/*
1471   M A K E S T R  --  Creates a dynamically allocated string.
1472
1473   Makes a new copy of string s and sets pointer p to its address.
1474   Handles degenerate cases, like when buffers overlap or are the same,
1475   one or both arguments are NULL, etc.
1476*/
1477VOID
1478makestr(p,s) char **p, *s; {
1479    int x;
1480    char *q = NULL;
1481
1482    if (*p == s)                        /* The two pointers are the same. */
1483      return;                           /* Don't do anything. */
1484
1485    if (!s) {                           /* New definition is null? */
1486        if (*p)                         /* Free old storage. */
1487          free(*p);
1488        *p = NULL;                      /* Return null pointer. */
1489        return;
1490    }
1491    if ((x = strlen(s)) >= 0) {         /* Get length, even of empty string. */
1492        q = malloc(x + 1);              /* Get and point to temp storage. */
1493        if (q)
1494          strcpy(q,s);
1495    } else
1496      q = NULL;                         /* Length of string is zero */
1497
1498    if (*p)                             /* Now free the original storage. */
1499      free(*p);
1500    *p = NULL;
1501
1502    if (!q)
1503      return;
1504
1505    if (x > 0) {                        /* Get length. */
1506        if (*p = malloc(x + 1))
1507          strcpy(*p,q);
1508    }
1509    free(q);                            /* Free temporary buffer. */
1510}
1511
1512/*  X X S T R C M P  --  Caseless string comparison  */
1513/*
1514  Call with pointers to the two strings, s1 and s2, and a length, n.
1515  Compares up to n characters of the two strings and returns:
1516    1 if s1 > t1
1517    0 if s1 = s2
1518   -1 if s1 < t1
1519*/
1520int
1521xxstrcmp(s1,s2,n) char *s1, *s2; int n; { /* Caseless string comparison. */
1522    char t1, t2;                       
1523
1524    if (n < 1) return(0);
1525    if (!s1) s1 = "";                   /* Watch out for null pointers. */
1526    if (!s2) s2 = "";
1527    while (n--) {
1528        t1 = *s1++;                     /* Get next character from each. */
1529        t2 = *s2++;
1530        if (!t1) return(t2 ? -1 : 0);
1531        if (!t2) return(t1 ? -1 : 0);
1532        if (isupper(t1)) t1 = tolower(t1);
1533        if (isupper(t2)) t2 = tolower(t2);
1534        if (t1 < t2) return(-1);        /* s1 < s2 */
1535        if (t1 > t2) return(1);         /* s1 > s2 */
1536    }
1537    return(0);                          /* They're equal */
1538}
1539
1540#ifndef NOCMDL
1541VOID
1542#ifdef CK_ANSIC
1543docmdline(void * threadinfo)
1544#else /* CK_ANSIC */
1545docmdline(threadinfo) VOID * threadinfo;
1546#endif /* CK_ANSIC */
1547{
1548#ifdef NTSIG
1549    if (threadinfo) {                   /* Thread local storage... */
1550       TlsSetValue(TlsIndex,threadinfo);
1551       debug( F100, "docmdline called with threadinfo block", "", 0 );
1552    }
1553   else debug( F100, "docmdline threadinfo is NULL","",0) ;
1554#endif /* NTSIG */
1555    proto();                            /* Take any requested action, then */
1556    if (!quiet)                         /* put cursor back at left margin, */
1557      conoll("");
1558#ifndef NOLOCAL
1559    if (cnflg) doconect(0);             /* connect if requested. */
1560#endif /* NOLOCAL */
1561
1562#ifdef NTSIG
1563     ckThreadEnd(threadinfo);
1564#endif /* NTSIG */
1565   return;
1566}
1567
1568VOID
1569#ifdef CK_ANSIC
1570failcmdline(void * foo)
1571#else /* CK_ANSIC */
1572failcmdline(foo) VOID * foo;
1573#endif /* CK_ANSIC */
1574{
1575#ifdef GEMDOS
1576    cc_clean();
1577#endif /* GEMDOS */
1578#ifndef NOLOCAL
1579    if (cnflg) doconect(0);             /* connect again if requested. */
1580#endif /* NOLOCAL */
1581}
1582#endif /* NOCMDL */
1583
1584#ifndef NOICP
1585VOID 
1586#ifdef CK_ANSIC
1587dotakeini(void * threadinfo)            /* Execute init file. */
1588#else  /* CK_ANSIC */
1589dotakeini(threadinfo) VOID * threadinfo; /* Execute init file. */
1590#endif /* CK_ANSIC */
1591/* dotakeini */ {
1592#ifdef NTSIG
1593    if (threadinfo) {                   /* Thread local storage... */
1594       TlsSetValue(TlsIndex,threadinfo);
1595       debug( F100, "dotakeini called with threadinfo block","", 0 ) ;
1596    } else
1597      debug( F100, "dotakeini - threadinfo is NULL", "", 0 ) ;
1598#endif /* NTSIG */
1599    cmdini();                           /* Sets tlevel */
1600    doinit();
1601    debug(F101,"main executing init file","",tlevel);
1602    while (tlevel > -1) {
1603        sstate = (CHAR) parser(1);      /* Execute one command at a time. */
1604        if (sstate) proto();            /* Enter protocol if requested. */
1605#ifdef NTSIG
1606       ck_ih();
1607#endif /* NTSIG */
1608    }
1609    debug(F101,"main exits init file","",tlevel);
1610
1611#ifdef NTSIG
1612     ckThreadEnd(threadinfo);
1613#endif /* NTSIG */
1614    return;
1615}
1616
1617VOID
1618#ifdef CK_ANSIC
1619failtakeini(void * threadinfo)
1620#else /* CK_ANSIC */
1621failtakeini(threadinfo) VOID * threadinfo;
1622#endif /* CK_ANSIC */
1623/* failtakeini */ {
1624#ifdef GEMDOS
1625    cc_clean();                         /* Atari: Clean up after ^C-trap. */
1626#endif /* GEMDOS */
1627    conoll("Interrupt during initialization or command-line processing.");
1628    conoll("C-Kermit quitting...");
1629    doexit(BAD_EXIT,-1);                /* Exit with bad status. */
1630}
1631
1632VOID
1633#ifdef CK_ANSIC
1634doicp(void * threadinfo)
1635#else /* CK_ANSIC */
1636doicp(threadinfo) VOID * threadinfo;
1637#endif /* CK_ANSIC */
1638/* doicp */ {
1639#ifdef NTSIG
1640    if (threadinfo) {                   /* Thread local storage... */
1641       if (!TlsSetValue(TlsIndex,threadinfo))
1642          debug(F101,"doicp TlsSetValue failed","",GetLastError() ) ;
1643       debug( F101, "doicp a threadinfo block - TlsIndex", "", TlsIndex ) ;
1644    } else {
1645        debug( F100, "doicp received a null threadinfo", "", 0 ) ;
1646    }
1647#endif /* NTSIG */
1648#ifdef MAC
1649    while (1) {
1650        extern char *lfiles;            /* Fake pointer cast */
1651
1652        if (connected) {
1653            debug(F100, "main: calling macparser", "", 0);
1654            sstate = newparser(1, 1, 0L);
1655
1656            /* ignore null command state */
1657            if (sstate == 'n')
1658              sstate = '\0';
1659
1660            if (sstate)
1661              proto();
1662#ifdef NTSIG
1663       ck_ih();
1664#endif /* NTSIG */
1665        } else {
1666            /*
1667             * process take files the finder gave us.
1668             */
1669            if ((tlevel == -1) && lfiles)
1670              startlfile();
1671
1672            debug(F100, "main: calling parser", "", 0);
1673            sstate = (CHAR) parser(0);
1674            if (sstate == 'c')          /* if MAC connect */
1675              sstate = 0;
1676            if (sstate)
1677              proto();
1678#ifdef NTSIG
1679       ck_ih();
1680#endif /* NTSIG */
1681        }
1682    }
1683#else /* Not MAC */
1684
1685#ifndef NOSPL
1686/*
1687  If interactive commands were given on the command line (using the
1688  -C "command, command, ..." option), assign them to a macro called
1689  "cl_commands", then execute the macro and leave it defined for
1690  subsequent re-execution if desired.
1691*/
1692    if (clcmds) {                       /* Check for -C commands */
1693        int x;
1694        x = addmac("cl_commands",clcmds); /* Put macro in table */
1695        if (x > -1) {                   /* If successful, */
1696            dodo(x,NULL,CF_CMDL);       /* set up for macro execution */
1697            while (maclvl > -1) {       /* Loop getting macro commands. */
1698                sstate = (CHAR) parser(1);
1699                if (sstate) proto();    /* Enter protocol if requested. */
1700#ifdef NTSIG
1701                ck_ih();
1702#endif /* NTSIG */
1703            }
1704        }
1705        herald();
1706    }
1707#endif /* NOSPL */
1708/*
1709  Running from an application file, or a command filename was
1710  specified on the command line.
1711*/
1712    debug(F101,"main cfilef","",cfilef);
1713    if (*cmdfil) {
1714        cfilef = 1;                     /* Remember we did this, */
1715        dotake(cmdfil);                 /* Command file spec'd on cmd line */
1716    }
1717    while(1) {                          /* Loop getting commands. */
1718        sstate = (CHAR) parser(0);
1719        if (sstate) proto();            /* Enter protocol if requested. */
1720#ifdef NTSIG
1721       ck_ih();
1722#endif /* NTSIG */
1723    }
1724#ifdef NTSIG
1725     ckThreadEnd(threadinfo);
1726#endif /* NTSIG */
1727   /* return ; */ /* If this routine is void there should be no return */
1728#endif /* MAC */
1729}
1730
1731VOID
1732#ifdef CK_ANSIC
1733failicp(void * threadinfo)
1734#else /* CK_ANSIC */
1735failicp(threadinfo) VOID * threadinfo;
1736#endif /* CK_ANSIC */
1737{
1738#ifdef GEMDOS
1739    cc_clean();
1740#endif /* GEMDOS */
1741    fixcmd();                           /* Pop command stacks, etc. */
1742    clcmds = NULL;
1743    debug(F100,"ckcmai got interrupt","",0);
1744}
1745#endif /* NOICP */
1746
1747#ifndef NOICP
1748VOID 
1749#ifdef CK_ANSIC
1750docmdfile(void * threadinfo)            /* Execute application file */
1751#else /* CK_ANSIC */
1752docmdfile(threadinfo) VOID * threadinfo;
1753#endif /* CK_ANSIC */
1754{
1755#ifdef NTSIG
1756    if (threadinfo) {                   /* Thread local storage... */
1757        TlsSetValue(TlsIndex,threadinfo);
1758        debug( F100, "docmdfile called with threadinfo block","", 0 ) ;
1759    } else debug( F100, "docmdfile - threadinfo is NULL", "", 0 ) ;
1760#endif /* NTSIG */
1761    debug(F110,"main cmdfil",cmdfil,0);
1762    dotake(cmdfil);                     /* execute it */
1763    while (tlevel > -1) {               /* until it runs out. */
1764        sstate = parser(1);             /* Loop getting commands. */
1765        if (sstate) proto();            /* Enter protocol if requested. */
1766#ifdef NTSIG
1767        ck_ih();
1768#endif /* NTSIG */
1769    }
1770    cfilef = 1;                         /* Remember we did this */
1771#ifdef NTSIG
1772    ckThreadEnd(threadinfo);
1773#endif /* NTSIG */
1774    return;
1775}
1776
1777VOID
1778#ifdef CK_ANSIC
1779failcmdfile(void * threadinfo)
1780#else /* CK_ANSIC */
1781failcmdfile(threadinfo) VOID * threadinfo;
1782#endif /* CK_ANSIC */
1783{
1784#ifdef GEMDOS
1785    cc_clean();                         /* Atari: Clean up after ^C-trap. */
1786#endif /* GEMDOS */
1787    conoll("Interrupt during initialization or command-line processing.");
1788    conoll("C-Kermit quitting...");
1789    doexit(BAD_EXIT,-1);                /* Exit with bad status. */
1790}
1791#endif /* NOICP */
1792
1793VOID
1794setprefix(z) int z; {                   /* Initial control-char prefixing */
1795#ifdef CK_SPEED
1796    int i, val;
1797
1798    prefixing = z;
1799    ptab[protocol].prefix = prefixing;
1800   
1801    switch(z) {
1802      case PX_ALL:                      /* All or None */
1803      case PX_NON:
1804        val = (z == PX_ALL) ? 1 : 0;
1805        for (i = 1; i < 32; i++) ctlp[i] = val;
1806        for (i = 127; i < 160; i++) ctlp[i] = val;
1807        ctlp[255] = val;
1808        break;
1809
1810      case PX_CAU:                      /* Cautious or Minimal */
1811      case PX_WIL:
1812        for (i = 1; i < 32; i++) ctlp[i] = 0;
1813        for (i = 127; i < 160; i++) ctlp[i] = 0;
1814        ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit start of packet */
1815        if (seol != 13) ctlp[seol] = ctlp[seol+128] = 1; /* Kermit end */
1816        ctlp[13] = ctlp[141] = 1;       /* In case of TELNET */
1817        ctlp[(unsigned)255] = 1;        /* Ditto */
1818        ctlp[17]  = ctlp[19]  = 1;
1819        ctlp[145] = ctlp[147] = 1;
1820
1821        if (prefixing == PX_CAU) {      /* Cautious - add some more */
1822            ctlp[3]   = ctlp[13]  = ctlp[16]  = 1;
1823            ctlp[28]  = ctlp[29]  = ctlp[30]  = 1;
1824            ctlp[131] = ctlp[141] = ctlp[144] = 1;
1825            ctlp[(unsigned)255] = ctlp[156] = ctlp[157] = ctlp[158] = 1;
1826        }
1827        break;
1828    }
1829#endif /* CK_SPEED */
1830}
1831
1832#ifdef aegis
1833/* On the Apollo, intercept main to insert a cleanup handler */
1834int
1835ckcmai(argc,argv) int argc; char **argv;
1836#else
1837#ifdef MAC                              /* Macintosh */
1838int
1839main (void)
1840#else
1841#ifdef VMSGCC                           /* (Open)VMS with GCC compiler */
1842int
1843main(argc,argv) int argc; char **argv;
1844#else
1845#ifdef __DECC                           /* DEC Alpha with DEC C compiler */
1846#ifdef __ALPHA
1847int
1848main(argc,argv) int argc; char **argv;
1849#else                                   /* DEC C compiler, not Alpha */
1850VOID
1851main(argc,argv) int argc; char **argv;
1852#endif  /* __ALPHA */
1853#else
1854#ifdef STRATUS                          /* Stratus VOS */
1855/* ANSI main returns int, and VOS compiler complains if not so. */
1856int
1857main(argc,argv) int argc; char **argv;
1858#else                                   /* All others */
1859#ifdef NT
1860#ifdef CK_WIN
1861void
1862Main( int argc, char ** argv )
1863#else
1864VOID
1865main(argc,argv) int argc; char **argv;
1866#endif /* CK_TAPI */
1867#else
1868VOID
1869main(argc,argv) int argc; char **argv;
1870#endif /* NT */
1871#endif /* STRATUS */
1872#endif /* __DECC */
1873#endif /* VMSGCC */
1874#endif /* MAC */
1875#endif /* aegis */
1876/* main */ {
1877#ifdef datageneral
1878    short *pfha = 016000000036;         /* Get around LANG_RT problem -- */
1879    *pfha = (short) 0;                  /* No user protection fault handler */
1880#endif /* datageneral */
1881/* Do some initialization */
1882
1883#ifndef MAC
1884    xargc = xargs = argc;               /* Make global copies of argc */
1885    xargv = argv;                       /* ...and argv. */
1886    xarg0 = argv[0];
1887#ifndef NOICP
1888#ifdef NT
1889    setOSVer();
1890#endif /* NT */
1891    prescan(0);                         /* Check for debugging */
1892#endif /* NOICP */
1893#endif /* MAC */
1894
1895    if (sysinit() < 0)                  /* System-dependent initialization. */
1896      fatal("Can't initialize!");
1897#ifdef CK_CURSES
1898#ifndef OS2
1899#ifndef COHERENT
1900    fxdinit();                          /* Init fullscreen package */
1901#endif /* COHERENT */
1902#endif /* OS2 */
1903#endif /* CK_CURSES */
1904
1905#ifdef TCPSOCKET
1906#ifdef CK_SOCKS
1907    SOCKSinit(argv[0]);                 /* Internet relay package... */
1908#endif /* CK_SOCKS */
1909#endif /* TCPSOCKET */
1910
1911#ifdef CK_XYZ                           /*  Initialize protocols...  */
1912
1913#ifdef XYZ_INTERNAL /* XYZMODEM are internal ... */
1914
1915    initproto(PROTO_X, "rx %s","rx %s",          NULL, NULL, NULL, NULL);
1916    initproto(PROTO_Y, "rb","rb",                NULL, NULL, NULL, NULL);
1917    initproto(PROTO_G, "rb","rb",                NULL, NULL, NULL, NULL);
1918    initproto(PROTO_Z, "rz","rz",                NULL, NULL, NULL, NULL);
1919    initproto(PROTO_K, "kermit -ir","kermit -r", NULL, NULL, NULL, NULL);
1920    /* Kermit Must be last */
1921
1922#else /* XYZMODEM are external protocols ... */
1923
1924    /*                  s1      s2       s3       s4          s5       s6   */
1925    initproto(PROTO_X, "rx %s","rx %s", "sx %s", "sx -a %s", "rx %s", "rx %s");
1926    initproto(PROTO_Y, "rb",   "rb",    "sb %s", "sb -a %s", "rb",    "rb"   );
1927    initproto(PROTO_G, "rb",   "rb",    "sb %s", "sb -a %s", "rb",    "rb"   );
1928    initproto(PROTO_Z, "rz",   "rz",    "sz %s", "sz -a %s", "rz",    "rz"   );
1929    initproto(PROTO_K, "kermit -ir", "kermit -r", NULL, NULL, NULL, NULL);
1930    /* Kermit must be last */
1931
1932#endif /* XYZ_INTERNAL */
1933
1934#else  /* No XYZMODEM support */
1935
1936    initproto(PROTO_K, "kermit -ir","kermit -r", NULL, NULL, NULL, NULL);
1937
1938#endif /* CK_XYZ */
1939
1940    connoi();                           /* Console interrupts off */
1941    sstate = 0;                         /* No default start state. */
1942#ifdef DYNAMIC
1943    if (getiobs() < 0)
1944      fatal("Can't allocate i/o buffers!");
1945#endif /* DYNAMIC */
1946    ckhost(myhost,MYHOSTL);             /* Name of local host */
1947    strcpy(ttname,dftty);               /* Set up default tty name. */
1948    local = dfloc;                      /* And whether it's local or remote. */
1949    parity = dfprty;                    /* Set initial parity, */
1950    flow = dfflow;                      /* and flow control. */
1951    myindex = getsysix(cksysid);
1952    if (local) if (ttopen(ttname,&local,0,0) < 0) { /* If default tty line */
1953#ifndef OS2
1954        conol("Can't open device: ");
1955        conoll(ttname);
1956#endif /* OS2 */
1957        local = 0;
1958        strcpy(ttname,CTTNAM);
1959    }
1960    speed = ttgspd();                   /* Get transmission speed. */
1961
1962#ifdef ANYX25
1963    initpad();                          /* Initialize X.25 PAD */
1964#endif /* ANYX25 */
1965
1966    if (inibufs(SBSIZ,RBSIZ) < 0)       /* Allocate packet buffers */
1967      fatal("Can't allocate packet buffers!");
1968#ifndef NOCKSPEED
1969    setprefix(prefixing);               /* Set up control char prefixing */
1970#endif /* NOCKSPEED */
1971
1972#ifndef NOICP
1973#ifdef MAC
1974    cmdini();
1975#else /* Not MAC */
1976
1977/* Attempt to take ini file before doing command line */
1978
1979    *cmdfil = '\0';                     /* Assume no command file. */
1980    prescan(1);                         /* But first check for -y option */
1981    debug(F101,"main argc after prescan()","",argc);
1982
1983/* Now process any relevant environment variables */
1984
1985#ifndef NODIAL
1986    getdialenv();                       /* Dialing */
1987#ifdef NETCONN
1988    ndinit();                           /* Initialize network directory info */
1989    getnetenv();                        /* Network directories */
1990#endif /* NETCONN */
1991#endif /* NODIAL */
1992
1993#ifdef NOCCTRAP
1994    dotakeini(0);
1995#else /* NOCCTRAP */
1996    setint();
1997    cc_execute( ckjaddr(cmjbuf), dotakeini, failtakeini );
1998#endif /* NOCCTRAP */
1999    debug(F101,"main 2 cfilef","",cfilef);
2000    if (*cmdfil) {                      /* If we got one (see prescan())... */
2001#ifdef NOCCTRAP
2002        docmdfile(0);                   /* execute it. */
2003#else /* NOCCTRAP */
2004        setint();
2005        cc_execute( ckjaddr(cmjbuf), docmdfile, failcmdfile );
2006#endif /* NOCCTRAP */
2007    }
2008    *cmdfil = '\0';                     /* Done, nullify the file name */
2009#endif /* MAC */
2010#endif /* NOICP */
2011
2012#ifndef NOCMDL
2013/* Look for a UNIX-style command line... */
2014
2015    what = W_NOTHING;
2016    debug(F101,"main argc","",argc);
2017    if (argc > 1) {                     /* Command line arguments? */
2018        sstate = (CHAR) cmdlin();       /* Yes, parse. */
2019        zstate = sstate;                /* Remember sstate around protocol */
2020
2021#ifndef NOLOCAL
2022        if (cflg)                       /* Connect first if requested */
2023          doconect(0);
2024#endif /* NOLOCAL */
2025
2026        if (sstate) {
2027#ifndef NOLOCAL
2028            if (displa) concb((char)escape); /* (for console "interrupts") */
2029#endif /* NOLOCAL */
2030
2031#ifdef NOCCTRAP
2032            docmdline(1);
2033#else /* NOCCTRAP */
2034            setint();
2035            cc_execute( ckjaddr(cmjbuf), docmdline, failcmdline );
2036#endif /* NOCCTRAP */
2037        }
2038
2039#ifndef NOICP
2040/*
2041  If a command-line action argument was given and -S ("stay") was not given,
2042  exit now.
2043*/
2044        if ((cflg || cnflg || zstate) && !stayflg)
2045#endif /* NOICP */
2046          doexit(GOOD_EXIT,xitsta);     /* Exit with good status */
2047#ifndef NOICP
2048#ifdef NETCONN
2049        if ((cflg || cnflg) && tn_exit && ttyfd == -1)
2050          doexit(GOOD_EXIT,xitsta);     /* Exit with good status */
2051#endif /* NETCONN */
2052#endif /* NOICP */
2053    }
2054#endif /* NOCMDL */
2055
2056#ifdef NOICP                            /* No interactive command parser */
2057    else {
2058#ifndef NOCMDL
2059        /* Command-line-only version */
2060        fatal("no command-line options given, type 'kermit -h' for help");
2061#else                                   /* Neither one! */
2062        sstate = 'x';
2063        proto();                        /* So go into server mode */
2064        doexit(GOOD_EXIT,xitsta);       /* exit with good status */
2065#endif /* NOCMDL */
2066    }
2067#else /* not NOICP */
2068/*
2069  If no action requested on command line, or if -S ("stay") was included,
2070  enter the interactive command parser.
2071*/
2072    if (!clcmds)
2073      herald();                         /* Display program herald. */
2074
2075#ifdef NOCCTRAP
2076    debug(F100,"ckcmai setting interrupt trap","",0);
2077    setint();                           /* Set up command interrupt traps */
2078    doicp(NULL);
2079#else /* NOCCTRAP */
2080    while (1) {
2081        debug(F100,"ckcmai setting interrupt trap","",0);
2082        setint();                       /* Set up command interrupt traps */
2083        if (!cc_execute(ckjaddr(cmjbuf), doicp, failicp))
2084          break;
2085    }
2086#endif /* NOCCTRAP */
2087#endif /* NOICP */
2088#ifdef MAC
2089    return(1);
2090#endif /* MAC */
2091}
2092
2093#ifdef DYNAMIC
2094/* Allocate file i/o buffers */
2095
2096char *zinbuffer, *zoutbuffer;
2097
2098int
2099getiobs() {
2100    zinbuffer = (char *)malloc(INBUFSIZE);
2101    if (!zinbuffer) return(-1);
2102    zoutbuffer = (char *)malloc(OBUFSIZE);
2103    if (!zoutbuffer) return(-1);
2104    debug(F100,"getiobs ok","",0);
2105    return(0);
2106}
2107#endif /* DYNAMIC */
Note: See TracBrowser for help on using the repository browser.