Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : libs/engrave

Dir     : e17/libs/engrave/src/lib


Modified Files:
        engrave_data.c engrave_data.h engrave_file.c engrave_file.h 
        engrave_font.c engrave_font.h engrave_image.c engrave_image.h 
        engrave_out.c 


Log Message:
- fill out more of the api. Porting engrave_out.c over to use the new api.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_data.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- engrave_data.c      24 Oct 2004 07:06:37 -0000      1.3
+++ engrave_data.c      12 Nov 2004 07:28:29 -0000      1.4
@@ -20,3 +20,65 @@
   return data;
 }
 
+/**
+ * engrave_data_free - free the given data block
+ * @param ed: The Engrave_Data to free
+ *
+ * @return Returns no value.
+ */
+void
+engrave_data_free(Engrave_Data *ed)
+{
+  if (!ed) return;
+
+  if (ed->key) free(ed->key);
+  ed->key = NULL;
+
+  if (ed->value) free(ed->value);
+  ed->value = NULL;
+
+  free(ed);
+  ed = NULL;
+}
+
+/**
+ * engrave_data_key_get - get the key for this data
+ * @param ed: The Engrave_Data to get the key from
+ *
+ * @return Returns a pointer to the key for this data or 
+ * NULL on failure. This pointer must be free'd by the user.
+ */
+char *
+engrave_data_key_get(Engrave_Data *ed)
+{
+  if (!ed) return NULL;
+  return (ed->key ? strdup(ed->key) : NULL);
+}
+
+/**
+ * engrave_data_value_get - get the string value of the data object
+ * @param ed: The Engrave_Data to get the string value from.
+ *
+ * @return Returns a pointer to the string value of the data on success
+ * or NULL on failure. This pointer must be free'd by the user.
+ */
+char *
+engrave_data_value_get(Engrave_Data *ed)
+{
+  if (!ed) return NULL;
+  return (ed->value ? strdup(ed->value) : NULL);
+}
+
+/**
+ * engrave_data_int_value_get - get the int value of the data object
+ * @param ed: The Engrave_Data to get the value from
+ * 
+ * @return Returns the int value of the data or 0 if its not set.
+ */
+int
+engrave_data_int_value_get(Engrave_Data *ed)
+{
+  return (ed ? ed->int_value : 0);
+}
+
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_data.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- engrave_data.h      24 Oct 2004 07:06:37 -0000      1.2
+++ engrave_data.h      12 Nov 2004 07:28:29 -0000      1.3
@@ -28,6 +28,11 @@
 };
 
 Engrave_Data * engrave_data_new(char *key, char *value);
+void engrave_data_free(Engrave_Data *ed);
+
+char *engrave_data_key_get(Engrave_Data *ed);
+char *engrave_data_value_get(Engrave_Data *ed);
+int engrave_data_int_value_get(Engrave_Data *ed);
 
 /**
  * @}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_file.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- engrave_file.c      24 Oct 2004 07:06:37 -0000      1.4
+++ engrave_file.c      12 Nov 2004 07:28:29 -0000      1.5
@@ -104,3 +104,88 @@
   return NULL;
 }
 
+/**
+ * engrave_file_image_foreach - call the given function for each image object
+ * @param ef: The Engrave_File for which the images should be iterated over
+ * @param func: The function to call for each image
+ * @param data: Any user data to pass to the given function.
+ *
+ * @return Returns no value.
+ */
+void
+engrave_file_image_foreach(Engrave_File *ef, 
+                      void (*func)(Engrave_Image *, void *data),
+                      void *data)
+{
+  Evas_List *l;
+
+  for (l = ef->images; l; l = l->next) {
+    Engrave_Image *image = l->data;
+    if (image) func(image, data);
+  }
+}
+
+/**
+ * engrave_file_data_foreach - call the given function for each data object
+ * @param ef: The Engrave_File for which the data should be iterated over
+ * @param func: The function to call for each piece of data
+ * @param data: Any user data to pass to the given function.
+ *
+ * @return Returns no value.
+ */
+void
+engrave_file_data_foreach(Engrave_File *ef, 
+                        void (*func)(Engrave_Data *, void *data),
+                        void *udata)
+{
+  Evas_List *l;
+
+  for (l = ef->data; l; l = l->next) {
+    Engrave_Data *data = l->data;
+    if (data) func(data, udata);
+  }
+}
+
+/**
+ * engrave_file_group_foreach - call the given function for each group object
+ * @param ef: The Engrave_File for which the groups should be iterated over
+ * @param func: The function to call for each group
+ * @param data: Any user data to pass to the given function.
+ *
+ * @return Returns no value.
+ */
+void
+engrave_file_group_foreach(Engrave_File *ef, 
+                          void (*func)(Engrave_Group *, void *data),
+                          void *data)
+{
+  Evas_List *l;
+
+  for (l = ef->groups; l; l = l->next) {
+    Engrave_Group *group = l->data;
+    if (group) func(group, data);
+  }
+}
+
+/**
+ * engrave_file_font_foreach - call the given function for each font object
+ * @param ef: The Engrave_File for which the fonts should be iterated over
+ * @param func: The function to call for each font
+ * @param data: Any user data to pass to the given function.
+ *
+ * @return Returns no value.
+ */
+void
+engrave_file_font_foreach(Engrave_File *ef, 
+                            void (*func)(Engrave_Font *, void *data), 
+                            void *data)
+{
+  Evas_List *l;
+
+  for (l = ef->fonts; l; l = l->next) {
+    Engrave_Font *font = l->data;
+    if (font) func(font, data);
+  }
+}
+
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_file.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- engrave_file.h      24 Oct 2004 07:06:37 -0000      1.3
+++ engrave_file.h      12 Nov 2004 07:28:29 -0000      1.4
@@ -36,9 +36,22 @@
 
 Engrave_Group *engrave_file_group_last_get(Engrave_File *ef);
 
