commit 8bdebf2

default  ·  2023-12-08 05:13:08 +0000 UTC
parent ce0e782
Backport from xs.
2 files changed,  +14, -27
+13, -26
 1@@ -42,10 +42,8 @@ typedef enum {
 2 struct xs_html {
 3     xs_html_type type;
 4     xs_str *content;
 5-    xs_html *f_attr;
 6-    xs_html *l_attr;
 7-    xs_html *f_tag;
 8-    xs_html *l_tag;
 9+    xs_html *attrs;
10+    xs_html *tags;
11     xs_html *next;
12 };
13 
14@@ -140,25 +138,14 @@ xs_html *_xs_html_add(xs_html *tag, xs_html *var[])
15     while (*var) {
16         xs_html *data = *var++;
17 
18-        xs_html **first;
19-        xs_html **last;
20-
21         if (data->type == XS_HTML_ATTR) {
22-            first = &tag->f_attr;
23-            last  = &tag->l_attr;
24+            data->next = tag->attrs;
25+            tag->attrs = data;
26         }
27         else {
28-            first = &tag->f_tag;
29-            last  = &tag->l_tag;
30+            data->next = tag->tags;
31+            tag->tags = data;
32         }
33-
34-        if (*first == NULL)
35-            *first = data;
36-
37-        if (*last != NULL)
38-            (*last)->next = data;
39-
40-        *last = data;
41     }
42 
43     return tag;
44@@ -206,17 +193,20 @@ void xs_html_render_f(xs_html *h, FILE *f)
45     if (h == NULL)
46         return;
47 
48+    /* follow the chain */
49+    xs_html_render_f(h->next, f);
50+
51     switch (h->type) {
52     case XS_HTML_TAG:
53         fprintf(f, "<%s", h->content);
54 
55         /* attributes */
56-        xs_html_render_f(h->f_attr, f);
57+        xs_html_render_f(h->attrs, f);
58 
59         fprintf(f, ">");
60 
61         /* sub-tags */
62-        xs_html_render_f(h->f_tag, f);
63+        xs_html_render_f(h->tags, f);
64 
65         fprintf(f, "</%s>", h->content);
66         break;
67@@ -225,14 +215,14 @@ void xs_html_render_f(xs_html *h, FILE *f)
68         fprintf(f, "<%s", h->content);
69 
70         /* attributes */
71-        xs_html_render_f(h->f_attr, f);
72+        xs_html_render_f(h->attrs, f);
73 
74         fprintf(f, "/>");
75         break;
76 
77     case XS_HTML_CONTAINER:
78         /* sub-tags */
79-        xs_html_render_f(h->f_tag, f);
80+        xs_html_render_f(h->tags, f);
81         break;
82 
83     case XS_HTML_ATTR:
84@@ -244,9 +234,6 @@ void xs_html_render_f(xs_html *h, FILE *f)
85         break;
86     }
87 
88-    /* follow the chain */
89-    xs_html_render_f(h->next, f);
90-
91     xs_free(h->content);
92     xs_free(h);
93 }
+1, -1
1@@ -1 +1 @@
2-/* 1b21549513460489504a2caa4127607c914a10da 2023-12-03T23:45:32+01:00 */
3+/* 3582ff265e19407df1d532eb1d90c372fe22ca62 2023-12-08T06:10:40+01:00 */