gnome-config



I yanked gnome-config from gnome yesterday and put it in my PRCS
server.  It was pretty easy, there were just a few functions I needed
to pull from gnome-utils or elsewhere.  I have a thought and a few
fixes:

1. It would be nice to seperate this completely and put the few 
missing functions in glib.  That way I can use it easily for non-gnome
applications, and contribute changes easily.

2. The one global variable, 'gnome_user_dir', makes it difficult to
package it as a library.  Perhaps it would be worthwhile to put all
the gnome-config context into a structure, allowing multiple config
dirs.  I notice that you've already got a syntax for absolute paths,
ignoring the gnome_user_dir, maybe this would be a cleaner solution.
In my case, I want a server-configuration which really doesn't belong
in a user's directory.

3. The code for gnome_config_get_vector_with_default was a little broken.  It
depended on a trailing space after the last string to recognize it.  It
also treated multiple spaces incorrectly.  I have fixed this.  I also
added functions gnome_config_get/set_garray_with_default to return an
array of strings.

Here's the patch.  I'll probably be making changes as I need them, but to
continuing to synchronize will be difficult until we can put the few 
dependencies in glib (and hopefully merge the rest of my glib changes).

Index: server/gnome-config.c
*** server/gnome-config.c.orig Sun, 26 Apr 1998 03:57:59 -0700 jmacd (repository/b/29_gnome-conf 1.2 644) 0.39
--- server/gnome-config.c      Sun, 26 Apr 1998 16:32:16 -0700 jmacd (repository/b/29_gnome-conf 1.2 644) 0.39(w)
***************
*** 911,945 ****
  	/* Figure out how large to make return vector.  Start at 1
  	   because we want to make NULL-terminated array.  */
  	count = 1;
! 	for (p = r; *p; ++p) {
  	        if (*p == '\\') {
! 		        if (! *p)
! 			        break;
! 			++p;
  		} else if (*p == ' ') {
! 		        ++count;
  		}
  	}
  
! 	*argcp = count - 1;
  	*argvp = (char **) g_malloc (count * sizeof (char *));
- 	(*argvp)[count - 1] = NULL;
  
  	count = 0;
  	last = r;
! 	for (p = r; *p; ++p) {
  	        if (*p == '\\') {
! 		        if (! *p)
! 			        break;
! 			++p;
  		} else if (*p == ' ') {
  		        tmp = g_malloc (p - last + 1);
  			strncpy (tmp, last, p - last);
  			tmp[p - last] = '\0';
  		        (*argvp)[count++] = tmp;
! 			last = p + 1;
  		}
  	}
  
  	release_path (pp);
  }
--- 913,968 ----
  	/* Figure out how large to make return vector.  Start at 1
  	   because we want to make NULL-terminated array.  */
  	count = 1;
! 	last = r;
! 	for (p = r; *p; ) {
  	  if (*p == '\\') {
! 	    p += 2;
  	  } else if (*p == ' ') {
! 	    count += 1;
! 
! 	    while (*p == ' ')
! 	      p += 1;
! 
! 	    last = p;
! 	  } else {
! 	    p += 1;
  	  }
  	}
  
! 	if (last < p)
! 	  count += 1;
! 
  	*argvp = (char **) g_malloc (count * sizeof (char *));
  
  	count = 0;
  	last = r;
! 	for (p = r; *p; ) {
  	  if (*p == '\\') {
! 	    p += 2;
  	  } else if (*p == ' ') {
  	    tmp = g_malloc (p - last + 1);
  	    strncpy (tmp, last, p - last);
  	    tmp[p - last] = '\0';
  	    (*argvp)[count++] = tmp;
! 
! 	    while (*p == ' ')
! 	      p += 1;
! 
! 	    last = p;
! 	  } else {
! 	    p += 1;
  	  }
  	}
+ 
+ 	if (last < p) {
+ 	  tmp = g_malloc (p - last + 1);
+ 	  strncpy (tmp, last, p - last);
+ 	  tmp[p - last] = '\0';
+ 	  (*argvp)[count++] = tmp;
+ 	}
+ 
+ 	*argcp = count;
+ 	(*argvp)[count] = NULL;
  
  	release_path (pp);
  }


-josh



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]