|
|
1.1 root 1: char *userv = "User Interface 5A(081), 8 Feb 92";
2:
3: /* C K U U S R -- "User Interface" for Unix Kermit (Part 1) */
4:
5: /*
6: Author: Frank da Cruz ([email protected], [email protected]),
7: Columbia University Center for Computing Activities.
8: First released January 1985.
9: Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
10: York. Permission is granted to any individual or institution to use, copy, or
11: redistribute this software so long as it is not sold for profit, provided this
12: copyright notice is retained.
13: */
14:
15: /*
16: NOTE: Because of the massive additions in functionality, and therefore
17: the increase in the number of commands, much code was moved from here to
18: the two new modules, ckuus4.c and ckuus5.c. This module now contains only
19: the top-level command keyword table, the SET command keyword table, and
20: the top-level interactive command parser/dispatcher. ckuus3.c contains the
21: rest of the SET and REMOTE command parsers; ckuus2.c contains the help
22: command parser and help text strings, and ckuus4.c and ckuus5.c contain
23: miscellaneous pieces that logically belong in the ckuusr.c file but had to
24: be moved because of size problems with some C compilers / linkers.
25: Later... as the other modules became too large, a ckuus6.c was created.
26: Still later... ckuus7.c.
27: Also: ckuusy.c contains the UNIX-style command-line interface;
28: ckuusx.c contains routines needed by both the command-line interface and
29: the interactive command parser.
30: */
31:
32: /*
33: The ckuus*.c modules depend on the existence of C library features like fopen,
34: fgets, feof, (f)printf, argv/argc, etc. Other functions that are likely to
35: vary among Unix implementations -- like setting terminal modes or interrupts
36: -- are invoked via calls to functions that are defined in the system-
37: dependent modules, ck?[ft]io.c. The command line parser processes any
38: arguments found on the command line, as passed to main() via argv/argc. The
39: interactive parser uses the facilities of the cmd package (developed for this
40: program, but usable by any program). Any command parser may be substituted
41: for this one. The only requirements for the Kermit command parser are these:
42:
43: 1. Set parameters via global variables like duplex, speed, ttname, etc. See
44: ckmain.c for the declarations and descriptions of these variables.
45:
46: 2. If a command can be executed without the use of Kermit protocol, then
47: execute the command directly and set the variable sstate to 0. Examples
48: include 'set' commands, local directory listings, the 'connect' command.
49:
50: 3. If a command requires the Kermit protocol, set the following variables:
51:
52: sstate string data
53: 'x' (enter server mode) (none)
54: 'r' (send a 'get' command) cmarg, cmarg2
55: 'v' (enter receive mode) cmarg2
56: 'g' (send a generic command) cmarg
57: 's' (send files) nfils, cmarg & cmarg2 OR cmlist
58: 'c' (send a remote host command) cmarg
59:
60: cmlist is an array of pointers to strings.
61: cmarg, cmarg2 are pointers to strings.
62: nfils is an integer.
63:
64: cmarg can be a filename string (possibly wild), or
65: a pointer to a prefabricated generic command string, or
66: a pointer to a host command string.
67: cmarg2 is the name to send a single file under, or
68: the name under which to store an incoming file; must not be wild.
69: If it's the name for receiving, a null value means to store the
70: file under the name it arrives with.
71: cmlist is a list of nonwild filenames, such as passed via argv.
72: nfils is an integer, interpreted as follows:
73: -1: filespec (possibly wild) in cmarg, must be expanded internally.
74: 0: send from stdin (standard input).
75: >0: number of files to send, from cmlist.
76:
77: The screen() function is used to update the screen during file transfer.
78: The tlog() function writes to a transaction log.
79: The debug() function writes to a debugging log.
80: The intmsg() and chkint() functions provide the user i/o for interrupting
81: file transfers.
82: */
83:
84: #ifndef NOICP
85: /* Includes */
86:
87: #include "ckcdeb.h"
88: #include "ckcasc.h"
89: #include "ckcker.h"
90: #include "ckuusr.h"
91: #include "ckcxla.h"
92: #include "ckcnet.h" /* Network symbols */
93:
94: #ifdef datageneral
95: #define fgets(stringbuf,max,fd) dg_fgets(stringbuf,max,fd)
96: #endif /* datageneral */
97:
98: /* External Kermit Variables, see ckmain.c for description. */
99:
100: extern int size, local, sndsrc, xitsta, server, displa, binary,
101: escape, duplex, nfils, quiet, tlevel, pflag, zincnt, atcapr, atdiso, verwho;
102:
103: extern long vernum;
104: extern char *versio;
105: extern char *ckxsys, *cmarg, *cmarg2, **cmlist;
106: extern char *PWDCMD, *WHOCMD, *TYPCMD;
107: extern char ttname[];
108: #ifndef NOFRILLS
109: extern int rmailf; /* MAIL command items */
110: extern char optbuf[];
111: #endif /* NOFRILLS */
112: extern CHAR sstate;
113:
114: #ifndef NOMSEND /* Multiple SEND */
115: extern char *msfiles[];
116: #endif /* NOMSEND */
117: extern char fspec[]; /* Most recent filespec */
118:
119: #ifndef NOCSETS
120: extern int nfilc;
121: extern struct keytab fcstab[];
122: #endif /* NOCSETS */
123:
124: int rcflag = 0; /* Pointer to home directory string */
125: int repars, /* Reparse needed */
126: techo = 0, /* Take echo */
127: terror = 0; /* Take error action, 1 = quit */
128: #ifndef NOSCRIPT
129: int secho = 1;
130: #endif /* NOSCRIPT */
131:
132: #ifndef NOXMIT
133: /* Variables for TRANSMIT command */
134:
135: int xmitx = 1; /* Whether to echo during TRANSMIT */
136: int xmitf = 0; /* Character to fill empty lines */
137: int xmitl = 0; /* 1 = Send linefeeds too */
138: int xmitp = LF; /* Host line prompt */
139: int xmits = 0; /* Use shift-in/shift-out, 0 = no */
140: int xmitw = 0; /* Milliseconds to pause during xmit */
141: #endif /* NOXMIT */
142:
143: /* Declarations from ck?fio.c module */
144:
145: extern char *SPACMD; /* Space command, home directory. */
146:
147: /* Command-oriented items */
148:
149: #ifdef DCMDBUF
150: extern char *cmdbuf; /* Command buffers */
151: extern char *line; /* Character buffer for anything */
152: #else
153: extern char cmdbuf[]; /* Command buffers */
154: extern char line[]; /* Character buffer for anything */
155: #endif /* DCMDBUF */
156:
157: char *lp; /* Pointer to line buffer */
158:
159: #ifndef NOSPL
160: extern char inpbuf[]; /* Buffer for INPUT and REINPUT */
161: char *inpbp = inpbuf; /* And pointer to same */
162: extern char lblbuf[]; /* Buffer for labels */
163: #endif /* NOSPL */
164:
165: char psave[80] = { NUL }; /* For saving & restoring prompt */
166:
167: extern char tmpbuf[]; /* Temporary buffer */
168:
169: extern int success; /* Command success/failure flag */
170:
171: #ifndef NOSPL
172: int /* SET INPUT parameters. */
173: indef = 5, /* 5 seconds default timeout */
174: intime = 0, /* 0 = proceed */
175: incase = 0, /* 0 = ignore */
176: inecho = 1; /* 1 = echo on */
177:
178: int maclvl = -1; /* Macro nesting level */
179: int mecho = 0; /* Macro echo, 0 = don't */
180: int merror = 0; /* Macro error action */
181: char varnam[6]; /* For variable names */
182: extern int macargc[]; /* ARGC from macro invocation */
183:
184: extern char *m_arg[MACLEVEL][NARGS]; /* Stack of macro arguments */
185:
186: extern char **a_ptr[]; /* Array pointers */
187: extern int a_dim[]; /* Array dimensions */
188:
189: #ifdef DCMDBUF
190: extern struct cmdptr *cmdstk; /* The command stack itself */
191: #else
192: extern struct cmdptr cmdstk[]; /* The command stack itself */
193: #endif /* DCMDBUF */
194: extern int cmdlvl; /* Current position in command stack */
195: #endif /* NOSPL */
196:
197: static int x, y, z = 0; /* Local workers */
198: static char *s;
199:
200: #define xsystem(s) zsyscmd(s)
201:
202: /* Top-Level Interactive Command Keyword Table */
203:
204: struct keytab cmdtab[] = {
205: #ifndef NOPUSH
206: "!", XXSHE, CM_INV, /* shell escape */
207: #endif /* NOPUSH */
208: "#", XXCOM, CM_INV, /* comment */
209: #ifndef NOSPL
210: ":", XXLBL, CM_INV, /* label */
211: #endif /* NOSPL */
212: #ifndef NOPUSH
213: "@", XXSHE, CM_INV, /* DCL escape */
214: #endif /* NOPUSH */
215: #ifndef NOSPL
216: "asg", XXASS, CM_INV, /* invisible synonym for assign */
217: "ask", XXASK, 0, /* ask */
218: "askq", XXASKQ,0, /* ask quietly */
219: "assign", XXASS, 0, /* assign */
220: #endif /* NOSPL */
221: #ifndef NOFRILLS
222: "bug", XXBUG, 0, /* bug report instructions */
223: #endif /* NOFRILLS */
224: "bye", XXBYE, 0, /* bye to remote server */
225: "c", XXCON, CM_INV|CM_ABR, /* invisible synonym for connect */
226: #ifndef NOFRILLS
227: "cat", XXTYP, CM_INV, /* display a local file */
228: #endif /* NOFRILLS */
229: "cd", XXCWD, 0, /* change directory */
230: #ifndef NOFRILLS
231: "clear", XXCLE, 0, /* clear input buffer */
232: #endif /* NOFRILLS */
233: "close", XXCLO, 0, /* close a log file */
234: #ifdef NOFRILLS
235: "comment", XXCOM, CM_INV, /* comment */
236: #else
237: "comment", XXCOM, 0, /* comment */
238: #endif /* NOFRILLS */
239: "connect", XXCON, 0, /* connect to remote system */
240: "cwd", XXCWD, CM_INV, /* invisisble synonym for cd */
241: #ifndef NOSPL
242: "dcl", XXDCL, CM_INV, /* declare an array */
243: "declare", XXDCL, 0, /* declare an array */
244: "decrement", XXDEC, 0, /* decrement a numeric variable */
245: "define", XXDEF, 0, /* define a macro */
246: #endif /* NOSPL */
247: #ifndef NOFRILLS
248: "delete", XXDEL, 0, /* delete a file */
249: #endif /* NOFRILLS */
250: #ifndef NODIAL
251: "dial", XXDIAL,0, /* dial a phone number */
252: #endif /* NODIAL */
253: #ifndef MAC
254: "directory", XXDIR, 0, /* directory of files */
255: #endif /* MAC */
256: #ifndef NOFRILLS
257: "disable", XXDIS, 0, /* disable server function */
258: #endif /* NOFRILLS */
259: #ifndef NOSPL
260: "do", XXDO, 0, /* execute a macro */
261: #endif /* NOSPL */
262: "echo", XXECH, 0, /* echo argument */
263: #ifndef NOSPL
264: "else", XXELS, CM_INV, /* ELSE part of IF statement */
265: #endif /* NOSPL */
266: #ifndef NOFRILLS
267: "enable", XXENA, 0, /* enable a server function */
268: #endif /* NOFRILLS */
269: #ifndef NOSPL
270: "end", XXEND, 0, /* END command file or macro */
271: #endif /* NOSPL */
272: #ifndef NOFRILLS
273: #ifdef COMMENT
274: /* The ERROR command is badly broken. Uncomment it when it's fixed! */
275: "error", XXERR, 0, /* Send an Error packet */
276: #endif /* COMMENT */
277: #endif /* NOFRILLS */
278: "exit", XXEXI, 0, /* exit the program */
279: "finish", XXFIN, 0, /* FINISH */
280: #ifndef NOSPL
281: "for", XXFOR, 0, /* FOR loop */
282: #endif /* NOSPL */
283: #ifndef NOFRILLS
284: #ifndef MAC
285: "fot", XXDIR, CM_INV, /* "fot" = "dir" (for Chris) */
286: #endif /* MAC */
287: #endif /* NOFRILLS */
288: #ifndef NOSPL
289: "ge", XXGET, CM_INV, /* Abbreviation for GET */
290: #endif /* NOSPL */
291: "get", XXGET, 0, /* GET */
292: #ifndef NOSPL
293: #ifndef NOFRILLS
294: "getok", XXGOK, 0, /* GETOK (ask for Yes/No) */
295: #endif /* NOFRILLS */
296: #endif /* NOSPL */
297: #ifndef NOSPL
298: "goto", XXGOTO,0, /* goto label in take file or macro */
299: #endif /* NOSPL */
300: "hangup", XXHAN, 0, /* hangup dialed phone connection */
301: "help", XXHLP, 0, /* display help text */
302: #ifndef NOSPL
303: "i", XXINP, CM_INV|CM_ABR, /* invisible synonym for INPUT */
304: "if", XXIF, 0, /* if (condition) command */
305: "in", XXINP, CM_INV|CM_ABR, /* invisible synonym for INPUT */
306: "increment", XXINC, 0, /* increment a numeric variable */
307: "input", XXINP, 0, /* input string from comm line */
308: #endif /* NOSPL */
309: #ifndef NOFRILLS
310: "l", XXLOG, CM_INV|CM_ABR,/* invisible synonym for log */
311: #endif /* NOFRILLS */
312: "log", XXLOG, 0, /* open a log file */
313: #ifndef NOFRILLS
314: #ifndef MAC
315: "ls", XXDIR, CM_INV, /* invisible synonym for directory */
316: #endif /* MAC */
317: "mail", XXMAI, 0, /* mail file to user */
318: "man", XXHLP, CM_INV, /* Synonym for help */
319: #endif /* NOFRILLS */
320: #ifndef NOMSEND
321: "mget", XXGET, CM_INV, /* MGET = GET */
322: "msend", XXMSE, 0, /* Multiple SEND */
323: "mput", XXMSE, CM_INV, /* MPUT = MSEND */
324: #endif /* NOMSEND */
325: #ifndef NOFRILLS
326: "mv", XXREN, CM_INV, /* rename a local file */
327: #endif /* NOFRILLS */
328: #ifndef NOSPL
329: "o", XXOUT, CM_INV|CM_ABR,/* invisible synonym for OUTPUT */
330: "open", XXOPE, 0, /* open file for reading or writing */
331: "output", XXOUT, 0, /* output string to comm line */
332: #endif /* NOSPL */
333: #ifdef SUNX25
334: "pad", XXPAD, 0, /* PAD commands */
335: #endif /* SUNX25 */
336: #ifndef NOSPL
337: "pause", XXPAU, 0, /* sleep for specified interval */
338: "pop", XXEND, CM_INV, /* allow POP as synonym for END */
339: #endif /* NOSPL */
340: #ifndef NOFRILLS
341: "print", XXPRI, 0, /* PRINT */
342: #ifndef NOPUSH
343: "pu", XXSHE, CM_INV, /* PU = PUSH */
344: "push", XXSHE, 0, /* PUSH command (like RUN, !) */
345: #endif /* NOPUSH */
346: "put", XXSEN, CM_INV, /* PUT = SEND */
347: #ifndef MAC
348: "pwd", XXPWD, 0, /* print working directory */
349: #endif /* MAC */
350: #endif /* NOFRILLS */
351: "quit", XXQUI, 0, /* quit from program = exit */
352: "r", XXREC, CM_INV, /* invisible synonym for receive */
353: #ifndef NOSPL
354: "read", XXREA, 0, /* read */
355: #endif /* NOSPL */
356: "receive", XXREC, 0, /* receive files */
357: #ifndef NODIAL
358: "redial", XXRED, 0, /* redial */
359: #endif /* NODIAL */
360: #ifndef NOSPL
361: "reinput", XXREI, 0, /* reinput */
362: #endif /* NOSPL */
363: "remote", XXREM, 0, /* send generic command to server */
364: #ifndef NOFRILLS
365: "rename", XXREN, 0, /* rename a local file */
366: "replay", XXTYP, CM_INV, /* replay (for now, just type) */
367: #endif /* NOFRILLS */
368: #ifndef NOSPL
369: "return", XXRET, 0, /* return from function */
370: #endif /* NOSPL */
371: #ifndef NOFRILLS
372: "rm", XXDEL, CM_INV, /* invisible synonym for delete */
373: #endif /* NOFRILLS */
374: #ifndef NOPUSH
375: "run", XXSHE, 0, /* run a program or command */
376: #endif /* NOPUSH */
377: "s", XXSEN, CM_INV|CM_ABR, /* invisible synonym for send */
378: #ifndef NOSCRIPT
379: "script", XXLOGI,0, /* execute a uucp-style script */
380: #endif /* NOSCRIPT */
381: "send", XXSEN, 0, /* send files */
382: #ifndef NOSERVER
383: "server", XXSER, 0, /* be a server */
384: #endif /* NOSERVER */
385: "set", XXSET, 0, /* set parameters */
386: #ifndef NOSHOW
387: "show", XXSHO, 0, /* show parameters */
388: #endif /* NOSHOW */
389: #ifndef NOSPL
390: #ifndef NOFRILLS
391: "sleep", XXPAU, CM_INV, /* sleep for specified interval */
392: #endif /* NOFRILLS */
393: #endif /* NOSPL */
394: #ifndef MAC
395: "space", XXSPA, 0, /* show available disk space */
396: #endif /* MAC */
397: #ifndef NOFRILLS
398: #ifndef NOPUSH
399: "spawn", XXSHE, CM_INV, /* synonym for PUSH, RUN */
400: #endif /* NOPUSH */
401: #endif /* NOFRILLS */
402: "statistics", XXSTA, 0, /* display file transfer stats */
403: #ifndef NOSPL
404: "stop", XXSTO, 0, /* stop all take files */
405: #endif /* NOSPL */
406: #ifndef NOJC
407: "suspend", XXSUS, 0, /* Suspend */
408: #endif /* NOJC */
409: "take", XXTAK, 0, /* take commands from file */
410: #ifndef NOFRILLS
411: #ifdef NETCONN
412: "telnet", XXTEL, 0, /* telnet */
413: #endif /* NETCONN */
414: "test", XXTES, CM_INV, /* (for testing) */
415: #endif /* NOFRILLS */
416: #ifndef NOCSETS
417: "translate", XXXLA, 0, /* translate local file char sets */
418: #endif
419: #ifndef NOXMIT
420: "transmit", XXTRA, 0, /* raw upload file */
421: #endif /* NOXMIT */
422: #ifndef NOFRILLS
423: "type", XXTYP, 0, /* display a local file */
424: #endif /* NOFRILLS */
425: "version", XXVER, 0 /* version number display */
426: #ifndef NOSPL
427: , "wait", XXWAI, 0 /* wait (like pause) */
428: , "while", XXWHI, 0 /* while */
429: #endif /* NOSPL */
430: #ifndef MAC
431: #ifndef NOFRILLS
432: , "who", XXWHO, 0 /* who */
433: #endif /* NOFRILLS */
434: #endif /* MAC */
435: #ifndef NOSPL
436: , "write", XXWRI, 0 /* write */
437: , "xif", XXIFX, 0 /* Extended IF */
438: #endif /* NOSPL */
439: #ifndef NOCSETS
440: , "xlate", XXXLA, CM_INV /* translate local file char sets */
441: #endif
442: #ifndef NOXMIT
443: , "xmit", XXTRA, CM_INV /* raw upload file */
444: #endif /* NOXMIT */
445: #ifndef NOJC
446: , "z", XXSUS, CM_INV /* Suspend */
447: #endif /* NOJC */
448: #ifndef NOSPL
449: , "_getargs", XXGTA, CM_INV /* used internally by FOR, etc */
450: , "_putargs", XXPTA, CM_INV /* used internally by FOR, etc */
451: #endif /* NOSPL */
452: };
453: int ncmd = (sizeof(cmdtab) / sizeof(struct keytab));
454:
455: char toktab[] = {
456: #ifndef NOPUSH
457: '!', /* Shell escape */
458: #endif /* NOPUSH */
459: '#', /* Comment */
460: ';', /* Comment */
461: #ifndef NOSPL
462: ':', /* Label */
463: #endif /* NOSPL */
464: #ifndef NOPUSH
465: '@', /* DCL escape */
466: #endif /* NOPUSH */
467: '\0' /* End of this string */
468: };
469:
470: #ifndef NOSPL
471: #ifndef NOFRILLS
472: struct keytab yesno[] = {
473: "no", 0, 0,
474: "ok", 1, 0,
475: "yes", 1, 0
476: };
477: int nyesno = (sizeof(yesno) / sizeof(struct keytab));
478: #endif /* NOFRILLS */
479: #endif /* NOSPL */
480:
481: /* Parameter keyword table */
482:
483: struct keytab prmtab[] = {
484: "attributes", XYATTR, 0,
485: "background", XYBACK, 0,
486: "baud", XYSPEE, CM_INV,
487: "block-check", XYCHKT, 0,
488: #ifdef DYNAMIC
489: "buffers", XYBUF, 0,
490: #endif /* DYNAMIC */
491: #ifndef MAC
492: "carrier", XYCARR, 0,
493: #endif /* MAC */
494: #ifndef NOSPL
495: "case", XYCASE, 0,
496: #endif /* NOSPL */
497: "command", XYCMD, 0,
498: #ifndef NOSPL
499: "count", XYCOUN, 0,
500: #endif /* NOSPL */
501: #ifdef DEBUG
502: "debug", XYDEBU, CM_INV,
503: #endif /* DEBUG */
504: #ifdef VMS
505: "default", XYDFLT, 0,
506: #else
507: #ifndef MAC
508: "default", XYDFLT, CM_INV,
509: #endif /* MAC */
510: #endif /* VMS */
511: "delay", XYDELA, 0,
512: #ifndef NODIAL
513: "dial", XYDIAL, 0,
514: #endif /* NODIAL */
515: "duplex", XYDUPL, 0,
516: "escape-character", XYESC, 0,
517: "file", XYFILE, 0,
518: "flow-control", XYFLOW, 0,
519: "handshake", XYHAND, 0,
520: #ifdef NETCONN
521: "host", XYHOST, 0,
522: #endif /* NETCONN */
523: "incomplete", XYIFD, 0,
524: #ifndef NOSPL
525: "input", XYINPU, 0,
526: #ifndef MAC
527: #ifndef NOSETKEY
528: "key", XYKEY, 0,
529: #endif /* NOSETKEY */
530: #endif /* MAC */
531: #endif /* NOSPL */
532: "l", XYLINE, CM_INV|CM_ABR,
533: #ifndef NOCSETS
534: "language", XYLANG, 0,
535: #endif /* NOCSETS */
536: "line", XYLINE, 0,
537: "local-echo", XYLCLE, CM_INV,
538: #ifndef NOSPL
539: "macro", XYMACR, 0,
540: #endif /* NOSPL */
541: #ifndef NODIAL
542: "modem-dialer", XYMODM, 0,
543: #endif
544: #ifdef NETCONN
545: "network", XYNET, CM_INV,
546: #endif /* NETCONN */
547: #ifdef COMMENT
548: "packet-length", XYLEN, CM_INV, /* moved to send/receive */
549: #endif
550: #ifdef SUNX25
551: "pad", XYPAD, 0,
552: #endif /* SUNX25 */
553: "parity", XYPARI, 0,
554: "port", XYLINE, CM_INV,
555: #ifndef NOFRILLS
556: "prompt", XYPROM, 0,
557: #endif /* NOFRILLS */
558: "quiet", XYQUIE, 0,
559: "receive", XYRECV, 0,
560: "retry-limit", XYRETR, 0,
561: #ifndef NOSCRIPT
562: "script", XYSCRI, 0,
563: #endif /* NOSCRIPT */
564: "send", XYSEND, 0,
565: #ifndef NOSERVER
566: "server", XYSERV, 0,
567: #endif /* NOSERVER */
568: #ifdef UNIX
569: "session-log", XYSESS, 0,
570: #endif /* UNIX */
571: "speed", XYSPEE, 0,
572: #ifndef NOJC
573: "suspend", XYSUSP, 0,
574: #endif /* NOJC */
575: "take", XYTAKE, 0,
576: "terminal", XYTERM, 0,
577: #ifndef NOCSETS
578: "transfer", XYXFER, 0,
579: #endif /* NOCSETS */
580: #ifndef NOXMIT
581: "transmit", XYXMIT, 0,
582: #endif /* NOXMIT */
583: #ifndef NOCSETS
584: "unknown-char-set", XYUNCS, 0,
585: #endif /* NOCSETS */
586: "window-size", XYWIND, 0
587: #ifdef UNIX
588: , "wildcard-expansion", XYWILD, 0
589: #endif /* UNIX */
590: #ifdef SUNX25
591: , "x.25", XYX25, 0
592: #endif /* SUNX25 */
593: #ifndef NOCSETS
594: , "xfer", XYXFER, CM_INV
595: #endif /* NOCSETS */
596: #ifndef NOXMIT
597: , "xmit", XYXMIT, CM_INV
598: #endif /* NOXMIT */
599: };
600: int nprm = (sizeof(prmtab) / sizeof(struct keytab)); /* How many parameters */
601:
602: /* Table of networks */
603: #ifdef NETCONN
604: struct keytab netcmd[] = {
605: /* "decnet", NET_DEC, 0, */
606: "tcp/ip", NET_TCPB, 0
607: /* "stream-tcp-ip", NET_TCPA, 0 */
608: #ifdef SUNX25
609: ,"x.25", NET_SX25, 0
610: #endif /* SUNX25 */
611: };
612: int nnets = (sizeof(netcmd) / sizeof(struct keytab)); /* How many networks */
613: #endif /* NETCONN */
614:
615: /* Remote Command Table */
616:
617: struct keytab remcmd[] = {
618: "cd", XZCWD, 0,
619: "cwd", XZCWD, CM_INV,
620: "delete", XZDEL, 0,
621: "directory", XZDIR, 0,
622: "help", XZHLP, 0,
623: #ifndef NOPUSH
624: "host", XZHOS, 0,
625: #endif /* NOPUSH */
626: #ifndef NOFRILLS
627: "kermit", XZKER, 0,
628: "login", XZLGI, 0,
629: "logout", XZLGO, 0,
630: "print", XZPRI, 0,
631: #endif /* NOFRILLS */
632: "set", XZSET, 0,
633: "space", XZSPA, 0
634: #ifndef NOFRILLS
635: , "type", XZTYP, 0,
636: "who", XZWHO, 0
637: #endif /* NOFRILLS */
638: };
639: int nrmt = (sizeof(remcmd) / sizeof(struct keytab));
640:
641: struct keytab logtab[] = {
642: #ifdef DEBUG
643: "debugging", LOGD, 0,
644: #endif /* DEBUG */
645: "packets", LOGP, 0,
646: "session", LOGS, 0
647: #ifdef TLOG
648: , "transactions", LOGT, 0
649: #endif /* TLOG */
650: };
651: int nlog = (sizeof(logtab) / sizeof(struct keytab));
652:
653: struct keytab writab[] = {
654: #ifndef NOSPL
655: "append-file", LOGW, CM_INV,
656: #endif /* NOSPL */
657: "debug-log", LOGD, 0,
658: #ifndef NOSPL
659: "file", LOGW, 0,
660: #endif /* NOSPL */
661: "packet-log", LOGP, 0,
662: "screen", LOGX, 0,
663: "session-log", LOGS, 0,
664: "sys$output", LOGX, CM_INV,
665: "transaction-log", LOGT, 0
666: };
667: int nwri = (sizeof(writab) / sizeof(struct keytab));
668:
669: struct keytab clstab[] = {
670: #ifndef NOSPL
671: "append-file", LOGW, CM_INV,
672: #endif /* NOSPL */
673: #ifdef DEBUG
674: "debug-log", LOGD, 0,
675: #endif /* DEBUG */
676: "packet-log", LOGP, 0,
677: #ifndef NOSPL
678: "read-file", LOGR, 0,
679: #endif /* NOSPL */
680: "session-log", LOGS, 0
681: #ifdef TLOG
682: , "transaction-log", LOGT, 0
683: #endif /* TLOG */
684: #ifndef NOSPL
685: , "write-file", LOGW, 0
686: #endif /* NOSPL */
687: };
688: int ncls = (sizeof(clstab) / sizeof(struct keytab));
689:
690: /* SHOW command arguments */
691:
692: struct keytab shotab[] = {
693: #ifndef NOSPL
694: "arguments", SHARG, 0,
695: "arrays", SHARR, 0,
696: #endif /* NOSPL */
697: "attributes", SHATT, 0,
698: "communications", SHCOM, 0,
699: #ifndef NOSPL
700: "count", SHCOU, 0,
701: #endif /* NOSPL */
702: #ifdef VMS
703: "default", SHDFLT, 0,
704: #else
705: "default", SHDFLT, CM_INV,
706: #endif /* VMS */
707: #ifndef NODIAL
708: "dial", SHDIA, 0,
709: #endif /* NODIAL */
710: "escape", SHESC, 0,
711: "file", SHFIL, 0,
712: #ifndef NOSPL
713: "functions", SHFUN, 0,
714: "globals", SHVAR, 0,
715: #endif /* NOSPL */
716: #ifndef NOSETKEY
717: "key", SHKEY, 0,
718: #endif /* NOSETKEY */
719: #ifdef VMS
720: "labeled-file-info", SHLBL, 0,
721: #endif /* VMS */
722: #ifndef NOCSETS
723: "languages", SHLNG, 0,
724: #endif /* NOCSETS */
725: #ifndef NOSPL
726: "macros", SHMAC, 0,
727: #endif /* NOSPL */
728: "modem", SHMOD, 0,
729: #ifdef NETCONN
730: "network", SHNET, 0,
731: #ifdef SUNX25
732: "pad", SHPAD, 0,
733: #endif /* SUNX25 */
734: #endif /* NETCONN */
735: "parameters", SHPAR, CM_INV,
736: "protocol", SHPRO, 0,
737: #ifndef NOSPL
738: "scripts", SHSCR, 0,
739: #endif /* NOSPL */
740: #ifndef NOSERVER
741: "server", SHSER, 0,
742: #endif /* NOSERVER */
743: "status", SHSTA, 0,
744: #ifdef MAC
745: "stack", SHSTK, 0, /* debugging */
746: #endif /* MAC */
747: "terminal", SHTER, 0
748: #ifndef NOXMIT
749: , "transmit", SHXMI, 0
750: #endif /* NOXMIT */
751: #ifndef NOSPL
752: , "variables", SHBUI, 0
753: #endif /* NOSPL */
754: #ifndef NOFRILLS
755: , "versions", SHVER, 0
756: #endif /* NOFRILLS */
757: #ifndef NOXMIT
758: , "xmit", SHXMI, CM_INV
759: #endif /* NOXMIT */
760: };
761: int nsho = (sizeof(shotab) / sizeof(struct keytab));
762:
763: #ifdef SUNX25
764: struct keytab padtab[] = { /* PAD commands */
765: "clear", XYPADL, 0,
766: "interrupt", XYPADI, 0,
767: "reset", XYPADR, 0,
768: "status", XYPADS, 0
769: };
770: int npadc = (sizeof(padtab) / sizeof(struct keytab));
771: #endif /* SUNX25 */
772:
773: struct keytab enatab[] = { /* ENABLE commands */
774: "all", EN_ALL, 0,
775: "bye", EN_BYE, 0,
776: "cd", EN_CWD, 0,
777: "cwd", EN_CWD, CM_INV,
778: "delete", EN_DEL, 0,
779: "directory", EN_DIR, 0,
780: "finish", EN_FIN, 0,
781: "get", EN_GET, 0,
782: "host", EN_HOS, 0,
783: "send", EN_SEN, 0,
784: "set", EN_SET, 0,
785: "space", EN_SPA, 0,
786: "type", EN_TYP, 0,
787: "who", EN_WHO, 0
788: };
789: int nena = (sizeof(enatab) / sizeof(struct keytab));
790:
791: #ifndef NOSPL
792: #ifdef COMMENT
793: struct mtab mactab[MAC_MAX] = { /* Preinitialized macro table */
794: NULL, NULL, 0
795: };
796: #else
797: struct mtab *mactab; /* Dynamically allocated macro table */
798: #endif /* COMMENT */
799: int nmac = 0;
800:
801: struct keytab mackey[MAC_MAX]; /* Macro names as command keywords */
802: #endif /* NOSPL */
803:
804: /* Forward declarations of functions */
805:
806: _PROTOTYP (int doask, ( int ) );
807: _PROTOTYP (int dodef, ( int ) );
808: _PROTOTYP (int dodel, ( void ) );
809: _PROTOTYP (int dodial, ( int ) );
810: _PROTOTYP (int dodir, ( void ) );
811: _PROTOTYP (int doelse, ( void ) );
812: _PROTOTYP (int dofor, ( void ) );
813: _PROTOTYP (int dogta, ( int ) );
814: _PROTOTYP (int doincr, ( int ) );
815: _PROTOTYP (int dopaus, ( int ) );
816: _PROTOTYP (int dorenam, ( void ) );
817:
818: /* D O C M D -- Do a command */
819:
820: /*
821: Returns:
822: -2: user typed an illegal command
823: -1: reparse needed
824: 0: parse was successful (even tho command may have failed).
825: */
826: int
827: docmd(cx) int cx; {
828:
829: debug(F101,"docmd entry, cx","",cx);
830:
831: /*
832: Massive switch() broken up into many smaller ones, for the benefit of
833: compilers that run out of space when trying to handle large switch
834: statements.
835: */
836: switch (cx) {
837: case -4: /* EOF */
838: #ifdef OSK
839: if (!quiet && pflag) printf("\n");
840: #else
841: if (!quiet && pflag) printf("\r\n");
842: #endif /* OSK */
843: doexit(GOOD_EXIT,xitsta);
844: case -3: /* Null command */
845: return(0);
846: case -9: /* Like -2, but errmsg already done */
847: case -6: /* Special */
848: case -2: /* Error, maybe */
849: case -1: /* Reparse needed */
850: return(cx);
851: default:
852: break;
853: }
854:
855: /* And later, even the smaller ones were removed, so now we just have ifs. */
856: /* (And even later, many of these were moved to separate modules...) */
857:
858: #ifndef NOSPL
859: /* Copy macro args from/to two levels up, used internally by _floop et al. */
860: if (cx == XXGTA || cx == XXPTA) { /* _GETARGS, _PUTARGS */
861: int x;
862: debug(F101,"docmd XXGTA","",XXGTA);
863: debug(F101,"docmd cx","",cx);
864: debug(F101,"docmd XXGTA maclvl","",maclvl);
865: x = dogta(cx);
866: debug(F101,"docmd dogta returns","",x);
867: debug(F101,"docmd dogta maclvl","",maclvl);
868: return(x);
869: }
870: #endif /* NOSPL */
871:
872: #ifndef NOSPL
873: /* ASK, ASKQ, READ */
874: if (cx == XXASK || cx == XXASKQ || cx == XXREA) {
875: return(doask(cx));
876: }
877: #endif /* NOSPL */
878:
879: #ifndef NOFRILLS
880: if (cx == XXBUG) { /* BUG */
881: if ((x = cmcfm()) < 0) return(x);
882: return(dobug());
883: }
884: #endif /* NOFRILLS */
885:
886: if (cx == XXBYE) { /* BYE */
887: if ((x = cmcfm()) < 0) return(x);
888: sstate = setgen('L',"","","");
889: if (local) ttflui(); /* If local, flush tty input buffer */
890: return(0);
891: }
892:
893: #ifndef NOFRILLS
894: if (cx == XXCLE) { /* CLEAR */
895: if ((x = cmcfm()) < 0) return(x);
896: y = ttflui(); /* Flush input buffer */
897: #ifndef NOSPL
898: for (x = 0; x < INPBUFSIZ; x++) /* and our local copy too */
899: inpbuf[x] = 0;
900: inpbp = inpbuf;
901: #endif /* NOSPL */
902: success = (y == 0); /* Set SUCCESS/FAILURE */
903: return(success);
904: }
905: #endif /* NOFRILLS */
906:
907: if (cx == XXCOM) { /* COMMENT */
908: if ((x = cmtxt("Text of comment line","",&s,NULL)) < 0)
909: return(x);
910: /* Don't change SUCCESS flag for this one */
911: return(0);
912: }
913:
914: if (cx == XXCON) { /* CONNECT */
915: if ((x = cmcfm()) < 0)
916: return(x);
917: return(success = doconect());
918: }
919:
920: if (cx == XXCWD) /* CWD */
921: return(success = docd());
922:
923: if (cx == XXCLO) { /* CLOSE */
924: x = cmkey(clstab,ncls,"Which log or file to close","",xxstring);
925: if (x == -3) {
926: printf("?You must tell which file or log\n");
927: return(-9);
928: }
929: if (x < 0) return(x);
930: if ((y = cmcfm()) < 0) return(y);
931: y = doclslog(x);
932: success = (y == 1);
933: return(success);
934: }
935:
936: #ifndef NOSPL
937: if (cx == XXDEC || cx == XXINC) /* DECREMENT, INCREMENT */
938: return(doincr(cx));
939: #endif /* NOSPL */
940:
941: #ifndef NOSPL
942: if (cx == XXDEF || cx == XXASS) /* DEFINE, ASSIGN */
943: return(dodef(cx));
944: #endif /* NOSPL */
945:
946: #ifndef NOSPL
947: if (cx == XXDCL) { /* DECLARE an array */
948: if ((y = cmfld("Array name","",&s,NULL)) < 0) {
949: if (y == -3) {
950: printf("?Array name required\n");
951: return(-9);
952: } else return(y);
953: }
954: if ((y = arraynam(s,&x,&z)) < 0) return(y);
955: if ((y = cmcfm()) < 0) return(y);
956: if (dclarray((char)x,z) < 0) {
957: printf("?Declare failed\n");
958: return(success = 0);
959: }
960: return(success = 1);
961: }
962: #endif /* NOSPL */
963:
964:
965: #ifndef NODIAL
966: if (cx == XXRED || cx == XXDIAL) /* DIAL or REDIAL */
967: return(dodial(cx));
968: #endif /* NODIAL */
969:
970: #ifndef NOFRILLS
971: if (cx == XXDEL) /* DELETE */
972: return(dodel());
973: #endif /* NOFRILLS */
974:
975: #ifndef MAC
976: if (cx == XXDIR) /* DIRECTORY */
977: return(dodir());
978: #endif /* MAC */
979:
980: #ifndef NOSPL
981: if (cx == XXELS) /* ELSE */
982: return(doelse());
983: #endif /* NOSPL */
984:
985: #ifndef NOFRILLS
986: if (cx == XXENA || cx == XXDIS) { /* ENABLE, DISABLE */
987: s = (cx == XXENA) ?
988: "Server function to enable" :
989: "Server function to disable";
990:
991: if ((x = cmkey(enatab,nena,s,"",xxstring)) < 0) {
992: if (x == -3) {
993: printf("?Name of server function required\n");
994: return(-9);
995: } else return(x);
996: }
997: if ((y = cmcfm()) < 0) return(y);
998: return(doenable(cx,x));
999: }
1000: #endif /* NOFRILLS */
1001:
1002: #ifndef NOSPL
1003: if (cx == XXEND) { /* END, POP (same thing) */
1004: if ((y = cmnum("exit status code","0",10,&x,xxstring)) < 0)
1005: return(y);
1006: if (cmdlvl == 0) { /* At top level, nothing happens... */
1007: if ((y = cmcfm()) < 0)
1008: return(y);
1009: return(success = (x == 0));
1010: }
1011: popclvl();
1012: return(success = (x == 0));
1013: }
1014: #endif /* NOSPL */
1015:
1016: #ifndef NOSPL
1017: if (cx == XXRET) { /* RETURN */
1018: if (cmdlvl == 0) { /* At top level, nothing happens... */
1019: if ((x = cmcfm()) < 0)
1020: return(x);
1021: return(success = 1);
1022: } else if (cmdstk[cmdlvl].src == CMD_TF) { /* In TAKE file, like POP */
1023: if ((x = cmtxt("optional return value","",&s,NULL)) < 0)
1024: return(x); /* Allow trailing text, but ignore. */
1025: if ((x = cmcfm()) < 0)
1026: return(x);
1027: popclvl(); /* pop command level */
1028: return(success = 1); /* always succeeds */
1029: } else if (cmdstk[cmdlvl].src == CMD_MD) { /* Within macro */
1030: if ((x = cmtxt("optional return value","",&s,NULL)) < 0)
1031: return(x);
1032: return(doreturn(s)); /* Trailing text is return value. */
1033: } else return(-2);
1034: }
1035: #endif /* NOSPL */
1036:
1037: #ifndef NOSPL
1038: if (cx == XXDO) { /* DO (a macro) */
1039: if (nmac == 0) {
1040: printf("\n?No macros defined\n");
1041: return(-2);
1042: }
1043: for (y = 0; y < nmac; y++) { /* copy the macro table */
1044: mackey[y].kwd = mactab[y].kwd; /* into a regular keyword table */
1045: mackey[y].kwval = y; /* with value = pointer to macro tbl */
1046: mackey[y].flgs = mactab[y].flgs;
1047: }
1048: /* parse name as keyword */
1049: if ((x = cmkey(mackey,nmac,"macro","",xxstring)) < 0) {
1050: if (x == -3) {
1051: printf("?Macro name required\n");
1052: return(-9);
1053: } else return(x);
1054: }
1055: if ((y = cmtxt("optional arguments","",&s,xxstring)) < 0)
1056: return(y); /* get args */
1057: return(success = dodo(x,s));
1058: }
1059: #endif /* NOSPL */
1060:
1061: if (cx == XXECH) { /* ECHO */
1062: if ((x = cmtxt("Material to be echoed","",&s,xxstring)) < 0)
1063: return(x);
1064: printf("%s\n",s);
1065: return(1); /* Always succeeds */
1066: }
1067:
1068: #ifndef NOSPL
1069: if (cx == XXOPE) /* OPEN */
1070: return(doopen());
1071: #endif /* NOSPL */
1072:
1073: #ifndef NOSPL
1074: if (cx == XXOUT) { /* OUTPUT */
1075: if ((x = cmtxt("Text to be output","",&s,xxstring)) < 0)
1076: return(x);
1077: if (*s == '{') {
1078: x = (int)strlen(s);
1079: if (s[x-1] == '}') {
1080: s[x-1] = NUL;
1081: s++;
1082: }
1083: }
1084: return(success = dooutput(s));
1085: }
1086: #endif /* NOSPL */
1087:
1088: #ifdef SUNX25
1089: if (cx == XXPAD) { /* PAD commands */
1090: x = cmkey(padtab,npadc,"PAD command","",xxstring);
1091: if (x == -3) {
1092: printf("?You must specify a PAD command to execute\n");
1093: return(-2);
1094: }
1095: if (x < 0) return(x);
1096:
1097: switch (x) {
1098: case XYPADL:
1099: if (x25stat() < 0)
1100: printf("Sorry, you must 'set network' & 'set host' first\r\n");
1101: else {
1102: x25clear();
1103: initpad();
1104: }
1105: break;
1106: case XYPADS:
1107: if (x25stat() < 0)
1108: printf("Not connected\r\n");
1109: else {
1110: extern int linkid, lcn;
1111: conol("Connected thru ");
1112: conol(ttname);
1113: printf(", Link id %d, Logical channel number %d\r\n",
1114: linkid,lcn);
1115: }
1116: break;
1117: case XYPADR:
1118: if (x25stat() < 0)
1119: printf("Sorry, you must 'set network' & 'set host' first\r\n");
1120: else
1121: x25reset(0,0);
1122: break;
1123: case XYPADI:
1124: if (x25stat() < 0)
1125: printf("Sorry, you must 'set network' & 'set host' first\r\n");
1126: else
1127: x25intr(0);
1128: }
1129: return(0);
1130: }
1131: #endif /* SUNX25 */
1132:
1133: #ifndef NOSPL
1134: if (cx == XXPAU || cx == XXWAI) { /* PAUSE, WAIT */
1135: return(dopaus(cx));
1136: }
1137: #endif /* NOSPL */
1138:
1139: #ifndef NOFRILLS
1140: if (cx == XXPRI) {
1141: if ((x = cmifi("File to print","",&s,&y,xxstring)) < 0) {
1142: if (x == -3) {
1143: printf("?A file specification is required\n");
1144: return(-9);
1145: } else return(x);
1146: }
1147: if (y != 0) {
1148: printf("?Wildcards not allowed\n");
1149: return(-9);
1150: }
1151: strcpy(line,s);
1152: if ((x = cmtxt("Local print command options, or carriage return","",&s,
1153: xxstring)) < 0) return(x);
1154: return(success = (zprint(s,line) == 0) ? 1 : 0);
1155: }
1156:
1157: #ifndef MAC
1158: if (cx == XXPWD) { /* PWD */
1159: if ((x = cmcfm()) < 0) return(x);
1160: xsystem(PWDCMD);
1161: return(success = 1); /* blind faith */
1162: }
1163: #endif /* MAC */
1164: #endif /* NOFRILLS */
1165:
1166: if (cx == XXQUI || cx == XXEXI) { /* EXIT, QUIT */
1167: if ((y = cmnum("exit status code","",10,&x,xxstring)) < 0) {
1168: if (y == -3)
1169: x = xitsta;
1170: else return(y);
1171: }
1172: if ((y = cmcfm()) < 0) return(y);
1173: #ifdef VMS
1174: doexit(GOOD_EXIT,x);
1175: #else
1176: #ifdef OSK
1177: /* Returning any codes here makes the OS-9 shell print an error message. */
1178: doexit(GOOD_EXIT,-1);
1179: #else
1180: doexit(x,-1);
1181: #endif /* OSK */
1182: #endif /* VMS */
1183: }
1184:
1185: #ifdef COMMENT /* DOESN'T WORK! */
1186: #ifndef NOFRILLS
1187: if (cx == XXERR) { /* ERROR */
1188: if ((x = cmcfm()) < 0) return(x);
1189: ttflui();
1190: sstate = 'a';
1191: return(0);
1192: }
1193: #endif /* NOFRILLS */
1194: #endif /* COMMENT */
1195:
1196: if (cx == XXFIN) { /* FINISH */
1197: if ((x = cmcfm()) < 0) return(x);
1198: sstate = setgen('F',"","","");
1199: if (local) ttflui(); /* If local, flush tty input buffer */
1200: return(0);
1201: }
1202:
1203: #ifndef NOSPL
1204: if (cx == XXFOR) /* FOR loop */
1205: return(dofor());
1206: #endif /* NOSPL */
1207:
1208: if (cx == XXGET) { /* GET */
1209: x = cmtxt("Name of remote file(s), or carriage return","",&cmarg,
1210: xxstring);
1211: #ifndef NOFRILLS
1212: if ((x == -2) || (x == -1)) return(x);
1213: #else
1214: if (x < 0) return(x);
1215: #endif /* NOFRILLS */
1216: x = doget();
1217: #ifdef MAC
1218: if (sstate == 'r')
1219: scrcreate();
1220: #endif /* MAC */
1221: return(x);
1222: }
1223:
1224: #ifndef NOSPL
1225: #ifndef NOFRILLS
1226: if (cx == XXGOK) { /* GETOK */
1227: return(success = doask(cx));
1228: }
1229: #endif /* NOFRILLS */
1230: #endif /* NOSPL */
1231:
1232: if (cx == XXHLP) { /* HELP */
1233: #ifdef NOHELP
1234: return(dohlp(XXHLP));
1235: #else
1236: x = cmkey2(cmdtab,ncmd,"C-Kermit command","help",toktab,xxstring);
1237: if (x == -5) {
1238: y = chktok(toktab);
1239: debug(F101,"top-level cmkey token","",y);
1240: ungword();
1241: switch (y) {
1242: #ifndef NOPUSH
1243: case '!': x = XXSHE; break;
1244: #endif /* NOPUSH */
1245: case '#': x = XXCOM; break;
1246: case ';': x = XXCOM; break;
1247: #ifndef NOSPL
1248: case ':': x = XXLBL; break;
1249: #endif /* NOSPL */
1250: case '&': x = XXECH; break;
1251: default:
1252: printf("\n?Invalid - %s\n",cmdbuf);
1253: x = -2;
1254: }
1255: }
1256: return(dohlp(x));
1257: #endif /* NOHELP */
1258: }
1259:
1260: if (cx == XXHAN) { /* HANGUP */
1261: if ((x = cmcfm()) < 0) return(x);
1262: success = (tthang() > -1);
1263: return(success);
1264: }
1265:
1266: #ifndef NOSPL
1267: if (cx == XXGOTO) { /* GOTO */
1268: /* Note, here we don't set SUCCESS/FAILURE flag */
1269: if ((y = cmfld("label","",&s,xxstring)) < 0) {
1270: if (y == -3) {
1271: printf("?Label name required\n");
1272: return(-9);
1273: } else return(y);
1274: }
1275: strcpy(lblbuf,s);
1276: if ((x = cmcfm()) < 0) return(x);
1277: s = lblbuf;
1278: return(dogoto(s));
1279: }
1280: #endif /* NOSPL */
1281:
1282: #ifndef NOSPL
1283: /* IF, Extended IF, WHILE */
1284: if (cx == XXIF || cx == XXIFX || cx == XXWHI) {
1285: return(doif(cx));
1286: }
1287: #endif /* NOSPL */
1288:
1289: #ifndef NOSPL
1290: if (cx == XXINP || cx == XXREI) { /* INPUT and REINPUT */
1291: y = cmnum("seconds to wait for input","1",10,&x,xxstring);
1292: if (y < 0) {
1293: return(y);
1294: }
1295: if (x <= 0) x = 1;
1296: if ((y = cmtxt("Material to be input","",&s,xxstring)) < 0)
1297: return(y);
1298: if (*s == '\0') {
1299: printf("?Text required\n");
1300: return(-9);
1301: }
1302: if (*s == '{') {
1303: y = (int)strlen(s);
1304: if (s[y-1] == '}') {
1305: s[y-1] = NUL;
1306: s++;
1307: }
1308: }
1309: if (cx == XXINP) { /* INPUT */
1310: debug(F110,"calling doinput",s,0);
1311: success = doinput(x,s); /* Go try to input the search string */
1312: } else { /* REINPUT */
1313: debug(F110,"xxrei line",s,0);
1314: success = doreinp(x,s);
1315: }
1316: if (intime && !success) { /* TIMEOUT-ACTION = QUIT? */
1317: popclvl(); /* If so, pop command level. */
1318: if (pflag && cmdlvl == 0) {
1319: if (cx == XXINP) printf("Input timed out\n");
1320: if (cx == XXREI) printf("Reinput failed\n");
1321: }
1322: }
1323: return(success); /* Return do(re)input's return code */
1324: }
1325: #endif /* NOSPL */
1326:
1327: #ifndef NOSPL
1328: if (cx == XXLBL) { /* LABEL */
1329: if ((x = cmfld("label","",&s,xxstring)) < 0) {
1330: if (x == -3) {
1331: printf("?Label name required\n");
1332: return(-9);
1333: } else return(x);
1334: }
1335: if ((x = cmcfm()) < 0) return(x);
1336: return(0);
1337: }
1338: #endif /* NOSPL */
1339:
1340: if (cx == XXLOG) { /* LOG */
1341: x = cmkey(logtab,nlog,"What to log","",xxstring);
1342: if (x == -3) {
1343: printf("?Type of log required\n");
1344: return(-9);
1345: }
1346: if (x < 0) return(x);
1347: x = dolog(x);
1348: if (x < 0)
1349: return(x);
1350: else
1351: return(success = x);
1352: }
1353:
1354: #ifndef NOSCRIPT
1355: if (cx == XXLOGI) { /* UUCP-style script */
1356: if ((x = cmtxt("expect-send expect-send ...","",&s,xxstring)) < 0)
1357: return(x);
1358: #ifdef VMS
1359: conres(); /* For Ctrl-C to work... */
1360: #endif /* VMS */
1361: return(success = dologin(s)); /* Return 1=completed, 0=failed */
1362: }
1363: #endif /* NOSCRIPT */
1364:
1365: if (cx == XXREC) { /* RECEIVE */
1366: cmarg2 = "";
1367: x = cmofi("Name under which to store the file, or CR","",&cmarg2,
1368: xxstring);
1369: if ((x == -1) || (x == -2)) return(x);
1370: debug(F111,"cmofi cmarg2",cmarg2,x);
1371: if ((x = cmcfm()) < 0) return(x);
1372: sstate = 'v';
1373: #ifdef MAC
1374: scrcreate();
1375: #endif /* MAC */
1376: if (local) displa = 1;
1377: return(0);
1378: }
1379:
1380: if (cx == XXREM) { /* REMOTE */
1381: x = cmkey(remcmd,nrmt,"Remote Kermit server command","",xxstring);
1382: if (x == -3) {
1383: printf("?You must specify a command for the remote server\n");
1384: return(-9);
1385: }
1386: return(dormt(x));
1387: }
1388:
1389: #ifndef NOFRILLS
1390: if (cx == XXREN) /* RENAME */
1391: return(dorenam());
1392: #endif /* NOFRILLS */
1393:
1394: if (cx == XXSEN || cx == XXMAI) { /* SEND, MAIL */
1395: cmarg = cmarg2 = "";
1396: if ((x = cmifi("File(s) to send","",&s,&y,xxstring)) < 0) {
1397: if (x == -3) {
1398: printf("?A file specification is required\n");
1399: return(-9);
1400: } else return(x);
1401: }
1402: nfils = -1; /* Files come from internal list. */
1403: strcpy(line,s); /* Save copy of string just parsed. */
1404: strncpy(fspec,s,FSPECL); /* and here for \v(filespec) */
1405: if (cx == XXSEN) { /* SEND command */
1406: debug(F101,"Send: wild","",y);
1407: if (y == 0) {
1408: if ((x = cmtxt("Name to send it with","",&cmarg2,
1409: xxstring)) < 0)
1410: return(x);
1411: } else {
1412: if ((x = cmcfm()) < 0) return(x);
1413: }
1414: cmarg = line; /* File to send */
1415: debug(F110,"Sending:",cmarg,0);
1416: if (*cmarg2 != '\0') debug(F110," as:",cmarg2,0);
1417: } else { /* MAIL */
1418: #ifndef NOFRILLS
1419: if (!atdiso || !atcapr) { /* Disposition attribute off? */
1420: printf("?Disposition Attribute is Off\n");
1421: return(-2);
1422: }
1423: debug(F101,"Mail: wild","",y);
1424: *optbuf = NUL; /* Wipe out any old options */
1425: if ((x = cmtxt("Address to mail to","",&s,xxstring)) < 0)
1426: return(x);
1427: if ((int)strlen(s) == 0) {
1428: printf("?Address required\n");
1429: return(-9);
1430: }
1431: strcpy(optbuf,s);
1432: if ((int)strlen(optbuf) > 94) { /* Ensure legal size */
1433: printf("?Option string too long\n");
1434: return(-2);
1435: }
1436: cmarg = line; /* File to send */
1437: debug(F110,"Mailing:",cmarg,0);
1438: debug(F110,"To:",optbuf,0);
1439: rmailf = 1; /* MAIL modifier flag for SEND */
1440: #else
1441: printf("?Sorry, MAIL feature not configured.\n");
1442: return(-2);
1443: #endif /* NOFRILLS */
1444: }
1445: sstate = 's'; /* Set start state to SEND */
1446: #ifdef MAC
1447: scrcreate();
1448: #endif /* MAC */
1449: if (local) { /* If in local mode, */
1450: displa = 1; /* turn on file transfer display */
1451: ttflui(); /* and flush tty input buffer. */
1452: }
1453: return(0);
1454: }
1455:
1456: #ifndef NOMSEND
1457: if (cx == XXMSE) { /* MSEND command */
1458: nfils = 0; /* Like getting a list of */
1459: lp = line; /* files on the command line */
1460: while (1) {
1461: char *p;
1462: if ((x = cmifi("Names of files to send, separated by spaces","",
1463: &s,&y,xxstring)) < 0) {
1464: if (x == -3) {
1465: if (nfils <= 0) {
1466: printf("?A file specification is required\n");
1467: return(-9);
1468: } else break;
1469: }
1470: return(x);
1471: }
1472: msfiles[nfils++] = lp; /* Got one, count it, point to it, */
1473: p = lp; /* remember pointer, */
1474: while (*lp++ = *s++) ; /* and copy it into buffer */
1475: if (nfils == 1) *fspec = NUL; /* Take care of \v(filespec) */
1476: if (((int)strlen(fspec) + (int)strlen(p) + 1) < FSPECL) {
1477: strcat(fspec,p);
1478: strcat(fspec," ");
1479: }
1480: }
1481: cmlist = msfiles; /* Point cmlist to pointer array */
1482: cmarg2 = ""; /* No internal expansion list (yet) */
1483: sndsrc = nfils; /* Filenames come from cmlist */
1484: sstate = 's'; /* Set start state to SEND */
1485: #ifdef MAC
1486: scrcreate();
1487: #endif /* MAC */
1488: if (local) { /* If in local mode, */
1489: displa = 1; /* turn on file transfer display */
1490: ttflui(); /* and flush tty input buffer. */
1491: }
1492: return(0);
1493: }
1494: #endif /* NOMSEND */
1495:
1496: #ifndef NOSERVER
1497: if (cx == XXSER) { /* SERVER */
1498: if ((x = cmcfm()) < 0) return(x);
1499: sstate = 'x';
1500: #ifdef MAC
1501: scrcreate();
1502: #endif /* MAC */
1503: if (local) displa = 1;
1504: #ifdef AMIGA
1505: reqoff(); /* No DOS requestors while server */
1506: #endif /* AMIGA */
1507: return(0);
1508: }
1509: #endif /* NOSERVER */
1510:
1511: if (cx == XXSET) { /* SET command */
1512: x = cmkey(prmtab,nprm,"Parameter","",xxstring);
1513: if (x == -3) {
1514: printf("?You must specify a parameter to set\n");
1515: return(-9);
1516: }
1517: if (x < 0) return(x);
1518: /* have to set success separately for each item in doprm()... */
1519: /* actually not really, could have just had doprm return 0 or 1 */
1520: /* and set success here... */
1521: y = doprm(x,0);
1522: if (y == -3) {
1523: printf("?More fields required\n");
1524: return(-9);
1525: } else return(y);
1526: }
1527:
1528: #ifndef NOPUSH
1529: if (cx == XXSHE) { /* SHELL (system) command */
1530: if (cmtxt("System command to execute","",&s,xxstring) < 0)
1531: return(-1);
1532: conres(); /* Make console normal */
1533: x = zshcmd(s);
1534: concb((char)escape);
1535: return(success = x);
1536: }
1537: #endif /* NOPUSH */
1538:
1539: #ifndef NOSHOW
1540: if (cx == XXSHO) { /* SHOW */
1541: x = cmkey(shotab,nsho,"","parameters",xxstring);
1542: if (x < 0) return(x);
1543: return(success = doshow(x));
1544: }
1545: #endif /* NOSHOW */
1546:
1547: #ifndef MAC
1548: if (cx == XXSPA) { /* SPACE */
1549: #ifdef datageneral
1550: /* The DG can take an argument after its "space" command. */
1551: if ((x = cmtxt("Confirm, or local directory name","",&s,xxstring)) < 0)
1552: return(x);
1553: if (*s == NUL) xsystem(SPACMD);
1554: else {
1555: char *cp;
1556: cp = alloc((int)strlen(s) + 7); /* For "space *s" */
1557: strcpy(cp,"space "), strcat(cp,s);
1558: xsystem(cp);
1559: if (cp) free(cp);
1560: }
1561: #else
1562: if ((x = cmcfm()) < 0) return(x);
1563: xsystem(SPACMD);
1564: #endif /* datageneral */
1565: return(success = 1); /* pretend it worked */
1566: }
1567: #endif /* MAC */
1568:
1569: if (cx == XXSTA) { /* STATISTICS */
1570: if ((x = cmcfm()) < 0) return(x);
1571: return(success = dostat());
1572: }
1573:
1574: #ifndef NOSPL
1575: if (cx == XXSTO) { /* STOP */
1576:
1577: if ((y = cmnum("exit status code","0",10,&x,xxstring)) < 0)
1578: return(y);
1579: if ((y = cmcfm()) < 0) return(y);
1580: dostop();
1581: return(success = (x == 0));
1582: }
1583: #endif /* NOSPL */
1584:
1585: if (cx == XXSUS) { /* SUSPEND */
1586: if ((y = cmcfm()) < 0) return(y);
1587: stptrap(0);
1588: return(0);
1589: }
1590:
1591: if (cx == XXTAK) { /* TAKE */
1592: if (tlevel > MAXTAKE-1) {
1593: printf("?Take files nested too deeply\n");
1594: return(-2);
1595: }
1596: if ((y = cmifi("C-Kermit command file","",&s,&x,xxstring)) < 0) {
1597: if (y == -3) {
1598: printf("?A file name is required\n");
1599: return(-9);
1600: } else return(y);
1601: }
1602: if (x != 0) {
1603: printf("?Wildcards not allowed in command file name\n");
1604: return(-9);
1605: }
1606: strcpy(line,s);
1607: if ((y = cmcfm()) < 0) return(y);
1608: return(success = dotake(line));
1609: }
1610:
1611: #ifdef NETCONN
1612: if (cx == XXTEL) { /* TELNET */
1613: if ((y = setlin(XYHOST,0)) < 0) return(y);
1614: return (success = (y == 0) ? 0 : doconect());
1615: }
1616: #endif /* NETCONN */
1617:
1618: #ifndef NOXMIT
1619: if (cx == XXTRA) { /* TRANSMIT */
1620: if ((x = cmifi("File to transmit","",&s,&y,xxstring)) < 0) {
1621: if (x == -3) {
1622: printf("?Name of an existing file\n");
1623: return(-9);
1624: } else return(x);
1625: }
1626: if (y != 0) {
1627: printf("?Only a single file may be transmitted\n");
1628: return(-2);
1629: }
1630: strcpy(line,s); /* Save copy of string just parsed. */
1631: if ((y = cmcfm()) < 0) return(y); /* Confirm the command */
1632: debug(F111,"calling transmit",line,xmitp);
1633: return(success = transmit(line,(char)xmitp)); /* Do the command */
1634: }
1635: #endif /* NOXMIT */
1636:
1637: #ifndef NOFRILLS
1638: if (cx == XXTYP) { /* TYPE */
1639: #ifndef MAC
1640: char *tc;
1641: #endif /* MAC */
1642: if ((x = cmifi("File to type","",&s,&y,xxstring)) < 0) {
1643: if (x == -3) {
1644: printf("?Name of an existing file\n");
1645: return(-9);
1646: } else return(x);
1647: }
1648: if (y != 0) {
1649: printf("?A single file please\n");
1650: return(-2);
1651: }
1652: #ifndef MAC
1653: if (!(tc = getenv("CK_TYPE"))) tc = TYPCMD;
1654: sprintf(line,"%s %s",tc,s);
1655: if ((y = cmcfm()) < 0) return(y); /* Confirm the command */
1656: xsystem(line);
1657: return(success = 1);
1658: #else
1659: strcpy(line,s);
1660: if ((y = cmcfm()) < 0) return(y); /* Confirm the command */
1661: return(success = dotype(line));
1662: #endif /* MAC */
1663: }
1664: #endif /* NOFRILLS */
1665:
1666: #ifndef NOFRILLS
1667: if (cx == XXTES) { /* TEST */
1668: /* Fill this in with whatever is being tested... */
1669: if ((y = cmcfm()) < 0) return(y); /* Confirm the command */
1670:
1671: #ifndef NOSPL
1672: #ifdef COMMENT
1673: { int d, i, j; /* Dump all arrays */
1674: char c, **p;
1675: for (i = 0; i < 27; i++) {
1676: p = a_ptr[i];
1677: d = a_dim[i];
1678: c = (i == 0) ? 64 : i + 96;
1679: if (d && p) {
1680: fprintf(stderr,"&%c[%d]\n",c,d);
1681: for (j = 0; j <= d; j++) {
1682: if (p[j]) {
1683: fprintf(stderr," &%c[%2d] = [%s]\n",c,j,p[j]);
1684: }
1685: }
1686: }
1687: }
1688: }
1689: #else /* Not COMMENT */
1690: printf("cmdlvl = %d, tlevel = %d, maclvl = %d\n",cmdlvl,tlevel,maclvl);
1691: if (maclvl < 0) {
1692: printf("%s\n",
1693: "Call me from inside a macro and I'll dump the argument stack");
1694: return(0);
1695: }
1696: printf("Macro level: %d, ARGC = %d\n ",maclvl,macargc[maclvl]);
1697: for (y = 0; y < 10; y++) printf("%7d",y);
1698: for (x = 0; x <= maclvl; x++) {
1699: printf("\n%2d: ",x);
1700: for (y = 0; y < 10; y++) {
1701: s = m_arg[x][y];
1702: printf("%7s",s ? s : "(none)");
1703: }
1704: }
1705: printf("\n");
1706: #endif /* COMMENT */
1707: #endif /* NOSPL */
1708: return(0);
1709: }
1710: #endif /* NOFRILLS */
1711:
1712: #ifndef NOCSETS
1713: if (cx == XXXLA) { /* TRANSLATE <ifn> from-cs to-cs <ofn> */
1714: int incs, outcs;
1715: if ((x = cmifi("File to translate","",&s,&y,xxstring)) < 0) {
1716: if (x == -3) {
1717: printf("?Name of an existing file\n");
1718: return(-9);
1719: } else return(x);
1720: }
1721: if (y != 0) {
1722: printf("?A single file please\n");
1723: return(-2);
1724: }
1725: strcpy(line,s); /* Save copy of string just parsed. */
1726:
1727: if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
1728: return(incs);
1729: if ((outcs = cmkey(fcstab,nfilc,"to character-set","",xxstring)) < 0)
1730: return(outcs);
1731: if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
1732: strncpy(tmpbuf,s,50);
1733: if ((y = cmcfm()) < 0) return(y); /* Confirm the command */
1734: return(success = xlate(line,tmpbuf,incs,outcs)); /* Execute it */
1735: }
1736: #endif /* NOCSETS */
1737:
1738: if (cx == XXVER) { /* VERSION */
1739: if ((y = cmcfm()) < 0) return(y);
1740: printf("%s,%s\n Numeric: %ld",versio,ckxsys,vernum);
1741: if (verwho) printf("-%d\n",verwho); else printf("\n");
1742: return(success = 1);
1743: }
1744:
1745: #ifndef MAC
1746: #ifndef NOFRILLS
1747: if (cx == XXWHO) { /* WHO */
1748: char *wc;
1749: if ((y = cmtxt("user name","",&s,xxstring)) < 0) return(y);
1750: if (!(wc = getenv("CK_WHO"))) wc = WHOCMD;
1751: sprintf(line,"%s %s",wc,s);
1752: xsystem(line);
1753: return(success = 1);
1754: }
1755: #endif /* NOFRILLS */
1756: #endif /* MAC */
1757:
1758: #ifndef NOFRILLS
1759: if (cx == XXWRI) { /* WRITE */
1760: if ((x = cmkey(writab,nwri,"to file or log","",xxstring)) < 0) {
1761: if (x == -3) printf("?Write to what?\n");
1762: return(x);
1763: }
1764: if ((y = cmtxt("text","",&s,xxstring)) < 0) return(y);
1765: switch (x) {
1766: case LOGD: y = ZDFILE; break;
1767: case LOGP: y = ZPFILE; break;
1768: case LOGS: y = ZSFILE; break;
1769: case LOGT: y = ZTFILE; break;
1770: #ifndef NOSPL
1771: case LOGW: y = ZWFILE; break;
1772: #endif /* NOSPL */
1773: case LOGX:
1774: printf("%s",s);
1775: #ifndef NOSPL
1776: if (cmdlvl == 0) printf("\n");
1777: #else
1778: if (tlevel == 0) printf("\n");
1779: #endif /* NOSPL */
1780: return(success = 1);
1781: default: return(-2);
1782: }
1783: if ((x = zsout(y,s)) < 0)
1784: printf("?File or log not open\n");
1785: return(success = (x == 0) ? 1 : 0);
1786: }
1787: #endif /* NOFRILLS */
1788:
1789: debug(F101,"docmd unk arg","",cx);
1790: return(-2); /* None of the above. */
1791: } /* end of docmnd() */
1792:
1793: #endif /* NOICP */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.