📄 ckuusr.c
字号:
"echo", XXECH, 0, "exit", XXEXI, 0, "finish", XXFIN, 0, "get", XXGET, 0, "help", XXHLP, 0, "log", XXLOG, 0, "quit", XXQUI, 0, "r", XXREC, CM_INV, "receive", XXREC, 0, "remote", XXREM, 0, "s", XXSEN, CM_INV, "script", XXLOGI, 0, "send", XXSEN, 0, "server", XXSER, 0, "set", XXSET, 0, "show", XXSHO, 0, "space", XXSPA, 0, "statistics", XXSTA, 0, "take", XXTAK, 0};int ncmd = (sizeof(cmdtab) / sizeof(struct keytab));/* Parameter keyword table */ struct keytab prmtab[] = { "baud", XYSPEE, CM_INV, "block-check", XYCHKT, 0, "delay", XYDELA, 0, "duplex", XYDUPL, 0, "end-of-packet", XYEOL, CM_INV, /* moved to send/receive */ "escape-character", XYESC, 0, "file", XYFILE, 0, "flow-control", XYFLOW, 0, "handshake", XYHAND, 0, "incomplete", XYIFD, 0, "line", XYLINE, 0, "modem-dialer", XYMODM, 0, "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 */ "parity", XYPARI, 0, "prompt", XYPROM, 0, "receive", XYRECV, 0, "retry", XYRETR, 0, "send", XYSEND, 0, "speed", XYSPEE, 0, "start-of-packet", XYMARK, CM_INV, /* moved to send/receive */ "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[] = { "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)); struct keytab logtab[] = { "debugging", LOGD, 0, "packets", LOGP, 0, "session", LOGS, 0, "transactions", LOGT, 0};int nlog = (sizeof(logtab) / sizeof(struct keytab)); /* Show command arguments */ #define SHPAR 0 /* Parameters */#define SHVER 1 /* Versions */ struct keytab shotab[] = { "parameters", SHPAR, 0, "versions", SHVER, 0};/* C M D I N I -- Initialize the interactive command parser */ cmdini() {#ifdef AMIGA congm(); concb(escape);#endif tlevel = -1; /* Take file level */ cmsetp("C-Kermit>"); /* 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);#ifdef AMIGA reqoff(); /* disable requestors */#endif 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; debug(F110,"init file",line,0); } else { debug(F100,"no init file","",0); } }#ifdef AMIGA reqpop(); /* restore requestors */#else congm(); /* Get console tty modes */#endif} /* Display version herald and initial prompt */herald() { if (!backgrd) printf("%s,%s\nType ? for help\n",versio,ckxsys);} /* T R A P -- Terminal interrupt handler */ trap() { debug(F100,"terminal interrupt...","",0); doexit(GOOD_EXIT); /* Exit indicating success */}/* S T P T R A P -- Handle SIGTSTP signals */stptrap() { conres(); /* Reset the console */#ifdef SIGTSTP kill(0, SIGSTOP); /* If job control, suspend the job */#else doexit(GOOD_EXIT); /* Probably won't happen otherwise */#endif concb(); /* Put console back in Kermit mode */}/* P A R S E R -- Top-level interactive command parser. */ parser() { int xx, cbn; char *cbp;#ifdef AMIGA reqres(); /* restore AmigaDOS requestors */#endif 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"); /*** Temporary kludge ***/ 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; lp = line; /* Got one, copy it. */ while (*cbp++ = *lp++) if (--cbn < 1) fatal("Command too long for internal buffer"); if (*(cbp - 3) == '\\') { /* Continued on next line? */ cbp -= 3; /* If so, back up pointer, */ goto again; /* go back, get next line. */ } stripq(cmdbuf); /* Strip any quotes from cmd buffer. */ } else { /* No take file, get typein. */ if (!backgrd) prompt(); /* Issue interactive prompt. */ cmini(ckxech); } repars = 1; displa = 0; while (repars) { cmres(); /* Reset buffer pointers. */ xx = cmkey(cmdtab,ncmd,"Command",""); debug(F101,"top-level cmkey","",xx); switch (docmd(xx)) { case -4: /* EOF */ doexit(GOOD_EXIT); /* ...exit successfully */ case -1: /* Reparse needed */ repars = 1; continue; case -2: /* Invalid command given */ if (backgrd) /* if in background, terminate */ fatal("Kermit command error in background execution"); if (tlevel > -1) { /* If in take file, quit */ ermsg("Kermit command error: take file terminated."); fclose(tfile[tlevel]); tlevel--; } cmini(ckxech); /* (fall thru) */ case -3: /* Empty command OK at top level */ default: /* Anything else (fall thru) */ repars = 0; /* No reparse, get new command. */ continue; } } }/* Got an action command; disable terminal interrupts and return start state */ if (!local) connoi(); /* Interrupts off only if remote */ return(sstate);}/* D O E X I T -- Exit from the program. */ doexit(exitstat) int exitstat; { ttclos(); /* Close external line, if any */ if (local) { strcpy(ttname,dftty); /* Restore default tty */ local = dfloc; /* And default remote/local status */ } if (!quiet) conres(); /* Restore console terminal. */ if (!quiet) connoi(); /* Turn off console interrupt traps. */ if (deblog) { /* Close any open logs. */ debug(F100,"Debug Log Closed","",0); *debfil = '\0'; deblog = 0; zclose(ZDFILE); } if (pktlog) { *pktfil = '\0'; pktlog = 0; zclose(ZPFILE); } if (seslog) { *sesfil = '\0'; seslog = 0; zclose(ZSFILE); } if (tralog) { tlog(F100,"Transaction Log Closed","",0l); *trafil = '\0'; tralog = 0; zclose(ZTFILE); } syscleanup(); exit(exitstat); /* Exit from the program. */}/* B L D L E N -- Make length-encoded copy of string */ char *bldlen(str,dest) char *str, *dest; { int len; len = strlen(str); *dest = tochar(len); strcpy(dest+1,str); return(dest+len+1);} /* S E T G E N -- Construct a generic command */ setgen(type,arg1,arg2,arg3) char type, *arg1, *arg2, *arg3; { char *upstr, *cp; cp = cmdstr; *cp++ = type; *cp = NUL; if (*arg1 != NUL) { upstr = bldlen(arg1,cp); if (*arg2 != NUL) { upstr = bldlen(arg2,upstr); if (*arg3 != NUL) bldlen(arg3,upstr); } } cmarg = cmdstr; debug(F110,"setgen",cmarg,0); return('g');}/* D O C M D -- Do a command */ /* Returns: -2: user typed an illegal command -1: reparse needed 0: parse was successful (even tho command may have failed).*/ docmd(cx) int cx; { int x, y; char *s; switch (cx) { case -4: /* EOF */ if (!quiet && !backgrd) printf("\r\n"); doexit(GOOD_EXIT);case -3: /* Null command */ return(0);case -2: /* Error */case -1: /* Reparse needed */ return(cx); case XXBYE: /* bye */ if ((x = cmcfm()) < 0) return(x); if (!local) { printf("You have to 'set line' first\n"); return(0); } sstate = setgen('L',"","",""); return(0); case XXCOM: /* comment */ if ((x = cmtxt("Text of comment line","",&s)) < 0) return(x); return(0); case XXCON: /* connect */ if ((x = cmcfm()) < 0) return(x); return(doconect()); case XXCWD:#ifdef AMIGA if (cmtxt("Name of local directory, or carriage return","",&s) < 0) return(-1); /* if no name, just print directory name */ if (*s) { if (chdir(s)) perror(s); cwdf = 1; } if (getcwd(line, sizeof(line)) == NULL) printf("Current directory name not available.\n"); else if (!backgrd) printf("%s\n", line);#else if (cmtxt("Name of local directory, or carriage return",homdir,&s) < 0) return(-1); if (chdir(s)) perror(s); cwdf = 1; system(PWDCMD);#endif return(0);case XXCLO: x = cmkey(logtab,nlog,"Which log to close",""); if (x == -3) { printf("?You must tell which log\n"); return(-2); } if (x < 0) return(x); if ((y = cmcfm()) < 0) return(y); switch (x) { case LOGD: if (deblog == 0) { printf("?Debugging log wasn't open\n"); return(0); } *debfil = '\0'; deblog = 0; return(zclose(ZDFILE)); case LOGP: if (pktlog == 0) { printf("?Packet log wasn't open\n"); return(0); } *pktfil = '\0'; pktlog = 0; return(zclose(ZPFILE)); case LOGS: if (seslog == 0) { printf("?Session log wasn't open\n"); return(0); } *sesfil = '\0'; seslog = 0; return(zclose(ZSFILE)); case LOGT:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -