Enlightenment CVS committal
Author : sarajervi
Project : misc
Module : erss
Dir : misc/erss/src
Modified Files:
erss.c erss.h parse.c
Log Message:
Added argument parsing and the ability to list available config files
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/erss.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- erss.c 22 Dec 2003 21:00:05 -0000 1.2
+++ erss.c 25 Dec 2003 20:16:06 -0000 1.3
@@ -11,6 +11,7 @@
Evas_Object *bg;
Evas_Object *cont;
Evas_Object *tid;
+Ewd_List *config_files;
char *main_buffer;
char *last_time;
@@ -142,11 +143,19 @@
if (list) {
ptr = ewd_list_goto_first (list);
while ((ptr = ewd_list_next(list))) {
+
+ /*
+ * Remove the evas object from the list
+ * and destory it.
+ */
e_container_element_destroy (cont, ptr->obj);
if (ptr->url)
free (ptr->url);
+ if (ptr->description)
+ free (ptr->description);
+
free (ptr);
}
}
@@ -296,22 +305,137 @@
}
+int erss_alphasort (const void *a, const void *b)
+{
+ struct dirent **ad = (struct dirent **)a;
+ struct dirent **bd = (struct dirent **)b;
+ return (strcmp((*bd)->d_name, (*ad)->d_name));
+}
-int main (int argc, const char **argv)
+void list_config_files ()
+{
+ char *str;
+ char *ptr;
+ Ewd_List *paths;
+ struct dirent **dentries;
+ struct stat statbuf;
+ int num, i;
+ char file[PATH_MAX];
+
+ paths = ewd_list_new ();
+ config_files = ewd_list_new ();
+
+ str = malloc (PATH_MAX);
+ snprintf (str, PATH_MAX, "%s/.%s/config",
+ getenv("HOME"), PACKAGE);
+ ewd_list_append (paths, str);
+
+ str = malloc (PATH_MAX);
+ snprintf (str, PATH_MAX, "/usr/local/share/%s/config",
+ PACKAGE);
+ ewd_list_append (paths, str);
+
+ str = malloc (PATH_MAX);
+ snprintf (str, PATH_MAX, "/usr/share/%s/config",
+ PACKAGE);
+ ewd_list_append (paths, str);
+
+ printf ("\n%s processing potential dirs ...\n", PACKAGE);
+
+ ptr = ewd_list_goto_first (paths);
+ while ((ptr = ewd_list_current (paths))) {
+ printf ("\nLookin in %s:\n", ptr);
+
+ i = stat (ptr, &statbuf);
+
+ if (S_ISDIR(statbuf.st_mode)) {
+
+ if ((num = scandir(ptr, &dentries, 0, erss_alphasort)) < 0)
+ perror("erss - scandir");
+
+ while (num--) {
+ snprintf(file, PATH_MAX, "%s/%s", ptr,
dentries[num]->d_name);
+
+ i = stat (file, &statbuf);
+ if (i == -1) {
+ perror("erss - stat 1");
+ continue;
+ }
+
+ if (S_ISDIR(statbuf.st_mode))
+ continue;
+
+ if (strstr (dentries[num]->d_name, ".cfg")) {
+ printf ("\t%s\n", file);
+ ewd_list_append (config_files, file);
+ }
+ }
+ } else {
+ printf ("\tNo such dir\n");
+ }
+
+ ewd_list_next (paths);
+ }
+
+ /*
+ * Finished reading and printing avaliable config files
+ * now remove the paths list since we don't need it anyumore.
+ */
+ ptr = ewd_list_goto_first (paths);
+ while ((ptr = ewd_list_current (paths))) {
+ if (ptr)
+ free (ptr);
+
+ ewd_list_next (paths);
+ }
+
+ ewd_list_destroy (paths);
+}
+
+int main (int argc, const char *argv[])
{
Evas_Object *header;
int x, y, w, h;
int height;
int width;
-
-
- if (argc < 2) {
- fprintf (stderr, "Usage: erss feedconfig.cfg\n");
- fprintf (stderr, "Example config files in the config/ folder.\n");
- exit (-1);
+ int c = 0;
+
+ while((c = getopt (argc, argv, "cvhl")) != -1)
+ {
+ switch (c) {
+ case 'l':
+ list_config_files ();
+ exit (-1);
+ case 'c':
+
+ if(optind >= argc) {
+ fprintf (stderr, "Usage: %s [OPTION] ...\n",
PACKAGE);
+ fprintf (stderr, "Try `%s -h` for more
information\n", PACKAGE);
+ exit (-1);
+ }
+ parse_config_file ((char *) argv[optind]);
+
+ break;
+ case 'v':
+ printf ("%s %s\n", PACKAGE, VERSION);
+ exit (-1);
+ case 'h':
+ printf ("Usage: %s [OPTION] ...\n\n", PACKAGE);
+
+ printf (" -c CONFIG \t specify a config file\n");
+ printf (" -l \t list avaliable config
files\n");
+ printf (" -h \t display this help and exit\n");
+ printf (" -v \t display %s version\n\n",
PACKAGE);
+ exit (-1);
+ default:
+ fprintf (stderr, "\nUsage: %s [OPTION] ...\n",
PACKAGE);
+ fprintf (stderr, "Try `%s -h` for more information\n",
PACKAGE);
+ exit (-1);
+ break;
+ }
+
}
- parse_config_file ((char *) argv[1]);
if (!cfg->hostname) {
fprintf (stderr, "Erss error: No hostname defined!\n");
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/erss.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- erss.h 22 Dec 2003 15:17:30 -0000 1.1.1.1
+++ erss.h 25 Dec 2003 20:16:06 -0000 1.2
@@ -15,6 +15,8 @@
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
+#include <unistd.h>
+#include <dirent.h>
#include <netdb.h>
#include <sys/types.h>
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- parse.c 22 Dec 2003 21:00:05 -0000 1.2
+++ parse.c 25 Dec 2003 20:16:06 -0000 1.3
@@ -264,7 +264,7 @@
if ((fp = fopen (file, "r")) == NULL)
{
- fprintf (stderr, "ERROR: Can't open config file\n");
+ fprintf (stderr, "Erss error: Can't open config file\n");
exit (-1);
}
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs