/*
- * "$Id: template.c 5352 2006-03-29 16:26:38Z mike $"
+ * "$Id: template.c 5461 2006-04-25 17:15:45Z mike $"
*
* CGI template function.
*
static void cgi_copy(FILE *out, FILE *in, int element, char term,
int indent);
static void cgi_puts(const char *s, FILE *out);
+static void cgi_puturi(const char *s, FILE *out);
/*
char outval[1024], /* Formatted output string */
compare[1024]; /* Comparison string */
int result; /* Result of comparison */
+ int uriencode; /* Encode as URI */
fprintf(stderr, "DEBUG: %*sStarting at file position %ld...\n", indent, "",
* Get a variable name...
*/
+ uriencode = 0;
+
for (s = name; (ch = getc(in)) != EOF;)
if (strchr("}]<>=! \t\n", ch))
break;
+ else if (s == name && ch == '%')
+ uriencode = 1;
else if (s > name && ch == '?')
break;
else if (s < (name + sizeof(name) - 1))
*/
if (out)
- cgi_puts(outptr, out);
+ {
+ if (uriencode)
+ cgi_puturi(outptr, out);
+ else
+ cgi_puts(outptr, out);
+ }
continue;
}
/*
- * End of "$Id: template.c 5352 2006-03-29 16:26:38Z mike $".
+ * 'cgi_puturi()' - Put a URI string to the output file, quoting as needed...
+ */
+
+static void
+cgi_puturi(const char *s, /* I - String to output */
+ FILE *out) /* I - Output file */
+{
+ while (*s)
+ {
+ if (strchr("%&+ <>#=", *s) || *s & 128)
+ fprintf(out, "%%%02X", *s & 255);
+ else
+ putc(*s, out);
+
+ s ++;
+ }
+}
+
+
+/*
+ * End of "$Id: template.c 5461 2006-04-25 17:15:45Z mike $".
*/