lexan.c

来自「关于SHELL方面的」· C语言 代码 · 共 49 行

C
49
字号
/* lexan.c - lexan */#include <conf.h>#include <kernel.h>#include <shell.h>/*------------------------------------------------------------------------ *  lexan  -  ad hoc lexical analyzer to divide command line into tokens *------------------------------------------------------------------------ */lexan(line)char	*line;{	char	**tokptr;	int	ntok;	char	*p;	char	ch;	char	*to;	char	quote;	to = Shl.shargst;		/* area to place token strings */	tokptr = &Shl.shtok[ntok = 0];	/* array of ptrs to tokens */	for  (p = line ; *p!='\0' && *p!='\n' && ntok < SHMAXTOK ;) {		while ( (ch = *p) == ' ')	/* skip leading blanks	*/			p++;		if (ch == '\0' || ch == '\n')	/* end of line or string*/			return(ntok);		*tokptr++ = to;			/* save start of token	*/		Shl.shtktyp[ntok++] = ch;		if (ch == '"' || ch == '\'') {	/* check for quoted str.*/			quote = ch;			for (p++ ; (ch = *p++) != quote && ch != '\n'				&& ch != '\0' ; )				*to++ = ch;			if (ch != quote)				return(SYSERR);		} else {		/* other possible tokens	*/			*to++ = *p++;			if (ch!='>' && ch!='<' && ch!='&')				while ((ch = *p)!='\n' && ch !='\0' &&					ch!='<' && ch!='>' && ch!=' ' &&					ch!='"' && ch!='\'' && ch !='&')					*to++= *p++; /* copy alphamerics*/		}		*to++ = NULLCH;		/* terminate token string	*/	}	return(ntok);}

⌨️ 快捷键说明

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