lexan.c,v
来自「TCP-IP红宝书源代码」· C,V 代码 · 共 73 行
C,V
73 行
head 1.1;
access;
symbols;
locks
dls:1.1; strict;
comment @ * @;
1.1
date 97.09.21.19.29.03; author dls; state Dist;
branches;
next ;
desc
@@
1.1
log
@pre-3e code
@
text
@/* 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 + -
显示快捷键?