⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comnd.c

📁 语法分析 编译原理 词法分析 语法分析 C++原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    case '\r':				/* Return */
	return (_CCEND);		/* Return end indication */

    case '?':				/* help ? */
	return (_CCHLP);		/*  give help */

    case '\033':			/* Escape */
	return (_CCCMP);		/* Completion */

    case '\006':			/* Control-F */
	return (_CCCMP);		/* Completion */

    default:				/* Other */
	return (_CCINC);		/* Just return incomplete */
    }
}
/*

*//* CMDcpt (CSBptr, cix)

	Checkpoint parse index


This routine checkpoints the parse by remembering that "cix" new
characters have been parsed.


Accepts :

	CSBptr		Address of command state block
	cix		Character index past old parse point


Returns


*/

int CMDcpt (CSBptr, cix)

CSB		*CSBptr;		/* Command state block addr */
int		cix;			/* Character index */

{
CSBptr -> CSB_PRS += cix;		/* Set checkpoint */
}
/*

*//* CMDcpl (CSBptr, str)

	Perform completion for a command string (element)

This routine attaches a string onto that already input, thus "completing"
a portion of the input string.


Accepts :

	CSBptr		Address of command state block
	str		string to add to input string


Returns :


Notes :

	As a side-effect, the parse-pointer is set to the end of the
string, since it is assumed that the completion was performed on the
say-so of a parsing routine.


*/

CMDcpl (CSBptr, str)

CSB		*CSBptr;		/* Addr of command state block */
char		*str;			/* Addr of string to add on */

{
IND	int	i;			/* Index */
IND	int	c;			/* Character */

i = CSBptr -> CSB_FLN;			/* Get filled length */
while ((c = *str++) != NUL)		/* Swap chars */
    {
    if (i >= (CSBptr -> CSB_BSZ-1))	/* Make sure it fits */
	{
	CMDpoc ('\007');
	break;
	}
    CSBptr -> CSB_BUF[i++] = c;		/*  store it. */
    CMDpoc (c);				/* Show it */
    }
CSBptr -> CSB_BUF[i] = NUL;		/* Put marker under end of string */
CSBptr -> CSB_FLN = i;			/* Update filled pointer */
CSBptr -> CSB_PRS = i;			/* Update parse pointer */
CMDfob();				/* Make it be seen */
}
/*

*//* CMDhlp (CFBptr, str)

	Assist in beginning to give help

Accepts :

	CFBptr		Address of command function block
	str		String to print as "default".

Returns :

	<value>		TRUE if default help processing should continue
			FALSE otherwise.

*/

int CMDhlp (CFBptr, str)

CFB		*CFBptr;		/* Addr of command function block */
char		*str;			/* String to print by default */

{
IND	int	flg;			/* Flags from CFB */

flg = CFBptr -> CFB_FLG;		/* Get flags */
if ((flg & _CFHPP) || !(flg & _CFSDH))	/* If help to be given */
    {
    if (CMDgvh)				/* See if we must give "or" */
	CMDpzs ("\n or ");		/*  give it. */
    else				/* Otherwise */
	CMDpoc (' ');			/*  make sure we give a space */
    }

if (flg & _CFHPP)			/* If any user help text */
    if (CFBptr -> CFB_HLP)		/*  If any... */
	CMDpzs (CFBptr -> CFB_HLP);	/*   print it */

if (flg & _CFSDH)			/* Suppress default ? */
    {
    CMDfob ();
    return (FALSE);			/* Yup, indicate that by return */
    }
CMDpzs (str);				/* Print his string */
CMDfob();
return (TRUE);				/* Tell him to continue */
}
/*

*//* CMDfill (CSBptr, CFBptr)

	Fill the command line into the text buffer.

This routine is called to fill or to continue filling text into the command
buffer which is indicated by the command state block.  It is responsible
for rubout and other command line editing function.

Accepts :

	CSBptr		Address of the command state block

	CFBptr		Address of the first CFB in the CFB chain

Returns :



*/

CMDfill (CSBptr, CFBptr)

