-
Notifications
You must be signed in to change notification settings - Fork 3
/
ckuusr.c
2181 lines (1898 loc) · 47.8 KB
/
ckuusr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef NOICP
char *userv = " JSYS UI, 4G(128)";
#endif /* ifndef NOICP */
/* C K U U S R -- "User Interface" (Part 1) */
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) 2021, 2022, 2023 Jeffrey H. Johnson <[email protected]>
*
* Copyright (c) 1981-2011,
* Trustees of Columbia University in the City of New York.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of Columbia University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* The ckuusr module contains the terminal input and output functions
* for UNIX Kermit. It includes a simple UNIX-style command line
* parser as well as an interactive prompting keyword command parser.
* It depends on the existence of UNIX facilities like fopen, fgets,
* feof, (f)printf, argv/argc, etc. Other functions that are likely
* to vary among UNIX implementations -- like setting terminal modes
* or interrupts -- are invoked via calls to functions that are defined
* in the system-dependent modules, ck?[ft]io.c.
*
* The command line parser processes any arguments found on the command
* line, as passed to main() via argv/argc. The interactive parser uses
* the facilities of the cmd package (developed for this program, but
* usable by any program).
*
* Any command parser may be substituted for this one. The only
* requirements for the Kermit command parser are these:
*
* 1. Set parameters via global variables like duplex, speed, ttname, etc.
* See ckmain.c for the declarations and descriptions of these variables.
*
* 2. If a command can be executed without the use of Kermit protocol, then
* execute the command directly and set the variable sstate to 0. Examples
* include 'set' commands, local directory listings, the 'connect' command.
*
* 3. If a command requires the Kermit protocol, set the following
* variables:
*
* sstate string data
* 'x' (enter server mode) (none)
* 'r' (send a 'get' command) cmarg, cmarg2
* 'v' (enter receive mode) cmarg2
* 'g' (send a generic command) cmarg
* 's' (send files) nfils, cmarg & cmarg2 OR cmlist
* 'c' (send a remote host command) cmarg
*
* cmlist is an array of pointers to strings.
* cmarg, cmarg2 are pointers to strings.
* nfils is an integer.
*
* cmarg can be a filename string (possibly wild), or
* a pointer to a prefabricated generic command string, or
* a pointer to a host command string.
* cmarg2 is the name to send a single file under, or
* the name under which to store an incoming file; must not be wild.
* cmlist is a list of nonwild filenames, such as passed via argv.
* nfils is an integer, interpreted as follows:
* -1: argument string is in cmarg, and should be expanded internally.
* 0: stdin.
* >0: number of files to send, from cmlist.
*
* The screen() function is used to update the screen during file transfer.
* The tlog() function maintains a transaction log.
* The debug() function maintains a debugging log.
* The intmsg() and chkint() functions provide the
* user i/o for interrupting file transfers.
*/
#include "ckcdeb.h"
#include <ctype.h>
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#include "ckcker.h"
#include "ckucmd.h"
#include "ckuusr.h"
#ifdef __linux__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#endif /* ifdef __linux__ */
#ifndef NOSERVER
extern int server;
#endif /* ifndef NOSERVER */
extern int size, rpsiz, urpsiz, speed, local, binary;
#ifndef NOICP
extern int displa;
#endif /* ifndef NOICP */
extern int parity, deblog, escape, xargc, flow, turn, duplex, nfils;
extern int ckxech, pktlog, seslog, tralog, stdouf, turnch, dfloc, keep;
extern int maxrps, warn, quiet, cnflg, tlevel, mdmtyp, zincnt;
extern char *versio;
#ifdef WART
extern char *protv;
#endif /* ifdef WART */
extern char *ckxv, *ckzv, *fnsv, *dftty, *cmdv;
#ifndef NOICP
extern char *connv;
#endif /* ifndef NOICP */
extern char *wartv;
#ifndef NOCKUDIA
extern char *dialv;
#endif /* ifndef NOCKUDIA */
#ifndef NOCKUSCR
extern char *loginv;
#endif /* ifndef NOCKUSCR */
extern char *ckxsys, *cmarg, *cmarg2;
extern char **xargv, **cmlist;
extern char *DIRCMD, *PWDCMD, cmerrp[];
extern CHAR sstate, ttname[];
extern CHAR *zinptr;
char *strcpy(), *getenv();
extern char cmdbuf[]; /* Command buffer */
#ifndef NOSPACE
extern char *SPACMD, *zhome(); /* Space command, home directory. */
#endif /* ifndef NOSPACE */
extern int backgrd; /* Kermit executing in background */
/*
* The background flag is set by ckutio.c
* ( via conint() ) to note whether
* this kermit is executing in background
* ( '&' on shell command line ).
*/
#ifndef NOICP
char line[CMDBL + 10], *lp; /* Character buffer for anything */
#endif /* ifndef NOICP */
#ifndef NOLOGS
char debfil[30]; /* Debugging log file name */
char pktfil[30]; /* Packet log file name */
char sesfil[30]; /* Session log file name */
char trafil[30]; /* Transaction log file name */
#endif /* ifndef NOLOGS */
int cflg; /* Command-line connect cmd given */
int action; /* Action selected on command line*/
#ifndef NOICP
int repars; /* Reparse needed */
int cwdf = 0; /* CWD has been done */
#define MAXTAKE 3 /* Maximum nesting of TAKE files */
FILE *tfile[MAXTAKE]; /* File pointers for TAKE command */
char *homdir; /* Pointer to home directory string */
#endif /* ifndef NOICP */
#ifndef MINBUF
char cmdstr[100]; /* Place to build generic command */
#else /* ifndef MINBUF */
char cmdstr[48];
#endif /* ifndef MINBUF */
/* C M D L I N -- Get arguments from command line */
/*
* Simple UNIX-style command line parser, conforming with
* 'A Proposed Command Syntax Standard for UNIX Systems',
* Hemenway & Armitage, UNIX/World, Vol.1, No.3, 1984.
*/
int
cmdlin()
{
char x; /* Local general-purpose int */
cmarg = ""; /* Initialize globals */
cmarg2 = "";
action = cflg = 0;
while (--xargc > 0) /* Go through command line words */
{
xargv++;
debug(F111, "xargv", *xargv, xargc);
if (**xargv == '-') /* Got an option (begins with dash) */
{
x = *( *xargv + 1 ); /* Get the option letter */
if (doarg(x) < 0)
{
doexit(BAD_EXIT); /* Go handle the option */
}
}
else /* No dash where expected */
{
usage();
doexit(BAD_EXIT);
}
}
debug(F101, "action", "", action);
if (!local)
{
if (
( action == 'g' ) || ( action == 'r' ) || ( action == 'c' ) ||
( cflg != 0 ))
{
fatal("-l and -b required");
}
}
if (*cmarg2 != 0)
{
if (( action != 's' ) && ( action != 'r' ) && ( action != 'v' ))
{
fatal("-a without -s, -r, or -g");
}
}
if (( action == 'v' ) && ( stdouf ) && ( !local ))
{
if (isatty(1))
{
fatal("unredirected -k only for local mode");
}
}
if (( action == 's' ) || ( action == 'v' ) || ( action == 'r' ) ||
( action == 'x' ))
{
if (local)
{
#ifndef NOICP
displa = 1;
#endif /* ifndef NOICP */
}
if (stdouf)
{
#ifndef NOICP
displa = 0;
quiet = 1;
#endif /* ifndef NOICP */
}
}
if (quiet)
{
#ifndef NOICP
displa = 0; /* No display if quiet requested */
#endif /* ifndef NOICP */
}
if (cflg)
{
#ifndef NOCONN
conect(); /* Connect if requested */
#endif /* ifndef NOCONN */
if (action == 0)
{
if (cnflg)
{
#ifndef NOCONN
conect(); /* And again if requested */
#endif /* if def NOCON */
}
doexit(GOOD_EXIT); /* Then exit indicating success */
}
}
#ifndef NOICP
if (displa)
{
concb(escape); /* (for console "interrupts") */
}
#endif /* ifndef NOICP */
return ( action ); /* Then do any requested protocol */
}
/* D O A R G -- Do a command-line argument */
int
doarg(x)
char x;
{
int z;
char *xp;
xp = *xargv + 1; /* Pointer for bundled args */
while (x)
{
switch (x)
{
#ifndef NOSERVER
case 'x': /* server */
if (action)
{
fatal("bad request");
}
action = 'x';
break;
#endif
case 'f':
if (action)
{
fatal("bad request");
}
action = setgen('F', "", "", "");
break;
case 'r': /* receive */
if (action)
{
fatal("bad request");
}
action = 'v';
break;
case 'k': /* receive to stdout */
if (action)
{
fatal("bad request");
}
stdouf = 1;
action = 'v';
break;
case 's': /* send */
if (action)
{
fatal("bad request");
}
if (*( xp + 1 ))
{
fatal("invalid arg");
}
z = nfils = 0; /* Initialize file counter, flag */
cmlist = xargv + 1; /* Remember this pointer */
while (--xargc > 0) /* Traverse the list */
{
xargv++;
if (**xargv == '-') /* Check for sending stdin */
{
if (strcmp(*xargv, "-") != 0)
{
break;
}
z++;
}
nfils++; /* Bump file counter */
}
xargc++, xargv--; /* Adjust argv/argc */
if (nfils < 1)
{
fatal("missing filename");
}
if (z > 1)
{
fatal("-s: too many -'s");
}
if (z == 1)
{
if (nfils == 1)
{
nfils = 0;
}
else
{
fatal("invalid mix of filenames and '-' in -s");
}
}
if (nfils == 0)
{
if (isatty(0))
{
fatal("terminal input not allowed");
}
}
debug(F101, *xargv, "", nfils);
action = 's';
break;
case 'g': /* get */
if (action)
{
fatal("bad request");
}
if (*( xp + 1 ))
{
fatal("invalid arg");
}
xargv++, xargc--;
if (( xargc == 0 ) || ( **xargv == '-' ))
{
fatal("missing filename");
}
cmarg = *xargv;
action = 'r';
break;
#ifndef NOCONN
case 'c': /* connect before */
cflg = 1;
break;
case 'n': /* connect after */
cnflg = 1;
break;
#endif /* ifndef NOCONN */
#ifndef NODOHLP
case 'h': /* help */
usage();
doexit(GOOD_EXIT);
#endif /* ifndef NODOHLP */
case 'a': /* "as" */
if (*( xp + 1 ))
{
fatal("invalid arg");
}
xargv++, xargc--;
if (( xargc < 1 ) || ( **xargv == '-' ))
{
fatal("missing name");
}
cmarg2 = *xargv;
break;
case 'l': /* set line */
if (*( xp + 1 ))
{
fatal("invalid arg");
}
xargv++, xargc--;
if (( xargc < 1 ) || ( **xargv == '-' ))
{
fatal("missing name");
}
strcpy(ttname, *xargv);
/* if (strcmp(ttname,dftty) == 0) local = dfloc; else local = 1; */
local = ( strcmp(ttname, CTTNAM) != 0 ); /* (better than old way) */
debug(F101, "local", "", local);
ttopen(ttname, &local, 0);
break;
case 'b': /* set baud */
if (*( xp + 1 ))
{
fatal("invalid arg");
}
xargv++, xargc--;
if (( xargc < 1 ) || ( **xargv == '-' ))
{
fatal("missing baud");
}
z = atoi(*xargv); /* Convert to number */
if (chkspd(z) > -1)
{
speed = z; /* Check it */
}
else
{
fatal("unsupported baud");
}
break;
case 'e': /* Extended packet length */
if (*( xp + 1 ))
{
fatal("invalid arg");
}
xargv++, xargc--;
if (( xargc < 1 ) || ( **xargv == '-' ))
{
fatal("missing length");
}
z = atoi(*xargv); /* Convert to number */
if (z > 10 && z < maxrps)
{
rpsiz = urpsiz = z;
if (z > 94)
{
rpsiz = 94; /* Fallback if other Kermit can't */
}
}
else
{
fatal("Unsupported length");
}
break;
case 'i': /* Treat files as text */
binary = 0;
break;
case 'w': /* File overwrite */
warn = 0;
break;
case 'q': /* Quiet */
quiet = 1;
break;
case 'd': /* debug */
#ifndef NOLOGS
#ifdef DEBUG
debopn("debug.log");
#endif /* ifdef DEBUG */
#endif /* ifndef NOLOGS */
break;
case 'p': /* set parity */
if (*( xp + 1 ))
{
fatal("invalid arg");
}
xargv++, xargc--;
if (( xargc < 1 ) || ( **xargv == '-' ))
{
fatal("missing parity");
}
switch (x = **xargv)
{
case 'e':
case 'o':
case 'm':
case 's':
parity = x;
break;
case 'n':
parity = 0;
break;
default:
fatal("invalid parity");
}
break;
case 't':
turn = 1; /* Line turnaround handshake */
turnch = XON; /* XON is turnaround character */
duplex = 1; /* Half duplex */
flow = 0; /* No flow control */
break;
default:
#ifndef NODOHLP
fatal("invalid arg, try '-h' for help");
#else
fatal("invalid argument");
#endif /* ifndef NODOHLP */
}
x = *++xp; /* See if options are bundled */
}
return ( 0 );
}
/*
* Misc
*/
int
fatal(msg)
char *msg;
{
/* Fatal error message */
fprintf(stderr, "\rFatal: %s\r\n", msg);
#ifndef NOLOGS
#ifdef TLOG
tlog(F110, "Fatal:", msg, 0l);
#endif /* ifdef TLOG */
#endif /* ifndef NOLOGS */
doexit(BAD_EXIT); /* Exit indicating failure */
return ( BAD_EXIT );
}
int
ermsg(msg)
char *msg;
{
/* Print error message */
if (!quiet)
{
fprintf(stderr, "\r\n%s - %s\n",
#ifndef NOICP
cmerrp,
#else /* ifndef NOICP */
"",
#endif /* ifndef NOICP */
msg);
}
#ifndef NOLOGS
#ifdef TLOG
tlog(F110, "Error -", msg, 0l);
#endif /* ifdef TLOG */
#endif /* ifndef NOLOGS */
return ( 0 );
}
/*
* Interactive command
* parser
*/
/*
* Top-Level Keyword
* Table
*/
#ifndef NOICP
struct keytab cmdtab[] = {
#ifndef NOPUSH
{ "!", XXSHE, 0, },
#endif /* ifndef NOPUSH */
{ "%", XXCOM, CM_INV, },
{ "bye", XXBYE, 0, },
#ifndef NOCONN
{ "c", XXCON, CM_INV, },
#endif /* ifndef NOCONN */
{ "cd", XXCWD, 0, },
{ "close", XXCLO, 0, },
#ifndef NOCONN
{ "connect", XXCON, 0, },
#endif /* ifndef NOCONN */
{ "cwd", XXCWD, 0, },
#ifndef NOCKUDIA
{ "dial", XXDIAL, 0, },
#endif /* ifndef NOCKUDIA */
{ "directory", XXDIR, 0, },
{ "echo", XXECH, 0, },
{ "exit", XXEXI, 0, },
{ "finish", XXFIN, 0, },
{ "get", XXGET, 0, },
#ifndef NOCKUDIA
{ "hangup", XXHAN, 0, },
#endif /* ifndef NOCKUDIA */
#ifndef NODOHLP
{ "help", XXHLP, 0, },
#endif /* ifndef NODOHLP */
#ifndef NOLOGS
{ "log", XXLOG, 0, },
#endif /* ifndef NOLOGS */
{ "quit", XXQUI, 0, },
/* "r", XXREC, CM_INV, */
{ "receive", XXREC, 0, },
{ "remote", XXREM, 0, },
/* "s", XXSEN, CM_INV, */
#ifndef NOCKUSCR
{ "script", XXLOGI, 0, },
#endif /* ifndef NOCKUSCR */
{ "send", XXSEN, 0, },
#ifndef NOSERVER
{ "server", XXSER, 0, },
#endif /* ifndef NOSERVER */
{ "set", XXSET, 0, },
{ "show", XXSHO, 0, },
#ifndef NOSPACE
{ "space", XXSPA, 0, },
#endif /* ifndef NOSPACE */
#ifndef NOSTATS
{ "statistics", XXSTA, 0, },
#endif /* ifndef NOSTATS */
{ "take", XXTAK, 0, },
{ "transmit", XXTRA, 0 }
};
int ncmd = ( sizeof ( cmdtab ) / sizeof ( struct keytab ));
/*
* Parameter keyword
* table
*/
struct keytab prmtab[] = {
{ "attributes", XYATTR, 0, },
{ "baud", XYSPEE, CM_INV, },
{ "block-check", XYCHKT, 0, },
{ "delay", XYDELA, 0, },
{ "duplex", XYDUPL, 0, },
#ifdef COMMENT
{ "end-of-packet", XYEOL, CM_INV, }, /* moved to send/receive */
#endif /* ifdef COMMENT */
{ "escape-character", XYESC, 0, },
{ "file", XYFILE, 0, },
{ "flow-control", XYFLOW, 0, },
{ "handshake", XYHAND, 0, },
{ "incomplete", XYIFD, 0, },
{ "line", XYLINE, 0, },
#ifndef NOCKUDIA
{ "modem-dialer", XYMODM, 0, },
#endif /* ifndef NOCKUDIA */
#ifdef COMMENT
{ "packet-length", XYLEN, CM_INV, }, /* moved to send/receive */
{ "pad-character", XYPADC, CM_INV, }, /* moved to send/receive */
{ "padding", XYNPAD, CM_INV, }, /* moved to send/receive */
#endif /* ifdef COMMENT */
{ "parity", XYPARI, 0, },
{ "prompt", XYPROM, 0, },
{ "receive", XYRECV, 0, },
{ "retry", XYRETR, 0, },
{ "send", XYSEND, 0, },
#ifndef NOSERVER
{ "server", XYSERV, 0, },
#endif /* ifndef NOSERVER */
{ "speed", XYSPEE, 0, },
#ifdef COMMENT
{ "start-of-packet", XYMARK, CM_INV, }, /* moved to send/receive */
#endif /* ifndef COMMENT */
{ "terminal", XYTERM, 0 }
/* "timeout", XYTIMO, CM_INV */ /* moved to send/receive */
};
int nprm = \
( sizeof ( prmtab ) / sizeof ( struct keytab )); /* How many parameters */
/*
* Remote Command
* Table
*/
struct keytab remcmd[] = {
{ "cd", XZCWD, CM_INV, },
{ "cwd", XZCWD, 0, },
{ "delete", XZDEL, 0, },
{ "directory", XZDIR, 0, },
{ "help", XZHLP, 0, },
{ "host", XZHOS, 0, },
{ "space", XZSPA, 0, },
{ "type", XZTYP, 0, },
{ "who", XZWHO, 0 }
};
int nrmt = ( sizeof ( remcmd ) / sizeof ( struct keytab ));
#ifndef NOLOGS
struct keytab logtab[] = {
{ "debugging", LOGD, 0, },
{ "packets", LOGP, 0, },
{ "session", LOGS, 0, },
{ "transactions", LOGT, 0 }
};
#endif /* ifndef NOLOGS */
#ifndef NOLOGS
int nlog = ( sizeof ( logtab ) / sizeof ( struct keytab ));
#endif /* ifndef NOLOGS */
#endif /* ifndef NOICP */
/*
* Show command
* arguments
*/
#define SHPAR 0 /* Parameters */
#define SHVER 1 /* Versions */
#ifndef NOICP
struct keytab shotab[] = {
{ "parameters", SHPAR, 0, },
{ "versions", SHVER, 0 }
};
#endif /* ifndef NOICP */
/* C M D I N I -- Initialize the interactive command parser */
#ifndef NOICP
int
cmdini()
{
tlevel = -1; /* Take file level */
cmsetp("uCKermit>"); /* Set default prompt */
/*
* Look for init file in
* home or current directory.
*/
homdir = zhome();
lp = line;
lp[0] = '\0';
if (homdir)
{
strcpy(lp, homdir);
if (lp[0] == '/')
{
strcat(lp, "/");
}
}
strcat(lp, KERMRC);
if (( tfile[0] = fopen(line, "r")) != NULL)
{
tlevel = 0;
debug(F110, "init file", line, 0);
}
if (homdir && ( tlevel < 0 ))
{
strcpy(lp, KERMRC);
if (( tfile[0] = fopen(line, "r")) != NULL)
{
tlevel = 0;
}
}
congm(); /* Get console tty modes */
return ( 0 );
}
#endif /* ifndef NOICP */
/*
* Display version herald
* and initial prompt
*/
#ifndef NOICP
int
herald()
{
if (!backgrd)
{
printf("%s,%s\n", versio, ckxsys);
#ifndef NODOHLP
printf("Interactive mode. Type '?' for help.\n");
#endif /* ifndef NODOHLP */
}
return ( 0 );
}
#endif /* ifndef NOICP */
/* T R A P -- Terminal interrupt handler */
#ifndef NOICP
int
trap(
#ifdef DEBUG
sig,
code
#endif /* ifdef DEBUG */
)
#ifdef DEBUG
int sig, code;
#endif /* ifdef DEBUG */
{
fprintf(stderr, "\r^C...\n");
#ifdef DEBUG
debug(F101, "trap() caught signal", "", sig);
debug(F101, " code", "", code);
#endif /* ifdef DEBUG */
doexit(GOOD_EXIT); /* Exit indicating success */
return ( 0 );
}
#endif /* ifndef NOICP */
/* S T P T R A P -- Handle SIGTSTP signals */
#ifdef __linux__
void
#endif /* ifdef __linux__ */
stptrap(
#ifdef DEBUG
sig,
code
#endif /* ifdef DEBUG */
)
#ifdef DEBUG
int sig, code;
#endif /* ifdef DEBUG */
{
#ifdef DEBUG
debug(F101, "stptrap() caught signal", "", sig);
debug(F101, " code", "", code);
#endif /* ifdef DEBUG */
conres(); /* Reset the console */
#ifdef SIGTSTP
kill(0, SIGSTOP); /* If job control, suspend the job */
#else /* ifdef SIGTSTP */
doexit(GOOD_EXIT); /* Probably won't happen otherwise */
#endif /* ifdef SIGTSTP */
concb(escape); /* Put console back in Kermit mode */
if (!backgrd)
{
#ifndef NOICP
prompt(); /* Reissue prompt when fg'd */
#endif /* ifndef NOICP */
}
}
/* P A R S E R -- Top-level interactive command parser */
#ifndef NOICP
char
parser()
{
int xx, cbn;
char *cbp;
concb(escape); /* Put console in cbreak mode. */
conint(trap); /* Turn on console terminal interrupts. */
/*
* sstate becomes nonzero when a command has been parsed that requires
* some action from the protocol module. Any non-protocol actions,
* such as local directory listing or terminal emulation, are invoked
* directly from below
*/
if (local && !backgrd)
{
printf("\n"); /* Ensure prompt will be visible */
}
sstate = 0; /* Start with no start state. */
while (sstate == 0) /* Parse cmds until action requested */
{
while (( tlevel > -1 ) && feof(tfile[tlevel])) /* If end of take */
{
fclose(tfile[tlevel--]); /* file, close it. */
cmini(ckxech); /* and clear the cmd buffer. */
if (tlevel < 0) /* Just popped out of cmd files? */
{
conint(trap); /* Check background stuff again. */
return ( 0 ); /* End of init file or whatever. */
}
}
debug(F101, "tlevel", "", tlevel);
if (tlevel > -1) /* If in take file */
{
cbp = cmdbuf; /* Get the next line. */
cbn = CMDBL;
/*
* Loop to get next command line and
* all continuation lines from take
* file.
*/
again:
if (fgets(line, cbn, tfile[tlevel]) == NULL)
{
continue;