mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	Added "dont override" behaviour
This commit is contained in:
		
							parent
							
								
									86ddd545be
								
							
						
					
					
						commit
						420065f2fe
					
				
					 1 changed files with 87 additions and 61 deletions
				
			
		
							
								
								
									
										148
									
								
								src/conf.c
									
										
									
									
									
								
							
							
						
						
									
										148
									
								
								src/conf.c
									
										
									
									
									
								
							| 
						 | 
					@ -461,7 +461,7 @@ static int _snd_config_search(snd_config_t *config,
 | 
				
			||||||
	return -ENOENT;
 | 
						return -ENOENT;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input, char **id)
 | 
					static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input, char **id, int skip)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	snd_config_t *n = *_n;
 | 
						snd_config_t *n = *_n;
 | 
				
			||||||
	char *s;
 | 
						char *s;
 | 
				
			||||||
| 
						 | 
					@ -470,6 +470,10 @@ static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input,
 | 
				
			||||||
	err = get_string(&s, 0, input);
 | 
						err = get_string(&s, 0, input);
 | 
				
			||||||
	if (err < 0)
 | 
						if (err < 0)
 | 
				
			||||||
		return err;
 | 
							return err;
 | 
				
			||||||
 | 
						if (skip) {
 | 
				
			||||||
 | 
							free(s);
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if ((s[0] >= '0' && s[0] <= '9') || s[0] == '-') {
 | 
						if ((s[0] >= '0' && s[0] <= '9') || s[0] == '-') {
 | 
				
			||||||
		long i;
 | 
							long i;
 | 
				
			||||||
		errno = 0;
 | 
							errno = 0;
 | 
				
			||||||
| 
						 | 
					@ -481,7 +485,7 @@ static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input,
 | 
				
			||||||
				free(s);
 | 
									free(s);
 | 
				
			||||||
				if (n) {
 | 
									if (n) {
 | 
				
			||||||
					if (n->type != SND_CONFIG_TYPE_REAL) {
 | 
										if (n->type != SND_CONFIG_TYPE_REAL) {
 | 
				
			||||||
						SNDERR("%s is not a real", id);
 | 
											SNDERR("%s is not a real", *id);
 | 
				
			||||||
						return -EINVAL;
 | 
											return -EINVAL;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
| 
						 | 
					@ -497,7 +501,7 @@ static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input,
 | 
				
			||||||
			free(s);
 | 
								free(s);
 | 
				
			||||||
			if (n) {
 | 
								if (n) {
 | 
				
			||||||
				if (n->type != SND_CONFIG_TYPE_INTEGER) {
 | 
									if (n->type != SND_CONFIG_TYPE_INTEGER) {
 | 
				
			||||||
					SNDERR("%s is not an integer", id);
 | 
										SNDERR("%s is not an integer", *id);
 | 
				
			||||||
					return -EINVAL;
 | 
										return -EINVAL;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
| 
						 | 
					@ -512,7 +516,7 @@ static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (n) {
 | 
						if (n) {
 | 
				
			||||||
		if (n->type != SND_CONFIG_TYPE_STRING) {
 | 
							if (n->type != SND_CONFIG_TYPE_STRING) {
 | 
				
			||||||
			SNDERR("%s is not a string", id);
 | 
								SNDERR("%s is not a string", *id);
 | 
				
			||||||
			free(s);
 | 
								free(s);
 | 
				
			||||||
			return -EINVAL;
 | 
								return -EINVAL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -528,21 +532,23 @@ static int parse_value(snd_config_t **_n, snd_config_t *father, input_t *input,
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int parse_defs(snd_config_t *father, input_t *input);
 | 
					static int parse_defs(snd_config_t *father, input_t *input, int skip);
 | 
				
			||||||
static int parse_array_defs(snd_config_t *farther, input_t *input);
 | 
					static int parse_array_defs(snd_config_t *farther, input_t *input, int skip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int parse_array_def(snd_config_t *father, input_t *input, int idx)
 | 
					static int parse_array_def(snd_config_t *father, input_t *input, int idx, int skip)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char static_id[12], *id;
 | 
						char static_id[12], *id = NULL;
 | 
				
			||||||
	int c;
 | 
						int c;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
	snd_config_t *n = NULL;
 | 
						snd_config_t *n = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	snprintf(static_id, sizeof(static_id), "%i", idx);
 | 
						if (!skip) {
 | 
				
			||||||
	static_id[sizeof(static_id)-1] = '\0';
 | 
							snprintf(static_id, sizeof(static_id), "%i", idx);
 | 
				
			||||||
	id = strdup(static_id);
 | 
							static_id[sizeof(static_id)-1] = '\0';
 | 
				
			||||||
	if (id == NULL)
 | 
							id = strdup(static_id);
 | 
				
			||||||
		return -ENOMEM;
 | 
							if (id == NULL)
 | 
				
			||||||
 | 
								return -ENOMEM;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	c = get_nonwhite(input);
 | 
						c = get_nonwhite(input);
 | 
				
			||||||
	if (c < 0) {
 | 
						if (c < 0) {
 | 
				
			||||||
		err = c;
 | 
							err = c;
 | 
				
			||||||
| 
						 | 
					@ -553,22 +559,24 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx)
 | 
				
			||||||
	case '[':
 | 
						case '[':
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char endchr;
 | 
							char endchr;
 | 
				
			||||||
		if (n) {
 | 
							if (!skip) {
 | 
				
			||||||
			if (n->type != SND_CONFIG_TYPE_COMPOUND) {
 | 
								if (n) {
 | 
				
			||||||
				SNDERR("%s is not a compound", id);
 | 
									if (n->type != SND_CONFIG_TYPE_COMPOUND) {
 | 
				
			||||||
				err = -EINVAL;
 | 
										SNDERR("%s is not a compound", id);
 | 
				
			||||||
				goto __end;
 | 
										err = -EINVAL;
 | 
				
			||||||
 | 
										goto __end;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									err = _snd_config_make_add(&n, &id, SND_CONFIG_TYPE_COMPOUND, father);
 | 
				
			||||||
 | 
									if (err < 0)
 | 
				
			||||||
 | 
										goto __end;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			err = _snd_config_make_add(&n, &id, SND_CONFIG_TYPE_COMPOUND, father);
 | 
					 | 
				
			||||||
			if (err < 0)
 | 
					 | 
				
			||||||
				goto __end;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (c == '{') {
 | 
							if (c == '{') {
 | 
				
			||||||
			err = parse_defs(n, input);
 | 
								err = parse_defs(n, input, skip);
 | 
				
			||||||
			endchr = '}';
 | 
								endchr = '}';
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			err = parse_array_defs(n, input);
 | 
								err = parse_array_defs(n, input, skip);
 | 
				
			||||||
			endchr = ']';
 | 
								endchr = ']';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		c = get_nonwhite(input);
 | 
							c = get_nonwhite(input);
 | 
				
			||||||
| 
						 | 
					@ -577,7 +585,8 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx)
 | 
				
			||||||
			goto __end;
 | 
								goto __end;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (c != endchr) {
 | 
							if (c != endchr) {
 | 
				
			||||||
			snd_config_delete(n);
 | 
								if (n)
 | 
				
			||||||
 | 
									snd_config_delete(n);
 | 
				
			||||||
			err = LOCAL_UNEXPECTED_CHAR;
 | 
								err = LOCAL_UNEXPECTED_CHAR;
 | 
				
			||||||
			goto __end;
 | 
								goto __end;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -585,7 +594,7 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		unget_char(c, input);
 | 
							unget_char(c, input);
 | 
				
			||||||
		err = parse_value(&n, father, input, &id);
 | 
							err = parse_value(&n, father, input, &id, skip);
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			goto __end;
 | 
								goto __end;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
| 
						 | 
					@ -597,7 +606,7 @@ static int parse_array_def(snd_config_t *father, input_t *input, int idx)
 | 
				
			||||||
      	return err;
 | 
					      	return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int parse_array_defs(snd_config_t *father, input_t *input)
 | 
					static int parse_array_defs(snd_config_t *father, input_t *input, int skip)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int idx = 0;
 | 
						int idx = 0;
 | 
				
			||||||
	while (1) {
 | 
						while (1) {
 | 
				
			||||||
| 
						 | 
					@ -607,33 +616,33 @@ static int parse_array_defs(snd_config_t *father, input_t *input)
 | 
				
			||||||
		unget_char(c, input);
 | 
							unget_char(c, input);
 | 
				
			||||||
		if (c == ']')
 | 
							if (c == ']')
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		err = parse_array_def(father, input, idx++);
 | 
							err = parse_array_def(father, input, idx++, skip);
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			return err;
 | 
								return err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int parse_def(snd_config_t *father, input_t *input)
 | 
					static int parse_def(snd_config_t *father, input_t *input, int skip)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char *id = NULL;
 | 
						char *id = NULL;
 | 
				
			||||||
	int c;
 | 
						int c;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
	snd_config_t *n;
 | 
						snd_config_t *n;
 | 
				
			||||||
	enum {MERGE, NOCREATE, REMOVE} mode;
 | 
						enum {MERGE_CREATE, MERGE, OVERRIDE, DONT_OVERRIDE} mode;
 | 
				
			||||||
	while (1) {
 | 
						while (1) {
 | 
				
			||||||
		c = get_nonwhite(input);
 | 
							c = get_nonwhite(input);
 | 
				
			||||||
		if (c < 0)
 | 
							if (c < 0)
 | 
				
			||||||
			return c;
 | 
								return c;
 | 
				
			||||||
		switch (c) {
 | 
							switch (c) {
 | 
				
			||||||
		case '?':
 | 
							case '?':
 | 
				
			||||||
			mode = NOCREATE;
 | 
								mode = DONT_OVERRIDE;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case '!':
 | 
							case '!':
 | 
				
			||||||
			mode = REMOVE;
 | 
								mode = OVERRIDE;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			mode = MERGE;
 | 
								mode = MERGE_CREATE;
 | 
				
			||||||
			unget_char(c, input);
 | 
								unget_char(c, input);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		err = get_string(&id, 1, input);
 | 
							err = get_string(&id, 1, input);
 | 
				
			||||||
| 
						 | 
					@ -642,8 +651,17 @@ static int parse_def(snd_config_t *father, input_t *input)
 | 
				
			||||||
		c = get_nonwhite(input);
 | 
							c = get_nonwhite(input);
 | 
				
			||||||
		if (c != '.')
 | 
							if (c != '.')
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							if (skip) {
 | 
				
			||||||
 | 
								free(id);
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if (_snd_config_search(father, id, -1, &n) == 0) {
 | 
							if (_snd_config_search(father, id, -1, &n) == 0) {
 | 
				
			||||||
			if (mode != REMOVE) {
 | 
								if (mode == DONT_OVERRIDE) {
 | 
				
			||||||
 | 
									skip = 1;
 | 
				
			||||||
 | 
									free(id);
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (mode != OVERRIDE) {
 | 
				
			||||||
				if (n->type != SND_CONFIG_TYPE_COMPOUND) {
 | 
									if (n->type != SND_CONFIG_TYPE_COMPOUND) {
 | 
				
			||||||
					SNDERR("%s is not a compound", id);
 | 
										SNDERR("%s is not a compound", id);
 | 
				
			||||||
					return -EINVAL;
 | 
										return -EINVAL;
 | 
				
			||||||
| 
						 | 
					@ -655,7 +673,7 @@ static int parse_def(snd_config_t *father, input_t *input)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			snd_config_delete(n);
 | 
								snd_config_delete(n);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (mode == NOCREATE) {
 | 
							if (mode == MERGE) {
 | 
				
			||||||
			SNDERR("%s does not exists", id);
 | 
								SNDERR("%s does not exists", id);
 | 
				
			||||||
			err = -ENOENT;
 | 
								err = -ENOENT;
 | 
				
			||||||
			goto __end;
 | 
								goto __end;
 | 
				
			||||||
| 
						 | 
					@ -671,17 +689,22 @@ static int parse_def(snd_config_t *father, input_t *input)
 | 
				
			||||||
		if (c < 0)
 | 
							if (c < 0)
 | 
				
			||||||
			return c;
 | 
								return c;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (_snd_config_search(father, id, -1, &n) == 0) {
 | 
						if (!skip) {
 | 
				
			||||||
		if (mode == REMOVE) {
 | 
							if (_snd_config_search(father, id, -1, &n) == 0) {
 | 
				
			||||||
			snd_config_delete(n);
 | 
								if (mode == DONT_OVERRIDE) {
 | 
				
			||||||
 | 
									skip = 1;
 | 
				
			||||||
 | 
									n = NULL;
 | 
				
			||||||
 | 
								} else if (mode == OVERRIDE) {
 | 
				
			||||||
 | 
									snd_config_delete(n);
 | 
				
			||||||
 | 
									n = NULL;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			n = NULL;
 | 
								n = NULL;
 | 
				
			||||||
		}
 | 
								if (mode == MERGE) {
 | 
				
			||||||
	} else {
 | 
									SNDERR("%s does not exists", id);
 | 
				
			||||||
		n = NULL;
 | 
									err = -ENOENT;
 | 
				
			||||||
		if (mode == NOCREATE) {
 | 
									goto __end;
 | 
				
			||||||
			SNDERR("%s does not exists", id);
 | 
								}
 | 
				
			||||||
			err = -ENOENT;
 | 
					 | 
				
			||||||
			goto __end;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	switch (c) {
 | 
						switch (c) {
 | 
				
			||||||
| 
						 | 
					@ -689,27 +712,30 @@ static int parse_def(snd_config_t *father, input_t *input)
 | 
				
			||||||
	case '[':
 | 
						case '[':
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char endchr;
 | 
							char endchr;
 | 
				
			||||||
		if (n) {
 | 
							if (!skip) {
 | 
				
			||||||
			if (n->type != SND_CONFIG_TYPE_COMPOUND) {
 | 
								if (n) {
 | 
				
			||||||
				SNDERR("%s is not a compound", id);
 | 
									if (n->type != SND_CONFIG_TYPE_COMPOUND) {
 | 
				
			||||||
				err = -EINVAL;
 | 
										SNDERR("%s is not a compound", id);
 | 
				
			||||||
				goto __end;
 | 
										err = -EINVAL;
 | 
				
			||||||
 | 
										goto __end;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									err = _snd_config_make_add(&n, &id, SND_CONFIG_TYPE_COMPOUND, father);
 | 
				
			||||||
 | 
									if (err < 0)
 | 
				
			||||||
 | 
										goto __end;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			err = _snd_config_make_add(&n, &id, SND_CONFIG_TYPE_COMPOUND, father);
 | 
					 | 
				
			||||||
			if (err < 0)
 | 
					 | 
				
			||||||
				goto __end;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (c == '{') {
 | 
							if (c == '{') {
 | 
				
			||||||
			err = parse_defs(n, input);
 | 
								err = parse_defs(n, input, skip);
 | 
				
			||||||
			endchr = '}';
 | 
								endchr = '}';
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			err = parse_array_defs(n, input);
 | 
								err = parse_array_defs(n, input, skip);
 | 
				
			||||||
			endchr = ']';
 | 
								endchr = ']';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		c = get_nonwhite(input);
 | 
							c = get_nonwhite(input);
 | 
				
			||||||
		if (c != endchr) {
 | 
							if (c != endchr) {
 | 
				
			||||||
			snd_config_delete(n);
 | 
								if (n)
 | 
				
			||||||
 | 
									snd_config_delete(n);
 | 
				
			||||||
			err = LOCAL_UNEXPECTED_CHAR;
 | 
								err = LOCAL_UNEXPECTED_CHAR;
 | 
				
			||||||
			goto __end;
 | 
								goto __end;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -717,7 +743,7 @@ static int parse_def(snd_config_t *father, input_t *input)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		unget_char(c, input);
 | 
							unget_char(c, input);
 | 
				
			||||||
		err = parse_value(&n, father, input, &id);
 | 
							err = parse_value(&n, father, input, &id, skip);
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			goto __end;
 | 
								goto __end;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
| 
						 | 
					@ -736,7 +762,7 @@ static int parse_def(snd_config_t *father, input_t *input)
 | 
				
			||||||
	return err;
 | 
						return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
static int parse_defs(snd_config_t *father, input_t *input)
 | 
					static int parse_defs(snd_config_t *father, input_t *input, int skip)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int c, err;
 | 
						int c, err;
 | 
				
			||||||
	while (1) {
 | 
						while (1) {
 | 
				
			||||||
| 
						 | 
					@ -746,7 +772,7 @@ static int parse_defs(snd_config_t *father, input_t *input)
 | 
				
			||||||
		unget_char(c, input);
 | 
							unget_char(c, input);
 | 
				
			||||||
		if (c == '}')
 | 
							if (c == '}')
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		err = parse_def(father, input);
 | 
							err = parse_def(father, input, skip);
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			return err;
 | 
								return err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1041,7 +1067,7 @@ int snd_config_load(snd_config_t *config, snd_input_t *in)
 | 
				
			||||||
	fd->next = NULL;
 | 
						fd->next = NULL;
 | 
				
			||||||
	input.current = fd;
 | 
						input.current = fd;
 | 
				
			||||||
	input.unget = 0;
 | 
						input.unget = 0;
 | 
				
			||||||
	err = parse_defs(config, &input);
 | 
						err = parse_defs(config, &input, 0);
 | 
				
			||||||
	fd = input.current;
 | 
						fd = input.current;
 | 
				
			||||||
	if (err < 0) {
 | 
						if (err < 0) {
 | 
				
			||||||
		const char *str;
 | 
							const char *str;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue