Rename json_{load,dump} to json_{load,dump}_file
authorPetri Lehtinen <petri@digip.org>
Tue, 28 Jul 2009 07:57:17 +0000 (10:57 +0300)
committerPetri Lehtinen <petri@digip.org>
Tue, 28 Jul 2009 07:58:13 +0000 (10:58 +0300)
src/dump.c
src/jansson.h
src/load.c
test/.gitignore
test/Makefile.am
test/load_file_dump_file.c [moved from test/load_dump.c with 81% similarity]
test/run-test

index e5af458..9645e9f 100644 (file)
@@ -225,20 +225,6 @@ static int do_dump(const json_t *json, uint32_t flags, int depth,
 }
 
 
-int json_dump(const json_t *json, const char *path, uint32_t flags)
-{
-    int result;
-
-    FILE *output = fopen(path, "w");
-    if(!output)
-        return -1;
-
-    result = json_dumpf(json, output, flags);
-
-    fclose(output);
-    return result;
-}
-
 char *json_dumps(const json_t *json, uint32_t flags)
 {
     strbuffer_t strbuff;
@@ -265,3 +251,17 @@ int json_dumpf(const json_t *json, FILE *output, uint32_t flags)
         return -1;
     return dump_to_file("\n", 1, (void *)output);
 }
+
+int json_dump_file(const json_t *json, const char *path, uint32_t flags)
+{
+    int result;
+
+    FILE *output = fopen(path, "w");
+    if(!output)
+        return -1;
+
+    result = json_dumpf(json, output, flags);
+
+    fclose(output);
+    return result;
+}
index e90491a..9b79892 100644 (file)
@@ -93,14 +93,14 @@ typedef struct {
     int line;
 } json_error_t;
 
-json_t *json_load(const char *path, json_error_t *error);
 json_t *json_loads(const char *input, json_error_t *error);
 json_t *json_loadf(FILE *input, json_error_t *error);
+json_t *json_load_file(const char *path, json_error_t *error);
 
 #define JSON_INDENT(n)   (n & 0xFF)
 
-int json_dump(const json_t *json, const char *path, uint32_t flags);
 char *json_dumps(const json_t *json, uint32_t flags);
 int json_dumpf(const json_t *json, FILE *output, uint32_t flags);
+int json_dump_file(const json_t *json, const char *path, uint32_t flags);
 
 #endif
index 975d7e9..d28721e 100644 (file)
@@ -734,25 +734,6 @@ json_t *parse_json(lex_t *lex, json_error_t *error)
     return parse_value(lex, error);
 }
 
-json_t *json_load(const char *path, json_error_t *error)
-{
-    json_t *result;
-    FILE *fp;
-
-    fp = fopen(path, "r");
-    if(!fp)
-    {
-        error_set(error, NULL, "unable to open %s: %s",
-                  path, strerror(errno));
-        return NULL;
-    }
-
-    result = json_loadf(fp, error);
-
-    fclose(fp);
-    return result;
-}
-
 typedef struct
 {
     const char *data;
@@ -821,3 +802,22 @@ json_t *json_loadf(FILE *input, json_error_t *error)
     lex_close(&lex);
     return result;
 }
+
+json_t *json_load_file(const char *path, json_error_t *error)
+{
+    json_t *result;
+    FILE *fp;
+
+    fp = fopen(path, "r");
+    if(!fp)
+    {
+        error_set(error, NULL, "unable to open %s: %s",
+                  path, strerror(errno));
+        return NULL;
+    }
+
+    result = json_loadf(fp, error);
+
+    fclose(fp);
+    return result;
+}
index 03b6f77..9a580ba 100644 (file)
@@ -1,4 +1,4 @@
-load_dump
 loadf_dumpf
 loads_dumps
+load_file_dump_file
 testlogs
index 865b1e9..16c5fd2 100644 (file)
@@ -1,4 +1,4 @@
-check_PROGRAMS = load_dump loadf_dumpf loads_dumps
+check_PROGRAMS = loadf_dumpf loads_dumps load_file_dump_file
 
 AM_CPPFLAGS = -I$(top_srcdir)/src
 AM_CFLAGS = -Wall -Werror
similarity index 81%
rename from test/load_dump.c
rename to test/load_file_dump_file.c
index 96995e5..5add119 100644 (file)
@@ -11,13 +11,13 @@ int main(int argc, char *argv[])
         return 2;
     }
 
-    json = json_load(argv[1], &error);
+    json = json_load_file(argv[1], &error);
     if(!json) {
         fprintf(stderr, "%d\n%s\n", error.line, error.text);
         return 1;
     }
 
-    json_dump(json, argv[2], 0);
+    json_dump_file(json, argv[2], 0);
     json_decref(json);
 
     return 0;
index aaaf2b7..2086c82 100644 (file)
@@ -8,7 +8,7 @@ run_testprog() {
     fi
 
     case "$prog" in
-        load_dump)
+        load_file_dump_file)
             $runner./$prog \
                 $prefix.in \
                 $prefix.$prog.stdout \
@@ -41,9 +41,9 @@ for testfile in $TESTFILES; do
     tmpdir="testlogs/`basename $testfile`"
     mkdir -p $tmpdir
     ${srcdir}/split-testfile.py $testfile $tmpdir | while read name; do
-        run_test load_dump $tmpdir/$name
         run_test loadf_dumpf $tmpdir/$name
         run_test loads_dumps $tmpdir/$name
+        run_test load_file_dump_file $tmpdir/$name
         echo -n '.'
     done || exit 1
     echo