/*
- * "$Id: template.c 6799 2007-08-15 19:33:36Z mike $"
+ * "$Id: template.c 6986 2007-09-25 15:34:52Z mike $"
*
* CGI template function.
*
#include "cgi-private.h"
#include <errno.h>
+#include <regex.h>
/*
compare[1024]; /* Comparison string */
int result; /* Result of comparison */
int uriencode; /* Encode as URI */
+ regex_t re; /* Regular expression to match */
fprintf(stderr, "DEBUG2: %*sStarting at file position %ld...\n", indent, "",
uriencode = 0;
for (s = name; (ch = getc(in)) != EOF;)
- if (strchr("}]<>=! \t\n", ch))
+ if (strchr("}]<>=!~ \t\n", ch))
break;
else if (s == name && ch == '%')
uriencode = 1;
* {name<value?true:false} Less than
* {name>value?true:false} Greater than
* {name!value?true:false} Not equal
+ * {name~refex?true:false} Regex match
*/
op = ch;
case '!' :
result = strcasecmp(outptr, compare) != 0;
break;
+ case '~' :
+ fprintf(stderr, "DEBUG: Regular expression \"%s\"\n", compare);
+
+ if (regcomp(&re, compare, REG_EXTENDED | REG_ICASE))
+ {
+ fprintf(stderr,
+ "ERROR: Unable to compile regular expresion \"%s\"!\n",
+ compare);
+ result = 0;
+ }
+ else
+ {
+ regmatch_t matches[10];
+
+ result = 0;
+
+ if (!regexec(&re, outptr, 10, matches, 0))
+ {
+ int i;
+ for (i = 0; i < 10; i ++)
+ {
+ fprintf(stderr, "DEBUG: matches[%d].rm_so=%d\n", i,
+ (int)matches[i].rm_so);
+ if (matches[i].rm_so < 0)
+ break;
+
+ result ++;
+ }
+ }
+
+ regfree(&re);
+ }
+ break;
default :
result = 1;
break;
/*
- * End of "$Id: template.c 6799 2007-08-15 19:33:36Z mike $".
+ * End of "$Id: template.c 6986 2007-09-25 15:34:52Z mike $".
*/