📄 ckuus6.c
字号:
debug(F101,"GETC coninc","",x); } concb((char)escape); /* Put keyboard back in cbreak mode */ if (x > -1) { if (xcmdsrc == 0) printf("\r\n");#ifdef OS2 if (cx == XXGETK) { /* GETKEYCODE */ sprintf(tmp,"%d",x); /* SAFE */ } else {#endif /* OS2 */ tmp[0] = (char) (x & 0xff); tmp[1] = NUL;#ifdef OS2 }#endif /* OS2 */ y = addmac(vnp,tmp); /* Add it to the macro table. */ debug(F111,"getc/getk addmac",vnp,y); } else y = -1; cmsetp(psave); /* Restore old prompt. */ if (x < -1) { asktimedout = 1; if (!quiet && !nomsg) printf("?Timed out"); printf("\n"); } timelimit = 0; return(success = ((y < 0 ? 0 : 1) && (asktimedout == 0))); } else { /* ASK or ASKQ */#ifdef CK_RECALL on_recall = 0;#endif /* CK_RECALL */ y = cmdgquo(); /* Get current quoting */ cmdsquo(0); /* Turn off quoting */ while (x == -1) { /* Prompt till they answer */ x = cmtxt("Please respond.",dfanswer,&s,NULL); debug(F111,"ASK cmtxt",s,x); cmres(); } cmdsquo(y); /* Restore previous quoting */ if (cx == XXASKQ) /* ASKQ must echo CRLF here */ printf("\r\n"); if (x == -10 && dfanswer) { /* Don't fail on timeout if */ s = dfanswer; /* a default was specified */ asktimedout = 0; /* and don't fail */ x = 0; } if (x < 0) { /* If cmtxt parse error, */ cmsetp(psave); /* restore original prompt */#ifdef VMS if (cmdlvl > 0) /* In VMS and not at top level, */ conres(); /* restore console again. */#endif /* VMS */ if (x == -10) { /* Timed out with no response */ if (!nomsg) printf("?Timed out"); printf("\n"); asktimedout = 1; if (dfanswer) /* Supply default answer if any */ s = dfanswer; success = x = 0; /* (was "x = -9;") */ } timelimit = 0; return(x); /* and return cmtxt's error code. */ } if (!s || *s == NUL) { /* If user typed a bare CR, */ cmsetp(psave); /* Restore old prompt, */ delmac(vnp,0); /* delete variable if it exists, */#ifdef VMS if (cmdlvl > 0) /* In VMS and not at top level, */ conres(); /* restore console again. */#endif /* VMS */ timelimit = 0; return(success = 1); /* and return. */ } y = addmac(vnp,s); /* Add it to the macro table. */ debug(F111,"ask addmac",vnp,y); cmsetp(psave); /* Restore old prompt. */#ifdef VMS if (cmdlvl > 0) /* In VMS and not at top level, */ conres(); /* restore console again. */#endif /* VMS */ timelimit = 0; return(success = (y < 0 ? 0 : 1) && (asktimedout == 0)); }}#endif /* NOSPL */#ifndef NOSPLintdoincr(cx) int cx; { /* INCREMENT, DECREMENT */ char vnambuf[VNAML+1]; /* Buffer for variable names */ int eval = 0; eval = (cx == XX_DECR || cx == XX_INCR); if ((y = cmfld("Variable name","",&s, eval ? xxstring : NULL)) < 0) { if (y == -3) { printf("?Variable name required\n"); return(-9); } else return(y); } ckstrncpy(vnambuf,s,VNAML); if ((y = cmnum("by amount","1",10,&x,xxstring)) < 0) return(y); if ((y = cmcfm()) < 0) return(y); z = (cx == XX_INCR || cx == XXINC) ? 1 : 0; /* Increment or decrement? */ if (incvar(vnambuf,x,z) < 0) { printf("?Variable %s not defined or not numeric\n",vnambuf); return(success = 0); } return(success = 1);}/* Used by doundef() */static intxxundef(s,verbose,simulate) char * s; int verbose, simulate; { int rc = 0; if (!s) return(0); if (*s == CMDQ && *(s+1) == '%') { char c = *(s+2), * p = NULL; if (c >= '0' && c <= '9') { if (maclvl < 0) p = g_var[c]; else p = m_arg[maclvl][c - '0']; } else { if (isupper(c)) c += ('a'-'A'); if (c >= 'a' && c <= 'z') p = g_var[c]; } if (!p) return(-1); } if (verbose) printf(" %s ",s); if (simulate) { printf("(SELECTED)\n"); } else if ((x = delmac(s,1)) > -1) { /* Full name required */ rc = 1; if (verbose) printf("(OK)\n"); } else if (verbose) printf("(FAILED)\n"); return(rc);}/* Do the (_)DEFINE, (_)ASSIGN, and UNDEFINE commands */#define UND_MAT 1#define UND_VRB 2#define UND_EXC 3#define UND_SIM 3static struct keytab undefswi[] = { { "/list", UND_VRB, 0 },#ifdef COMMENT { "/except", UND_EXC, CM_ARG },#endif /* COMMENT */ { "/matching", UND_MAT, 0 }, { "/simulate", UND_SIM, 0 }, { "/verbose", UND_VRB, CM_INV }};static int nundefswi = sizeof(undefswi) / sizeof(struct keytab);#define UNDEFMAX 64static char ** undeflist = NULL;intdoundef(cx) int cx; { /* UNDEF, _UNDEF */ int i, j, n, rc = 0, arraymsg = 0; int domatch = 0, verbose = 0, errors = 0, simulate = 0, flag = 0; char *vnp, vnbuf[4];#ifdef COMMENT char *except = NULL;#endif /* COMMENT */ struct FDB sw, fl; int getval; char c; if (!undeflist) { /* Allocate list if necessary */ undeflist = (char **)malloc(UNDEFMAX * sizeof(char *)); if (!undeflist) { printf("?Memory allocation failure\n"); return(-9); } for (i = 0; i < UNDEFMAX; i++) undeflist[i] = NULL; } cmfdbi(&sw, /* First FDB - command switches */ _CMKEY, /* fcode */ "Variable name or switch", "", /* default */ "", /* addtl string data */ nundefswi, /* addtl numeric data 1: tbl size */ 4, /* addtl numeric data 2: 4 = cmswi */ xxstring, /* Processing function */ undefswi, /* Keyword table */ &fl /* Pointer to next FDB */ ); cmfdbi(&fl, /* Anything that doesn't match */ _CMFLD, /* fcode */ "", /* hlpmsg */ "", /* default */ "", /* addtl string data */ 0, /* addtl numeric data 1 */ 0, /* addtl numeric data 2 */ (cx == XXUNDEF) ? NULL : xxstring, NULL, NULL ); while (1) { /* Parse 0 or more switches */ x = cmfdb(&sw); /* Parse something */ if (x < 0) return(x); if (cmresult.fcode != _CMKEY) /* Break out if not a switch */ break; c = cmgbrk(); if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) { printf("?This switch does not take an argument\n"); return(-9); } switch (cmresult.nresult) { case UND_MAT: domatch = 1; break; case UND_SIM: simulate = 1; /* fall thru on purpose */ case UND_VRB: verbose = 1; break;#ifdef COMMENT case UND_EXC: if (!getval) break; if ((x = cmfld("Pattern","",&s,xxstring)) < 0) { if (x == -3) { printf("?Pattern required\n"); x = -9; } goto xgetx; } makestr(&except,cmresult.sresult); break;#endif /* COMMENT */ default: return(-2); } } n = 0; makestr(&(undeflist[n++]),cmresult.sresult); for (i = 1; i < UNDEFMAX; i++) { x = cmfld("Macro or variable name","",&s, ((cx == XXUNDEF) ? NULL : xxstring) ); if (x == -3) { if ((y = cmcfm()) < 0) return(y); break; } else if (y < 0) { return(y); } makestr(&(undeflist[n++]),s); } /* Now we have a list of n variables or patterns to undefine */ for (i = 0; i < n; i++) { flag = 0; if (!(vnp = undeflist[i])) continue; if (vnp[0] == CMDQ && (vnp[1] == '%' || vnp[1] == '&')) { flag++; vnp++; } if (!domatch) { /* Pattern match not requested */ if (flag) { if ((y = parsevar(vnp,&x,&z)) < 0) { vnp--; if (verbose) printf(" %s...error\n",vnp); continue; } vnp--; } x = xxundef(vnp,verbose,simulate); if (x > -1) { if (!x && !simulate) errors++; rc += x; } continue; } /* Pattern match requested */ if (!flag) { /* It's a macro */ for (j = 0; j < nmac; j++) { if (ckmatch(vnp,mactab[j].kwd,0,1)) { x = xxundef(mactab[j].kwd,verbose,simulate); if (x > -1) { rc += x; if (!x) errors++; } if (!simulate) j--; /* Because mactab shifted up */ } } } else if (vnp[0] == '%') { /* It's a \%x variable */ vnbuf[0] = CMDQ; vnbuf[1] = '%'; vnbuf[3] = NUL; for (j = '0'; j <= 'z'; j++) { /* 0..9 a..z */ vnbuf[2] = j; if (ckmatch(vnp,&vnbuf[1],0,1)) { x = xxundef(vnbuf,verbose,simulate); if (x > -1) { if (!x) errors++; rc += x; } } if (j == '9') j = (int)'a' - 1; /* 9 -> a */ } } else if (vnp[0] == '&') { if (!arraymsg && !quiet) { printf("?UNDEFINE /MATCH can't be used with arrays.\n"); printf("(Type HELP ARRAY to see other methods.)\n"); } arraymsg++; errors++; } } if (verbose) printf("undefined: %d, errors: %d\n",rc,errors); for (i = 0; i < UNDEFMAX; i++) { /* Check them all */ if (undeflist[i]) { /* in case we were interrupted */ free(undeflist[i]); /* previously... */ undeflist[i] = NULL; } } return(success = (errors == 0) ? 1 : 0);}intdodef(cx) int cx; { extern int xxdot; extern char ppvnambuf[]; int doeval = 0; char vnambuf[VNAML+1]; /* Buffer for variable names */ char *vnp; /* Pointer to same */ int k, mydot; mydot = xxdot; /* Copy */ xxdot = 0; /* and reset *//* In case we got here from a command that begins like ".\%a", cmkey() has already evaluated \%a, but we don't want that, so we retrieve the variable name from a special pre-evaluation buffer in the command module, and we undo the "unget word" that would be done because of the token, because if the variable was defined, it will unget its value rather than its name.*/ s = NULL; if (mydot && ppvnambuf[0] == '.' && ppvnambuf[1]) { s = ppvnambuf+1; unungw(); } if (!s) { if (cx == XXDFX || cx == XXASX) /* Evaluate variable name */ y = cmfld("Macro or variable name","",&s,xxstring); else /* Don't evaluate the variable name */ y = cmfld("Macro or variable name","",&s,NULL); if (y < 0) { if (y == -3) { printf("?Variable name required\n"); return(-9); } else return(y); } } k = strlen(s); if (k > VNAML) { printf("?Name too long: \"%s\"\n",s); return(-9); } ckstrncpy(vnambuf,s,VNAML);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -