mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Better handling of string/integer parsing/printing
This commit is contained in:
parent
0561650846
commit
014de04488
1 changed files with 20 additions and 15 deletions
|
|
@ -282,7 +282,7 @@ static int get_delimstring(char **string, int delim, input_t *input)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return 1 for free string, 0 for delimited string */
|
/* Return 0 for free string, 1 for delimited string */
|
||||||
static int get_string(char **string, input_t *input)
|
static int get_string(char **string, input_t *input)
|
||||||
{
|
{
|
||||||
int c = get_nonwhite(input);
|
int c = get_nonwhite(input);
|
||||||
|
|
@ -309,13 +309,13 @@ static int get_string(char **string, input_t *input)
|
||||||
err = get_delimstring(string, c, input);
|
err = get_delimstring(string, c, input);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
return 0;
|
return 1;
|
||||||
default:
|
default:
|
||||||
unget_char(c, input);
|
unget_char(c, input);
|
||||||
err = get_freestring(string, input);
|
err = get_freestring(string, input);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,7 +475,7 @@ static int parse_def(snd_config_t *father, input_t *input)
|
||||||
err = get_string(&s, input);
|
err = get_string(&s, input);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
if (s[0] >= '0' && s[0] <= '9') {
|
if (!err && ((s[0] >= '0' && s[0] <= '9') || s[0] == '-')) {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
long i;
|
long i;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
@ -772,14 +772,20 @@ int snd_config_get(snd_config_t *config, void *ptr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void quoted_print(char *str, FILE *fp)
|
void string_print(char *str, int id, FILE *fp)
|
||||||
{
|
{
|
||||||
int quote = 0;
|
|
||||||
unsigned char *p = str;
|
unsigned char *p = str;
|
||||||
|
if (!id) {
|
||||||
|
switch (*p) {
|
||||||
|
case '0' ... '9':
|
||||||
|
case '-':
|
||||||
|
goto quoted;
|
||||||
|
}
|
||||||
|
}
|
||||||
loop:
|
loop:
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
goto nonquoted;
|
||||||
case 1 ... 31:
|
case 1 ... 31:
|
||||||
case 127 ... 255:
|
case 127 ... 255:
|
||||||
case ' ':
|
case ' ':
|
||||||
|
|
@ -791,16 +797,15 @@ void quoted_print(char *str, FILE *fp)
|
||||||
case ',':
|
case ',':
|
||||||
case '\'':
|
case '\'':
|
||||||
case '"':
|
case '"':
|
||||||
quote = 1;
|
goto quoted;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
p++;
|
p++;
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
if (!quote) {
|
nonquoted:
|
||||||
fputs(str, fp);
|
fputs(str, fp);
|
||||||
return;
|
return;
|
||||||
}
|
quoted:
|
||||||
putc('\'', fp);
|
putc('\'', fp);
|
||||||
p = str;
|
p = str;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
|
|
@ -863,7 +868,7 @@ static int _snd_config_save_leaf(snd_config_t *n, FILE *fp,
|
||||||
fprintf(fp, "%16g", n->u.real);
|
fprintf(fp, "%16g", n->u.real);
|
||||||
break;
|
break;
|
||||||
case SND_CONFIG_TYPE_STRING:
|
case SND_CONFIG_TYPE_STRING:
|
||||||
quoted_print(n->u.string, fp);
|
string_print(n->u.string, 0, fp);
|
||||||
break;
|
break;
|
||||||
case SND_CONFIG_TYPE_COMPOUND:
|
case SND_CONFIG_TYPE_COMPOUND:
|
||||||
putc('{', fp);
|
putc('{', fp);
|
||||||
|
|
@ -887,7 +892,7 @@ static void id_print(snd_config_t *n, FILE *fp, unsigned int joins)
|
||||||
id_print(n->father, fp, joins - 1);
|
id_print(n->father, fp, joins - 1);
|
||||||
putc('.', fp);
|
putc('.', fp);
|
||||||
}
|
}
|
||||||
quoted_print(n->id, fp);
|
string_print(n->id, 1, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _snd_config_save_leaves(snd_config_t *config, FILE *fp, unsigned int level, unsigned int joins)
|
static int _snd_config_save_leaves(snd_config_t *config, FILE *fp, unsigned int level, unsigned int joins)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue