diff options
Diffstat (limited to 'template.c')
-rw-r--r-- | template.c | 166 |
1 files changed, 86 insertions, 80 deletions
@@ -268,98 +268,104 @@ static int do_Parameter(char **pp, struct template *pTpl) /* Check frompos, if it has an R, then topos should be a regex */ if(*p == ':') { ++p; /* eat ':' */ -#ifdef FEATURE_REGEXP
- if (*p == 'R') {
- /* APR: R found! regex alarm ! :) */
- ++p; /* eat ':' */
-
- if (*p != ':') {
- /* There is something more than an R , this is invalid ! */
- /* Complain on extra characters */
- dprintf
- ("error: extra character in frompos, only \"R\" and numbers are allowed: '%s'\n",
- p);
- /* TODO: rger- add/change to logerror? */
- } else {
- pTpe->data.field.has_regex = 1;
- }
- } else {
- /* now we fall through the "regular" FromPos code */
+#ifdef FEATURE_REGEXP + if (*p == 'R') { + /* APR: R found! regex alarm ! :) */ + ++p; /* eat ':' */ + + if (*p != ':') { + /* There is something more than an R , this is invalid ! */ + /* Complain on extra characters */ + dprintf + ("error: extra character in frompos, only \"R\" and numbers are allowed: '%s'\n", + p); + /* TODO: rger- add/change to logerror? */ + } else { + pTpe->data.field.has_regex = 1; + } + } else { + /* now we fall through the "regular" FromPos code */ #endif /* #ifdef FEATURE_REGEXP */ - iNum = 0; - while(isdigit(*p)) - iNum = iNum * 10 + *p++ - '0'; - pTpe->data.field.iFromPos = iNum; - /* skip to next known good */ - while(*p && *p != '%' && *p != ':') { - /* TODO: complain on extra characters */ - dprintf("error: extra character in frompos: '%s'\n", p); - ++p; + iNum = 0; + while(isdigit(*p)) + iNum = iNum * 10 + *p++ - '0'; + pTpe->data.field.iFromPos = iNum; + /* skip to next known good */ + while(*p && *p != '%' && *p != ':') { + /* TODO: complain on extra characters */ + dprintf("error: extra character in frompos: '%s'\n", p); + ++p; + } +#ifdef FEATURE_REGEXP } +#endif /* #ifdef FEATURE_REGEXP */ } /* check topos (holds an regex if FromPos is "R"*/ if(*p == ':') { ++p; /* eat ':' */ #ifdef FEATURE_REGEXP - if (pTpe->data.field.has_regex) {
-
- dprintf("debug: has regex \n");
-
- /* APR 2005-09 I need the string that represent the regex */
- /* The regex end is: "--end" */
- /* TODO : this is hardcoded and cant be escaped, please change */
- regex_end = strstr(p, "--end");
- if (regex_end == NULL) {
- dprintf("error: Cant find regex end in: '%s'\n", p);
- pTpe->data.field.has_regex = 0;
- } else {
- /* We get here ONLY if the regex end was found */
- longitud = regex_end - p;
- /* Malloc for the regex string */
- regex_char = (char *) malloc(longitud + 1);
- if (regex_char == NULL) {
- dprintf
- ("Could not allocate memory for template parameter!\n");
- pTpe->data.field.has_regex = 0;
- return 1;
- /* TODO: RGer: check if we can recover better... (probably not) */
- }
-
- regex_char[0] = '\0';
-
- /* Get the regex string for compiling later */
- strncpy(regex_char, p, longitud);
-
- dprintf("debug: regex detected: '%s'\n",
- regex_char);
-
- /* Now i compile the regex */
- /* Remember that the re is an attribute of the Template entry */
- if (regcomp(&(pTpe->data.field.re), regex_char, 0) != 0) {
- dprintf("error: Cant compile regex: '%s'\n", regex_char);
- pTpe->data.field.has_regex = 2;
- }
-
- /* Finally we move the pointer to the end of the regex so it aint parsed twice or something weird */
- p = regex_end + 5/*strlen("--end")*/;
- free(regex_char);
- }
- } else {
- /* fallthrough to "regular" ToPos code */
+ if (pTpe->data.field.has_regex) { + + dprintf("debug: has regex \n"); + + /* APR 2005-09 I need the string that represent the regex */ + /* The regex end is: "--end" */ + /* TODO : this is hardcoded and cant be escaped, please change */ + regex_end = strstr(p, "--end"); + if (regex_end == NULL) { + dprintf("error: Cant find regex end in: '%s'\n", p); + pTpe->data.field.has_regex = 0; + } else { + /* We get here ONLY if the regex end was found */ + longitud = regex_end - p; + /* Malloc for the regex string */ + regex_char = (char *) malloc(longitud + 1); + if (regex_char == NULL) { + dprintf + ("Could not allocate memory for template parameter!\n"); + pTpe->data.field.has_regex = 0; + return 1; + /* TODO: RGer: check if we can recover better... (probably not) */ + } + + regex_char[0] = '\0'; + /* Get the regex string for compiling later */ + strncpy(regex_char, p, longitud); + + dprintf("debug: regex detected: '%s'\n", + regex_char); + + /* Now i compile the regex */ + /* Remember that the re is an attribute of the Template entry */ + if (regcomp(&(pTpe->data.field.re), regex_char, 0) != 0) { + dprintf("error: Cant compile regex: '%s'\n", regex_char); + pTpe->data.field.has_regex = 2; + } + + /* Finally we move the pointer to the end of the regex + * so it aint parsed twice or something weird */ + p = regex_end + 5/*strlen("--end")*/; + free(regex_char); + } + } else { + /* fallthrough to "regular" ToPos code */ #endif /* #ifdef FEATURE_REGEXP */ - iNum = 0; - while(isdigit(*p)) - iNum = iNum * 10 + *p++ - '0'; - pTpe->data.field.iToPos = iNum; - /* skip to next known good */ - while(*p && *p != '%' && *p != ':') { - /* TODO: complain on extra characters */ - dprintf("error: extra character in frompos: '%s'\n", p); - ++p; + iNum = 0; + while(isdigit(*p)) + iNum = iNum * 10 + *p++ - '0'; + pTpe->data.field.iToPos = iNum; + /* skip to next known good */ + while(*p && *p != '%' && *p != ':') { + /* TODO: complain on extra characters */ + dprintf("error: extra character in frompos: '%s'\n", p); + ++p; + } +#ifdef FEATURE_REGEXP } +#endif /* #ifdef FEATURE_REGEXP */ } /* TODO: add more sanity checks. For now, we do the bare minimum */ |