📄 cmdpf1.c
字号:
{
IND int c; /* Character */
c = CMDgcc (CSBptr, CMDspc(CSBptr)); /* Get the character that's next */
switch (c) /* Process it */
{
case _CCINC: /* Incomplete */
return (_CPAGN); /* just continue parsing */
case _CCCMP: /* Completion... */
CMDbel++; /* Indicate our desire to beep */
return (_CPAGN); /* Try again. */
case _CCHLP: /* Help */
CMDhlp (CFBptr, "confirm with carriage return");
return (_CPGVH); /* Indicate help given */
case _CCEND: /* End? */
return (_CPSUCC); /* we was successful */
default: /* Anything else */
return (_CPNOP); /* no parse */
}
}
/*
*//* CFPkey (CSBptr, CFBptr, ccptr)
Function parse for type=_CMKEY, keyword parse.
This routine handles parsing for type _CMKEY, a table of keywords.
Basically, it hands off to CFPgky, the general keyword parser.
Accepts :
CSBptr Address of command state block
CFBptr Address of command function block
ccptr Address of CC table (where appropriate)
Returns :
<value> Parse result, one of the _CPxxx values, as defined
in "comndi.h"
*/
CFPkey (CSBptr, CFBptr, ccptr)
CSB *CSBptr; /* Addr of command state block */
CFB *CFBptr; /* Addr of command function block */
WORD *ccptr; /* Addr of CC table */
{
return (CFPgky (CSBptr, CFBptr, CFBptr -> CFB_DAT, CFPktf, ccptr));
}
/*
*//* CFPgsk (CSBptr, CFBptr, ccptr)
Function parse for type=_CMGSK, general keyword.
This routine handles parsing for type _CMGSK, where a method of fetching
each candidate keyword is provided. CFB_DAT contains the address of a
CGK block, which in turns specifies a routine to call to get a pointer
to a keyword's pointer when given a specified base (also in CGK) and
the address of the previous pointer.
This routine calls CFBgky, the general keyword parser.
Accepts :
CSBptr Address of command state block
CFBptr Address of command function block
ccptr Address of CC table (where appropriate)
Returns :
<value> Parse result, one of the _CPxxx values, as defined
in "comndi.h"
*/
CFPgsk (CSBptr, CFBptr, ccptr)
CSB *CSBptr; /* Addr of command state block */
CFB *CFBptr; /* Addr of command function block */
WORD *ccptr; /* Addr of CC table */
{
IND CGK *CGKptr; /* Points to COMND Genl Kwd block */
CGKptr = (CGK *) CFBptr -> CFB_DAT; /* Get addr of CGK block */
return (CFPgky (CSBptr, CFBptr, CGKptr->CGK_BAS, CGKptr->CGK_KFR, ccptr));
}
/*
*//* CFPgky (CSBptr, CFBptr, base, kfr, ccptr)
General keyword parse.
This routine handles parsing for strings, using a general keyword fetch
mechanism.
Accepts :
CSBptr Address of command state block
CFBptr Address of command function block
base A base variable to pass to the keyword fetch
routine (we don't need to know what it is).
kfr Address of the routine to fetch strings.
ccptr Addr of CC table to use.
Returns :
<value> Parse status, _CPxxx as defined in comndi.h.
*/
CFPgky (CSBptr, CFBptr, base, kfr, ccptr)
CSB *CSBptr; /* Addr of command state block */
CFB *CFBptr; /* Addr of command function block */
char *base; /* Some base pointer */
char **(*kfr)(); /* Addr of routine to fetch ptr
to next string */
WORD *ccptr; /* Addr of CC table */
{
IND int ec; /* End char (action char, if any) */
IND BYTE c,c1; /* A character */
IND char **entptr; /* Entry pointer pointer */
IND char *entstr; /* Entry string pointer */
IND char **matptr,**mat1; /* Two previous matches */
IND char *matend; /* End of matched string */
IND BYTE *wrdptr; /* Pointer to the word */
IND int cix; /* Command index */
IND int hcol; /* Help display column # */
IND char *hptr; /* start of help pointer */
IND int i; /* Scratch */
hptr = NULL; /* Init start-of-help pointer */
if (CFBptr -> CFB_FLG & _CFHPP) /* If user-supplied help */
hptr = ""; /* don't US say "keyword" */
if (hptr == NULL) /* Now if no start-of-help */
hptr = "keyword, "; /* use our own */
/* Collect the command string into the atom buffer, for starts. */
cix = CMDcab (CSBptr, /* Collect atom buffer */
CSBptr -> CSB_ABF, /* where to put it */
CSBptr -> CSB_ASZ, /* how big it is */
ccptr, /* Char table */
&ec, /* What the end char is */
CMDspc(CSBptr)); /* Initial parse index */
if (ec == _CCINV) /* If invalid delimiter */
return (_CPNOP); /* return no-parse */
/* Now attempt to match the string in the atom buffer according to
strings given. */
entptr = NULL; /* Init entry pointer */
matptr = NULL; /* No match yet */
mat1 = NULL; /* No first match */
while ((entptr = (*kfr)(base, entptr)) != NULL)
/* End of table is a null entry */
{
entstr = *entptr; /* Get pointer to string */
wrdptr = CSBptr -> CSB_ABF; /* Get pointer to atom buffer */
while (TRUE) /* Scan to end of word */
{
c = *wrdptr++;
c = toupper(c); /* Get its uppercase */
c1 = *entstr++; /* Get next char from table ent */
if (c == NUL) /* If end of our string */
break; /* go check more */
if (c != toupper(c1)) /* if mismatch */
break; /* be done */
}
if (c == NUL) /* If end of word, we matched */
{
if (ec == _CCHLP) /* Give help ? */
{
if (!matptr) /* No other match... */
matptr = entptr; /* Remember it */
else /* Must print as help */
{
if (!mat1) /* If must print help message */
{
mat1 = matptr;
if (CMDhlp (CFBptr, hptr))
{
CMDpzs ("one of the following:\n");
CMDpzs (*matptr);
hcol = strlen (*matptr);
}
}
i = hcol;
hcol = (hcol+16)&(-16); /* Next tab stop */
if (!(CFBptr -> CFB_FLG & _CFSDH)) /* If not suppressed */
{
if (hcol + strlen(*entptr) > 79)
{
hcol = 0;
CMDpoc ('\n');
}
else
{
CMDpoc ('\011');
if (hcol-i > 8)
CMDpoc ('\011');
}
CMDpzs (*entptr);
hcol += strlen(*entptr);
}
}
continue;
}
if (c1 == NUL) /* If also end of entry , real match */
{
matptr = entptr; /* Set match to this entry */
matend = entstr-1; /* Remember completion ptr */
mat1 = NULL; /* Disambiguate */
break; /* Go return it. */
}
else
{
if (matptr) /* Any other ambig match ? */
mat1 = matptr; /* flag it */
else /* Otherwise */
{
matptr = entptr; /* remember this one */
matend = entstr-1; /* Point to rest-of-string */
}
}
}
}
/* Here, scanned table. */
if (mat1 && matptr) /* If multiply matched */
{
switch (ec) /* Process according to final char */
{
case _CCHLP: /* Gave help already? */
CMDfob(); /* Show what we did */
return (_CPGVH); /* Return that status */
case _CCCMP: /* Complete */
CMDbel++; /* Say we would beep */
case _CCINC: /* Incomplete input? */
return (_CPAGN); /* Try again */
case _CCEND: /* End of line */
return (_CPNOP); /* No match. */
default:
return (_CPNOP); /* Ambiguous with some other junk,
give failure. */
}
}
if (matptr) /* Any match at all ? */
{
CSBptr->CSB_RVL._ADR = matptr; /* Pass back the result. */
switch (ec) /* Process according to action char */
{
case _CCHLP: /* Give help */
if (CMDhlp (CFBptr, hptr))
{
CMDpzs ("only choice is: ");
CMDpzs (*matptr);
}
CMDfob();
return (_CPGVH); /* Gave help */
case _CCCMP: /* Complete */
CMDcpl (CSBptr, matend); /* Complete with end of match */
CMDcpl (CSBptr, " "); /* Add space */
return (_CPCPE); /* Completed with escape */
case _CCINC: /* Incomplete */
return (_CPAGN); /* Try again with more */
default: /* Anything else */
if (*CSBptr -> CSB_ABF == NUL)
return (_CPNOP); /* If null entry, no parse */
CMDcpt (CSBptr, cix); /* Checkpoint parse to here */
return (_CPSUCC); /* Success */
}
}
else /* No match at all */
{
switch (ec) /* Depends on final char */
{
default: /* Anything */
return (_CPNOP); /* no parse */
}
}
}
/*
*//* CFPktf (base, str)
Returns address of next string in a table of pointers to strings
This is a general keyword address fetcher for use in the _CMKEY parse
function. It accepts the address of a string ptr, and returns the address
of the next one.
Accepts :
base Address of the base of the table
str Address of a pointer to the previous string, or
NULL to indicate fetching the first string.
Note: this routine deals in address of POINTERS because it points to
the table entry, in general, where the table is composed of pointers
to strings. Get it?
Returns :
<value> Address of the next string, or
NULL if no more.
*/
char **CFPktf (base, str)
char *base[]; /* Table address */
char **str; /* Addr of string pointer */
{
if (str == NULL) /* If pointer is NULL */
{
if (*base == NULL) /* If empty table */
return (NULL); /* return end */
return (base); /* Return base address */
}
if (*++str == NULL) /* If next entry is NULL */
return (NULL); /* then return END */
else /* Otherwise */
return (str); /* return the pointer */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -