-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckuus5.c
12695 lines (11771 loc) · 390 KB
/
ckuus5.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
#include "ckcsym.h"
int xcmdsrc = 0;
#ifdef NOICP
int cmdsrc() { return(0); }
#endif /* NOICP */
/* C K U U S 5 -- "User Interface" for C-Kermit, part 5 */
/*
Authors:
Frank da Cruz <fdc@columbia.edu>,
The Kermit Project, New York City
Jeffrey E Altman <jaltman@secure-endpoints.com>
Secure Endpoints Inc., New York City
Copyright (C) 1985, 2017,
Trustees of Columbia University in the City of New York.
All rights reserved. See the C-Kermit COPYING.TXT file or the
copyright text in the ckcmai.c module for disclaimer and permissions.
*/
/* Includes */
#include "ckcdeb.h"
#include "ckcasc.h"
#include "ckcker.h"
#include "ckuusr.h"
#ifdef DCMDBUF
char *line; /* Character buffer for anything */
char *tmpbuf;
#else
char line[LINBUFSIZ+1];
char tmpbuf[TMPBUFSIZ+1]; /* Temporary buffer */
#endif /* DCMDBUF */
char lasttakeline[TMPBUFSIZ+1]; /* Last TAKE-file line */
#ifndef NOICP
#include "ckcnet.h"
#ifndef NOCSETS
#include "ckcxla.h"
#endif /* NOCSETS */
#ifdef MAC
#include "ckmasm.h"
#endif /* MAC */
#ifdef CK_SSL
#include "ck_ssl.h"
#endif /* CK_SSL */
extern char * ck_cryear; /* (ckcmai.c) Latest C-Kermit copyright year */
#ifdef OS2
#include "ckoetc.h"
#ifndef NT
#define INCL_NOPM
#define INCL_VIO /* Needed for ckocon.h */
#include <os2.h>
#undef COMMENT
#else /* NT */
#include <windows.h>
#define TAPI_CURRENT_VERSION 0x00010004
#include <tapi.h>
#include <mcx.h>
#include "ckntap.h"
#define APIRET ULONG
extern int DialerHandle;
extern int StartedFromDialer;
#endif /* NT */
#include "ckocon.h"
#include "ckokey.h"
#ifdef KUI
#include "ikui.h"
#endif /* KUI */
#ifdef putchar
#undef putchar
#endif /* putchar */
#define putchar(x) conoc(x)
extern int cursor_save ;
extern bool cursorena[] ;
#endif /* OS2 */
/* 2010-03-09 SMS. VAX C V3.1-051 needs <stat.h> for off_t. */
#ifdef VMS
#include <stat.h>
#endif /* def VMS */
/* For formatted screens, "more?" prompting, etc. */
#ifdef FT18
#define isxdigit(c) isdigit(c)
#endif /* FT18 */
#ifdef STRATUS /* Stratus Computer, Inc. VOS */
#ifdef putchar
#undef putchar
#endif /* putchar */
#define putchar(x) conoc(x)
#ifdef getchar
#undef getchar
#endif /* getchar */
#define getchar(x) coninc(0)
#endif /* STRATUS */
/* External variables */
extern int carrier, cdtimo, local, quiet, backgrd, bgset, sosi, xsuspend,
binary, escape, xargs, flow, cmdmsk, duplex, ckxech, seslog, what,
inserver, diractive, tlevel, cwdf, nfuncs, msgflg, remappd, hints, mdmtyp,
zincnt, cmask, rcflag, success, xitsta, pflag, tnlm, tn_nlm, xitwarn,
debses, xaskmore, parity, saveask, wasclosed, whyclosed, cdactive,
rcdactive, keepallchars, cmd_err;
#ifdef LOCUS
extern int locus, autolocus;
#endif /* LOCUS */
#ifndef NOMSEND
extern int addlist;
#endif /* NOMSEND */
#ifdef CK_SPEED
extern int prefixing;
#endif /* CK_SPEED */
extern int g_matchdot;
#ifdef RECURSIVE
extern int recursive;
#endif /* RECURSIVE */
extern int xfiletype;
#ifdef IKSDCONF
extern char * iksdconf;
extern int iksdcf;
#endif /* IKSDCONF */
#ifdef CK_RECALL
extern int on_recall;
#endif /* CK_RECALL */
extern int ngetpath, exitonclose;
extern char * getpath[];
extern CHAR * epktmsg;
extern char * snd_move;
extern char * snd_rename;
extern char * rcv_move;
extern char * rcv_rename;
extern char * g_snd_move;
extern char * g_snd_rename;
extern char * g_rcv_move;
extern char * g_rcv_rename;
extern char * nm[];
#ifdef CK_UTSNAME
extern char unm_mch[];
extern char unm_mod[];
extern char unm_nam[];
extern char unm_rel[];
extern char unm_ver[];
#endif /* CK_UTSNAME */
#ifndef NOPUSH
#ifndef NOFRILLS
extern char editor[];
extern char editfile[];
extern char editopts[];
#ifdef BROWSER
extern char browser[];
extern char browsopts[];
extern char browsurl[];
#endif /* BROWSER */
#endif /* NOFRILLS */
#endif /* NOPUSH */
#ifndef NOFRILLS
#ifndef NORENAME
_PROTOTYP(VOID shorename, (void));
#endif /* NORENAME */
#endif /* NOFRILLS */
#ifndef NOSERVER
extern char * x_user, * x_passwd, * x_acct;
#endif /* NOSERVER */
#ifdef CKLOGDIAL
extern int dialog;
extern char diafil[];
#endif /* CKLOGDIAL */
#ifdef CKROOT
extern int ckrooterr;
#endif /* CKROOT */
#ifndef NOSPL
extern int cfilef, xxdot, vareval;
extern char cmdfil[];
struct localvar * localhead[CMDSTKL];
struct localvar * localtail = NULL;
struct localvar * localnext = NULL;
_PROTOTYP( VOID shosexp, (void) );
_PROTOTYP( static VOID shoinput, (void) );
_PROTOTYP( static char gettok, (void) );
_PROTOTYP( static VOID factor, (void) );
_PROTOTYP( static VOID term, (void) );
_PROTOTYP( static VOID termp, (void) );
_PROTOTYP( static VOID exprp, (void) );
_PROTOTYP( static VOID expr, (void) );
_PROTOTYP( static VOID simple, (void) );
_PROTOTYP( static VOID simpler, (void) );
_PROTOTYP( static VOID simplest, (void) );
_PROTOTYP( static CK_OFF_T xparse, (void) );
#endif /* NOSPL */
#ifndef NOSHOW
_PROTOTYP( int sho_iks, (void) );
#endif /* NOSHOW */
#ifdef MAC
char * ckprompt = "Mac-Kermit>"; /* Default prompt for Macintosh */
char * ikprompt = "IKSD>";
#else /* Not MAC */
#ifdef NOSPL
#ifdef OS2
char * ckprompt = "K-95> "; /* Default prompt for Win32 */
char * ikprompt = "IKSD> ";
#else
char * ckprompt = "C-Kermit>";
char * ikprompt = "IKSD>";
#endif /* NT */
#else /* NOSPL */
#ifdef OS2
/* Default prompt for OS/2 and Win32 */
/* fdc 2013-12-06 - C-Kermit 9.0 and later is just "C-Kermit" */
#ifdef NT
#ifdef COMMENT
char * ckprompt = "[\\freplace(\\flongpath(\\v(dir)),/,\\\\)] K-95> ";
#else
char * ckprompt = "[\\freplace(\\flongpath(\\v(dir)),/,\\\\)] C-Kermit> ";
#endif /* COMMENT */
char * ikprompt = "[\\freplace(\\flongpath(\\v(dir)),/,\\\\)] IKSD> ";
#else /* NT */
#ifdef COMMENT
char * ckprompt = "[\\freplace(\\v(dir),/,\\\\)] K-95> ";
#else
char * ckprompt = "[\\freplace(\\v(dir),/,\\\\)] C-Kermit> ";
#endif /* COMMENT */
char * ikprompt = "[\\freplace(\\v(dir),/,\\\\)] IKSD> ";
#endif /* NT */
#else /* OS2 */
#ifdef VMS
char * ckprompt = "\\v(dir) C-Kermit>"; /* Default prompt VMS */
char * ikprompt = "\\v(dir) IKSD>";
#else
#ifdef UNIX
/* Note: parens, not brackets, because of ISO646 */
/* Collapse long paths using ~ notation if in home directory tree */
char * ckprompt = "(\\freplace(\\v(dir),\\fpathname(\\v(home)),~/)) C-Kermit>";
char * ikprompt = "(\\freplace(\\v(dir),\\fpathname(\\v(home)),~/)) IKSD>";
#else
/* Default prompt for other platforms */
char * ckprompt = "(\\v(dir)) C-Kermit>"; /* Default prompt for others */
char * ikprompt = "(\\v(dir)) IKSD>";
#endif /* UNIX */
#endif /* VMS */
#endif /* NT */
#endif /* NOSPL */
#endif /* MAC */
#ifndef CCHMAXPATH
#define CCHMAXPATH 257
#endif /* CCHMAXPATH */
char inidir[CCHMAXPATH] = { NUL, NUL }; /* Directory INI file executed from */
#ifdef TNCODE
extern int tn_b_nlm; /* TELNET BINARY newline mode */
#endif /* TNCODE */
#ifndef NOKVERBS
extern struct keytab kverbs[]; /* Table of \Kverbs */
extern int nkverbs; /* Number of \Kverbs */
#endif /* NOKVERBS */
#ifndef NOPUSH
extern int nopush;
#endif /* NOPUSH */
#ifdef CK_RECALL
extern int cm_recall;
#endif /* CK_RECALL */
extern char *ccntab[];
/* Printer stuff */
extern char *printername;
extern int printpipe;
#ifdef BPRINT
extern int printbidi, pportparity, pportflow;
extern long pportspeed;
#endif /* BPRINT */
#ifdef OS2
_PROTOTYP (int os2getcp, (void) );
_PROTOTYP (int os2getcplist, (int *, int) );
#ifdef OS2MOUSE
extern int tt_mouse;
#endif /* OS2MOUSE */
extern int tt_update, tt_updmode, updmode, tt_utf8;
#ifndef IKSDONLY
extern int tt_status[];
#endif /* IKSDONLY */
#ifdef PCFONTS
extern struct keytab term_font[];
#else
#ifdef KUI
extern struct keytab * term_font;
#endif /* KUI */
#endif /* PCFONTS */
extern int ntermfont, tt_font, tt_font_size;
extern unsigned char colornormal, colorunderline, colorstatus,
colorhelp, colorselect, colorborder, colorgraphic, colordebug,
colorreverse, colorcmd, coloritalic;
extern int priority;
extern struct keytab prtytab[];
extern int nprty;
char * cmdmac = NULL;
#endif /* OS2 */
#ifdef VMS
_PROTOTYP (int zkermini, (char *, int, char *) );
#endif /* VMS */
extern long vernum;
extern int inecho, insilence, inbufsize, nvars, inintr;
extern char *protv, *fnsv, *cmdv, *userv, *ckxv, *ckzv, *ckzsys, *xlav,
*cknetv, *clcmds;
#ifdef OS2
extern char *ckyv;
#endif /* OS2 */
#ifdef CK_AUTHENTICATION
extern char * ckathv;
#endif /* CK_AUTHENTICATION */
#ifdef CK_SSL
extern char * cksslv;
#endif /* CK_SSL */
#ifdef CK_ENCRYPTION
#ifndef CRYPT_DLL
extern char * ckcrpv;
#endif /* CRYPT_DLL */
#endif /* CK_ENCRYPTION */
#ifdef SSHBUILTIN
extern char *cksshv;
#ifdef SFTP_BUILTIN
extern char *cksftpv;
#endif /* SFTP_BUILTIN */
#endif /* SSHBUILTIN */
#ifdef TNCODE
extern char *cktelv;
#endif /* TNCODE */
#ifndef NOFTP
#ifndef SYSFTP
extern char * ckftpv;
#endif /* SYSFTP */
#endif /* NOFTP */
extern int srvidl;
#ifdef OS2
extern char *ckonetv;
extern int interm;
#ifdef CK_NETBIOS
extern char *ckonbiv;
#endif /* CK_NETBIOS */
#ifdef OS2MOUSE
extern char *ckomouv;
#endif /* OS2MOUSE */
#endif /* OS2 */
#ifndef NOLOCAL
extern char *connv;
#endif /* NOLOCAL */
#ifndef NODIAL
extern char *dialv;
#endif /* NODIAL */
#ifndef NOSCRIPT
extern char *loginv;
extern int secho;
#endif /* NOSCRIPT */
#ifndef NODIAL
extern int nmdm, dirline;
extern struct keytab mdmtab[];
#endif /* NODIAL */
extern int network, nettype, ttnproto;
#ifdef OS2
#ifndef NOTERM
/* SET TERMINAL items... */
extern int tt_type, tt_arrow, tt_keypad, tt_wrap, tt_answer, tt_scrsize[];
extern int tt_bell, tt_roll[], tt_ctstmo, tt_cursor, tt_pacing, tt_type_mode;
extern char answerback[];
extern struct tt_info_rec tt_info[]; /* Indexed by terminal type */
extern int max_tt;
#endif /* NOTERM */
#endif /* OS2 */
_PROTOTYP( VOID shotrm, (void) );
_PROTOTYP( int shofea, (void) );
#ifdef OS2
extern int tt_rows[], tt_cols[];
#else /* OS2 */
extern int tt_rows, tt_cols;
#endif /* OS2 */
extern int cmd_rows, cmd_cols;
#ifdef CK_TMPDIR
extern int f_tmpdir; /* Directory changed temporarily */
extern char savdir[]; /* Temporary directory */
#endif /* CK_TMPDIR */
#ifndef NOLOCAL
extern int tt_crd, tt_lfd, tt_escape;
#endif /* NOLOCAL */
#ifndef NOCSETS
extern int language, nfilc, tcsr, tcsl, tcs_transp, fcharset;
extern struct keytab fcstab[];
extern struct csinfo fcsinfo[];
#ifndef MAC
extern struct keytab ttcstab[];
#endif /* MAC */
#endif /* NOCSETS */
extern long speed;
#ifndef NOXMIT
extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
extern char xmitbuf[];
#endif /* NOXMIT */
extern char **xargv, *versio, *ckxsys, *dftty, *lp;
#ifdef DCMDBUF
extern char *cmdbuf, *atmbuf; /* Command buffers */
#ifndef NOSPL
extern char *savbuf; /* Command buffers */
#endif /* NOSPL */
#else
extern char cmdbuf[], atmbuf[]; /* Command buffers */
#ifndef NOSPL
extern char savbuf[]; /* Command buffers */
#endif /* NOSPL */
#endif /* DCMDBUF */
extern char toktab[], ttname[], psave[];
extern CHAR sstate, feol;
extern int cmflgs, techo, repars, ncmd;
extern struct keytab cmdtab[];
#ifndef NOSETKEY
KEY *keymap;
#ifndef OS2
#define mapkey(x) keymap[x]
#endif /* OS2 */
MACRO *macrotab;
_PROTOTYP( VOID shostrdef, (CHAR *) );
#endif /* NOSETKEY */
extern int cmdlvl;
#ifndef NOSPL
extern struct mtab *mactab;
extern struct keytab mackey[];
extern struct keytab vartab[], fnctab[], iftab[];
extern int maclvl, nmac, mecho, fndiags, fnerror, fnsuccess, nif;
#endif /* NOSPL */
FILE *tfile[MAXTAKE]; /* TAKE file stack */
char *tfnam[MAXTAKE]; /* Name of TAKE file */
int tfline[MAXTAKE]; /* Current line number */
int tfblockstart[MAXTAKE]; /* Current block-start line */
int topcmd = -1; /* cmdtab index of current command */
int havetoken = 0;
extern int dblquo; /* Doublequoting enabled */
#ifdef DCMDBUF /* Initialization filespec */
char *kermrc = NULL;
#else
char kermrcb[KERMRCL];
char *kermrc = kermrcb;
#endif /* DCMDBUF */
int noherald = 0;
int cm_retry = 1; /* Command retry enabled */
xx_strp xxstring = zzstring;
#ifndef NOXFER
extern int displa, bye_active, protocol, pktlog, remfile, rempipe, unkcs,
keep, lf_opts, fncnv, pktpaus, autodl, xfrcan, xfrchr, xfrnum, srvtim,
srvdis, query, retrans, streamed, reliable, crunched, timeouts,
fnrpath, autopath, rpackets, spackets, epktrcvd, srvping;
#ifdef CK_AUTODL
extern int inautodl, cmdadl;
#endif /* CK_AUTODL */
#ifndef NOSERVER
extern int en_asg, en_cwd, en_cpy, en_del, en_dir, en_fin, en_bye, en_ret,
en_get, en_hos, en_que, en_ren, en_sen, en_set, en_spa, en_typ, en_who,
en_mai, en_pri, en_mkd, en_rmd, en_xit, en_ena;
#endif /* NOSERVER */
extern int atcapr,
atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,
attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
#ifdef STRATUS
extern int atfrmi, atfrmo, atcrei, atcreo, atacti, atacto;
#endif /* STRATUS */
#ifdef CK_PERMS
extern int atlpri, atlpro, atgpri, atgpro;
#endif /* CK_PERMS */
#ifdef CK_LOGIN
extern char * anonfile; /* Anonymous login init file */
extern char * anonroot; /* Anonymous file-system root */
extern char * userfile; /* Forbidden user file */
extern int isguest; /* Flag for anonymous user */
#endif /* CK_LOGIN */
#endif /* NOXFER */
#ifdef DCMDBUF
int *xquiet = NULL;
int *xvarev = NULL;
#else
int xquiet[CMDSTKL];
int xvarev[CMDSTKL];
#endif /* DCMDBUF */
char * prstring[CMDSTKL];
#ifndef NOSPL
extern long ck_alarm;
extern char alrm_date[], alrm_time[];
/* Local declarations */
static int nulcmd = 0; /* Flag for next cmd to be ignored */
/* Definitions for predefined macros */
/* First, the single-line macros, installed with addmac()... */
/* IBM-LINEMODE macro */
char *m_ibm = "set parity mark, set dupl half, set handsh xon, set flow none";
/* FATAL macro */
char *m_fat = "if def \\%1 echo \\%1, if not = \\v(local) 0 hangup, stop 1";
#ifdef CK_SPEED
#ifdef IRIX65
char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
#else
#ifdef IRIX
/* Because of bug in telnet server */
char *m_fast = "set window 30, set rec pack 4000, set send pack 4000,\
set pref cautious";
#else
#ifdef pdp11
char *m_fast = "set win 3, set rec pack 1024, set prefix cautious";
#else
#ifdef BIGBUFOK
char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
#else
char *m_fast = "set win 4, set rec pack 2200, set prefix cautious";
#endif /* BIGBUFOK */
#endif /* IRIX */
#endif /* IRIX65 */
#endif /* pdp11 */
#ifdef pdp11
char *m_cautious = "set win 2, set rec pack 512, set prefixing cautious";
#else
char *m_cautious = "set win 4, set rec pack 1000, set prefixing cautious";
#endif /* pdp11 */
char *m_robust = "set win 1, set rec pack 90, set prefixing all, \
set reliable off, set clearchannel off, set send timeout 20 fixed";
#else
#ifdef BIGBUFOK
#ifdef IRIX65
char *m_fast = "set win 30, set rec pack 4000";
#else
#ifdef IRIX
char *m_fast = "set win 30, set rec pack 4000, set send pack 4000";
#else
char *m_fast = "set win 30, set rec pack 4000";
#endif /* IRIX */
#endif /* IRIX65 */
#else /* Not BIGBUFOK */
char *m_fast = "set win 4, set rec pack 2200";
#endif /* BIGBUFOK */
char *m_cautious = "set win 4, set rec pack 1000";
char *m_robust = "set win 1, set rec pack 90, set reliable off,\
set send timeout 20 fixed";
#endif /* CK_SPEED */
#ifdef VMS
char *m_purge = "run purge \\%*";
#endif /* VMS */
#ifdef OS2
char *m_manual = "browse \\v(exedir)docs/manual/kermit95.htm";
#endif /* OS2 */
/* Now the multiline macros, defined with addmmac()... */
/*
Kermit's scripting language is so much more powerful than C that it was
about a thousand time easier to implement FOR, WHILE, IF, and SWITCH
commands as internal Kermit macros. This was done in 1996 for C-Kermit 6.0.
The following definitions, down to #ifdef COMMENT, are from C-Kermit
9.0.304 Dev.22, April 2017, where the command parser was changed to not
evaluate macro arguments on the DO command line, but to defer evaluation
until after the arguments had been separated and counted. This change
required subtle modifications to the internal macro templates.
IMPORTANT: Internal macros must have names that start with '_', followed
by three letters, e.g. _whi for WHILE. The definitions below are just
templates for some other code that constructs the actual menu to be
executed by filling in the \%x variables. The generated macros have names
like _whil2, _whil3, etc, where the trailing number is the execution stack
level. The reason for the strict naming convention is so internal macros
can be parsed differently than regular ones. See
ckuusr.c:isinternalmacro(), which determines the type of macro.
*/
/*
The WHILE macro:
\%1 = Loop condition
\%2 = Loop body
*/
char *whil_def[] = { "_assign _whi\\v(cmdlevel) {_getargs,",
":_..inc,\\fcontents(\\%1),\\fcontents(\\%2),goto _..inc,:_..bot,_putargs},",
"_define break goto _..bot, _define continue goto _..inc,",
"do _whi\\v(cmdlevel),_assign _whi\\v(cmdlevel)",
""};
/*
FOR macro for \%i-style loop variables (see dofor()...)
\%1 = Loop variable
\%2 = Initial value (can be an expression)
\%3 = Loop exit value
\%4 = Loop increment
\%5 = > or <
\%6 = Loop body
*/
char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
"define \\\\\\%1 \\feval(\\%2),:_..top,if \\%5 \\\\\\%1 \\%3 goto _..bot,",
"\\fcontents(\\%6),:_..inc,incr \\\\\\%1 \\%4,goto _..top,:_..bot,_putargs},",
"define break goto _..bot, define continue goto _..inc,",
"do _for\\v(cmdlevel) \\\\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
""};
/*
FOR macro when the loop variable is itself a macro, with same arguments
but slightly different quoting.
*/
char *foz_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
"def \\%1 \\feval(\\%2),:_..top,if \\%5 \\%1 \\%3 goto _..bot,",
"\\fcontents(\\%6),:_..inc,incr \\%1 \\%4,goto _..top,:_..bot,_putargs},",
"def break goto _..bot, def continue goto _..inc,",
"do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
""};
/*
SWITCH macro
\%1 = Switch variable
\%2 = Switch body
*/
char *sw_def[] = { "_assign _sw_\\v(cmdlevel) {_getargs,",
"_forward {\\fcontents(\\%1)},\\fcontents(\\%2),:default,:_..bot,_putargs},_def break goto _..bot,",
"do _sw_\\v(cmdlevel),_assign _sw_\\v(cmdlevel)",
""};
/*
IF macro
/%1 = Commands to execute (IF part and ELSE part if any)
*/
char *xif_def[] = {
"_assign _if_\\v(cmdlevel) {_getargs,\\fcontents(\\%1),_putargs},",
"do _if_\\v(cmdlevel),_assign _if\\v(cmdlevel)",
""};
#ifdef COMMENT
/* Internal macro definitions for C-Kermit 6.0 through 9.0.302 */
char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
"def \\\\\\%1 \\feval(\\%2),:_..top,if \\%5 \\\\\\%1 \\%3 goto _..bot,",
"\\%6,:_..inc,incr \\\\\\%1 \\%4,goto _..top,:_..bot,_putargs},",
"def break goto _..bot, def continue goto _..inc,",
"do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
""};
char *foz_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
"def \\%1 \\feval(\\%2),:_..top,if \\%5 \\%1 \\%3 goto _..bot,",
"\\%6,:_..inc,incr \\%1 \\%4,goto _..top,:_..bot,_putargs},",
"def break goto _..bot, def continue goto _..inc,",
"do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
""};
/* SWITCH macro */
char *sw_def[] = { "_assign _sw_\\v(cmdlevel) {_getargs,",
"_forward {\\%1},\\%2,:default,:_..bot,_putargs},_def break goto _..bot,",
"do _sw_\\v(cmdlevel),_assign _sw_\\v(cmdlevel)",
""};
/* XIF macro */
char *xif_def[] = {
"_assign _if\\v(cmdlevel) {_getargs,\\%1,_putargs},",
"do _if\\v(cmdlevel),_assign _if\\v(cmdlevel)",
""};
#endif /* COMMENT */
/*
Variables declared here for use by other ckuus*.c modules.
Space is allocated here to save room in ckuusr.c.
*/
#ifdef DCMDBUF
struct cmdptr *cmdstk;
int
*ifcmd = NULL,
*count = NULL,
*iftest = NULL,
*intime = NULL,
*inpcas = NULL,
*takerr = NULL,
*merror = NULL;
#else
struct cmdptr cmdstk[CMDSTKL];
int ifcmd[CMDSTKL], count[CMDSTKL], iftest[CMDSTKL], intime[CMDSTKL],
inpcas[CMDSTKL], takerr[CMDSTKL], merror[CMDSTKL];
#endif /* DCMDBUF */
/* Macro stack */
#ifdef COMMENT
char *topline = NULL; /* Program invocation arg line */
char *m_line[MACLEVEL] = { NULL, NULL }; /* Stack of macro invocation lines */
#endif /* COMMENT */
char **m_xarg[MACLEVEL]; /* Pointers to arg vector arrays */
int n_xarg[MACLEVEL]; /* Sizes of arg vector arrays */
char *m_arg[MACLEVEL][NARGS]; /* Args of each level */
int macargc[MACLEVEL]; /* Argc of each level */
char *macp[MACLEVEL]; /* Current position in each macro */
char *macx[MACLEVEL]; /* Beginning of each macro def */
char *mrval[MACLEVEL]; /* RETURN value at each level */
int lastcmd[MACLEVEL]; /* Last command at each level */
int topargc = 0; /* Argc at top level */
char **topxarg = NULL; /* Argv at top level */
char *toparg[MAXARGLIST+2];
/* Global Variables */
char *g_var[GVARS+1]; /* Global \%a..z pointers */
extern char varnam[]; /* \%x variable name buffer */
/* Arrays -- Dimension must be 'z' - ARRAYBASE + 1 */
/* Note: a_link[x] < 0 means no link; >= 0 is a link */
char **a_ptr[32]; /* Array pointers, for arrays a-z */
int a_dim[32]; /* Dimensions for each array */
int a_link[32]; /* Link (index of linked-to-array) */
char **aa_ptr[CMDSTKL][32]; /* Array stack for automatic arrays */
int aa_dim[CMDSTKL][32]; /* Dimensions for each array */
/* INPUT command buffers and variables */
char * inpbuf = NULL; /* Buffer for INPUT and REINPUT */
extern char * inpbp; /* Global/static pointer to it */
char inchar[2] = { NUL, NUL }; /* Last character that was INPUT */
int incount = 0; /* INPUT character count */
extern int instatus; /* INPUT status */
static char * i_text[] = { /* INPUT status text */
"success", "timeout", "interrupted", "internal error", "i/o error"
};
char lblbuf[LBLSIZ]; /* Buffer for labels */
#else /* NOSPL */
int takerr[MAXTAKE];
#endif /* NOSPL */
static char *prevdir = NULL;
int pacing = 0; /* OUTPUT pacing */
char *tp; /* Temporary buffer pointer */
int timelimit = 0, asktimer = 0; /* Timers for time-limited commands */
#ifdef CK_APC /* Application Program Command (APC) */
int apcactive = APC_INACTIVE;
int apcstatus = APC_OFF; /* OFF by default everywhere */
#ifdef DCMDBUF
char *apcbuf;
#else
char apcbuf[APCBUFLEN];
#endif /* DCMDBUF */
#endif /* CK_APC */
extern char pktfil[],
#ifdef DEBUG
debfil[],
#endif /* DEBUG */
#ifdef TLOG
trafil[],
#endif /* TLOG */
sesfil[];
#ifndef NOFRILLS
extern int rmailf, rprintf; /* REMOTE MAIL & PRINT items */
extern char optbuf[];
#endif /* NOFRILLS */
extern int noinit; /* Flat to skip init file */
#ifndef NOSPL
static struct keytab kcdtab[] = { /* Symbolic directory names */
#ifdef NT
{ "appdata", VN_APPDATA, 0 },
{ "common", VN_COMMON, 0 },
{ "desktop", VN_DESKTOP, 0 },
#endif /* NT */
{ "download", VN_DLDIR, 0 },
#ifdef OS2ORUNIX
{ "exedir", VN_EXEDIR, 0 },
#endif /* OS2ORUNIX */
{ "home", VN_HOME, 0 },
{ "inidir", VN_INI, 0 },
#ifdef UNIX
{ "lockdir", VN_LCKDIR, 0 },
#endif /* UNIX */
#ifdef NT
{ "my_documents",VN_PERSONAL, 0 },
{ "personal", VN_PERSONAL, CM_INV },
#endif /* NT */
{ "startup", VN_STAR, 0 },
{ "textdir", VN_TXTDIR, 0 },
{ "tmpdir", VN_TEMP, 0 }
};
static int nkcdtab = (sizeof(kcdtab) / sizeof(struct keytab));
#endif /* NOSPL */
#ifndef NOSPL
_PROTOTYP( VOID freelocal, (int) );
_PROTOTYP( static CK_OFF_T expon, (CK_OFF_T, CK_OFF_T) );
_PROTOTYP( static CK_OFF_T gcd, (CK_OFF_T, CK_OFF_T) );
_PROTOTYP( static CK_OFF_T fact, (CK_OFF_T) );
int /* Initialize macro data structures. */
macini() { /* Allocate mactab and preset the first element. */
int i;
if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX)))
return(-1);
mactab[0].kwd = NULL;
mactab[0].mval = NULL;
mactab[0].flgs = 0;
for (i = 0; i < MACLEVEL; i++)
localhead[i] = NULL;
return(0);
}
#endif /* NOSPL */
/* C M D S R C -- Returns current command source */
/* 0 = top level, 1 = file, 2 = macro, -1 = error (shouldn't happen) */
/*
As of 19 Aug 2000 this routine is obsolete. The scalar global variable
xcmdsrc can be checked instead to save the overhead of a function call.
*/
int
cmdsrc() {
#ifdef COMMENT
return(xcmdsrc);
#else
#ifndef NOSPL
if (cmdlvl == 0)
return(0);
else if (cmdstk[cmdlvl].src == CMD_MD)
return(2);
else if (cmdstk[cmdlvl].src == CMD_TF)
return(1);
else
return(-1);
#else
if (tlevel < 0)
return(0);
else
return(1);
#endif /* NOSPL */
#endif /* COMMENT */
}
/* C M D I N I -- Initialize the interactive command parser */
static int cmdinited = 0; /* Command parser initialized */
extern int cmdint; /* Interrupts are allowed */
#ifdef CK_AUTODL
int cmdadl = 1; /* Autodownload */
#else
int cmdadl = 0;
#endif /* CK_AUTODL */
char * k_info_dir = NULL; /* Where to find text files */
#ifdef UNIX
static char * txtdir[] = {
"/usr/local/doc/", /* Linux, SunOS, ... */
"/usr/share/lib/", /* HP-UX 10.xx... */
"/usr/share/doc/", /* Other possibilities... */
"/usr/local/lib/", /* NOTE: Each of these is tried */
"/usr/local/share/", /* as is, and also with a kermit */
"/usr/local/share/doc/", /* subdirectory. */
"/usr/local/share/lib/",
"/opt/kermit/", /* Solaris */
"/opt/kermit/doc/",
"/opt/",
"/usr/doc/",
"/doc/",
""
};
#endif /* UNIX */
/*
lookup() cache to speed up script execution.
This is a static cache. Items are stored in decreasing frequency of
reference based on statistics from a range of scripts. This gives
better performance than a dynamic cache, which would require a lot more
code and also would require system-dependent elements including system
calls (e.g. to get subsecond times for entry aging).
*/
#ifdef USE_LUCACHE /* Set in ckuusr.h */
#define LUCACHE 32 /* Change this to reduce cache size */
int lusize = 0;
char * lucmd[LUCACHE];
int luval[LUCACHE];
int luidx[LUCACHE];
struct keytab * lutab[LUCACHE];
#endif /* USE_LUCACHE */
static VOID
luinit() { /* Initialize lookup() cache */
int x, y;
#ifdef USE_LUCACHE
x = lookup(cmdtab,"if",ncmd,&y);
lucmd[lusize] = "if";
luval[lusize] = x;
luidx[lusize] = y;
lutab[lusize] = cmdtab;
if (++lusize > LUCACHE) return;
x = lookup(iftab,"not",nif,&y);
lucmd[lusize] = "not";
luval[lusize] = x;
luidx[lusize] = y;
lutab[lusize] = iftab;
if (++lusize > LUCACHE) return;
x = lookup(vartab,"cmdlevel",nvars,&y);
lucmd[lusize] = "cmdlevel";
luval[lusize] = x;
luidx[lusize] = y;
lutab[lusize] = vartab;
if (++lusize > LUCACHE) return;
x = lookup(cmdtab,"goto",ncmd,&y);
lucmd[lusize] = "goto";
luval[lusize] = x;
luidx[lusize] = y;
lutab[lusize] = cmdtab;
if (++lusize > LUCACHE) return;