Enlightenment CVS committal

Author  : sarajervi
Project : misc
Module  : erss

Dir     : misc/erss/src


Modified Files:
        erss.c 


Log Message:
another bugfix and a new path in the cfg listing and some code moved around
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/erss.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- erss.c      26 Dec 2003 01:54:45 -0000      1.7
+++ erss.c      26 Dec 2003 12:48:09 -0000      1.8
@@ -273,7 +273,7 @@
        waiting_for_reply = FALSE;
 
        if (total_connects == 1)
-               printf ("%s info: connection information only displays on first 
connect.\n", 
+               printf ("%s info: connection information only displays on the first 
connect.\n", 
                                PACKAGE);
 
        return 1;
@@ -347,7 +347,7 @@
        return (strcmp((*bd)->d_name, (*ad)->d_name));
 }
 
-void list_config_files ()
+void list_config_files (int output)
 {
        char *str;
        char *ptr;
@@ -356,6 +356,8 @@
        struct stat statbuf;
        int num, i;
        char file[PATH_MAX];
+       int found_files = FALSE;
+       int no_dir = FALSE;
 
        paths = ewd_list_new ();
        config_files = ewd_list_new ();
@@ -366,6 +368,10 @@
        ewd_list_append (paths, str);
 
        str = malloc (PATH_MAX);
+       snprintf (str, PATH_MAX, "/etc/%s/config", 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);
@@ -375,40 +381,57 @@
                        PACKAGE);
        ewd_list_append (paths, str);
 
-       printf ("\n%s processing potential dirs ...\n", PACKAGE);
+       if (output)
+               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);
+               if (output)
+                       printf ("\nprocessing '%s':\n", ptr);
 
                i = stat (ptr, &statbuf);
 
-               if (S_ISDIR(statbuf.st_mode)) {
+               if (i == -1) {
+                       no_dir = TRUE;
+               } else {
+                       if (S_ISDIR(statbuf.st_mode)) {
                
-                       if ((num = scandir(ptr, &dentries, 0, erss_alphasort)) < 0) 
-                               perror("erss - scandir");
+                               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);
+                               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;
+                                       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")) {
+                                               found_files = TRUE;
+                                               printf ("\t%s\n", file);
+                                               ewd_list_append (config_files, file);
+                                       }
                                }
 
-                               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);
+                               if (!found_files) {
+                                       if (output)
+                                               printf ("\tno config files in this dir 
...\n");
+                                       found_files = FALSE;
                                }
                        }
-               } else {
-                       printf ("\tno such dir ..\n");
                }
                
+               if (output) {
+                       if (no_dir)
+                               printf ("\tno such dir ...\n");
+                       no_dir = FALSE;
+               }
+
                ewd_list_next (paths);
        }
 
@@ -427,6 +450,13 @@
        ewd_list_destroy (paths);
 }
 
+void 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[])
 {
        Evas_Object *header;
@@ -449,15 +479,13 @@
        {
                switch (c) {
                        case 'l':
-                               list_config_files ();
+                               list_config_files (TRUE);
                                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);
-                               } 
+                               if(optind >= argc) 
+                                       display_default_usage ();
+                               
                                got_config_file = TRUE;
                                snprintf (config_file, PATH_MAX, "%s", (char *) 
argv[optind]);
                                break;
@@ -488,13 +516,12 @@
                got_rc_file = TRUE;
                
        if(!got_config_file) {
-               if (!got_rc_file) {
-                       fprintf (stderr, "Usage: %s [OPTION] ...\n", PACKAGE);
-                       fprintf (stderr, "Try `%s -h` for more information\n", 
PACKAGE);
-                       exit (-1);
-               } else {
+               
+               if (!got_rc_file) 
+                       display_default_usage ();
+                else 
                        parse_config_file (rc->config);
-               }
+
        } else {
                parse_config_file (config_file);
        }




-------------------------------------------------------
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

Reply via email to