Browse Source

Removed parse_json_file

Sergey Lyubka 11 years ago
parent
commit
e66a7f1360
4 changed files with 5 additions and 52 deletions
  1. 5 7
      README.md
  2. 0 25
      frozen.c
  3. 0 1
      frozen.h
  4. 0 19
      unit_test.c

+ 5 - 7
README.md

@@ -16,7 +16,7 @@ JSON parser and generator for C/C++
    1. Copy `frozen.c` and `frozen.h` to your project
    2. Add `frozen.c` to the list of source files
    3. Parsing with Frozen is done in two steps: first, split JSON string
-      into tokens by `parse_json()`, `parse_json2()` or `parse_json_file()`.
+      into tokens by `parse_json()` or `parse_json2()`.
       Second, search for certain
       parameters in parsed string by `find_json_token()`. Below is an example,
       error handling is omitted for clarity:
@@ -47,11 +47,10 @@ JSON parser and generator for C/C++
     int parse_json(const char *json_string, int json_string_length,
                    struct json_token *tokens_array, int size_of_tokens_array);
     struct json_token *parse_json2(const char *json_string, int string_length);
-    struct json_token *parse_json_file(const char *path);
 
-`parse_json()` and `parse_json2()` parse a string, `parse_json_file()` parses
-file. `parse_json()` needs pre-allocated tokens array or NULL, whereas
-`parse_json2()` and `parse_json_file()` allocate tokens array automatically.
+`parse_json()` and `parse_json2()` parse JSON string.
+`parse_json()` needs pre-allocated tokens array or NULL, whereas
+`parse_json2()` allocates tokens array automatically.
 
 
 `parse_json()` tokenizes `json_string` of length `json_string_length`.
@@ -89,8 +88,7 @@ returned, one of:
     #define JSON_STRING_INCOMPLETE        -2
     #define JSON_TOKEN_ARRAY_TOO_SMALL    -3
 
-`parse_json2()` and `parse_json_file()` return NULL on error
-and non-NULL on success.
+`parse_json2()` returns NULL on error and non-NULL on success.
 
 Below is an illustration on how JSON string gets tokenized:
 

+ 0 - 25
frozen.c

@@ -308,31 +308,6 @@ struct json_token *parse_json2(const char *s, int s_len) {
   return frozen.tokens;
 }
 
-struct json_token *parse_json_file(const char *path) {
-  FILE *fp;
-  char *file_data = NULL, buf[BUFSIZ];
-  int n, buf_size = 0, file_size = 0;
-  struct json_token *result;
-
-  if ((fp = fopen(path, "rb")) == NULL) return NULL;
-  while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
-    if (buf_size - file_size < n) {
-      int new_size = buf_size == 0 ? sizeof(buf) : buf_size * 2;
-      void *p = FROZEN_REALLOC(file_data, new_size);
-      if (p == NULL) { fclose(fp); return NULL; }
-      file_data = (char *) p;
-      buf_size = new_size;
-    }
-    memcpy(file_data + file_size, buf, n);
-    file_size += n;
-  }
-  fclose(fp);
-
-  result = parse_json2(file_data, file_size);
-  FROZEN_FREE((char *) file_data);
-  return result;
-}
-
 static int path_part_len(const char *p) {
   int i = 0;
   while (p[i] != '\0' && p[i] != '[' && p[i] != '.') i++;

+ 0 - 1
frozen.h

@@ -49,7 +49,6 @@ int parse_json(const char *json_string, int json_string_length,
                struct json_token *tokens_array, int size_of_tokens_array);
 
 struct json_token *parse_json2(const char *json_string, int string_length);
-struct json_token *parse_json_file(const char *path);
 
 const struct json_token *find_json_token(const struct json_token *toks,
                                          const char *path);

+ 0 - 19
unit_test.c

@@ -249,24 +249,6 @@ static const char *test_realloc(void) {
   return NULL;
 }
 
-static const char *test_file(void) {
-  static const char *test_file_name = "test.json";
-  struct json_token *p;
-  FILE *fp;
-
-  ASSERT((p = parse_json_file(test_file_name)) == NULL);
-
-  ASSERT((fp = fopen(test_file_name, "w+")) != NULL);
-  fprintf(fp, "%s\n", "{ foo: 1, bar: [1, 2, 3] }");
-  fclose(fp);
-
-  ASSERT((p = parse_json_file(test_file_name)) != NULL);
-  free(p);
-  remove(test_file_name);
-
-  return NULL;
-}
-
 static const char *run_all_tests(void) {
   RUN_TEST(test_errors);
   RUN_TEST(test_config);
@@ -275,7 +257,6 @@ static const char *run_all_tests(void) {
   RUN_TEST(test_emit_overflow);
   RUN_TEST(test_nested);
   RUN_TEST(test_realloc);
-  RUN_TEST(test_file);
   return NULL;
 }