skip to main content

kiesler.at

a2html
updated by rck, 2004-10-10

a2html is a lex-program, which I wrote back in May 2004. I've encountered some problems while pasting JAVA-Sourcecode in phpWebSite, which hindered me on adding examples to my Tutorials. As I've been using Lex for another lecture of my study at the same time, I put it to good use here as well.

                     
1 | 2 | 3

Example

1 /*              a2html 0.6
2                 converts a given text-file to inline-html
3 
4                 http://www.kiesler.at/article113.html
5 */
6 
7 
8                 int col=0, line=1;
9                 int nums=1;             /* we want linenumbers in the output */
10                 char twochar[2]=" ";
11 
12 
13                 linenumber() {
14                         if(nums)
15                                 printf("<i>%d</i>&nbsp;", line);
16                 }
17 
18 
19                 print(char *s) {
20 
21                         if(col==0) {
22                                 printf("<tt>");
23                                 linenumber();
24                         }
25 
26                         col++;
27 
28                         printf("%s", s);
29                 }
30 
31 
32 /* html */
33 
34 AMP             [\&]
35 LT              [\<]
36 GT              [\>]
37 
38 
39 /* template engine */
40 
41 CUROP           [\{]
42 CURCL           [\}]
43 
44 
45 /* bbcode */
46 
47 SQOP            [\[]
48 SQCL            [\]]
49 
50 
51 /* smilies */
52 
53 SMILIE1         \:\D
54 SMILIE2         \:\]
55 SMILIE3         \:\(
56 SMILIE4         \:\o
57 SMILIE5         \O
58 SMILIE6         \:\?
59 SMILIE7         \)
60 SMILIE8         \:\x
61 SMILIE9         \:\|
62 SMILIE10        \:\P
63 
64 
65 /* white space */
66 
67 SPACE           [ ]
68 TAB             \t
69 NEWLINE         \n
70 ANY             .
71 
72 
73 %%
74 
75 
76 
77 {AMP}           print("&amp;");
78 {LT}            print("&lt;");
79 {GT}            print("&gt;");
80 
81 {CUROP}         print("<i></i>{<i></i>");
82 {CURCL}         print("<i></i>}<i></i>");
83 
84 {SQOP}          print("<i></i>[<i></i>");
85 {SQCL}          print("<i></i>]<i></i>");
86 
87 {SMILIE1}       print("<i></i>:<i></i>D<i></i>");
88 {SMILIE2}       print("<i></i>:<i></i>)<i></i>");
89 {SMILIE3}       print("<i></i>:<i></i>(<i></i>");
90 {SMILIE4}       print("<i></i>:<i></i>o<i></i>");
91 {SMILIE5}       print("<i></i>8<i></i>O<i></i>");
92 {SMILIE6}       print("<i></i>:<i></i>?<i></i>");
93 {SMILIE7}       print("<i></i>8<i></i>)<i></i>");
94 {SMILIE8}       print("<i></i>:<i></i>x<i></i>");
95 {SMILIE9}       print("<i></i>:<i></i>|<i></i>");
96 {SMILIE10}      print("<i></i>:<i></i>P<i></i>");
97 
98 {SPACE}         print("&nbsp;");
99 
100 
101 {TAB}           {       print("&nbsp;");
102 
103                         while((col % 8) != 0) {
104                                 printf("&nbsp;");
105                                 col++;
106                         }
107                 }
108 
109 
110 {NEWLINE}       {
111                         if(col!=0)
112                                 printf("</tt>");
113                         else
114                         if(nums) {
115                                 printf("<tt>");
116                                 linenumber("</tt>");
117                                 printf("</tt>");
118                         }
119 
120                         col=0; line++;
121                         printf("<br />\n");
122                 }
123 
124 
125 {ANY}           print(yytext);
126 
127 
128 
129 %%
130 
131 
132                 main(int argc, char **argv) {
133                         yyin=argc>1? fopen(argv[1], "r") : stdin;
134 
135                         printf("<p>");
136 
137                         yylex();
138 
139                         if(col!=0)
140                                 printf("</tt>\n");
141 
142                         printf("</p>");
143 
144                         exit(0);
145                 }

                     
1 | 2 | 3



RSSComments - Make a comment
The comments are owned by the poster. We are not responsible for its content.
RSSAll Articles
2008, 2007, 2006, 2005, 2004

Latest Updates

AdministrativeTexts
updated by freddiemac1993, 2013-06-14
wiki

Re: adventures
created by brittdavis10, 2012-02-23 (1 rply, 3 views)
thread

Re: how to run phpwebsite...
created by alexander, 2011-08-25 (2 rpls, 3607 views)
thread

Re: Forum tags
created by HaroldFaragher, 2011-08-22 (3 rpls, 8488 views)
thread


Zu den KO2100 Foren