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

📄 lexan.c

📁 TCP-IP红宝书源代码
💻 C
字号:
/* 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -