Text File

Received: from odin.INS.CWRU.Edu (odin.INS.CWRU.Edu [129.22.8.102]) by garcon.unicom.com (8.6.12/8.6.12) with ESMTP id MAA15329 for <chip@unicom.com>; Thu, 12 Dec 1996 12:53:31 -0600 (CST) Received: (trier@localhost) by odin.INS.CWRU.Edu (8.7.6+cwru/CWRU-2.3-ins) id NAA20462; Thu, 12 Dec 1996 13:53:19 -0500 (EST) (from trier for chip@unicom.com) Message-Id: <199612121853.NAA20462@odin.INS.CWRU.Edu> From: trier@odin.INS.CWRU.Edu (Stephen C. Trier) Date: Thu, 12 Dec 1996 13:53:18 -0500 X-Mailer: Mail User's Shell (7.2.5 10/14/92) To: chip@unicom.com Subject: cgi-postin patch for TCL output Status: OR

Chip,

Here is a patch to make cgi-postin work with TCL. I used the -T command-line option to enable TCL output, and the TCL output always goes into an associative array: by default, or the "prefix" if -v is specified.

Stephen

*** cgi-postin.c.orig Wed Dec 11 11:52:38 1996 --- cgi-postin.c Thu Dec 12 13:42:50 1996 *************** *** 11,24 **** * * Edit at tabstops=4. * ! * Usage: cgi-postin [-pt] [-v prefix] * * Thanks to: * - David DeSimone <fox@mikey.convex.com> for the CONTENT_LENGTH fix. * - Paul E. Hoffman <phoffman@proper.com> for the perl assistance. */

! #define USAGE "usage: %s [-pt] [-v prefix]"

/* --- 11,24 ---- * * Edit at tabstops=4. * ! * Usage: cgi-postin [-ptT] [-v prefix] * * Thanks to: * - David DeSimone <fox@mikey.convex.com> for the CONTENT_LENGTH fix. * - Paul E. Hoffman <phoffman@proper.com> for the perl assistance. */

! #define USAGE "usage: %s [-ptT] [-v prefix]"

/* *************** *** 120,125 **** --- 120,126 ---- char *unescape(); void emit_assignment_sh(); void emit_assignment_perl(); + void emit_assignment_tcl();

main(argc, argv) *************** *** 144,150 **** /* * Crack the command line. */ ! while ((i = getopt(argc, argv, "ptv:")) != EOF) { switch (i) { case 'p': emit_assignment = emit_assignment_perl; --- 145,151 ---- /* * Crack the command line. */ ! while ((i = getopt(argc, argv, "ptTv:")) != EOF) { switch (i) { case 'p': emit_assignment = emit_assignment_perl; *************** *** 152,157 **** --- 153,161 ---- case 't': Terse_diagnostics = TRUE; break; + case 'T': + emit_assignment = emit_assignment_tcl; + break; case 'v': if (optarg[0] == '\0' || strcmp(optarg, "-") == 0) Var_prefix = NULL; *************** *** 404,407 **** --- 408,470 ---- fputs("';\n", stdout); }

+ + /* + * Output a TCL assignment in format: set CGI(name) "value" + * + * The TCL usage looks like this: + * eval [exec cgi-postin -T] + * + * It sets elements of the associative array to the name-value pairs. + * + * The -v option sets the name of the associative array to use; the default + * is . + */ + + static void tcl_clean(); + + void emit_assignment_tcl(name, value) + char *name, *value; + { + char *prefix = "CGI"; + + if (!name) + return; + if (Var_prefix) + prefix = Var_prefix; + + fprintf(stdout, "set %s(", prefix); + tcl_clean(name); + fputs(") \"", stdout); + tcl_clean(value); + fputs("\"\n", stdout); + } + + /* + * tcl_clean: Given a string, do appropriate backslash-escaping so that + * it can be delivered to TCL in a string without corruption. + */ + + static void tcl_clean(s) + char *s; + { + while (s && *s) { + switch (*s) { + case '{': + case '}': + case '"': + case '[': + case ']': + case '$': + case ' ': + case '\\': + putchar('\\'); + break; + default: + break; + } + putchar(*s); + s++; + } + }

-- Stephen Trier Les grandes personnes sont décidément bien bizarres, trier@ins.cwru.edu se dit le petit prince. KG8IH Antoine de Saint Exupéry, _Le Petit Prince_