changeset 13:a593eddaf0a3

Add jason_ prefix to all exposed functions
author Norman Gray <norman@astro.gla.ac.uk>
date Sun, 23 Feb 2014 22:23:23 +0000
parents a9a41fa6fa73
children 2221a941abaa
files README.md src/jason.c src/jason.h src/json-parse.y src/json2der.c src/json_lex.lex src/test/unit_tests.c src/util.c
diffstat 8 files changed, 224 insertions(+), 217 deletions(-) [+]
line wrap: on
line diff
--- a/README.md	Fri Jan 03 16:52:58 2014 +0000
+++ b/README.md	Sun Feb 23 22:23:23 2014 +0000
@@ -56,58 +56,70 @@
 The interface is still somewhat preliminary, and not documented very
 elaborately.  However...
 
+Unless noted otherwise, each of the non-void functions returns an
+object which is owned by the caller, which must subsequently free it
+either with `jason_free_object()` or plain `free()`.
+
+The exceptions are functions `jason_get_...`.
+Each of these returns a pointer to an object which is either static or
+(in the case of `jason_get_der_encoding`) object by another object.
+
     #include <jason.h>
 
-    JsonObject parse_json_string(const char* json_string);
+    JsonObject jason_parse_string(const char* json_string);
 
 Parse the JSON object given in the string.  If the string cannot be
 parsed, then this returns `NULL`, and an explanation is available from
-the function `const char* unsupported_message()`.  The returned object
-should be freed by `free_json_object`.
-
-    void free_json_object(JsonObject o);
-
-Free the object.  Any allocated memory within the object is freed also.
-
-    const char* print_json_object(JsonObject obj);
-
-Serialise the object to a string.  The string must be subsequently
-freed by the caller.
+the function `const char* jason_get_error_message()`.
 
-    uint8_t* get_der_encoding(JsonObject obj, size_t *len);
-
-Get the DER-encoding of the object.  The object must not be freed by
-the caller.
-
-    char* bytes_to_string(uint8_t* b, size_t blen);
-
-Utility method to serialise a byte sequence to a printable string of
-hex digits.  The returned object must be freed by the caller.
-
-    JsonObject parse_der_bytes(uint8_t*, size_t, size_t*);
+    JsonObject jason_parse_der_bytes(uint8_t*, size_t, size_t*);
 
 Decode a sequence of bytes which are the DER encoding of a JSON
 object, and return the object.  If the byte sequence
 cannot be parsed, then this returns `NULL`, and an explanation is
-available from the function `const char* unsupported_message()`.
-The result should be freed by `free_json_object` when no longer required.  
+available from the function `const char* jason_get_error_message()`.
+
+A `JsonObject` should be freed by `jason_free_object` when no longer required.  
+
+    void jason_free_object(JsonObject o);
+
+Free the object.  Any allocated memory within the object is freed also.
+
+    const char* jason_get_error_message(void);
+
+Retrieve the error message associated with a recent JSON parse, or DER
+encoding.  This string must not be freed.
 
-    const char* jason_version_string(void);
+    const char* jason_print_object(JsonObject obj);
+
+Serialise the object to a string.
+
+    uint8_t* jason_get_der_encoding(JsonObject obj, size_t *len);
+
+Get the DER-encoding of the object.
+The object must not be freed by the caller.
+
+    char* jason_bytes_to_string(uint8_t* b, size_t blen);
+
+Utility method to serialise a byte sequence to a printable string of
+hex digits.
+
+    const char* jason_get_version_string(void);
     int jason_version_number(void);
 
-Return information about the library version number.
+Return information about the library version number.  The
+value returned by `jason_get_version_string` must not be freed.
 
-Though this library is not intended as a general JSON parser, the
-contents of the `JsonObject` structure should be fairly stable.  See
-the `jason.h` header for the details.
+The contents of the `JsonObject` structure should be fairly stable.
+See the `jason.h` header for the details.
 
 
 Name
 ----
 
