/*
- * "$Id: template.c 5113 2006-02-16 12:02:44Z mike $"
+ * "$Id: template.c 5548 2006-05-19 19:38:31Z 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);
/*
fprintf(stderr, "DEBUG: cgiCopyTemplateFile(out=%p, tmpl=\"%s\")\n", out,
- tmpl);
+ tmpl ? tmpl : "(null)");
/*
* Open the template file...
if ((in = fopen(tmpl, "r")) == NULL)
{
fprintf(stderr, "ERROR: Unable to open template file \"%s\" - %s\n",
- tmpl, strerror(errno));
+ tmpl ? tmpl : "(null)", strerror(errno));
return;
}
FILE *in; /* Input file */
- fprintf(stderr, "DEBUG: cgiCopyTemplateLang(tmpl=\"%s\")\n", tmpl);
+ fprintf(stderr, "DEBUG: cgiCopyTemplateLang(tmpl=\"%s\")\n",
+ tmpl ? tmpl : "(null)");
/*
* Convert the language to a locale name...
if ((lang = getenv("LANG")) != NULL)
{
for (i = 0; lang[i] && i < 15; i ++)
- if (isalnum(lang[i] & 255))
+ if (isalnum(lang[i] & 255) || lang[i] == '_')
locale[i] = tolower(lang[i]);
else if (lang[i] == '-')
locale[i] = '_';
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 5113 2006-02-16 12:02:44Z 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 5548 2006-05-19 19:38:31Z mike $".
*/