compile.c: refactor out alias parsing
This commit is contained in:
parent
06dca6c150
commit
31ede77a9a
1 changed files with 38 additions and 30 deletions
68
compile.c
68
compile.c
|
|
@ -107,8 +107,7 @@ static char* parse_value() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int parse_alias_definition() {
|
||||||
static int parse_alias() {
|
|
||||||
|
|
||||||
static char name[MAXNAME];
|
static char name[MAXNAME];
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
@ -140,6 +139,36 @@ static int parse_alias() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char* parse_alias() {
|
||||||
|
|
||||||
|
static char buf[4096];
|
||||||
|
int c, len = 0, trailing_space = 0;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
c = get_next_ch();
|
||||||
|
if (c == EOF || c == '\n')
|
||||||
|
break;
|
||||||
|
if (isspace(c)) {
|
||||||
|
if (len)
|
||||||
|
trailing_space = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isalias(c)) {
|
||||||
|
error("Invalid character '%c' in alias\n", c);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (trailing_space) {
|
||||||
|
error("Space not allowed in alias\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (len >= sizeof(buf))
|
||||||
|
return NULL;
|
||||||
|
buf[len++] = tolower(c);
|
||||||
|
}
|
||||||
|
buf[len] = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_filter(struct target *target) {
|
static int parse_filter(struct target *target) {
|
||||||
|
|
||||||
char *value = parse_value();
|
char *value = parse_value();
|
||||||
|
|
@ -151,8 +180,8 @@ static int parse_filter(struct target *target) {
|
||||||
|
|
||||||
static int parse_target(struct target *target) {
|
static int parse_target(struct target *target) {
|
||||||
|
|
||||||
char src[4096], alias[4096];
|
char src[4096], *alias;
|
||||||
int c, len = 0, trailing_space = 0;
|
int c, len = 0;
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
c = get_next_ch();
|
c = get_next_ch();
|
||||||
|
|
@ -165,31 +194,10 @@ static int parse_target(struct target *target) {
|
||||||
src[len] = '\0';
|
src[len] = '\0';
|
||||||
|
|
||||||
/* next, get alias */
|
/* next, get alias */
|
||||||
len = 0;
|
alias = parse_alias();
|
||||||
for(;;) {
|
if (!alias)
|
||||||
c = get_next_ch();
|
return -1;
|
||||||
if (c == EOF || c == '\n')
|
if (!alias[0] && !dest_table_nr) {
|
||||||
break;
|
|
||||||
if (isspace(c)) {
|
|
||||||
if (len)
|
|
||||||
trailing_space = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!isalias(c)) {
|
|
||||||
error("Invalid character '%c' in alias\n", c);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (trailing_space) {
|
|
||||||
error("Space not allowed in alias\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (len >= sizeof(alias))
|
|
||||||
return -1;
|
|
||||||
alias[len++] = tolower(c);
|
|
||||||
}
|
|
||||||
alias[len] = '\0';
|
|
||||||
|
|
||||||
if (!len && !dest_table_nr) {
|
|
||||||
error("No destination found for target '%s'\n", src);
|
error("No destination found for target '%s'\n", src);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -216,7 +224,7 @@ static int parse_config_file(const char *file) {
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
return 0;
|
return 0;
|
||||||
if (c == ':') {
|
if (c == ':') {
|
||||||
if (parse_alias() < 0)
|
if (parse_alias_definition() < 0)
|
||||||
break;
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue