1.1 --- a/src/config.c Sun Jul 06 03:17:32 2008 +0000
1.2 +++ b/src/config.c Sun Jul 20 11:37:47 2008 +0000
1.4 gboolean lxdream_save_config_stream( FILE *f );
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.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.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.38 - { "alsa", alsa_config },
1.39 + { "alsa", alsa_config },
1.41 - { NULL, CONFIG_TYPE_NONE }};
1.42 + { NULL, CONFIG_TYPE_NONE }};
1.44 static gchar *lxdream_config_load_filename = NULL;
1.45 static gchar *lxdream_config_save_filename = NULL;
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.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.61 - lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
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.71 + lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
1.78 void lxdream_set_config_filename( const gchar *filename )
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.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.89 lxdream_config_save_filename = g_strdup(filename);
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.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.120 maple_detach_all();
1.122 @@ -123,10 +123,10 @@
1.123 void lxdream_set_config_value( lxdream_config_entry_t param, const gchar *value )
1.125 if( param->value != value ) {
1.126 - if( param->value != param->default_value && param->value != NULL ) {
1.127 - free( param->value );
1.129 - param->value = g_strdup(value);
1.130 + if( param->value != param->default_value && param->value != NULL ) {
1.131 + free( param->value );
1.133 + param->value = g_strdup(value);
1.137 @@ -144,10 +144,10 @@
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.145 + if( strcasecmp( group->params[i].key, key ) == 0 ) {
1.146 + lxdream_set_config_value( &group->params[i], value );
1.152 @@ -156,14 +156,14 @@
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.161 gboolean lxdream_load_config( )
1.163 if( lxdream_config_load_filename == NULL ) {
1.164 - lxdream_find_config();
1.165 + lxdream_find_config();
1.167 return lxdream_load_config_file(lxdream_config_load_filename);
1.169 @@ -171,7 +171,7 @@
1.170 gboolean lxdream_save_config( )
1.172 if( lxdream_config_save_filename == NULL ) {
1.173 - lxdream_find_config();
1.174 + lxdream_find_config();
1.176 return lxdream_save_config_file(lxdream_config_save_filename);
1.178 @@ -182,16 +182,16 @@
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.190 f = fopen(filename, "ro");
1.192 - ERROR( "Unable to open configuration file '%s': %s", filename, strerror(errno) );
1.193 - lxdream_set_default_config();
1.195 + ERROR( "Unable to open configuration file '%s': %s", filename, strerror(errno) );
1.196 + lxdream_set_default_config();
1.200 result = lxdream_load_config_stream( f );
1.201 @@ -210,77 +210,77 @@
1.202 lxdream_set_default_config();
1.204 while( fgets( buf, sizeof(buf), f ) != NULL ) {
1.206 - if( buf[0] == '#' )
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.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.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.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.239 - maple_subdevice = 0;
1.240 - device = maple_new_device( value );
1.241 - if( device == NULL ) {
1.242 - ERROR( "Unrecognized device '%s'", value );
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.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.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.267 - while( param->key != NULL ) {
1.268 - if( strcasecmp( param->key, buf ) == 0 ) {
1.269 - param->value = g_strdup(value);
1.277 + if( buf[0] == '#' )
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.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.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.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.310 + maple_subdevice = 0;
1.311 + device = maple_new_device( value );
1.312 + if( device == NULL ) {
1.313 + ERROR( "Unrecognized device '%s'", value );
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.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.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.338 + while( param->key != NULL ) {
1.339 + if( strcasecmp( param->key, buf ) == 0 ) {
1.340 + param->value = g_strdup(value);
1.350 @@ -290,8 +290,8 @@
1.351 FILE *f = fopen(filename, "wo");
1.354 - ERROR( "Unable to open '%s': %s", filename, strerror(errno) );
1.356 + ERROR( "Unable to open '%s': %s", filename, strerror(errno) );
1.359 result = lxdream_save_config_stream(f);
1.361 @@ -301,42 +301,42 @@
1.362 gboolean lxdream_save_config_stream( FILE *f )
1.364 struct lxdream_config_group *group = &lxdream_config_root[0];
1.367 while( group->key != NULL ) {
1.368 - struct lxdream_config_entry *entry = group->params;
1.369 - fprintf( f, "[%s]\n", group->key );
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.378 - } else if( strcmp(group->key, "controllers") == 0 ) {
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.385 - fprintf( f, "Device %d = %s\n", i, dev->device_class->name );
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.400 - fprintf( f, "\n" );
1.402 + struct lxdream_config_entry *entry = group->params;
1.403 + fprintf( f, "[%s]\n", group->key );
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.412 + } else if( strcmp(group->key, "controllers") == 0 ) {
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.419 + fprintf( f, "Device %d = %s\n", i, dev->device_class->name );
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.434 + fprintf( f, "\n" );