diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 2004-05-07 01:13:29 -0400 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 2004-05-07 01:13:29 -0400 |
commit | d326f24d169154673717129098ff4554a673f178 (patch) | |
tree | 7229f817b10bcdb82f8df2b6af3a3acc792a762d /WWW/Library/Implementation/HTLex.c | |
parent | 2cd8e80bfe2792ce8999a26b34384598f58e3889 (diff) | |
download | lynx-snapshots-d326f24d169154673717129098ff4554a673f178.tar.gz |
snapshot of project "lynx", label v2-8-6dev_3
Diffstat (limited to 'WWW/Library/Implementation/HTLex.c')
-rw-r--r-- | WWW/Library/Implementation/HTLex.c | 153 |
1 files changed, 80 insertions, 73 deletions
diff --git a/WWW/Library/Implementation/HTLex.c b/WWW/Library/Implementation/HTLex.c index 6297a1f7..fea6aae8 100644 --- a/WWW/Library/Implementation/HTLex.c +++ b/WWW/Library/Implementation/HTLex.c @@ -1,57 +1,55 @@ /* MODULE HTLex.c -** LEXICAL ANALYSOR -** -** AUTHORS: -** AL Ari Luotonen luotonen@dxcern.cern.ch -** -** HISTORY: -** -** -** BUGS: -** -** -*/ + * LEXICAL ANALYSOR + * + * AUTHORS: + * AL Ari Luotonen luotonen@dxcern.cern.ch + * + * HISTORY: + * + * + * BUGS: + * + * + */ #include <HTUtils.h> -#include <HTLex.h> /* Implemented here */ +#include <HTLex.h> /* Implemented here */ #include <LYLeaks.h> /* -** Global variables -*/ -char HTlex_buffer[40]; /* Read lexical string */ -int HTlex_line = 1; /* Line number in source file */ - + * Global variables + */ +char HTlex_buffer[40]; /* Read lexical string */ +int HTlex_line = 1; /* Line number in source file */ /* -** Module-wide variables -*/ + * Module-wide variables + */ static int lex_cnt; static BOOL lex_template; static LexItem lex_pushed_back = LEX_NONE; static FILE *cache = NULL; - -void unlex (LexItem lex_item) +void unlex(LexItem lex_item) { lex_pushed_back = lex_item; } - -LexItem lex (FILE * fp) +LexItem lex(FILE *fp) { int ch = 0; - if (fp != cache) { /* This cache doesn't work ok because the system */ - cache = fp; /* often assign same FILE structure the next open */ - HTlex_line = 1; /* file. So, if there are syntax errors in setup */ - } /* files it may confuse things later on. */ - + if (fp != cache) { /* This cache doesn't work ok because the system */ + cache = fp; /* often assign same FILE structure the next open */ + HTlex_line = 1; /* file. So, if there are syntax errors in setup */ + } + /* files it may confuse things later on. */ if (lex_pushed_back != LEX_NONE) { LexItem ret = lex_pushed_back; + lex_pushed_back = LEX_NONE; return ret; } @@ -59,73 +57,82 @@ LexItem lex (FILE * fp) lex_cnt = 0; lex_template = NO; - for(;;) { + for (;;) { switch (ch = getc(fp)) { - case EOF: - case ' ': - case '\t': - case '\r': - case '\n': - case ':': - case ',': - case '(': - case ')': - case '@': + case EOF: + case ' ': + case '\t': + case '\r': + case '\n': + case ':': + case ',': + case '(': + case ')': + case '@': if (lex_cnt > 0) { - if (ch != EOF) ungetc(ch,fp); - if (lex_template) return LEX_TMPL_STR; - else return LEX_ALPH_STR; - } - else switch(ch) { - case EOF: return LEX_EOF; - case '\n': - HTlex_line++; return LEX_REC_SEP; - case ':': return LEX_FIELD_SEP; - case ',': return LEX_ITEM_SEP; - case '(': return LEX_OPEN_PAREN; - case ')': return LEX_CLOSE_PAREN; - case '@': return LEX_AT_SIGN; - default: ; /* Leading white space ignored (SP,TAB,CR) */ - } + if (ch != EOF) + ungetc(ch, fp); + if (lex_template) + return LEX_TMPL_STR; + else + return LEX_ALPH_STR; + } else + switch (ch) { + case EOF: + return LEX_EOF; + case '\n': + HTlex_line++; + return LEX_REC_SEP; + case ':': + return LEX_FIELD_SEP; + case ',': + return LEX_ITEM_SEP; + case '(': + return LEX_OPEN_PAREN; + case ')': + return LEX_CLOSE_PAREN; + case '@': + return LEX_AT_SIGN; + default:; /* Leading white space ignored (SP,TAB,CR) */ + } break; - default: + default: HTlex_buffer[lex_cnt++] = (char) ch; HTlex_buffer[lex_cnt] = '\0'; - if ('*' == ch) lex_template = YES; - } /* switch ch */ - } /* forever */ + if ('*' == ch) + lex_template = YES; + } /* switch ch */ + } /* forever */ } - -char *lex_verbose (LexItem lex_item) +char *lex_verbose(LexItem lex_item) { static char msg[100]; /* @@@@@@@@ */ switch (lex_item) { - case LEX_NONE: /* Internally used */ + case LEX_NONE: /* Internally used */ return "NO-LEX-ITEM"; - case LEX_EOF: /* End of file */ + case LEX_EOF: /* End of file */ return "end-of-file"; - case LEX_REC_SEP: /* Record separator */ + case LEX_REC_SEP: /* Record separator */ return "record separator (newline)"; - case LEX_FIELD_SEP: /* Field separator */ + case LEX_FIELD_SEP: /* Field separator */ return "field separator ':'"; - case LEX_ITEM_SEP: /* List item separator */ + case LEX_ITEM_SEP: /* List item separator */ return "item separator ','"; - case LEX_OPEN_PAREN: /* Group start tag */ + case LEX_OPEN_PAREN: /* Group start tag */ return "'('"; - case LEX_CLOSE_PAREN: /* Group end tag */ + case LEX_CLOSE_PAREN: /* Group end tag */ return "')'"; - case LEX_AT_SIGN: /* Address qualifier */ + case LEX_AT_SIGN: /* Address qualifier */ return "address qualifier '@'"; - case LEX_ALPH_STR: /* Alphanumeric string */ + case LEX_ALPH_STR: /* Alphanumeric string */ sprintf(msg, "alphanumeric string '%.70s'", HTlex_buffer); return msg; - case LEX_TMPL_STR: /* Template string */ + case LEX_TMPL_STR: /* Template string */ sprintf(msg, "template string '%.70s'", HTlex_buffer); return msg; - default: + default: return "UNKNOWN-LEX-ITEM"; } } - |