]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/mothra/html.h
mothra: fix alt display resizing, filter control characters in panel entries, use...
[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  1024    /* 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 width;              /* size of image */
37         int height;
38         int     table;          /* depth of table nesting */
39         char image[NNAME];      /* arg of <img> */
40         char link[NNAME];       /* arg of <a href=...> */
41         char name[NNAME];       /* arg of <a name=...> */
42 };
43
44 /*
45  * Globals -- these are packed up into a struct that gets passed around
46  * so that multiple parsers can run concurrently
47  */
48 struct Hglob{
49         char *tp;               /* pointer in text buffer */
50         char *name;             /* input file name */
51         int hfd;                /* input file descriptor */
52         char hbuf[NHBUF];       /* input buffer */
53         char *hbufp;            /* next character in buffer */
54         char *ehbuf;            /* end of good characters in buffer */
55         int heof;               /* end of file flag */
56         int peekc[NPEEKC];      /* characters to re-read */
57         int npeekc;             /* # of characters to re-read */
58         char token[NTOKEN];     /* if token type is TEXT */
59         Pair attr[NATTR];       /* tag attribute/value pairs */
60         int nsp;                /* # of white-space characters before TEXT token */
61         int spacc;              /* place to accumulate more spaces */
62                                 /* if negative, won't accumulate! */
63         int tag;                /* if token type is TAG or END */
64         Stack stack[NSTACK];    /* parse stack */
65         Stack *state;           /* parse stack pointer */
66         int lineno;             /* input line number */
67         int linebrk;            /* flag set if we require a line-break in output */
68         int para;               /* flag set if we need an indent at the break */
69         char *text;             /* text buffer */
70         char *etext;            /* end of text buffer */
71         Form *form;             /* data for form under construction */
72         Www *dst;               /* where the text goes */
73 };
74
75 /*
76  * Token types
77  */
78 enum{
79         TAG=1,
80         ENDTAG,
81         TEXT,
82 };
83
84 /*
85  * Magic characters corresponding to
86  *      literal < followed by / ! or alpha,
87  *      literal > and
88  *      end of file
89  */
90 #define STAG    65536
91 #define ETAG    65537
92 #define EOF     -1
93
94 /*
95  * fonts
96  */
97 enum{
98         ROMAN,
99         ITALIC,
100         BOLD,
101         CWIDTH,
102 };
103
104 /*
105  * font sizes
106  */
107 enum{
108         SMALL,
109         NORMAL,
110         LARGE,
111         ENORMOUS,
112 };
113
114 /*
115  * Token names for the html parser.
116  * Tag_end corresponds to </end> tags.
117  * Tag_text tags text not in a tag.
118  * Those two must follow the others.
119  */
120 enum{
121         Tag_comment,
122         Tag_a,
123         Tag_address,
124         Tag_b,
125         Tag_base,
126         Tag_blockquot,
127         Tag_body,
128         Tag_br,
129         Tag_button,
130         Tag_center,
131         Tag_cite,
132         Tag_code,
133         Tag_dd,
134         Tag_dfn,
135         Tag_dir,
136         Tag_dl,
137         Tag_dt,
138         Tag_em,
139         Tag_font,
140         Tag_form,
141         Tag_h1,
142         Tag_h2,
143         Tag_h3,
144         Tag_h4,
145         Tag_h5,
146         Tag_h6,
147         Tag_head,
148         Tag_hr,
149         Tag_html,
150         Tag_i,
151         Tag_img,
152         Tag_input,
153         Tag_isindex,
154         Tag_kbd,
155         Tag_key,
156         Tag_li,
157         Tag_link,
158         Tag_listing,
159         Tag_menu,
160         Tag_meta,
161         Tag_nextid,
162         Tag_ol,
163         Tag_option,
164         Tag_p,
165         Tag_plaintext,
166         Tag_pre,
167         Tag_samp,
168         Tag_select,
169         Tag_strong,
170         Tag_textarea,
171         Tag_title,
172         Tag_tt,
173         Tag_u,
174         Tag_ul,
175         Tag_var,
176         Tag_xmp,
177         Tag_frame,      /* rm 5.8.97 */
178         Tag_table,      /* rm 3.8.00 */
179         Tag_td,
180         Tag_tr,
181         Tag_script,
182         Tag_style,
183         Tag_end,        /* also used to indicate unrecognized start tag */
184
185         Tag_text,
186 };
187 enum{
188         NTAG=Tag_end,
189         END=1,  /* tag must have a matching end tag */
190         NOEND,  /* tag must not have a matching end tag */
191         OPTEND, /* tag may have a matching end tag */
192         ERR,            /* tag must not occur */
193 };
194 Tag tag[];
195 void rdform(Hglob *);
196 void endform(Hglob *);
197 char *pl_getattr(Pair *, char *);
198 int pl_hasattr(Pair *, char *);
199 void pl_htmloutput(Hglob *, int, char *, Field *);