yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=1c6671f6fb18c4358f1a6ae9b395b8bf23415c90

commit 1c6671f6fb18c4358f1a6ae9b395b8bf23415c90
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Sun Nov 15 15:13:18 2015 +0200

    Add json_file_generate(const Gui_Context *ctx, const char *filename) API
    
    Add API to be able to provide filename as a parameter
---
 src/lib/json_generator.c | 40 ++++++++++++++++++++++++----------------
 src/lib/json_generator.h |  3 +++
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/lib/json_generator.c b/src/lib/json_generator.c
index d319f83..54f80b8 100644
--- a/src/lib/json_generator.c
+++ b/src/lib/json_generator.c
@@ -660,35 +660,43 @@ _context_json_generate(const Gui_Context *ctx)
    return root_obj;
 }
 
-/* Save context into "project" files. */
-void
-json_generate(const Gui_Context *ctx)
+Eina_Bool
+json_file_generate(const Gui_Context *ctx, const char *filename)
 {
+   Eina_Bool ret = EINA_FALSE;
+   FILE *fp_json = fopen(filename, "w+");
    char *json_str = NULL;
 
-   /*Add JSON generation of all Context. */
-   Eina_Json_Value *root_obj = _context_json_generate(ctx);
-   json_str = eina_json_format_string_get(root_obj, EINA_JSON_FORMAT_BASIC);
-   eina_json_value_free(root_obj);
-
-   const char *path = gui_context_project_path_get(ctx);
-   const char *filename = gui_context_project_filename_get(ctx);
-   char *filename_json = (char *) calloc(strlen(path) + strlen(filename) + 2, 
1);
-   sprintf(filename_json, "%s/%s", path, filename);
-   FILE *fp_json = fopen(filename_json, "w+");
-
    if (!fp_json)
      {
-        ERR("Can't create file: %s", filename_json);
+        ERR("Can't create file: %s", filename);
         goto end;
      }
 
+   /*Add JSON generation of all Context. */
+   Eina_Json_Value *root_obj = _context_json_generate(ctx);
+   json_str = eina_json_format_string_get(root_obj, EINA_JSON_FORMAT_BASIC);
+   eina_json_value_free(root_obj);
+
    fprintf(fp_json, "%s", json_str);
+   ret = EINA_TRUE;
 
 end:
    if (json_str) free(json_str);
    if (fp_json) fclose(fp_json);
-   free(filename_json);
+   return ret;
+}
+
+/* Save context into "project" files. */
+void
+json_generate(const Gui_Context *ctx)
+{
+   EINA_SAFETY_ON_NULL_RETURN(ctx);
+   const char *path = gui_context_project_path_get(ctx);
+   const char *filename = gui_context_project_filename_get(ctx);
+   char filename_json[PATH_MAX];
+   sprintf(filename_json, "%s/%s", path, filename);
+   json_file_generate(ctx, filename_json);
 }
 
 char *
diff --git a/src/lib/json_generator.h b/src/lib/json_generator.h
index 5e33465..764bfb1 100644
--- a/src/lib/json_generator.h
+++ b/src/lib/json_generator.h
@@ -5,6 +5,9 @@
 
 void json_generate(const Gui_Context *ctx);
 
+Eina_Bool
+json_file_generate(const Gui_Context *ctx, const char *filename);
+
 char *
 json_widget_generate(Eid *wdg_id);
 

-- 


Reply via email to