Lines 186-196
EST_read_status EST_TNamedEnum<ENUM>::pr
Link Here
|
186 |
if ((file=fopen(name, "rb"))==NULL) |
186 |
if ((file=fopen(name, "rb"))==NULL) |
187 |
return misc_read_error; |
187 |
return misc_read_error; |
188 |
|
188 |
|
189 |
if (definitions) |
189 |
if (this->definitions) |
190 |
delete[] definitions; |
190 |
delete[] this->definitions; |
191 |
|
191 |
|
192 |
ndefinitions= -1; |
192 |
this->ndefinitions= -1; |
193 |
definitions=NULL; |
193 |
this->definitions=NULL; |
194 |
|
194 |
|
195 |
buffer[LINE_LENGTH-1] = 'x'; |
195 |
buffer[LINE_LENGTH-1] = 'x'; |
196 |
|
196 |
|
Lines 202-228
EST_read_status EST_TNamedEnum<ENUM>::pr
Link Here
|
202 |
return wrong_format; |
202 |
return wrong_format; |
203 |
} |
203 |
} |
204 |
|
204 |
|
205 |
if (ndefinitions>=0 && quote != '\0' && buffer[0] == '=') |
205 |
if (this->ndefinitions>=0 && quote != '\0' && buffer[0] == '=') |
206 |
{ |
206 |
{ |
207 |
// definition by number |
207 |
// definition by number |
208 |
|
208 |
|
209 |
if ( n>= ndefinitions) |
209 |
if ( n>= this->ndefinitions) |
210 |
{ |
210 |
{ |
211 |
cerr << "too many definitions\n"; |
211 |
cerr << "too many definitions\n"; |
212 |
return wrong_format; |
212 |
return wrong_format; |
213 |
} |
213 |
} |
214 |
|
214 |
|
215 |
int ntokens = split(line, tokens, NAMED_ENUM_MAX_SYNONYMS+2, RXwhite, '"'); |
215 |
int ntokens = split(line, tokens, NAMED_ENUM_MAX_SYNONYMS+2, RXwhite, '"'); |
216 |
definitions[n].token = (ENUM)atoi(tokens[0].after(0,1)); |
216 |
this->definitions[n].token = (ENUM)atoi(tokens[0].after(0,1)); |
217 |
|
217 |
|
218 |
for(int i=1; i<ntokens; i++) |
218 |
for(int i=1; i<ntokens; i++) |
219 |
definitions[n].values[i-1] = wstrdup(tokens[i].unquote_if_needed(quote)); |
219 |
this->definitions[n].values[i-1] = wstrdup(tokens[i].unquote_if_needed(quote)); |
220 |
for(int j=ntokens-1 ; j< NAMED_ENUM_MAX_SYNONYMS; j++) |
220 |
for(int j=ntokens-1 ; j< NAMED_ENUM_MAX_SYNONYMS; j++) |
221 |
definitions[n].values[j]=NULL; |
221 |
this->definitions[n].values[j]=NULL; |
222 |
|
222 |
|
223 |
n++; |
223 |
n++; |
224 |
} |
224 |
} |
225 |
else if (have_unknown && ndefinitions>=0 && quote != '\0' && buffer[0] == quote) |
225 |
else if (have_unknown && this->ndefinitions>=0 && quote != '\0' && buffer[0] == quote) |
226 |
{ |
226 |
{ |
227 |
// definition by standard name |
227 |
// definition by standard name |
228 |
if (!definitive) |
228 |
if (!definitive) |
Lines 230-236
EST_read_status EST_TNamedEnum<ENUM>::pr
Link Here
|
230 |
cerr << "can't use names in this definition\n"; |
230 |
cerr << "can't use names in this definition\n"; |
231 |
return wrong_format; |
231 |
return wrong_format; |
232 |
} |
232 |
} |
233 |
if ( n>= ndefinitions) |
233 |
if ( n>= this->ndefinitions) |
234 |
{ |
234 |
{ |
235 |
cerr << "too many definitions\n"; |
235 |
cerr << "too many definitions\n"; |
236 |
return wrong_format; |
236 |
return wrong_format; |
Lines 238-249
EST_read_status EST_TNamedEnum<ENUM>::pr
Link Here
|
238 |
|
238 |
|
239 |
int ntokens = split(line, tokens, NAMED_ENUM_MAX_SYNONYMS+2, RXwhite, quote); |
239 |
int ntokens = split(line, tokens, NAMED_ENUM_MAX_SYNONYMS+2, RXwhite, quote); |
240 |
|
240 |
|
241 |
definitions[n].token = definitive->token(tokens[0].unquote(quote)); |
241 |
this->definitions[n].token = definitive->token(tokens[0].unquote(quote)); |
242 |
|
242 |
|
243 |
for(int i=1; i<ntokens; i++) |
243 |
for(int i=1; i<ntokens; i++) |
244 |
definitions[n].values[i-1] = wstrdup(tokens[i].unquote_if_needed(quote)); |
244 |
this->definitions[n].values[i-1] = wstrdup(tokens[i].unquote_if_needed(quote)); |
245 |
for(int j=ntokens-1 ; j< NAMED_ENUM_MAX_SYNONYMS; j++) |
245 |
for(int j=ntokens-1 ; j< NAMED_ENUM_MAX_SYNONYMS; j++) |
246 |
definitions[n].values[j]=NULL; |
246 |
this->definitions[n].values[j]=NULL; |
247 |
|
247 |
|
248 |
n++; |
248 |
n++; |
249 |
} |
249 |
} |
Lines 269-284
EST_read_status EST_TNamedEnum<ENUM>::pr
Link Here
|
269 |
} |
269 |
} |
270 |
else if (key == "number") |
270 |
else if (key == "number") |
271 |
{ |
271 |
{ |
272 |
ndefinitions=atoi(line.after(eq,1)); |
272 |
this->ndefinitions=atoi(line.after(eq,1)); |
273 |
// cout << "n = '" << ndefinitions << "'\n"; |
273 |
// cout << "n = '" << ndefinitions << "'\n"; |
274 |
definitions = new Defn[ndefinitions]; |
274 |
this->definitions = new Defn[this->ndefinitions]; |
275 |
for(int i=0; i<ndefinitions; i++) |
275 |
for(int i=0; i<this->ndefinitions; i++) |
276 |
definitions[i].values[0] =NULL; |
276 |
this->definitions[i].values[0] =NULL; |
277 |
n=0; |
277 |
n=0; |
278 |
} |
278 |
} |
279 |
else if (key == "unknown") |
279 |
else if (key == "unknown") |
280 |
{ |
280 |
{ |
281 |
p_unknown_enum=(ENUM)atoi(line.after(eq,1)); |
281 |
this->p_unknown_enum=(ENUM)atoi(line.after(eq,1)); |
282 |
// cout << "unknown = '" << p_unknown_enum << "'\n"; |
282 |
// cout << "unknown = '" << p_unknown_enum << "'\n"; |
283 |
have_unknown=1; |
283 |
have_unknown=1; |
284 |
} |
284 |
} |
Lines 305-324
EST_write_status EST_TNamedEnum<ENUM>::p
Link Here
|
305 |
if ((file=fopen(name, "wb"))==NULL) |
305 |
if ((file=fopen(name, "wb"))==NULL) |
306 |
return write_fail; |
306 |
return write_fail; |
307 |
|
307 |
|
308 |
fprintf(file, "unknown=%d\n", p_unknown_enum); |
308 |
fprintf(file, "unknown=%d\n", this->p_unknown_enum); |
309 |
fprintf(file, "quote=%c\n", quote); |
309 |
fprintf(file, "quote=%c\n", quote); |
310 |
fprintf(file, "number=%d\n", ndefinitions); |
310 |
fprintf(file, "number=%d\n", this->ndefinitions); |
311 |
|
311 |
|
312 |
for(int i=0; i<ndefinitions; i++) |
312 |
for(int i=0; i<this->ndefinitions; i++) |
313 |
if (definitions[i].values[0]) |
313 |
if (this->definitions[i].values[0]) |
314 |
{ |
314 |
{ |
315 |
if (definitive) |
315 |
if (definitive) |
316 |
fprintf(file, "%s ", (const char *)EST_String(definitive->name(definitions[i].token)).quote(quote)); |
316 |
fprintf(file, "%s ", (const char *)EST_String(definitive->name(this->definitions[i].token)).quote(quote)); |
317 |
else |
317 |
else |
318 |
fprintf(file, "=%d ", (int)definitions[i].token); |
318 |
fprintf(file, "=%d ", (int)this->definitions[i].token); |
319 |
|
319 |
|
320 |
for(int j=0; j<NAMED_ENUM_MAX_SYNONYMS && definitions[i].values[j] != NULL; j++) |
320 |
for(int j=0; j<NAMED_ENUM_MAX_SYNONYMS && this->definitions[i].values[j] != NULL; j++) |
321 |
fprintf(file, "%s ", (const char *) EST_String(definitions[i].values[j]).quote_if_needed(quote)); |
321 |
fprintf(file, "%s ", (const char *) EST_String(this->definitions[i].values[j]).quote_if_needed(quote)); |
322 |
|
322 |
|
323 |
fputc('\n', file); |
323 |
fputc('\n', file); |
324 |
} |
324 |
} |