Sun, 27 Aug 2000 21:21:29 +0200
trunk: changeset 23
Made check_args non-static for use with ion
include/libtu/misc.h | file | annotate | diff | comparison | revisions | |
include/libtu/parser.h | file | annotate | diff | comparison | revisions | |
include/libtu/tokenizer.h | file | annotate | diff | comparison | revisions | |
parser.c | file | annotate | diff | comparison | revisions | |
tokenizer.c | file | annotate | diff | comparison | revisions |
--- a/include/libtu/misc.h Mon Jul 24 16:38:12 2000 +0200 +++ b/include/libtu/misc.h Sun Aug 27 21:21:29 2000 +0200 @@ -20,7 +20,7 @@ #define ALLOC_N(X, N) (X*)malloczero(sizeof(X)*(N)) #define REALLOC_N(PTR, X, S, N) (X*)remalloczero(PTR, sizeof(X)*(S), sizeof(X)*(N)) -#define FREE(X) ({if(X!=NULL) free(X);}) +#define FREE(X) do{if(X!=NULL)free(X);}while(0) extern void* malloczero(size_t size); extern void* remalloczero(void *ptr, size_t oldsize, size_t newsize);
--- a/include/libtu/parser.h Mon Jul 24 16:38:12 2000 +0200 +++ b/include/libtu/parser.h Sun Aug 27 21:21:29 2000 +0200 @@ -39,5 +39,7 @@ extern bool parse_config_tokz(Tokenizer *tokz, const ConfOpt *options); extern bool parse_config(const char *fname, const ConfOpt *options, int flags); extern bool parse_config_file(FILE *file, const ConfOpt *options, int flags); +extern bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens, + const char *fmt); #endif /* LIBTU_PARSER_H */
--- a/include/libtu/tokenizer.h Mon Jul 24 16:38:12 2000 +0200 +++ b/include/libtu/tokenizer.h Sun Aug 27 21:21:29 2000 +0200 @@ -50,14 +50,14 @@ enum{ TOK_INVALID=0, - TOK_LONG, - TOK_DOUBLE, - TOK_CHAR, - TOK_STRING, - TOK_IDENT, - TOK_BOOL, - TOK_COMMENT, - TOK_OP + TOK_LONG='l', + TOK_DOUBLE='d', + TOK_CHAR='c', + TOK_STRING='s', + TOK_IDENT='i', + TOK_BOOL='b', + TOK_COMMENT='#', + TOK_OP='+' };
--- a/parser.c Mon Jul 24 16:38:12 2000 +0200 +++ b/parser.c Sun Aug 27 21:21:29 2000 +0200 @@ -27,12 +27,9 @@ }; -static bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens, - const char *fmt); +/* */ -/* */ - static bool opt_include(Tokenizer *tokz, int n, Token *toks); @@ -339,21 +336,25 @@ break; case P_END_SECT: - if(errornest!=0){ - errornest--; - break; - } - if(tokz->nest_lvl==0){ tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX); had_error=TRUE; break; } - if(!had_error) - had_error=!call_end_sect(tokz, tokz->optstack[tokz->nest_lvl]); + if(errornest!=0){ + if(errornest==1){ + call_cancel_sect(tokz, tokz->optstack[tokz->nest_lvl]); + tokz->nest_lvl--; + } + errornest--; + }else{ + if(!had_error) + had_error=!call_end_sect(tokz, + tokz->optstack[tokz->nest_lvl]); - tokz->nest_lvl--; + tokz->nest_lvl--; + } if(tokz->nest_lvl<init_nest_lvl) goto eof; @@ -362,8 +363,11 @@ if(!had_error) continue; - if(t==P_STMT_SECT) + if(t==P_STMT_SECT || t==P_END_SECT){ errornest++; + /*if(t==P_END_SECT) + tokz->nest_lvl--;*/ + } if(!(tokz->flags&TOKZ_ERROR_TOLERANT)) break; @@ -446,14 +450,11 @@ static int arg_match(Token *tok, char c) { - static const char chs[]={0, 'l', 'd', 'c', 's', 'i', 'b', 0, 0}; - char c2; + char c2=tok->type; if(c=='.' || c=='*') return 0; - c2=chs[tok->type]; - if(c2==c) return 0; @@ -567,8 +568,8 @@ } -static bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens, - const char *fmt) +bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens, + const char *fmt) { int i; int e;
--- a/tokenizer.c Mon Jul 24 16:38:12 2000 +0200 +++ b/tokenizer.c Sun Aug 27 21:21:29 2000 +0200 @@ -115,19 +115,14 @@ }else{ c=getc(tokz->file); } -/* if(c=='\n') - tokz->line++;*/ - + return c; } static void _ungetch(Tokenizer *tokz, int c) { -/* if(c=='\n') - tokz->line--;*/ tokz->ungetc=c; - /*ungetc(c, tokz->file);*/ } @@ -557,10 +552,17 @@ if(e==E_TOKZ_UNEXPECTED_EOF) line=0; - if(e<0) - warn_obj_line(tokz->name, line, "%s", strerror(-e)); - else - warn_obj_line(tokz->name, line, "%s", TR(errors[e])); + if(tokz!=NULL){ + if(e<0) + warn_obj_line(tokz->name, line, "%s", strerror(-e)); + else + warn_obj_line(tokz->name, line, "%s", TR(errors[e])); + }else{ + if(e<0) + warn("%s", strerror(-e)); + else + warn("%s", TR(errors[e])); + } }