Debian Codegraph @

modules/gcide/markup.c

raw
1 /* This file is part of GNU Dico.
2 Copyright (C) 2012-2024 Sergey Poznyakoff
3
4 GNU Dico is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Dico is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <dico.h>
19 #include <unistd.h>
20 #include <getopt.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <sysexits.h>
25 #include <setjmp.h>
26 #include <ctype.h>
27 #include <appi18n.h>
28 #include "gcide.h"
29 #include "wordsplit.h"
30
31 #define yy_create_buffer gcide_markup_yy_create_buffer
32 #define yy_delete_buffer gcide_markup_yy_delete_buffer
33 #define yy_flex_debug gcide_markup_yy_flex_debug
34 #define yy_init_buffer gcide_markup_yy_init_buffer
35 #define yy_flush_buffer gcide_markup_yy_flush_buffer
36 #define yy_load_buffer_state gcide_markup_yy_load_buffer_state
37 #define yy_switch_to_buffer gcide_markup_yy_switch_to_buffer
38 #define yyin gcide_markup_yyin
39 #define yyleng gcide_markup_yyleng
40 #define yylex gcide_markup_yylex
41 #define yylineno gcide_markup_yylineno
42 #define yyout gcide_markup_yyout
43 #define yyrestart gcide_markup_yyrestart
44 #define yytext gcide_markup_yytext
45 #define yywrap gcide_markup_yywrap
46 #define yyalloc gcide_markup_yyalloc
47 #define yyrealloc gcide_markup_yyrealloc
48 #define yyfree gcide_markup_yyfree
49 #define yyunput gcide_markup_yyunput
50
51 #define yylex_destroy gcide_markup_yylex_destroy
52 #define yyget_debug gcide_markup_yyget_debug
53 #define yyset_debug gcide_markup_yyset_debug
54 #define yyget_extra gcide_markup_yyget_extra
55 #define yyset_extra gcide_markup_yyset_extra
56 #define yyget_in gcide_markup_yyget_in
57 #define yyset_in gcide_markup_yyset_in
58 #define yyget_out gcide_markup_yyget_out
59 #define yyset_out gcide_markup_yyset_out
60 #define yyget_leng gcide_markup_yyget_leng
61 #define yyget_text gcide_markup_yyget_text
62 #define yyget_lineno gcide_markup_yyget_lineno
63 #define yyset_lineno gcide_markup_yyset_lineno
64
65 #line 65 "markup.c"
66
67 #define YY_INT_ALIGNED short int
68
69 /* A lexical scanner generated by flex */
70
71 /* %not-for-header */
72 /* %if-c-only */
73 /* %if-not-reentrant */
74
75 /* %endif */
76 /* %endif */
77 /* %ok-for-header */
78
79 #define FLEX_SCANNER
80 #define YY_FLEX_MAJOR_VERSION 2
81 #define YY_FLEX_MINOR_VERSION 6
82 #define YY_FLEX_SUBMINOR_VERSION 4
83 #if YY_FLEX_SUBMINOR_VERSION > 0
84 #define FLEX_BETA
85 #endif
86
87 /* %if-c++-only */
88 /* %endif */
89
90 /* %if-c-only */
91
92 /* %endif */
93
94 /* %if-c-only */
95
96 /* %endif */
97
98 /* First, we deal with platform-specific or compiler-specific issues. */
99
100 /* begin standard C headers. */
101 /* %if-c-only */
102 #include <stdio.h>
103 #include <string.h>
104 #include <errno.h>
105 #include <stdlib.h>
106 /* %endif */
107
108 /* %if-tables-serialization */
109 /* %endif */
110 /* end standard C headers. */
111
112 /* %if-c-or-c++ */
113 /* flex integer type definitions */
114
115 #ifndef FLEXINT_H
116 #define FLEXINT_H
117
118 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
119
120 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
121
122 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
123 * if you want the limit (max/min) macros for int types.
124 */
125 #ifndef __STDC_LIMIT_MACROS
126 #define __STDC_LIMIT_MACROS 1
127 #endif
128
129 #include <inttypes.h>
130 typedef int8_t flex_int8_t;
131 typedef uint8_t flex_uint8_t;
132 typedef int16_t flex_int16_t;
133 typedef uint16_t flex_uint16_t;
134 typedef int32_t flex_int32_t;
135 typedef uint32_t flex_uint32_t;
136 #else
137 typedef signed char flex_int8_t;
138 typedef short int flex_int16_t;
139 typedef int flex_int32_t;
140 typedef unsigned char flex_uint8_t;
141 typedef unsigned short int flex_uint16_t;
142 typedef unsigned int flex_uint32_t;
143
144 /* Limits of integral types. */
145 #ifndef INT8_MIN
146 #define INT8_MIN (-128)
147 #endif
148 #ifndef INT16_MIN
149 #define INT16_MIN (-32767-1)
150 #endif
151 #ifndef INT32_MIN
152 #define INT32_MIN (-2147483647-1)
153 #endif
154 #ifndef INT8_MAX
155 #define INT8_MAX (127)
156 #endif
157 #ifndef INT16_MAX
158 #define INT16_MAX (32767)
159 #endif
160 #ifndef INT32_MAX
161 #define INT32_MAX (2147483647)
162 #endif
163 #ifndef UINT8_MAX
164 #define UINT8_MAX (255U)
165 #endif
166 #ifndef UINT16_MAX
167 #define UINT16_MAX (65535U)
168 #endif
169 #ifndef UINT32_MAX
170 #define UINT32_MAX (4294967295U)
171 #endif
172
173 #ifndef SIZE_MAX
174 #define SIZE_MAX (~(size_t)0)
175 #endif
176
177 #endif /* ! C99 */
178
179 #endif /* ! FLEXINT_H */
180
181 /* %endif */
182
183 /* begin standard C++ headers. */
184 /* %if-c++-only */
185 /* %endif */
186
187 /* TODO: this is always defined, so inline it */
188 #define yyconst const
189
190 #if defined(__GNUC__) && __GNUC__ >= 3
191 #define yynoreturn __attribute__((__noreturn__))
192 #else
193 #define yynoreturn
194 #endif
195
196 /* %not-for-header */
197 /* Returned upon end-of-file. */
198 #define YY_NULL 0
199 /* %ok-for-header */
200
201 /* %not-for-header */
202 /* Promotes a possibly negative, possibly signed char to an
203 * integer in range [0..255] for use as an array index.
204 */
205 #define YY_SC_TO_UI(c) ((YY_CHAR) (c))
206 /* %ok-for-header */
207
208 /* %if-reentrant */
209 /* %endif */
210
211 /* %if-not-reentrant */
212
213 /* %endif */
214
215 /* Enter a start condition. This macro really ought to take a parameter,
216 * but we do it the disgusting crufty way forced on us by the ()-less
217 * definition of BEGIN.
218 */
219 #define BEGIN (yy_start) = 1 + 2 *
220 /* Translate the current start state into a value that can be later handed
221 * to BEGIN to return to the state. The YYSTATE alias is for lex
222 * compatibility.
223 */
224 #define YY_START (((yy_start) - 1) / 2)
225 #define YYSTATE YY_START
226 /* Action number for EOF rule of a given start state. */
227 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
228 /* Special action meaning "start processing a new file". */
229 #define YY_NEW_FILE yyrestart( yyin )
230 #define YY_END_OF_BUFFER_CHAR 0
231
232 /* Size of default input buffer. */
233 #ifndef YY_BUF_SIZE
234 #ifdef __ia64__
235 /* On IA-64, the buffer size is 16k, not 8k.
236 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
237 * Ditto for the __ia64__ case accordingly.
238 */
239 #define YY_BUF_SIZE 32768
240 #else
241 #define YY_BUF_SIZE 16384
242 #endif /* __ia64__ */
243 #endif
244
245 /* The state buf must be large enough to hold one state per character in the main buffer.
246 */
247 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
248
249 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
250 #define YY_TYPEDEF_YY_BUFFER_STATE
251 typedef struct yy_buffer_state *YY_BUFFER_STATE;
252 #endif
253
254 #ifndef YY_TYPEDEF_YY_SIZE_T
255 #define YY_TYPEDEF_YY_SIZE_T
256 typedef size_t yy_size_t;
257 #endif
258
259 /* %if-not-reentrant */
260 extern int yyleng;
261 /* %endif */
262
263 /* %if-c-only */
264 /* %if-not-reentrant */
265 extern FILE *yyin, *yyout;
266 /* %endif */
267 /* %endif */
268
269 #define EOB_ACT_CONTINUE_SCAN 0
270 #define EOB_ACT_END_OF_FILE 1
271 #define EOB_ACT_LAST_MATCH 2
272
273 #define YY_LESS_LINENO(n)
274 #define YY_LINENO_REWIND_TO(ptr)
275
276 /* Return all but the first "n" matched characters back to the input stream. */
277 #define yyless(n) \
278 do \
279 { \
280 /* Undo effects of setting up yytext. */ \
281 int yyless_macro_arg = (n); \
282 YY_LESS_LINENO(yyless_macro_arg);\
283 *yy_cp = (yy_hold_char); \
284 YY_RESTORE_YY_MORE_OFFSET \
285 (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
286 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
287 } \
288 while ( 0 )
289 #define unput(c) yyunput( c, (yytext_ptr) )
290
291 #ifndef YY_STRUCT_YY_BUFFER_STATE
292 #define YY_STRUCT_YY_BUFFER_STATE
293 struct yy_buffer_state
294 {
295 /* %if-c-only */
296 FILE *yy_input_file;
297 /* %endif */
298
299 /* %if-c++-only */
300 /* %endif */
301
302 char *yy_ch_buf; /* input buffer */
303 char *yy_buf_pos; /* current position in input buffer */
304
305 /* Size of input buffer in bytes, not including room for EOB
306 * characters.
307 */
308 int yy_buf_size;
309
310 /* Number of characters read into yy_ch_buf, not including EOB
311 * characters.
312 */
313 int yy_n_chars;
314
315 /* Whether we "own" the buffer - i.e., we know we created it,
316 * and can realloc() it to grow it, and should free() it to
317 * delete it.
318 */
319 int yy_is_our_buffer;
320
321 /* Whether this is an "interactive" input source; if so, and
322 * if we're using stdio for input, then we want to use getc()
323 * instead of fread(), to make sure we stop fetching input after
324 * each newline.
325 */
326 int yy_is_interactive;
327
328 /* Whether we're considered to be at the beginning of a line.
329 * If so, '^' rules will be active on the next match, otherwise
330 * not.
331 */
332 int yy_at_bol;
333
334 int yy_bs_lineno; /**< The line count. */
335 int yy_bs_column; /**< The column count. */
336
337 /* Whether to try to fill the input buffer when we reach the
338 * end of it.
339 */
340 int yy_fill_buffer;
341
342 int yy_buffer_status;
343
344 #define YY_BUFFER_NEW 0
345 #define YY_BUFFER_NORMAL 1
346 /* When an EOF's been seen but there's still some text to process
347 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
348 * shouldn't try reading from the input source any more. We might
349 * still have a bunch of tokens to match, though, because of
350 * possible backing-up.
351 *
352 * When we actually see the EOF, we change the status to "new"
353 * (via yyrestart()), so that the user can continue scanning by
354 * just pointing yyin at a new input file.
355 */
356 #define YY_BUFFER_EOF_PENDING 2
357
358 };
359 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
360
361 /* %if-c-only Standard (non-C++) definition */
362 /* %not-for-header */
363 /* %if-not-reentrant */
364
365 /* Stack of input buffers. */
366 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
367 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
368 static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
369 /* %endif */
370 /* %ok-for-header */
371
372 /* %endif */
373
374 /* We provide macros for accessing buffer states in case in the
375 * future we want to put the buffer states in a more general
376 * "scanner state".
377 *
378 * Returns the top of the stack, or NULL.
379 */
380 #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
381 ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
382 : NULL)
383 /* Same as previous macro, but useful when we know that the buffer stack is not
384 * NULL or when we need an lvalue. For internal use only.
385 */
386 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
387
388 /* %if-c-only Standard (non-C++) definition */
389
390 /* %if-not-reentrant */
391 /* %not-for-header */
392 /* yy_hold_char holds the character lost when yytext is formed. */
393 static char yy_hold_char;
394 static int yy_n_chars; /* number of characters read into yy_ch_buf */
395 int yyleng;
396
397 /* Points to current character in buffer. */
398 static char *yy_c_buf_p = NULL;
399 static int yy_init = 0; /* whether we need to initialize */
400 static int yy_start = 0; /* start state number */
401
402 /* Flag which is used to allow yywrap()'s to do buffer switches
403 * instead of setting up a fresh yyin. A bit of a hack ...
404 */
405 static int yy_did_buffer_switch_on_eof;
406 /* %ok-for-header */
407
408 /* %endif */
409
410 void yyrestart ( FILE *input_file );
411 void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
412 YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
413 void yy_delete_buffer ( YY_BUFFER_STATE b );
414 void yy_flush_buffer ( YY_BUFFER_STATE b );
415 void yypush_buffer_state ( YY_BUFFER_STATE new_buffer );
416 void yypop_buffer_state ( void );
417
418 static void yyensure_buffer_stack ( void );
419 static void yy_load_buffer_state ( void );
420 static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file );
421 #define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER )
422
423 YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size );
424 YY_BUFFER_STATE yy_scan_string ( const char *yy_str );
425 YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len );
426
427 /* %endif */
428
429 void *yyalloc ( yy_size_t );
430 void *yyrealloc ( void *, yy_size_t );
431 void yyfree ( void * );
432
433 #define yy_new_buffer yy_create_buffer
434 #define yy_set_interactive(is_interactive) \
435 { \
436 if ( ! YY_CURRENT_BUFFER ){ \
437 yyensure_buffer_stack (); \
438 YY_CURRENT_BUFFER_LVALUE = \
439 yy_create_buffer( yyin, YY_BUF_SIZE ); \
440 } \
441 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
442 }
443 #define yy_set_bol(at_bol) \
444 { \
445 if ( ! YY_CURRENT_BUFFER ){\
446 yyensure_buffer_stack (); \
447 YY_CURRENT_BUFFER_LVALUE = \
448 yy_create_buffer( yyin, YY_BUF_SIZE ); \
449 } \
450 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
451 }
452 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
453
454 /* %% [1.0] yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here */
455 /* Begin user sect3 */
456
457 #define FLEX_DEBUG
458 typedef flex_uint8_t YY_CHAR;
459
460 FILE *yyin = NULL, *yyout = NULL;
461
462 typedef int yy_state_type;
463
464 extern int yylineno;
465 int yylineno = 1;
466
467 extern char *yytext;
468 #ifdef yytext_ptr
469 #undef yytext_ptr
470 #endif
471 #define yytext_ptr yytext
472
473 /* %% [1.5] DFA */
474
475 /* %if-c-only Standard (non-C++) definition */
476
477 static yy_state_type yy_get_previous_state ( void );
478 static yy_state_type yy_try_NUL_trans ( yy_state_type current_state );
479 static int yy_get_next_buffer ( void );
480 static void yynoreturn yy_fatal_error ( const char* msg );
481
482 /* %endif */
483
484 /* Done after the current pattern has been matched and before the
485 * corresponding action - sets up yytext.
486 */
487 #define YY_DO_BEFORE_ACTION \
488 (yytext_ptr) = yy_bp; \
489 /* %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ */\
490 yyleng = (int) (yy_cp - yy_bp); \
491 (yy_hold_char) = *yy_cp; \
492 *yy_cp = '\0'; \
493 /* %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ */\
494 (yy_c_buf_p) = yy_cp;
495 /* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
496 #define YY_NUM_RULES 24
497 #define YY_END_OF_BUFFER 25
498 /* This struct is not used in this scanner,
499 but its presence is necessary. */
500 struct yy_trans_info
501 {
502 flex_int32_t yy_verify;
503 flex_int32_t yy_nxt;
504 };
505 static const flex_int16_t yy_accept[65] =
506 { 0,
507 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
508 25, 13, 12, 11, 23, 23, 22, 22, 20, 12,
509 17, 19, 18, 16, 12, 15, 14, 14, 13, 12,
510 10, 2, 10, 10, 10, 10, 10, 10, 0, 21,
511 20, 12, 16, 12, 14, 1, 0, 8, 0, 0,
512 0, 0, 3, 0, 0, 0, 0, 6, 5, 0,
513 4, 7, 9, 0
514 } ;
515
516 static const YY_CHAR yy_ec[256] =
517 { 0,
518 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
519 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
520 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
521 1, 2, 5, 6, 1, 1, 1, 1, 7, 1,
522 1, 8, 1, 1, 9, 10, 11, 12, 12, 12,
523 12, 12, 12, 12, 12, 12, 12, 1, 1, 13,
524 1, 14, 15, 1, 16, 16, 16, 16, 16, 16,
525 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
526 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
527 1, 17, 1, 1, 10, 18, 19, 20, 19, 19,
528
529 19, 19, 16, 16, 16, 16, 16, 16, 16, 16,
530 16, 16, 16, 21, 16, 16, 16, 16, 16, 16,
531 16, 16, 1, 1, 1, 1, 1, 1, 1, 1,
532 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
533 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
534 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
535 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
536 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
537 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
538 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
539
540 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
541 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
542 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
543 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
544 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
545 1, 1, 1, 1, 1
546 } ;
547
548 static const YY_CHAR yy_meta[22] =
549 { 0,
550 1, 2, 3, 4, 1, 5, 1, 5, 2, 2,
551 6, 7, 4, 2, 1, 8, 4, 5, 8, 8,
552 8
553 } ;
554
555 static const flex_int16_t yy_base[79] =
556 { 0,
557 0, 15, 39, 37, 30, 46, 62, 78, 94, 109,
558 46, 0, 42, 317, 126, 143, 30, 317, 0, 39,
559 317, 317, 317, 0, 38, 317, 0, 0, 0, 37,
560 317, 317, 30, 0, 26, 163, 14, 2, 17, 317,
561 0, 27, 0, 26, 0, 317, 184, 317, 16, 12,
562 6, 0, 317, 14, 4, 197, 0, 0, 317, 1,
563 317, 317, 317, 317, 218, 226, 234, 242, 250, 258,
564 266, 274, 282, 290, 1, 293, 301, 308
565 } ;
566
567 static const flex_int16_t yy_def[79] =
568 { 0,
569 65, 65, 66, 66, 67, 67, 68, 68, 69, 69,
570 64, 70, 64, 64, 64, 15, 71, 64, 72, 72,
571 64, 64, 64, 73, 73, 64, 74, 74, 70, 64,
572 64, 64, 64, 75, 76, 64, 36, 64, 71, 64,
573 72, 72, 73, 73, 74, 64, 64, 64, 76, 77,
574 78, 36, 64, 36, 64, 47, 47, 56, 64, 77,
575 64, 64, 64, 0, 64, 64, 64, 64, 64, 64,
576 64, 64, 64, 64, 64, 64, 64, 64
577 } ;
578
579 static const flex_int16_t yy_nxt[339] =
580 { 0,
581 64, 64, 13, 14, 64, 64, 64, 50, 47, 64,
582 64, 64, 15, 55, 61, 63, 16, 13, 14, 53,
583 55, 55, 63, 63, 62, 61, 48, 15, 44, 42,
584 40, 16, 20, 14, 54, 21, 48, 22, 46, 30,
585 44, 42, 15, 40, 30, 64, 16, 23, 20, 14,
586 18, 21, 18, 22, 64, 64, 64, 64, 15, 64,
587 64, 64, 16, 23, 25, 14, 64, 26, 64, 26,
588 64, 64, 64, 64, 15, 64, 64, 64, 16, 26,
589 25, 14, 64, 26, 64, 26, 64, 64, 64, 64,
590 15, 64, 64, 64, 16, 26, 28, 14, 64, 64,
591
592 64, 64, 64, 64, 64, 64, 15, 64, 64, 64,
593 16, 28, 14, 64, 64, 64, 64, 64, 64, 64,
594 64, 15, 64, 64, 64, 16, 31, 31, 31, 31,
595 32, 31, 31, 31, 33, 31, 34, 31, 31, 31,
596 35, 36, 31, 31, 36, 37, 36, 31, 64, 38,
597 64, 31, 64, 31, 64, 64, 64, 31, 31, 64,
598 64, 31, 31, 31, 50, 64, 64, 64, 64, 64,
599 64, 51, 51, 48, 52, 64, 53, 64, 52, 64,
600 64, 52, 52, 52, 56, 56, 56, 56, 56, 56,
601 56, 56, 57, 57, 58, 57, 56, 59, 56, 57,
602
603 56, 56, 57, 57, 57, 56, 56, 64, 56, 64,
604 64, 64, 56, 64, 64, 56, 56, 56, 12, 12,
605 12, 12, 12, 12, 12, 12, 17, 17, 17, 17,
606 17, 17, 17, 17, 19, 19, 19, 19, 19, 19,
607 19, 19, 24, 24, 24, 24, 24, 24, 24, 24,
608 27, 27, 27, 27, 27, 27, 27, 27, 29, 29,
609 64, 64, 29, 29, 29, 29, 39, 39, 39, 39,
610 39, 39, 39, 39, 41, 41, 41, 64, 64, 41,
611 41, 41, 43, 43, 43, 64, 64, 43, 43, 43,
612 45, 45, 45, 64, 45, 45, 45, 45, 49, 49,
613
614 49, 60, 60, 60, 60, 60, 60, 60, 60, 51,
615 64, 64, 64, 64, 51, 51, 11, 64, 64, 64,
616 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
617 64, 64, 64, 64, 64, 64, 64, 64
618 } ;
619
620 static const flex_int16_t yy_chk[339] =
621 { 0,
622 0, 0, 1, 1, 0, 0, 0, 51, 75, 0,
623 0, 0, 1, 38, 60, 55, 1, 2, 2, 51,
624 38, 38, 55, 55, 54, 50, 49, 2, 44, 42,
625 39, 2, 5, 5, 37, 5, 35, 5, 33, 30,
626 25, 20, 5, 17, 13, 11, 5, 5, 6, 6,
627 4, 6, 3, 6, 0, 0, 0, 0, 6, 0,
628 0, 0, 6, 6, 7, 7, 0, 7, 0, 7,
629 0, 0, 0, 0, 7, 0, 0, 0, 7, 7,
630 8, 8, 0, 8, 0, 8, 0, 0, 0, 0,
631 8, 0, 0, 0, 8, 8, 9, 9, 0, 0,
632
633 0, 0, 0, 0, 0, 0, 9, 0, 0, 0,
634 9, 10, 10, 0, 0, 0, 0, 0, 0, 0,
635 0, 10, 0, 0, 0, 10, 15, 15, 15, 15,
636 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
637 15, 15, 15, 15, 15, 15, 15, 16, 0, 16,
638 0, 16, 0, 16, 0, 0, 0, 16, 16, 0,
639 0, 16, 16, 16, 36, 0, 0, 0, 0, 0,
640 0, 36, 36, 36, 36, 0, 36, 0, 36, 0,
641 0, 36, 36, 36, 47, 47, 47, 47, 47, 47,
642 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
643
644 47, 47, 47, 47, 47, 56, 56, 0, 56, 0,
645 56, 0, 56, 0, 0, 56, 56, 56, 65, 65,
646 65, 65, 65, 65, 65, 65, 66, 66, 66, 66,
647 66, 66, 66, 66, 67, 67, 67, 67, 67, 67,
648 67, 67, 68, 68, 68, 68, 68, 68, 68, 68,
649 69, 69, 69, 69, 69, 69, 69, 69, 70, 70,
650 0, 0, 70, 70, 70, 70, 71, 71, 71, 71,
651 71, 71, 71, 71, 72, 72, 72, 0, 0, 72,
652 72, 72, 73, 73, 73, 0, 0, 73, 73, 73,
653 74, 74, 74, 0, 74, 74, 74, 74, 76, 76,
654
655 76, 77, 77, 77, 77, 77, 77, 77, 77, 78,
656 0, 0, 0, 0, 78, 78, 64, 64, 64, 64,
657 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
658 64, 64, 64, 64, 64, 64, 64, 64
659 } ;
660
661 static yy_state_type yy_last_accepting_state;
662 static char *yy_last_accepting_cpos;
663
664 extern int yy_flex_debug;
665 int yy_flex_debug = 1;
666
667 static const flex_int16_t yy_rule_linenum[24] =
668 { 0,
669 322, 323, 324, 328, 332, 336, 340, 344, 352, 364,
670 369, 372, 378, 381, 384, 385, 388, 389, 390, 391,
671 394, 399, 402
672 } ;
673
674 /* The intent behind this definition is that it'll catch
675 * any uses of REJECT which flex missed.
676 */
677 #define REJECT reject_used_but_not_detected
678 #define yymore() yymore_used_but_not_detected
679 #define YY_MORE_ADJ 0
680 #define YY_RESTORE_YY_MORE_OFFSET
681 char *yytext;
682 #line 1 "markup.l"
683
684 #line 68 "markup.l"
685
686 static struct gcide_locus *base_locus;
687 static char const *input_buf;
688 static size_t input_len;
689 static unsigned token_beg;
690 static unsigned token_end;
691
692 /*
693 * Dictionary entries in GCIDE corpus files begin with "<p><ent>", but index
694 * entries in the GCIDE.IDX file point to the first "<hw>" tag that follows.
695 * Thus, the very first "</p>" encountered when parsing an entry has no
696 * corresponding "<p>" tag. The first_p_seen variable is set by push_tag
697 * when it sees the first opening "<p>" tag and is used in pop_tag to generate
698 * the first "p" block tag and avoid issuing a spurious error message when
699 * the first "</p>" is encountered.
700 */
701 static int first_p_seen;
702
703 #define LOCUS_FILE (base_locus ? base_locus->file : "")
704 #define LOCUS_OFF(off) ((base_locus ? base_locus->offset : 0) + off)
705
706 static char *textspace; /* Text storage space */
707 static size_t textsize; /* Size of text space */
708 static size_t textpos; /* Current position in the text space */
709 static size_t textstart; /* Start of the current text segment */
710 static size_t textstart_offset;
711
712 static dico_list_t tagstk;
713 static struct gcide_tag *current_tag;
714
715 static jmp_buf errbuf;
716
717 static void
718 memerr(const char *text)
719 {
720 dico_log(L_ERR, ENOMEM, "%s", text);
721 longjmp(errbuf, 1);
722 }
723
724 #define YY_USER_ACTION do { \
725 token_beg = token_end; \
726 token_end += yyleng; \
727 } while (0);
728 #define YY_INPUT(buf,result,max_size) do { \
729 size_t __n = (max_size) > input_len ? input_len : (max_size); \
730 if (__n) \
731 memcpy((buf), input_buf, __n); \
732 input_buf += __n; \
733 input_len -= __n; \
734 (result) = __n; \
735 } while(0)
736
737 static int retstate;
738 static char *endtag;
739 static size_t endtaglen;
740 #define BEGIN_COMMENT(end) \
741 { retstate = YYSTATE; endtag = (end); endtaglen = strlen(endtag); BEGIN(COMMENT); }
742
743 static void
744 text_assert_size(size_t len)
745 {
746 while (textsize - textpos < len) {
747 size_t nsize;
748 char *newp;
749
750 if (SIZE_MAX / 2 < textsize)
751 memerr("text_add_str");
752 nsize = 2 * textsize;
753 newp = realloc(textspace, nsize);
754 if (!newp)
755 memerr("text_add_str");
756 textspace = newp;
757 textsize = nsize;
758 }
759 }
760
761 static void
762 text_add_str(char const *s, size_t l)
763 {
764 if (textstart == textpos) textstart_offset = token_beg;
765 text_assert_size(l);
766 memcpy(textspace + textpos, s, l);
767 textpos += l;
768 }
769
770 static void
771 text_add_strz(char const *s)
772 {
773 text_add_str(s, strlen(s));
774 }
775
776 static void
777 text_add_chr(int ch)
778 {
779 char c = ch;
780 text_add_str(&c, 1);
781 }
782
783 #define text_segment_length() (textpos - textstart)
784
785 static size_t
786 text_segment_finish()
787 {
788 size_t ret = textstart;
789 text_add_chr(0);
790 textstart = textpos;
791 return ret;
792 }
793
794 static int free_tag(void *item, void *data);
795
796 static struct gcide_tag *
797 alloc_tag(enum gcide_content_type type)
798 {
799 dico_list_t list;
800 struct gcide_tag *tag = calloc(1, sizeof(*tag));
801 if (!tag)
802 memerr("alloc_tag");
803 tag->tag_type = type;
804 switch (type) {
805 case gcide_content_top:
806 case gcide_content_tag:
807 list = dico_list_create();
808 if (!list) {
809 free(tag);
810 memerr("alloc_tag");
811 }
812 dico_list_set_free_item(list, free_tag, NULL);
813 tag->v.tag.taglist = list;
814 break;
815 default:
816 break;
817 }
818 return tag;
819 }
820
821 struct gcide_tag *
822 gcide_tag_alloc(const char *text, size_t len)
823 {
824 struct gcide_tag *tag;
825 struct wordsplit ws;
826 size_t i;
827
828 if (wordsplit_len(text, len, &ws, WRDSF_DEFFLAGS & ~WRDSF_CESCAPES)) {
829 dico_log(L_ERR, 0, _("cannot parse line %.*s: %s"),
830 (int)len, text, wordsplit_strerror(&ws));
831 longjmp(errbuf, 1);
832 }
833
834 for (i = 0; i < ws.ws_wordc; i++) {
835 char *p;
836 for (p = ws.ws_wordv[i]; *p; p++) {
837 if (*p == '=')
838 break;
839 *p = tolower(*p);
840 }
841 }
842 tag = alloc_tag(gcide_content_tag);
843 tag->v.tag.tag_parmc = ws.ws_wordc;
844 tag->v.tag.tag_parmv = ws.ws_wordv;
845 tag->offset = token_beg;
846 ws.ws_wordc = 0;
847 ws.ws_wordv = NULL;
848 wordsplit_free(&ws);
849 return tag;
850 }
851
852 #define alloc_taglist gcide_tag_alloc
853
854 void
855 gcide_tag_free(struct gcide_tag *tag)
856 {
857 if (tag) {
858 switch (tag->tag_type) {
859 default:
860 break;
861 case gcide_content_top:
862 case gcide_content_tag:
863 dico_list_destroy(&tag->v.tag.taglist);
864 }
865 free(tag);
866 }
867 }
868
869 int
870 gcide_is_tag(struct gcide_tag *tag, char const *name)
871 {
872 return tag != NULL && tag->tag_type == gcide_content_tag &&
873 strcmp(tag->tag_name, name) == 0;
874 }
875
876 static int
877 free_tag(void *item, void *data)
878 {
879 gcide_tag_free(item);
880 return 0;
881 }
882
883 static void
884 append_tag(struct gcide_tag *tag)
885 {
886 dico_list_t list;
887
888 switch (current_tag->tag_type) {
889 case gcide_content_text: {
890 struct gcide_tag *subtag = alloc_tag(gcide_content_text);
891 subtag->offset = current_tag->offset;
892 subtag->v.textpos = current_tag->v.textpos;
893 list = dico_list_create();
894 if (!list) {
895 free(subtag);
896 free(tag);
897 memerr("append_tag");
898 }
899 dico_list_set_free_item(list, free_tag, NULL);
900 dico_list_append(list, subtag);
901 current_tag->tag_type = gcide_content_tag;
902 current_tag->v.tag.taglist = list;
903 break;
904 }
905
906 default:
907 break;
908 }
909
910 dico_list_append(current_tag->v.tag.taglist, tag);
911 }
912
913 static void push_tag(struct gcide_tag *tag);
914 static void pop_tag(const char *tagstr, size_t taglen);
915
916 static void
917 flush_text_segment(void)
918 {
919 if (text_segment_length()) {
920 struct gcide_tag *tag = alloc_tag(gcide_content_text);
921 tag->v.textpos = text_segment_finish();
922 tag->offset = textstart_offset;
923 append_tag(tag);
924 }
925 }
926 #line 926 "markup.c"
927 #define YY_NO_INPUT 1
928
929 #line 929 "markup.c"
930
931 #define INITIAL 0
932 #define COMMENT 1
933 #define PR 2
934 #define HW 3
935 #define PRE 4
936
937 #ifndef YY_NO_UNISTD_H
938 /* Special case for "unistd.h", since it is non-ANSI. We include it way
939 * down here because we want the user's section 1 to have been scanned first.
940 * The user has a chance to override it with an option.
941 */
942 /* %if-c-only */
943 #include <unistd.h>
944 /* %endif */
945 /* %if-c++-only */
946 /* %endif */
947 #endif
948
949 #ifndef YY_EXTRA_TYPE
950 #define YY_EXTRA_TYPE void *
951 #endif
952
953 /* %if-c-only Reentrant structure and macros (non-C++). */
954 /* %if-reentrant */
955 /* %if-c-only */
956
957 static int yy_init_globals ( void );
958
959 /* %endif */
960 /* %if-reentrant */
961 /* %endif */
962 /* %endif End reentrant structures and macros. */
963
964 /* Accessor methods to globals.
965 These are made visible to non-reentrant scanners for convenience. */
966
967 int yylex_destroy ( void );
968
969 int yyget_debug ( void );
970
971 void yyset_debug ( int debug_flag );
972
973 YY_EXTRA_TYPE yyget_extra ( void );
974
975 void yyset_extra ( YY_EXTRA_TYPE user_defined );
976
977 FILE *yyget_in ( void );
978
979 void yyset_in ( FILE * _in_str );
980
981 FILE *yyget_out ( void );
982
983 void yyset_out ( FILE * _out_str );
984
985 int yyget_leng ( void );
986
987 char *yyget_text ( void );
988
989 int yyget_lineno ( void );
990
991 void yyset_lineno ( int _line_number );
992
993 /* %if-bison-bridge */
994 /* %endif */
995
996 /* Macros after this point can all be overridden by user definitions in
997 * section 1.
998 */
999
1000 #ifndef YY_SKIP_YYWRAP
1001 #ifdef __cplusplus
1002 extern "C" int yywrap ( void );
1003 #else
1004 extern int yywrap ( void );
1005 #endif
1006 #endif
1007
1008 /* %not-for-header */
1009 #ifndef YY_NO_UNPUT
1010
1011 #endif
1012 /* %ok-for-header */
1013
1014 /* %endif */
1015
1016 #ifndef yytext_ptr
1017 static void yy_flex_strncpy ( char *, const char *, int );
1018 #endif
1019
1020 #ifdef YY_NEED_STRLEN
1021 static int yy_flex_strlen ( const char * );
1022 #endif
1023
1024 #ifndef YY_NO_INPUT
1025 /* %if-c-only Standard (non-C++) definition */
1026 /* %not-for-header */
1027 #ifdef __cplusplus
1028 static int yyinput ( void );
1029 #else
1030 static int input ( void );
1031 #endif
1032 /* %ok-for-header */
1033
1034 /* %endif */
1035 #endif
1036
1037 /* %if-c-only */
1038
1039 /* %endif */
1040
1041 /* Amount of stuff to slurp up with each read. */
1042 #ifndef YY_READ_BUF_SIZE
1043 #ifdef __ia64__
1044 /* On IA-64, the buffer size is 16k, not 8k */
1045 #define YY_READ_BUF_SIZE 16384
1046 #else
1047 #define YY_READ_BUF_SIZE 8192
1048 #endif /* __ia64__ */
1049 #endif
1050
1051 /* Copy whatever the last rule matched to the standard output. */
1052 #ifndef ECHO
1053 /* %if-c-only Standard (non-C++) definition */
1054 /* This used to be an fputs(), but since the string might contain NUL's,
1055 * we now use fwrite().
1056 */
1057 #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
1058 /* %endif */
1059 /* %if-c++-only C++ definition */
1060 /* %endif */
1061 #endif
1062
1063 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
1064 * is returned in "result".
1065 */
1066 #ifndef YY_INPUT
1067 #define YY_INPUT(buf,result,max_size) \
1068 /* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
1069 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
1070 { \
1071 int c = '*'; \
1072 int n; \
1073 for ( n = 0; n < max_size && \
1074 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
1075 buf[n] = (char) c; \
1076 if ( c == '\n' ) \
1077 buf[n++] = (char) c; \
1078 if ( c == EOF && ferror( yyin ) ) \
1079 YY_FATAL_ERROR( "input in flex scanner failed" ); \
1080 result = n; \
1081 } \
1082 else \
1083 { \
1084 errno=0; \
1085 while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
1086 { \
1087 if( errno != EINTR) \
1088 { \
1089 YY_FATAL_ERROR( "input in flex scanner failed" ); \
1090 break; \
1091 } \
1092 errno=0; \
1093 clearerr(yyin); \
1094 } \
1095 }\
1096 \
1097 /* %if-c++-only C++ definition \ */\
1098 /* %endif */
1099
1100 #endif
1101
1102 /* No semi-colon after return; correct usage is to write "yyterminate();" -
1103 * we don't want an extra ';' after the "return" because that will cause
1104 * some compilers to complain about unreachable statements.
1105 */
1106 #ifndef yyterminate
1107 #define yyterminate() return YY_NULL
1108 #endif
1109
1110 /* Number of entries by which start-condition stack grows. */
1111 #ifndef YY_START_STACK_INCR
1112 #define YY_START_STACK_INCR 25
1113 #endif
1114
1115 /* Report a fatal error. */
1116 #ifndef YY_FATAL_ERROR
1117 /* %if-c-only */
1118 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
1119 /* %endif */
1120 /* %if-c++-only */
1121 /* %endif */
1122 #endif
1123
1124 /* %if-tables-serialization structures and prototypes */
1125 /* %not-for-header */
1126 /* %ok-for-header */
1127
1128 /* %not-for-header */
1129 /* %tables-yydmap generated elements */
1130 /* %endif */
1131 /* end tables serialization structures and prototypes */
1132
1133 /* %ok-for-header */
1134
1135 /* Default declaration of generated scanner - a define so the user can
1136 * easily add parameters.
1137 */
1138 #ifndef YY_DECL
1139 #define YY_DECL_IS_OURS 1
1140 /* %if-c-only Standard (non-C++) definition */
1141
1142 extern int yylex (void);
1143
1144 #define YY_DECL int yylex (void)
1145 /* %endif */
1146 /* %if-c++-only C++ definition */
1147 /* %endif */
1148 #endif /* !YY_DECL */
1149
1150 /* Code executed at the beginning of each rule, after yytext and yyleng
1151 * have been set up.
1152 */
1153 #ifndef YY_USER_ACTION
1154 #define YY_USER_ACTION
1155 #endif
1156
1157 /* Code executed at the end of each rule. */
1158 #ifndef YY_BREAK
1159 #define YY_BREAK /*LINTED*/break;
1160 #endif
1161
1162 /* %% [6.0] YY_RULE_SETUP definition goes here */
1163 #define YY_RULE_SETUP \
1164 YY_USER_ACTION
1165
1166 /* %not-for-header */
1167 /** The main scanner function which does all the work.
1168 */
1169 YY_DECL
1170 {
1171 yy_state_type yy_current_state;
1172 char *yy_cp, *yy_bp;
1173 int yy_act;
1174
1175 if ( !(yy_init) )
1176 {
1177 (yy_init) = 1;
1178
1179 #ifdef YY_USER_INIT
1180 YY_USER_INIT;
1181 #endif
1182
1183 if ( ! (yy_start) )
1184 (yy_start) = 1; /* first start state */
1185
1186 if ( ! yyin )
1187 /* %if-c-only */
1188 yyin = stdin;
1189 /* %endif */
1190 /* %if-c++-only */
1191 /* %endif */
1192
1193 if ( ! yyout )
1194 /* %if-c-only */
1195 yyout = stdout;
1196 /* %endif */
1197 /* %if-c++-only */
1198 /* %endif */
1199
1200 if ( ! YY_CURRENT_BUFFER ) {
1201 yyensure_buffer_stack ();
1202 YY_CURRENT_BUFFER_LVALUE =
1203 yy_create_buffer( yyin, YY_BUF_SIZE );
1204 }
1205
1206 yy_load_buffer_state( );
1207 }
1208
1209 {
1210 /* %% [7.0] user's declarations go here */
1211 #line 320 "markup.l"
1212
1213 #line 1213 "markup.c"
1214
1215 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
1216 {
1217 /* %% [8.0] yymore()-related code goes here */
1218 yy_cp = (yy_c_buf_p);
1219
1220 /* Support of yytext. */
1221 *yy_cp = (yy_hold_char);
1222
1223 /* yy_bp points to the position in yy_ch_buf of the start of
1224 * the current run.
1225 */
1226 yy_bp = yy_cp;
1227
1228 /* %% [9.0] code to set up and find next match goes here */
1229 yy_current_state = (yy_start);
1230 yy_match:
1231 do
1232 {
1233 YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
1234 if ( yy_accept[yy_current_state] )
1235 {
1236 (yy_last_accepting_state) = yy_current_state;
1237 (yy_last_accepting_cpos) = yy_cp;
1238 }
1239 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1240 {
1241 yy_current_state = (int) yy_def[yy_current_state];
1242 if ( yy_current_state >= 65 )
1243 yy_c = yy_meta[yy_c];
1244 }
1245 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1246 ++yy_cp;
1247 }
1248 while ( yy_base[yy_current_state] != 317 );
1249
1250 yy_find_action:
1251 /* %% [10.0] code to find the action number goes here */
1252 yy_act = yy_accept[yy_current_state];
1253 if ( yy_act == 0 )
1254 { /* have to back up */
1255 yy_cp = (yy_last_accepting_cpos);
1256 yy_current_state = (yy_last_accepting_state);
1257 yy_act = yy_accept[yy_current_state];
1258 }
1259
1260 YY_DO_BEFORE_ACTION;
1261
1262 /* %% [11.0] code for yylineno update goes here */
1263
1264 do_action: /* This label is used only to access EOF actions. */
1265
1266 /* %% [12.0] debug code goes here */
1267 if ( yy_flex_debug )
1268 {
1269 if ( yy_act == 0 )
1270 fprintf( stderr, "--scanner backing up\n" );
1271 else if ( yy_act < 24 )
1272 fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
1273 (long)yy_rule_linenum[yy_act], yytext );
1274 else if ( yy_act == 24 )
1275 fprintf( stderr, "--accepting default rule (\"%s\")\n",
1276 yytext );
1277 else if ( yy_act == 25 )
1278 fprintf( stderr, "--(end of buffer or a NUL)\n" );
1279 else
1280 fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
1281 }
1282
1283 switch ( yy_act )
1284 { /* beginning of action switch */
1285 /* %% [13.0] actions go here */
1286 case 0: /* must back up */
1287 /* undo the effects of YY_DO_BEFORE_ACTION */
1288 *yy_cp = (yy_hold_char);
1289 yy_cp = (yy_last_accepting_cpos);
1290 yy_current_state = (yy_last_accepting_state);
1291 goto yy_find_action;
1292
1293 case 1:
1294 YY_RULE_SETUP
1295 #line 322 "markup.l"
1296 BEGIN_COMMENT("-->");
1297 YY_BREAK
1298 case 2:
1299 YY_RULE_SETUP
1300 #line 323 "markup.l"
1301 BEGIN_COMMENT("!>");
1302 YY_BREAK
1303 case 3:
1304 YY_RULE_SETUP
1305 #line 324 "markup.l"
1306 {
1307 flush_text_segment();
1308 push_tag(alloc_taglist(yytext + 1, yyleng - 2));
1309 }
1310 YY_BREAK
1311 case 4:
1312 /* rule 4 can match eol */
1313 YY_RULE_SETUP
1314 #line 328 "markup.l"
1315 {
1316 flush_text_segment();
1317 push_tag(alloc_taglist(yytext + 1, yyleng - 2));
1318 }
1319 YY_BREAK
1320 case 5:
1321 YY_RULE_SETUP
1322 #line 332 "markup.l"
1323 {
1324 flush_text_segment();
1325 pop_tag(yytext + 2, yyleng - 3);
1326 }
1327 YY_BREAK
1328 case 6:
1329 /* rule 6 can match eol */
1330 YY_RULE_SETUP
1331 #line 336 "markup.l"
1332 {
1333 dico_log(L_WARN, 0, _("%s:%zu: malformed entity or tag: %s"),
1334 LOCUS_FILE, LOCUS_OFF(token_beg), yytext);
1335 }
1336 YY_BREAK
1337 case 7:
1338 YY_RULE_SETUP
1339 #line 340 "markup.l"
1340 {
1341 flush_text_segment();
1342 append_tag(alloc_tag(gcide_content_br));
1343 }
1344 YY_BREAK
1345 case 8:
1346 YY_RULE_SETUP
1347 #line 344 "markup.l"
1348 {
1349 char const *s = gcide_entity_to_utf8(yytext);
1350 if (s)
1351 text_add_str(s, strlen(s));
1352 else
1353 dico_log(L_WARN, 0, _("%s:%zu: unrecognized entity: %s"),
1354 LOCUS_FILE, LOCUS_OFF(token_beg), yytext);
1355 }
1356 YY_BREAK
1357 case 9:
1358 YY_RULE_SETUP
1359 #line 352 "markup.l"
1360 {
1361 char const *s = gcide_escape_to_utf8(yytext+2);
1362
1363 if (s)
1364 text_add_str(s, strlen(s));
1365 else {
1366 text_add_str(yytext, yyleng);
1367 dico_log(L_WARN, 0,
1368 _("%s:%zu: unknown character sequence %s"),
1369 LOCUS_FILE, LOCUS_OFF(token_beg), yytext);
1370 }
1371 }
1372 YY_BREAK
1373 case 10:
1374 /* rule 10 can match eol */
1375 YY_RULE_SETUP
1376 #line 364 "markup.l"
1377 {
1378 text_add_chr(yytext[0]);
1379 yyless(1);
1380 token_end--;
1381 }
1382 YY_BREAK
1383 case 11:
1384 YY_RULE_SETUP
1385 #line 369 "markup.l"
1386 ;
1387 YY_BREAK
1388
1389
1390 case 12:
1391 /* rule 12 can match eol */
1392 YY_RULE_SETUP
1393 #line 372 "markup.l"
1394 {
1395 flush_text_segment();
1396 append_tag(alloc_tag(gcide_content_nl));
1397 }
1398 YY_BREAK
1399
1400
1401 case 13:
1402 YY_RULE_SETUP
1403 #line 378 "markup.l"
1404 text_add_str(yytext, yyleng);
1405 YY_BREAK
1406
1407
1408 case 14:
1409 /* rule 14 can match eol */
1410 YY_RULE_SETUP
1411 #line 381 "markup.l"
1412 text_add_str(yytext, yyleng);
1413 YY_BREAK
1414
1415
1416 case 15:
1417 YY_RULE_SETUP
1418 #line 384 "markup.l"
1419 ;
1420 YY_BREAK
1421 case 16:
1422 /* rule 16 can match eol */
1423 YY_RULE_SETUP
1424 #line 385 "markup.l"
1425 text_add_str(yytext, yyleng);
1426 YY_BREAK
1427
1428
1429 case 17:
1430 YY_RULE_SETUP
1431 #line 388 "markup.l"
1432 text_add_strz("ˈ"); /* Main accent */
1433 YY_BREAK
1434 case 18:
1435 YY_RULE_SETUP
1436 #line 389 "markup.l"
1437 text_add_strz("ˌ"); /* Secondary accent */
1438 YY_BREAK
1439 case 19:
1440 YY_RULE_SETUP
1441 #line 390 "markup.l"
1442 text_add_strz("‑"); /* Syllable break */
1443 YY_BREAK
1444 case 20:
1445 /* rule 20 can match eol */
1446 YY_RULE_SETUP
1447 #line 391 "markup.l"
1448 text_add_str(yytext, yyleng);
1449 YY_BREAK
1450
1451
1452 case 21:
1453 /* rule 21 can match eol */
1454 YY_RULE_SETUP
1455 #line 394 "markup.l"
1456 {
1457 if (yyleng >= endtaglen &&
1458 memcmp(yytext + yyleng - endtaglen, endtag, endtaglen) == 0)
1459 BEGIN(retstate);
1460 }
1461 YY_BREAK
1462 case 22:
1463 /* rule 22 can match eol */
1464 YY_RULE_SETUP
1465 #line 399 "markup.l"
1466 ;
1467 YY_BREAK
1468
1469 case 23:
1470 YY_RULE_SETUP
1471 #line 402 "markup.l"
1472 {
1473 if (input_len > 0)
1474 dico_log(L_NOTICE, 0,
1475 _("%s:%zu: unmatched character %03o; please report"),
1476 LOCUS_FILE, LOCUS_OFF(token_beg), yytext[0]);
1477 text_add_chr(yytext[0]);
1478 }
1479 YY_BREAK
1480 case 24:
1481 YY_RULE_SETUP
1482 #line 409 "markup.l"
1483 YY_FATAL_ERROR( "flex scanner jammed" );
1484 YY_BREAK
1485 #line 1485 "markup.c"
1486 case YY_STATE_EOF(INITIAL):
1487 case YY_STATE_EOF(COMMENT):
1488 case YY_STATE_EOF(PR):
1489 case YY_STATE_EOF(HW):
1490 case YY_STATE_EOF(PRE):
1491 yyterminate();
1492
1493 case YY_END_OF_BUFFER:
1494 {
1495 /* Amount of text matched not including the EOB char. */
1496 int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
1497
1498 /* Undo the effects of YY_DO_BEFORE_ACTION. */
1499 *yy_cp = (yy_hold_char);
1500 YY_RESTORE_YY_MORE_OFFSET
1501
1502 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1503 {
1504 /* We're scanning a new file or input source. It's
1505 * possible that this happened because the user
1506 * just pointed yyin at a new source and called
1507 * yylex(). If so, then we have to assure
1508 * consistency between YY_CURRENT_BUFFER and our
1509 * globals. Here is the right place to do so, because
1510 * this is the first action (other than possibly a
1511 * back-up) that will match for the new input source.
1512 */
1513 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1514 /* %if-c-only */
1515 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1516 /* %endif */
1517 /* %if-c++-only */
1518 /* %endif */
1519 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1520 }
1521
1522 /* Note that here we test for yy_c_buf_p "<=" to the position
1523 * of the first EOB in the buffer, since yy_c_buf_p will
1524 * already have been incremented past the NUL character
1525 * (since all states make transitions on EOB to the
1526 * end-of-buffer state). Contrast this with the test
1527 * in input().
1528 */
1529 if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1530 { /* This was really a NUL. */
1531 yy_state_type yy_next_state;
1532
1533 (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
1534
1535 yy_current_state = yy_get_previous_state( );
1536
1537 /* Okay, we're now positioned to make the NUL
1538 * transition. We couldn't have
1539 * yy_get_previous_state() go ahead and do it
1540 * for us because it doesn't know how to deal
1541 * with the possibility of jamming (and we don't
1542 * want to build jamming into it because then it
1543 * will run more slowly).
1544 */
1545
1546 yy_next_state = yy_try_NUL_trans( yy_current_state );
1547
1548 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1549
1550 if ( yy_next_state )
1551 {
1552 /* Consume the NUL. */
1553 yy_cp = ++(yy_c_buf_p);
1554 yy_current_state = yy_next_state;
1555 goto yy_match;
1556 }
1557
1558 else
1559 {
1560 /* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
1561 yy_cp = (yy_c_buf_p);
1562 goto yy_find_action;
1563 }
1564 }
1565
1566 else switch ( yy_get_next_buffer( ) )
1567 {
1568 case EOB_ACT_END_OF_FILE:
1569 {
1570 (yy_did_buffer_switch_on_eof) = 0;
1571
1572 if ( yywrap( ) )
1573 {
1574 /* Note: because we've taken care in
1575 * yy_get_next_buffer() to have set up
1576 * yytext, we can now set up
1577 * yy_c_buf_p so that if some total
1578 * hoser (like flex itself) wants to
1579 * call the scanner after we return the
1580 * YY_NULL, it'll still work - another
1581 * YY_NULL will get returned.
1582 */
1583 (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
1584
1585 yy_act = YY_STATE_EOF(YY_START);
1586 goto do_action;
1587 }
1588
1589 else
1590 {
1591 if ( ! (yy_did_buffer_switch_on_eof) )
1592 YY_NEW_FILE;
1593 }
1594 break;
1595 }
1596
1597 case EOB_ACT_CONTINUE_SCAN:
1598 (yy_c_buf_p) =
1599 (yytext_ptr) + yy_amount_of_matched_text;
1600
1601 yy_current_state = yy_get_previous_state( );
1602
1603 yy_cp = (yy_c_buf_p);
1604 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1605 goto yy_match;
1606
1607 case EOB_ACT_LAST_MATCH:
1608 (yy_c_buf_p) =
1609 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
1610
1611 yy_current_state = yy_get_previous_state( );
1612
1613 yy_cp = (yy_c_buf_p);
1614 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1615 goto yy_find_action;
1616 }
1617 break;
1618 }
1619
1620 default:
1621 YY_FATAL_ERROR(
1622 "fatal flex scanner internal error--no action found" );
1623 } /* end of action switch */
1624 } /* end of scanning one token */
1625 } /* end of user's declarations */
1626 } /* end of yylex */
1627 /* %ok-for-header */
1628
1629 /* %if-c++-only */
1630 /* %not-for-header */
1631 /* %ok-for-header */
1632
1633 /* %endif */
1634
1635 /* yy_get_next_buffer - try to read in a new buffer
1636 *
1637 * Returns a code representing an action:
1638 * EOB_ACT_LAST_MATCH -
1639 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1640 * EOB_ACT_END_OF_FILE - end of file
1641 */
1642 /* %if-c-only */
1643 static int yy_get_next_buffer (void)
1644 /* %endif */
1645 /* %if-c++-only */
1646 /* %endif */
1647 {
1648 char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1649 char *source = (yytext_ptr);
1650 int number_to_move, i;
1651 int ret_val;
1652
1653 if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1654 YY_FATAL_ERROR(
1655 "fatal flex scanner internal error--end of buffer missed" );
1656
1657 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1658 { /* Don't try to fill the buffer, so this is an EOF. */
1659 if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
1660 {
1661 /* We matched a single character, the EOB, so
1662 * treat this as a final EOF.
1663 */
1664 return EOB_ACT_END_OF_FILE;
1665 }
1666
1667 else
1668 {
1669 /* We matched some text prior to the EOB, first
1670 * process it.
1671 */
1672 return EOB_ACT_LAST_MATCH;
1673 }
1674 }
1675
1676 /* Try to read more data. */
1677
1678 /* First move last chars to start of buffer. */
1679 number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
1680
1681 for ( i = 0; i < number_to_move; ++i )
1682 *(dest++) = *(source++);
1683
1684 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1685 /* don't do the read, it's not guaranteed to return an EOF,
1686 * just force an EOF
1687 */
1688 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
1689
1690 else
1691 {
1692 int num_to_read =
1693 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1694
1695 while ( num_to_read <= 0 )
1696 { /* Not enough room in the buffer - grow it. */
1697
1698 /* just a shorter name for the current buffer */
1699 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1700
1701 int yy_c_buf_p_offset =
1702 (int) ((yy_c_buf_p) - b->yy_ch_buf);
1703
1704 if ( b->yy_is_our_buffer )
1705 {
1706 int new_size = b->yy_buf_size * 2;
1707
1708 if ( new_size <= 0 )
1709 b->yy_buf_size += b->yy_buf_size / 8;
1710 else
1711 b->yy_buf_size *= 2;
1712
1713 b->yy_ch_buf = (char *)
1714 /* Include room in for 2 EOB chars. */
1715 yyrealloc( (void *) b->yy_ch_buf,
1716 (yy_size_t) (b->yy_buf_size + 2) );
1717 }
1718 else
1719 /* Can't grow it, we don't own it. */
1720 b->yy_ch_buf = NULL;
1721
1722 if ( ! b->yy_ch_buf )
1723 YY_FATAL_ERROR(
1724 "fatal error - scanner input buffer overflow" );
1725
1726 (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
1727
1728 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1729 number_to_move - 1;
1730
1731 }
1732
1733 if ( num_to_read > YY_READ_BUF_SIZE )
1734 num_to_read = YY_READ_BUF_SIZE;
1735
1736 /* Read in more data. */
1737 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1738 (yy_n_chars), num_to_read );
1739
1740 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1741 }
1742
1743 if ( (yy_n_chars) == 0 )
1744 {
1745 if ( number_to_move == YY_MORE_ADJ )
1746 {
1747 ret_val = EOB_ACT_END_OF_FILE;
1748 yyrestart( yyin );
1749 }
1750
1751 else
1752 {
1753 ret_val = EOB_ACT_LAST_MATCH;
1754 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1755 YY_BUFFER_EOF_PENDING;
1756 }
1757 }
1758
1759 else
1760 ret_val = EOB_ACT_CONTINUE_SCAN;
1761
1762 if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1763 /* Extend the array by 50%, plus the number we really need. */
1764 int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1765 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
1766 (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size );
1767 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1768 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1769 /* "- 2" to take care of EOB's */
1770 YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
1771 }
1772
1773 (yy_n_chars) += number_to_move;
1774 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
1775 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
1776
1777 (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1778
1779 return ret_val;
1780 }
1781
1782 /* yy_get_previous_state - get the state just before the EOB char was reached */
1783
1784 /* %if-c-only */
1785 /* %not-for-header */
1786 static yy_state_type yy_get_previous_state (void)
1787 /* %endif */
1788 /* %if-c++-only */
1789 /* %endif */
1790 {
1791 yy_state_type yy_current_state;
1792 char *yy_cp;
1793
1794 /* %% [15.0] code to get the start state into yy_current_state goes here */
1795 yy_current_state = (yy_start);
1796
1797 for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1798 {
1799 /* %% [16.0] code to find the next state goes here */
1800 YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1801 if ( yy_accept[yy_current_state] )
1802 {
1803 (yy_last_accepting_state) = yy_current_state;
1804 (yy_last_accepting_cpos) = yy_cp;
1805 }
1806 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1807 {
1808 yy_current_state = (int) yy_def[yy_current_state];
1809 if ( yy_current_state >= 65 )
1810 yy_c = yy_meta[yy_c];
1811 }
1812 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1813 }
1814
1815 return yy_current_state;
1816 }
1817
1818 /* yy_try_NUL_trans - try to make a transition on the NUL character
1819 *
1820 * synopsis
1821 * next_state = yy_try_NUL_trans( current_state );
1822 */
1823 /* %if-c-only */
1824 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
1825 /* %endif */
1826 /* %if-c++-only */
1827 /* %endif */
1828 {
1829 int yy_is_jam;
1830 /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
1831 char *yy_cp = (yy_c_buf_p);
1832
1833 YY_CHAR yy_c = 1;
1834 if ( yy_accept[yy_current_state] )
1835 {
1836 (yy_last_accepting_state) = yy_current_state;
1837 (yy_last_accepting_cpos) = yy_cp;
1838 }
1839 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1840 {
1841 yy_current_state = (int) yy_def[yy_current_state];
1842 if ( yy_current_state >= 65 )
1843 yy_c = yy_meta[yy_c];
1844 }
1845 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1846 yy_is_jam = (yy_current_state == 64);
1847
1848 return yy_is_jam ? 0 : yy_current_state;
1849 }
1850
1851 #ifndef YY_NO_UNPUT
1852 /* %if-c-only */
1853
1854 /* %endif */
1855 #endif
1856
1857 /* %if-c-only */
1858 #ifndef YY_NO_INPUT
1859 #ifdef __cplusplus
1860 static int yyinput (void)
1861 #else
1862 static int input (void)
1863 #endif
1864
1865 /* %endif */
1866 /* %if-c++-only */
1867 /* %endif */
1868 {
1869 int c;
1870
1871 *(yy_c_buf_p) = (yy_hold_char);
1872
1873 if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
1874 {
1875 /* yy_c_buf_p now points to the character we want to return.
1876 * If this occurs *before* the EOB characters, then it's a
1877 * valid NUL; if not, then we've hit the end of the buffer.
1878 */
1879 if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1880 /* This was really a NUL. */
1881 *(yy_c_buf_p) = '\0';
1882
1883 else
1884 { /* need more input */
1885 int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
1886 ++(yy_c_buf_p);
1887
1888 switch ( yy_get_next_buffer( ) )
1889 {
1890 case EOB_ACT_LAST_MATCH:
1891 /* This happens because yy_g_n_b()
1892 * sees that we've accumulated a
1893 * token and flags that we need to
1894 * try matching the token before
1895 * proceeding. But for input(),
1896 * there's no matching to consider.
1897 * So convert the EOB_ACT_LAST_MATCH
1898 * to EOB_ACT_END_OF_FILE.
1899 */
1900
1901 /* Reset buffer status. */
1902 yyrestart( yyin );
1903
1904 /*FALLTHROUGH*/
1905
1906 case EOB_ACT_END_OF_FILE:
1907 {
1908 if ( yywrap( ) )
1909 return 0;
1910
1911 if ( ! (yy_did_buffer_switch_on_eof) )
1912 YY_NEW_FILE;
1913 #ifdef __cplusplus
1914 return yyinput();
1915 #else
1916 return input();
1917 #endif
1918 }
1919
1920 case EOB_ACT_CONTINUE_SCAN:
1921 (yy_c_buf_p) = (yytext_ptr) + offset;
1922 break;
1923 }
1924 }
1925 }
1926
1927 c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
1928 *(yy_c_buf_p) = '\0'; /* preserve yytext */
1929 (yy_hold_char) = *++(yy_c_buf_p);
1930
1931 /* %% [19.0] update BOL and yylineno */
1932
1933 return c;
1934 }
1935 /* %if-c-only */
1936 #endif /* ifndef YY_NO_INPUT */
1937 /* %endif */
1938
1939 /** Immediately switch to a different input stream.
1940 * @param input_file A readable stream.
1941 *
1942 * @note This function does not reset the start condition to @c INITIAL .
1943 */
1944 /* %if-c-only */
1945 void yyrestart (FILE * input_file )
1946 /* %endif */
1947 /* %if-c++-only */
1948 /* %endif */
1949 {
1950
1951 if ( ! YY_CURRENT_BUFFER ){
1952 yyensure_buffer_stack ();
1953 YY_CURRENT_BUFFER_LVALUE =
1954 yy_create_buffer( yyin, YY_BUF_SIZE );
1955 }
1956
1957 yy_init_buffer( YY_CURRENT_BUFFER, input_file );
1958 yy_load_buffer_state( );
1959 }
1960
1961 /* %if-c++-only */
1962 /* %endif */
1963
1964 /** Switch to a different input buffer.
1965 * @param new_buffer The new input buffer.
1966 *
1967 */
1968 /* %if-c-only */
1969 void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
1970 /* %endif */
1971 /* %if-c++-only */
1972 /* %endif */
1973 {
1974
1975 /* TODO. We should be able to replace this entire function body
1976 * with
1977 * yypop_buffer_state();
1978 * yypush_buffer_state(new_buffer);
1979 */
1980 yyensure_buffer_stack ();
1981 if ( YY_CURRENT_BUFFER == new_buffer )
1982 return;
1983
1984 if ( YY_CURRENT_BUFFER )
1985 {
1986 /* Flush out information for old buffer. */
1987 *(yy_c_buf_p) = (yy_hold_char);
1988 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1989 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1990 }
1991
1992 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1993 yy_load_buffer_state( );
1994
1995 /* We don't actually know whether we did this switch during
1996 * EOF (yywrap()) processing, but the only time this flag
1997 * is looked at is after yywrap() is called, so it's safe
1998 * to go ahead and always set it.
1999 */
2000 (yy_did_buffer_switch_on_eof) = 1;
2001 }
2002
2003 /* %if-c-only */
2004 static void yy_load_buffer_state (void)
2005 /* %endif */
2006 /* %if-c++-only */
2007 /* %endif */
2008 {
2009 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2010 (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
2011 /* %if-c-only */
2012 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
2013 /* %endif */
2014 /* %if-c++-only */
2015 /* %endif */
2016 (yy_hold_char) = *(yy_c_buf_p);
2017 }
2018
2019 /** Allocate and initialize an input buffer state.
2020 * @param file A readable stream.
2021 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
2022 *
2023 * @return the allocated buffer state.
2024 */
2025 /* %if-c-only */
2026 YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
2027 /* %endif */
2028 /* %if-c++-only */
2029 /* %endif */
2030 {
2031 YY_BUFFER_STATE b;
2032
2033 b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
2034 if ( ! b )
2035 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2036
2037 b->yy_buf_size = size;
2038
2039 /* yy_ch_buf has to be 2 characters longer than the size given because
2040 * we need to put in 2 end-of-buffer characters.
2041 */
2042 b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) );
2043 if ( ! b->yy_ch_buf )
2044 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2045
2046 b->yy_is_our_buffer = 1;
2047
2048 yy_init_buffer( b, file );
2049
2050 return b;
2051 }
2052
2053 /* %if-c++-only */
2054 /* %endif */
2055
2056 /** Destroy the buffer.
2057 * @param b a buffer created with yy_create_buffer()
2058 *
2059 */
2060 /* %if-c-only */
2061 void yy_delete_buffer (YY_BUFFER_STATE b )
2062 /* %endif */
2063 /* %if-c++-only */
2064 /* %endif */
2065 {
2066
2067 if ( ! b )
2068 return;
2069
2070 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
2071 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
2072
2073 if ( b->yy_is_our_buffer )
2074 yyfree( (void *) b->yy_ch_buf );
2075
2076 yyfree( (void *) b );
2077 }
2078
2079 /* Initializes or reinitializes a buffer.
2080 * This function is sometimes called more than once on the same buffer,
2081 * such as during a yyrestart() or at EOF.
2082 */
2083 /* %if-c-only */
2084 static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
2085 /* %endif */
2086 /* %if-c++-only */
2087 /* %endif */
2088
2089 {
2090 int oerrno = errno;
2091
2092 yy_flush_buffer( b );
2093
2094 /* %if-c-only */
2095 b->yy_input_file = file;
2096 /* %endif */
2097 /* %if-c++-only */
2098 /* %endif */
2099 b->yy_fill_buffer = 1;
2100
2101 /* If b is the current buffer, then yy_init_buffer was _probably_
2102 * called from yyrestart() or through yy_get_next_buffer.
2103 * In that case, we don't want to reset the lineno or column.
2104 */
2105 if (b != YY_CURRENT_BUFFER){
2106 b->yy_bs_lineno = 1;
2107 b->yy_bs_column = 0;
2108 }
2109
2110 /* %if-c-only */
2111
2112 b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
2113
2114 /* %endif */
2115 /* %if-c++-only */
2116 /* %endif */
2117 errno = oerrno;
2118 }
2119
2120 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
2121 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
2122 *
2123 */
2124 /* %if-c-only */
2125 void yy_flush_buffer (YY_BUFFER_STATE b )
2126 /* %endif */
2127 /* %if-c++-only */
2128 /* %endif */
2129 {
2130 if ( ! b )
2131 return;
2132
2133 b->yy_n_chars = 0;
2134
2135 /* We always need two end-of-buffer characters. The first causes
2136 * a transition to the end-of-buffer state. The second causes
2137 * a jam in that state.
2138 */
2139 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
2140 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
2141
2142 b->yy_buf_pos = &b->yy_ch_buf[0];
2143
2144 b->yy_at_bol = 1;
2145 b->yy_buffer_status = YY_BUFFER_NEW;
2146
2147 if ( b == YY_CURRENT_BUFFER )
2148 yy_load_buffer_state( );
2149 }
2150
2151 /* %if-c-or-c++ */
2152 /** Pushes the new state onto the stack. The new state becomes
2153 * the current state. This function will allocate the stack
2154 * if necessary.
2155 * @param new_buffer The new state.
2156 *
2157 */
2158 /* %if-c-only */
2159 void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
2160 /* %endif */
2161 /* %if-c++-only */
2162 /* %endif */
2163 {
2164 if (new_buffer == NULL)
2165 return;
2166
2167 yyensure_buffer_stack();
2168
2169 /* This block is copied from yy_switch_to_buffer. */
2170 if ( YY_CURRENT_BUFFER )
2171 {
2172 /* Flush out information for old buffer. */
2173 *(yy_c_buf_p) = (yy_hold_char);
2174 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
2175 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
2176 }
2177
2178 /* Only push if top exists. Otherwise, replace top. */
2179 if (YY_CURRENT_BUFFER)
2180 (yy_buffer_stack_top)++;
2181 YY_CURRENT_BUFFER_LVALUE = new_buffer;
2182
2183 /* copied from yy_switch_to_buffer. */
2184 yy_load_buffer_state( );
2185 (yy_did_buffer_switch_on_eof) = 1;
2186 }
2187 /* %endif */
2188
2189 /* %if-c-or-c++ */
2190 /** Removes and deletes the top of the stack, if present.
2191 * The next element becomes the new top.
2192 *
2193 */
2194 /* %if-c-only */
2195 void yypop_buffer_state (void)
2196 /* %endif */
2197 /* %if-c++-only */
2198 /* %endif */
2199 {
2200 if (!YY_CURRENT_BUFFER)
2201 return;
2202
2203 yy_delete_buffer(YY_CURRENT_BUFFER );
2204 YY_CURRENT_BUFFER_LVALUE = NULL;
2205 if ((yy_buffer_stack_top) > 0)
2206 --(yy_buffer_stack_top);
2207
2208 if (YY_CURRENT_BUFFER) {
2209 yy_load_buffer_state( );
2210 (yy_did_buffer_switch_on_eof) = 1;
2211 }
2212 }
2213 /* %endif */
2214
2215 /* %if-c-or-c++ */
2216 /* Allocates the stack if it does not exist.
2217 * Guarantees space for at least one push.
2218 */
2219 /* %if-c-only */
2220 static void yyensure_buffer_stack (void)
2221 /* %endif */
2222 /* %if-c++-only */
2223 /* %endif */
2224 {
2225 yy_size_t num_to_alloc;
2226
2227 if (!(yy_buffer_stack)) {
2228
2229 /* First allocation is just for 2 elements, since we don't know if this
2230 * scanner will even need a stack. We use 2 instead of 1 to avoid an
2231 * immediate realloc on the next call.
2232 */
2233 num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
2234 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
2235 (num_to_alloc * sizeof(struct yy_buffer_state*)
2236 );
2237 if ( ! (yy_buffer_stack) )
2238 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2239
2240 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
2241
2242 (yy_buffer_stack_max) = num_to_alloc;
2243 (yy_buffer_stack_top) = 0;
2244 return;
2245 }
2246
2247 if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
2248
2249 /* Increase the buffer to prepare for a possible push. */
2250 yy_size_t grow_size = 8 /* arbitrary grow size */;
2251
2252 num_to_alloc = (yy_buffer_stack_max) + grow_size;
2253 (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
2254 ((yy_buffer_stack),
2255 num_to_alloc * sizeof(struct yy_buffer_state*)
2256 );
2257 if ( ! (yy_buffer_stack) )
2258 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2259
2260 /* zero only the new slots.*/
2261 memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
2262 (yy_buffer_stack_max) = num_to_alloc;
2263 }
2264 }
2265 /* %endif */
2266
2267 /* %if-c-only */
2268 /** Setup the input buffer state to scan directly from a user-specified character buffer.
2269 * @param base the character buffer
2270 * @param size the size in bytes of the character buffer
2271 *
2272 * @return the newly allocated buffer state object.
2273 */
2274 YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
2275 {
2276 YY_BUFFER_STATE b;
2277
2278 if ( size < 2 ||
2279 base[size-2] != YY_END_OF_BUFFER_CHAR ||
2280 base[size-1] != YY_END_OF_BUFFER_CHAR )
2281 /* They forgot to leave room for the EOB's. */
2282 return NULL;
2283
2284 b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
2285 if ( ! b )
2286 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
2287
2288 b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
2289 b->yy_buf_pos = b->yy_ch_buf = base;
2290 b->yy_is_our_buffer = 0;
2291 b->yy_input_file = NULL;
2292 b->yy_n_chars = b->yy_buf_size;
2293 b->yy_is_interactive = 0;
2294 b->yy_at_bol = 1;
2295 b->yy_fill_buffer = 0;
2296 b->yy_buffer_status = YY_BUFFER_NEW;
2297
2298 yy_switch_to_buffer( b );
2299
2300 return b;
2301 }
2302 /* %endif */
2303
2304 /* %if-c-only */
2305 /** Setup the input buffer state to scan a string. The next call to yylex() will
2306 * scan from a @e copy of @a str.
2307 * @param yystr a NUL-terminated string to scan
2308 *
2309 * @return the newly allocated buffer state object.
2310 * @note If you want to scan bytes that may contain NUL values, then use
2311 * yy_scan_bytes() instead.
2312 */
2313 YY_BUFFER_STATE yy_scan_string (const char * yystr )
2314 {
2315
2316 return yy_scan_bytes( yystr, (int) strlen(yystr) );
2317 }
2318 /* %endif */
2319
2320 /* %if-c-only */
2321 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
2322 * scan from a @e copy of @a bytes.
2323 * @param yybytes the byte buffer to scan
2324 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2325 *
2326 * @return the newly allocated buffer state object.
2327 */
2328 YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len )
2329 {
2330 YY_BUFFER_STATE b;
2331 char *buf;
2332 yy_size_t n;
2333 int i;
2334
2335 /* Get memory for full buffer, including space for trailing EOB's. */
2336 n = (yy_size_t) (_yybytes_len + 2);
2337 buf = (char *) yyalloc( n );
2338 if ( ! buf )
2339 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2340
2341 for ( i = 0; i < _yybytes_len; ++i )
2342 buf[i] = yybytes[i];
2343
2344 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2345
2346 b = yy_scan_buffer( buf, n );
2347 if ( ! b )
2348 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2349
2350 /* It's okay to grow etc. this buffer, and we should throw it
2351 * away when we're done.
2352 */
2353 b->yy_is_our_buffer = 1;
2354
2355 return b;
2356 }
2357 /* %endif */
2358
2359 #ifndef YY_EXIT_FAILURE
2360 #define YY_EXIT_FAILURE 2
2361 #endif
2362
2363 /* %if-c-only */
2364 static void yynoreturn yy_fatal_error (const char* msg )
2365 {
2366 fprintf( stderr, "%s\n", msg );
2367 exit( YY_EXIT_FAILURE );
2368 }
2369 /* %endif */
2370 /* %if-c++-only */
2371 /* %endif */
2372
2373 /* Redefine yyless() so it works in section 3 code. */
2374
2375 #undef yyless
2376 #define yyless(n) \
2377 do \
2378 { \
2379 /* Undo effects of setting up yytext. */ \
2380 int yyless_macro_arg = (n); \
2381 YY_LESS_LINENO(yyless_macro_arg);\
2382 yytext[yyleng] = (yy_hold_char); \
2383 (yy_c_buf_p) = yytext + yyless_macro_arg; \
2384 (yy_hold_char) = *(yy_c_buf_p); \
2385 *(yy_c_buf_p) = '\0'; \
2386 yyleng = yyless_macro_arg; \
2387 } \
2388 while ( 0 )
2389
2390 /* Accessor methods (get/set functions) to struct members. */
2391
2392 /* %if-c-only */
2393 /* %if-reentrant */
2394 /* %endif */
2395
2396 /** Get the current line number.
2397 *
2398 */
2399 int yyget_lineno (void)
2400 {
2401
2402 return yylineno;
2403 }
2404
2405 /** Get the input stream.
2406 *
2407 */
2408 FILE *yyget_in (void)
2409 {
2410 return yyin;
2411 }
2412
2413 /** Get the output stream.
2414 *
2415 */
2416 FILE *yyget_out (void)
2417 {
2418 return yyout;
2419 }
2420
2421 /** Get the length of the current token.
2422 *
2423 */
2424 int yyget_leng (void)
2425 {
2426 return yyleng;
2427 }
2428
2429 /** Get the current token.
2430 *
2431 */
2432
2433 char *yyget_text (void)
2434 {
2435 return yytext;
2436 }
2437
2438 /* %if-reentrant */
2439 /* %endif */
2440
2441 /** Set the current line number.
2442 * @param _line_number line number
2443 *
2444 */
2445 void yyset_lineno (int _line_number )
2446 {
2447
2448 yylineno = _line_number;
2449 }
2450
2451 /** Set the input stream. This does not discard the current
2452 * input buffer.
2453 * @param _in_str A readable stream.
2454 *
2455 * @see yy_switch_to_buffer
2456 */
2457 void yyset_in (FILE * _in_str )
2458 {
2459 yyin = _in_str ;
2460 }
2461
2462 void yyset_out (FILE * _out_str )
2463 {
2464 yyout = _out_str ;
2465 }
2466
2467 int yyget_debug (void)
2468 {
2469 return yy_flex_debug;
2470 }
2471
2472 void yyset_debug (int _bdebug )
2473 {
2474 yy_flex_debug = _bdebug ;
2475 }
2476
2477 /* %endif */
2478
2479 /* %if-reentrant */
2480 /* %if-bison-bridge */
2481 /* %endif */
2482 /* %endif if-c-only */
2483
2484 /* %if-c-only */
2485 static int yy_init_globals (void)
2486 {
2487 /* Initialization is the same as for the non-reentrant scanner.
2488 * This function is called from yylex_destroy(), so don't allocate here.
2489 */
2490
2491 (yy_buffer_stack) = NULL;
2492 (yy_buffer_stack_top) = 0;
2493 (yy_buffer_stack_max) = 0;
2494 (yy_c_buf_p) = NULL;
2495 (yy_init) = 0;
2496 (yy_start) = 0;
2497
2498 /* Defined in main.c */
2499 #ifdef YY_STDINIT
2500 yyin = stdin;
2501 yyout = stdout;
2502 #else
2503 yyin = NULL;
2504 yyout = NULL;
2505 #endif
2506
2507 /* For future reference: Set errno on error, since we are called by
2508 * yylex_init()
2509 */
2510 return 0;
2511 }
2512 /* %endif */
2513
2514 /* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
2515 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
2516 int yylex_destroy (void)
2517 {
2518
2519 /* Pop the buffer stack, destroying each element. */
2520 while(YY_CURRENT_BUFFER){
2521 yy_delete_buffer( YY_CURRENT_BUFFER );
2522 YY_CURRENT_BUFFER_LVALUE = NULL;
2523 yypop_buffer_state();
2524 }
2525
2526 /* Destroy the stack itself. */
2527 yyfree((yy_buffer_stack) );
2528 (yy_buffer_stack) = NULL;
2529
2530 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2531 * yylex() is called, initialization will occur. */
2532 yy_init_globals( );
2533
2534 /* %if-reentrant */
2535 /* %endif */
2536 return 0;
2537 }
2538 /* %endif */
2539
2540 /*
2541 * Internal utility routines.
2542 */
2543
2544 #ifndef yytext_ptr
2545 static void yy_flex_strncpy (char* s1, const char * s2, int n )
2546 {
2547
2548 int i;
2549 for ( i = 0; i < n; ++i )
2550 s1[i] = s2[i];
2551 }
2552 #endif
2553
2554 #ifdef YY_NEED_STRLEN
2555 static int yy_flex_strlen (const char * s )
2556 {
2557 int n;
2558 for ( n = 0; s[n]; ++n )
2559 ;
2560
2561 return n;
2562 }
2563 #endif
2564
2565 void *yyalloc (yy_size_t size )
2566 {
2567 return malloc(size);
2568 }
2569
2570 void *yyrealloc (void * ptr, yy_size_t size )
2571 {
2572
2573 /* The cast to (char *) in the following accommodates both
2574 * implementations that use char* generic pointers, and those
2575 * that use void* generic pointers. It works with the latter
2576 * because both ANSI C and C++ allow castless assignment from
2577 * any pointer type to void*, and deal with argument conversions
2578 * as though doing an assignment.
2579 */
2580 return realloc(ptr, size);
2581 }
2582
2583 void yyfree (void * ptr )
2584 {
2585 free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2586 }
2587
2588 /* %if-tables-serialization definitions */
2589 /* %define-yytables The name for this specific scanner's tables. */
2590 #define YYTABLES_NAME "yytables"
2591 /* %endif */
2592
2593 /* %ok-for-header */
2594
2595 #line 409 "markup.l"
2596
2597
2598 int
2599 yywrap()
2600 {
2601 return 1;
2602 }
2603
2604 static void
2605 push_tag(struct gcide_tag *tag)
2606 {
2607 append_tag(tag);
2608 dico_list_push(tagstk, current_tag);
2609 current_tag = tag;
2610 if (strcmp(current_tag->tag_name, "pr") == 0)
2611 BEGIN(PR);
2612 else if (strcmp(current_tag->tag_name, "hw") == 0)
2613 BEGIN(HW);
2614 else if (strcmp(current_tag->tag_name, "pre") == 0)
2615 BEGIN(PRE);
2616 else if (strcmp(current_tag->tag_name, "p") == 0)
2617 first_p_seen = 1;
2618 }
2619
2620 static void
2621 pop_tag(const char *tagstr, size_t taglen)
2622 {
2623 int len;
2624 char *p;
2625
2626 text_assert_size(taglen);
2627 p = textspace + textpos;
2628 for (len = 0; len < taglen; len++) {
2629 if (tagstr[len] == ' ' || tagstr[len] == '\t')
2630 break;
2631 *p++ = tolower(tagstr[len]);
2632 }
2633 tagstr = textspace + textpos;
2634
2635 if ((len == 2 && (memcmp(tagstr, "pr", len) == 0 ||
2636 memcmp(tagstr, "hw", len) == 0)) ||
2637 (len == 3 && memcmp(tagstr, "pre", len) == 0))
2638 BEGIN(INITIAL);
2639
2640 if (current_tag->tag_type == gcide_content_tag &&
2641 strlen(current_tag->tag_name) == len &&
2642 memcmp(current_tag->tag_name, tagstr, len) == 0)
2643 current_tag = dico_list_pop(tagstk);
2644 else if (current_tag->tag_type == gcide_content_top &&
2645 len == 1 &&
2646 tagstr[0] == 'p' &&
2647 !first_p_seen) {
2648 /*
2649 * The first instance of </p> has no corresponding open <p> tag
2650 * because idxgcide stores the offset of the first <hw> tag in the
2651 * index entry, whereas the opening <p> tag in GCIDE entries appears
2652 * before the <ent> tag (which precedes the <hw>).
2653 *
2654 * Re-create the first <p>...</p> block from the data collected so
2655 * far and push it as the first element to the newly created top-
2656 * level tag list. Set first_p_seen flag to make sure this code is
2657 * executed once.
2658 *
2659 * See also the comment to first_p_seen, above.
2660 */
2661 struct gcide_tag *tag = current_tag;
2662 tag->tag_type = gcide_content_tag;
2663 tag->v.tag.tag_parmc = 1;
2664 tag->v.tag.tag_parmv = calloc(2, sizeof(tag->v.tag.tag_parmv[0]));
2665 if (!tag->v.tag.tag_parmv)
2666 memerr("pop_tag");
2667 tag->v.tag.tag_parmv[0] = strdup("p");
2668 if (!tag->v.tag.tag_parmv[0])
2669 memerr("pop_tag");
2670 tag->v.tag.tag_parmv[1] = NULL;
2671 current_tag = alloc_tag(gcide_content_top);
2672 append_tag(tag);
2673 first_p_seen = 1;
2674 } else {
2675 size_t i, count;
2676
2677 /* Try to find matching entry */
2678 count = dico_list_count(tagstk);
2679 for (i = count; i > 0; i--) {
2680 struct gcide_tag *p = dico_list_item(tagstk, i-1);
2681 if (p->tag_type == gcide_content_tag &&
2682 strlen(p->tag_name) == len &&
2683 memcmp(p->tag_name, tagstr, len) == 0) {
2684 do {
2685 if (current_tag->tag_type == gcide_content_tag)
2686 dico_log(L_WARN, 0, "%s:%zu: %s: unclosed tag",
2687 LOCUS_FILE, LOCUS_OFF(current_tag->offset),
2688 current_tag->tag_name);
2689 } while ((current_tag = dico_list_pop(tagstk)) != p);
2690 current_tag = dico_list_pop(tagstk);
2691 return;
2692 }
2693 }
2694 dico_log(L_WARN, 0, "%s:%zu: %*.*s: unexpected closing tag",
2695 LOCUS_FILE, LOCUS_OFF(token_beg), len, len, tagstr);
2696 }
2697 }
2698
2699 struct walk_closure {
2700 int (*fun)(int, struct gcide_tag *, void *);
2701 void *data;
2702 };
2703
2704 static int
2705 inorder_helper(void *item, void *data)
2706 {
2707 struct gcide_tag *tag = item;
2708 struct walk_closure *cp = data;
2709
2710 if (cp->fun(0, tag, cp->data))
2711 return 1;
2712 if (tag->tag_type == gcide_content_top ||
2713 tag->tag_type == gcide_content_tag) {
2714 dico_list_iterate(tag->v.tag.taglist, inorder_helper, data);
2715 if (cp->fun(1, tag, cp->data))
2716 return 1;
2717 }
2718 return 0;
2719 }
2720
2721 int
2722 gcide_parse_tree_inorder(struct gcide_parse_tree *tp,
2723 int (*fun)(int, struct gcide_tag *, void *),
2724 void *data)
2725 {
2726 struct walk_closure clos;
2727 clos.fun = fun;
2728 clos.data = data;
2729 return inorder_helper(tp->root, &clos);
2730 }
2731
2732 static int
2733 tag_fixup(void *item, void *data)
2734 {
2735 struct gcide_tag *tag = item;
2736 char *textspace = data;
2737
2738 switch (tag->tag_type) {
2739 case gcide_content_text:
2740 tag->v.text = textspace + tag->v.textpos;
2741 break;
2742 case gcide_content_top:
2743 case gcide_content_tag:
2744 dico_list_iterate(tag->v.tag.taglist, tag_fixup, textspace);
2745 break;
2746 default:
2747 break;
2748 }
2749 return 0;
2750 }
2751
2752 static char const *block_tags[] = {
2753 "source",
2754 "sn",
2755 "p",
2756 "q",
2757 "rj",
2758 "gcide_quote",
2759 NULL
2760 };
2761
2762 int
2763 gcide_is_block_tag(struct gcide_tag *tag)
2764 {
2765 if (tag && tag->tag_type == gcide_content_tag) {
2766 char const **p;
2767
2768 for (p = block_tags; *p; p++)
2769 if (strcmp(tag->tag_name, *p) == 0)
2770 return 1;
2771 }
2772 return 0;
2773 }
2774
2775 int
2776 gcide_is_ws_text(struct gcide_tag *tag)
2777 {
2778 if (tag && tag->tag_type == gcide_content_text) {
2779 char *p;
2780 for (p = tag->v.text; *p == '\n' || *p == ' ' || *p == '\t'; p++);
2781 return *p == 0;
2782 }
2783 return 0;
2784 }
2785
2786 /*
2787 * Fix up the nl/br usage. See the comment to ws_fixup, below.
2788 */
2789 static int
2790 ws_reduce(void *a, void *b, void *data)
2791 {
2792 struct gcide_tag *atag = a;
2793 struct gcide_tag *btag = b;
2794
2795 if (atag->delete)
2796 return 1;
2797
2798 switch (atag->tag_type) {
2799 case gcide_content_tag:
2800 if (strcmp(atag->tag_name, "source") == 0 &&
2801 btag &&
2802 btag->tag_type == gcide_content_text &&
2803 btag->v.text[0] == ']')
2804 btag->v.text++;
2805 dico_list_reduce(atag->v.tag.taglist, ws_reduce, NULL);
2806 if (gcide_is_block_tag(atag) && gcide_is_ws_text(btag))
2807 btag->delete = 1;
2808 break;
2809
2810 case gcide_content_text:
2811 if (atag->v.text[0] == 0)
2812 return 1;
2813 else if (gcide_is_ws_text(atag) && gcide_is_block_tag(btag))
2814 return 1;
2815 else {
2816 size_t len = strlen(atag->v.text);
2817 if (atag->v.text[len-1] == '[' &&
2818 btag &&
2819 btag->tag_type == gcide_content_tag &&
2820 strcmp(btag->tag_name, "source") == 0) {
2821 if (len == 1)
2822 return 1;
2823 atag->v.text[len-1] = 0;
2824 }
2825 }
2826 break;
2827
2828 case gcide_content_nl:
2829 if (btag == NULL)
2830 return 1;
2831 switch (btag->tag_type) {
2832 case gcide_content_tag:
2833 return gcide_is_block_tag(btag);
2834
2835 case gcide_content_text:
2836 if (btag->v.text[0] == ' ' || btag->v.text[0] == '\t')
2837 return 1;
2838 break;
2839
2840 case gcide_content_nl:
2841 case gcide_content_br:
2842 return 1;
2843
2844 default:
2845 break;
2846 }
2847 break;
2848
2849 case gcide_content_br:
2850 if (btag != NULL) {
2851 if (btag->tag_type == gcide_content_nl)
2852 btag->delete = 1;
2853 }
2854 break;
2855
2856 default:
2857 break;
2858 }
2859 return 0;
2860 }
2861
2862 /*
2863 * This analyzes the placement of gcide_content_nl and gcide_content_br
2864 * elements and removes the former where they are superfluous.
2865 * The gcide_content_nl elements are removed when they appear at either
2866 * side of a gcide_content_br element, or before a block tag, or a text
2867 * segment that begins with a whitespace character.
2868 *
2869 * Additionally, curly brackets surrounding a <source>...</source> construct
2870 * are removed as well.
2871 */
2872 static void
2873 ws_fixup(struct gcide_tag *tag)
2874 {
2875 if (tag->tag_type == gcide_content_top ||
2876 tag->tag_type == gcide_content_tag)
2877 dico_list_reduce(tag->v.tag.taglist, ws_reduce, NULL);
2878 }
2879
2880 static size_t
2881 greek_translit(size_t n)
2882 {
2883 while (textspace[n]) {
2884 size_t rd;
2885 const char *greek = gcide_grk_to_utf8(textspace + n, &rd);
2886
2887 if (greek) {
2888 text_add_str(greek, strlen(greek));
2889 n += rd;
2890 } else {
2891 text_add_chr(textspace[n]);
2892 n++;
2893 }
2894 }
2895 return text_segment_finish();
2896 }
2897
2898 static int
2899 early_fixup(void *item, void *data)
2900 {
2901 struct gcide_tag *tag = item;
2902 int translate = data ? *(int*)data : 0;
2903
2904 switch (tag->tag_type) {
2905 case gcide_content_text:
2906 if (translate)
2907 tag->v.textpos = greek_translit(tag->v.textpos);
2908 break;
2909 case gcide_content_top:
2910 dico_list_iterate(tag->v.tag.taglist, early_fixup, &translate);
2911 break;
2912 case gcide_content_tag:
2913 translate = gcide_is_tag(tag, "grk");
2914 dico_list_iterate(tag->v.tag.taglist, early_fixup, &translate);
2915 break;
2916 default:
2917 break;
2918 }
2919 return 0;
2920 }
2921
2922 /*
2923 * The <as> blocks in GCIDE corpus often begin with "as, ". This looks strange
2924 * if another font is used for <as> content or if it is otherwise marked up.
2925 * To avoid this, move "as, " out of <as>block.
2926 */
2927 static void
2928 as_fixup(struct gcide_tag *tag)
2929 {
2930 dico_iterator_t itr;
2931
2932 switch (tag->tag_type) {
2933 case gcide_content_top:
2934 case gcide_content_tag:
2935 itr = dico_list_iterator(tag->v.tag.taglist);
2936 tag = dico_iterator_first(itr);
2937 while (tag) {
2938 if (gcide_is_tag(tag, "as")) {
2939 struct gcide_tag *t = dico_list_head(tag->v.tag.taglist);
2940 char *s = textspace + t->v.textpos;
2941 if (strncmp(s, "as", 2) == 0 &&
2942 (isspace(s[3]) || ispunct(s[3]))) {
2943 int len;
2944 struct gcide_tag *t1;
2945
2946 for (len = 3; s[len] && isspace(s[len]); len++);
2947 text_add_str(s, len);
2948 t1 = alloc_tag(gcide_content_text);
2949 t1->v.textpos = text_segment_finish();
2950 dico_iterator_insert_before(itr, t1);
2951 dico_list_remove(tag->v.tag.taglist, t, NULL);
2952 if (s[len]) {
2953 t1 = alloc_tag(gcide_content_text);
2954 text_add_strz(s + len);
2955 t1->v.textpos = text_segment_finish();
2956 dico_list_prepend(tag->v.tag.taglist, t1);
2957 }
2958 }
2959 } else
2960 as_fixup(tag);
2961 tag = dico_iterator_next(itr);
2962 }
2963 dico_iterator_destroy(&itr);
2964 break;
2965 default:
2966 break;
2967 }
2968 }
2969
2970 struct gcide_parse_tree *
2971 gcide_markup_parse(char const *text, size_t len, int dbg, struct gcide_locus *loc)
2972 {
2973 struct gcide_parse_tree *tp;
2974 struct gcide_tag *p;
2975
2976 input_buf = text;
2977 input_len = len;
2978 token_beg = token_end = 0;
2979 first_p_seen = 0;
2980 base_locus = loc;
2981
2982 if (setjmp(errbuf)) {
2983 free(textspace);
2984 dico_list_destroy(&tagstk);
2985 free_tag(current_tag, NULL);
2986 }
2987
2988 if (SIZE_MAX / 2 < len)
2989 memerr("gcide_markup_parse");
2990 textsize = 2 * len;
2991 textspace = malloc(textsize);
2992 if (!textspace)
2993 memerr("gcide_markup_parse");
2994 textpos = textstart = 0;
2995
2996 tagstk = dico_list_create();
2997 if (!tagstk)
2998 memerr("gcide_markup_parse");
2999 dico_list_set_free_item(tagstk, free_tag, NULL);
3000 current_tag = alloc_tag(gcide_content_top);
3001
3002 yy_flex_debug = dbg;
3003 BEGIN(INITIAL);
3004 while (yylex())
3005 ;
3006
3007 /* Append trailing text segment, if any */
3008 flush_text_segment();
3009
3010 if (current_tag->tag_type != gcide_content_top) {
3011 p = current_tag;
3012 do {
3013 if (p->tag_type == gcide_content_tag)
3014 dico_log(L_WARN, 0, "%s:%zu: unclosed %s tag",
3015 LOCUS_FILE, LOCUS_OFF(p->offset), p->tag_name);
3016 current_tag = p;
3017 } while ((p = dico_list_pop(tagstk)));
3018 }
3019
3020 dico_list_destroy(&tagstk);
3021
3022 if (!current_tag) {
3023 free(textspace);
3024 return NULL;
3025 }
3026
3027 early_fixup(current_tag, NULL);
3028 as_fixup(current_tag);
3029
3030 tp = malloc(sizeof(*tp));
3031 if (!tp)
3032 memerr("gcide_markup_parse");
3033
3034 tp->textspace = textspace;
3035 tp->textsize = textsize;
3036
3037 tp->root = current_tag;
3038
3039 tag_fixup(tp->root, textspace);
3040 ws_fixup(tp->root);
3041
3042 return tp;
3043 }
3044
3045 void
3046 gcide_parse_tree_free(struct gcide_parse_tree *tp)
3047 {
3048 free(tp->textspace);
3049 free_tag(tp->root, NULL);
3050 free(tp);
3051 }
3052