1
/* Validating XML processor for octave.dtd.
2
* Generated 2004/02/13 14:47:24.
4
* This program was generated with the FleXML XML processor generator,
5
* (Id: flexml.pl,v 1.28 2003/02/12 02:55:41 krisrose Exp).
6
* Copyright � 1999 Kristoffer Rose. All rights reserved.
8
* You can redistribute and/or modify this program provided the following
11
* 1. The program is distributed WITHOUT ANY WARRANTY from the author of
12
* FleXML; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE.
15
* 2. The program distribution conditions do not in any way affect the
16
* distribution conditions of the FleXML system used to generate this
17
* file or any version of FleXML derived from that system.
19
* Notice that these are explicit rights granted to you for files
20
* generated by the FleXML system. For your rights in connection with
21
* the FleXML system itself please consult the GNU General Public License.
26
/* Version strings. */
27
const char rcs_flexml_skeleton[] =
28
"$" "Id: skel,v 1.16 1999/12/09 04:01:51 krisrose Exp $";
29
const char rcs_flexml[] =
30
"$" "Id: flexml.pl,v 1.28 2003/02/12 02:55:41 krisrose Exp $";
40
/* Generated definitions. */
41
#define FLEXML_BUFFERSTACKSIZE 100000
43
/* XML application entry points. */
44
static void STag_octave(void);
45
static void ETag_octave(void);
46
static void STag_scalar(void);
47
static void ETag_scalar(void);
48
static void STag_complex(void);
49
static void ETag_complex(void);
50
static void STag_string(void);
51
static void ETag_string(void);
52
static void STag_array(void);
53
static void ETag_array(void);
54
static void STag_matrix(void);
55
static void ETag_matrix(void);
56
static void STag_structure(void);
57
static void ETag_structure(void);
58
static void STag_list(void);
59
static void ETag_list(void);
60
static void STag_cell(void);
61
static void ETag_cell(void);
63
/* XML application data. */
64
typedef char* AT_list_length;
65
#define AU_list_length NULL
66
typedef char* AT_matrix_rows;
67
#define AU_matrix_rows NULL
68
typedef char* AT_matrix_name;
69
#define AU_matrix_name NULL
70
typedef char* AT_cell_columns;
71
#define AU_cell_columns NULL
72
typedef char* AT_scalar_name;
73
#define AU_scalar_name NULL
74
typedef char* AT_array_name;
75
#define AU_array_name NULL
76
typedef char* AT_complex_name;
77
#define AU_complex_name NULL
78
typedef char* AT_matrix_columns;
79
#define AU_matrix_columns NULL
80
typedef char* AT_cell_name;
81
#define AU_cell_name NULL
82
typedef char* AT_string_length;
83
#define AU_string_length NULL
84
typedef char* AT_list_name;
85
#define AU_list_name NULL
86
typedef enum { AU_scalar_value, A_scalar_value_undefined,A_scalar_value_true,A_scalar_value_false,A_scalar_value_inf,A_scalar_value_neginf,A_scalar_value_na,A_scalar_value_nan } AT_scalar_value;
87
typedef char* AT_structure_name;
88
#define AU_structure_name NULL
89
typedef char* AT_cell_rows;
90
#define AU_cell_rows NULL
91
typedef char* AT_array_rows;
92
#define AU_array_rows NULL
93
typedef char* AT_string_name;
94
#define AU_string_name NULL
96
/* FleXML-provided data. */
98
static AT_list_length A_list_length;
99
static AT_matrix_rows A_matrix_rows;
100
static AT_matrix_name A_matrix_name;
101
static AT_cell_columns A_cell_columns;
102
static AT_scalar_name A_scalar_name;
103
static AT_array_name A_array_name;
104
static AT_complex_name A_complex_name;
105
static AT_matrix_columns A_matrix_columns;
106
static AT_cell_name A_cell_name;
107
static AT_string_length A_string_length;
108
static AT_list_name A_list_name;
109
static AT_scalar_value A_scalar_value;
110
static AT_structure_name A_structure_name;
111
static AT_cell_rows A_cell_rows;
112
static AT_array_rows A_array_rows;
113
static AT_string_name A_string_name;
117
# define ENTER(state) debug_enter(state,#state)
118
# define LEAVE debug_leave()
119
# define SET(state) debug_set(state,#state)
120
static void debug_enter(int, char*);
121
static void debug_leave(void);
122
static void debug_set(int, char*);
124
# define ENTER(state) (yy_push_state(state))
125
# define LEAVE (yy_pop_state())
126
# define SET(state) BEGIN(state)
129
/* Generic actions. */
130
#define SKIP /*skip*/
131
#define SUCCEED return 0
133
#define FAIL return fail
134
static int fail(const char*, ...);
136
/* Text buffer stack handling. */
137
char bufferstack[FLEXML_BUFFERSTACKSIZE];
138
char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE;
139
typedef struct BufferLast_s {
140
struct BufferLast_s *old; char* saved; char new[1];
142
BufferLast* last = (BufferLast*)0;
143
char* next = bufferstack;
145
#define BUFFERSET(P) (P = next)
146
#define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
147
#define BUFFERDONE (BUFFERPUTC('\0'))
149
#define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
150
static void bufferliteral(char c, char** pp, char* text)
152
char *s = strchr(text,c), *e = strrchr(text,c);
153
assert(s <= e); BUFFERSET(*pp);
155
if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
161
#ifdef FLEXML_HasMixed
162
static void pushbuffer(char* p)
164
BufferLast* l = (BufferLast*)next;
165
assert(next < limit);
172
static char* popbuffer(void)
174
BufferLast* l = last;
175
assert(last != (BufferLast*)0);
182
/* General internal entities are `unput' back onto the input stream... */
183
#define ENTITYTEXT(T) \
184
{ char *s = (T), *e = s+strlen(s);\
185
while (--e >= s) { unput(*e); }}
188
/* Flex standard options. */
190
%option noyy_top_state
196
/* Flex user-requested options. */
199
/* XML character classes (currently restricted to ASCII). */
201
/* "Common syntactic structures." */
205
/* "Names and Tokens." */
206
NameChar [A-Za-z0-9.:_-]
207
Name [A-Za-z_:]{NameChar}*
208
Names {Name}({S}{Name})*
209
Nmtoken ({NameChar})+
210
Nmtokens {Nmtoken}({S}{Nmtoken})*
213
VersionNum [a-zA-Z0-9_.:-]+
215
Literal \'[^'']*\'|\"[^""]*\"
217
/* Parser states (flex `exclusive start conditions'):
219
* PROLOG the XML prolog of the document before <?xml...>
220
* DOCTYPE the XML prolog of the document after <?xml...>
221
* EPILOG after the root element
222
* INCOMMENT inside an XML comment <!--....-->
223
* INPI inside an XML PI <?...?>
224
* VALUE1 inside a '...'-delimited literal
225
* VALUE2 inside a "..."-delimited literal
226
* CDATA inside a <![CDATA[...]]> section.
227
* ROOT_<tag> expect root element <tag>
228
* AL_<tag> inside the attribute list for <tag>
229
* IN_<tag> inside a <tag> with element contents (ready for end tag)
230
* IMPOSSIBLE dummy to permit disabling rules; must be last
232
%x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
233
%x ROOT_octave AL_octave S_octave E_octave
234
%x ROOT_scalar AL_scalar IN_scalar
235
%x ROOT_complex AL_complex S_complex S_complex_1 E_complex
236
%x ROOT_string AL_string IN_string
237
%x ROOT_array AL_array S_array S_array_1 S_array_2 S_array_3 E_array
238
%x ROOT_matrix AL_matrix S_matrix S_matrix_1 S_matrix_2 E_matrix
239
%x ROOT_structure AL_structure IN_structure
240
%x ROOT_list AL_list IN_list
241
%x ROOT_cell AL_cell IN_cell
246
char* statenames[IMPOSSIBLE];
248
void FleXML_init(void)
250
statenames[PROLOG] = NULL;
251
statenames[DOCTYPE] = NULL;
252
statenames[EPILOG] = NULL;
253
statenames[INCOMMENT] = NULL;
254
statenames[INPI] = NULL;
255
statenames[VALUE1] = NULL;
256
statenames[VALUE2] = NULL;
257
statenames[CDATA] = NULL;
258
statenames[ROOT_octave] = NULL;
259
statenames[AL_octave] = NULL;
260
statenames[S_octave] = "octave";
261
statenames[E_octave] = "octave";
262
statenames[ROOT_scalar] = NULL;
263
statenames[AL_scalar] = NULL;
264
statenames[IN_scalar] = "scalar";
265
statenames[ROOT_complex] = NULL;
266
statenames[AL_complex] = NULL;
267
statenames[S_complex] = "complex";
268
statenames[S_complex_1] = "complex";
269
statenames[E_complex] = "complex";
270
statenames[ROOT_string] = NULL;
271
statenames[AL_string] = NULL;
272
statenames[IN_string] = "string";
273
statenames[ROOT_array] = NULL;
274
statenames[AL_array] = NULL;
275
statenames[S_array] = "array";
276
statenames[S_array_1] = "array";
277
statenames[S_array_2] = "array";
278
statenames[S_array_3] = "array";
279
statenames[E_array] = "array";
280
statenames[ROOT_matrix] = NULL;
281
statenames[AL_matrix] = NULL;
282
statenames[S_matrix] = "matrix";
283
statenames[S_matrix_1] = "matrix";
284
statenames[S_matrix_2] = "matrix";
285
statenames[E_matrix] = "matrix";
286
statenames[ROOT_structure] = NULL;
287
statenames[AL_structure] = NULL;
288
statenames[IN_structure] = "structure";
289
statenames[ROOT_list] = NULL;
290
statenames[AL_list] = NULL;
291
statenames[IN_list] = "list";
292
statenames[ROOT_cell] = NULL;
293
statenames[AL_cell] = NULL;
294
statenames[IN_cell] = "cell";
300
/* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
301
SET(PROLOG); FleXML_init();
303
/* COMMENTS and PIs: handled uniformly for efficiency. */
305
<ROOT_octave,AL_octave,S_octave,E_octave,ROOT_scalar,AL_scalar,IN_scalar,ROOT_complex,AL_complex,S_complex,S_complex_1,E_complex,ROOT_string,AL_string,IN_string,ROOT_array,AL_array,S_array,S_array_1,S_array_2,S_array_3,E_array,ROOT_matrix,AL_matrix,S_matrix,S_matrix_1,S_matrix_2,E_matrix,ROOT_structure,AL_structure,IN_structure,ROOT_list,AL_list,IN_list,ROOT_cell,AL_cell,IN_cell,PROLOG,DOCTYPE,EPILOG>{
306
"<!--" ENTER(INCOMMENT);
314
<<EOF>> FAIL("EOF in comment.");
320
<<EOF>> FAIL("EOF in PI (processing instruction).");
323
/* SPACES: skipped uniformly */
325
<ROOT_octave,AL_octave,S_octave,E_octave,ROOT_scalar,AL_scalar,ROOT_complex,AL_complex,S_complex,S_complex_1,E_complex,ROOT_string,AL_string,ROOT_array,AL_array,S_array,S_array_1,S_array_2,S_array_3,E_array,ROOT_matrix,AL_matrix,S_matrix,S_matrix_1,S_matrix_2,E_matrix,ROOT_structure,AL_structure,ROOT_list,AL_list,ROOT_cell,AL_cell,PROLOG,DOCTYPE,EPILOG>{S} SKIP;
327
/* PROLOG: determine root element and process it. */
330
"<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?"?>" SET(DOCTYPE);
331
"<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
335
"<!DOCTYPE"{S}"scalar"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_scalar);
336
"<!DOCTYPE"{S}"octave"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_octave);
337
"<!DOCTYPE"{S}"complex"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_complex);
338
"<!DOCTYPE"{S}"string"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_string);
339
"<!DOCTYPE"{S}"matrix"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_matrix);
340
"<!DOCTYPE"{S}"array"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_array);
341
"<!DOCTYPE"{S}"structure"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_structure);
342
"<!DOCTYPE"{S}"cell"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_cell);
343
"<!DOCTYPE"{S}"list"{S}SYSTEM{S}("'octave.dtd'"|"\"octave.dtd\""){s}">" SET(ROOT_list);
344
"<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
345
. FAIL("Unexpected character `%c' in prolog.", yytext[0]);
346
<<EOF>> FAIL("EOF in prolog.");
349
/* RULES DERIVED FROM DTD. */
351
<ROOT_octave,IN_list,IN_structure,IN_cell>"<octave"{s} {
357
LEAVE; STag_octave(); pcdata = NULL; ENTER(S_octave);
359
"/>" FAIL("`octave' element cannot be empty.");
360
. FAIL("Unexpected character `%c' in attribute list of octave element.", yytext[0]);
361
{Name} FAIL("Bad attribute `%s' in `octave' element start tag.",yytext);
362
<<EOF>> FAIL("EOF in attribute list of `octave' element.");
370
case ROOT_octave: SET(EPILOG); break;
373
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</octave>' expected.",yytext);
374
. FAIL("Unexpected character `%c': `</octave>' expected.",yytext[0]);
375
<<EOF>> FAIL("Premature EOF: `</octave>' expected.");
378
/* value (undefined | true | false | inf | neginf | na | nan) "undefined"
379
* name CDATA #IMPLIED> */
381
<ROOT_scalar,IN_list,S_matrix_2,IN_cell,S_octave,S_complex,S_matrix_1,S_complex_1,S_matrix,IN_structure>"<scalar"{s} {
382
A_scalar_value = A_scalar_value_undefined;
383
A_scalar_name = NULL;
388
"value"{Eq}"'undefined'" |
389
"value"{Eq}"\"undefined\"" A_scalar_value = A_scalar_value_undefined;
390
"value"{Eq}"'true'" |
391
"value"{Eq}"\"true\"" A_scalar_value = A_scalar_value_true;
392
"value"{Eq}"'false'" |
393
"value"{Eq}"\"false\"" A_scalar_value = A_scalar_value_false;
395
"value"{Eq}"\"inf\"" A_scalar_value = A_scalar_value_inf;
396
"value"{Eq}"'neginf'" |
397
"value"{Eq}"\"neginf\"" A_scalar_value = A_scalar_value_neginf;
399
"value"{Eq}"\"na\"" A_scalar_value = A_scalar_value_na;
401
"value"{Eq}"\"nan\"" A_scalar_value = A_scalar_value_nan;
403
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_scalar_name);
404
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_scalar_name);
407
LEAVE; STag_scalar(); pcdata = BUFFERSET(pcdata); ENTER(IN_scalar);
410
LEAVE; STag_scalar(); pcdata = ""; ETag_scalar();
412
case S_complex_1: SET(E_complex); break;
413
case S_octave: SET(E_octave); break;
414
case S_complex: SET(S_complex_1); break;
415
case S_matrix_1: case S_matrix: case S_matrix_2: SET(S_matrix_2); break;
416
case ROOT_scalar: SET(EPILOG); break;
419
. FAIL("Unexpected character `%c' in attribute list of scalar element.", yytext[0]);
420
{Name} FAIL("Bad attribute `%s' in `scalar' element start tag.",yytext);
421
<<EOF>> FAIL("EOF in attribute list of `scalar' element.");
430
case S_complex_1: SET(E_complex); break;
431
case S_octave: SET(E_octave); break;
432
case S_complex: SET(S_complex_1); break;
433
case S_matrix_1: case S_matrix: case S_matrix_2: SET(S_matrix_2); break;
434
case ROOT_scalar: SET(EPILOG); break;
437
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</scalar>' expected.",yytext);
438
<<EOF>> FAIL("Premature EOF: `</scalar>' expected.");
441
<ROOT_complex,IN_list,S_matrix_2,IN_cell,S_octave,S_matrix_1,S_matrix,IN_structure>"<complex"{s} {
442
A_complex_name = NULL;
447
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_complex_name);
448
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_complex_name);
451
LEAVE; STag_complex(); pcdata = NULL; ENTER(S_complex);
453
"/>" FAIL("`complex' element cannot be empty.");
454
. FAIL("Unexpected character `%c' in attribute list of complex element.", yytext[0]);
455
{Name} FAIL("Bad attribute `%s' in `complex' element start tag.",yytext);
456
<<EOF>> FAIL("EOF in attribute list of `complex' element.");
464
case S_octave: SET(E_octave); break;
465
case S_matrix_1: case S_matrix: case S_matrix_2: SET(S_matrix_2); break;
466
case ROOT_complex: SET(EPILOG); break;
469
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</complex>' expected.",yytext);
470
. FAIL("Unexpected character `%c': `</complex>' expected.",yytext[0]);
471
<<EOF>> FAIL("Premature EOF: `</complex>' expected.");
474
/* length CDATA #REQUIRED
475
* name CDATA #IMPLIED> */
477
<ROOT_string,S_array,IN_list,S_array_1,IN_cell,S_octave,S_array_2,S_array_3,IN_structure>"<string"{s} {
478
A_string_length = NULL;
479
A_string_name = NULL;
484
"length"{Eq}\' ENTER(VALUE1); BUFFERSET(A_string_length);
485
"length"{Eq}\" ENTER(VALUE2); BUFFERSET(A_string_length);
487
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_string_name);
488
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_string_name);
491
if (!A_string_length) FAIL("Required attribute `length' not set for `string' element.");
492
LEAVE; STag_string(); pcdata = BUFFERSET(pcdata); ENTER(IN_string);
495
if (!A_string_length) FAIL("Required attribute `length' not set for `string' element.");
496
LEAVE; STag_string(); pcdata = ""; ETag_string();
498
case S_octave: SET(E_octave); break;
499
case S_array_2: case S_array_3: case S_array_1: SET(S_array_3); break;
500
case ROOT_string: SET(EPILOG); break;
501
case S_array: SET(S_array_1); break;
504
. FAIL("Unexpected character `%c' in attribute list of string element.", yytext[0]);
505
{Name} FAIL("Bad attribute `%s' in `string' element start tag.",yytext);
506
<<EOF>> FAIL("EOF in attribute list of `string' element.");
515
case S_octave: SET(E_octave); break;
516
case S_array_2: case S_array_3: case S_array_1: SET(S_array_3); break;
517
case ROOT_string: SET(EPILOG); break;
518
case S_array: SET(S_array_1); break;
521
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</string>' expected.",yytext);
522
<<EOF>> FAIL("Premature EOF: `</string>' expected.");
525
/* rows CDATA #REQUIRED
526
* name CDATA #IMPLIED> */
528
<ROOT_array,IN_list,IN_cell,S_octave,IN_structure>"<array"{s} {
535
"rows"{Eq}\' ENTER(VALUE1); BUFFERSET(A_array_rows);
536
"rows"{Eq}\" ENTER(VALUE2); BUFFERSET(A_array_rows);
538
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_array_name);
539
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_array_name);
542
if (!A_array_rows) FAIL("Required attribute `rows' not set for `array' element.");
543
LEAVE; STag_array(); pcdata = NULL; ENTER(S_array);
545
"/>" FAIL("`array' element cannot be empty.");
546
. FAIL("Unexpected character `%c' in attribute list of array element.", yytext[0]);
547
{Name} FAIL("Bad attribute `%s' in `array' element start tag.",yytext);
548
<<EOF>> FAIL("EOF in attribute list of `array' element.");
556
case S_octave: SET(E_octave); break;
557
case ROOT_array: SET(EPILOG); break;
560
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</array>' expected.",yytext);
561
. FAIL("Unexpected character `%c': `</array>' expected.",yytext[0]);
562
<<EOF>> FAIL("Premature EOF: `</array>' expected.");
565
/* rows CDATA #REQUIRED
566
* columns CDATA #REQUIRED
567
* name CDATA #IMPLIED> */
569
<ROOT_matrix,IN_list,IN_cell,IN_structure>"<matrix"{s} {
570
A_matrix_rows = NULL;
571
A_matrix_columns = NULL;
572
A_matrix_name = NULL;
577
"rows"{Eq}\' ENTER(VALUE1); BUFFERSET(A_matrix_rows);
578
"rows"{Eq}\" ENTER(VALUE2); BUFFERSET(A_matrix_rows);
580
"columns"{Eq}\' ENTER(VALUE1); BUFFERSET(A_matrix_columns);
581
"columns"{Eq}\" ENTER(VALUE2); BUFFERSET(A_matrix_columns);
583
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_matrix_name);
584
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_matrix_name);
587
if (!A_matrix_rows) FAIL("Required attribute `rows' not set for `matrix' element.");
588
if (!A_matrix_columns) FAIL("Required attribute `columns' not set for `matrix' element.");
589
LEAVE; STag_matrix(); pcdata = NULL; ENTER(S_matrix);
592
if (!A_matrix_rows) FAIL("Required attribute `rows' not set for `matrix' element.");
593
if (!A_matrix_columns) FAIL("Required attribute `columns' not set for `matrix' element.");
594
LEAVE; STag_matrix(); pcdata = NULL; ETag_matrix();
596
case ROOT_matrix: SET(EPILOG); break;
599
. FAIL("Unexpected character `%c' in attribute list of matrix element.", yytext[0]);
600
{Name} FAIL("Bad attribute `%s' in `matrix' element start tag.",yytext);
601
<<EOF>> FAIL("EOF in attribute list of `matrix' element.");
604
<S_matrix,S_matrix_2,E_matrix>{
609
case ROOT_matrix: SET(EPILOG); break;
612
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</matrix>' expected.",yytext);
613
. FAIL("Unexpected character `%c': `</matrix>' expected.",yytext[0]);
614
<<EOF>> FAIL("Premature EOF: `</matrix>' expected.");
617
<ROOT_structure,IN_list,IN_cell,S_octave,IN_structure>"<structure"{s} {
618
A_structure_name = NULL;
623
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_structure_name);
624
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_structure_name);
627
LEAVE; STag_structure(); pcdata = BUFFERSET(pcdata); ENTER(IN_structure);
630
LEAVE; STag_structure(); pcdata = ""; ETag_structure();
632
case S_octave: SET(E_octave); break;
633
case ROOT_structure: SET(EPILOG); break;
636
. FAIL("Unexpected character `%c' in attribute list of structure element.", yytext[0]);
637
{Name} FAIL("Bad attribute `%s' in `structure' element start tag.",yytext);
638
<<EOF>> FAIL("EOF in attribute list of `structure' element.");
642
"</structure"{s}">" {
647
case S_octave: SET(E_octave); break;
648
case ROOT_structure: SET(EPILOG); break;
651
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</structure>' expected.",yytext);
652
<<EOF>> FAIL("Premature EOF: `</structure>' expected.");
655
/* length CDATA #REQUIRED
656
* name CDATA #IMPLIED> */
658
<ROOT_list,IN_list,IN_cell,S_octave,IN_structure>"<list"{s} {
659
A_list_length = NULL;
665
"length"{Eq}\' ENTER(VALUE1); BUFFERSET(A_list_length);
666
"length"{Eq}\" ENTER(VALUE2); BUFFERSET(A_list_length);
668
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_list_name);
669
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_list_name);
672
if (!A_list_length) FAIL("Required attribute `length' not set for `list' element.");
673
LEAVE; STag_list(); pcdata = BUFFERSET(pcdata); ENTER(IN_list);
676
if (!A_list_length) FAIL("Required attribute `length' not set for `list' element.");
677
LEAVE; STag_list(); pcdata = ""; ETag_list();
679
case S_octave: SET(E_octave); break;
680
case ROOT_list: SET(EPILOG); break;
683
. FAIL("Unexpected character `%c' in attribute list of list element.", yytext[0]);
684
{Name} FAIL("Bad attribute `%s' in `list' element start tag.",yytext);
685
<<EOF>> FAIL("EOF in attribute list of `list' element.");
694
case S_octave: SET(E_octave); break;
695
case ROOT_list: SET(EPILOG); break;
698
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</list>' expected.",yytext);
699
<<EOF>> FAIL("Premature EOF: `</list>' expected.");
702
/* rows CDATA #REQUIRED
703
* columns CDATA #REQUIRED
704
* name CDATA #IMPLIED> */
706
<ROOT_cell,IN_list,IN_cell,S_octave,IN_structure>"<cell"{s} {
708
A_cell_columns = NULL;
714
"rows"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cell_rows);
715
"rows"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cell_rows);
717
"columns"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cell_columns);
718
"columns"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cell_columns);
720
"name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cell_name);
721
"name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cell_name);
724
if (!A_cell_rows) FAIL("Required attribute `rows' not set for `cell' element.");
725
if (!A_cell_columns) FAIL("Required attribute `columns' not set for `cell' element.");
726
LEAVE; STag_cell(); pcdata = BUFFERSET(pcdata); ENTER(IN_cell);
729
if (!A_cell_rows) FAIL("Required attribute `rows' not set for `cell' element.");
730
if (!A_cell_columns) FAIL("Required attribute `columns' not set for `cell' element.");
731
LEAVE; STag_cell(); pcdata = ""; ETag_cell();
733
case S_octave: SET(E_octave); break;
734
case ROOT_cell: SET(EPILOG); break;
737
. FAIL("Unexpected character `%c' in attribute list of cell element.", yytext[0]);
738
{Name} FAIL("Bad attribute `%s' in `cell' element start tag.",yytext);
739
<<EOF>> FAIL("EOF in attribute list of `cell' element.");
748
case S_octave: SET(E_octave); break;
749
case ROOT_cell: SET(EPILOG); break;
752
"</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</cell>' expected.",yytext);
753
<<EOF>> FAIL("Premature EOF: `</cell>' expected.");
756
/* EPILOG: after the root element. */
759
. FAIL("Unexpected character `%c' after document.", yytext[0]);
763
/* CHARACTER DATA. */
765
<IN_scalar,IN_structure,IN_string,IN_cell,IN_list,VALUE1,VALUE2>{
766
/* Non-defined standard entities... */
767
"&" BUFFERPUTC('&');
768
"<" BUFFERPUTC('<');
769
">" BUFFERPUTC('>');
770
"'" BUFFERPUTC('\'');
771
""" BUFFERPUTC('"');
773
/* Character entities. */
774
"&#"[[:digit:]]+";" BUFFERPUTC((unsigned char)atoi(yytext+2));
775
"&#x"[[:xdigit:]]+";" BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
778
<IN_scalar,IN_structure,IN_string,IN_cell,IN_list,VALUE1,VALUE2,CDATA>{
782
"\n\r" BUFFERPUTC('\n');
785
<IN_scalar,IN_structure,IN_string,IN_cell,IN_list>{
786
"<![CDATA[" ENTER(CDATA);
787
"]]>" FAIL("Unexpected `]]>' in character data.");
791
\' BUFFERDONE; LEAVE;
792
<<EOF>> FAIL("EOF in literal (\"'\" expected).");
796
\" BUFFERDONE; LEAVE;
797
<<EOF>> FAIL("EOF in literal (`\"' expected).");
800
<IN_scalar,IN_structure,IN_string,IN_cell,IN_list,VALUE1,VALUE2>{
801
[^<&] BUFFERPUTC(yytext[0]);
802
[<&] FAIL("Spurious `%c' in character data.",yytext[0]);
807
"]]" BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]);
808
. BUFFERPUTC(yytext[0]);
809
<<EOF>> FAIL("EOF in CDATA section.");
812
/* Impossible rules to avoid warnings from flex(1). */
814
<INITIAL,IMPOSSIBLE>{
815
.|[\n] FAIL("The Impossible Happened: INITIAL or IMPOSSIBLE state entered?");
820
/* Element context stack lookup. */
821
int element_context(int i)
823
return (0<i && i<yy_start_stack_depth
824
? yy_start_stack[yy_start_stack_ptr - i]
829
void print_yy_stack(char* fmt, ...)
831
int i = 0; va_list ap; va_start(ap, fmt);
832
vfprintf(stderr, fmt, ap);
833
for (i=1; i<yy_start_stack_ptr; i++)
834
fprintf(stderr, "%s/", statenames[yy_start_stack[i]]);
835
fprintf(stderr,"%s\n", statenames[YY_START]);
839
static void debug_enter(int state, char* statename) {
840
yy_push_state(state);
841
if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
844
static void debug_leave(void) {
845
if (yy_flex_debug) print_yy_stack("--LEAVE : ");
849
static void debug_set(int state, char* statename) {
851
if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
856
static int fail(const char* fmt, ...)
858
va_list ap; va_start(ap, fmt);
859
#ifdef FLEXML_yylineno
860
fprintf(stderr, "Invalid XML (XML input line %d, state %d): ", yylineno, YY_START);
862
fprintf(stderr, "Invalid XML (state %d): ",YY_START);
864
vfprintf(stderr, fmt, ap);
865
fprintf(stderr, "\n");
870
#line 30 "xmltree_read.act"
877
#define warning perror
883
void STag_octave(void)
885
#line 43 "xmltree_read.act"
887
root = new_element();
888
root->def_value = value_data;
889
current = &(root->child);
891
lastlist = new_list(lastlist);
892
lastlist->root = current;
896
void ETag_octave(void)
898
#line 52 "xmltree_read.act"
900
current = lastlist->root;
901
lastlist = pop_list(lastlist);
902
current = &((*current)->next);
906
void STag_scalar(void)
908
#line 60 "xmltree_read.act"
910
*current = new_element();
913
(*current)->name = (char *) malloc(strlen(A_scalar_name)+1);
914
strcpy ((*current)->name, A_scalar_name);
917
(*current)->def_value = value_scalar;
918
switch (A_scalar_value) {
919
case A_scalar_value_true: (*current)->const_value = const_true; break;
920
case A_scalar_value_false: (*current)->const_value = const_false; break;
921
case A_scalar_value_inf: (*current)->const_value = const_inf; break;
922
case A_scalar_value_neginf: (*current)->const_value = const_neginf; break;
923
case A_scalar_value_nan: (*current)->const_value = const_nan; break;
924
case A_scalar_value_na: (*current)->const_value = const_na; break;
925
default: (*current)->const_value = const_undef;
930
void ETag_scalar(void)
932
#line 80 "xmltree_read.act"
934
if (((*current)->const_value == const_undef) && (pcdata))
935
(*current)->scalar_value = strtod (pcdata, NULL);
937
(*(lastlist->root))->nb_elements++;
939
current = &((*current)->next);
943
void STag_string(void)
945
#line 91 "xmltree_read.act"
947
*current = new_element();
950
(*current)->name = (char *) malloc(strlen(A_string_name)+1);
951
strcpy ((*current)->name, A_string_name);
955
(*current)->length = strtol (A_string_length, NULL, 10);
957
(*current)->def_value = value_string;
961
void ETag_string(void)
963
#line 105 "xmltree_read.act"
967
int len = strlen(pcdata);
968
/* check length parameter */
969
if ((*current)->length != len) {
970
warning("incorrect length parameter for string\n");
971
(*current)->length = len;
974
(*current)->string_value = (char *) malloc ((len+1) * sizeof(char));
975
strcpy((*current)->string_value, pcdata);
978
(*(lastlist->root))->nb_elements++;
980
current = &((*current)->next);
984
void STag_complex(void)
986
#line 126 "xmltree_read.act"
988
*current = new_element();
990
if (A_complex_name) {
991
(*current)->name = (char *) malloc(strlen(A_complex_name)+1);
992
strcpy ((*current)->name, A_complex_name);
995
(*current)->def_value = value_complex;
997
lastlist = new_list(lastlist);
998
lastlist->root = current;
999
current = &((*current)->child);
1001
} /* STag_complex */
1003
void ETag_complex(void)
1005
#line 141 "xmltree_read.act"
1007
current = lastlist->root;
1008
lastlist = pop_list(lastlist);
1010
(*(lastlist->root))->nb_elements++;
1012
current = &((*current)->next);
1014
} /* ETag_complex */
1016
void STag_array(void)
1018
#line 152 "xmltree_read.act"
1020
*current = new_element();
1023
(*current)->name = (char *) malloc(strlen(A_array_name)+1);
1024
strcpy ((*current)->name, A_array_name);
1028
(*current)->rows = strtol (A_array_rows, NULL, 10);
1030
(*current)->def_value = value_array;
1032
lastlist = new_list(lastlist);
1033
lastlist->root = current;
1034
current = &((*current)->child);
1038
void ETag_array(void)
1040
#line 170 "xmltree_read.act"
1042
/* check rows parameter */
1043
if ((*(lastlist->root))->rows != (*(lastlist->root))->nb_elements) {
1044
warning("incorrect length parameter for array\n");
1045
(*(lastlist->root))->rows = (*(lastlist->root))->nb_elements;
1048
current = lastlist->root;
1049
lastlist = pop_list(lastlist);
1051
(*(lastlist->root))->nb_elements++;
1053
current = &((*current)->next);
1057
void STag_matrix(void)
1059
#line 187 "xmltree_read.act"
1061
*current = new_element();
1063
if (A_matrix_name) {
1064
(*current)->name = (char *) malloc(strlen(A_matrix_name)+1);
1065
strcpy ((*current)->name, A_matrix_name);
1069
(*current)->rows = strtol (A_matrix_rows, NULL, 10);
1071
if (A_matrix_columns)
1072
(*current)->columns = strtol (A_matrix_columns, NULL, 10);
1074
(*current)->def_value = value_matrix;
1076
lastlist = new_list(lastlist);
1077
lastlist->root = current;
1078
current = &((*current)->child);
1082
void ETag_matrix(void)
1084
#line 208 "xmltree_read.act"
1086
/* check (rows, columns) parameters */
1087
if ((*(lastlist->root))->rows * (*(lastlist->root))->columns !=
1088
(*(lastlist->root))->nb_elements) {
1089
warning("incorrect (rows, columns) parameters for matrix: reshaping matrix into vector\n");
1090
(*(lastlist->root))->rows = 1;
1091
(*(lastlist->root))->columns = (*(lastlist->root))->nb_elements;
1094
current = lastlist->root;
1095
lastlist = pop_list(lastlist);
1097
(*(lastlist->root))->nb_elements++;
1099
current = &((*current)->next);
1103
void STag_structure(void)
1105
#line 227 "xmltree_read.act"
1107
*current = new_element();
1109
if (A_structure_name) {
1110
(*current)->name = (char *) malloc(strlen(A_structure_name)+1);
1111
strcpy ((*current)->name, A_structure_name);
1114
(*current)->def_value = value_structure;
1116
lastlist = new_list(lastlist);
1117
lastlist->root = current;
1118
current = &((*current)->child);
1120
} /* STag_structure */
1122
void ETag_structure(void)
1124
#line 242 "xmltree_read.act"
1126
/* no check possible (sic) */
1128
current = lastlist->root;
1129
lastlist = pop_list(lastlist);
1131
(*(lastlist->root))->nb_elements++;
1133
current = &((*current)->next);
1135
} /* ETag_structure */
1137
void STag_list(void)
1139
#line 255 "xmltree_read.act"
1141
*current = new_element();
1144
(*current)->name = (char *) malloc(strlen(A_list_name)+1);
1145
strcpy ((*current)->name, A_list_name);
1149
(*current)->length = strtol (A_list_length, NULL, 10);
1151
(*current)->def_value = value_list;
1153
lastlist = new_list(lastlist);
1154
lastlist->root = current;
1155
current = &((*current)->child);
1159
void ETag_list(void)
1161
#line 273 "xmltree_read.act"
1163
/* check length parameter */
1164
if ((*(lastlist->root))->length != (*(lastlist->root))->nb_elements) {
1165
warning("incorrect length parameter for list\n");
1166
(*(lastlist->root))->length = (*(lastlist->root))->nb_elements;
1169
current = lastlist->root;
1170
lastlist = pop_list(lastlist);
1172
(*(lastlist->root))->nb_elements++;
1174
current = &((*current)->next);
1178
void STag_cell(void)
1180
#line 290 "xmltree_read.act"
1182
*current = new_element();
1185
(*current)->name = (char *) malloc(strlen(A_cell_name)+1);
1186
strcpy ((*current)->name, A_cell_name);
1190
(*current)->rows = strtol (A_cell_rows, NULL, 10);
1193
(*current)->columns = strtol (A_cell_columns, NULL, 10);
1195
(*current)->def_value = value_cell;
1197
lastlist = new_list(lastlist);
1198
lastlist->root = current;
1199
current = &((*current)->child);
1203
void ETag_cell(void)
1205
#line 311 "xmltree_read.act"
1207
/* check (rows, columns) parameters */
1208
if ((*(lastlist->root))->rows * (*(lastlist->root))->columns !=
1209
(*(lastlist->root))->nb_elements) {
1210
warning("incorrect (rows, columns) parameters for cell: reshaping cell into list\n");
1211
(*(lastlist->root))->def_value = value_list;
1212
(*(lastlist->root))->length = (*(lastlist->root))->nb_elements;
1215
current = lastlist->root;
1216
lastlist = pop_list(lastlist);
1218
(*(lastlist->root))->nb_elements++;
1220
current = &((*current)->next);
1225
#line 346 "xmltree_read.act"
1227
element *read_xmltree (const char *file) {
1233
xml_in = fopen(file, "r");
1235
perror("can't open file\n");
1244
/* XML application entry points. */