]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/mothra/html.h
exec(2): fix prototypes
[plan9front.git] / sys / src / cmd / mothra / html.h
1 /*
2  * Parameters
3  */
4 #define NSTACK  100     /* html grammar is not recursive, so 30 or so should do */
5 #define NHBUF   8192    /* Input buffer size */
6 #define NPEEKC  3       /* Maximum lookahead */
7 #define NTOKEN  4096    /* Maximum token length */
8 #define NATTR   512     /* Maximum number of attributes of a tag */
9 typedef struct Pair Pair;
10 typedef struct Tag Tag;
11 typedef struct Stack Stack;
12 typedef struct Hglob Hglob;
13 typedef struct Form Form;
14 typedef struct Entity Entity;
15 struct Pair{
16         char *name;
17         char *value;
18 };
19 struct Entity{
20         char *name;
21         Rune value;
22 };
23 struct Tag{
24         char *name;
25         int action;
26 };
27 struct Stack{
28         int tag;                /* html tag being processed */
29         int pre;                /* in preformatted text? */
30         int font;               /* typeface */
31         int size;               /* point size of text */
32         int margin;             /* left margin position */
33         int indent;             /* extra indent at paragraph start */
34         int number;             /* paragraph number */
35         int ismap;              /* flag of <img> */
36         int isscript;           /* inside <script> */
37         int strike;             /* flag of <strike> */
38         int width;              /* size of image */
39         int height;
40         char image[NNAME];      /* arg of <img> */
41         char link[NNAME];       /* arg of <a href=...> */
42         char name[NNAME];       /* arg of <a name=...> */
43 };
44
45 /*
46  * Globals -- these are packed up into a struct that gets passed around
47  * so that multiple parsers can run concurrently
48  */
49 struct Hglob{
50         char *tp;               /* pointer in text buffer */
51         char *name;             /* input file name */
52         int hfd;                /* input file descriptor */
53         char hbuf[NHBUF];       /* input buffer */
54         char *hbufp;            /* next character in buffer */
55         char *ehbuf;            /* end of good characters in buffer */
56         int heof;               /* end of file flag */
57         int peekc[NPEEKC];      /* characters to re-read */
58         int npeekc;             /* # of characters to re-read */
59         char token[NTOKEN];     /* if token type is TEXT */
60         Pair attr[NATTR];       /* tag attribute/value pairs */
61         int nsp;                /* # of white-space characters before TEXT token */
62         int spacc;              /* place to accumulate more spaces */
63                                 /* if negative, won't accumulate! */
64         int tag;                /* if token type is TAG or END */
65         Stack stack[NSTACK];    /* parse stack */
66         Stack *state;           /* parse stack pointer */
67         int lineno;             /* input line number */
68         int linebrk;            /* flag set if we require a line-break in output */
69         int para;               /* flag set if we need an indent at the break */
70         char *text;             /* text buffer */
71         char *etext;            /* end of text buffer */
72         Form *form;             /* data for form under construction */
73         Www *dst;               /* where the text goes */
74 };
75
76 /*
77  * Token types
78  */
79 enum{
80         TAG=1,
81         ENDTAG,
82         TEXT,
83 };
84
85 /*
86  * Magic characters corresponding to
87  *      literal < followed by / ! or alpha,
88  *      literal > and
89  *      end of file
90  */
91 #define STAG    65536
92 #define ETAG    65537
93 #define EOF     -1
94
95 /*
96  * fonts
97  */
98 enum{
99         ROMAN,
100         ITALIC,
101         BOLD,
102         CWIDTH,
103 };
104
105 /*
106  * font sizes
107  */
108 enum{
109         SMALL,
110         NORMAL,
111         LARGE,
112         ENORMOUS,
113 };
114
115 /*
116  * length direction
117  */
118 enum{
119         HORIZ,
120         VERT,
121 };
122 int strtolength(Hglob *g, int dir, char *str);
123
124 /*
125  * Token names for the html parser.
126  * Tag_end corresponds to </end> tags.
127  * Tag_text tags text not in a tag.
128  * Those two must follow the others.
129  */
130 enum{
131         Tag_comment,
132
133         Tag_a,
134         Tag_abbr,
135         Tag_acronym,
136         Tag_address,
137         Tag_applet,
138         Tag_audio,
139         Tag_b,
140         Tag_base,
141         Tag_blockquot,
142         Tag_body,
143         Tag_br,
144         Tag_button,
145         Tag_center,
146         Tag_cite,
147         Tag_code,
148         Tag_dd,
149         Tag_del,
150         Tag_div,
151         Tag_dfn,
152         Tag_dir,
153         Tag_dl,
154         Tag_dt,
155         Tag_em,
156         Tag_embed,
157         Tag_font,
158         Tag_form,
159         Tag_frame,      /* rm 5.8.97 */
160         Tag_h1,
161         Tag_h2,
162         Tag_h3,
163         Tag_h4,
164         Tag_h5,
165         Tag_h6,
166         Tag_head,
167         Tag_hr,
168         Tag_html,
169         Tag_i,
170         Tag_iframe,
171         Tag_img,
172         Tag_input,
173         Tag_ins,
174         Tag_isindex,
175         Tag_kbd,
176         Tag_key,
177         Tag_li,
178         Tag_link,
179         Tag_listing,
180         Tag_menu,
181         Tag_meta,
182         Tag_nextid,
183         Tag_object,
184         Tag_ol,
185         Tag_option,
186         Tag_p,
187         Tag_plaintext,
188         Tag_pre,
189         Tag_s,
190         Tag_samp,
191         Tag_script,
192         Tag_select,
193         Tag_span,
194         Tag_strike,
195         Tag_strong,
196         Tag_style,
197         Tag_source,
198         Tag_table,      /* rm 3.8.00 */
199         Tag_td,
200         Tag_textarea,
201         Tag_title,
202         Tag_tr,
203         Tag_tt,
204         Tag_u,
205         Tag_ul,
206         Tag_var,
207         Tag_video,
208         Tag_wbr,
209         Tag_xmp,
210
211         Tag_end,        /* also used to indicate unrecognized start tag */
212         Tag_text,
213 };
214 enum{
215         NTAG=Tag_end,
216         END=1,  /* tag must have a matching end tag */
217         NOEND,  /* tag must not have a matching end tag */
218         OPTEND, /* tag may have a matching end tag */
219         ERR,            /* tag must not occur */
220 };
221 Tag tag[];
222 void rdform(Hglob *);
223 void endform(Hglob *);
224 char *pl_getattr(Pair *, char *);
225 int pl_hasattr(Pair *, char *);
226 void pl_htmloutput(Hglob *, int, char *, Field *);