parser.c

Sat, 14 May 2005 22:23:20 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 14 May 2005 22:23:20 +0200
changeset 100
8ae0f0aa5a16
parent 70
e866dc825481
permissions
-rw-r--r--

Added some coercions to remove gcc complaints in snprintf_2.2.

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 *
36
63cd573ffbcf trunk: changeset 39
tuomov
parents: 35
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
53
f8f9366b359c trunk: changeset 57
tuomov
parents: 46
diff changeset
5 *
f8f9366b359c trunk: changeset 57
tuomov
parents: 46
diff changeset
6 * You may distribute and modify this library under the terms of either
f8f9366b359c trunk: changeset 57
tuomov
parents: 46
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
0
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>
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
11 #include <errno.h>
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
12
70
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
13 #include "parser.h"
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
14 #include "misc.h"
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
15 #include "output.h"
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
16
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
17 #define MAX_TOKENS 256
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
18 #define MAX_NEST 256
0
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
21 enum{
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
22 P_NONE=1,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
23 P_EOF,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
24 P_STMT,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
25 P_STMT_NS,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
26 P_STMT_SECT,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
27 P_BEG_SECT,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
28 P_END_SECT
0
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
20
3f11f764772a trunk: changeset 23
tuomov
parents: 17
diff changeset
32 /* */
0
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
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
35 static bool opt_include(Tokenizer *tokz, int n, Token *toks);
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
36
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
37
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
38 static ConfOpt common_opts[]={
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
39 {"include", "s", opt_include, NULL},
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
40 {NULL, NULL, NULL, NULL}
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
41 };
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
42
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
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
46
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
47 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
48 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
49 int ntokens=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
50 Token *tok=NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
51 int had_comma=0; /* 0 - no, 1 - yes, 2 - not had, not expected */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
52 int retval=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
53 int e=0;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
54
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
55 while(1){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
56 tok=&tokens[ntokens];
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
57
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
58 if(!tokz_get_token(tokz, tok)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
59 e=1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
60 continue;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
61 }
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
62
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
63 if(ntokens==MAX_TOKENS-1){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
64 e=E_TOKZ_TOKEN_LIMIT;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
65 tokz_warn_error(tokz, tok->line, e);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
66 if(!(tokz->flags&TOKZ_ERROR_TOLERANT))
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
67 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
68 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
69 ntokens++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
70 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
71
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
72 if(!TOK_IS_OP(tok)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
73 if(ntokens==1 && !had_comma){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
74 /* first token */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
75 had_comma=2;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
76 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
77 if(had_comma==0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
78 goto syntax;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
79
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
80 had_comma=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
81 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
82 continue;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
83 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
84
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
85 /* It is an operator */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
86 ntokens--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
87
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
88 switch(TOK_OP_VAL(tok)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
89 case OP_SCOLON:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
90 retval=(ntokens==0 ? P_NONE : P_STMT_NS);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
91 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
92
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
93 case OP_NEXTLINE:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
94 retval=(ntokens==0 ? P_NONE : P_STMT);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
95 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
96
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
97 case OP_L_BRC:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
98 retval=(ntokens==0 ? P_BEG_SECT : P_STMT_SECT);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
99 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
100
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
101 case OP_R_BRC:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
102 if(ntokens==0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
103 retval=P_END_SECT;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
104 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
105 tokz_unget_token(tokz, tok);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
106 retval=P_STMT_NS;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
107 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
108 break;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
109
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
110 case OP_EOF:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
111 retval=(ntokens==0 ? P_EOF : P_STMT_NS);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
112
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
113 if(had_comma==1){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
114 e=E_TOKZ_UNEXPECTED_EOF;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
115 goto handle_error;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
116 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
117
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
118 goto end;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
119
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
120 case OP_COMMA:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
121 if(had_comma!=0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
122 goto syntax;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
123
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
124 had_comma=1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
125 continue;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
126
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
127 default:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
128 goto syntax;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
129 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
130
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
131 if(had_comma!=1)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
132 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
133
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
134 syntax:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
135 e=E_TOKZ_SYNTAX;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
136 handle_error:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
137 tokz_warn_error(tokz, tok->line, e);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
138
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
139 if(!(tokz->flags&TOKZ_ERROR_TOLERANT) || retval!=0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
140 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
141 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
142
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
143 end:
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
144 if(e!=0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
145 retval=-retval;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
146
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
147 *ntok_ret=ntokens;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
148
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
149 return retval;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
150 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
151
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
152
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
153 static bool find_beg_sect(Tokenizer *tokz)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
154 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
155 Token tok=TOK_INIT;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
156
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
157 while(tokz_get_token(tokz, &tok)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
158 if(TOK_IS_OP(&tok)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
159 if(TOK_OP_VAL(&tok)==OP_NEXTLINE)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
160 continue;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
161
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
162 if(TOK_OP_VAL(&tok)==OP_SCOLON)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
163 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
164
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
165 if(TOK_OP_VAL(&tok)==OP_L_BRC)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
166 return TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
167 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
168
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
169 tokz_unget_token(tokz, &tok);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
170 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
171 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
172 return FALSE;
2
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
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
176 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
177
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
178
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
179 static const ConfOpt* lookup_option(const ConfOpt *opts, const char *name)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
180 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
181 while(opts->optname!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
182 if(strcmp(opts->optname, name)==0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
183 return opts;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
184 opts++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
185 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
186 return NULL;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
187 }
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
188
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
189
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
190 static bool call_end_sect(Tokenizer *tokz, const ConfOpt *opts)
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
191 {
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
192 opts=lookup_option(opts, "#end");
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
193 if(opts!=NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
194 return opts->fn(tokz, 0, NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
195
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
196 return TRUE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
197 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
198
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
199
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
200 static bool call_cancel_sect(Tokenizer *tokz, const ConfOpt *opts)
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
201 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
202 opts=lookup_option(opts, "#cancel");
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
203 if(opts!=NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
204 return opts->fn(tokz, 0, NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
205
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
206 return TRUE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
207 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
208
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
209
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
210 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
211
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
212
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
213 bool parse_config_tokz(Tokenizer *tokz, const ConfOpt *options)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
214 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
215 Token tokens[MAX_TOKENS];
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
216 bool alloced_optstack=FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
217 int i, t, ntokens=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
218 int init_nest_lvl;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
219 bool had_error;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
220 int errornest=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
221 bool is_default=FALSE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
222
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
223 /* Allocate tokz->optstack if it does not yet exist (if it does,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
224 * we have been called from an option handler)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
225 */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
226 if(!tokz->optstack){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
227 tokz->optstack=ALLOC_N(const ConfOpt*, MAX_NEST);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
228 if(!tokz->optstack){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
229 warn_err();
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
230 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
231 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
232
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
233 memset(tokz->optstack, 0, sizeof(ConfOpt*)*MAX_NEST);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
234 init_nest_lvl=tokz->nest_lvl=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
235 alloced_optstack=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
236 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
237 init_nest_lvl=tokz->nest_lvl;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
238 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
239
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
240 tokz->optstack[init_nest_lvl]=options;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
241
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
242 for(i=0; i<MAX_TOKENS; i++)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
243 tok_init(&tokens[i]);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
244
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
245
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
246 while(1){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
247 had_error=FALSE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
248
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
249 /* free the tokens */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
250 while(ntokens--)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
251 tok_free(&tokens[ntokens]);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
252
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
253 /* read the tokens */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
254 t=read_statement(tokz, tokens, &ntokens);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
255
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
256 if((had_error=t<0))
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
257 t=-t;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
258
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
259 switch(t){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
260 case P_STMT:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
261 case P_STMT_NS:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
262 case P_STMT_SECT:
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
263
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
264 if(errornest)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
265 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
266 else if(tokz->flags&TOKZ_PARSER_INDENT_MODE)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
267 verbose_indent(tokz->nest_lvl);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
268
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
269 if(!TOK_IS_IDENT(tokens+0)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
270 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
271 tokz_warn_error(tokz, tokens->line,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
272 E_TOKZ_IDENTIFIER_EXPECTED);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
273 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
274
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
275 if(t==P_STMT){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
276 if(find_beg_sect(tokz))
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
277 t=P_STMT_SECT;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
278 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
279
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
280 if(had_error)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
281 break;
22
79fb689317ea trunk: changeset 25
tuomov
parents: 20
diff changeset
282
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
283 /* Got the statement and its type */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
284
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
285 options=lookup_option(tokz->optstack[tokz->nest_lvl],
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
286 TOK_IDENT_VAL(tokens+0));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
287 if(options==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
288 options=lookup_option(common_opts, TOK_IDENT_VAL(tokens+0));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
289 if(options==NULL && (tokz->flags&TOKZ_DEFAULT_OPTION)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
290 options=lookup_option(tokz->optstack[tokz->nest_lvl], "#default");
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
291 is_default=(options!=NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
292 }
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
293
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
294 if(options==NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
295 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
296 tokz_warn_error(tokz, tokens->line, E_TOKZ_UNKNOWN_OPTION);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
297 }else if(!is_default) {
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
298 had_error=!check_args(tokz, tokens, ntokens, options->argfmt);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
299 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
300
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
301 if(had_error)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
302 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
303
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
304 /* Found the option and arguments are ok */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
305
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
306 if(options->opts!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
307 if(t!=P_STMT_SECT){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
308 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
309 tokz_warn_error(tokz, tokz->line, E_TOKZ_LBRACE_EXPECTED);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
310 }else if(tokz->nest_lvl==MAX_NEST-1){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
311 tokz_warn_error(tokz, tokz->line, E_TOKZ_MAX_NEST);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
312 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
313 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
314 tokz->nest_lvl++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
315 tokz->optstack[tokz->nest_lvl]=options->opts;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
316 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
317 }else if(t==P_STMT_SECT){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
318 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
319 tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
320 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
321
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
322 if(!had_error && options->fn!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
323 had_error=!options->fn(tokz, ntokens, tokens);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
324 if(t==P_STMT_SECT && had_error)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
325 tokz->nest_lvl--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
326 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
327 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
328
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
329 case P_EOF:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
330 if(tokz_popf(tokz)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
331 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
332 }else if(tokz->nest_lvl>0 || errornest>0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
333 tokz_warn_error(tokz, 0, E_TOKZ_UNEXPECTED_EOF);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
334 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
335 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
336 goto eof;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
337
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
338 case P_BEG_SECT:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
339 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
340 errornest++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
341 tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
342 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
343
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
344 case P_END_SECT:
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
345 if(tokz->nest_lvl+errornest==0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
346 tokz_warn_error(tokz, tokz->line, E_TOKZ_SYNTAX);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
347 had_error=TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
348 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
349
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
350 if(had_error)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
351 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
352
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
353 if(errornest!=0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
354 errornest--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
355 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
356 had_error=!call_end_sect(tokz, tokz->optstack[tokz->nest_lvl]);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
357 tokz->nest_lvl--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
358 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
359
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
360 if(tokz->nest_lvl<init_nest_lvl)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
361 goto eof;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
362 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
363
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
364 if(!had_error)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
365 continue;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
366
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
367 if(t==P_STMT_SECT)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
368 errornest++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
369
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
370 if(!(tokz->flags&TOKZ_ERROR_TOLERANT))
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
371 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
372 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
373
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
374 eof:
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
375 /* free the tokens */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
376 while(ntokens--)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
377 tok_free(&tokens[ntokens]);
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
378
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
379 while(tokz->nest_lvl>=init_nest_lvl){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
380 if(tokz->flags&TOKZ_ERROR_TOLERANT || !had_error)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
381 call_end_sect(tokz, tokz->optstack[tokz->nest_lvl]);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
382 else
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
383 call_cancel_sect(tokz, tokz->optstack[tokz->nest_lvl]);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
384 tokz->nest_lvl--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
385 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
386
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
387 /* Free optstack if it was alloced by this call */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
388 if(alloced_optstack){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
389 free(tokz->optstack);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
390 tokz->optstack=NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
391 tokz->nest_lvl=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
392 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
393
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
394 if(tokz->flags&TOKZ_PARSER_INDENT_MODE)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
395 verbose_indent(init_nest_lvl);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
396
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
397 return !had_error;
0
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
403
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
404 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
405 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
406 Tokenizer *tokz;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
407 bool ret;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
408
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
409 tokz=tokz_open(fname);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
410
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
411 if(tokz==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
412 return FALSE;
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
413
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
414 tokz->flags|=flags&~TOKZ_READ_COMMENTS;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
415
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
416 ret=parse_config_tokz(tokz, options);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
417
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
418 tokz_close(tokz);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
419
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
420 return ret;
0
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
423
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
424 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
425 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
426 Tokenizer *tokz;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
427 bool ret;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
428
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
429 tokz=tokz_open_file(file, NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
430
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
431 if(tokz==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
432 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
433
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
434 tokz->flags|=flags&~TOKZ_READ_COMMENTS;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
435
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
436 ret=parse_config_tokz(tokz, options);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
437
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
438 tokz_close(tokz);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
439
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
440 return ret;
0
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 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
445 * Argument validity checking stuff
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
448
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
449 static int arg_match(Token *tok, char c, bool si)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
450 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
451 char c2=tok->type;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
452
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
453 if(c=='.' || c=='*')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
454 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
455
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
456 if(c2==c)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
457 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
458
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
459 if(si){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
460 if(c2=='i' && c=='s'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
461 TOK_SET_IDENT(tok, TOK_STRING_VAL(tok));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
462 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
463 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
464
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
465 if(c2=='s' && c=='i'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
466 TOK_SET_STRING(tok, TOK_IDENT_VAL(tok));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
467 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
468 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
469 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
470
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
471 if(c2=='c' && c=='l'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
472 TOK_SET_LONG(tok, TOK_CHAR_VAL(tok));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
473 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
474 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
475
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
476 if(c2=='l' && c=='c'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
477 TOK_SET_CHAR(tok, TOK_LONG_VAL(tok));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
478 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
479 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
480
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
481 if(c2=='l' && c=='d'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
482 TOK_SET_DOUBLE(tok, TOK_LONG_VAL(tok));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
483 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
484 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
485
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
486 if(c=='b'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
487 if(c2=='l'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
488 TOK_SET_BOOL(tok, TOK_LONG_VAL(tok));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
489 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
490 }else if(c2=='i'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
491 if(strcmp(TOK_IDENT_VAL(tok), "TRUE")==0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
492 tok_free(tok);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
493 TOK_SET_BOOL(tok, TRUE);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
494 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
495 }else if(strcmp(TOK_IDENT_VAL(tok), "FALSE")==0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
496 tok_free(tok);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
497 TOK_SET_BOOL(tok, FALSE);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
498 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
499 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
500 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
501 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
502
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
503 return E_TOKZ_INVALID_ARGUMENT;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
504 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
505
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
506
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
507 static int check_argument(const char **pret, Token *tok, const char *p,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
508 bool si)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
509 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
510 int mode;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
511 int e=E_TOKZ_TOO_MANY_ARGS;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
512
2
e14a1aba4c56 trunk: changeset 5
tuomov
parents: 1
diff changeset
513 again:
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
514 mode=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
515
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
516 if(*p=='*'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
517 *pret=p;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
518 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
519 }else if(*p=='?'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
520 mode=1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
521 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
522 }else if(*p==':'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
523 mode=2;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
524 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
525 }else if(*p=='+'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
526 *pret=p;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
527 return arg_match(tok, *(p-1), si);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
528 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
529
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
530 while(*p!='\0'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
531 e=arg_match(tok, *p, si);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
532 if(e==0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
533 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
534 while(mode==2 && *p==':'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
535 if(*++p=='\0')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
536 break; /* Invalid argument format string, though... */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
537 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
538 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
539 *pret=p;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
540 return 0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
541 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
542
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
543 if(mode==0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
544 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
545
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
546 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
547
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
548 if(mode==1)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
549 goto again;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
550
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
551 /* mode==2 */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
552
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
553 if(*p!=':')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
554 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
555 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
556 e=E_TOKZ_TOO_MANY_ARGS;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
557 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
558
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
559 *pret=p;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
560 return e;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
561 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
562
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
563
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
564 static bool args_at_end(const char *p)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
565 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
566 if(p==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
567 return TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
568
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
569 while(*p!='\0'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
570 if(*p=='*' || *p=='+')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
571 p++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
572 else if(*p=='?')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
573 p+=2;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
574 else
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
575 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
576 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
577
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
578 return TRUE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
579 }
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
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
582 bool do_check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
583 const char *fmt, bool si)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
584 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
585 int i;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
586 int e;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
587
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
588 if(fmt==NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
589 if(ntokens!=1)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
590 tokz_warn_error(tokz, tokens[0].line, E_TOKZ_TOO_MANY_ARGS);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
591 return ntokens==1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
592 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
593
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
594 for(i=1; i<ntokens; i++){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
595 e=check_argument(&fmt, &tokens[i], fmt, si);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
596 if(e!=0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
597 tokz_warn_error(tokz, tokens[i].line, e);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
598 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
599 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
600 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
601
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
602 if(!args_at_end(fmt)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
603 tokz_warn_error(tokz, tokens[i].line, E_TOKZ_TOO_FEW_ARGS);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
604 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
605 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
606
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
607 return TRUE;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
608 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
609
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
610
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
611 bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
612 const char *fmt)
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
613 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
614 return do_check_args(tokz, tokens, ntokens, fmt, FALSE);
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
615 }
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
616
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
617
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
618 bool check_args_loose(const Tokenizer *tokz, Token *tokens, int ntokens,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
619 const char *fmt)
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
620 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
621 return do_check_args(tokz, tokens, ntokens, fmt, TRUE);
40
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
622 }
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
623
0a050a9536a1 trunk: changeset 43
tuomov
parents: 36
diff changeset
624
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
625 /* */
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
626
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
627
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
628 static bool try_include(Tokenizer *tokz, const char *fname)
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
629 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
630 FILE *f;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
631
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
632 f=fopen(fname, "r");
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
633
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
634 if(f==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
635 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
636
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
637 if(!tokz_pushf_file(tokz, f, fname)){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
638 fclose(f);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
639 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
640 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
641
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
642 return TRUE;
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
643 }
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
644
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
645
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
646 static bool try_include_dir(Tokenizer *tokz, const char *dir, int dlen,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
647 const char *file)
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
648 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
649 char *tmpname;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
650 bool retval;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
651
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
652 tmpname=scatn(dir, dlen, file, -1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
653
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
654 if(tmpname==NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
655 warn_err();
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
656 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
657 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
658
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
659 retval=try_include(tokz, tmpname);
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
660
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
661 free(tmpname);
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
662
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
663 return retval;
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
664 }
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
665
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
666
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
667 static bool opt_include(Tokenizer *tokz, int n, Token *toks)
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
668 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
669 const char *fname=TOK_STRING_VAL(toks+1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
670 const char *lastndx=NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
671 bool retval, e;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
672 int i=0;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
673
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
674 if(fname[0]!='/' && tokz->name!=NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
675 lastndx=strrchr(tokz->name, '/');
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
676
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
677 if(lastndx==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
678 retval=try_include(tokz, fname);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
679 else
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
680 retval=try_include_dir(tokz, tokz->name, lastndx-tokz->name+1, fname);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
681
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
682 if(retval==TRUE)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
683 return TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
684
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
685 e=errno;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
686
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
687 if(tokz->includepaths!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
688 while(tokz->includepaths[i]!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
689 if(try_include_dir(tokz, tokz->includepaths[i], -1, fname))
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
690 return TRUE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
691 i++;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
692 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
693 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
694
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
695 warn_obj(fname, "%s", strerror(e));
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
696
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
697 return FALSE;
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
698 }
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
699
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
700
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
701 extern void tokz_set_includepaths(Tokenizer *tokz, char **paths)
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
702 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
703 tokz->includepaths=paths;
14
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
704 }
91f0c87b62a7 trunk: changeset 17
tuomov
parents: 13
diff changeset
705
46
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
706
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
707
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
708 ConfOpt libtu_dummy_confopts[]={
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
709 END_CONFOPTS
46
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
710 };
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
711
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
712
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
713
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
714 bool parse_config_tokz_skip_section(Tokenizer *tokz)
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
715 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
716 return parse_config_tokz(tokz, libtu_dummy_confopts);
46
c6deeee169aa trunk: changeset 50
tuomov
parents: 40
diff changeset
717 }

mercurial