-The name *Jason* is a fairly obvious amalgam of JSON and ASN.  JASN
-would be a better name, but someone's had that idea before me, and
-[that name's already taken][jasn] for a Java ASN parser.
+The name *Jason* is a fairly obvious amalgam of JSON and ASN.
+JASN would be a better name,
+but [that name's already taken][jasn] for a Java ASN parser.
 
 
 Source code and licence information
@@ -115,7 +127,7 @@
 
 The source code is available at <https://bitbucket.org/nxg/jason>.
 
-Jason is Copyright 2013 Norman Gray, and is released under the
+Jason is Copyright 2013, 2014 Norman Gray, and is released under the
 terms of the [BSD 2-clause licence][] (see the file LICENCE for text).
 
 The distribution includes the [`lcut` unit-testing framework][lcut],
--- a/src/jason.c	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/jason.c	Sun Feb 23 22:23:23 2014 +0000
@@ -2,10 +2,10 @@
  * This file is part of the Jason library.
  * See <https://bitbucket.org/nxg/jason>
  *
- * Copyright 2013, Norman Gray <http://nxg.me.uk>
+ * Copyright 2013, 2014, Norman Gray <http://nxg.me.uk>
  *
- * It is distributed under the terms of the GNU General Public
- * Licence.  See the file README.me for details.
+ * It is distributed under the terms of the BSD 2-clause Licence.
+ * See the file README.md for details.
  */
 
 #include <stdlib.h>
@@ -49,7 +49,7 @@
 // If get_der_encoding fails because of unsupported behaviour,
 // then it returns NULL and sets a message which can be retrieved
 // here.  The message will be NULL unless this is the cause of the failure.
-const char* unsupported_message() 
+const char* jason_get_error_message() 
 {
     if (unsupported_msg[0] == '\0') {
         return NULL;
@@ -58,7 +58,7 @@
     }
 }
 
-JsonObject initialise_json_object(JsonObject r, JsonType type)
+static JsonObject initialise_json_object(JsonObject r, JsonType type)
 {
     r->type = type;
     r->der_encoding = NULL;
@@ -105,7 +105,7 @@
  * Free the object.
  * Any allocated memory within the object is freed also.
  */
-void free_json_object(JsonObject o)
+void jason_free_object(JsonObject o)
 {
     free_json_object_internal(o, 1);
 }
@@ -118,7 +118,7 @@
 static void print_json_array(JsonObject arr, StringBuilder sb);
 static void print_json_oneobject(JsonObject obj, StringBuilder sb);
 
-void print_json_object_to_buffer(JsonObject obj, StringBuilder sb)
+static void print_json_object_to_buffer(JsonObject obj, StringBuilder sb)
 {
 #define BUFLEN 64          /* can any integer or float be longer than this? */
     char printbuf[BUFLEN];
@@ -236,7 +236,7 @@
  *
  * The string must be subsequently freed by the caller.
  */
-const char* print_json_object(JsonObject obj)
+const char* jason_print_object(JsonObject obj)
 {
     const char* rval;
 
@@ -263,36 +263,39 @@
     return initialise_json_object(r, type);
 }
 
+// the make_* functions below are not documented, but are exposed
+// because they must be called by the parser.
+
 // argument 's' should me malloc-ed, and not a constant string
-JsonObject make_string(const char* s)
+JsonObject jason_make_string_(const char* s)
 {
     JsonObject r = new_object(JSON_STRING);
     r->x.s = s;
     return r;
 }
 
-JsonObject make_integer(jsonint i)
+JsonObject jason_make_integer_(jsonint i)
 {
     JsonObject r = new_object(JSON_INTEGER);
     r->x.i = i;
     return r;
 }
 
-JsonObject make_real(double f)
+JsonObject jason_make_real_(double f)
 {
     JsonObject r = new_object(JSON_REAL);
     r->x.f = f;
     return r;
 }
 
-JsonObject make_boolean(int b)
+JsonObject jason_make_boolean_(int b)
 {
     JsonObject r = new_object(JSON_BOOLEAN);
     r->x.b = b;
     return r;
 }
 
-JsonObject make_null(void)
+JsonObject jason_make_null_(void)
 {
     JsonObject r = new_object(JSON_NULL);
     return r;
@@ -316,7 +319,7 @@
         size_t alloc = 4;
         JsonObject* arr = (JsonObject*)malloc(alloc * sizeof(JsonObject));
         if (arr == NULL) {
-            error_exit("Can't allocate space for make_array");
+            error_exit("Can't allocate space for jason_make_array_");
         }
         arr[0] = initial;
         r->x.a.p = arr;
@@ -326,19 +329,19 @@
     return r;
 }
 
-JsonObject make_array(JsonObject obj)
+JsonObject jason_make_array_(JsonObject obj)
 {
     return make_initial_array(JSON_ARRAY, obj);
 }
 
-JsonObject make_object(JsonObject obj)
+JsonObject jason_make_object_(JsonObject obj)
 {
     assert(obj == NULL || obj->type == JSON_KVPAIR);
     return make_initial_array(JSON_OBJECT, obj);
 }
 
 // argument 'k' should me malloc-ed, and not a constant string
-JsonObject make_kv(const char* k, JsonObject o)
+JsonObject jason_make_kv_(const char* k, JsonObject o)
 {
     JsonObject r = new_object(JSON_KVPAIR);
     r->x.kv.k = k;
@@ -347,7 +350,7 @@
 }
 
 // the newobj object is now 'owned' by this module
-JsonObject append_object(JsonObject o, JsonObject newobj)
+JsonObject jason_append_object_(JsonObject o, JsonObject newobj)
 {
     assert(o != NULL);
     assert(o->type == JSON_ARRAY
@@ -361,7 +364,7 @@
         JsonObject* arr = (JsonObject*)realloc((void*)(o->x.a.p),
                                                alloc*sizeof(JsonObject));
         if (arr == NULL) {
-            error_exit("Can't realloc memory for append_object");
+            error_exit("Can't realloc memory for jason_append_object_");
         }
         o->x.a.p = arr;
         o->x.a.alloc = alloc;
@@ -450,7 +453,7 @@
  * Get the DER-encoding of the object.
  * The object must not be freed by the caller.
  */
-byte* get_der_encoding(JsonObject obj, size_t *len) 
+byte* jason_get_der_encoding(JsonObject obj, size_t *len) 
 {
     byte* rval;
     
@@ -480,7 +483,7 @@
  * Utility method to serialise a byte sequence to a printable string of
  * hex digits.  The returned object must be freed by the caller.
  */
-char* bytes_to_string(byte* b, size_t blen)
+char* jason_bytes_to_string(byte* b, size_t blen)
 {
     static char* buf = NULL;
     static size_t buflen = 0;
@@ -1009,13 +1012,13 @@
 
 // interface to parsing functions
 
-// lexer functions
+// lexer functions, defined in json_lex.lex
 int yylex(void);
-int lex_setup(const char*);
-void lex_release(void);
+int jason_lex_setup(const char*);
+void jason_lex_release(void);
 
-// parser functions
-JsonObject get_parsed_value(void);
+// parser functions, defined in json-parse.y
+JsonObject jason_get_parsed_value_(void);
 int yyparse(void);
 
 void yyerror(const char* msg)
@@ -1026,10 +1029,10 @@
 /**
  * Parse the JSON object given in the string.  If the string cannot be
  * parsed, then this returns `NULL`, and an explanation is available from
- * the function `const char* unsupported_message()`.  The returned object
- * should be freed by @{link #free_json_object}.
+ * the function `const char* get_jason_error_message()`.  The returned object
+ * should be freed by {@link #jason_free_object}.
  */
-JsonObject parse_json_string(const char* json_string)
+JsonObject jason_parse_string(const char* json_string)
 {
     JsonObject rval;
 
@@ -1043,13 +1046,13 @@
         in_jmp_code = 1;
         unsupported_msg[0] = '\0';
 
-        lex_setup(json_string);
+        jason_lex_setup(json_string);
         if (yyparse() == 0) {
-            rval = get_parsed_value();
+            rval = jason_get_parsed_value_();
         } else {
             rval = NULL;
         }
-        lex_release();
+        jason_lex_release();
     }
 
     in_jmp_code = 0;
@@ -1068,7 +1071,7 @@
     str = (char*)allocb(blen+1);
     memcpy(str, b, blen);
     str[blen] = '\0';
-    return make_string(str);
+    return jason_make_string_(str);
 }
 
 static jsonint parse_der_integer_content_to_integer(byte* b, size_t blen)
@@ -1111,13 +1114,13 @@
 static JsonObject parse_der_integer_content(byte* b, size_t blen)
 {
     jsonint result = parse_der_integer_content_to_integer(b, blen);
-    return make_integer(result);
+    return jason_make_integer_(result);
 }
 
 static JsonObject parse_der_real_content(byte* b, size_t blen)
 {
     if (blen == 0) {
-        return make_real(0.0);
+        return jason_make_real_(0.0);
     } else {
         int sign;
         int exponent = 0;       /* initialise to keep -Wall happy */
@@ -1156,7 +1159,7 @@
         printf("der_real: %d:%d:%ld -> %g\n", sign, exponent, mantissa, result);
 #endif
 
-        return make_real(result);
+        return jason_make_real_(result);
     }
 }
 
@@ -1165,7 +1168,7 @@
     if (blen != 1) {
         unsupported_operation("Boolean with a peculiar number of bytes (%d)", blen);
     }
-    return make_boolean(b[0] ? 1 : 0);
+    return jason_make_boolean_(b[0] ? 1 : 0);
 }
 
 static JsonObject parse_der_null_content(byte* b, size_t blen)
@@ -1173,7 +1176,7 @@
     if (blen != 0) {
         unsupported_operation("Null with content (%d bytes)", blen);
     }
-    return make_null();
+    return jason_make_null_();
 }
 
 static JsonObject parse_der_sequence_content(byte* b, size_t blen)
@@ -1187,12 +1190,12 @@
         b += olen;
         blen -= olen;
         if (list_of_objects == NULL) {
-            list_of_objects = make_array(obj);
+            list_of_objects = jason_make_array_(obj);
         } else {
-            list_of_objects = append_object(list_of_objects, obj);
+            list_of_objects = jason_append_object_(list_of_objects, obj);
         }
     }
-    return list_of_objects == NULL ? make_array(NULL) : list_of_objects;
+    return list_of_objects == NULL ? jason_make_array_(NULL) : list_of_objects;
 }
 
 static JsonObject parse_der_object_content(byte* b, size_t blen)
@@ -1246,19 +1249,19 @@
 
         assert(ok_object && key != NULL && value != NULL);
 
-        obj = make_kv(key->x.s, value);
+        obj = jason_make_kv_(key->x.s, value);
         free_json_object_internal(key, 0);
         free_json_object_internal(array_obj, 0);
         
         b += olen;
         blen -= olen;
         if (list_of_objects == NULL) {
-            list_of_objects = make_object(obj);
+            list_of_objects = jason_make_object_(obj);
         } else {
-            list_of_objects = append_object(list_of_objects, obj);
+            list_of_objects = jason_append_object_(list_of_objects, obj);
         }
     }
-    return list_of_objects == NULL ? make_object(NULL) : list_of_objects;
+    return list_of_objects == NULL ? jason_make_object_(NULL) : list_of_objects;
 }
 
 static JsonObject parse_der_bytes_internal(byte* b, size_t blen, size_t* actuallen)
@@ -1348,12 +1351,12 @@
  * Decode a sequence of bytes which are the DER encoding of a JSON
  * object, and return the object.  If the byte sequence
  * cannot be parsed, then this returns `NULL`, and an explanation is
- * available from the function {@link #unsupported_message}.
+ * available from the function {@link #jason_get_error_message}.
  *
  * The result should be freed by
- * {@link #free_json_object} when no longer required.
+ * {@link #jason_free_object} when no longer required.
  */
-JsonObject parse_der_bytes(byte* b, size_t blen, size_t* actuallen)
+JsonObject jason_parse_der_bytes(byte* b, size_t blen, size_t* actuallen)
 {
     JsonObject rval = NULL;
 
@@ -1381,7 +1384,7 @@
  *
  * @see jason_version_number
  */
-const char* jason_version_string(void)
+const char* jason_get_version_string(void)
 {
     const char* snapshotid = SNAPSHOTID;
     if (snapshotid[0] == '\0') {
@@ -1404,4 +1407,3 @@
 {
     return PACKAGE_VERSION_INTEGER;
 }
-
--- a/src/jason.h	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/jason.h	Sun Feb 23 22:23:23 2014 +0000
@@ -56,29 +56,28 @@
 };
 typedef struct json_object* JsonObject;
 
-JsonObject initialise_json_object(JsonObject, JsonType);
-void free_json_object(JsonObject o);
-const char* print_json_object(JsonObject obj);
-uint8_t* get_der_encoding(JsonObject obj, size_t *len);
-char* bytes_to_string(uint8_t* b, size_t blen);
-JsonObject parse_json_string(const char* json_string);
-JsonObject parse_der_bytes(uint8_t*, size_t, size_t*);
-const char* unsupported_message();
+void jason_free_object(JsonObject o);
+const char* jason_print_object(JsonObject obj);
+uint8_t* jason_get_der_encoding(JsonObject obj, size_t *len);
+char* jason_bytes_to_string(uint8_t* b, size_t blen);
+JsonObject jason_parse_string(const char* json_string);
+JsonObject jason_parse_der_bytes(uint8_t*, size_t, size_t*);
+const char* jason_get_error_message();
 
-const char* jason_version_string();
+const char* jason_get_version_string();
 int jason_version_number();
 
 #if JASON_IMPLEMENTATION
 
-JsonObject make_string(const char*);
-JsonObject make_integer(jsonint);
-JsonObject make_real(double);
-JsonObject make_boolean(int);
-JsonObject make_null(void);
-JsonObject make_array(JsonObject);
-JsonObject make_object(JsonObject);
-JsonObject make_kv(const char*, JsonObject);
-JsonObject append_object(JsonObject, JsonObject);
+JsonObject jason_make_string_(const char*);
+JsonObject jason_make_integer_(jsonint);
+JsonObject jason_make_real_(double);
+JsonObject jason_make_boolean_(int);
+JsonObject jason_make_null_(void);
+JsonObject jason_make_array_(JsonObject);
+JsonObject jason_make_object_(JsonObject);
+JsonObject jason_make_kv_(const char*, JsonObject);
+JsonObject jason_append_object_(JsonObject, JsonObject);
 
 #endif /* JASON_IMPLEMENTATION */
 
--- a/src/json-parse.y	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/json-parse.y	Sun Feb 23 22:23:23 2014 +0000
@@ -10,7 +10,7 @@
 
     static JsonObject return_value;
     static void set_parsed_value(JsonObject);
-    JsonObject get_parsed_value(void);
+    JsonObject jason_get_parsed_value_(void);
 %}
 
 %union {
@@ -38,41 +38,41 @@
 %%
 input: value { set_parsed_value($1); }
 
-value: STRING { $$ = make_string($1); }
-  | INTEGER { $$ = make_integer($1); }
-  | REAL { $$ = make_real($1); }
-  | TRUE { $$ = make_boolean(1); }
-  | FALSE { $$ = make_boolean(0); }
-  | JNULL { $$ = make_null(); }
+value: STRING { $$ = jason_make_string_($1); }
+  | INTEGER { $$ = jason_make_integer_($1); }
+  | REAL { $$ = jason_make_real_($1); }
+  | TRUE { $$ = jason_make_boolean_(1); }
+  | FALSE { $$ = jason_make_boolean_(0); }
+  | JNULL { $$ = jason_make_null_(); }
   | object
   | array
 
 array: LEFTSQ RIGHTSQ {
-    $$ = make_array(NULL);
+    $$ = jason_make_array_(NULL);
   }
   | LEFTSQ list.of.value RIGHTSQ {
     $$ = $2;
   }
 
 list.of.value: value {
-    $$ = make_array($1);
+    $$ = jason_make_array_($1);
   }
   | list.of.value COMMA value {
-    $$ = append_object($1, $3);
+    $$ = jason_append_object_($1, $3);
   }
 
 object: LEFTCURLY RIGHTCURLY {
-    $$ = make_object(NULL);
+    $$ = jason_make_object_(NULL);
   }
   | LEFTCURLY list.of.kv RIGHTCURLY {
     $$ = $2;
   }
 
 list.of.kv: STRING COLON value {
-    $$ = make_object(make_kv($1, $3));
+    $$ = jason_make_object_(jason_make_kv_($1, $3));
   }
   | list.of.kv COMMA STRING COLON value {
-    $$ = append_object($1, make_kv($3, $5));
+    $$ = jason_append_object_($1, jason_make_kv_($3, $5));
   }
 
 %%
@@ -81,7 +81,7 @@
     return_value = o;
 }
  
-JsonObject get_parsed_value(void)
+JsonObject jason_get_parsed_value_(void)
 {
     return return_value;
 }
--- a/src/json2der.c	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/json2der.c	Sun Feb 23 22:23:23 2014 +0000
@@ -2,10 +2,10 @@
  * This file is part of the Jason library.
  * See <https://bitbucket.org/nxg/jason>
  *
- * Copyright 2013, Norman Gray <http://nxg.me.uk>
+ * Copyright 2013, 2014, Norman Gray <http://nxg.me.uk>
  *
- * It is distributed under the terms of the GNU General Public
- * Licence.  See the file README.me for details.
+ * It is distributed under the terms of the BSD 2-clause Licence.
+ * See the file README.md for details.
  */
 
 #include <stdio.h>
@@ -84,7 +84,7 @@
             }
             break;
           case 'V':
-            puts(jason_version_string());
+            puts(jason_get_version_string());
             exit(0);
             break;
           case 'h':
@@ -141,17 +141,17 @@
 
     switch (input) {
       case FMT_JSON:
-        parse_val = parse_json_string((char*)input_string);
+        parse_val = jason_parse_string((char*)input_string);
         break;
       case FMT_DER:
-        parse_val = parse_der_bytes((byte*)input_string, input_string_length, NULL);
+        parse_val = jason_parse_der_bytes((byte*)input_string, input_string_length, NULL);
         break;
       default:
         Usage();
     }
     
     if (parse_val == NULL) {
-        const char* msg = unsupported_message();
+        const char* msg = jason_get_error_message();
         if (msg == NULL) {
             fprintf(stderr, "Parsing failed\n");
         } else {
@@ -160,16 +160,16 @@
     } else {
         switch (output) {
           case FMT_JSON:
-            fputs(print_json_object(parse_val), out);
+            fputs(jason_print_object(parse_val), out);
             fputc('\n', out);
             break;
           case FMT_DER:
             {
                 size_t blen;
-                byte* b = get_der_encoding(parse_val, &blen);
+                byte* b = jason_get_der_encoding(parse_val, &blen);
                 if (b == NULL) {
                     fprintf(stderr, "Failed to DER-encode that value (%s)\n",
-                            unsupported_message());
+                            jason_get_error_message());
                     exit(1);
                 }
                 fwrite(b, sizeof(byte), blen, out);
@@ -181,20 +181,20 @@
         }
     }
 
-    free_json_object(parse_val);
+    jason_free_object(parse_val);
 }
 
 // defined in json_lex.c
 int yylex(void);
-char* lex_error_message(void);
-int lex_setup(const char*);
-void lex_release(void);
+char* jason_lex_error_message(void);
+int jason_lex_setup(const char*);
+void jason_lex_release(void);
 
 static void display_lexemes(const char* input)
 {
     int l;
     
-    lex_setup(input);
+    jason_lex_setup(input);
     
     while ((l = yylex()) != 0) {
 
@@ -243,15 +243,11 @@
         }
     }
 
-    if (lex_error_message()) {
-        printf("Lexing error: %s\n", lex_error_message());
+    if (jason_lex_error_message()) {
+        printf("Lexing error: %s\n", jason_lex_error_message());
     }
     
-    /* if (lex_unexpected_character() != '\0') { */
-    /*     printf("Unexpected character: %c\n", lex_unexpected_character()); */
-    /* } */
-    
-    lex_release();
+    jason_lex_release();
 }
 
 void Usage(void)
--- a/src/json_lex.lex	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/json_lex.lex	Sun Feb 23 22:23:23 2014 +0000
@@ -14,7 +14,7 @@
 
 #define ERR_MSG_LEN 64
 static char err_msg[ERR_MSG_LEN];
-char* lex_error_message(void)
+char* jason_lex_error_message(void)
 {
     if (err_msg[0] == '\0') {
         return NULL;
@@ -26,8 +26,8 @@
 static const char* parse_string_endp = NULL;
 static const char* parse_string_p = NULL;
 static const char* parse_string_buf = NULL;
-int lex_setup(const char*);
-void lex_release(void);
+int jason_lex_setup(const char*);
+void jason_lex_release(void);
 
 /* Prevent flex emitting an input() function (not a documented flex option) */
 #define YY_NO_INPUT 1
@@ -123,7 +123,7 @@
 }
 #endif
  
-int lex_setup(const char* s) 
+int jason_lex_setup(const char* s) 
 {
     int slen;                   /* length of buffer */
     
@@ -135,7 +135,7 @@
 
     if (parse_string_buf != NULL) {
         // we've been called before -- forget that
-        lex_release();
+        jason_lex_release();
     }
     assert(parse_string_buf == NULL);
 
@@ -172,9 +172,9 @@
     return 0;
 }
 
-void lex_release(void) 
+void jason_lex_release(void) 
 {
-    // lex_release releases the memory allocated in lex_setup.
+    // jason_lex_release releases the memory allocated in lex_setup.
     // Without this, we'd have a memory leak after repeated calls.
     // I spit on C.
     if (parse_string_buf != NULL) {
--- a/src/test/unit_tests.c	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/test/unit_tests.c	Sun Feb 23 22:23:23 2014 +0000
@@ -13,32 +13,32 @@
     
     // Just a single uncomplicated one of each, to check the basics
 
-    o = parse_json_string("1");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "020101", bytes_to_string(b, blen));
+    o = jason_parse_string("1");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "020101", jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("\"foo\"");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "1603666f6f", bytes_to_string(b, blen));
+    o = jason_parse_string("\"foo\"");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "1603666f6f", jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("true");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "0101ff", bytes_to_string(b, blen));
+    o = jason_parse_string("true");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "0101ff", jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("false");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "010100", bytes_to_string(b, blen));
+    o = jason_parse_string("false");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "010100", jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("null");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "0500", bytes_to_string(b, blen));
+    o = jason_parse_string("null");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "0500", jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("[1, \"two\", true, null]");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "300d020101160374776f0101ff0500", bytes_to_string(b, blen));
+    o = jason_parse_string("[1, \"two\", true, null]");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "300d020101160374776f0101ff0500", jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("{\"one\": 1, \"two\": 2, \"thr\": 3}");
-    b = get_der_encoding(o, &blen);
+    o = jason_parse_string("{\"one\": 1, \"two\": 2, \"thr\": 3}");
+    b = jason_get_der_encoding(o, &blen);
     // The resulting order is important: DER-encoding requires that
     // the elements in the SET OF are ordered by the lexicographic
     // order of their contents.  The test above is chosen so that the
@@ -49,11 +49,11 @@
                    "300816036f6e65020101" // one:1
                    "30081603746872020103" // three:3
                    "3008160374776f020102", // two:2
-                   bytes_to_string(b, blen));
+                   jason_bytes_to_string(b, blen));
 
-    o = parse_json_string("2.0");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "0903800101", bytes_to_string(b, blen));
+    o = jason_parse_string("2.0");
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "0903800101", jason_bytes_to_string(b, blen));
 }
 
 void tc_torture_syntax(lcut_tc_t *tc, void *data)
@@ -62,23 +62,23 @@
     size_t blen;
     byte* b;
 
-    o = parse_json_string("  [ \n    1   ,  \"two\"  ,\t\ttrue, null ]    \n   ");
+    o = jason_parse_string("  [ \n    1   ,  \"two\"  ,\t\ttrue, null ]    \n   ");
     LCUT_ASSERT(tc, "string torture test failed", o != NULL);
-    b = get_der_encoding(o, &blen);
+    b = jason_get_der_encoding(o, &blen);
     LCUT_STR_EQUAL(tc,
                    "300d020101160374776f0101ff0500",
-                   bytes_to_string(b, blen));
+                   jason_bytes_to_string(b, blen));
 
     // 4-byte integers
-    o = parse_json_string("[16777216,16777216,16777216,16777216]");
-    b = get_der_encoding(o, &blen);
+    o = jason_parse_string("[16777216,16777216,16777216,16777216]");
+    b = jason_get_der_encoding(o, &blen);
     LCUT_STR_EQUAL(tc,
                    "3018020401000000020401000000020401000000020401000000",
-                   bytes_to_string(b, blen));
+                   jason_bytes_to_string(b, blen));
 
     // more than 127 characters in DER encoding
     // and including a string which is 200 characters long
-    o = parse_json_string("["
+    o = jason_parse_string("["
                           "16777216,16777216,16777216,16777216,"
                           "16777216,16777216,16777216,16777216,"
                           "16777216,16777216,16777216,16777216,"
@@ -87,7 +87,7 @@
                           "16777216,16777216,16777216,16777216,"
                           "\"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\""
                           "]");
-    b = get_der_encoding(o, &blen);
+    b = jason_get_der_encoding(o, &blen);
     LCUT_STR_EQUAL(tc,
                    "3082015b" // array with 347 octets of content
                    "020401000000020401000000020401000000020401000000"
@@ -107,10 +107,10 @@
                    "3031323334353637383930313233343536373839"
                    "3031323334353637383930313233343536373839"
                    "3031323334353637383930313233343536373839",
-                   bytes_to_string(b, blen));
+                   jason_bytes_to_string(b, blen));
 
 #define PARSEQ(str) do {                                                \
-        o = parse_json_string(str);                                     \
+        o = jason_parse_string(str);                                     \
         LCUT_ASSERT(tc, "parsing " str " should have succeeded", o != NULL); \
     } while (0)
 
@@ -127,8 +127,8 @@
     byte* b;
     size_t blen;
 
-    o = parse_json_string("[0,127,128,255,+256,-127,-128,-129]");
-    b = get_der_encoding(o, &blen);
+    o = jason_parse_string("[0,127,128,255,+256,-127,-128,-129]");
+    b = jason_get_der_encoding(o, &blen);
     LCUT_STR_EQUAL(tc,
                    "301c" // array with 28 bytes of content
                    "020100"
@@ -139,7 +139,7 @@
                    "020181"
                    "020180"
                    "0202ff7f",
-                   bytes_to_string(b, blen));
+                   jason_bytes_to_string(b, blen));
     {
         // The integer conversion code depends on the machine being a
         // twos-complement machine, with sizeof(uintmax_t) being 8.
@@ -177,10 +177,10 @@
                 "    buf=%s\n",
                 sizeof(uintmax_t), um, um, sm, -sm, -sm, buf);
 #endif
-        o = parse_json_string(buf);
-        b = get_der_encoding(o, &blen);
+        o = jason_parse_string(buf);
+        b = jason_get_der_encoding(o, &blen);
 #if 0
-        fprintf(stderr, "actual:%s\n", bytes_to_string(b, blen));
+        fprintf(stderr, "actual:%s\n", jason_bytes_to_string(b, blen));
 #endif
         LCUT_STR_EQUAL(tc,
                        "3034"
@@ -192,7 +192,7 @@
                        "02028001"
                        "02017f"
                        "020181",
-                       bytes_to_string(b, blen));
+                       jason_bytes_to_string(b, blen));
     } else {
         fputs("intmax_t test skipped", stderr);
     }
@@ -206,7 +206,7 @@
     char* benc;
     char* expected;
 
-    o = parse_json_string("[ 0.0, 1.0, -1.0, "
+    o = jason_parse_string("[ 0.0, 1.0, -1.0, "
                           "2.0, -0.25,"
                           "1e1," // +10
                           "-1e1, -1.0e+1, -10.0, -1e+001, " // -10
@@ -215,8 +215,8 @@
                           "1361129467683753853853498429727072845824.0" // 2^130
                           " ]");
 
-    b = get_der_encoding(o, &blen);
-    benc = bytes_to_string(b, blen);
+    b = jason_get_der_encoding(o, &blen);
+    benc = jason_bytes_to_string(b, blen);
     expected = "305e"
         "0900" // 0.0
         "0903800001" // 1x2^0 = 1
@@ -254,25 +254,25 @@
     // check encoding of special real values (these can't be read in
     // normal JSON, but it seems nice and complete to include these in
     // the translation, just in case)
-    o = parse_json_string("1.0");
+    o = jason_parse_string("1.0");
     o->x.f = INFINITY;
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "090140", bytes_to_string(b, blen));
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "090140", jason_bytes_to_string(b, blen));
     o->der_encoding = NULL;     /* hack */
     
     o->x.f = -INFINITY;
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "090141", bytes_to_string(b, blen));
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "090141", jason_bytes_to_string(b, blen));
     o->der_encoding = NULL;     /* hack */
     
     o->x.f = nan("");
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "090142", bytes_to_string(b, blen));
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "090142", jason_bytes_to_string(b, blen));
     o->der_encoding = NULL;     /* hack */
     
     o->x.f = -0.0;
