📄 ckuus5.c
字号:
if (DeleteStartupFile) { debug(F101,"DeleteStartupFile",cmdfil,0); zdelet(cmdfil); } } return(0); /* End of init file or whatever. */ } }#ifdef MAC miniparser(1); if (sstate == 'a') { /* if cmd-. cancel */ debug(F100, "parser: cancel take due to sstate", "", sstate); sstate = '\0'; dostop(); return(0); /* End of init file or whatever. */ }#endif /* MAC */#else /* NOSPL */ if ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */ popclvl(); /* Pop up one level. */ cmini(ckxech); /* and clear the cmd buffer. */ if (tlevel < 0) /* Just popped out of cmd files? */ return(0); /* End of init file or whatever. */ }#endif /* NOSPL */#ifndef NOSPL if (cmdstk[cmdlvl].src == CMD_MD) { /* Executing a macro? */ debug(F100,"parser macro","",0); maclvl = cmdstk[cmdlvl].lvl; /* Get current level */ debug(F101,"parser maclvl","",maclvl); cbp = cmdbuf; /* Copy next cmd to command buffer. */ *cbp = NUL; if (*savbuf) { /* In case then-part of 'if' command */ strcpy(cbp,savbuf); /* was saved, restore it. */ *savbuf = '\0'; } else { /* Else get next cmd from macro def */ if (getncm(cbp,CMDBL) < 0) { if (m && (cmdlvl < inlevel)) return((int) sstate); else /* if (!m) */ continue; } } debug(F110,"cmdbuf from macro",cmdbuf,0); } else if (cmdstk[cmdlvl].src == CMD_TF)#else if (tlevel > -1) #endif /* NOSPL */ {#ifndef NOSPL if (*savbuf) { /* In case THEN-part of IF command */ strcpy(cmdbuf,savbuf); /* was saved, restore it. */ *savbuf = '\0'; } else#endif /* NOSPL */ /* Get next line from TAKE file */ if ((tfcode = getnct(cmdbuf,CMDBL,tfile[tlevel],0)) < 0) { if (tfcode < -1) { /* Error */ printf("?Error in TAKE command file: %s\n", (tfcode == -2) ? "Memory allocation failure" : "Line too long or contains NUL characters" ); dostop(); } continue; /* -1 means EOF */ } /* If interactive, get next command from user. */ } else { /* User types it in. */ if (pflag) prompt(xxstring); cmini(ckxech); } /* Now we know where next command is coming from. Parse and execute it. */ repars = 1; /* 1 = command needs parsing */ displa = 0; /* Assume no file transfer display */ while (repars) { /* Parse this cmd until entered. */ debug(F101,"parser top of while loop","",0); cmres(); /* Reset buffer pointers. */#ifdef OS2#ifdef COMMENT /* we check to see if a macro is waiting to be executed */ /* if so, we call domac on it */ if (cmdmac) { strncpy(cmdbuf, cmdmac, CMDBL); free(cmdmac); cmdmac = NULL; }#endif /* COMMENT */#endif /* OS2 */ bye_active = 0; xx = cmkey2(cmdtab,ncmd,"Command","",toktab,xxstring,1); debug(F101,"top-level cmkey2","",xx); if (xx == -5) { yy = chktok(toktab); debug(F101,"top-level cmkey token","",yy); ungword(); switch (yy) { case '#': xx = XXCOM; break; /* Comment */ case ';': xx = XXCOM; break; /* Comment */#ifndef NOSPL case ':': xx = XXLBL; break; /* GOTO label */#endif /* NOSPL */#ifndef NOPUSH#ifdef CK_REDIR case '<':#endif /* CK_REDIR */ case '@': case '!': if (!nopush) { switch(yy) {#ifdef CK_REDIR case '<': xx = XXFUN; break; /* REDIRECT */#endif /* CK_REDIR */ case '@': case '!': xx = XXSHE; break; /* Shell escape */ } } break;#endif /* NOPUSH */ default: printf("\n?Invalid - %s\n",cmdbuf); if (tlevel > -1) { printf("Command file: %s, line %d\n", tfnam[tlevel] ? tfnam[tlevel] : "", tfline[tlevel] ); } xx = -2; } }#ifndef NOSPL /* Special handling for IF..ELSE */ if (ifcmd[cmdlvl]) /* Count stmts after IF */ ifcmd[cmdlvl]++; if (ifcmd[cmdlvl] > 2 && xx != XXELS && xx != XXCOM) ifcmd[cmdlvl] = 0; /* Execute the command and take action based on return code. */ if (nulcmd) { /* Ignoring this command? */ xx = XXCOM; /* Make this command a comment. */ }#endif /* NOSPL */ zz = docmd(xx); /* Parse rest of command & execute. */ debug(F101,"docmd returns","",zz); debug(F110,"cmdbuf",cmdbuf,""); debug(F110,"atmbuf",atmbuf,"");#ifdef MAC if (tlevel > -1) { if (sstate == 'a') { /* if cmd-. cancel */ debug(F110, "parser: cancel take, sstate:", "a", 0); sstate = '\0'; dostop(); return(0); /* End of init file or whatever. */ } }#endif /* MAC */ switch (zz) { case -4: /* EOF (e.g. on redirected stdin) */ doexit(GOOD_EXIT,xitsta); /* ...exit successfully */ case -1: /* Reparse needed */ repars = 1; /* Just set reparse flag and... */ continue;#ifdef OS2 case -7: /* They typed a disk letter */ if (!zchdir((char *)cmdbuf)) { perror((char *)cmdbuf); success = 0; } else success = 1; repars = 0; continue; #endif /* OS2 */ case -6: /* Invalid command given w/no args */ case -2: /* Invalid command given w/args */#ifdef COMMENT#ifndef NOSPL /* This is going to be really ugly... */ yy = mlook(mactab,atmbuf,nmac); /* Look in macro table */ if (yy > -1) { /* If it's there */ if (zz == -2) { /* insert "do" */ char *mp; mp = malloc((int)strlen(cmdbuf) + 5); if (!mp) { printf("?malloc error 1\n"); return(-2); } sprintf(mp,"do %s ",cmdbuf); strcpy(cmdbuf,mp); free(mp); mp = NULL; } else sprintf(cmdbuf,"do %s %c",atmbuf, CR); if (ifcmd[cmdlvl] == 2) /* This one doesn't count! */ ifcmd[cmdlvl]--; debug(F111,"stuff cmdbuf",cmdbuf,zz); repars = 1; /* Go for reparse */ continue; } else { char *p; int n; p = cmdbuf; lp = line; n = LINBUFSIZ; if (cmflgs == 0) printf("\n"); if (zzstring(p,&lp,&n) > -1) printf("?Invalid: %s\n",line); else printf("?Invalid: %s\n",cmdbuf); } /* (fall thru...) */#else printf("?Invalid: %s\n",cmdbuf);#endif /* NOSPL */#else /* Not COMMENT */ printf("?Invalid: %s\n",cmdbuf);#endif /* COMMENT */ case -9: /* Bad, error message already done */ success = 0; debug(F110,"top-level cmkey failed",cmdbuf,0); /* If in background w/ commands coming stdin, terminate */ if (pflag == 0 && tlevel < 0) fatal("Kermit command error in background execution");/* Command retry feature, edit 190. If we're at interactive prompting level, reprompt the user with as much of the command as didn't fail.*/#ifdef CK_RECALL if (cm_retry && /* If command retry enabled... */#ifndef NOSPL (cmdlvl == 0) /* and at top (interactive) level... */ #else (tlevel < 0)#endif /* NOSPL */ ) { int len; char *p, *s; len = strlen(cmdbuf); /* Length of command buffer */ p = malloc(len + 1); /* Allocate space for copy */ if (p) { /* If we got the space */ strcpy(p,cmdbuf); /* copy the command buffer. */ /* Chop off final field, the one that failed. */ s = p + len - 1; /* Point to end */ while (*s == SP && s > p) /* Trim blanks */ s--; while (*s != SP && s > p) /* Trim last field */ s--; if (s > p) /* Keep the space */ s++; /* after last good field */ if (s >= p) /* Cut off remainder */ *s = NUL; cmini(ckxech); /* Reinitialize the parser */ strcpy(cmdbuf,p); /* Copy truncated cmd back */ free(p); /* Free temporary storage */ p = NULL; prompt(xxstring); /* Reprint the prompt */ printf("%s",cmdbuf); /* Reprint partial command */ repars = 1; /* Force reparse */ continue; } } else#endif /* CK_RECALL */ if (tlevel > -1) { printf("Command file: %s, line %d\n", tfnam[tlevel] ? tfnam[tlevel] : "", tfline[tlevel] ); } cmini(ckxech); /* (fall thru) */ case -3: /* Empty command OK at top level */ repars = 0; /* Don't need to reparse. */ continue; /* Go back and get another command. */ default: /* Command was successful. */#ifndef NOSPL debug(F101,"parser preparing to continue","",maclvl);#endif /* NOSPL */ repars = 0; /* Don't need to reparse. */ continue; /* Go back and get another command. */ } }#ifndef NOSPL debug(F101,"parser breaks out of while loop","",maclvl); if (m && (cmdlvl < inlevel)) return((int) sstate);#endif /* NOSPL */ }/* Got an action command, return start state. */ return((int) sstate);}#ifndef NOSPL/* OUTPUT command. Buffering and pacing added by L.I. Kirby, 5A(189), June 1993.*/#define OBSIZE 80 /* Size of local character buffer */static int obn; /* Buffer offset (high water mark) */static char obuf[OBSIZE+1]; /* OUTPUT buffer. */static char *obp; /* Pointer to output buffer. */_PROTOTYP( static int oboc, (char) );_PROTOTYP( static int xxout, (char *, int) );static int#ifdef CK_ANSICxxout(char *obuf, int obsize)#elsexxout(obuf, obsize) char *obuf; int obsize; #endif /* CK_ANSIC *//* xxout */ { /* OUTPUT command's output function */ int i, rc; debug(F101,"xxout obsize","",obsize); debug(F101,"xxout pacing","",pacing); debug(F111,"xxout string",obuf,strlen(obuf)); rc = 0; /* Initial return code. */ if (!obuf || (obsize <= 0)) /* Nothing to output. */ goto xxout_x; /* Return successfully */ rc = -1; /* Now assume failure */ if (pacing == 0) { /* Is pacing enabled? */ if ((local ? /* No, write entire string at once */ ttol((CHAR *)obuf, obsize) : /* to communications device */ conxo(obsize, obuf)) /* or to console */ != obsize) goto xxout_x; } else { for (i = 0; i < obsize; i++) { /* Write individual chars */ if ((local ? ttoc(obuf[i]) : conoc(obuf[i])) < 0) goto xxout_x; msleep(pacing); } } rc = 0; /* Success */ xxout_x: obn = 0; /* Reset count */ obp = obuf; /* and pointers */ return(rc); /* return our return code */}#ifdef COMMENT/* Macros for OUTPUT command execution, to make it go faster. */#define obfls() ((xxout(obuf,obn)<0)?-1:0)#define oboc(c) ((*obp++=(char)(c)),*obp=0,(((++obn)>=OBSIZE)?obfls():0))#else /* The macros cause some compilers to generate bad code. */static int#ifdef CK_ANSICoboc(char c)#elseoboc(c) char c;#endif /* CK_ANSIC *//* oboc */ { /* OUTPUT command's output function */ *obp++ = c; /* Deposit character */ *obp = NUL; /* Flush buffer if it's now full */ return(((++obn) >= OBSIZE) ? xxout(obuf,obn) : 0);}#endif /* COMMENT */#endif /* NOSPL */#ifndef NOSPL/* Routines for handling local variables -- also see popclvl(). */VOIDfreelocal(m) int m; { /* Free local variables */ struct localvar * v, * tv; /* at macro level m... */ debug(F101,"freelocal level","",m); if (m < 0) return; v = localhead[m]; /* List head for level m */ while (v) { if (v->lv_name) /* Variable name */ free(v->lv_name); if (v->lv_value) /* Value */ free(v->lv_value); tv = v; /* Save pointer to this node */ v = v->lv_next; /* Get next one */ if (tv) /* Free this one */ free(tv); } localhead[m] = (struct localvar *) NULL; /* Done, set list head to NULL */}intdolocal() { /* Do the LOCAL command */ int i, x, z, len; char * s, * p; char * list[65]; /* Up to 64 variables per line */ struct localvar * v, *prev; if ((x = cmtxt("Variable name(s)","",&s,NULL) < 0)) return(x); xwords(s,64,list,0); /* Break up line into "words" *//* loop thru variable list. if variable is defined, allocate a node for it, copy its value to the node, and undefine it.*/ if (v = localhead[cmdlvl]) { /* Already have some at this level? */ while (v) { /* Find end of list */ prev = v; v = v->lv_next; } } for (i = 1; i < 10 && list[i]; i++) { /* Go through the list */ if (*(list[i]) == CMDQ) { if (parsevar(list[i],&x,&z) < 0) /* Check for valid name */ continue; sprintf(tmpbuf,"\\fcontents(%s)",list[i]); /* Get definition */ } else { /* Macro */ sprintf(tmpbuf,"\\fdefinition(%s)",list[i]); /* Get def */ } s = line; /* Point to destination buffer */ x = LINBUFSIZ; /* Length of destination buffer */ zzstring(tmpbuf,&s,&x); /* Get definition *//* Name is in list[i], definition is in line[] */ v = (struct localvar *) malloc(sizeof(struct localvar)); if (!v) { printf("?Failure to allocate storage for local variables"); return(-9); } if (!localhead[cmdlvl]) /* If first, set list head */ localhead[cmdlvl] = v; else /* Otherwise link previous to this */ prev->lv_next = v; prev = v; /* And make this previous */ v->lv_next = (struct localvar *) NULL; /* No next yet */ if (!(v->lv_name = (char *) malloc((int) strlen(list[i]) + 1))) goto localbad; strcpy(v->lv_name, list[i]); /* Copy name into new node */ if (*line) { if (!(v->lv_value = (char *) malloc((int) strlen(line) + 1))) goto localbad;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -