File: flexml.skel

package info (click to toggle)
flexml 1-5
  • links: PTS
  • area: main
  • in suites: potato, woody
  • size: 884 kB
  • ctags: 203
  • sloc: perl: 2,016; makefile: 160; ansic: 56; xml: 28
file content (813 lines) | stat: -rw-r--r-- 16,741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
head	1.7;
access;
symbols;
locks; strict;
comment	@ * @;


1.7
date	99.11.23.10.10.36;	author krisrose;	state Exp;
branches;
next	1.6;

1.6
date	99.11.23.09.32.31;	author krisrose;	state Exp;
branches;
next	1.5;

1.5
date	99.11.23.04.03.05;	author krisrose;	state Exp;
branches;
next	1.4;

1.4
date	99.11.22.18.41.48;	author krisrose;	state Exp;
branches;
next	1.3;

1.3
date	99.11.21.19.38.12;	author krisrose;	state Exp;
branches;
next	1.2;

1.2
date	99.11.08.03.21.00;	author krisrose;	state Exp;
branches;
next	1.1;

1.1
date	99.10.26.16.20.08;	author krisrose;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Spellling mistakes fixed...
@
text
@/* Flex(1) XML processor skeleton scanner.
 * Copyright  1999 Kristoffer Rose.  All rights reserved.
 * 
 * This file is part of the FleXML XML processor generator system.
 * Copyright  1999 Kristoffer Rose.  All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * Note: FleXML depends on the following line.
 */
%{

/* Version strings. */
const char* rcs_flexml_skeleton =
 "$Id: flexml.skel 1.6 1999/11/23 09:32:31 krisrose Exp krisrose $";
FLEXML_VERSION

/* ANSI headers. */
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
#include <ctype.h>

FLEXML_API

/* XML state. */
#ifdef DEBUG
#define ENTER(state)	(yy_push_state(state),fprintf(stderr,"--ENTER(%s)\n",X##state))
#define LEAVE(state)	(fprintf(stderr,"--LEAVE(%s)\n",X##state),yy_pop_state())
#else
#define ENTER(state)	(yy_push_state(state))
#define LEAVE(state)	(yy_pop_state())
#endif
#define CHECKEPILOG(tag) if (YY_START==ROOT_##tag) BEGIN(EPILOG)

/* Generic actions. */
#define SKIP	/*skip*/
#define FAIL	return fail
#define SUCCEED	return 0

static int fail(const char* fmt, ...)
{
  va_list ap; va_start(ap, fmt);
  fprintf(stderr, "Invalid XML: ");
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  va_end(ap);
  return 1;
}

/* Text buffer stack. */
#define ROOTBUFFERSIZE 100000
static char rootbuffer[ROOTBUFFERSIZE];
static char* limit = rootbuffer + ROOTBUFFERSIZE;
typedef struct BufferLast_s {
  struct BufferLast_s *old; char* saved; char new[1];
} BufferLast;
static BufferLast* last = (BufferLast*)0;
static char* next = rootbuffer;

#define BUFFERSET(P) (P = next)
#define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
#define BUFFERDONE    (BUFFERPUTC('\0'))

#define BUFFERLITERAL(C,P) \
  { char *s = strchr(yytext,C), *e = strrchr(yytext,C); \
    assert(s <= e); BUFFERSET(P); \
    while (++s<e) { \
      if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; } \
      else BUFFERPUTC(*s); \
    } \
    BUFFERDONE; }

void pushbuffer(char* p)
{
  BufferLast* l = (BufferLast*)next;
  assert(next < limit);
  l->old = last;
  l->saved = p;
  next = l->new;
  last = l;
}

char* popbuffer(void)
{
  BufferLast* l = last;
  assert(last != (BufferLast*)0);
  last = l->old;
  next = (char*)l;
  return l->saved;
}


/* General entities are `unput' back onto the input stream... */
#define ENTITYTEXT(T) \
  { char *s = (T), *e = s+strlen(s);\
    while (--e >= s) { unput(*e); }}
%}

/* Flex options. */
%option 8bit
%option stack
%option noyy_top_state
%option noinput
%option noreject
%option noyymore
%option noyywrap
FLEXML_FLEX_OPTIONS

/* XML character classes (currently restricted to ASCII). */

/* "Common syntactic structures." */
S		[ \t\n\r\f]+
s		[ \t\n\r\f]*

/* "Names and Tokens." */
NameChar	[A-Za-z0-9.:_-]
Name		[A-Za-z_:]{NameChar}*
Names 		{Name}({S}{Name})*
Nmtoken		({NameChar})+
Nmtokens 	{Nmtoken}({S}{Nmtoken})*

/* Miscellaneous. */
VersionNum	[a-zA-Z0-9_.:-]+
Eq		{s}"="{s}
Literal		'[^'']*'|"[^""]*"

/* "Attribute types." */

/* Exclusive parser states:
 *
 * INITIAL	initial state of scanner (not used)
 * PROLOG	the XML prolog of the document before <?xml...>
 * DOCTYPE	the XML prolog of the document after <?xml...>
 * EPILOG	after the root element
 * COMMENT	inside an XML comment <!--....-->
 * VALUE1	inside a '...'-delimited literal
 * VALUE2	inside a "..."-delimited literal
 * CDATA	inside a <![CDATA[...]]> section.
 * ROOT_<tag>	expect root element <tag>
 * AL_<tag>	inside the attribute list for <tag>
 * IN_<tag>	inside a <tag> with element contents
 * DISABLE	dummy to permit disabling rules
 */
%x PROLOG DOCTYPE EPILOG COMMENT VALUE1 VALUE2 CDATA DISABLE
FLEXML_START_CONDITIONS

%%

 /* Bypass INITIAL state and begin by parsing the XML prolog. */
 BEGIN(PROLOG);

 /* PROLOG: determine root element and process it. */
<PROLOG>{
 "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?"?>" BEGIN(DOCTYPE);
 "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
}

<PROLOG,DOCTYPE>{
FLEXML_DOCTYPES
 "<!--"		ENTER(COMMENT);
 "<!"[^>]*">"	FAIL("Bad declaration %s.",yytext);
 {S} 		SKIP;
 . 		FAIL("Unexpected character `%c' in prolog.", *yytext);
 <<EOF>> 	FAIL("EOF in prolog.");
}

 /* RULES DERIVED FROM DTD. */
FLEXML_RULES

 /* EPILOG: after the root element. */

<EPILOG>{
 "<!--"		ENTER(COMMENT);
 {S} 		SKIP;
 . 		FAIL("Unexpected character `%c' after document.", *yytext);
 <<EOF>> 	SUCCEED;
}

 /* COMMON SYNTAX. */

 /* Comments. */

<COMMENT>{
 "-->"		LEAVE(COMMENT);
 {S}		|
 .		SKIP;
 <<EOF>>	FAIL("EOF in comment.");
}

 /* Character data. */

<FLEXML_MIXED,VALUE1,VALUE2>{
FLEXML_ENTITIES

 /* Standard entities. */
 "&amp;" 	BUFFERPUTC('&');
 "&lt;" 	BUFFERPUTC('<');
 "&gt;" 	BUFFERPUTC('>');
 "&apos;" 	BUFFERPUTC('\'');
 "&quot;" 	BUFFERPUTC('\"');

 /* Character entities. */
 "&#"[[:digit:]]+";"	BUFFERPUTC((unsigned char)atoi(yytext+2));
 "&#x"[[:xdigit:]]+";"	BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
}

<FLEXML_MIXED,VALUE1,VALUE2,CDATA>{
 "\n"		|
 "\r"		|
 "\r\n"		|
 "\n\r"		BUFFERPUTC('\n');
}

<FLEXML_MIXED>{
 "<!--"		ENTER(COMMENT);
 "<![CDATA["	ENTER(CDATA);
 "]]>"		FAIL("Unexpected `]]>' in character data.");
}

<VALUE1>{
 \'		BUFFERDONE; LEAVE(VALUE1);
 <<EOF>>	FAIL("EOF in literal (\"'\" expected).");
}

<VALUE2>{
 \"		BUFFERDONE; LEAVE(VALUE2);
 <<EOF>>	FAIL("EOF in literal (`\"' expected).");
}

<FLEXML_MIXED,VALUE1,VALUE2>{
 [^<&]		BUFFERPUTC(*yytext);
 [<&]		FAIL("Spurious `%c' in character data.",*yytext);
}

<CDATA>{
 "]]>"		LEAVE(CDATA);
 .		BUFFERPUTC(*yytext);
 <<EOF>>	FAIL("EOF in CDATA section.");
}

 /* Impossible rules to avoid warnings from flex(1). */

<INITIAL,DISABLE>{
  {S}		|
 .		|
   <<EOF>>	FAIL("Panic: INITIAL or DISABLE state entered?");
}

