📄 ckuus7.c
字号:
if ((y = cmcfm()) < 0) return(y); *prm = x; return(1);}/* S E T C C -- Set parameter var to an ASCII control character value. *//* Parses a number, or a literal control character, or a caret (^) followed by an ASCII character whose value is 63-95 or 97-122, then gets confirmation, then sets the parameter to the code value of the character given. If there are any parse errors, they are returned, otherwise on success 1 is returned.*/intsetcc(dflt,var) char *dflt; int *var; { int x, y; unsigned int c; char *hlpmsg = "Control character,\n\ numeric ASCII value,\n\ or in ^X notation,\n\ or preceded by a backslash and entered literally"; /* This is a hack to turn off complaints from expression evaluator. */ x_ifnum = 1; y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */ x_ifnum = 0; /* Allow complaints again */ if (y < 0) { /* Parse failed */ if (y != -2) /* Reparse needed or somesuch */ return(y); /* Pass failure back up the chain */ } /* Did they type a real control character? */ for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */ if (atmbuf[c] == SP) atmbuf[c] = NUL; if (y < 0) { /* It was not a number */ if ((c = atmbuf[0]) && !atmbuf[1]) { /* Was it a literal Ctrl char? */ if ((c > 037) && (c != 0177)) { printf("\n?Not a control character - %d\n",c); return(-9); } else { if ((y = cmcfm()) < 0) /* Confirm */ return(y); *var = c; /* Set the variable */ return(1); } } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */ c = atmbuf[1]; if (islower((char) c)) /* Uppercase lowercase letters */ c = toupper(c); if (c > 62 && c < 96) { /* Check range */ if ((y = cmcfm()) < 0) return(y); *var = ctl(c); /* OK */ return(1); } else { printf("?Not a control character - %s\n", atmbuf); return(-9); } } else { /* Something illegal was typed */ printf("?Invalid - %s\n", atmbuf); return(-9); } } if ((x > 037) && (x != 0177)) { /* They typed a number */ printf("\n?Not in ASCII control range - %d\n",x); return(-9); } if ((y = cmcfm()) < 0) /* In range, confirm */ return(y); *var = x; /* Set variable */ return(1);}#ifndef NOSPL /* The SORT command... */static struct keytab srtswtab[] = { /* SORT command switches */ "/case", SRT_CAS, CM_ARG, "/key", SRT_KEY, CM_ARG, "/numeric", SRT_NUM, 0, "/range", SRT_RNG, CM_ARG, "/reverse", SRT_REV, 0};static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);extern char **a_ptr[]; /* Array pointers */extern int a_dim[]; /* Array dimensions */intdosort() { /* Do the SORT command */ char c, *p = NULL, ** ap, ** xp = NULL; struct FDB sw, fl, cm; int hi, lo; int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0; int getval = 0, range[2], confirmed = 0; cmfdbi(&sw, /* First FDB - command switches */ _CMKEY, /* fcode */ "Array name or switch", "", /* default */ "", /* addtl string data */ nsrtswtab, /* addtl numeric data 1: tbl size */ 4, /* addtl numeric data 2: 4 = cmswi */ NULL, /* Processing function */ srtswtab, /* Keyword table */ &fl /* Pointer to next FDB */ ); cmfdbi(&fl, /* Anything that doesn't match */ _CMFLD, /* fcode */ "Array name", /* hlpmsg */ "", /* default */ "", /* addtl string data */ 0, /* addtl numeric data 1 */ 0, /* addtl numeric data 2 */ NULL, NULL, &cm ); cmfdbi(&cm, /* Or premature confirmation */ _CMCFM, /* fcode */ "", /* hlpmsg */ "", /* default */ "", /* addtl string data */ 0, /* addtl numeric data 1 */ 0, /* addtl numeric data 2 */ NULL, NULL, NULL ); range[0] = -1; range[1] = -1; while (1) { /* Parse 0 or more switches */ x = cmfdb(&sw); if (x < 0) return(x); if (cmresult.fcode != _CMKEY) /* Break out if not a switch */ break; c = cmgbrk(); getval = (c == ':' || c == '='); if (getval && !(cmresult.kflags & CM_ARG)) { printf("?This switch does not take arguments\n"); return(-9); } switch (cmresult.nresult) { case SRT_REV: xr = 1; break; case SRT_KEY: if (getval) { if ((y = cmnum("Column for comparison (1-based)", "1",10,&x,xxstring)) < 0) return(y); xk = x - 1; } else xk = 0; break; case SRT_CAS: if (getval) { if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y); xc = y; } else xc = 1; break; case SRT_RNG: /* /RANGE */ if (getval) { char buf[32]; char buf2[16]; int i; char * p, * q; if ((y = cmfld("low:high element","1",&s,NULL)) < 0) return(y); s = brstrip(s); ckstrncpy(buf,s,32); p = buf; for (i = 0; *p && i < 2; i++) { /* Get low and high */ q = p; /* Start of this piece */ while (*p) { /* Find end of this piece */ if (*p == ':') { *p = NUL; p++; break; } p++; } y = 15; /* Evaluate this piece */ s = buf2; zzstring(q,&s,&y); s = evalx(buf2); if (s) if (*s) ckstrncpy(buf2,s,16); if (!rdigits(buf2)) { printf("?Not numeric: %s\n",buf2); return(-9); } range[i] = atoi(buf2); } } break; case SRT_NUM: /* /NUMERIC */ xn = 1; break; default: return(-2); } } switch (cmresult.fcode) { case _CMCFM: confirmed = 1; break; case _CMFLD: ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */ s = line; break; default: printf("?Unexpected function code: %d\n",cmresult.fcode); return(-9); } if (confirmed) { printf("?Array name required\n"); return(-9); } sprintf(tmpbuf,"Second array to sort according to %s",s); debug(F101,"XXX 1","",0); if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0) if (x != -3) return(x); debug(F101,"XXX 2","",0); tmpbuf[0] = NUL; strcpy(tmpbuf,p); p = tmpbuf; if ((x = cmcfm()) < 0) /* Get confirmation */ return(x); debug(F101,"XXX 3","",0); x = arraybounds(s,&lo,&hi); /* Get array index & bounds */ if (x < 0) { /* Check */ printf("?Bad array name: %s\n",s); return(-9); } if (lo > -1) range[0] = lo; /* Set range */ if (hi > -1) range[1] = hi; ap = a_ptr[x]; /* Get pointer to array element list */ if (!ap) { /* Check */ printf("?Array not declared: %s\n", s); return(-9); } if (range[0] < 0) /* Starting element */ range[0] = 1; if (range[1] < 0) /* Final element */ range[1] = a_dim[x]; if (range[1] > a_dim[x]) { printf("?range %d:%d exceeds array dimension %d\n", range[0],range[1],a_dim[x] ); return(-9); } ap += range[0]; xs = range[1] - range[0] + 1; /* Number of elements to sort */ if (xs < 1) { /* Check */ printf("?Bad range: %d:%d\n",range[0],range[1]); return(-9); } if (xk < 0) xk = 0; /* Key position */ if (xr < 0) xr = 0; /* Reverse flag */ if (xn) /* Numeric flag */ xc = 2; else if (xc < 0) /* Not numeric */ xc = inpcas[cmdlvl]; /* so alpha case option */ if (*p) { /* Parallel array given? */ y = xarray(p); /* Yes, get its index. */ if (y < 0) { printf("?Bad array name: %s\n", p); return(-9); } if (y != x) { /* If the 2 arrays are different */ xp = a_ptr[y]; /* Pointer to 2nd array element list */ if (!xp) { printf("?Array not declared: %s\n", p); return(-9); } if (a_dim[y] < range[1]) { printf("?Array %s smaller than %s\n", p, s); return(-9); } xp += range[0]; /* Set base to same as 1st array */ } } debug(F101,"XXX xp","",xp); debug(F101,"XXX xc","",xc); sh_sort(ap,xp,xs,xk,xr,xc); /* Sort the array(s) */ return(success = 1); /* Always succeeds */}#endif /* NOSPL */static struct keytab purgtab[] = { /* PURGE command switches */ "/after", PU_AFT, CM_ARG, "/ask", PU_ASK, 0, "/before", PU_BEF, CM_ARG, "/delete", PU_DELE, CM_INV,#ifdef UNIXOROSK "/dotfiles", PU_DOT, 0,#endif /* UNIXOROSK */ "/except", PU_EXC, CM_ARG, "/heading", PU_HDG, 0, "/keep", PU_KEEP, CM_ARG, "/larger-than", PU_LAR, CM_ARG, "/list", PU_LIST, 0, "/log", PU_LIST, CM_INV, "/noask", PU_NASK, 0, "/nodelete", PU_NODE, CM_INV,#ifdef UNIXOROSK "/nodotfiles", PU_NODOT,0,#endif /* UNIXOROSK */ "/noheading", PU_NOH, 0, "/nol", PU_NOLI, CM_INV|CM_ABR, "/nolist", PU_NOLI, 0, "/nolog", PU_NOLI, CM_INV,#ifdef CK_TTGWSIZ "/nopage", PU_NOPA, 0,#endif /* CK_TTGWSIZ */ "/not-after", PU_NAF, CM_ARG, "/not-before", PU_NBF, CM_ARG, "/not-since", PU_NAF, CM_INV|CM_ARG,#ifdef CK_TTGWSIZ "/page", PU_PAGE, 0,#endif /* CK_TTGWSIZ */ "/quiet", PU_QUIE, CM_INV,#ifdef RECURSIVE "/recursive", PU_RECU, 0,#endif /* RECURSIVE */ "/since", PU_AFT, CM_ARG|CM_INV, "/simulate", PU_NODE, 0, "/smaller-than", PU_SMA, CM_ARG, "/verbose", PU_VERB, CM_INV};static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);intbkupnum(s,i) char * s; int *i; { int k = 0, pos = 0; char * p = NULL, *q; *i = pos; if (!s) s = ""; if (!*s) return(-1); if ((k = strlen(s)) < 5) return(-1); if (s[k-1] != '~') return(-1); pos = k - 2; q = s + pos; while (q >= s && isdigit(*q)) { p = q--; pos--; } if (!p) return(-1); if (q < s+2) return(-1); if (*q != '~' || *(q-1) != '.') return(-1); pos--; *i = pos; debug(F111,"bkupnum",s+pos,pos); return(atoi(p));}#ifdef CKPURGE/* Presently only for UNIX because we need direct access to the file array. *//* Not needed for VMS anyway, because we don't make backup files there. */#define MAXKEEP 32 /* Biggest /KEEP: value */static int pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;#ifdef CK_TTGWSIZstatic int pu_page = -1;#elsestatic int pu_page = 0;#endif /* CK_TTGWSIZ */#ifndef NOSHOWVOIDshowpurgopts() { /* SHOW PURGE command options */ int x = 0; extern int optlines; prtopt(&optlines,"PURGE"); if (pu_ask > -1) { x++; prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK"); }#ifdef UNIXOROSK if (pu_dot > -1) { x++; prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES"); }#endif /* UNIXOROSK */ if (pu_keep > -1) { x++; sprintf(tmpbuf, "%s:%d", "/KEEP", pu_keep); prtopt(&optlines,tmpbuf); } if (pu_list > -1) { x++; prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST"); } if (pu_hdg > -1) { x++; prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING"); }#ifdef CK_TTGWSIZ if (pu_page > -1) { x++; prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE"); }#endif /* CK_TTGWSIZ */ if (!x) prtopt(&optlines,"(no options set)"); prtopt(&optlines,"");}#endif /* NOSHOW */intsetpurgopts() { /* Set PURGE command options */ int c, z, getval = 0; int x_keep = -1, x_list = -1, x_page = -1, x_hdg = -1, x_ask = -1, x_dot = -1; while (1) { if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) { if (y == -3) break; else return(y); } c = cmgbrk(); if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) { printf("?This switch does not take an argument\n"); return(-9); } if (!getval && (cmgkwflgs() & CM_ARG)) { printf("?This switch requires an argument\n"); return(-9); } switch (y) { case PU_KEEP: z = 1; if (c == ':' || c == '=') if ((y = cmnum("How many backup files to keep", "1",10,&z,xxstring)) < 0) return(y); if (z < 0 || z > MAXKEEP) { printf("?Please specify a number between 0 and %d\n", MAXKEEP ); return(-9); } x_keep = z; break; case PU_LIST: case PU_VERB: x_list = 1; break; case PU_QUIE: case PU_NOLI: x_list = 0; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -