version 1.43, 2017/12/08 18:41:59 |
version 1.44, 2017/12/11 13:25:57 |
|
|
|
|
static char *compile_addr(char *, struct s_addr *); |
static char *compile_addr(char *, struct s_addr *); |
static char *compile_ccl(char **, char *); |
static char *compile_ccl(char **, char *); |
static char *compile_delimited(char *, char *, int); |
static char *compile_delimited(char *, char *); |
static char *compile_flags(char *, struct s_subst *); |
static char *compile_flags(char *, struct s_subst *); |
static char *compile_re(char *, regex_t **); |
static char *compile_re(char *, regex_t **); |
static char *compile_subst(char *, struct s_subst *); |
static char *compile_subst(char *, struct s_subst *); |
|
|
* with the processed string. |
* with the processed string. |
*/ |
*/ |
static char * |
static char * |
compile_delimited(char *p, char *d, int is_tr) |
compile_delimited(char *p, char *d) |
{ |
{ |
char c; |
char c; |
|
|
|
|
p += 2; |
p += 2; |
continue; |
continue; |
} else if (*p == '\\' && p[1] == '\\') { |
} else if (*p == '\\' && p[1] == '\\') { |
if (is_tr) |
*d++ = *p++; |
p++; |
|
else |
|
*d++ = *p++; |
|
} else if (*p == c) { |
} else if (*p == c) { |
*d = '\0'; |
*d = '\0'; |
return (p + 1); |
return (p + 1); |
|
|
char *re; |
char *re; |
|
|
re = xmalloc(strlen(p) + 1); /* strlen(re) <= strlen(p) */ |
re = xmalloc(strlen(p) + 1); /* strlen(re) <= strlen(p) */ |
p = compile_delimited(p, re, 0); |
p = compile_delimited(p, re); |
if (p && strlen(re) == 0) { |
if (p && strlen(re) == 0) { |
*repp = NULL; |
*repp = NULL; |
free(re); |
free(re); |
|
|
* Compile a translation set of strings into a lookup table. |
* Compile a translation set of strings into a lookup table. |
*/ |
*/ |
static char * |
static char * |
compile_tr(char *p, char **transtab) |
compile_tr(char *old, char **transtab) |
{ |
{ |
int i; |
int i; |
char *lt, *op, *np; |
char delimiter, check[UCHAR_MAX]; |
char *old = NULL, *new = NULL; |
char *new, *end; |
|
|
if (*p == '\0' || *p == '\\') |
memset(check, 0, sizeof(check)); |
error(COMPILE, |
delimiter = *old; |
"transform pattern can not be delimited by newline or backslash"); |
if (delimiter == '\\') |
old = xmalloc(strlen(p) + 1); |
error(COMPILE, "\\ can not be used as a string delimiter"); |
p = compile_delimited(p, old, 1); |
else if (delimiter == '\n' || delimiter == '\0') |
if (p == NULL) { |
error(COMPILE, "newline can not be used as a string delimiter"); |
error(COMPILE, "unterminated transform source string"); |
|
goto bad; |
new = old++; |
} |
do { |
new = xmalloc(strlen(p) + 1); |
if ((new = strchr(new + 1, delimiter)) == NULL) |
p = compile_delimited(--p, new, 1); |
error(COMPILE, "unterminated transform source string"); |
if (p == NULL) { |
} while (*(new - 1) == '\\' && *(new -2) != '\\'); |
error(COMPILE, "unterminated transform target string"); |
*new = '\0'; |
goto bad; |
end = new++; |
} |
do { |
EATSPACE(); |
if ((end = strchr(end + 1, delimiter)) == NULL) |
if (strlen(new) != strlen(old)) { |
error(COMPILE, "unterminated transform target string"); |
error(COMPILE, "transform strings are not the same length"); |
} while (*(end -1) == '\\' && *(end -2) != '\\'); |
goto bad; |
*end = '\0'; |
} |
|
/* We assume characters are 8 bits */ |
/* We assume characters are 8 bits */ |
lt = xmalloc(UCHAR_MAX + 1); |
*transtab = xmalloc(UCHAR_MAX + 1); |
for (i = 0; i <= UCHAR_MAX; i++) |
for (i = 0; i <= UCHAR_MAX; i++) |
lt[i] = (char)i; |
(*transtab)[i] = (char)i; |
for (op = old, np = new; *op; op++, np++) |
|
lt[(u_char)*op] = *np; |
while (*old != '\0' && *new != '\0') { |
*transtab = lt; |
if (*old == '\\') { |
free(old); |
old++; |
free(new); |
if (*old == 'n') |
return (p); |
*old = '\n'; |
bad: |
else if (*old != delimiter && *old != '\\') |
free(old); |
error(COMPILE, "Unexpected character after " |
free(new); |
"backslash"); |
return (NULL); |
|
|
} |
|
if (*new == '\\') { |
|
new++; |
|
if (*new == 'n') |
|
*new = '\n'; |
|
else if (*new != delimiter && *new != '\\') |
|
error(COMPILE, "Unexpected character after " |
|
"backslash"); |
|
} |
|
if (check[*old] == 1) |
|
error(COMPILE, "Repeated character in source string"); |
|
check[*old] = 1; |
|
(*transtab)[*old++] = *new++; |
|
} |
|
if (*old != '\0' || *new != '\0') |
|
error(COMPILE, "transform strings are not the same length"); |
|
return end + 1; |
} |
} |
|
|
/* |
/* |