-    b = get_der_encoding(o, &blen);
-    LCUT_STR_EQUAL(tc, "090143", bytes_to_string(b, blen));
+    b = jason_get_der_encoding(o, &blen);
+    LCUT_STR_EQUAL(tc, "090143", jason_bytes_to_string(b, blen));
     o->der_encoding = NULL;     /* hack */
     
 }
@@ -286,7 +286,7 @@
     // Test DER-mandated sorting of the keys in an object.
     // Remember that the sort order is based on the DER-encoded
     // ["one",1], etc.
-    o = parse_json_string("{"
+    o = jason_parse_string("{"
                           "\"one\": 1,"
                           "\"two\": 2,"
                           "\"three\": 3,"
@@ -297,7 +297,7 @@
                           "\"eight\": 8,"
                           "\"nine\": 9,"
                           "\"ten\": 10 }");
-    b = get_der_encoding(o, &blen);
+    b = jason_get_der_encoding(o, &blen);
     LCUT_STR_EQUAL(tc,
                    "316d"
                    "300816036f6e65020101" // one
@@ -310,7 +310,7 @@
                    "300a16056569676874020108" // eight
                    "300a1605736576656e020107" // seven
                    "300a16057468726565020103",// three
-                   bytes_to_string(b, blen));
+                   jason_bytes_to_string(b, blen));
 }
 
 void tc_strings(lcut_tc_t *tc, void *data)
