Permalink
Browse files

import of version 0.1

git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@2 327403b1-1117-474d-bef2-5cb71233fd97
  • Loading branch information...
1 parent 6d59966 commit f0d08887b857fce1fe95a68d29eb7a07cd527d7c @michaeljclark michaeljclark committed Mar 13, 2007
Showing with 3,750 additions and 0 deletions.
  1. +1,153 −0 Doxyfile
  2. +40 −0 Makefile
  3. +32 −0 README.html
  4. +94 −0 arraylist.c
  5. +52 −0 arraylist.h
  6. +38 −0 bits.h
  7. +75 −0 debug.c
  8. +33 −0 debug.h
  9. +30 −0 json.h
  10. +493 −0 json_object.c
  11. +300 −0 json_object.h
  12. +25 −0 json_object_private.h
  13. +426 −0 json_tokener.c
  14. +70 −0 json_tokener.h
  15. +79 −0 json_util.c
  16. +13 −0 json_util.h
  17. +225 −0 linkhash.c
  18. +270 −0 linkhash.h
  19. +106 −0 printbuf.c
  20. +43 −0 printbuf.h
  21. +134 −0 test1.c
  22. +19 −0 test2.c
View
1,153 Doxyfile

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,40 @@
+# $Id: Makefile,v 1.4 2004/07/22 01:37:44 mclark Exp $
+
+CFLAGS += -g -Wall -std=gnu99 -D_GNU_SOURCE -D_REENTRANT
+LDFLAGS +=
+LDLIBS +=
+
+LIB_OBJS = debug.o \
+ linkhash.o \
+ printbuf.o \
+ arraylist.o \
+ json_object.o \
+ json_tokener.o
+
+LIB_HDRS = debug.h \
+ linkhash.h \
+ printbuf.h \
+ arraylist.h \
+ json_object.h \
+ json_tokener.h
+
+TESTS = test1 test2
+
+all: tests
+
+tests: $(TESTS)
+test1: test1.o $(LIB_OBJS)
+test2: test2.o $(LIB_OBJS)
+
+clean:
+ rm -f *.o *~ $(TESTS)
+
+cex.o: cex.c cex.h
+debug.o: debug.c debug.h
+linkhash.o: linkhash.c linkhash.h
+arraylist.o: arraylist.c arraylist.h
+json_object.o: json_object.c $(LIB_HDRS)
+json_tokener.o: json_tokener.c $(LIB_HDRS)
+test1.o: test1.c $(LIB_HDRS)
+test2.o: test2.c $(LIB_HDRS)
+
View
@@ -0,0 +1,32 @@
+<h2>JSON-C - A JSON implementation in C</h2>
+<p>Latest release: <a href="json-c-0.1.tar.gz">json-c-0.1.tar.gz</a></p>
+
+<p>JSON-C implements a reference counting object model that allows you
+to easily construct JSON objects in C, output them as JSON formatted strings
+and parse JSON formatted strings back into the C representation of JSON
+objects.</p>
+
+<p>Minimal documentation exists <a href="doc/html/json__object_8h.html">here</a>,
+Although you are probably better reading the example code in test1.c.</p>
+
+<p>JSON-C currently depends on some gcc 3.0+ features so can probably only be
+ compiled with gcc 3.0+. It also uses some specifc glibc functions such as
+ vasprintf. Patches welcome to port to other compilers / platforms.</p>
+
+<p>Please send bug reports to <a href="mailto:michael@metaparadigm.com">michael@metaparadigm.com</a></p>
+
+<h3>Anonymous CVS</h3>
+<p><code># <b>export CVSROOT=:pserver:anoncvs@cvs.metaparadigm.com:/cvsroot</b><br>
+# <b>cvs login</b><br>
+Logging in to :pserver:anoncvs@cvs.metaparadigm.com:2401/cvsroot<br>
+CVS password: &lt;enter '<b>anoncvs</b>'&gt;<br>
+# <b>cvs co json-c</b></code></p>
+
+<p>Copyright Metaparadigm Pte. Ltd. 2004. <a href="mailto:michael@metaparadigm.com">Michael Clark </a></p>
+
+<p>This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public (LGPL)
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.</p>
+
+<hr>
View
@@ -0,0 +1,94 @@
+/*
+ * $Id: arraylist.c,v 1.2 2004/07/21 01:24:33 mclark Exp $
+ *
+ * Copyright Metaparadigm Pte. Ltd. 2004.
+ * Michael Clark <michael@metaparadigm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public (LGPL)
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details: http://www.gnu.org/
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+#include "bits.h"
+#include "arraylist.h"
+
+
+struct array_list*
+array_list_new(array_list_free_fn *free_fn)
+{
+ struct array_list *this;
+
+ if(!(this = calloc(1, sizeof(struct array_list)))) return NULL;
+ this->size = ARRAY_LIST_DEFAULT_SIZE;
+ this->length = 0;
+ this->free_fn = free_fn;
+ if(!(this->array = calloc(sizeof(void*), this->size))) {
+ free(this);
+ return NULL;
+ }
+ return this;
+}
+
+extern void
+array_list_free(struct array_list *this)
+{
+ int i;
+ for(i = 0; i < this->length; i++)
+ if(this->array[i]) this->free_fn(this->array[i]);
+ free(this->array);
+ free(this);
+}
+
+void*
+array_list_get_idx(struct array_list *this, int i)
+{
+ if(i >= this->length) return NULL;
+ return this->array[i];
+}
+
+static int array_list_expand_internal(struct array_list *this, int max)
+{
+ void *t;
+ int new_size;
+
+ if(max < this->size) return 0;
+ new_size = max(this->size << 1, max);
+ if(!(t = realloc(this->array, new_size*sizeof(void*)))) return -1;
+ this->array = t;
+ bzero(this->array + this->size, (new_size-this->size)*sizeof(void*));
+ this->size = new_size;
+ return 0;
+}
+
+int
+array_list_put_idx(struct array_list *this, int idx, void *data)
+{
+ if(array_list_expand_internal(this, idx)) return -1;
+ if(this->array[idx]) this->free_fn(this->array[idx]);
+ this->array[idx] = data;
+ if(this->length <= idx) this->length = idx + 1;
+ return 0;
+}
+
+int
+array_list_add(struct array_list *this, void *data)
+{
+ return array_list_put_idx(this, this->length, data);
+}
+
+int
+array_list_length(struct array_list *this)
+{
+ return this->length;
+}
View
@@ -0,0 +1,52 @@
+/*
+ * $Id: arraylist.h,v 1.2 2004/07/21 01:24:33 mclark Exp $
+ *
+ * Copyright Metaparadigm Pte. Ltd. 2004.
+ * Michael Clark <michael@metaparadigm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public (LGPL)
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details: http://www.gnu.org/
+ *
+ */
+
+#ifndef _arraylist_h_
+#define _arraylist_h_
+
+#define ARRAY_LIST_DEFAULT_SIZE 32
+
+typedef void (array_list_free_fn) (void *data);
+
+struct array_list
+{
+ void **array;
+ int length;
+ int size;
+ array_list_free_fn *free_fn;
+};
+
+extern struct array_list*
+array_list_new(array_list_free_fn *free_fn);
+
+extern void
+array_list_free(struct array_list *this);
+
+extern void*
+array_list_get_idx(struct array_list *this, int i);
+
+extern int
+array_list_put_idx(struct array_list *this, int i, void *data);
+
+extern int
+array_list_add(struct array_list *this, void *data);
+
+extern int
+array_list_length(struct array_list *this);
+
+#endif
View
38 bits.h
@@ -0,0 +1,38 @@
+/*
+ * $Id: bits.h,v 1.3 2004/07/21 10:10:22 mclark Exp $
+ *
+ * Copyright Metaparadigm Pte. Ltd. 2004.
+ * Michael Clark <michael@metaparadigm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public (LGPL)
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details: http://www.gnu.org/
+ *
+ */
+
+#ifndef _bits_h_
+#define _bits_h_
+
+#define min(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; })
+
+#define max(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; })
+
+#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
+#define error_ptr(error) ((void*)error)
+#define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L)
+
+#endif
View
75 debug.c
@@ -0,0 +1,75 @@
+/*
+ * $Id: debug.c,v 1.3 2004/08/07 03:11:38 mclark Exp $
+ *
+ * Copyright Metaparadigm Pte. Ltd. 2004.
+ * Michael Clark <michael@metaparadigm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public (LGPL)
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details: http://www.gnu.org/
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+#include "debug.h"
+
+
+static int _syslog = 0;
+static int _debug = 0;
+
+void mc_set_debug(int debug) { _debug = debug; }
+int mc_get_debug() { return _debug; }
+
+extern void mc_set_syslog(int syslog)
+{
+ _syslog = syslog;
+}
+
+void mc_abort(const char *msg, ...)
+{
+ va_list ap;
+ va_start(ap, msg);
+ if(_syslog) vsyslog(LOG_ERR, msg, ap);
+ else vprintf(msg, ap);
+ exit(1);
+}
+
+
+void mc_debug(const char *msg, ...)
+{
+ va_list ap;
+ if(_debug) {
+ va_start(ap, msg);
+ if(_syslog) vsyslog(LOG_DEBUG, msg, ap);
+ else vprintf(msg, ap);
+ }
+}
+
+void mc_error(const char *msg, ...)
+{
+ va_list ap;
+ va_start(ap, msg);
+ if(_syslog) vsyslog(LOG_ERR, msg, ap);
+ else vfprintf(stderr, msg, ap);
+}
+
+void mc_info(const char *msg, ...)
+{
+ va_list ap;
+ va_start(ap, msg);
+ if(_syslog) vsyslog(LOG_INFO, msg, ap);
+ else vfprintf(stderr, msg, ap);
+}
View
33 debug.h
@@ -0,0 +1,33 @@
+/*
+ * $Id: debug.h,v 1.2 2004/07/21 01:24:33 mclark Exp $
+ *
+ * Copyright Metaparadigm Pte. Ltd. 2004.
+ * Michael Clark <michael@metaparadigm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public (LGPL)
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details: http://www.gnu.org/
+ *
+ */
+
+#ifndef _DEBUG_H_
+#define _DEBUG_H_
+
+#define errstr strerror(errno)
+
+extern void mc_set_debug(int debug);
+extern int mc_get_debug();
+
+extern void mc_set_syslog(int syslog);
+extern void mc_abort(const char *msg, ...);
+extern void mc_debug(const char *msg, ...);
+extern void mc_error(const char *msg, ...);
+extern void mc_info(const char *msg, ...);
+
+#endif
Oops, something went wrong.

0 comments on commit f0d0888

Please sign in to comment.