%%

/* Local Variables: */
/* mode:c */
/* End: */
@


1.6
log
@Documentation updated.
@
text
@d4 1
a4 1
 * This file is part of the FleXML XML processer generator system.
d27 1
a27 1
 "$Id: flexml.skel 1.5 1999/11/23 04:03:05 krisrose Exp krisrose $";
@


1.5
log
@Works for simple examples
@
text
@a4 1
 * See the companion README and INSTALL files for further information.
d27 1
a27 1
 "$Id: flexml.skel 1.4 1999/11/22 18:41:48 krisrose Exp krisrose $";
d75 13
a105 13

#define BUFFERSET(P) (P = next)
#define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
#define BUFFERDONE    (BUFFERPUTC('\0'))

#define BUFFERLITERAL(C,P) \
  { char *s = strchr(yytext,C), *e = strrchr(yytext,C); \
    assert(s <= e); BUFFERSET(P); \
    while (++s<e) { \
      if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; } \
      else BUFFERPUTC(*s); \
    } \
    BUFFERDONE; }
@


1.4
log
@Working like mad...
@
text
@d28 1
a28 1
 "$Id: flexml.skel 1.3 1999/11/21 19:38:12 krisrose Exp krisrose $";
d37 1
d42 4
d48 1
a48 4

#define ENTER(state)	(yy_push_state(state))
#define LEAVE(state)	(yy_pop_state())

d51 3
a53 17
/* Text buffer. */
#define BUFFERSIZE 24000
static char buffer[BUFFERSIZE];
static char* nextp;
static char* lastp = buffer+BUFFERSIZE-1;
#define BUFFERINIT (nextp = buffer)
#define BUFFERSET(P) (P = nextp)
#define BUFFERPUTC(C) (assert(nextp<lastp), *(nextp++) = (C))
#define BUFFERDONE (BUFFERPUTC('\0'))

/* General entities are unput back onto the input stream... */
#define ENTITYTEXT(T) { char *s = (T), *e = s+strlen(s);\
                        while (--e >= s) { unput(*e); }}

/* Actions. */
#define SKIP
#define FAIL	fail
a55 1
/* Diagnostics. */
d63 21
a83 1
  exit(1);
d85 28
d123 1
d129 1
d132 2
a133 2
NameChar	[[:alpha][:digit].:_-]
Name		[[:alpha:]_:]{NameChar}*
d140 2
a141 1
Eq		{S}?"="{S}?
d143 1
d145 1
a145 1
/* XML parser states:
d147 1
d165 1
a165 1
 /* PROLOG: determine root element and process it. */
d168 5
a172 1
<PROLOG>"<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?"?>" BEGIN(DOCTYPE);
d177 1
@


