--- a/src/config.c Sun Jul 06 03:17:32 2008 +0000 +++ b/src/config.c Mon Jul 21 00:08:34 2008 +0000 @@ -36,27 +36,27 @@ gboolean lxdream_save_config_stream( FILE *f ); static struct lxdream_config_entry global_config[] = - {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, "dcboot.rom" }, - { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, "dcflash.rom" }, - { "default path", N_("Default disc path"), CONFIG_TYPE_PATH, "." }, - { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, "save" }, - { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, "IP.BIN" }, - { "gdrom", NULL, CONFIG_TYPE_FILE, NULL }, - { "recent", NULL, CONFIG_TYPE_FILE, NULL }, - { NULL, CONFIG_TYPE_NONE }}; + {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, "dcboot.rom" }, + { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, "dcflash.rom" }, + { "default path", N_("Default disc path"), CONFIG_TYPE_PATH, "." }, + { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, "save" }, + { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, "IP.BIN" }, + { "gdrom", NULL, CONFIG_TYPE_FILE, NULL }, + { "recent", NULL, CONFIG_TYPE_FILE, NULL }, + { NULL, CONFIG_TYPE_NONE }}; static struct lxdream_config_entry serial_config[] = - {{ "device", N_("Serial device"), CONFIG_TYPE_FILE, "/dev/ttyS1" }, - { NULL, CONFIG_TYPE_NONE }}; + {{ "device", N_("Serial device"), CONFIG_TYPE_FILE, "/dev/ttyS1" }, + { NULL, CONFIG_TYPE_NONE }}; struct lxdream_config_group lxdream_config_root[] = - {{ "global", global_config }, - { "controllers", NULL }, - { "serial", serial_config }, + {{ "global", global_config }, + { "controllers", NULL }, + { "serial", serial_config }, #ifdef HAVE_ALSA - { "alsa", alsa_config }, + { "alsa", alsa_config }, #endif - { NULL, CONFIG_TYPE_NONE }}; + { NULL, CONFIG_TYPE_NONE }}; static gchar *lxdream_config_load_filename = NULL; static gchar *lxdream_config_save_filename = NULL; @@ -66,19 +66,19 @@ gboolean result = TRUE; char *home = getenv("HOME"); if( lxdream_config_save_filename == NULL ) { - lxdream_config_save_filename = g_strdup_printf("%s/.%s", home, DEFAULT_CONFIG_FILENAME); + lxdream_config_save_filename = g_strdup_printf("%s/.%s", home, DEFAULT_CONFIG_FILENAME); } if( lxdream_config_load_filename == NULL ) { - if( access(lxdream_config_save_filename, R_OK) == 0 ) { - lxdream_config_load_filename = g_strdup(lxdream_config_save_filename); - } else if( access( PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) { - lxdream_config_load_filename = g_strdup(PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME); - } else if( access( "./" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) { - lxdream_config_load_filename = g_strdup("./" DEFAULT_CONFIG_FILENAME); - } else { - lxdream_config_load_filename = g_strdup(lxdream_config_save_filename); - result = FALSE; - } + if( access(lxdream_config_save_filename, R_OK) == 0 ) { + lxdream_config_load_filename = g_strdup(lxdream_config_save_filename); + } else if( access( PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) { + lxdream_config_load_filename = g_strdup(PACKAGE_CONF_DIR "/" DEFAULT_CONFIG_FILENAME); + } else if( access( "./" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) { + lxdream_config_load_filename = g_strdup("./" DEFAULT_CONFIG_FILENAME); + } else { + lxdream_config_load_filename = g_strdup(lxdream_config_save_filename); + result = FALSE; + } } return result; } @@ -86,11 +86,11 @@ void lxdream_set_config_filename( const gchar *filename ) { if( lxdream_config_load_filename != NULL ) { - g_free(lxdream_config_load_filename); + g_free(lxdream_config_load_filename); } lxdream_config_load_filename = g_strdup(filename); if( lxdream_config_save_filename != NULL ) { - g_free(lxdream_config_save_filename); + g_free(lxdream_config_save_filename); } lxdream_config_save_filename = g_strdup(filename); } @@ -99,18 +99,18 @@ { struct lxdream_config_group *group = lxdream_config_root; while( group->key != NULL ) { - struct lxdream_config_entry *param = group->params; - if( param != NULL ) { - while( param->key != NULL ) { - if( param->value != param->default_value ) { - if( param->value != NULL ) - free( param->value ); - param->value = (gchar *)param->default_value; - } - param++; - } - } - group++; + struct lxdream_config_entry *param = group->params; + if( param != NULL ) { + while( param->key != NULL ) { + if( param->value != param->default_value ) { + if( param->value != NULL ) + free( param->value ); + param->value = (gchar *)param->default_value; + } + param++; + } + } + group++; } maple_detach_all(); } @@ -123,10 +123,10 @@ void lxdream_set_config_value( lxdream_config_entry_t param, const gchar *value ) { if( param->value != value ) { - if( param->value != param->default_value && param->value != NULL ) { - free( param->value ); - } - param->value = g_strdup(value); + if( param->value != param->default_value && param->value != NULL ) { + free( param->value ); + } + param->value = g_strdup(value); } } @@ -144,10 +144,10 @@ { int i; for( i=0; group->params[i].key != NULL; i++ ) { - if( strcasecmp( group->params[i].key, key ) == 0 ) { - lxdream_set_config_value( &group->params[i], value ); - return TRUE; - } + if( strcasecmp( group->params[i].key, key ) == 0 ) { + lxdream_set_config_value( &group->params[i], value ); + return TRUE; + } } return FALSE; } @@ -156,14 +156,14 @@ { int i; for( i=0; src[i].key != NULL; i++ ) { - lxdream_set_config_value( &dest[i], src[i].value ); + lxdream_set_config_value( &dest[i], src[i].value ); } } gboolean lxdream_load_config( ) { if( lxdream_config_load_filename == NULL ) { - lxdream_find_config(); + lxdream_find_config(); } return lxdream_load_config_file(lxdream_config_load_filename); } @@ -171,7 +171,7 @@ gboolean lxdream_save_config( ) { if( lxdream_config_save_filename == NULL ) { - lxdream_find_config(); + lxdream_find_config(); } return lxdream_save_config_file(lxdream_config_save_filename); } @@ -182,16 +182,16 @@ gboolean result; if( access(filename, F_OK) != 0 ) { - INFO( "Configuration file '%s' does not exist, creating from defaults" ); - lxdream_set_default_config(); - lxdream_save_config(); + INFO( "Configuration file '%s' does not exist, creating from defaults" ); + lxdream_set_default_config(); + lxdream_save_config(); } f = fopen(filename, "ro"); if( f == NULL ) { - ERROR( "Unable to open configuration file '%s': %s", filename, strerror(errno) ); - lxdream_set_default_config(); - return FALSE; + ERROR( "Unable to open configuration file '%s': %s", filename, strerror(errno) ); + lxdream_set_default_config(); + return FALSE; } result = lxdream_load_config_stream( f ); @@ -210,77 +210,77 @@ lxdream_set_default_config(); while( fgets( buf, sizeof(buf), f ) != NULL ) { - g_strstrip(buf); - if( buf[0] == '#' ) - continue; - if( *buf == '[' ) { - char *p = strchr(buf, ']'); - if( p != NULL ) { - struct lxdream_config_group *tmp_group; - maple_device = maple_subdevice = -1; - *p = '\0'; - g_strstrip(buf+1); - tmp_group = &lxdream_config_root[0]; - while( tmp_group->key != NULL ) { - if( strcasecmp(tmp_group->key, buf+1) == 0 ) { - group = tmp_group; - break; - } - tmp_group++; - } - } - } else if( group != NULL ) { - char *value = strchr( buf, '=' ); - if( value != NULL ) { - struct lxdream_config_entry *param = group->params; - *value = '\0'; - value++; - g_strstrip(buf); - g_strstrip(value); - if( strcmp(group->key,"controllers") == 0 ) { - if( g_strncasecmp( buf, "device ", 7 ) == 0 ) { - maple_device = strtoul( buf+7, NULL, 0 ); - if( maple_device < 0 || maple_device > 3 ) { - ERROR( "Device number must be between 0..3 (not '%s')", buf+7); - continue; - } - maple_subdevice = 0; - device = maple_new_device( value ); - if( device == NULL ) { - ERROR( "Unrecognized device '%s'", value ); - } else { - devgroup.key = "controllers"; - devgroup.params = maple_get_device_config(device); - maple_attach_device( device, maple_device, maple_subdevice ); - group = &devgroup; - } - continue; - } else if( g_strncasecmp( buf, "subdevice ", 10 ) == 0 ) { - maple_subdevice = strtoul( buf+10, NULL, 0 ); - if( maple_device == -1 ) { - ERROR( "Subdevice not allowed without primary device" ); - } else if( maple_subdevice < 1 || maple_subdevice > 5 ) { - ERROR( "Subdevice must be between 1..5 (not '%s')", buf+10 ); - } else if( (device = maple_new_device(value)) == NULL ) { - ERROR( "Unrecognized subdevice '%s'", value ); - } else { - devgroup.key = "controllers"; - devgroup.params = maple_get_device_config(device); - maple_attach_device( device, maple_device, maple_subdevice ); - group = &devgroup; - } - continue; - } - } - while( param->key != NULL ) { - if( strcasecmp( param->key, buf ) == 0 ) { - param->value = g_strdup(value); - break; - } - param++; - } - } - } + g_strstrip(buf); + if( buf[0] == '#' ) + continue; + if( *buf == '[' ) { + char *p = strchr(buf, ']'); + if( p != NULL ) { + struct lxdream_config_group *tmp_group; + maple_device = maple_subdevice = -1; + *p = '\0'; + g_strstrip(buf+1); + tmp_group = &lxdream_config_root[0]; + while( tmp_group->key != NULL ) { + if( strcasecmp(tmp_group->key, buf+1) == 0 ) { + group = tmp_group; + break; + } + tmp_group++; + } + } + } else if( group != NULL ) { + char *value = strchr( buf, '=' ); + if( value != NULL ) { + struct lxdream_config_entry *param = group->params; + *value = '\0'; + value++; + g_strstrip(buf); + g_strstrip(value); + if( strcmp(group->key,"controllers") == 0 ) { + if( g_strncasecmp( buf, "device ", 7 ) == 0 ) { + maple_device = strtoul( buf+7, NULL, 0 ); + if( maple_device < 0 || maple_device > 3 ) { + ERROR( "Device number must be between 0..3 (not '%s')", buf+7); + continue; + } + maple_subdevice = 0; + device = maple_new_device( value ); + if( device == NULL ) { + ERROR( "Unrecognized device '%s'", value ); + } else { + devgroup.key = "controllers"; + devgroup.params = maple_get_device_config(device); + maple_attach_device( device, maple_device, maple_subdevice ); + group = &devgroup; + } + continue; + } else if( g_strncasecmp( buf, "subdevice ", 10 ) == 0 ) { + maple_subdevice = strtoul( buf+10, NULL, 0 ); + if( maple_device == -1 ) { + ERROR( "Subdevice not allowed without primary device" ); + } else if( maple_subdevice < 1 || maple_subdevice > 5 ) { + ERROR( "Subdevice must be between 1..5 (not '%s')", buf+10 ); + } else if( (device = maple_new_device(value)) == NULL ) { + ERROR( "Unrecognized subdevice '%s'", value ); + } else { + devgroup.key = "controllers"; + devgroup.params = maple_get_device_config(device); + maple_attach_device( device, maple_device, maple_subdevice ); + group = &devgroup; + } + continue; + } + } + while( param->key != NULL ) { + if( strcasecmp( param->key, buf ) == 0 ) { + param->value = g_strdup(value); + break; + } + param++; + } + } + } } return TRUE; } @@ -290,8 +290,8 @@ FILE *f = fopen(filename, "wo"); gboolean result; if( f == NULL ) { - ERROR( "Unable to open '%s': %s", filename, strerror(errno) ); - return FALSE; + ERROR( "Unable to open '%s': %s", filename, strerror(errno) ); + return FALSE; } result = lxdream_save_config_stream(f); fclose(f); @@ -301,42 +301,42 @@ gboolean lxdream_save_config_stream( FILE *f ) { struct lxdream_config_group *group = &lxdream_config_root[0]; - + while( group->key != NULL ) { - struct lxdream_config_entry *entry = group->params; - fprintf( f, "[%s]\n", group->key ); - - if( entry != NULL ) { - while( entry->key != NULL ) { - if( entry->value != NULL ) { - fprintf( f, "%s = %s\n", entry->key, entry->value ); - } - entry++; - } - } else if( strcmp(group->key, "controllers") == 0 ) { - int i,j; - for( i=0; i<4; i++ ) { - for( j=0; j<6; j++ ) { - maple_device_t dev = maple_get_device( i, j ); - if( dev != NULL ) { - if( j == 0 ) - fprintf( f, "Device %d = %s\n", i, dev->device_class->name ); - else - fprintf( f, "Subdevice %d = %s\n", j, dev->device_class->name ); - if( dev->get_config != NULL && ((entry = dev->get_config(dev)) != NULL) ) { - while( entry->key != NULL ) { - if( entry->value != NULL ) { - fprintf( f, "%*c%s = %s\n", j==0?4:8, ' ',entry->key, entry->value ); - } - entry++; - } - } - } - } - } - } - fprintf( f, "\n" ); - group++; + struct lxdream_config_entry *entry = group->params; + fprintf( f, "[%s]\n", group->key ); + + if( entry != NULL ) { + while( entry->key != NULL ) { + if( entry->value != NULL ) { + fprintf( f, "%s = %s\n", entry->key, entry->value ); + } + entry++; + } + } else if( strcmp(group->key, "controllers") == 0 ) { + int i,j; + for( i=0; i<4; i++ ) { + for( j=0; j<6; j++ ) { + maple_device_t dev = maple_get_device( i, j ); + if( dev != NULL ) { + if( j == 0 ) + fprintf( f, "Device %d = %s\n", i, dev->device_class->name ); + else + fprintf( f, "Subdevice %d = %s\n", j, dev->device_class->name ); + if( dev->get_config != NULL && ((entry = dev->get_config(dev)) != NULL) ) { + while( entry->key != NULL ) { + if( entry->value != NULL ) { + fprintf( f, "%*c%s = %s\n", j==0?4:8, ' ',entry->key, entry->value ); + } + entry++; + } + } + } + } + } + } + fprintf( f, "\n" ); + group++; } return TRUE; }