diff options
Diffstat (limited to 'xs_html.h')
| -rw-r--r-- | xs_html.h | 39 |
1 files changed, 13 insertions, 26 deletions
| @@ -42,10 +42,8 @@ typedef enum { | |||
| 42 | struct xs_html { | 42 | struct xs_html { |
| 43 | xs_html_type type; | 43 | xs_html_type type; |
| 44 | xs_str *content; | 44 | xs_str *content; |
| 45 | xs_html *f_attr; | 45 | xs_html *attrs; |
| 46 | xs_html *l_attr; | 46 | xs_html *tags; |
| 47 | xs_html *f_tag; | ||
| 48 | xs_html *l_tag; | ||
| 49 | xs_html *next; | 47 | xs_html *next; |
| 50 | }; | 48 | }; |
| 51 | 49 | ||
| @@ -140,25 +138,14 @@ xs_html *_xs_html_add(xs_html *tag, xs_html *var[]) | |||
| 140 | while (*var) { | 138 | while (*var) { |
| 141 | xs_html *data = *var++; | 139 | xs_html *data = *var++; |
| 142 | 140 | ||
| 143 | xs_html **first; | ||
| 144 | xs_html **last; | ||
| 145 | |||
| 146 | if (data->type == XS_HTML_ATTR) { | 141 | if (data->type == XS_HTML_ATTR) { |
| 147 | first = &tag->f_attr; | 142 | data->next = tag->attrs; |
| 148 | last = &tag->l_attr; | 143 | tag->attrs = data; |
| 149 | } | 144 | } |
| 150 | else { | 145 | else { |
| 151 | first = &tag->f_tag; | 146 | data->next = tag->tags; |
| 152 | last = &tag->l_tag; | 147 | tag->tags = data; |
| 153 | } | 148 | } |
| 154 | |||
| 155 | if (*first == NULL) | ||
| 156 | *first = data; | ||
| 157 | |||
| 158 | if (*last != NULL) | ||
| 159 | (*last)->next = data; | ||
| 160 | |||
| 161 | *last = data; | ||
| 162 | } | 149 | } |
| 163 | 150 | ||
| 164 | return tag; | 151 | return tag; |
| @@ -206,17 +193,20 @@ void xs_html_render_f(xs_html *h, FILE *f) | |||
| 206 | if (h == NULL) | 193 | if (h == NULL) |
| 207 | return; | 194 | return; |
| 208 | 195 | ||
| 196 | /* follow the chain */ | ||
| 197 | xs_html_render_f(h->next, f); | ||
| 198 | |||
| 209 | switch (h->type) { | 199 | switch (h->type) { |
| 210 | case XS_HTML_TAG: | 200 | case XS_HTML_TAG: |
| 211 | fprintf(f, "<%s", h->content); | 201 | fprintf(f, "<%s", h->content); |
| 212 | 202 | ||
| 213 | /* attributes */ | 203 | /* attributes */ |
| 214 | xs_html_render_f(h->f_attr, f); | 204 | xs_html_render_f(h->attrs, f); |
| 215 | 205 | ||
| 216 | fprintf(f, ">"); | 206 | fprintf(f, ">"); |
| 217 | 207 | ||
| 218 | /* sub-tags */ | 208 | /* sub-tags */ |
| 219 | xs_html_render_f(h->f_tag, f); | 209 | xs_html_render_f(h->tags, f); |
| 220 | 210 | ||
| 221 | fprintf(f, "</%s>", h->content); | 211 | fprintf(f, "</%s>", h->content); |
| 222 | break; | 212 | break; |
| @@ -225,14 +215,14 @@ void xs_html_render_f(xs_html *h, FILE *f) | |||
| 225 | fprintf(f, "<%s", h->content); | 215 | fprintf(f, "<%s", h->content); |
| 226 | 216 | ||
| 227 | /* attributes */ | 217 | /* attributes */ |
| 228 | xs_html_render_f(h->f_attr, f); | 218 | xs_html_render_f(h->attrs, f); |
| 229 | 219 | ||
| 230 | fprintf(f, "/>"); | 220 | fprintf(f, "/>"); |
| 231 | break; | 221 | break; |
| 232 | 222 | ||
| 233 | case XS_HTML_CONTAINER: | 223 | case XS_HTML_CONTAINER: |
| 234 | /* sub-tags */ | 224 | /* sub-tags */ |
| 235 | xs_html_render_f(h->f_tag, f); | 225 | xs_html_render_f(h->tags, f); |
| 236 | break; | 226 | break; |
| 237 | 227 | ||
| 238 | case XS_HTML_ATTR: | 228 | case XS_HTML_ATTR: |
| @@ -244,9 +234,6 @@ void xs_html_render_f(xs_html *h, FILE *f) | |||
| 244 | break; | 234 | break; |
| 245 | } | 235 | } |
| 246 | 236 | ||
| 247 | /* follow the chain */ | ||
| 248 | xs_html_render_f(h->next, f); | ||
| 249 | |||
| 250 | xs_free(h->content); | 237 | xs_free(h->content); |
| 251 | xs_free(h); | 238 | xs_free(h); |
| 252 | } | 239 | } |