[syslinux:master] zzjson: Adding sample module

syslinux-bot for Erwan Velu erwanaliasr1 at gmail.com
Mon Apr 25 15:27:57 PDT 2011


Commit-ID:  984ece2a8024d24967797904222629f5ec319dbc
Gitweb:     http://syslinux.zytor.com/commit/984ece2a8024d24967797904222629f5ec319dbc
Author:     Erwan Velu <erwanaliasr1 at gmail.com>
AuthorDate: Fri, 18 Mar 2011 22:41:15 +0100
Committer:  Erwan Velu <erwanaliasr1 at gmail.com>
CommitDate: Fri, 18 Mar 2011 22:41:15 +0100

zzjson: Adding sample module

Note, this module is lacking of the reading test as the ungetc isn't
available. At least, this first implementation consider that syslinux
needs more the output stuff than the input one.


---
 com32/modules/Makefile |    2 +-
 com32/modules/zzjson.c |  101 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletions(-)

diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 2d47913..8e061f7 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -22,7 +22,7 @@ MODULES	  = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \
 	    disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \
 	    meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \
 	    kbdmap.c32 cmd.c32 vpdtest.c32 host.c32 ls.c32 gpxecmd.c32 \
-	    ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32 whichsys.c32
+	    ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32 zzjson.c32 whichsys.c32
 
 TESTFILES =
 
diff --git a/com32/modules/zzjson.c b/com32/modules/zzjson.c
new file mode 100644
index 0000000..e2516fa
--- /dev/null
+++ b/com32/modules/zzjson.c
@@ -0,0 +1,101 @@
+/*
+ * Display directory contents
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <console.h>
+#include <string.h>
+#include <com32.h>
+#include <zzjson/zzjson.h>
+#include <stdarg.h>
+
+static void myerror(void *ehandle, const char *format, ...) {
+    va_list ap;
+    fprintf(ehandle, "error: ");
+    va_start(ap, format);
+    vfprintf(ehandle, format, ap);
+    va_end(ap);
+    fputc('\n', ehandle);
+}
+
+
+int main(int argc, char *argv[])
+{
+    openconsole(&dev_rawcon_r, &dev_stdcon_w);
+    (void) argc;
+    (void) argv;
+    ZZJSON  *tmp;
+    ZZJSON_CONFIG config = { ZZJSON_VERY_STRICT, NULL,
+                             (int(*)(void*)) fgetc,
+                             NULL,
+                             malloc, calloc, free, realloc,
+                             stderr, myerror, stdout,
+                             (int(*)(void*,const char*,...)) fprintf,
+                             (int(*)(int,void*)) fputc };
+    
+    do {
+        ZZJSON *tmp2;
+
+        tmp = zzjson_create_array(&config,
+                zzjson_create_number_d(&config, 3.14),
+                zzjson_create_number_i(&config, 1234LL),
+                zzjson_create_number_i(&config, -4321LL),
+                zzjson_create_true(&config),
+                zzjson_create_false(&config),
+                zzjson_create_null(&config),
+                zzjson_create_string(&config, "hello, world"),
+                zzjson_create_object(&config,
+                    "picard", zzjson_create_string(&config, "jean-luc"),
+                    "riker",  zzjson_create_string(&config, "william t."),
+                    NULL),
+                zzjson_create_object(&config, NULL),
+                zzjson_create_array(&config, NULL),
+                NULL );
+
+        if (!tmp) {
+            fprintf(stderr, "error during creation of json tree\n");
+            break;
+        }
+
+        tmp2 = zzjson_array_prepend(&config, tmp,
+                    zzjson_create_string(&config, "prepended string"));
+
+        if (!tmp2) {
+            fprintf(stderr, "error during prepend\n");
+            break;
+        }
+        tmp = tmp2;
+
+        tmp2 = zzjson_array_append(&config, tmp,
+                    zzjson_create_string(&config, "appended string (slow)"));
+
+        if (!tmp2) {
+            fprintf(stderr, "error during append\n");
+            break;
+        }
+        tmp = tmp2;
+
+        zzjson_print(&config, tmp);
+    } while(0);
+    if (tmp) zzjson_free(&config, tmp);
+
+    {
+        tmp = zzjson_create_array(&config, NULL); /* empty array */
+        tmp = zzjson_array_prepend(&config, tmp, zzjson_create_true(&config));
+        zzjson_print(&config, tmp);
+        zzjson_free(&config, tmp);
+    }
+
+    {
+        tmp = zzjson_create_object(&config, NULL); /* empty object */
+        tmp = zzjson_object_prepend(&config, tmp, "hello",
+                                zzjson_create_string(&config, "world"));
+        tmp = zzjson_object_append(&config, tmp, "goodbye",
+                                zzjson_create_string(&config, "cruel world"));
+        zzjson_print(&config, tmp);
+        zzjson_free(&config, tmp);
+    }
+
+    return 0;
+}
+  



More information about the Syslinux-commits mailing list