parser.c

Wed, 23 Feb 2000 08:47:59 +0100

author
tuomov
date
Wed, 23 Feb 2000 08:47:59 +0100
changeset 2
e14a1aba4c56
parent 1
6e704fc09528
child 5
f878a9ffa3e0
permissions
-rw-r--r--

trunk: changeset 5
Error tolerant config file parsing mode

0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
1 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
2 * libtu/parser.c
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
3 *
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2000.
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
5 *
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
6 * This file is distributed under the terms of the "Artistic License".
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
7 * See the included file LICENSE for details.
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
8 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
9
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
10 #include <string.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
11
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
12 #include "include/parser.h"
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
13 #include "include/misc.h"
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
14 #include "include/output.h"
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
15
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
16 #define MAX_TOKENS 32
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
17 #define MAX_NEST 16
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
18
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
19
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
20 enum{
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
21 P_NONE=1,
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
22 P_EOF,
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
23 P_STMT,
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
24 P_STMT_NS,
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
25 P_STMT_SECT,
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
26 P_BEG_SECT,
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
27 P_END_SECT
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
28 };
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
29
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
30
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
31 static bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
32 const char *fmt);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
33
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
34
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
35 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
36
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
37 static bool opt_include(Tokenizer *tokz, int n, Token *toks);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
38
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
39
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
40 static ConfOpt common_opts[]={
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
41 {"include", "s", opt_include, NULL},
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
42 {NULL, NULL, NULL, NULL}
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
43 };
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
44
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
45
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
46 /* */
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
47
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
48
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
49 static int read_statement(Tokenizer *tokz, Token *tokens, int *ntok_ret)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
50 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
51 int ntokens=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
52 Token *tok=NULL;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
53 int had_comma=0; /* 0 - no, 1 - yes, 2 - not had, not expected */
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
54 int retval=0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
55 int e=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
56
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
57 while(1){
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
58 tok=&tokens[ntokens];
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
59
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
60 if(!tokz_get_token(tokz, tok)){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
61 e=1;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
62 continue;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
63 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
64
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
65 if(ntokens==MAX_TOKENS-1){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
66 e=E_TOKZ_TOKEN_LIMIT;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
67 tokz_warn_error(tokz, tok->line, e);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
68 if(!(tokz->flags&TOKZ_ERROR_TOLERANT))
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
69 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
70 }else{
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
71 ntokens++;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
72 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
73
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
74 if(!TOK_IS_OP(tok)){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
75 if(ntokens==1 && !had_comma){
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
76 /*if(!TOK_IS_IDENT(tok)){
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
77 e=E_TOKZ_IDENTIFIER_EXPECTED;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
78 goto handle_error;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
79 }*/
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
80
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
81 had_comma=2;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
82 }else{
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
83 if(had_comma==0)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
84 goto syntax;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
85
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
86 had_comma=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
87 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
88 continue;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
89 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
90
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
91 /* It is an operator */
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
92 ntokens--;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
93
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
94 switch(TOK_OP_VAL(tok)){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
95 case OP_SCOLON:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
96 retval=(ntokens==0 ? P_NONE : P_STMT_NS);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
97 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
98
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
99 case OP_NEXTLINE:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
100 retval=(ntokens==0 ? P_NONE : P_STMT);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
101 break;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
102
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
103 case OP_L_BRC:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
104 retval=(ntokens==0 ? P_BEG_SECT : P_STMT_SECT);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
105 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
106
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
107 case OP_R_BRC:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
108 if(ntokens==0){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
109 retval=P_END_SECT;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
110 }else{
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
111 tokz_unget_token(tokz, tok);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
112 retval=P_STMT_NS;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
113 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
114 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
115
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
116 case OP_EOF:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
117 retval=(ntokens==0 ? P_EOF : P_STMT_NS);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
118
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
119 if(had_comma==1){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
120 e=E_TOKZ_UNEXPECTED_EOF;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
121 goto handle_error;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
122 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
123
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
124 goto end;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
125
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
126 case OP_COMMA:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
127 if(had_comma!=0)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
128 goto syntax;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
129
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
130 had_comma=1;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
131 continue;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
132
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
133 default:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
134 goto syntax;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
135 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
136
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
137 if(had_comma!=1)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
138 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
139
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
140 syntax:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
141 e=E_TOKZ_SYNTAX;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
142 handle_error:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
143 tokz_warn_error(tokz, tok->line, e);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
144
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
145 if(!(tokz->flags&TOKZ_ERROR_TOLERANT) || retval!=0)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
146 break;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
147 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
148
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
149 end:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
150 if(e!=0)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
151 retval=-retval;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
152
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
153 *ntok_ret=ntokens;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
154
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
155 return retval;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
156 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
157
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
158
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
159 static bool find_beg_sect(Tokenizer *tokz)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
160 {
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
161 Token tok;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
162
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
163 while(tokz_get_token(tokz, &tok)){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
164 if(TOK_IS_OP(&tok)){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
165 if(TOK_OP_VAL(&tok)==OP_NEXTLINE)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
166 continue;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
167
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
168 if(TOK_OP_VAL(&tok)==OP_SCOLON)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
169 return FALSE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
170
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
171 if(TOK_OP_VAL(&tok)==OP_L_BRC)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
172 return TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
173 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
174
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
175 tokz_unget_token(tokz, &tok);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
176 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
177 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
178 return FALSE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
179 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
180
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
181
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
182 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
183
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
184
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
185 static const ConfOpt* lookup_option(const ConfOpt *opts, const char *name)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
186 {
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
187 while(opts->optname!=NULL){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
188 if(strcmp(opts->optname, name)==0)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
189 return opts;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
190 opts++;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
191 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
192 return NULL;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
193 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
194
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
195
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
196 static bool call_end_sect(Tokenizer *tokz, const ConfOpt *opts)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
197 {
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
198 opts=lookup_option(opts, "#end");
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
199 if(opts!=NULL)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
200 return opts->fn(tokz, 0, NULL);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
201
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
202 return TRUE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
203 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
204
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
205
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
206 static bool call_cancel_sect(Tokenizer *tokz, const ConfOpt *opts)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
207 {
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
208 opts=lookup_option(opts, "#cancel");
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
209 if(opts!=NULL)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
210 return opts->fn(tokz, 0, NULL);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
211
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
212 return TRUE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
213 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
214
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
215
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
216 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
217
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
218
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
219 bool parse_config_tokz(Tokenizer *tokz, const ConfOpt *options)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
220 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
221 Token tokens[MAX_TOKENS];
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
222 bool alloced_optstack=FALSE;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
223 int i, t, ntokens=0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
224 int init_nest_lvl;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
225 bool had_error;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
226 int errornest=0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
227
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
228 /* Allocate tokz->optstack if it does not yet exist (if it does,
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
229 * we have been called from an option handler)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
230 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
231 if(!tokz->optstack){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
232 tokz->optstack=ALLOC_N(const ConfOpt*, MAX_NEST);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
233 if(!tokz->optstack){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
234 warn_err();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
235 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
236 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
237
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
238 memset(tokz->optstack, 0, sizeof(ConfOpt*)*MAX_NEST);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
239 init_nest_lvl=tokz->nest_lvl=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
240 alloced_optstack=TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
241 }else{
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
242 init_nest_lvl=tokz->nest_lvl;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
243 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
244
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
245 tokz->optstack[init_nest_lvl]=options;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
246
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
247 for(i=0; i<MAX_TOKENS; i++)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
248 tok_init(&tokens[i]);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
249
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
250
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
251 /* The loop
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
252 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
253 while(1){
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
254 had_error=FALSE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
255
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
256 /* free the tokens */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
257 while(ntokens--)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
258 tok_free(&tokens[ntokens]);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
259
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
260 /* read the tokens */
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
261 t=read_statement(tokz, tokens, &ntokens);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
262
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
263 if((had_error=t<0))
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
264 t=-t;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
265
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
266 switch(t){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
267 case P_STMT:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
268 case P_STMT_NS:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
269 case P_STMT_SECT:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
270
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
271 if(errornest)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
272 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
273 else if(tokz->flags&TOKZ_PARSER_INDENT_MODE)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
274 verbose_indent(tokz->nest_lvl);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
275
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
276 if(!TOK_IS_IDENT(tokens+0)){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
277 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
278 tokz_warn_error(tokz, tokens->line,
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
279 E_TOKZ_IDENTIFIER_EXPECTED);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
280 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
281
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
282 if(had_error)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
283 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
284
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
285 if(t==P_STMT){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
286 if(find_beg_sect(tokz))
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
287 t=P_STMT_SECT;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
288 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
289
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
290 options=lookup_option(tokz->optstack[tokz->nest_lvl],
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
291 TOK_IDENT_VAL(tokens+0));
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
292 if(options==NULL)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
293 options=lookup_option(common_opts, TOK_IDENT_VAL(tokens+0));
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
294
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
295 if(options==NULL){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
296 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
297 tokz_warn_error(tokz, tokens->line, E_TOKZ_UNKNOWN_OPTION);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
298 }else{
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
299 had_error=!check_args(tokz, tokens, ntokens, options->argfmt);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
300 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
301
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
302 if(had_error)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
303 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
304
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
305 if(options->opts!=NULL){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
306 if(t!=P_STMT_SECT){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
307 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
308 tokz_warn_error(tokz, tokz->line, E_TOKZ_LBRACE_EXPECTED);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
309 }else if(tokz->nest_lvl==MAX_NEST-1){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
310 tokz_warn_error(tokz, tokz->line, E_TOKZ_MAX_NEST);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
311 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
312 }else{
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
313 tokz->optstack[++tokz->nest_lvl]=options->opts;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
314 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
315 }else if(t==P_STMT_SECT){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
316 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
317 tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
318 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
319
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
320 if(!had_error && options->fn!=NULL){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
321 had_error=!options->fn(tokz, ntokens, tokens);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
322 if(t==P_STMT_SECT && had_error)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
323 tokz->nest_lvl--;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
324 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
325 break;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
326
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
327 case P_EOF:
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
328 if(tokz_popf(tokz)){
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
329 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
330 }else if(tokz->nest_lvl>0 || errornest>0){
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
331 tokz_warn_error(tokz, 0, E_TOKZ_UNEXPECTED_EOF);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
332 had_error=TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
333 }
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
334 goto eof;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
335
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
336 case P_BEG_SECT:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
337 had_error=TRUE;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
338 errornest++;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
339 tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
340 break;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
341
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
342 case P_END_SECT:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
343 if(errornest!=0){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
344 errornest--;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
345 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
346 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
347
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
348 if(tokz->nest_lvl==0){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
349 tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
350 had_error=TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
351 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
352 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
353
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
354 if(!had_error)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
355 had_error=!call_end_sect(tokz, tokz->optstack[tokz->nest_lvl]);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
356
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
357 tokz->nest_lvl--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
358
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
359 if(tokz->nest_lvl<init_nest_lvl)
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
360 goto eof;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
361 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
362
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
363 if(!had_error)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
364 continue;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
365
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
366 if(t==P_STMT_SECT)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
367 errornest++;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
368
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
369 if(!(tokz->flags&TOKZ_ERROR_TOLERANT))
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
370 break;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
371 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
372
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
373 eof:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
374 /* free the tokens */
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
375 while(ntokens--)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
376 tok_free(&tokens[ntokens]);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
377
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
378 while(tokz->nest_lvl>=init_nest_lvl){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
379 if(tokz->flags&TOKZ_ERROR_TOLERANT || !had_error)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
380 call_end_sect(tokz, tokz->optstack[tokz->nest_lvl]);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
381 else
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
382 call_cancel_sect(tokz, tokz->optstack[tokz->nest_lvl]);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
383 tokz->nest_lvl--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
384 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
385
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
386 /* Free optstack if it was alloced by this call */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
387 if(alloced_optstack){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
388 free(tokz->optstack);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
389 tokz->optstack=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
390 tokz->nest_lvl=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
391 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
392
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
393 if(tokz->flags&TOKZ_PARSER_INDENT_MODE)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
394 verbose_indent(init_nest_lvl);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
395
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
396 return !had_error;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
397 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
398
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
399
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
400 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
401
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
402
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
403 bool parse_config(const char *fname, const ConfOpt *options, int flags)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
404 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
405 Tokenizer *tokz;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
406 bool ret;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
407
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
408 tokz=tokz_open(fname);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
409
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
410 if(tokz==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
411 return FALSE;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
412
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
413 tokz->flags|=flags&~TOKZ_READ_COMMENTS;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
414
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
415 ret=parse_config_tokz(tokz, options);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
416
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
417 tokz_close(tokz);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
418
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
419 return ret;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
420 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
421
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
422
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
423 bool parse_config_file(FILE *file, const ConfOpt *options, int flags)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
424 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
425 Tokenizer *tokz;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
426 bool ret;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
427
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
428 tokz=tokz_open_file(file);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
429
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
430 if(tokz==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
431 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
432
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
433 tokz->flags|=flags&~TOKZ_READ_COMMENTS;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
434
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
435 ret=parse_config_tokz(tokz, options);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
436
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
437 tokz_close(tokz);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
438
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
439 return ret;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
440 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
441
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
442
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
443 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
444 * Argument validity checking stuff
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
445 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
446
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
447
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
448 static int arg_match(Token *tok, char c)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
449 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
450 static const char chs[]={0, 'l', 'd', 'c', 's', 'i', 0, 0};
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
451 char c2;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
452
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
453 if(c=='.' || c=='*')
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
454 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
455
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
456 c2=chs[tok->type];
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
457
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
458 if(c2==c)
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
459 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
460
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
461 if(c2=='c' && c=='l'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
462 TOK_SET_LONG(tok, TOK_CHAR_VAL(tok));
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
463 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
464 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
465
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
466 if(c2=='l' && c=='c'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
467 TOK_SET_CHAR(tok, TOK_LONG_VAL(tok));
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
468 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
469 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
470
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
471 if(c2=='l' && c=='d'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
472 TOK_SET_DOUBLE(tok, TOK_LONG_VAL(tok));
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
473 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
474 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
475
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
476 return E_TOKZ_INVALID_ARGUMENT;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
477 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
478
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
479
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
480 static int check_argument(const char **pret, Token *tok, const char *p)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
481 {
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
482 int mode;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
483 int e=E_TOKZ_TOO_MANY_ARGS;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
484
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
485 again:
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
486 mode=0;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
487
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
488 if(*p=='*'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
489 *pret=p;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
490 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
491 }else if(*p=='?'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
492 mode=1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
493 p++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
494 }else if(*p==':'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
495 mode=2;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
496 p++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
497 }else if(*p=='+'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
498 *pret=p;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
499 return arg_match(tok, *(p-1));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
500 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
501
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
502 while(*p!='\0'){
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
503 e=arg_match(tok, *p);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
504 if(e==0){
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
505 p++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
506 while(mode==2 && *p==':'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
507 if(*++p=='\0')
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
508 break; /* Invalid argument format string, though... */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
509 p++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
510 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
511 *pret=p;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
512 return 0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
513 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
514
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
515 if(mode==0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
516 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
517
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
518 p++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
519
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
520 if(mode==1)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
521 goto again;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
522
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
523 /* mode==2 */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
524
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
525 if(*p!=':')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
526 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
527 p++;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
528 e=E_TOKZ_TOO_MANY_ARGS;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
529 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
530
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
531 *pret=p;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
532 return e;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
533 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
534
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
535
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
536 static bool args_at_end(const char *p)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
537 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
538 if(p==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
539 return TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
540
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
541 while(*p!='\0'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
542 if(*p=='*' || *p=='+')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
543 p++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
544 else if(*p=='?')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
545 p+=2;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
546 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
547 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
548 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
549
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
550 return TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
551 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
552
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
553
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
554 static bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
555 const char *fmt)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
556 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
557 int i;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
558 int e;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
559
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
560 if(fmt==NULL){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
561 if(ntokens!=1)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
562 tokz_warn_error(tokz, tokens[0].line, E_TOKZ_TOO_MANY_ARGS);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
563 return ntokens==1;
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
564 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
565
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
566 for(i=1; i<ntokens; i++){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
567 e=check_argument(&fmt, &tokens[i], fmt);
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
568 if(e!=0){
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
569 tokz_warn_error(tokz, tokens[i].line, e);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
570 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
571 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
572 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
573
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
574 if(!args_at_end(fmt)){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
575 tokz_warn_error(tokz, tokens[i].line, E_TOKZ_TOO_FEW_ARGS);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
576 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
577 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
578
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
579 return TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
580 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
581
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
582
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
583 /* */
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
584
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
585
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
586 static bool opt_include(Tokenizer *tokz, int n, Token *toks)
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
587 {
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
588 const char *fname=TOK_STRING_VAL(toks+1);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
589 const char *lastndx;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
590 char *tmpname;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
591 bool retval;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
592
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
593 if(fname[0]=='/' || tokz->name==NULL)
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
594 goto thisdir;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
595
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
596 lastndx=strrchr(tokz->name, '/');
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
597
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
598 if(lastndx==NULL)
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
599 goto thisdir;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
600
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
601 tmpname=scatn(tokz->name, lastndx-tokz->name+1, fname, -1);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
602
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
603 if(tmpname==NULL){
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
604 warn_err();
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
605 return FALSE;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
606 }
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
607
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
608 retval=tokz_pushf(tokz, tmpname);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
609
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
610 free(tmpname);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
611
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
612 return retval;
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
613
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
614 thisdir:
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
615 return tokz_pushf(tokz, fname);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
616 }
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
617

mercurial