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

📄 cmdpf1.c

📁 语法分析 编译原理 词法分析 语法分析 C++原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	cmdpf1.c	COMND module; COMND parsing routines, set # 1

	Copyright (C) 1985 Mark E. Mallett

	Permission is hereby granted to distribute this file indiscriminately.

	This file contains parsing routines for various individual
function codes, as well as the function-code decoder (?).

Edit history

When	Who	What
------	---	--------------------------------
84xxxx	MEM	Create file.


	Routines included are:

		CMDpf		Function parsing controller.
		CFPini		Initialize parse
		CFPnoi		Noise word (guide word) parsing
		CFPcfm		Confirm (carriage return)
		CFPkey		Parse keyword from table of keywords
		CFPgky		General keyword parser
		CFPktf		Keyword table fetch routine
*/


#include "stdio.h"			/* Standard system defs */
#include "comnd.h"			/* COMND interface definitions */
#include "comndi.h"			/* COMND internal definitions */


/* External/forward routines */

extern	int	CFPcfm();		/* Confirm */
extern	int	CFPdat();		/* Date and Time */
extern	int	CFPgsk();		/* General Storage Keyword */
extern	int	CFPini();		/* Initialize parse */
extern	int	CFPkey();		/* Keyword parse */
extern	char	**CFPktf();		/* Keyword fetch routine */
extern	int	CFPnoi();		/* Noise words (guide string) */
extern	int	CFPnum();		/* Number */
extern	int	CFPswi();		/* Switch */
extern	int	CFPtok();		/* Token */
extern	int	CFPtxt();		/* Text to end of line */
extern	int	CFPuqs();		/* Unquoted string */

/* External data */

extern	int	CMDbel;			/* Beep flag */

/* Internal (public) routines */



/* Internal (public) data */


/* Local (static) data */



static	WORD	CCkey[] = {		/* CC for keywords */
			0x0000,		/* ^@ ^A ^B ^C ^D ^E ^F ^G */
			0x3000,		/* ^H ^I ^J ^K ^L ^M ^N ^O */
			0x0000,		/* ^P ^Q ^R ^S ^T ^U ^V ^W */
			0x0000,		/* ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
			0xC000,		/* sp  !  "  #  $  %  &  ' */
			0x0023,		/*  (  )  *  +  ,  -  .  / */
			0x5555,		/*  0  1  2  3  4  5  6  7 */
			0x5000,		/*  8  9  :  ;  <  =  >  ? */
			0x2AAA,		/*  @  A  B  C  D  E  F  G */
			0xAAAA,		/*  H  I  J  K  L  M  N  O */
			0xAAAA,		/*  P  Q  R  S  T  U  V  W */
			0xA802,		/*  X  Y  Z  [  \  ]  ^  _ */
			0x2AAA,		/*  `  a  b  c  d  e  f  g */
			0xAAAA,		/*  h  i  j  k  l  m  n  o */
			0xAAAA,		/*  p  q  r  s  t  u  v  w */
			0xA800		/*  x  y  z  {  |  }  ~ dl */
			  };

static	WORD	CCuqs[] = {		/* CC for unquoted string */
			0xFFFF,		/* ^@ ^A ^B ^C ^D ^E ^F ^G */
			0xFFFF,		/* ^H ^I ^J ^K ^L ^M ^N ^O */
			0xFFFF,		/* ^P ^Q ^R ^S ^T ^U ^V ^W */
			0xFCFF,		/* ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
			0xEAAA,		/* sp  !  "  #  $  %  &  ' */
			0xAAEB,		/*  (  )  *  +  ,  -  .  / */
			0xAAAA,		/*  0  1  2  3  4  5  6  7 */
			0xAAAA,		/*  8  9  :  ;  <  =  >  ? */
			0xAAAA,		/*  @  A  B  C  D  E  F  G */
			0xAAAA,		/*  H  I  J  K  L  M  N  O */
			0xAAAA,		/*  P  Q  R  S  T  U  V  W */
			0xAAAA,		/*  X  Y  Z  [  \  ]  ^  _ */
			0xAAAA,		/*  `  a  b  c  d  e  f  g */
			0xAAAA,		/*  h  i  j  k  l  m  n  o */
			0xAAAA,		/*  p  q  r  s  t  u  v  w */
			0xAAAB		/*  x  y  z  {  |  }  ~ dl */
			  };


