1 %{
2 /*
3 * Copyright (c) 2015, Carsten Kunze
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28 #include <string.h>
29 #include "dhtml.h"
30 #include "tr_out.h"
31 #include "char.h"
32 #include "main.h"
33 static int i0;
34 %}
35 %x X FONT_NUM FONT_NAM T X_X LINK ULINK ANCHOR
36 WS [ ]
37 NWS [^ \n]
38 %%
39 <X>f{NWS}*{WS}+ { BEGIN FONT_NUM; }
40 <X>T{NWS}*{WS}+ { BEGIN T; }
41 <X>X{NWS}*{WS}+ { BEGIN X_X; }
42 <X>[^fTX].* { BEGIN 0; }
43 <FONT_NUM>[0-9]+{WS}+ { i0 = atoi(yytext);
44 BEGIN FONT_NAM; }
45 <FONT_NAM>{NWS}+ { out_x_f(i0, yytext);
46 BEGIN 0; }
47 <T>{NWS}+ { out_x_T(yytext);
48 BEGIN 0; }
49 <X_X>Link{WS}+ { BEGIN LINK; }
50 <X_X>ULink{WS}+ { BEGIN ULINK; }
51 <X_X>U?Link{WS}*\n { out_end_link();
52 BEGIN 0; }
53 <X_X>Anchor{WS}+ { BEGIN ANCHOR; }
54 <X_X>LC_TYPE.* { BEGIN 0; }
55 <X_X>[^AL].* { BEGIN 0; }
56 <LINK>.+ { out_begin_link(yytext);
57 BEGIN 0; }
58 <ULINK>.+ { out_begin_ulink(yytext);
59 BEGIN 0; }
60 <ANCHOR>.+ { out_anchor(yytext);
61 BEGIN 0; }
62 c. { char_c(yytext[1]); }
63 [0-9][0-9]. { char_c(yytext[2]); }
64 C{NWS}+ { char_C(yytext+1); }
65 w { out_w(); }
66 H-?[0-9]+ { ; }
67 h-?[0-9]+ { out_h(atoi(yytext+1)); }
68 V-?[0-9]+ { out_V(atoi(yytext+1)); }
69 v-?[0-9]+ { fprintf(stderr, "Ignore v %s\n", yytext+1); }
70 f[0-9]+ { out_f(atoi(yytext+1)); }
71 N[0-9]+ { char_N(atoi(yytext+1)); }
72 n[0-9]+{WS}+[0-9]+ { out_n(atoi(yytext+1)); }
73 s[0-9]+ { out_s(atoi(yytext+1)); }
74 p[0-9]+ { ; }
75 x{WS}+ { BEGIN X; }
76 D.+ { ; }
77 \n { ; }
78 . { fprintf(stderr, "Ignore '%c'\n", *yytext); }
79 %%
80 int
81 yywrap(void) {
82 return 1;
83 }
84 void
run_lex(void)85 run_lex(void) {
86 yylex();
87 }
88