@@ -320,9 +320,9 @@
     size_t blen;
 
     char* teststring = "\"q\\\" rs\\\\ s\\/ b\\b f\\f n\\n r\\r t\\t\"";
-    o = parse_json_string(teststring);
+    o = jason_parse_string(teststring);
 
-    b = get_der_encoding(o, &blen);
+    b = jason_get_der_encoding(o, &blen);
     {
         char* expected =
             "1618"
@@ -334,12 +334,12 @@
             "6e0a20" // n<newline>
             "720d20" // r<carriage-return>
             "7409";  // t<tab>
-        char* actual = bytes_to_string(b, blen);
+        char* actual = jason_bytes_to_string(b, blen);
         LCUT_STR_EQUAL(tc, expected, actual);
     }
 
 #define SHOULDFAIL(str) do {                       \
-        o = parse_json_string(str);             \
+        o = jason_parse_string(str);             \
         LCUT_ASSERT(tc, "parsing " str " should have failed", o == NULL); \
     } while (0)
 
@@ -416,8 +416,10 @@
     
     const char* json_s;
 
-#define TESTDECODE(arr, str) do {                  \
-        json_s = print_json_object(parse_der_bytes(arr, sizeof(arr), NULL)); \
+#define TESTDECODE(arr, str) do {                                       \
+        json_s = jason_print_object(jason_parse_der_bytes(arr,          \
+                                                          sizeof(arr),  \
+                                                          NULL));       \
         LCUT_STR_EQUAL(tc, str, json_s);                                \
         if (json_s != NULL) {                                           \
             free((void*)json_s);                                        \
@@ -461,9 +463,9 @@
                  ", %" JSONFMT ", %" JSONFMT
                  ", 32767, -32767, 127, -127 ]",
                  sm, -sm, s7, -s7);