-Engrave_Image * engrave_file_image_by_name_find(Engrave_File *ef,
+Engrave_Image *engrave_file_image_by_name_find(Engrave_File *ef,
                                                       char *name);
 
+void engrave_file_image_foreach(Engrave_File *ef,
+                                    void (*func)(Engrave_Image *, void *),
+                                    void *data);
+void engrave_file_data_foreach(Engrave_File *ef,
+                                    void (*func)(Engrave_Data *, void *),
+                                    void *data);
+void engrave_file_group_foreach(Engrave_File *ef,
+                                    void (*func)(Engrave_Group *, void *),
+                                    void *data);
+void engrave_file_font_foreach(Engrave_File *ef,
+                                    void (*func)(Engrave_Font *, void *),
+                                    void *data);
+
 /**
  * @}
  */
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_font.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- engrave_font.c      24 Oct 2004 07:06:37 -0000      1.3
+++ engrave_font.c      12 Nov 2004 07:28:29 -0000      1.4
@@ -11,12 +11,62 @@
 Engrave_Font *
 engrave_font_new(char *path, char *name)
 {
-    Engrave_Font *ef;
-    ef = NEW(Engrave_Font, 1);
-    if (!ef) return NULL;
-
-    ef->name = (name ? strdup(name) : NULL);
-    ef->path = (path ? strdup(path) : NULL);
-    return ef;
+  Engrave_Font *ef;
+  ef = NEW(Engrave_Font, 1);
+  if (!ef) return NULL;
+
+  ef->name = (name ? strdup(name) : NULL);
+  ef->path = (path ? strdup(path) : NULL);
+  return ef;
+}
+
+/**
+ * engrave_font_free - free the memory
+ * @param ef: The Engrave_Font to free
+ *
+ * @return Returns no value
+ */
+void
+engrave_font_free(Engrave_Font *ef)
+{
+  if (!ef) return;
+
+  if (ef->name) free(ef->name);
+  ef->name = NULL;
+
+  if (ef->path) free(ef->path);
+  ef->path = NULL;
+
+  free(ef);
+  ef = NULL;
 }
 
+/**
+ * engrave_font_name_get - get the font name
+ * @param ef: The Engrave_Font to get the name from
+ *
+ * @return Returns a pointer to the name of the font
+ * on success or NULL on error. This pointer must be freed by the user.
+ */
+char *
+engrave_font_name_get(Engrave_Font *ef)
+{
+  if (!ef) return NULL;
+  return (ef->name ? strdup(ef->name) : NULL);
+}
+
+/**
+ * engrave_font_path_get - get the font path
+ * @param ef: The Engrave_Font to get the path from 
+ *
+ * @return Returns a pointer to the path on success 
+ * or NULL on error. This pointer must be freed by the user.
+ */
+char *
+engrave_font_path_get(Engrave_Font *ef)
+{
+  if (!ef) return NULL;
+  return (ef->path ? strdup(ef->path) : NULL);
+}
+
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_font.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- engrave_font.h      24 Oct 2004 20:46:30 -0000      1.3
+++ engrave_font.h      12 Nov 2004 07:28:29 -0000      1.4
@@ -27,6 +27,10 @@
 };
 
 Engrave_Font *engrave_font_new(char *path, char *name);
+void engrave_font_free(Engrave_Font *ef);
+
+char *engrave_font_name_get(Engrave_Font *ef);
+char *engrave_font_path_get(Engrave_Font *ef);
 
 /**
  * @}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_image.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- engrave_image.c     24 Oct 2004 23:03:48 -0000      1.4
+++ engrave_image.c     12 Nov 2004 07:28:29 -0000      1.5
@@ -33,8 +33,83 @@
 Engrave_Image *
 engrave_image_dup(Engrave_Image *from)
 {
-    Engrave_Image *to;
-    to = engrave_image_new(from->name, from->type, from->value);
-    return to;
+  Engrave_Image *to;
+  to = engrave_image_new(from->name, from->type, from->value);
+  return to;
 }
 
+/**
+ * engrave_image_free - free the image data
+ * @param ef: The Engrave_Image to free
+ *
+ * @return Returns no value.
+ */
+void
+engrave_image_free(Engrave_Image *ef)
+{
+  if (!ef) return;
+
+  if (ef->name) free(ef->name);
+  ef->name = NULL;
+
+  if (ef->path) free(ef->path);
+  ef->path = NULL;
+
+  free(ef);
+  ef = NULL;
+}
+
+/** 
+ * engrave_image_name_get - get the image name
+ * @param ei: The Engrave_Image to get the name from
+ * 
+ * @return Returns a pointer to the name of the image or NULL
+ * on error. This pointer must be free'd by the user.
+ */
+char *
+engrave_image_name_get(Engrave_Image *ei)
+{
+  if (!ei) return NULL;
+  return (ei->name ? strdup(ei->name) : NULL);
+}
+
+/**
+ * engrave_image_path_get - get the image path
+ * @param ei: The Engrave_Image to get the path from
+ * 
+ * @return Returns a pointer to the path of the image or NULL
+ * on error. This pointer must be free'd by the user.
+ */
+char *
+engrave_image_path_get(Engrave_Image *ei)
+{
+  if (!ei) return NULL;
+  return (ei->path ? strdup(ei->path) : NULL);
+}
+
+/**
+ * engrave_image_type_get - get the type of the image
+ * @param ei: The Engrave_Image to get the type from
+ * 
+ * @return Returns the Engrave_Image_Type associated with @a ei or
+ * ENGRAVE_IMAGE_TYPE_NUM if the type is not set.
+ */
+Engrave_Image_Type
+engrave_image_type_get(Engrave_Image *ei)
+{
+  return (ei ? ei->type : ENGRAVE_IMAGE_TYPE_NUM);
+}
+
+/**
+ * engrave_image_value_get - get the image compression value
+ * @param ei: The Engrave_Image to get the value from
+ *
+ * @return Returns the compression value of the image or 0 if not set.
+ */
+double
+engrave_image_value_get(Engrave_Image *ei)
+{
+  return (ei ? ei->value : 0.0);
+}
+
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_image.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- engrave_image.h     24 Oct 2004 23:03:48 -0000      1.3
+++ engrave_image.h     12 Nov 2004 07:28:29 -0000      1.4
@@ -31,6 +31,12 @@
 Engrave_Image *engrave_image_new(char *name, 
                     Engrave_Image_Type type, double value);
 Engrave_Image *engrave_image_dup(Engrave_Image *from);
+void engrave_image_free(Engrave_Image *ef);
+
+char *engrave_image_name_get(Engrave_Image *ei);
+char *engrave_image_path_get(Engrave_Image *ei);
+Engrave_Image_Type engrave_image_type_get(Engrave_Image *ei);
+double engrave_image_value_get(Engrave_Image *ei);
 
 /**
  * @}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_out.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- engrave_out.c       24 Oct 2004 20:46:30 -0000      1.9
+++ engrave_out.c       12 Nov 2004 07:28:29 -0000      1.10
@@ -3,10 +3,13 @@
 #include <stdarg.h>
 #include "Engrave.h"
 
-static void _engrave_output_group(Engrave_Group *group, FILE *out);
 static void _engrave_output_part(Engrave_Part *part, FILE *out);
 static void _engrave_output_program(Engrave_Program *program, FILE *out);
 static void _engrave_output_state(Engrave_Part *part, Engrave_Part_State 
*state, FILE *out);
+static void _engrave_output_image(Engrave_Image *image, void *data);
+static void _engrave_output_font(Engrave_Font *font, void *data);
+static void _engrave_output_data(Engrave_Data *data, void *udata);
+static void _engrave_output_group(Engrave_Group *group, void *data);
 
 static int level = 0;
 
@@ -152,12 +155,10 @@
 engrave_edc_output(Engrave_File *engrave_file, char *path)
 {
   FILE *out = NULL;
-  Evas_List *l;
   
   if (!engrave_file) return 0;
 
   out = fopen(path, "w");
-
   if (!out)
   {
     printf("can't open %s for writing\n", path);
@@ -166,67 +167,35 @@
 
   /* fonts */
   engrave_out_start(out, "fonts");
-  for (l = engrave_file->fonts; l; l = l->next)
-  {
-    Engrave_Font *font = l->data;
-    if (font)
-      engrave_out_data(out, "font", "\"%s\" \"%s\"", font->path, font->name);
-  }
+  engrave_file_font_foreach(engrave_file, _engrave_output_font, out);
   engrave_out_end(out);
 
   /* images */
   engrave_out_start(out, "images");
-  for (l = engrave_file->images; l; l = l->next)
-  {
-    Engrave_Image *image = l->data;
-    if (image)
-    {
-      if (image->type == ENGRAVE_IMAGE_TYPE_LOSSY)
-        engrave_out_data(out, "image", "\"%s\" %s %.2f", image->name,
-                _image_type_string[image->type],
-                image->value);
-      else
-        engrave_out_data(out, "image", "\"%s\" %s", image->name,
-                _image_type_string[image->type]);
-    }
-  }
+  engrave_file_image_foreach(engrave_file, _engrave_output_image, out);
   engrave_out_end(out);
 
   /* data */
   engrave_out_start(out, "data");
-  for (l = engrave_file->data; l; l = l->next)
-  {
-    Engrave_Data *data = l->data;
-    if (data)
-    {
-      if (data->value)
-        engrave_out_data(out, "item", "\"%s\" \"%s\"",
-                data->key, data->value);
-      else
-        engrave_out_data(out, "item", "\"%s\" %d",
-                data->key, data->int_value);
-    }
-  }
+  engrave_file_data_foreach(engrave_file, _engrave_output_data, out);
   engrave_out_end(out);
 
   /* collections */
   engrave_out_start(out, "collections");
-  for (l = engrave_file->groups; l; l = l->next)
-  {
-    Engrave_Group *group = l->data;
-    if (group) _engrave_output_group(group, out);
-  }
+  engrave_file_group_foreach(engrave_file, _engrave_output_group, out);
   engrave_out_end(out);
 
   fclose(out);
-
   return 1;
 }
 
 static void
-_engrave_output_group(Engrave_Group *group, FILE *out)
+_engrave_output_group(Engrave_Group *group, void *data)
 {
   Evas_List *l;
+  FILE *out;
+
+  out = data;
 
   engrave_out_start(out, "group");
 
@@ -553,4 +522,59 @@
   engrave_out_end(out);
 }
 
+static void
+_engrave_output_image(Engrave_Image *image, void *data)
+{
+  char *name;
+  FILE *out;
+
+  out = data;
+  name = engrave_image_name_get(image);
+
+  if (engrave_image_type_get(image) == ENGRAVE_IMAGE_TYPE_LOSSY)
+    engrave_out_data(out, "image", "\"%s\" %s %.2f", name,
+              _image_type_string[engrave_image_type_get(image)],
+              engrave_image_value_get(image));
+  else
+    engrave_out_data(out, "image", "\"%s\" %s", name,
+              _image_type_string[engrave_image_type_get(image)]);
+
+  if (name) free(name);
+}
+
+static void
+_engrave_output_font(Engrave_Font *font, void *data)
+{
+  char *name, *path;
+  FILE *out;
+
+  out = data;
+  name = engrave_font_name_get(font);
+  path = engrave_font_path_get(font);
+
+  engrave_out_data(out, "font", "\"%s\" \"%s\"", path, name);
+  if (name) free(name);
+  if (path) free(path);
+}
+
+static void
+_engrave_output_data(Engrave_Data *data, void *udata)
+{
+  char *key, *value;
+  FILE *out;
+
+  out = udata;
+  key = engrave_data_key_get(data);
+  value = engrave_data_value_get(data);
+
+  if (value)
+    engrave_out_data(out, "item", "\"%s\" \"%s\"", key, value);
+  else
+    engrave_out_data(out, "item", "\"%s\" %d",
+                            key, engrave_data_int_value_get(data));
+
+  free(key);
+  free(value);
+}
+
 




-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to