Enlightenment CVS committal

Author  : azundris
Project : misc
Module  : erss

Dir     : misc/erss/src


Modified Files:
        erss.c erss.h gui.c gui.h net.c parse.c parse.h parse_config.c 
        parse_config.h 


Log Message:
* refactoring: remove "cfg" global (per-stream config, now p/o feed)
* clicking on a tooltip closes it

===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/erss.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -3 -r1.38 -r1.39
--- erss.c      21 Feb 2004 11:12:18 -0000      1.38
+++ erss.c      26 Feb 2004 21:05:32 -0000      1.39
@@ -1,23 +1,28 @@
 #include "erss.h"
-#include "parse_config.h"
-#include "net.h"
-#include "ls.h"
-#include "gui.h"
+#include "parse_config.h"     /* rc, erss_parse_config_file(), erss_parse_rc_file() */
+#include "parse.h"            /* erss_parse_free() */
+#include "net.h"              /* erss_net_connect(), erss_net_poll() */
+#include "ls.h"               /* erss_list_config_files() */
+#include "gui.h"              /* erss_gui_init(), erss_gui_exit() */
+
+
 
 Ewd_List    *config_files=NULL;
+char        *theme=NULL;
+
 
 
 #if 0
-static void erss_xml_error_handler (void *ctx, const char *msg, ...)
-{
+static void erss_xml_error_handler (void *ctx, const char *msg, ...) {
        fprintf (stderr, "%s xml report: %s\n", PACKAGE, msg);
 
        return;
 }
 #endif
 
-static int erss_handler_signal_exit (void *data, int ev_type, void *ev)
-{
+
+
+static int erss_handler_signal_exit (void *data, int ev_type, void *ev) {
        Ecore_Event_Signal_Exit *e = ev;
 
        if (e->interrupt)
@@ -32,8 +37,9 @@
        return 1;
 }
 
-char *erss_time_format () 
-{
+
+
+char *erss_time_format () {
        char    *str;
        struct  tm  *ts;
        time_t  curtime;
@@ -49,28 +55,103 @@
        return str;
 }
 
-static void erss_display_default_usage ()
-{
+
+
+static void erss_display_default_usage () {
        fprintf (stderr, "Usage: %s [OPTION] ...\n", PACKAGE);
        fprintf (stderr, "Try `%s -h` for more information\n", PACKAGE);
        exit (-1);
 }
 
-int main (int argc, char * const argv[])
-{
-       int         c = 0;
-       int         got_config_file = FALSE;
-       int         got_theme_file = FALSE;
-       int         got_rc_file = FALSE;
-       char        config_file[PATH_MAX];
-       char        theme_file[PATH_MAX];
-       char       *config=NULL;
-       struct stat statbuf;
-       Erss_Feed   f;
 
-       memset(&f,0,sizeof(Erss_Feed));
 
-       cfg = NULL;
+static Erss_Feed *erss_feed_dst(Erss_Feed **feed) {
+       Erss_Feed *f;
+
+       if((feed != NULL) && ((f=*feed) != NULL)) {
+               *feed = NULL;
+
+               if(f->cfg)
+                       erss_cfg_dst(&f->cfg);
+
+               if(f->main_buffer)
+                       free(f->main_buffer);
+
+               if(f->last_time)
+                       free(f->last_time);
+
+               erss_parse_free (f);
+
+               erss_gui_items_drop(&f->list);
+
+               memset(f,0,sizeof(Erss_Feed));
+               free(f);
+       }
+       return NULL;
+}
+
+
+
+static Erss_Feed *erss_feed_new(char *config_file, char *theme_file) {
+       Erss_Feed *f=malloc(sizeof(Erss_Feed));
+
+       if(f == NULL)
+               return f;
+
+       memset(f,0,sizeof(Erss_Feed));
+
+       f->cfg = erss_parse_config_file (config_file);
+       if(f->cfg == NULL) {
+               fprintf (stderr, "%s error: failed parse config file '%s'!\n", 
PACKAGE, config_file);
+               goto fail;
+       }
+
+       if(theme_file != NULL) {
+               char *t = strdup(theme_file);
+               if(t == NULL) {
+                       fprintf (stderr, "%s error: out of memory!\n", PACKAGE);
+                       goto fail;
+               }
+               if(f->cfg->theme != NULL)
+                       free(f->cfg->theme);
+               f->cfg->theme = t;
+       }
+       if(f->cfg->theme == NULL) {
+               fprintf (stderr, "%s error: no theme for '%s'!\n", PACKAGE, 
config_file);
+               goto fail;
+       }
+
+       return f;
+
+  fail:
+       erss_feed_dst(&f);
+       return NULL;
+}
+
+
+
+static int erss_feed_start(Erss_Feed *f) {
+       erss_net_connect(f);
+       erss_net_poll(f);
+       ecore_timer_add (f->cfg->update_rate, erss_net_poll, f);
+       return TRUE;
+}
+
+
+
+
+
+
+int main (int argc, char * const argv[]) {
+       int          c = 0;
+       int          got_config_file = FALSE;
+       int          got_theme_file = FALSE;
+       int          got_rc_file = FALSE;
+       char         config_file[PATH_MAX];
+       char         theme_file[PATH_MAX];
+       char        *config = NULL;
+       struct stat  statbuf;
+       Erss_Feed   *f = NULL;
 
        /*
         * Disable this for now..
@@ -117,44 +198,50 @@
        if (erss_parse_rc_file ()) 
                got_rc_file = TRUE;
                
-       if(!got_config_file) {
-               
-               if (!got_rc_file || !rc->config)
-                       erss_display_default_usage ();
-               else
-                       erss_parse_config_file (config=rc->config);
 
-       } else
-               erss_parse_config_file (config=config_file);
-       
+
        if (!got_theme_file) {
                if (!got_rc_file) 
-                       cfg->theme = strdup (PACKAGE_DATA_DIR"/default.eet");
+                       theme = strdup (PACKAGE_DATA_DIR"/default.eet");
                else
-                       cfg->theme = strdup (rc->theme);
+                       theme = strdup (rc->theme);
        }
        else
-               cfg->theme = strdup (theme_file);
+               theme = strdup (theme_file);
 
-       stat (cfg->theme, &statbuf);
+       stat (theme, &statbuf);
        if (!S_ISREG(statbuf.st_mode)) {
-               printf ("%s error: themefile '%s' does not exist!\n", 
-                               PACKAGE, cfg->theme);
+               fprintf (stderr, "%s error: themefile '%s' does not exist!\n", 
+                               PACKAGE, theme);
                exit (-1);
        }
 
 
 
+       if(!got_config_file) {
+               if (!got_rc_file || !rc->config)
+                       erss_display_default_usage ();
+               else
+                       config=rc->config;
+
+       } else
+               config=config_file;
+       
+
+
        ecore_init ();
        ecore_event_handler_add (ECORE_EVENT_SIGNAL_EXIT,erss_handler_signal_exit, 
NULL);
-       if (!ecore_con_init ()) return -1;
+       if (!ecore_con_init ())
+               return -1;
        ecore_app_args_set (argc, (const char **) argv);
-       erss_gui_init(config);
-
-       erss_net_connect(&f);
-       erss_net_poll (&f);
-       ecore_timer_add (cfg->update_rate, erss_net_poll, &f);
 
+       f=erss_feed_new(config, theme);
+       if(f == NULL)
+               fprintf (stderr, "%s error: failed to add feed '%s'!\n", PACKAGE, 
config);
+       else {
+               erss_gui_init(config, f->cfg);
+               erss_feed_start(f);
+       }
        ecore_main_loop_begin ();
 
        erss_gui_exit();
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/erss.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- erss.h      21 Feb 2004 11:12:18 -0000      1.13
+++ erss.h      26 Feb 2004 21:05:32 -0000      1.14
@@ -42,6 +42,34 @@
 
 
 
+typedef struct _erss_config {
+       char *header;
+       char *hostname;
+       char *url;
+
+       char *item_root;
+       char *item_start;
+       char *item_title;
+       char *item_url;
+       char *item_description;
+
+       int   update_rate;
+       int   clock;
+       int   num_stories;
+
+       int   x;
+       int   y;
+
+       int   borderless;
+
+       char *prefix;
+
+       char *theme;
+       char *config;
+} Erss_Config;
+
+
+
 typedef struct _erss_article {
   Evas_Object *obj;
   char        *title;
@@ -62,6 +90,7 @@
   Ewd_List         *list;
   xmlDocPtr         doc;
   Erss_Article     *item;
+  Erss_Config      *cfg;
 } Erss_Feed;
 
 
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/gui.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- gui.c       21 Feb 2004 11:12:18 -0000      1.2
+++ gui.c       26 Feb 2004 21:05:32 -0000      1.3
@@ -1,5 +1,5 @@
 #include "erss.h"
-#include "parse_config.h"      /* rc, cfg */
+#include "parse_config.h"      /* rc */
 #include "tooltip.h"           /* Erss_Tooltip, erss_tooltip_new() */
 
 
@@ -109,9 +109,10 @@
                                         void *event_info)
 {
        Ecore_X_Window win;
+       Erss_Feed *f = (Erss_Feed *) data;
 
        win = ecore_evas_software_x11_window_get(ee);
-       if (cfg->item_url)
+       if ((f != NULL) && (f->cfg->item_url != NULL))
                ecore_x_cursor_shape_set(win, ECORE_X_CURSOR_HAND2);
 }
 
@@ -129,23 +130,23 @@
 
 
 
-erss_gai_error erss_gui_add_item(Erss_Feed *f,Erss_Article *item) {
+static erss_gai_error erss_gui_item_new(Erss_Feed *f,Erss_Article *item) {
   if(!f)
     return ERSS_GAI_NOFEED;
   if(!item)
     return ERSS_GAI_NOITEM;
 
-  /* fprintf(stderr, "%s: %p -- %s\n", __FUNCTION__, item, item->title); */
+/* fprintf(stderr, "%s: %p -- %s\n", __FUNCTION__, item, item->title); */
 
   if(item->title) {
     item->obj = edje_object_add (evas);
-    edje_object_file_set (item->obj, cfg->theme, "erss_item");
+    edje_object_file_set (item->obj, f->cfg->theme, "erss_item");
     evas_object_show (item->obj);
 
     evas_object_event_callback_add (item->obj,
-                                   EVAS_CALLBACK_MOUSE_IN, 
erss_mouse_in_cursor_change, NULL);
+                                   EVAS_CALLBACK_MOUSE_IN, 
erss_mouse_in_cursor_change, f);
     evas_object_event_callback_add (item->obj,
-                                   EVAS_CALLBACK_MOUSE_OUT, 
erss_mouse_out_cursor_change, NULL);
+                                   EVAS_CALLBACK_MOUSE_OUT, 
erss_mouse_out_cursor_change, f);
 
     e_container_element_append(cont, item->obj);
     edje_object_part_text_set (item->obj, "article", item->title);
@@ -166,7 +167,7 @@
 
 
 
-int erss_gui_add_items(Erss_Feed *f) {
+int erss_gui_items_add(Erss_Feed *f) {
   int c=0;
 
   if (!f)
@@ -175,7 +176,7 @@
   if (f->list) {
     Erss_Article *item = ewd_list_goto_first (f->list);
     while ((item = ewd_list_next(f->list))) {
-      if(erss_gui_add_item(f,item)==ERSS_GAI_SUCC)
+      if(erss_gui_item_new(f,item)==ERSS_GAI_SUCC)
        c++;
     }
   }
@@ -184,10 +185,55 @@
 
 
 
+static Erss_Article *erss_gui_item_dst(Erss_Article **i) {
+       Erss_Article *item;
 
 
+       if((i != NULL) && ((item=*i) != NULL)) {
+               *i = NULL;
 
-int erss_gui_init (char *config) {
+               if (item->obj)
+                       e_container_element_destroy (cont, item->obj);
+
+               if (item->title)
+                       free (item->title);
+
+               if (item->url)
+                       free (item->url);
+
+               if (item->description)
+                       free (item->description);
+
+               free (item);
+       }
+
+       return NULL;
+}
+
+
+
+int erss_gui_items_drop(Ewd_List **l) {
+       Ewd_List     *list;
+       Erss_Article *item;
+
+       if ((l == NULL) || ((list=*l) == NULL))
+               return FALSE;
+
+       item = ewd_list_goto_first (list);
+       while ((item = ewd_list_next(list)))
+               erss_gui_item_dst(&item);
+
+       ewd_list_remove (list);
+
+       return TRUE;
+}
+
+
+
+
+
+
+int erss_gui_init (char *winname, Erss_Config *cfg) {
        Ecore_X_Window  win;
        Evas_Object    *header;
        char            title[PATH_MAX];
@@ -195,13 +241,17 @@
        int             height,width;
 
        ecore_x_init (NULL);
-       if (!ecore_evas_init ()) return -1;
+
+       if (!ecore_evas_init ())
+               return -1;
 
        width = 300;
        height = 16 * cfg->num_stories;
 
+       printf("stories in %s: %d\n",winname,cfg->num_stories);
+
        if (cfg->header) height += 26;
-       if (cfg->clock) height += 26;
+       if (cfg->clock)  height += 26;
 
        ee = ecore_evas_software_x11_new (NULL, 0, 0, 0, width, height);
        win = ecore_evas_software_x11_window_get(ee);
@@ -210,7 +260,7 @@
                return -1;
 
        ecore_evas_borderless_set (ee, cfg->borderless);
-       snprintf(title, PATH_MAX, "erss - %s", config);
+       snprintf(title, PATH_MAX, "erss - %s", winname);
        ecore_evas_title_set (ee, title);
        ecore_x_window_prop_layer_set(win, ECORE_X_WINDOW_LAYER_BELOW);
        ecore_evas_show (ee);
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/gui.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- gui.h       21 Feb 2004 11:12:18 -0000      1.2
+++ gui.h       26 Feb 2004 21:05:32 -0000      1.3
@@ -2,7 +2,8 @@
 
 int  erss_set_time (void *);
 
-int  erss_gui_add_items(Erss_Feed *);
+int  erss_gui_items_add(Erss_Feed *);
+int  erss_gui_items_drop(Ewd_List **);
 
-int  erss_gui_init (char *);
+int  erss_gui_init (char *, Erss_Config *);
 int  erss_gui_exit (void);
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/net.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- net.c       25 Feb 2004 17:02:57 -0000      1.4
+++ net.c       26 Feb 2004 21:05:32 -0000      1.5
@@ -1,6 +1,6 @@
 #include "erss.h"
 #include "parse.h"             /* erss_parse() */
-#include "parse_config.h"      /* cfg, rc */
+#include "parse_config.h"      /* rc */
 #include "gui.h"               /* erss_set_time(), erss_gui_add_items() */
 
 int erss_net_poll (void *data)
@@ -19,12 +19,12 @@
        if (f->last_time)
                free (f->last_time);
        else
-               printf ("%s info: connecting to %s...\n", PACKAGE, 
cfg->hostname?cfg->hostname:"host");
+               printf ("%s info: connecting to %s...\n", PACKAGE, 
f->cfg->hostname?f->cfg->hostname:"host");
 
        if (rc->proxy) {
                if (!strcasecmp (rc->proxy, ""))
                        f->server = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
-                                                             cfg->hostname, 80, NULL);
+                                                             f->cfg->hostname, 80, 
NULL);
                else {
                        if (!rc->proxy_port)
                                fprintf (stderr, "%s error: You need to define a proxy 
port!\n", PACKAGE);
@@ -34,7 +34,7 @@
                }
        } else
                f->server = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
-                                                     cfg->hostname, 80, NULL);
+                                                     f->cfg->hostname, 80, NULL);
 
        if (!f->server)
                fprintf (stderr, "%s error: Could not connect to server ..\n", 
PACKAGE);
@@ -56,11 +56,11 @@
         * We want to be connected before sending the request.
         */
        if (f->total_connects == 1)
-               printf ("%s info: requesting \"%s\"...\n", PACKAGE, 
cfg->url?cfg->url:"feed");
+               printf ("%s info: requesting \"%s\"...\n", PACKAGE, 
f->cfg->url?f->cfg->url:"feed");
        
-       snprintf (c, sizeof (c), "GET %s HTTP/1.0\r\n", cfg->url);
+       snprintf (c, sizeof (c), "GET %s HTTP/1.0\r\n", f->cfg->url);
        ecore_con_server_send (f->server, c, strlen (c));
-       snprintf (c, sizeof (c), "Host: %s\r\n", cfg->hostname);
+       snprintf (c, sizeof (c), "Host: %s\r\n", f->cfg->hostname);
        ecore_con_server_send (f->server, c, strlen (c));
        snprintf (c, sizeof (c), "User-Agent: %s/%s\r\n\r\n",
                  PACKAGE, VERSION);
@@ -77,7 +77,7 @@
        Ecore_Con_Event_Server_Data *e = event;
 
        if (f->total_connects == 1)
-               printf ("%s info: reading \"%s\" (%ld octets)...\n", PACKAGE, 
cfg->header?cfg->header:"feed", (long)e->size);
+               printf ("%s info: reading \"%s\" (%ld octets)...\n", PACKAGE, 
f->cfg->header?f->cfg->header:"feed", (long)e->size);
 
        /* 
         * Read everything we receive into one big buffer, and handle
@@ -92,14 +92,13 @@
 
 static int erss_net_server_del (void *data, int type, void *event)
 {
-       Erss_Feed                  *f=(Erss_Feed *)data;
+       Erss_Feed                  *f = (Erss_Feed *)data;
        Ecore_Con_Event_Server_Del *e = event;
-       char         *buf = f->main_buffer;
-       char         *temp;
-       Erss_Article *item;
+       char                       *buf = f->main_buffer;
+       char                       *temp;
 
        if (f->total_connects == 1)
-               printf ("%s info: disconnecting from %s...\n", PACKAGE, 
cfg->hostname?cfg->hostname:"host");
+               printf ("%s info: disconnecting from %s...\n", PACKAGE, 
f->cfg->hostname?f->cfg->hostname:"host");
 
        /*
         * Now split our buffer in each newline and then parse the line.
@@ -109,37 +108,7 @@
         * Clean out the evas objects from the container to
         * make room for the new items.
         */
-       if (f->list) {
-               item = ewd_list_goto_first (f->list);
-               while ((item = ewd_list_next(f->list))) {
-
-                       /*
-                        * Remove the evas object from the list 
-                        * and destory it.
-                        */
-
-                       if (item->obj)
-                               e_container_element_destroy (cont, item->obj);
-
-                       if (item->title)
-                               free (item->title);
-
-                       if (item->url)
-                               free (item->url);
-
-                       if (item->description)
-                               free (item->description);
-
-                       free (item);
-               }
-
-               /* 
-                * Remove the list, we want to build a new one for 
-                * the next connection.
-                */
-               ewd_list_remove (f->list);
-               f->list = NULL;
-       }
+       erss_gui_items_drop(&f->list);
 
        f->item = NULL;
        f->list = ewd_list_new ();
@@ -148,7 +117,7 @@
        f->doc = xmlParseMemory (temp, f->main_bufsize - (temp - f->main_buffer));
 
        erss_parse (f);
-       erss_gui_add_items (f);
+       erss_gui_items_add (f);
 
        ecore_con_server_del (e->server);
        f->server = NULL;
@@ -157,7 +126,7 @@
                if (buf)
                        printf ("%s\n", temp);
                else 
-                       printf ("%s error: could not connect to '%s'\n", PACKAGE, 
cfg->url);
+                       printf ("%s error: could not connect to '%s'\n", PACKAGE, 
f->cfg->url);
 
                fprintf (stderr, "\n%s error: parsing data\n", PACKAGE);
                fprintf (stderr, "%s error: are you sure you have to correct input in 
your config file?\n", PACKAGE);
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -3 -r1.27 -r1.28
--- parse.c     21 Feb 2004 11:12:18 -0000      1.27
+++ parse.c     26 Feb 2004 21:05:32 -0000      1.28
@@ -1,10 +1,9 @@
 #include "erss.h"
 #include "parse.h"          /* ERSS_PARSE_* */
-#include "parse_config.h"   /* cfg */
 
 
 
-static Erss_Article *erss_story_new (Erss_Feed *f)
+static Erss_Article *erss_parse_story_new (Erss_Feed *f)
 {
        f->item=malloc(sizeof(Erss_Article));
        memset(f->item,0,sizeof(Erss_Article));
@@ -15,13 +14,13 @@
        return f->item;
 }
 
-static void erss_story_end (Erss_Feed *f)
+static void erss_parse_story_end (Erss_Feed *f)
 {
        ewd_list_append (f->list, f->item);
        f->item = NULL;
 }
 
-static char *erss_desc_clean (char *description) {
+static char *erss_parse_desc_clean (char *description) {
        /* remove potential tags. not using libXML here, contents may not
           be well-formed...  */
 
@@ -49,9 +48,10 @@
 
 static void erss_parse_story (Erss_Feed *f, xmlNodePtr cur)
 {
-       char    *text;
-       xmlChar *str;
-       int      i;
+       char        *text;
+       xmlChar     *str;
+       int          i;
+       Erss_Config *cfg=f->cfg;
 
        cur = cur->xmlChildrenNode;
 
@@ -61,9 +61,9 @@
                        return;
 
                if (!strcmp(cur->name, cfg->item_start)) {
-                       erss_story_new (f);
+                       erss_parse_story_new (f);
                        erss_parse_story (f, cur);
-                       erss_story_end (f);
+                       erss_parse_story_end (f);
                }
 
                if ((!strcmp(cur->name, cfg->item_title)) && f->item) {
@@ -92,7 +92,7 @@
                                char *desc;
 
                                if((str = xmlNodeListGetString(f->doc, 
cur->xmlChildrenNode, 1))) {
-                                       if((desc = erss_desc_clean(str)))
+                                       if((desc = erss_parse_desc_clean(str)))
                                                f->item->description=desc;
                                        xmlFree (str);
                                }
@@ -103,10 +103,25 @@
        }
 }
 
+
+
+int erss_parse_free (Erss_Feed *f) {
+       if(f->item)
+               erss_parse_story_end(f);
+       if(f->doc) {
+               xmlFreeDoc(f->doc);
+               f->doc = NULL;
+       }
+       return TRUE;
+}
+
+
+
 int erss_parse (Erss_Feed *f)
 {
-       xmlNodePtr cur;
-       int        ret;
+       xmlNodePtr   cur;
+       int          ret;
+       Erss_Config *cfg = f->cfg;
 
        if (f->doc == NULL ) {
                fprintf(stderr, "%s warn: buffer not parsed successfully.\n", PACKAGE);
@@ -135,15 +150,15 @@
                                erss_parse_story (f, cur);
                        }
                } else if (!strcmp(cur->name, cfg->item_start)) {
-                       erss_story_new (f);
+                       erss_parse_story_new (f);
                        erss_parse_story (f, cur);
-                       erss_story_end (f);
+                       erss_parse_story_end (f);
                }
 
                cur = cur->next;
        }
 
-       xmlFreeDoc(f->doc);
+       erss_parse_free(f);
 
        return ret;
 }
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- parse.h     21 Feb 2004 11:12:18 -0000      1.11
+++ parse.h     26 Feb 2004 21:05:32 -0000      1.12
@@ -7,3 +7,4 @@
 } erss_parse_error;
 
 int erss_parse (Erss_Feed *);
+int erss_parse_free (Erss_Feed *);
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse_config.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- parse_config.c      21 Feb 2004 11:12:18 -0000      1.5
+++ parse_config.c      26 Feb 2004 21:05:32 -0000      1.6
@@ -2,7 +2,6 @@
 #include "parse_config.h"      /* Erss_Config, Erss_Rc_Config  */
 #include "ls.h"                /* erss_list_config_files() */
 
-Erss_Config    *cfg = NULL;
 Erss_Rc_Config *rc = NULL;
 
 
@@ -101,13 +100,37 @@
 
 
 
-void erss_parse_config_file (char *file)
+Erss_Config *erss_cfg_dst (Erss_Config **c) {
+       Erss_Config *cfg;
+       if((c != NULL) && ((cfg=*c) != NULL)) {
+               if(cfg->header)           free(cfg->header);
+               if(cfg->hostname)         free(cfg->hostname);
+               if(cfg->url)              free(cfg->url);
+               if(cfg->item_root)        free(cfg->item_root);
+               if(cfg->item_start)       free(cfg->item_start);
+               if(cfg->item_title)       free(cfg->item_title);
+               if(cfg->item_url)         free(cfg->item_url);
+               if(cfg->item_description) free(cfg->item_description);
+               if(cfg->prefix)           free(cfg->prefix);
+               if(cfg->theme)            free(cfg->theme);
+               if(cfg->config)           free(cfg->config);
+
+               memset(cfg,0,sizeof(Erss_Config));
+               *c = NULL;
+       }
+       return NULL;
+}
+
+
+
+Erss_Config *erss_parse_config_file (char *file)
 {
-       xmlDocPtr doc;
-       xmlNodePtr cur;
-       xmlChar *str = NULL;
-       char *tmp;
-       int match = FALSE;
+       xmlDocPtr    doc;
+       xmlNodePtr   cur;
+       xmlChar     *str = NULL;
+       char        *tmp;
+       int          match = FALSE;
+       Erss_Config *cfg = NULL;
 
        /*
         * Look in the list of config files and try to
@@ -152,12 +175,13 @@
         * Now allocate and fill the config struct
         */
        cfg = malloc (sizeof (Erss_Config));
-       memset(cfg, 0, sizeof (Erss_Config));
 
        if (!cfg) {
                fprintf (stderr, "%s error: out of memory\n", PACKAGE);
                exit (-1);
        }
+
+       memset(cfg, 0, sizeof (Erss_Config));
        
        cur = xmlDocGetRootElement(doc);
        cur = cur->xmlChildrenNode;
@@ -287,4 +311,6 @@
                
        if (!cfg->prefix)
                cfg->prefix = strdup(" . ");
+
+       return cfg;
 }
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse_config.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- parse_config.h      21 Feb 2004 11:12:18 -0000      1.5
+++ parse_config.h      26 Feb 2004 21:05:32 -0000      1.6
@@ -1,31 +1,3 @@
-typedef struct _erss_config {
-       char *header;
-       char *hostname;
-       char *url;
-
-       char *item_root;
-       char *item_start;
-       char *item_title;
-       char *item_url;
-       char *item_description;
-
-       int   update_rate;
-       int   clock;
-       int   num_stories;
-
-       int   x;
-       int   y;
-
-       int   borderless;
-
-       char *prefix;
-
-       char *theme;
-       char *config;
-} Erss_Config;
-
-
-
 typedef struct _erss_rc_config {
        char   *config;
        char   *theme;
@@ -38,8 +10,8 @@
 
 
 
-extern Erss_Config    *cfg;
 extern Erss_Rc_Config *rc;
 
 int  erss_parse_rc_file ();
-void erss_parse_config_file (char *file);
+Erss_Config *erss_parse_config_file (char *file);
+Erss_Config *erss_cfg_dst (Erss_Config **);




-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to