CSB		*CSBptr;		/* Addr of CSB */
CFB		*CFBptr;		/* Addr of first CFB */

{
IND	int		c;		/* Character */
IND	int		i;		/* Scratch */
IND	int		col;		/* Column number */
IND	int		col1;		/* Another column number */
IND	int		recena;		/* Recovery enabled */
IND	int		hlpena;		/* If help enabled */

recena = FALSE;				/* Set recovery not enabled */
if (CSBptr -> CSB_FLN == -1)		/* but if it is */
    {
    CMDpzs (CSBptr -> CSB_PMT);		/* Output the prompt */
    CMDfob();				/* Make sure it is seen */
    CSBptr -> CSB_FLN = 0;		/* Reset filled length */
    recena = TRUE;			/* Set recovery enable */
    }

hlpena = TRUE;				/* Presume help is enabled */
i = CFBptr -> CFB_FLG;			/* Get flags from CFB */
if ((i & _CFSDH) && (!(i & _CFHPP)))	/* If no help provided for */
    hlpena = FALSE;			/*  then set help not enabled */

CSBptr -> CSB_RFL = CSBptr -> CSB_RFL & (~_CFRPT);
					/* Clear bits we want cleared */
col = CMDccol (CSBptr, CSBptr -> CSB_FLN); /* See what column we're at */

while (TRUE)
    {
    c = CMDgtc();			/* Get character */

/* Check specials */

    if (recena)				/* Recovery enabled ? */
	{
	recena = FALSE;			/* Not true after this */
	if (c == '\010')		/* control-h */
	    {
	    CSBptr -> CSB_FLN = CSBptr -> CSB_PRS;
					/* Set filled length to parse inx */
	    for (i = 0; i < CSBptr -> CSB_FLN; i++)
		CMDpoc (CSBptr -> CSB_BUF[i]);
	    CMDfob();			/* Show it */
	    col = CMDccol (CSBptr, CSBptr -> CSB_FLN);
	    CSBptr -> CSB_PRS = 0;	/* Parse from zero */
	    continue;
	    }
	CSBptr -> CSB_PRS = 0;		/* Parse from zero */
	}

    if ((c == '\010')			/* Backspace */
       || (c == '\177')			/*  or rubout */
       || (c == '\027')			/* or control-W */
       || (c == '\030'))		/* or control-X */
	{
	if ((i = CSBptr -> CSB_FLN-1) >= 0)	/* If anything accumulated */
	    {
	    if (c == '\027')		/* If control-W */
		{
		for (; i > 0; i--)	/* Find beginning of "field" */
		    {
		    c = CSBptr -> CSB_BUF[i-1];
		    if ((!isalpha(c)) && (!isdigit(c)))
			break;		/* Found it. */
		    }
		}
	    else if (c == '\030')	/* If control-X */
		i = 0;			/*  erase to beginning */
	    CSBptr -> CSB_FLN = i;	/* Set new index */
	    if (i <= CSBptr -> CSB_PRS)	/* If backed to parsed area */
		CSBptr -> CSB_RFL |= _CFRPT; /* Set reparse flag */
	    if (Echofl)			/* If echoing... */
		{
		col1 = CMDccol (CSBptr, i);
					/* Find out what column to go to */
		while (col > col1)	/* Wipe out back to there */
		    {
		    CMDpzs ("\010 \010"); /* <BSP><SPC><BSP> */
		    col--;
		    }
		CMDfob();
		}
	    }
	}


    else if (c == '\022')		/* Control-r */
	{
	if (Echofl)			/* If echoing */
	    {
	    CMDpzs ("^R\n");
	    CMDpzs (CSBptr -> CSB_PMT);	/* Output prompt */
	    for (i = 0; i < CSBptr -> CSB_FLN; i++)
		CMDpoc (CSBptr -> CSB_BUF[i]);
	    CMDfob();
	    }
	}

    else if (c == '\025')		/* Control-U */
	{
	CMDpzs ("^U\n");
	CSBptr -> CSB_FLN = 0;		/* Filled length is zero */
	if (Echofl)			/* If echoing */
	    CMDpzs (CSBptr -> CSB_PMT);	/*  re-issue prompt */
	col = CMDccol (CSBptr, 0);	/* Get accurate column number */
	CMDfob();
	if (CSBptr -> CSB_PRS > 0)	/* If backed before parsed area */
	    CSBptr -> CSB_RFL |= _CFRPT; /* Set reparse flag */
	}

    else				/* Anything else */
	{
	if (CSBptr -> CSB_PFL & _CFRAI) /* Raise lowercase? */
	    c = toupper(c);		/* Make it upper */
	CSBptr -> CSB_BUF[CSBptr -> CSB_FLN] = c;
					/* Store char */

	if (c == '\r')			/* If return */
	    {
	    CMDpoc ('\n');
	    return;
	    }

	if (hlpena && (c == '?'))	/* Check for help request */
	    {
	    CMDpoc (c);
	    CMDfob();
	    return;
	    }

	if ((c == '\006')		/* control-F */
	 || (c == '\027')		/* Control-W */
	 || (c == '\033')		/* Escape */
	   )
	    return;			/* Return OK, go parse */

	if (c == '\026')		/* Control-V, literal next char */
	    {
	    c = CMDgtc();		/*  get another one */
	    CSBptr -> CSB_BUF[CSBptr -> CSB_FLN] = c;
	    }

	if (++(CSBptr -> CSB_FLN) >= (CSBptr -> CSB_BSZ-1))
	    {				/*  if full . . */
	    CMDpoc ('\007');		/*  beep at him */
	    CMDfob ();			/* Make sure it is heard */
	    CSBptr -> CSB_FLN--;	/* Don't store it. */
	    }

	else if (c == '\011')		/* tab... */
	    {
	    col = (col+8)&-8;		/* Compute next column */
	    if (Echofl)
		{
		CMDpoc (c);		/* Echo it if ok */
		CMDfob();
		}
	    }

	else if (c < ' ')		/* Control char ? */
	    {
	    col += 2;			/* Update col by 2 */
	    if (Echofl)			/* If echoing */
		{
		CMDpoc ('^');		/* Carat */
		CMDpoc (c+'@');		/* Valid char */
		CMDfob();
		}
	    }

	else				/* Any other char */
	    {
	    col++;			/* Bump col */
	    if (Echofl)			/* If echoing */
		{
		CMDpoc (c);		/* echo it */
		CMDfob();
		}
	    }
	}
    }
}
/*

*//* CMDccol (CSBptr, cix)

	Count column position

This routine counts the column position for a particular point in the
command buffer input stream.  The prompt buffer is included in this
calculation.


Accepts :

	CSBptr		Address of command state block
	cix		Character index to consider

Returns :

	<value>		Column number, zero-based.

*/

