Better handling of configuration defaults for the new settings
This commit is contained in:
		
							parent
							
								
									f28188a36b
								
							
						
					
					
						commit
						7678102e3b
					
				
					 3 changed files with 27 additions and 13 deletions
				
			
		| 
						 | 
					@ -76,7 +76,7 @@ void config_init(void)
 | 
				
			||||||
	config.scrollstep = 0.03;
 | 
						config.scrollstep = 0.03;
 | 
				
			||||||
	config.osd = 1;
 | 
						config.osd = 1;
 | 
				
			||||||
	config.osd_color = (char *) default_osd_color;
 | 
						config.osd_color = (char *) default_osd_color;
 | 
				
			||||||
	config.osd_monitor_number = 0;
 | 
						config.osd_monitor_number = -1;
 | 
				
			||||||
	config.osd_monitor_name = NULL;
 | 
						config.osd_monitor_name = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,14 +111,13 @@ void config_release(void)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void parse_monitor_value(char *value)
 | 
					bool parse_monitor_value(char *value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char *end;
 | 
						char *end;
 | 
				
			||||||
	long mon = strtol(value, &end, 10);
 | 
						long mon = strtol(value, &end, 10);
 | 
				
			||||||
	if (end == value + strlen(value)) {
 | 
						if (end == value + strlen(value)) {
 | 
				
			||||||
		if ((mon > INT_MAX) || (mon < -1)) {
 | 
							if ((mon > INT_MAX) || (mon < -1)) {
 | 
				
			||||||
			fprintf(stderr, "wmix:warning: unreasonable monitor number provided, falling back to default\n");
 | 
								return false;
 | 
				
			||||||
			config.osd_monitor_number = 0;
 | 
					 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (mon == -1)
 | 
								if (mon == -1)
 | 
				
			||||||
				config.osd = 0;
 | 
									config.osd = 0;
 | 
				
			||||||
| 
						 | 
					@ -128,6 +127,7 @@ void parse_monitor_value(char *value)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		config.osd_monitor_name = strdup(value);
 | 
							config.osd_monitor_name = strdup(value);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -203,7 +203,8 @@ void parse_cli_options(int argc, char **argv)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case 'o':
 | 
							case 'o':
 | 
				
			||||||
			parse_monitor_value(optarg);
 | 
								if (!parse_monitor_value(optarg))
 | 
				
			||||||
 | 
									fprintf(stderr, "wmix:warning: unreasonable monitor number provided on command line, ignoring\n");
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case 'v':
 | 
							case 'v':
 | 
				
			||||||
| 
						 | 
					@ -216,13 +217,6 @@ void parse_cli_options(int argc, char **argv)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	config.exclude_channel[count_exclude] = NULL;
 | 
						config.exclude_channel[count_exclude] = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!config.mixer_device) {
 | 
					 | 
				
			||||||
		if (config.api == 0)
 | 
					 | 
				
			||||||
			config.mixer_device = (char *)default_card_name;
 | 
					 | 
				
			||||||
		else if (config.api == 1)
 | 
					 | 
				
			||||||
			config.mixer_device = (char *)default_mixer_device;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (optind < argc) {
 | 
						if (optind < argc) {
 | 
				
			||||||
		fprintf(stderr, "wmix:error: argument '%s' not understood\n", argv[optind]);
 | 
							fprintf(stderr, "wmix:error: argument '%s' not understood\n", argv[optind]);
 | 
				
			||||||
		error_found = true;
 | 
							error_found = true;
 | 
				
			||||||
| 
						 | 
					@ -361,7 +355,10 @@ void config_read(void)
 | 
				
			||||||
			config.osd_color = strdup(value);
 | 
								config.osd_color = strdup(value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} else if (strcmp(keyword, "osdmonitor") == 0) {
 | 
							} else if (strcmp(keyword, "osdmonitor") == 0) {
 | 
				
			||||||
			parse_monitor_value(value);
 | 
								if (!config.osd_monitor_name &&
 | 
				
			||||||
 | 
								    config.osd_monitor_number == -1 &&
 | 
				
			||||||
 | 
								    !parse_monitor_value(value))
 | 
				
			||||||
 | 
									fprintf(stderr, "wmix:warning: unreasonable monitor number in config, ignoring\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} else if (strcmp(keyword, "scrolltext") == 0) {
 | 
							} else if (strcmp(keyword, "scrolltext") == 0) {
 | 
				
			||||||
			config.scrolltext = atoi(value);
 | 
								config.scrolltext = atoi(value);
 | 
				
			||||||
| 
						 | 
					@ -393,3 +390,16 @@ void config_read(void)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	fclose(fp);
 | 
						fclose(fp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void config_set_defaults()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!config.mixer_device) {
 | 
				
			||||||
 | 
							if (config.api == 0)
 | 
				
			||||||
 | 
								config.mixer_device = (char *)default_card_name;
 | 
				
			||||||
 | 
							else if (config.api == 1)
 | 
				
			||||||
 | 
								config.mixer_device = (char *)default_mixer_device;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!config.osd_monitor_name && config.osd_monitor_number == -1)
 | 
				
			||||||
 | 
							config.osd_monitor_number = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,4 +64,7 @@ void parse_cli_options(int argc, char **argv);
 | 
				
			||||||
/* Read configuration from file */
 | 
					/* Read configuration from file */
 | 
				
			||||||
void config_read(void);
 | 
					void config_read(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Set some default values based on configuration choices */
 | 
				
			||||||
 | 
					void config_set_defaults();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif	/* WMIX_CONFIG_H */
 | 
					#endif	/* WMIX_CONFIG_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,6 +71,7 @@ int main(int argc, char **argv)
 | 
				
			||||||
    config_init();
 | 
					    config_init();
 | 
				
			||||||
    parse_cli_options(argc, argv);
 | 
					    parse_cli_options(argc, argv);
 | 
				
			||||||
    config_read();
 | 
					    config_read();
 | 
				
			||||||
 | 
					    config_set_defaults();
 | 
				
			||||||
    choose_api(config.api);
 | 
					    choose_api(config.api);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mixer_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel);
 | 
					    mixer_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue