Annotation of xinu/sys/shell/lexan.c, revision 1.1.1.1

1.1       root        1: /* lexan.c - lexan */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <shell.h>
                      6: 
                      7: /*------------------------------------------------------------------------
                      8:  *  lexan  -  ad hoc lexical analyzer to divide command line into tokens
                      9:  *------------------------------------------------------------------------
                     10:  */
                     11: lexan(line)
                     12: char   *line;
                     13: {
                     14:        char    **tokptr;
                     15:        int     ntok;
                     16:        char    *p;
                     17:        char    ch;
                     18:        char    *to;
                     19:        char    quote;
                     20: 
                     21:        to = Shl.shargst;               /* area to place token strings */
                     22:        tokptr = &Shl.shtok[ntok = 0];  /* array of ptrs to tokens */
                     23:        for  (p = line ; *p!='\0' && *p!='\n' && ntok < SHMAXTOK ;) {
                     24:                while ( (ch = *p) == ' ')       /* skip leading blanks  */
                     25:                        p++;
                     26:                if (ch == '\0' || ch == '\n')   /* end of line or string*/
                     27:                        return(ntok);
                     28:                *tokptr++ = to;                 /* save start of token  */
                     29:                Shl.shtktyp[ntok++] = ch;
                     30:                if (ch == '"' || ch == '\'') {  /* check for quoted str.*/
                     31:                        quote = ch;
                     32:                        for (p++ ; (ch = *p++) != quote && ch != '\n'
                     33:                                && ch != '\0' ; )
                     34:                                *to++ = ch;
                     35:                        if (ch != quote)
                     36:                                return(SYSERR);
                     37:                } else {                /* other possible tokens        */
                     38:                        *to++ = *p++;
                     39:                        if (ch!='>' && ch!='<' && ch!='&')
                     40:                                while ((ch = *p)!='\n' && ch !='\0' &&
                     41:                                        ch!='<' && ch!='>' && ch!=' ' &&
                     42:                                        ch!='"' && ch!='\'' && ch !='&')
                     43:                                        *to++= *p++; /* copy alphamerics*/
                     44:                }
                     45:                *to++ = NULLCH;         /* terminate token string       */
                     46:        }
                     47:        return(ntok);
                     48: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.