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

📄 select.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
* EXAMPLES:**	node = es$parse(stat,fldno,"eq rp06, rp07");*	node = es$parse(stat,fldno,"eq %s",p1);*--**********************************************************************/SELNODE *es$parse(va_alist)va_dcl{#define FMTBUFSIZE 128va_list	incr;long	*statptr;long	retstat;char	*opc;char	*token;short	fldno;short	opcode;char	*fmt;			/* pointer to local copy of fmt string */char	*ufmt;			/* user format string */static	char	fmtbuf[FMTBUFSIZE]; /* store local fmt string here */short	ftype;char	*spar;			/* string paramter */long	lpar ;			/* long paramter */short	ptype;			/* paramter type */short	argcnt;			/* number in arglist */char	*temp;ARGLIST *args;				/* argument list */SELNODE *snode;				/* store the return value here */DD$STD_ITEMS_DSD_PTR item_ptr;va_start(incr);statptr = va_arg(incr,long *);	        /* address of the status array */fldno = va_arg(incr,long);		/* pick up field number */ufmt = va_arg(incr,char *);		/* address of selection format */fmt = fmtbuf;strcpy(fmt,ufmt);		    /* make a local copy */fmt = trimleadingspaces(fmt); if ((item_ptr = find_std_item_dsd(fldno)) == DD$UNKNOWN_ITEM)    {    *statptr = ES$NOFLD;    return(NULL);    }ftype = item_ptr->TYPE;					/* process opcode */fmt = trimleadingspaces(fmt);opc = nexttoken(fmt,' ',&fmt);  /* get opcode */strtoupper(opc);opcode = cvtopc(opc);if (opcode == ES$FAIL)    {    *statptr = ES$BADOPCODE;    return(NULL);    }				/* process the remaining paramters				   there must be atleast one */argcnt = 1;args = es$mkarglist(fldno,ftype,0); while (fmt != NULL) /* for each token */    {    token = nexttoken(fmt,',',&fmt); /* for each token */    token = trimspaces(token);    if (strlen(token) != 0)        {	ptype = DT_STRING; /* default to string */	if (*token == '%')	    {	    token++;	    switch(*token)	/* char after % defines the type */	        {		case 'd' :		    lpar = va_arg(incr,long);		    ptype = DT_LONG;		break;		case 's' :		    spar = va_arg(incr,char *);		    ptype = DT_STRING;		break;		default :		    *statptr = ES$BADFMT;		    return(NULL);		break;		}	    }	else	    spar = token;	temp = cvtparms(&retstat,fldno,ftype,ptype,spar,lpar);	if (retstat != ES$SUCC)	    {	    *statptr = retstat;	    return(NULL);	    }	argcnt++;	retstat = es$apparglist(args,fldno,ftype,temp);        }			 /* end of test for zero length tokens */    }				 /* end of reading tokens */    snode = es$mkselectnode(opcode,NULL,NULL,args);*statptr = ES$SUCC;return(snode);}/****************************** CVTPARMS ******************************//**   This function converts the input paramater to the*   type of the EIMS field.*   The function returns the address of the stored paramter */char *cvtparms(stat,fldno,ftype,ptype,spar,lpar)long	*stat;short	fldno;short	ftype;short	ptype;char	*spar;long	lpar;{char	*ret;long	llong;*stat	= ES$SUCC;ret	= NULL;switch (ftype)    {    case DT_SHORT :      case DT_LONG  :    case DT_SHORT_REGISTER :    case DT_REGISTER :    case DT_DATE  :	if (ptype == DT_STRING)	    ret = storelong(atol(spar));	else	    ret = storelong(lpar);    break;    case DT_STRING :	ret = storestring(spar);    break;    case DT_SHORT_INDEX :    case DT_INDEXED :	if (ptype == DT_STRING)	    {	    if ((llong = get_code_std_item(fldno,spar)) == DD$UNKNOWN_CODE)		{		*stat = ES$TBLERR;		return(NULL);		}	    *stat = ES$SUCC;	    ret = storelong(llong);	    }	else	    ret = storelong(lpar);    break;    default:	*stat = ES$TPER;	return(NULL);    break;    }return(ret);}/****************************** STORESTRING ***************************/char *storestring(s)char *s;{char *ret;ret = malloc(strlen(s)+1);strcpy(ret,s);return(ret);}/****************************** STORELONG ***************************/char *storelong(l)long l;{long *ret;ret = (long *) malloc(sizeof(long));*ret = l;return((char *)ret);}/****************************** CVTOPC ***************************/long cvtopc(s)char *s;{static char *opcodes[] = { 	    "",	    "AND",	    "OR",	    "NOT",	    "EQ",	    "RANGE",	    "LT",	    "LE",	    "GT",	    "GE" };short	 low = 1;short	 high = 10;short	 i;    for (i = low; i < high; i++)    {    if (strcmp(opcodes[i],s) == 0)	return(i);    }return(ES$FAIL);    }/****************************** STRTOUPPER ***************************/void strtoupper(s)char *s;{while (*s != NULL)    {    *s = toupper(*s);    s++;    }}/****************************** NEXTTOKEN ****************************/char *nexttoken(str,delimiter,rem)char	*str;int	delimiter;char	**rem;{char	*ret;char	*cloc;    ret	 = str;cloc	 = strchr(str,delimiter);if (cloc == NULL)     {    *rem = NULL;			/* set remainder to NULL */    return(ret);    }*(cloc) = '\0';			 /* terminate the string at the delimiter */cloc++;*rem = cloc;return(ret);      }/****************************** TRIMSPACES ***************************/char *trimspaces(str)char *str;{char	*ret;char	*strend;ret	= str;while (isspace(*ret) != 0)    ret++;strend = ret + strlen(ret) -1 ;while (isspace(*strend) != 0)    strend--;strend++;*(strend) = '\0';return(ret);}/*************************** TRIMLEADINGSPACES ***************************/char *trimleadingspaces(str)char *str;{char	*ret;char	*strend;ret = str;while (isspace(*ret) != 0)    ret++;return(ret);}/**************************************************************************	.SBTTL	Make select node*++* FUNCTIONAL DESCRIPTION:		**	This function creates a selection node. Space is allocated*	for the node, a node is created, and the input parameters*	are stored in the node.** FUNCTION DECLARATION*	SELNODE *es$mkselectnode();*	* CALLING SEQUENCE: node = es$mkselectnode(opr,left,right,args)** FORMAL PARAMETERS:		**   short opr; Must be on of the following:*		ES$AND ES$OR ES$NOT ES$EQUAL ES$RANGE ES$LT ES$LE ES$GT ES$GE *   SELNODE *left;*   SELNODE *right;*   ARGLIST *args;** IMPLICIT INPUTS: Paramters passed in the call**	* SIDE EFFECTS:			*	Space is allocated for a node and data is*	stored in that node.** UNDESIRED EVENTS*	This function returns a NULL pointer if the node cannot*	be created for some reason. The only know reason is*	insufficient memory to allocate for the node.*	*--*************************************************************************/SELNODE *es$mkselectnode(opr,lnode,rnode,args)short opr;SELNODE *lnode;SELNODE	*rnode;ARGLIST *args;{SELNODE *answer;answer = (SELNODE *) malloc(sizeof(SELNODE));answer->operator	= opr;answer->left		= lnode;answer->parent		= NULL;answer->right		= rnode;answer->operands	= args;if (lnode != NULL)    lnode->parent = answer;if (rnode != NULL)    rnode->parent = answer;return(answer);}/***************************************************************************	.SBTTL	Make new argument list*++* FUNCTIONAL DESCRIPTION:		**	This function creates a new argument list. The first*	element of the list is also created.** FUNCTION DECLARATION*	ARGLIST arglist *es$mkarglist();*	* CALLING SEQUENCE: args = es$mkarglist(fldno,ftype,varadr)** FORMAL PARAMETERS:		**   short fldno; EIMS field number*   short ftype; on of the following data types*		    DT_SHORT DT_LONG DT_DATE DT_STRING*   char *varadr;  address of a variable** IMPLICIT INPUTS: Paramters passed in the call**	* SIDE EFFECTS:			*	Space is allocated for the first (top) element of the list.** UNDESIRED EVENTS*	This function returns a NULL pointer if the list cannot*	be created for some reason. The only know reason is*	insufficient memory to allocate for the node.*	*--*************************************************************************/ARGLIST *es$mkarglist(fldno,fldtype,varadr)short	fldno;short	fldtype;char	*varadr;{ARGLIST *answer;answer = (ARGLIST *) malloc(sizeof(ARGLIST));if (answer == NULL)    return(NULL);answer->fldno		 = fldno;answer->varaddress	 = varadr;answer->vartype		 = fldtype;answer->next		 = NULL;return(answer);}/**************************************************************************	.SBTTL	Append to end of argument list*++* FUNCTIONAL DESCRIPTION:		**	This function adds a new element to the end of an*	argument list.** FUNCTION DECLARATION*	long es$apparglist();*	* CALLING SEQUENCE: status = es$apparglist(args,fldno,fldtype,varadr)** FORMAL PARAMETERS:		**   ARGLIST *args ; pointer to the argument list to append to*   short fldno; EIMS field number*   short vartype; on of the following data types*		    DT_SHORT DT_LONG DT_DATE DT_STRING*   char *varadr;  address of a user variable** IMPLICIT INPUTS: Paramters passed in the call**	* SIDE EFFECTS:			*	Space is allocated for the first (top) element of the list.** FUNCTION VALUE*	ES$SUCC - element appended to list*	ES$NOMEM - no room to add element** UNDESIRED EVENTS*	This function returns ES$NOMEM if the list cannot*	be created for some reason. The only know reason is*	insufficient memory to allocate for the node.*	*--*************************************************************************/long es$apparglist(args,fldno,fldtype,varadr)ARGLIST *args;short	fldno;short	fldtype;char	*varadr;{ARGLIST *curr;ARGLIST	*newone;curr = args;while (curr->next != NULL)    curr = curr->next;newone = (ARGLIST *) malloc(sizeof(ARGLIST));if (newone == NULL)    return(ES$NOMEM);curr->next		 = newone;newone->fldno		 = fldno;newone->varaddress	 = varadr;newone->vartype		 = fldtype;newone->next		 = NULL;return(ES$SUCC);}/**************************** DELETETREE *****************************//*  This function deletes and tree and frees up the space */void deletetree(tree)SELNODE *tree;{if (tree != NULL)    {    if (tree->left != NULL)  deletetree(tree->left);    if (tree->right != NULL) deletetree(tree->right);    free(tree);    }}/**************************** NEXTINORDER ****************************//*  This function returns a pointer to the next node processed inorder. */SELNODE *nextinorder(last)SELNODE *last;{SELNODE	*ans;SELNODE	*prev;if (last->right != NULL)    return(firstinorder(last->right));		/* the easy one */ans	= last->parent;prev	= last;  while (ans != NULL)    {    if (prev == ans->left)	return(ans);			/* If we came from the left					    then we now do the parent */    prev = ans;    ans = ans->parent;			/* back up one parent */    }return(NULL);				/* backed up to parent */}/****************************** FIRSTINORDER ****************************//*  This function returns a pointer to the first node processed inorder. */SELNODE *firstinorder(top)SELNODE *top;{SELNODE *ans;ans = top;while (ans->left != NULL)    ans = ans->left;return(ans);}

⌨️ 快捷键说明

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