]> saetta.ns0.it Git - libzakcgi/commitdiff
Added ZakCgiTag::text and ::file (refs #945).
authorAndrea Zagli <azagli@libero.it>
Mon, 27 Jul 2015 19:09:07 +0000 (21:09 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 27 Jul 2015 19:09:07 +0000 (21:09 +0200)
src/tag.c
src/tag.h
tests/tag.c

index 65116583cc9ec4208c7b85d9fcf7da1ee90abd1c..1abe847f85227e5b209849b7f19de764285b7850 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
 
 #include "tag.h"
 
+static GPtrArray
+*zak_cgi_tag_valist_to_gptrarray (va_list ap)
+{
+       GPtrArray *ret;
+
+       gchar *attr;
+
+       ret = g_ptr_array_new ();
+
+       do
+               {
+                       attr = va_arg (ap, gchar *);
+                       if (attr != NULL)
+                               {
+                                       g_ptr_array_add (ret, g_strdup (attr));
+                               }
+                       else
+                               {
+                                       break;
+                               }
+               } while (TRUE);
+       va_end (ap);
+
+       return ret;
+}
+
 static gchar
-*zak_cgi_tag_tag_valist (const gchar *name,
-                                                const gchar *id,
-                                                va_list ap)
+*zak_cgi_tag_tag_attrs (const gchar *name,
+                                               const gchar *id,
+                                               GPtrArray *ar_attrs)
 {
        gchar *ret;
        GString *str;
 
+       guint i;
+       guint l;
+
        gboolean with_name;
        gboolean with_content;
 
@@ -49,12 +78,13 @@ static gchar
                                                        name,
                                                        id);
 
-       do
+       l = ar_attrs->len;
+       for (i = 0; i < l; i++)
                {
-                       attr = va_arg (ap, gchar *);
+                       attr = g_ptr_array_index (ar_attrs, i);
                        if (attr != NULL)
                                {
-                                       attr_val = va_arg (ap, gchar *);
+                                       attr_val = g_ptr_array_index (ar_attrs, ++i);
                                        if (attr_val != NULL)
                                                {
                                                        if (g_strcmp0 (attr, "content") == 0)
@@ -89,8 +119,7 @@ static gchar
                                {
                                        break;
                                }
-               } while (TRUE);
-       va_end (ap);
+               }
 
        if (!with_name)
                {
@@ -134,7 +163,7 @@ gchar
 
        va_start (ap, id);
 
-       return zak_cgi_tag_tag_valist (name, id, ap);
+       return zak_cgi_tag_tag_attrs (name, id, zak_cgi_tag_valist_to_gptrarray (ap));
 }
 
 /**
@@ -152,5 +181,51 @@ gchar
 
        va_start (ap, id);
 
-       return zak_cgi_tag_tag_valist ("img", id, ap);
+       return zak_cgi_tag_tag_attrs ("img", id, zak_cgi_tag_valist_to_gptrarray (ap));
+}
+
+/**
+ * zak_cgi_tag_text:
+ * @name:
+ * @id:
+ *
+ * Returns:
+ */
+gchar
+*zak_cgi_tag_text (const gchar *id,
+                                  ...)
+{
+       GPtrArray *ar;
+       va_list ap;
+
+       va_start (ap, id);
+
+       ar = zak_cgi_tag_valist_to_gptrarray (ap);
+       g_ptr_array_add (ar, "type");
+       g_ptr_array_add (ar, "text");
+
+       return zak_cgi_tag_tag_attrs ("input", id, ar);
+}
+
+/**
+ * zak_cgi_tag_file:
+ * @name:
+ * @id:
+ *
+ * Returns:
+ */
+gchar
+*zak_cgi_tag_file (const gchar *id,
+                                  ...)
+{
+       GPtrArray *ar;
+       va_list ap;
+
+       va_start (ap, id);
+
+       ar = zak_cgi_tag_valist_to_gptrarray (ap);
+       g_ptr_array_add (ar, "type");
+       g_ptr_array_add (ar, "file");
+
+       return zak_cgi_tag_tag_attrs ("input", id, ar);
 }
index 5e29a3f9a03c1069bf682b310595974423f2bc2b..3a22f70b749b6f3fd30526eedbd9ae948a9b38ad 100644 (file)
--- a/src/tag.h
+++ b/src/tag.h
@@ -32,5 +32,11 @@ gchar *zak_cgi_tag_tag (const gchar *name,
 gchar *zak_cgi_tag_img (const gchar *id,
                                                ...);
 
+gchar *zak_cgi_tag_text (const gchar *id,
+                                                ...);
+
+gchar *zak_cgi_tag_file (const gchar *id,
+                                                ...);
+
 
 #endif /* __ZAK_CGI_TAG_H__ */
index 5999391d539c18e7ea97a4b51b20a2462006450b..2cbf68cdaea8cbf0b4e99f903b0e39ce7bfb2921 100644 (file)
@@ -29,5 +29,7 @@ main (int argc, char *argv[])
 
        g_message ("%s", zak_cgi_tag_img ("theimage", "src", "pippo.png", NULL));
 
+       g_message ("%s", zak_cgi_tag_text ("thetext", NULL));
+
        return 0;
 }