1.3
log
@Moved to flexml.skel.
@
text
@a0 1
%{
d22 1
a22 1
 * (Note: FleXML depends on the format of this comment.)
d24 1
d26 1
d28 2
a29 1
"$Id: skeleton.l,v 1.2 1999/11/08 03:21:00 krisrose Exp krisrose $";
d42 5
a46 1
#define LEAVE(state)	(assert(yy_top_state()==state), yy_pop_state())
d58 4
a61 1
#define ENTITYTEXT(T) 
d65 1
a65 1
#define FAIL	return fail
d76 1
a76 1
  return 1;
d83 1
a84 1
%option nounput
d102 1
a102 1
Version		([a-zA-Z0-9_.:-])+
d107 2
a108 2
 *  
 * INITIAL	the XML prolog of the document before <?xml...>
a113 1
 * PCDATA	inside a <tag> with textual ("mixed") contents
d118 1
d120 1
a120 1
%x DOCTYPE EPILOG COMMENT VALUE1 VALUE2 PCDATA CDATA
d125 2
a126 1
    /* PROLOG: determine root element and process it. */
d128 1
a128 1
<INITIAL>"<?xml"[^>]*"?>" BEGIN(DOCTYPE);
d130 1
a130 1
<DOCTYPE,INITIAL>{
d138 1
a138 1
    /* RULES DERIVED FROM DTD. */
d141 1
a141 1
    /* EPILOG: after the root element. */
d150 1
a150 1
    /* COMMON SYNTAX. */
d152 1
a152 1
    /* Comments. */
d161 1
a161 4
    /* Text. */

<VALUE1>\'	BUFFERDONE; LEAVE(VALUE1);
<VALUE2>\"	BUFFERDONE; LEAVE(VALUE2);
d163 1
a163 6
<PCDATA>{
 "<!--"		ENTER(COMMENT);
 "<![CDATA["	ENTER(CDATA);
}

<PCDATA,VALUE1,VALUE2>{
d166 1
d172 2
a175 2
 .		|
 "\n"		BUFFERPUTC(*yytext);
d178 17
a194 3
<PCDATA><<EOF>>	FAIL("Premature EOF.");
<VALUE1><<EOF>>	FAIL("EOF in literal (' expected).");
<VALUE2><<EOF>>	FAIL("EOF in literal (\" expected).");
d196 9
a204 1
    /* Literal data. */
d208 8
d217 1
a217 2
 "\n"		BUFFERPUTC(*yytext);
 <<EOF>>	FAIL("EOF in CDATA section.");
d221 4
@


1.2
log
@ZZzzz.
@
text
@d2 11
a12 3
/*
 * FleXML: flex(1) based XML scanner generator.
 * Copyright  1999 NTSys, Ecully (France).  All rights reserved.
d14 4
a17 4
 * Description: Flex(1) skeleton scanner for XML data
 * Author:	Kristoffer Rose
 * Created:	August 1999
 * License:	GNU GPL "copyleft"
d19 3
a21 4
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
d23 1
a23 10
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
FLEXML_TOPMATTER
d27 1
a27 3
"$Header: /plume/yquem/home/krisrose/cons/FleXML/RCS/skeleton.l,v 1.1 1999/10/26 16:20:08 krisrose Exp krisrose $";

FLEXML_VERSION
d34 1
d38 1
a38 1
/* Internals. */
d41 1
d43 1
d50 19
a68 2
#define BUFFERPUT(C) (assert(nextp<lastp), *(nextp++) = (C))
#define BUFFERNEXT (BUFFERPUT('\0'))
d71 1
a71 2
/* Flex options for in-memory scanner with stack... */

d82 1
a83 3
s		[ \t\n\r\f]*

NameChar	[[:alpha]_:[:digit].-]
d85 3
a87 1
Name		[[:alpha:]_:]{NameChar}+
a88 1

d92 3
a94 2
Eq		{s}"="{s}
Q		[\'\"]
d96 2
a97 1
/* Start conditions:
d99 10
a108 6
 * INITIAL	the XML prolog of the document
 * COMMENT	inside an XML comment <!--....-->		(exclusive)
 * XML		ready for XML elements
 * AT_<tag>	inside the attribute list for <tag>
 * VALUE1	inside a '...'-delimited attribute value	(exclusive)
 * VALUE2	inside a "..."-delimited attribute value	(exclusive)
a109 1
 * PCDATA	inside a <tag> with textual contents		(exclusive)
d111 2
d114 1
a114 4
%x COMMENT
%s XML
%x VALUE1 VALUE2
%x PCDATA CDATA
d116 1
d118 1
a118 3
/* Start conditions derived from DTD. */
FLEXML_START_CONDITIONS
/* End of start conditions derived from DTD. */
d120 7
d128 2
a129 1
%%
d131 1
a131 1
    /* GENERIC RULES PART. */
d133 5
a137 4
<INITIAL>{
 "<?xml"{S}([^?]|"?"[^>])*"?>"		|
FLEXML_DOCTYPE
 {S}					;
d140 3
a142 1
    /* Comments are permitted almost everywhere, including in the prolog. */
a143 1
"<!--"					ENTER(COMMENT);
d145 4
a148 2
 .|{S}					/*IGNORE*/;
 "-->"					LEAVE(COMMENT);
d151 1
a151 1
    /* The prolog is finished as soon as none of the above rules apply :) */
d153 2
a154 1
<INITIAL>				BEGIN(XML);
d156 4
a159 7

    /* Rules derived from DTD. */
FLEXML_RULES

    /* End of rules derived from DTD. */

    /* CharData. */
d162 1
a162 7
 "&amp;" 				BUFFERPUT('&');
 "&lt;" 				BUFFERPUT('<');
 "&gt;" 				BUFFERPUT('>');
 "&apos;" 				BUFFERPUT('\'');
 "&quot;" 				BUFFERPUT('"');
 "&#"[[:digit:]]+";"			BUFFERPUT((char)atoi(yytext+2));
}
d164 9
a172 2
<VALUE1,VALUE2>"%"[0-9a-zA-Z][0-9a-zA-Z] {
    BUFFERPUT((char)strtol(yytext+1,NULL,16));
d175 11
a185 15
<VALUE1>\'				BUFFERNEXT; LEAVE(VALUE1);
<VALUE2>\"				BUFFERNEXT; LEAVE(VALUE2);

<PCDATA,VALUE1,VALUE2>[^&<]		BUFFERPUT(*yytext);

    /* Comments are permitted in text mode. */

<PCDATA>"<!--"				ENTER(COMMENT);

    /* Literal text. */

<PCDATA>"<![CDATA["			ENTER(CDATA);
<CDATA> {
 "]]>"					LEAVE(CDATA);
 .					BUFFERPUT(*yytext);
a186 4

    /* Only `normal' exit is at the end of the input. */

<<EOF>>				yyterminate();
@


1.1
log
@Initial revision
@
text
@d28 2
a29 2
static char* rcs_flexml_skeleton =
"$Header: /var/cvsroot/ntsys/FleXML/skeleton.l,v 1.8 1999/09/14 15:42:13 krisrose Exp $";
d37 1
d39 1
d41 12
a52 32
/* ------------------- USER HANDLER DECLARATIONS -------------------- */

void XML_init(void);
void XML_eof(void);
FLEXML_HANDLER_DECLARATIONS

/* --------------- END OF USER HANDLER DECLARATIONS ----------------- */


/* Declarations for use in the flex rules. */

#define STag(tag)	(STag_##tag(), flexml_new_emit())
#define ETag(tag)	flexml_pass_emitted(&ETag_##tag)

#define ENTER(state)	(flexml_new_emit(), yy_push_state(state))
#define LEAVE(state)	(flexml_new_emit(), yy_pop_state())

typedef void FLEXML_Handler(char*);
FLEXML_Handler* flexml_text_handlerp;
#define Attribute(tag,attribute) \
  (ENTER(yytext[yyleng-1] == '\'' ? VALUE1 : VALUE2), \
   flexml_new_emit(), flexml_text_handlerp = &Attribute_##tag##_##attribute)
#define HANDLE		flexml_pass_emitted(flexml_text_handlerp)

void flexml_new_emit(void);
void flexml_emit(char);
void flexml_pass_emitted(FLEXML_Handler*);

void flexml_dummy_STag(char*);
void flexml_dummy_ETag(char*,char*);
void flexml_dummy_Attribute(char*,char*,char*);

a62 1
%option noyy_top_state
d96 1
a96 1
%x PCDATA
d110 1
a110 1
 "<!DOCTYPE"{S}[^][>]*">"		|
d124 1
a124 1
<INITIAL>				XML_init(); BEGIN(XML);
d135 6
a140 6
 "&amp;" 				flexml_emit('&');
 "&lt;" 				flexml_emit('<');
 "&gt;" 				flexml_emit('>');
 "&apos;" 				flexml_emit('\'');
 "&quot;" 				flexml_emit('"');
 "&#"[[:digit:]]+";"			flexml_emit((char)atoi(yytext+2));
d144 1
a144 1
    flexml_emit((char)strtol(yytext+1,NULL,16));
d147 2
a148 2
<VALUE1>\'			HANDLE, LEAVE(VALUE1);
<VALUE2>\"			HANDLE, LEAVE(VALUE2);
d150 1
a150 1
<PCDATA,VALUE1,VALUE2>[^&<]	flexml_emit(yytext[0]);
d154 1
a154 1
<PCDATA>"<!--"			ENTER(COMMENT);
d156 1
a156 1
    /* Unmatched stuff ignored silently... */
d158 7
a164 1
<*>{S}|.			;
d166 1
a166 1
<<EOF>>				XML_eof();
a168 27

    /* GENERIC C FUNCTION PART. */

/* Emit buffer management.  (TODO: use recursive scanning.) */

#define BIGBLOCKSIZE 10000
char emit_buf[BIGBLOCKSIZE];
int total;

void flexml_new_emit(void)
{
    memset(emit_buf,0,BIGBLOCKSIZE);
    total = 0;
}

void flexml_emit(char c)
{
    if (total+1 < BIGBLOCKSIZE)
	emit_buf[total++] = c;
    else
	fprintf(stderr, "#PCDATA or AttributeValue to long.\n");
}

void flexml_pass_emitted(FLEXML_Handler* hp)
{
    (*hp)(emit_buf);
}
@