-        json_s = print_json_object(parse_der_bytes(der_intarray,
-                                                   sizeof(der_intarray),
-                                                   NULL));
+        json_s = jason_print_object(jason_parse_der_bytes(der_intarray,
+                                                          sizeof(der_intarray),
+                                                          NULL));
         LCUT_STR_EQUAL(tc, buf, json_s);
         if (json_s != NULL) {
             free((void*)json_s);
--- a/src/util.c	Fri Jan 03 16:52:58 2014 +0000
+++ b/src/util.c	Sun Feb 23 22:23:23 2014 +0000
@@ -2,21 +2,17 @@
  * This file is part of the Jason library.
  * See <https://bitbucket.org/nxg/jason>
  *
- * Copyright 2013, Norman Gray <http://nxg.me.uk>
+ * Copyright 2013, 2014, Norman Gray <http://nxg.me.uk>
  *
- * It is distributed under the terms of the GNU General Public
- * Licence.  See the file README.me for details.
+ * It is distributed under the terms of the BSD 2-clause licence.
+ * See the file README.md for details.
  */
 
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
-//#include <unistd.h>
-//#include <fcntl.h>
 #include <assert.h>
 #include <string.h>
-//#include <sys/stat.h>
-//#include <sys/mman.h>
 
 #include "util.h"