"<HEAD>\n<TITLE>CSO/PH Query Form for $(HOST)</TITLE>\n</HEAD>\n<BODY>",
"<HTML>\n<HEAD>\n<TITLE>CSO/PH Query Form for $(HOST)</TITLE>\n</HEAD>\n<BODY>",
PRIVATE int generate_cso_form ARGS4(	char *,		host,	int,		port,	char *,		buf,	HTStream *,	Target){    int i, j, length;    size_t out;    int full_flag = 1;    char *key, *line;    CSOformgen_context ctx;    static char *template[] = {   "<HEAD>\n<TITLE>CSO/PH Query Form for $(HOST)</TITLE>\n</HEAD>\n<BODY>",   "<H2><I>CSO/PH Query Form</I> for <EM>$(HOST)</EM></H2>",   "To search the database for a name, fill in one or more of the fields",   "in the form below and activate the 'Submit query' button.  At least",   "one of the entered fields must be flagged as indexed.",   "<HR><FORM method=\"POST\" action=\"cso://$(HOST)/\">",   "[ <input type=\"submit\" value=\"Submit query\"> | ",   "<input type=\"reset\" value=\"Clear fields\"> ]",   "<P><DL>",   "   <DT>Search parameters (* indicates indexed field):",   "   <DD>", "$(NAMEFLD)    <DL COMPACT>\n    <DT><I>$(FDESC)</I>$(FNDX)",   "    <DD>Last: <input name=\"q_$(FID)\" type=\"text\" size=49$(FSIZE2)>",   "    <DD>First: <input name=\"q_$(FID)\" type=\"text\" size=48$(FSIZE2)>",   "$(QFIELDS)    <DT><I>$(FDESC)</I>$(FNDX)",   "    <DD><input name=\"q_$(FID)\" type=\"text\" $(FSIZE)>\n$(NEXTFLD)",   "    </DL>",   "   </DL>\n<P><DL>",   "   <DT>Output format:",   "   <DD>Returned data option: <select name=\"return\">",   "    <option>default<option selected>all<option>selected</select><BR>",   "$(RFIELDS)    <input type=\"checkbox\" name=\"r_$(FID)\"$(FDEF)> $(FDESC)<BR>",   "$(NEXTFLD)    ",   "   </DL></FORM><HR>\n</BODY>\n</HTML>",   (char *) 0    };    out = 0;    ctx.host = host;    ctx.seek = (char *) 0;    ctx.port = port;    ctx.fld = (CSOfield_info *) 0;    ctx.public_override = full_flag;    /*    **	Parse the strings in the template array to produce HTML document    **	to send to client.  First line is skipped for 'full' lists.    */    out = 0;    buf[out] = '\0';    for (i = full_flag ? /***1***/ 0 : 0; template[i]; i++) {	/*	**  Search the current string for substitution, flagged by $(	*/	for (line=template[i], j = 0; line[j]; j++) {	    if ((line[j] == '$') && (line[j+1] == '(')) {		/*		** Command detected, flush output buffer and find closing ')'		** that delimits the command.		*/		buf[out] = '\0';		if (out > 0)		    (*Target->isa->put_block)(Target, buf, strlen(buf));		out = 0;		for (key = &line[j]; line[j+1] && (line[j] != ')'); j++)		    ;		/*		**  Save context, interpet command and restore updated context.		*/		ctx.cur_line = i;		ctx.cur_off = j;		interpret_cso_key(key, buf, &length, &ctx, Target);		i = ctx.cur_line;		j = ctx.cur_off;		line = template[i];		out = length;		if (ctx.seek) {		    /*		    **	Command wants us to skip (forward) to indicated token.		    **	Start at current position.		    */		    int slen = strlen(ctx.seek);		    for (; template[i]; i++) {			for (line = template[i]; line[j]; j++) {			    if (line[j] == '$')				if (0 == strncmp(ctx.seek, &line[j], slen)) {				    if (j == 0)					j = strlen(template[--i])-1;				    else					--j;				    line = template[i];				    ctx.seek = (char *) 0;				    break;				}			}			if (!ctx.seek)			    break;			j = 0;		    }		    if (ctx.seek) {			char *temp = 0;			HTSprintf0(&temp, GOPHER_CSO_SEEK_FAILED, ctx.seek);			(*Target->isa->put_block)(Target, temp, strlen(temp));			FREE(temp);		    }		}	    } else {		/*		**  Non-command text, add to output buffer.		*/		buf[out++] = line[j];		if (out > (sizeof(buf)-3)) {		    buf[out] = '\0';			(*Target->isa->put_block)(Target, buf, strlen(buf));		    out = 0;		}	    }	}	buf[out++] = '\n';	buf[out] = '\0';    }    if (out > 0)	(*Target->isa->put_block)(Target, buf, strlen(buf));    return 0;}