Search
lxdream.org :: lxdream/src/config.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/config.c
changeset 1041:5fcc39857c5c
prev1038:f220d18c0615
next1072:d82e04e6d497
author nkeynes
date Fri Jun 26 05:47:04 2009 +0000 (14 years ago)
permissions -rw-r--r--
last change Refactor path operations into lxpaths.[ch]
file annotate diff log raw
1.1 --- a/src/config.c Thu Jun 25 01:15:25 2009 +0000
1.2 +++ b/src/config.c Fri Jun 26 05:47:04 2009 +0000
1.3 @@ -18,17 +18,16 @@
1.4
1.5 #include <unistd.h>
1.6 #include <stdio.h>
1.7 -#include <ctype.h>
1.8 #include <errno.h>
1.9 #include <stdlib.h>
1.10 #include <string.h>
1.11 -#include <wordexp.h>
1.12 #include <glib/gmem.h>
1.13 #include <glib/gstrfuncs.h>
1.14 #include <sys/types.h>
1.15 #include <sys/stat.h>
1.16 #include "dream.h"
1.17 #include "config.h"
1.18 +#include "lxpaths.h"
1.19 #include "maple/maple.h"
1.20
1.21 #define MAX_ROOT_GROUPS 16
1.22 @@ -196,82 +195,6 @@
1.23 }
1.24 }
1.25
1.26 -gchar *get_expanded_path( const gchar *input )
1.27 -{
1.28 - wordexp_t we;
1.29 - if( input == NULL ) {
1.30 - return NULL;
1.31 - }
1.32 - memset(&we,0,sizeof(we));
1.33 - int result = wordexp(input, &we, WRDE_NOCMD);
1.34 - if( result != 0 || we.we_wordc == 0 ) {
1.35 - /* On failure, return the original input unchanged */
1.36 - return g_strdup(input);
1.37 - } else {
1.38 - /* On success, concatenate all 'words' together into a single
1.39 - * space-separated string
1.40 - */
1.41 - int length = we.we_wordc, i;
1.42 - gchar *result, *p;
1.43 -
1.44 - for( i=0; i<we.we_wordc; i++ ) {
1.45 - length += strlen(we.we_wordv[i]);
1.46 - }
1.47 - p = result = g_malloc(length);
1.48 - for( i=0; i<we.we_wordc; i++ ) {
1.49 - if( i != 0 )
1.50 - *p++ = ' ';
1.51 - strcpy( p, we.we_wordv[i] );
1.52 - p += strlen(p);
1.53 - }
1.54 - wordfree(&we);
1.55 - return result;
1.56 - }
1.57 -}
1.58 -
1.59 -/**
1.60 - * Test if we need to escape a path to prevent substitution mangling.
1.61 - * @return TRUE if the input value contains any character that doesn't
1.62 - * match [a-zA-Z0-9._@%/] (this will escape slightly more than it needs to,
1.63 - * but is safe)
1.64 - */
1.65 -gboolean path_needs_escaping( const gchar *value )
1.66 -{
1.67 - const gchar *p = value;
1.68 - while( *p ) {
1.69 - if( !isalnum(*p) && *p != '.' && *p != '_' &&
1.70 - *p != '@' && *p != '%' && *p != '/' ) {
1.71 - return TRUE;
1.72 - }
1.73 - p++;
1.74 - }
1.75 - return FALSE;
1.76 -}
1.77 -
1.78 -gchar *get_escaped_path( const gchar *value )
1.79 -{
1.80 - if( value != NULL && path_needs_escaping(value) ) {
1.81 - /* Escape with "", and backslash the remaining characters:
1.82 - * \ " $ `
1.83 - */
1.84 - char buf[strlen(value)*2+3];
1.85 - const char *s = value;
1.86 - char *p = buf;
1.87 - *p++ = '\"';
1.88 - while( *s ) {
1.89 - if( *s == '\\' || *s == '"' || *s == '$' || *s == '`' ) {
1.90 - *p++ = '\\';
1.91 - }
1.92 - *p++ = *s++;
1.93 - }
1.94 - *p++ = '\"';
1.95 - *p = '\0';
1.96 - return g_strdup(buf);
1.97 - } else {
1.98 - return g_strdup(value);
1.99 - }
1.100 -}
1.101 -
1.102 gchar *lxdream_get_global_config_path_value( int key )
1.103 {
1.104 const gchar *str = lxdream_get_global_config_value(key);
.