static	int	(*Cfptbl[])() = {	/* Command function routine table */
			CFPini,		/* Initialize parse */
			CFPkey,		/* Keyword parse */
			CFPnum,		/* Number */
			CFPnoi,		/* Noise words (guide string) */
			CFPcfm,		/* Confirm */
			CFPgsk,		/* General Storage Keyword */
			CFPswi,		/* Switch */
			CFPtxt,		/* Text to end of line */
			CFPtok,		/* Token */
			CFPuqs,		/* unquoted string */
			CFPdat		/* Date and time */
			      };

static	WORD	**Ccctbl[] = {		/* Default CC tables for each fc */
			NULL,		/* _CMINI */
			CCkey,		/* _CMKEY */
			NULL,		/* _CMNUM */
			NULL,		/* _CMNOI */
			NULL,		/* _CMCFM */
			CCkey,		/* _CMGSK */
			CCkey,		/* _CMSWI */
			NULL,		/* _CMTXT */
			NULL,		/* _CMTOK */
			CCuqs,		/* _CMUQS */
			NULL		/* _CMDTM */
				};



/*

*//* CMDpf (CSBptr, CFBptr)

	Process parse for a particular function block

This routine attempts to parse the remaining input according to
the command function block (CFBptr).  It is responsible for calling
the appropriate parse routine, and passing the result code back to
the main COMND executor.


Accepts :

	CSBptr		Address of command state block
	CFBptr		Address of command function block

Returns :

	<value>		parse result, of form _CPxxx as defined in the
			include file "comndi.h".

*/

CMDpf (CSBptr, CFBptr)

CSB		*CSBptr;		/* Addr of command state block */
CFB		*CFBptr;		/* Addr of command function block */

{
IND	int		i;		/* Index */
IND	WORD		*ccptr;		/* Addr of CC table, if any */

i = CFBptr -> CFB_FNC;			/* Get function code */
if ((i < 0) || (i > _CMMAX))		/* If out of legit range */
    {
    CSBptr -> CSB_RCD = _CRIFC;		/* Set invalid function code status */
    return (_CPABT);			/* Abort, right away. */
    }

ccptr = Ccctbl[i];			/* Get default CC table */
if (ccptr)				/* If any (if meaningful here) */
    if (CFBptr->CFB_FLG & _CFCC)	/* If user-supplied bit set */
	ccptr = CFBptr -> CFB_CC;	/*   then use his/hers! */
return ((*Cfptbl[i])(CSBptr, CFBptr, ccptr));	/* Process it */
}
/*

*//* CFBini (CSBptr, CFBptr, ccptr)

	Function parse for type=_CMINI, initialize the parse


This routine is called to initialize a parse for a line.

Accepts :

	CSBptr		Address of command state block
	CFBptr		Address of command function block
	ccptr		Address of CC table (where appropriate)


Returns :

	<value>		Parse status, _CPxxx as defined in comndi.h.

*/

CFPini (CSBptr, CFBptr, ccptr)

CSB		*CSBptr;		/* Addr of command state block */
CFB		*CFBptr;		/* Addr of command function block */
WORD		*ccptr;			/* Addr of CC table */

{
CSBptr -> CSB_FLN = -1;			/* No text filled, yet */
					/* -1 enables ^H recovery */
return (_CPSUCC);			/* This parse MATCHED, by jove */
}
/*

*//* CFPnoi (CSBptr, CFBptr, ccptr)

	Function parse for type=_CMNOI, noise words (guide string)

This routine attempts a parse of a particular guide string.  The
guide words are given in the CFB_DEF pointer area, and are matched if
enclosed in parentheses (the parens are NOT included in the supplied
string).

Accepts :

	CSBptr		Address of command state block
	CFBptr		Address of command function block
	ccptr		Address of CC table (where appropriate)


Returns :

	<value>		Parse status, _CPxxx as defined in comndi.h.

*/

CFPnoi (CSBptr, CFBptr, ccptr)

CSB		*CSBptr;		/* Addr of command state block */
CFB		*CFBptr;		/* Addr of command function block */
WORD		*ccptr;			/* Addr of CC table */

{
IND	char	*dptr;			/* Default string pointer */
IND	int	cix;			/* Command index */
IND	int	c,c1;			/* Character */

cix = CMDspc (CSBptr);			/* Skip spaces */
dptr = CFBptr -> CFB_DEF;		/* Get addr of default string */
if (CSBptr -> CSB_RFL & _CFPFE)		/* If previous ended in escape */
    c = _CCCMP;				/* Flag completion wanted */
else					/* Otherwise */
    c = CMDgcc(CSBptr, cix++);		/*  get next char */

if (c == _CCCMP)			/* If completion wanted at start */
    {
    CMDcpl (CSBptr, "(");		/* Complete... opening paren */
    CMDcpl (CSBptr, dptr);		/* Complete... guide words */
    CMDcpl (CSBptr, ") ");		/* Complete... closing paren */
    return (_CPCPE);			/* Return successful parse */
    }

if (c == _CCINC)			/* If incomplete */
    return (_CPAGN);			/*  try again */

if (c != '(')				/* If not open paren */
    return (_CPSUCC);			/*  guide words are optional */

while (TRUE)				/* Loop on chars in input */
    {
    while (TRUE)			/* Get non-blank char from input */
	{
	c = CMDgcc (CSBptr, cix++);
	if ((c != ' ') && (c != '	'))
	    break;
	}

    while (TRUE)			/* Get non-blank char from default */
	{
	c1 = *dptr++;
	if ((c1 != ' ') && (c1 != '	'))
	    break;
	}

    if ((c == _CCCMP)			/* completion ? */
     || (c == _CCHLP)			/* Give help ? */
     || (c == _CCEND)			/* End? */
      )
	break;				/*  quit the loop */

    c = toupper(c);			/* Compare in same case */
    c1 = toupper(c1);			/*     .     */
    if (c1 != c)			/* If not the same */
	break;				/*  then leave this loop. */
    }

/* Found non-match, or special request */

if (c == _CCCMP)			/* If completion wanted, */
    {
    CMDcpl (CSBptr, --dptr);		/* Complete with rest of string */
    CMDcpl (CSBptr, ") ");		/* Complete with closing paren */
    return (_CPCPE);			/* Return success */
    }

if (c == _CCHLP)			/* Give help ? */
    {
    if (CMDhlp (CFBptr, "guide string: ("))
	{
	CMDpzs (CFBptr -> CFB_DEF);	/* Print string */
	CMDpzs (")");
	CMDfob();			/* Make sure it is seen */
	}
    return (_CPGVH);			/* Indicate we gave help */
    }

if (c == _CCEND)			/* If end of input */
    return (_CPNOP);			/*  no parse */

if (c == _CCINC)			/* If incomplete */
    return (_CPAGN);			/*  try again */

if ((c1 == NUL) && (c == ')'))		/* If end of guideword */
    {
    CMDcpt (CSBptr, cix);		/* Set parse checkpoint */
    return (_CPSUCC);			/* Return success! */
    }

return (_CPNOP);			/* Sorry, no parse */
}
/*

*//* CFPcfm (CSBptr, CFBptr, ccptr)

	Function parse for type=_CMCFM, confirm with carriage return


Accepts :

	CSBptr		Address of command state block
	CFBptr		Address of command function block
	ccptr		Address of CC table (where appropriate)


Returns :

	<value>		Parse status, _CPxxx as defined in comndi.h.

*/

CFPcfm (CSBptr, CFBptr, ccptr)

CSB		*CSBptr;		/* Addr of command state block */
CFB		*CFBptr;		/* Addr of command function block */
WORD		*ccptr;			/* Addr of CC table */

⌨️ 快捷键说明

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