From f1424bf3264203c80b0af4a520deb82a760977df Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 9 Feb 2015 23:58:33 -0700 Subject: add liblaxjson package --- index.html | 4 +++ src/liblaxjson-test.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/liblaxjson.mk | 30 ++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 src/liblaxjson-test.c create mode 100644 src/liblaxjson.mk diff --git a/index.html b/index.html index 32cdb8a..5a051f4 100644 --- a/index.html +++ b/index.html @@ -1726,6 +1726,10 @@ local-pkg-list: $(LOCAL_PKG_LIST) libircclient + liblaxjson + liblaxjson + + liblo liblo diff --git a/src/liblaxjson-test.c b/src/liblaxjson-test.c new file mode 100644 index 0000000..dae2b9d --- /dev/null +++ b/src/liblaxjson-test.c @@ -0,0 +1,87 @@ +/* + * This file is part of MXE. + * See index.html for further information. + */ + +/* + * Copyright (c) 2013 Andrew Kelley + * + * This file is part of liblaxjson, which is MIT licensed. + * See http://opensource.org/licenses/MIT + */ + +#include +#include + +static int on_string(struct LaxJsonContext *context, + enum LaxJsonType type, const char *value, int length) +{ + (void)context; + (void)length; + char *type_name = (type == LaxJsonTypeProperty) ? "property" : "string"; + printf("%s: %s\n", type_name, value); + return 0; +} + +static int on_number(struct LaxJsonContext *context, double x) +{ + (void)context; + printf("number: %f\n", x); + return 0; +} + +static int on_primitive(struct LaxJsonContext *context, enum LaxJsonType type) +{ + (void)context; + char *type_name; + if (type == LaxJsonTypeTrue) + type_name = "true"; + else if (type == LaxJsonTypeFalse) + type_name = "false"; + else + type_name = "null"; + + printf("primitive: %s\n", type_name); + return 0; +} + +static int on_begin(struct LaxJsonContext *context, enum LaxJsonType type) +{ + (void)context; + char *type_name = (type == LaxJsonTypeArray) ? "array" : "object"; + printf("begin %s\n", type_name); + return 0; +} + +static int on_end(struct LaxJsonContext *context, enum LaxJsonType type) +{ + (void)context; + char *type_name = (type == LaxJsonTypeArray) ? "array" : "object"; + printf("end %s\n", type_name); + return 0; +} + +int main() { + char buf[1024]; + struct LaxJsonContext *context; + FILE *f; + int amt_read; + + context = lax_json_create(); + + context->userdata = NULL; /* can set this to whatever you want */ + context->string = on_string; + context->number = on_number; + context->primitive = on_primitive; + context->begin = on_begin; + context->end = on_end; + + f = fopen("file.json", "rb"); + while ((amt_read = fread(buf, 1, sizeof(buf), f))) { + lax_json_feed(context, amt_read, buf); + } + lax_json_destroy(context); + + return 0; +} + diff --git a/src/liblaxjson.mk b/src/liblaxjson.mk new file mode 100644 index 0000000..72621fd --- /dev/null +++ b/src/liblaxjson.mk @@ -0,0 +1,30 @@ +# This file is part of MXE. +# See index.html for further information. + +PKG := liblaxjson +$(PKG)_IGNORE := +$(PKG)_VERSION := 1.0.3 +$(PKG)_CHECKSUM := 9e00362429d98d043c02ae726fd507abbc2ca9cc +$(PKG)_SUBDIR := liblaxjson-$($(PKG)_VERSION) +$(PKG)_FILE := $(PKG)-$($(PKG)_VERSION).tar.gz +$(PKG)_URL := https://github.com/andrewrk/liblaxjson/archive/$($(PKG)_VERSION).tar.gz +$(PKG)_DEPS := gcc + +define $(PKG)_UPDATE + $(WGET) -q -O- 'https://github.com/andrewrk/liblaxjson/releases' | \ + $(SED) -n 's,.*/archive/\([0-9][^>]*\)\.tar.*,\1,p' | \ + head -1 +endef + +define $(PKG)_BUILD + mkdir '$(1)/build' + cd '$(1)/build' && cmake .. \ + -DCMAKE_TOOLCHAIN_FILE='$(CMAKE_TOOLCHAIN_FILE)' + + $(MAKE) -C '$(1)/build' -j '$(JOBS)' install + + '$(TARGET)-gcc' \ + -W -Wall -Werror -ansi -pedantic -std=c99 \ + '$(2).c' -o '$(PREFIX)/$(TARGET)/bin/test-liblaxjson.exe' \ + -llaxjson +endef -- cgit v0.12