int CMDccol (CSBptr, cix)

CSB		*CSBptr;		/* Addr of CSB */
int		cix;			/* Character index */

{
IND	int	c;			/* Char */
IND	int	w;			/* Which string being considered */
					/* 0 = prompt, 1 = text */
IND	char	*sptr;			/* String pointer */
IND	int	col;			/* Column # accumulator */


col = 0;				/* Init col # */
sptr = CSBptr -> CSB_PMT;		/* Look at prompt buffer first */
for (w = 0; w < 2; w++)			/* Step through 2 strings */
    {
    while ((c = *sptr++) != NUL)	/* Look at the string */
	{
	if (w == 1)			/* If text string */
	    if (cix-- == 0)		/* If at desired index */
		break;			/* be done */
	if (c == '\011')		/* If tab */
	    col = (col+8)&(-8);		/* Calc next position */
	else if (c < ' ')		/* Control char ? */
	    col += 2;			/*  count carat, and char */
	else				/* anything else */
	    col++;			/* counts as one */
	}
    sptr = CSBptr -> CSB_BUF;		/* Do text buffer now */
    }

return (col);				/* Return the value */
}

/*

*//* CMDpoc(c)

	Output character.

*/

CMDpoc(c)

int			c;

{
(*Cocrtc)(c);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -