Search
lxdream.org :: lxdream/src/config.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/config.c
changeset 736:a02d1475ccfd
prev724:f2bc1c7cca14
next759:f16975739abc
author nkeynes
date Sat Jul 19 02:48:50 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Add debian control files to the dist
file annotate diff log raw
1.1 --- a/src/config.c Sun Jul 06 03:17:32 2008 +0000
1.2 +++ b/src/config.c Sat Jul 19 02:48:50 2008 +0000
1.3 @@ -36,27 +36,27 @@
1.4 gboolean lxdream_save_config_stream( FILE *f );
1.5
1.6 static struct lxdream_config_entry global_config[] =
1.7 - {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, "dcboot.rom" },
1.8 - { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, "dcflash.rom" },
1.9 - { "default path", N_("Default disc path"), CONFIG_TYPE_PATH, "." },
1.10 - { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, "save" },
1.11 - { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, "IP.BIN" },
1.12 - { "gdrom", NULL, CONFIG_TYPE_FILE, NULL },
1.13 - { "recent", NULL, CONFIG_TYPE_FILE, NULL },
1.14 - { NULL, CONFIG_TYPE_NONE }};
1.15 + {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, "dcboot.rom" },
1.16 + { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, "dcflash.rom" },
1.17 + { "default path", N_("Default disc path"), CONFIG_TYPE_PATH, "." },
1.18 + { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, "save" },
1.19 + { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, "IP.BIN" },
1.20 + { "gdrom", NULL, CONFIG_TYPE_FILE, NULL },
1.21 + { "recent", NULL, CONFIG_TYPE_FILE, NULL },
1.22 + { NULL, CONFIG_TYPE_NONE }};
1.23
1.24 static struct lxdream_config_entry serial_config[] =
1.25 - {{ "device", N_("Serial device"), CONFIG_TYPE_FILE, "/dev/ttyS1" },
1.26 - { NULL, CONFIG_TYPE_NONE }};
1.27 + {{ "device", N_("Serial device"), CONFIG_TYPE_FILE, "/dev/ttyS1" },
1.28 + { NULL, CONFIG_TYPE_NONE }};
1.29
1.30 struct lxdream_config_group lxdream_config_root[] =
1.31 - {{ "global", global_config },
1.32 - { "controllers", NULL },
1.33 - { "serial", serial_config },
1.34 + {{ "global", global_config },
1.35 + { "controllers", NULL },
1.36 + { "serial", serial_config },
1.37 #ifdef HAVE_ALSA
1.38 - { "alsa", alsa_config },
1.39 + { "alsa", alsa_config },
1.40 #endif
1.41 - { NULL, CONFIG_TYPE_NONE }};
1.42 + { NULL, CONFIG_TYPE_NONE }};
1.43
1.44 static gchar *lxdream_config_load_filename = NULL;
1.45 static gchar *lxdream_config_save_filename = NULL;
1.46 @@ -66,19 +66,19 @@
1.47 gboolean result = TRUE;
1.48 char *home = getenv("HOME");
1.49 if( lxdream_config_save_filename == NULL ) {
1.50 - lxdream_config_save_filename = g_strdup_printf("%s/.%s", home, DEFAULT_CONFIG_FILENAME);
1.51 + lxdream_config_save_filename = g_strdup_printf("%s/.%s", home, DEFAULT_CONFIG_FILENAME);
1.52 }
1.53 if( lxdream_config_load_filename == NULL ) {
1.54 - if( access(lxdream_config_save_filename, R_OK) == 0 ) {
1.55 - lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
1.56 - } else if( access( PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) {
1.57 - lxdream_config_load_filename = g_strdup(PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME);
1.58 - } else if( access( "./" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) {
1.59 - lxdream_config_load_filename = g_strdup("./" DEFAULT_CONFIG_FILENAME);
1.60 - } else {
1.61 - lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
1.62 - result = FALSE;
1.63 - }
1.64 + if( access(lxdream_config_save_filename, R_OK) == 0 ) {
1.65 + lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
1.66 + } else if( access( PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) {
1.67 + lxdream_config_load_filename = g_strdup(PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME);
1.68 + } else if( access( "./" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) {
1.69 + lxdream_config_load_filename = g_strdup("./" DEFAULT_CONFIG_FILENAME);
1.70 + } else {
1.71 + lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
1.72 + result = FALSE;
1.73 + }
1.74 }
1.75 return result;
1.76 }
1.77 @@ -86,11 +86,11 @@
1.78 void lxdream_set_config_filename( const gchar *filename )
1.79 {
1.80 if( lxdream_config_load_filename != NULL ) {
1.81 - g_free(lxdream_config_load_filename);
1.82 + g_free(lxdream_config_load_filename);
1.83 }
1.84 lxdream_config_load_filename = g_strdup(filename);
1.85 if( lxdream_config_save_filename != NULL ) {
1.86 - g_free(lxdream_config_save_filename);
1.87 + g_free(lxdream_config_save_filename);
1.88 }
1.89 lxdream_config_save_filename = g_strdup(filename);
1.90 }
1.91 @@ -99,18 +99,18 @@
1.92 {
1.93 struct lxdream_config_group *group = lxdream_config_root;
1.94 while( group->key != NULL ) {
1.95 - struct lxdream_config_entry *param = group->params;
1.96 - if( param != NULL ) {
1.97 - while( param->key != NULL ) {
1.98 - if( param->value != param->default_value ) {
1.99 - if( param->value != NULL )
1.100 - free( param->value );
1.101 - param->value = (gchar *)param->default_value;
1.102 - }
1.103 - param++;
1.104 - }
1.105 - }
1.106 - group++;
1.107 + struct lxdream_config_entry *param = group->params;
1.108 + if( param != NULL ) {
1.109 + while( param->key != NULL ) {
1.110 + if( param->value != param->default_value ) {
1.111 + if( param->value != NULL )
1.112 + free( param->value );
1.113 + param->value = (gchar *)param->default_value;
1.114 + }
1.115 + param++;
1.116 + }
1.117 + }
1.118 + group++;
1.119 }
1.120 maple_detach_all();
1.121 }
1.122 @@ -123,10 +123,10 @@
1.123 void lxdream_set_config_value( lxdream_config_entry_t param, const gchar *value )
1.124 {
1.125 if( param->value != value ) {
1.126 - if( param->value != param->default_value && param->value != NULL ) {
1.127 - free( param->value );
1.128 - }
1.129 - param->value = g_strdup(value);
1.130 + if( param->value != param->default_value && param->value != NULL ) {
1.131 + free( param->value );
1.132 + }
1.133 + param->value = g_strdup(value);
1.134 }
1.135 }
1.136
1.137 @@ -144,10 +144,10 @@
1.138 {
1.139 int i;
1.140 for( i=0; group->params[i].key != NULL; i++ ) {
1.141 - if( strcasecmp( group->params[i].key, key ) == 0 ) {
1.142 - lxdream_set_config_value( &group->params[i], value );
1.143 - return TRUE;
1.144 - }
1.145 + if( strcasecmp( group->params[i].key, key ) == 0 ) {
1.146 + lxdream_set_config_value( &group->params[i], value );
1.147 + return TRUE;
1.148 + }
1.149 }
1.150 return FALSE;
1.151 }
1.152 @@ -156,14 +156,14 @@
1.153 {
1.154 int i;
1.155 for( i=0; src[i].key != NULL; i++ ) {
1.156 - lxdream_set_config_value( &dest[i], src[i].value );
1.157 + lxdream_set_config_value( &dest[i], src[i].value );
1.158 }
1.159 }
1.160
1.161 gboolean lxdream_load_config( )
1.162 {
1.163 if( lxdream_config_load_filename == NULL ) {
1.164 - lxdream_find_config();
1.165 + lxdream_find_config();
1.166 }
1.167 return lxdream_load_config_file(lxdream_config_load_filename);
1.168 }
1.169 @@ -171,7 +171,7 @@
1.170 gboolean lxdream_save_config( )
1.171 {
1.172 if( lxdream_config_save_filename == NULL ) {
1.173 - lxdream_find_config();
1.174 + lxdream_find_config();
1.175 }
1.176 return lxdream_save_config_file(lxdream_config_save_filename);
1.177 }
1.178 @@ -182,16 +182,16 @@
1.179 gboolean result;
1.180
1.181 if( access(filename, F_OK) != 0 ) {
1.182 - INFO( "Configuration file '%s' does not exist, creating from defaults" );
1.183 - lxdream_set_default_config();
1.184 - lxdream_save_config();
1.185 + INFO( "Configuration file '%s' does not exist, creating from defaults" );
1.186 + lxdream_set_default_config();
1.187 + lxdream_save_config();
1.188 }
1.189
1.190 f = fopen(filename, "ro");
1.191 if( f == NULL ) {
1.192 - ERROR( "Unable to open configuration file '%s': %s", filename, strerror(errno) );
1.193 - lxdream_set_default_config();
1.194 - return FALSE;
1.195 + ERROR( "Unable to open configuration file '%s': %s", filename, strerror(errno) );
1.196 + lxdream_set_default_config();
1.197 + return FALSE;
1.198 }
1.199
1.200 result = lxdream_load_config_stream( f );
1.201 @@ -210,77 +210,77 @@
1.202 lxdream_set_default_config();
1.203
1.204 while( fgets( buf, sizeof(buf), f ) != NULL ) {
1.205 - g_strstrip(buf);
1.206 - if( buf[0] == '#' )
1.207 - continue;
1.208 - if( *buf == '[' ) {
1.209 - char *p = strchr(buf, ']');
1.210 - if( p != NULL ) {
1.211 - struct lxdream_config_group *tmp_group;
1.212 - maple_device = maple_subdevice = -1;
1.213 - *p = '\0';
1.214 - g_strstrip(buf+1);
1.215 - tmp_group = &lxdream_config_root[0];
1.216 - while( tmp_group->key != NULL ) {
1.217 - if( strcasecmp(tmp_group->key, buf+1) == 0 ) {
1.218 - group = tmp_group;
1.219 - break;
1.220 - }
1.221 - tmp_group++;
1.222 - }
1.223 - }
1.224 - } else if( group != NULL ) {
1.225 - char *value = strchr( buf, '=' );
1.226 - if( value != NULL ) {
1.227 - struct lxdream_config_entry *param = group->params;
1.228 - *value = '\0';
1.229 - value++;
1.230 - g_strstrip(buf);
1.231 - g_strstrip(value);
1.232 - if( strcmp(group->key,"controllers") == 0 ) {
1.233 - if( g_strncasecmp( buf, "device ", 7 ) == 0 ) {
1.234 - maple_device = strtoul( buf+7, NULL, 0 );
1.235 - if( maple_device < 0 || maple_device > 3 ) {
1.236 - ERROR( "Device number must be between 0..3 (not '%s')", buf+7);
1.237 - continue;
1.238 - }
1.239 - maple_subdevice = 0;
1.240 - device = maple_new_device( value );
1.241 - if( device == NULL ) {
1.242 - ERROR( "Unrecognized device '%s'", value );
1.243 - } else {
1.244 - devgroup.key = "controllers";
1.245 - devgroup.params = maple_get_device_config(device);
1.246 - maple_attach_device( device, maple_device, maple_subdevice );
1.247 - group = &devgroup;
1.248 - }
1.249 - continue;
1.250 - } else if( g_strncasecmp( buf, "subdevice ", 10 ) == 0 ) {
1.251 - maple_subdevice = strtoul( buf+10, NULL, 0 );
1.252 - if( maple_device == -1 ) {
1.253 - ERROR( "Subdevice not allowed without primary device" );
1.254 - } else if( maple_subdevice < 1 || maple_subdevice > 5 ) {
1.255 - ERROR( "Subdevice must be between 1..5 (not '%s')", buf+10 );
1.256 - } else if( (device = maple_new_device(value)) == NULL ) {
1.257 - ERROR( "Unrecognized subdevice '%s'", value );
1.258 - } else {
1.259 - devgroup.key = "controllers";
1.260 - devgroup.params = maple_get_device_config(device);
1.261 - maple_attach_device( device, maple_device, maple_subdevice );
1.262 - group = &devgroup;
1.263 - }
1.264 - continue;
1.265 - }
1.266 - }
1.267 - while( param->key != NULL ) {
1.268 - if( strcasecmp( param->key, buf ) == 0 ) {
1.269 - param->value = g_strdup(value);
1.270 - break;
1.271 - }
1.272 - param++;
1.273 - }
1.274 - }
1.275 - }
1.276 + g_strstrip(buf);
1.277 + if( buf[0] == '#' )
1.278 + continue;
1.279 + if( *buf == '[' ) {
1.280 + char *p = strchr(buf, ']');
1.281 + if( p != NULL ) {
1.282 + struct lxdream_config_group *tmp_group;
1.283 + maple_device = maple_subdevice = -1;
1.284 + *p = '\0';
1.285 + g_strstrip(buf+1);
1.286 + tmp_group = &lxdream_config_root[0];
1.287 + while( tmp_group->key != NULL ) {
1.288 + if( strcasecmp(tmp_group->key, buf+1) == 0 ) {
1.289 + group = tmp_group;
1.290 + break;
1.291 + }
1.292 + tmp_group++;
1.293 + }
1.294 + }
1.295 + } else if( group != NULL ) {
1.296 + char *value = strchr( buf, '=' );
1.297 + if( value != NULL ) {
1.298 + struct lxdream_config_entry *param = group->params;
1.299 + *value = '\0';
1.300 + value++;
1.301 + g_strstrip(buf);
1.302 + g_strstrip(value);
1.303 + if( strcmp(group->key,"controllers") == 0 ) {
1.304 + if( g_strncasecmp( buf, "device ", 7 ) == 0 ) {
1.305 + maple_device = strtoul( buf+7, NULL, 0 );
1.306 + if( maple_device < 0 || maple_device > 3 ) {
1.307 + ERROR( "Device number must be between 0..3 (not '%s')", buf+7);
1.308 + continue;
1.309 + }
1.310 + maple_subdevice = 0;
1.311 + device = maple_new_device( value );
1.312 + if( device == NULL ) {
1.313 + ERROR( "Unrecognized device '%s'", value );
1.314 + } else {
1.315 + devgroup.key = "controllers";
1.316 + devgroup.params = maple_get_device_config(device);
1.317 + maple_attach_device( device, maple_device, maple_subdevice );
1.318 + group = &devgroup;
1.319 + }
1.320 + continue;
1.321 + } else if( g_strncasecmp( buf, "subdevice ", 10 ) == 0 ) {
1.322 + maple_subdevice = strtoul( buf+10, NULL, 0 );
1.323 + if( maple_device == -1 ) {
1.324 + ERROR( "Subdevice not allowed without primary device" );
1.325 + } else if( maple_subdevice < 1 || maple_subdevice > 5 ) {
1.326 + ERROR( "Subdevice must be between 1..5 (not '%s')", buf+10 );
1.327 + } else if( (device = maple_new_device(value)) == NULL ) {
1.328 + ERROR( "Unrecognized subdevice '%s'", value );
1.329 + } else {
1.330 + devgroup.key = "controllers";
1.331 + devgroup.params = maple_get_device_config(device);
1.332 + maple_attach_device( device, maple_device, maple_subdevice );
1.333 + group = &devgroup;
1.334 + }
1.335 + continue;
1.336 + }
1.337 + }
1.338 + while( param->key != NULL ) {
1.339 + if( strcasecmp( param->key, buf ) == 0 ) {
1.340 + param->value = g_strdup(value);
1.341 + break;
1.342 + }
1.343 + param++;
1.344 + }
1.345 + }
1.346 + }
1.347 }
1.348 return TRUE;
1.349 }
1.350 @@ -290,8 +290,8 @@
1.351 FILE *f = fopen(filename, "wo");
1.352 gboolean result;
1.353 if( f == NULL ) {
1.354 - ERROR( "Unable to open '%s': %s", filename, strerror(errno) );
1.355 - return FALSE;
1.356 + ERROR( "Unable to open '%s': %s", filename, strerror(errno) );
1.357 + return FALSE;
1.358 }
1.359 result = lxdream_save_config_stream(f);
1.360 fclose(f);
1.361 @@ -301,42 +301,42 @@
1.362 gboolean lxdream_save_config_stream( FILE *f )
1.363 {
1.364 struct lxdream_config_group *group = &lxdream_config_root[0];
1.365 -
1.366 +
1.367 while( group->key != NULL ) {
1.368 - struct lxdream_config_entry *entry = group->params;
1.369 - fprintf( f, "[%s]\n", group->key );
1.370 -
1.371 - if( entry != NULL ) {
1.372 - while( entry->key != NULL ) {
1.373 - if( entry->value != NULL ) {
1.374 - fprintf( f, "%s = %s\n", entry->key, entry->value );
1.375 - }
1.376 - entry++;
1.377 - }
1.378 - } else if( strcmp(group->key, "controllers") == 0 ) {
1.379 - int i,j;
1.380 - for( i=0; i<4; i++ ) {
1.381 - for( j=0; j<6; j++ ) {
1.382 - maple_device_t dev = maple_get_device( i, j );
1.383 - if( dev != NULL ) {
1.384 - if( j == 0 )
1.385 - fprintf( f, "Device %d = %s\n", i, dev->device_class->name );
1.386 - else
1.387 - fprintf( f, "Subdevice %d = %s\n", j, dev->device_class->name );
1.388 - if( dev->get_config != NULL && ((entry = dev->get_config(dev)) != NULL) ) {
1.389 - while( entry->key != NULL ) {
1.390 - if( entry->value != NULL ) {
1.391 - fprintf( f, "%*c%s = %s\n", j==0?4:8, ' ',entry->key, entry->value );
1.392 - }
1.393 - entry++;
1.394 - }
1.395 - }
1.396 - }
1.397 - }
1.398 - }
1.399 - }
1.400 - fprintf( f, "\n" );
1.401 - group++;
1.402 + struct lxdream_config_entry *entry = group->params;
1.403 + fprintf( f, "[%s]\n", group->key );
1.404 +
1.405 + if( entry != NULL ) {
1.406 + while( entry->key != NULL ) {
1.407 + if( entry->value != NULL ) {
1.408 + fprintf( f, "%s = %s\n", entry->key, entry->value );
1.409 + }
1.410 + entry++;
1.411 + }
1.412 + } else if( strcmp(group->key, "controllers") == 0 ) {
1.413 + int i,j;
1.414 + for( i=0; i<4; i++ ) {
1.415 + for( j=0; j<6; j++ ) {
1.416 + maple_device_t dev = maple_get_device( i, j );
1.417 + if( dev != NULL ) {
1.418 + if( j == 0 )
1.419 + fprintf( f, "Device %d = %s\n", i, dev->device_class->name );
1.420 + else
1.421 + fprintf( f, "Subdevice %d = %s\n", j, dev->device_class->name );
1.422 + if( dev->get_config != NULL && ((entry = dev->get_config(dev)) != NULL) ) {
1.423 + while( entry->key != NULL ) {
1.424 + if( entry->value != NULL ) {
1.425 + fprintf( f, "%*c%s = %s\n", j==0?4:8, ' ',entry->key, entry->value );
1.426 + }
1.427 + entry++;
1.428 + }
1.429 + }
1.430 + }
1.431 + }
1.432 + }
1.433 + }
1.434 + fprintf( f, "\n" );
1.435 + group++;
1.436 }
1.437 return TRUE;
1.438 }
.