📄 ckuus6.c
字号:
intdoask(cx) int cx; { extern int cmflgs, asktimer, timelimit;#ifdef CK_RECALL extern int on_recall;#endif /* CK_RECALL */ int popupflg = 0; int guiflg = 0; int nomsg = 0; int mytimer = 0;#ifdef CK_APC extern int apcactive, apcstatus;#endif /* CK_APC */ char dfbuf[1024]; /* Buffer for default answer */ char * dfanswer = NULL; /* Pointer to it */ char vnambuf[VNAML+1]; /* Buffer for variable names */ char *vnp = NULL; /* Pointer to same */ dfbuf[0] = NUL; vnambuf[0] = NUL;#ifdef CK_APC if ( apcactive != APC_INACTIVE && (apcstatus & APC_NOINP) ) { return(success = 0); }#endif /* CK_APC */ mytimer = asktimer; /* Inherit global ASK timer */ if (cx == XXASK || cx == XXASKQ) { struct FDB sw, fl; int getval; char c; if (cx == XXASKQ) /* Don't log ASKQ response */ debok = 0; cmfdbi(&sw, /* First FDB - command switches */ _CMKEY, /* fcode */ "Variable name or switch", "", /* default */ "", /* addtl string data */ nasktab, /* addtl numeric data 1: tbl size */ 4, /* addtl numeric data 2: 4 = cmswi */ xxstring, /* Processing function */ asktab, /* 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 */ NULL, 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); } if (!getval && (cmgkwflgs() & CM_ARG)) { printf("?This switch requires an argument\n"); return(-9); } switch (cmresult.nresult) { case ASK_QUI: nomsg = 1; break; case ASK_PUP: popupflg = 1; break; case ASK_GUI: guiflg = 1; break; case ASK_TMO: { if ((y = cmnum("seconds","1",10,&x,xxstring)) < 0) return(y); if (x < 0) x = 0; mytimer = x; break; } case ASK_DEF: { if ((y = cmfld("Text to supply if reply is empty", "",&s,xxstring)) < 0) return(y); ckstrncpy(dfbuf,s,1024); dfanswer = dfbuf; break; } default: return(-2); } } /* Have variable name, make copy. */ ckstrncpy(vnambuf,cmresult.sresult,VNAML); vnp = vnambuf; if (vnambuf[0] == CMDQ && (vnambuf[1] == '%' || vnambuf[1] == '&')) vnp++; y = 0; if (*vnp == '%' || *vnp == '&') { if ((y = parsevar(vnp,&x,&z)) < 0) return(y); } } else if (cx != XXGOK && cx != XXRDBL) { /* Get variable name */ if ((y = cmfld("Variable name","",&s,NULL)) < 0) { if (y == -3) { printf("?Variable name required\n"); return(-9); } else return(y); } ckstrncpy(vnambuf,s,VNAML); /* Make a copy. */ vnp = vnambuf; if (vnambuf[0] == CMDQ && (vnambuf[1] == '%' || vnambuf[1] == '&')) vnp++; y = 0; if (*vnp == '%' || *vnp == '&') { if ((y = parsevar(vnp,&x,&z)) < 0) return(y); } } if (cx == XXREA || cx == XXRDBL) { /* READ or READBLOCK command */ if ((y = cmcfm()) < 0) /* Get confirmation */ return(y); if (chkfn(ZRFILE) < 1) { /* File open? */ printf("?Read file not open\n"); return(success = 0); } if (!(s = (char *)readbuf)) { /* Where to read into. */ printf("?Oops, no READ buffer!\n"); return(success = 0); } y = zsinl(ZRFILE, s, readblock); /* Read a line. */ debug(F111,"read zsinl",s,y); if (y < 0) { /* On EOF or other error, */ zclose(ZRFILE); /* close the file, */ delmac(vnp,0); /* delete the variable, */ return(success = 0); /* and return failure. */ } else { /* Read was OK. */ readsize = (int) strlen(s); success = (addmac(vnp,s) < 0 ? 0 : 1); /* Define variable */ debug(F111,"read addmac",vnp,success); return(success); /* Return success. */ } } /* ASK, ASKQ, GETOK, or GETC */ if (cx == XXGOK) { /* GETOK can take switches */ struct FDB sw, fl; int getval; char c; cmfdbi(&sw, /* First FDB - command switches */ _CMKEY, /* fcode */ "Variable name or question prompt", "", /* default */ "", /* addtl string data */ nasktab, /* addtl numeric data 1: tbl size */ 4, /* addtl numeric data 2: 4 = cmswi */ xxstring, /* Processing function */ asktab, /* Keyword table */ &fl /* Pointer to next FDB */ ); cmfdbi(&fl, /* Anything that doesn't match */ _CMTXT, /* fcode */ "", /* hlpmsg */ "", /* default */ "", /* addtl string data */ 0, /* addtl numeric data 1 */ 0, /* addtl numeric data 2 */ NULL, 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); } if (!getval && (cmgkwflgs() & CM_ARG)) { printf("?This switch requires an argument\n"); return(-9); } switch (cmresult.nresult) { case ASK_PUP: popupflg = 1; break; case ASK_GUI: guiflg = 1; break; case ASK_TMO: { if ((y = cmnum("seconds","1",10,&x,xxstring)) < 0) return(y); if (x < 0) x = 0; mytimer = x; break; } case ASK_DEF: { if ((y = cmfld("Text to supply if reply is empty", "",&s,xxstring)) < 0) return(y); ckstrncpy(dfbuf,s,1024); dfanswer = dfbuf; break; } case ASK_QUI: nomsg = 1; break; default: return(-2); } } p = cmresult.sresult; } else if ((y = cmtxt("Prompt,\n\ enclose in { braces } or \" quotes \" to preserve leading and trailing\n\ spaces, precede question mark with backslash (\\).", "",&p,xxstring)) < 0) return(y); if (!p) p = "";#ifndef NOLOCAL#ifdef OS2 if (popupflg) { /* Popup requested */ int len = -1; ckstrncpy(tmpbuf,brstrip(p),TMPBUFSIZ); p = tmpbuf; if (cx == XXASK || cx == XXASKQ) { if (cx == XXASK) len = popup_readtext(vmode,NULL,p,line,LINBUFSIZ,mytimer); else len = popup_readpass(vmode,NULL,p,line,LINBUFSIZ,mytimer); asktimedout = ( len < 0 && mytimer ); } else if (cx == XXGOK) { printf("?Sorry, GETOK /POPUP not implemented yet\n"); timelimit = 0; return(-9); } if (len >= 0) { y = addmac(vnp,(char *)line); /* Add it to the macro table. */ } else if ( asktimedout && dfanswer ) { y = addmac(vnp,dfanswer); /* Add it to the macro table. */ asktimedout = 0; len = 0; } timelimit = 0; return(success = ((len >= 0) && (y >= 0)) && !asktimedout); }#ifdef KUI if (guiflg) { /* GUI requested */ int rc, n; char * s1; s1 = tmpbuf; n = TMPBUFSIZ-1; zzstring(brstrip(p),&s1,&n); p = tmpbuf; if (cx == XXASK || cx == XXASKQ) { rc = gui_txt_dialog(NULL,p,(cx == XXASK), line,LINBUFSIZ,dfanswer,mytimer); asktimedout = (rc == -1 && mytimer); if (rc == 1) { y = addmac(vnp,(char *)line); /* Add it to the macro table. */ } else if ( asktimedout && dfanswer ) { y = addmac(vnp,dfanswer); /* Add default to macro table. */ asktimedout = 0; rc = 1; } timelimit = 0; return(success = (rc == 1 && (y >= 0)) && !asktimedout); } else if (cx == XXGOK) { int x; x = lookup(yesno,dfanswer,nyesno,NULL); if (x != 1) x = 2; rc = uq_ok(NULL, p, 3, NULL, x); return(success = (rc == 1)); } }#endif /* KUI */#endif /* OS2 */#endif /* NOLOCAL */ concb((char)escape); /* Enter CBREAK mode */ cmsavp(psave,PROMPTL); /* Save old prompt */ cmsetp(brstrip(p)); /* Make new prompt */reprompt: if (cx == XXASKQ) { /* For ASKQ, */ cmini(0); /* no-echo mode. */ } else { /* For others, regular echoing. */ cmini(ckxech); } askflag = 1; x = -1; /* This means to reparse. */ cmflgs = 0; if (pflag) prompt(xxstring); /* Issue prompt. */ asktimedout = 0; /* Handle timed responses. */ timelimit = mytimer;reparse: cmres(); if (cx == XXGOK) { /* GETOK */#ifdef CK_RECALL on_recall = 0;#endif /* CK_RECALL */ askflag = 0; /* GETOK uses keyword table */ x = cmkey(yesno,nyesno,"",dfanswer,xxstring); if (x < 0) { /* Parse error */ if (x == -10) { char * ds; ds = dfanswer ? dfanswer : "No"; if (!nomsg) printf("?Timed out, assuming \"%s\"",ds); printf("\n"); asktimedout = 1; x = lookup(yesno,ds,nyesno,NULL); if (x != 1) x = 0; goto gokdone; } else if (x == -3) { /* No answer? */ printf("Please respond Yes or No\n"); /* Make them answer */ cmini(ckxech); goto reprompt; } else if (x == -1) { goto reparse; } else goto reprompt; } if (cmcfm() < 0) /* Get confirmation */ goto reparse; gokdone: askflag = 0; cmsetp(psave); /* Restore prompt */#ifdef VMS if (cmdlvl > 0) /* In VMS and not at top level, */ conres(); /* restore console again. */#endif /* VMS */ timelimit = 0; return(x); /* Return success or failure */ } else if (cx == XXGETC /* GETC */#ifdef OS2 || cx == XXGETK /* or GETKEYCODE */#endif /* OS2 */ ) { /* GETC */ char tmp[16]; conbin((char)escape); /* Put keyboard in raw mode */#ifndef NOSETKEY#ifdef OS2 if (cx == XXGETK) { /* GETKEYCODE */ extern int os2gks; int t; t = os2gks; /* Turn off kverb recognition */ os2gks = 0; x = congks(timelimit); /* Read a key event, blocking */ os2gks = t; /* Put back kverb recognition */ } else /* GETC */#endif /* OS2 */#endif /* NOSETKEY */ { debug(F101,"GETC conchk","",conchk()); x = coninc(timelimit); /* Just read one character */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -