CTRACE(tfp, "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n");
CTRACE((tfp, "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n"));
PRIVATE int generate_cso_report ARGS1(	HTStream *,	Target){    int ich;    char line[BIG];    char *buf = 0;    char *p = line, *href = NULL;    int len, i, prev_ndx, ndx;    char *rcode, *ndx_str, *fname, *fvalue, *l;    CSOfield_info *fld;    BOOL stop = FALSE;    /*    **	Read lines until non-negative status.    */    prev_ndx = -100;    /*    **	Start grabbing chars from the network.    */    while (!stop && (ich = NEXT_CHAR) != EOF) {	if (interrupted_in_htgetcharacter) {	    CTRACE(tfp, "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n");	    _HTProgress (CONNECTION_INTERRUPTED);	    goto end_CSOreport;	}	if ((char)ich != LF) {	    *p = ich;		/* Put character in line */	    if (p < &line[BIG-1]) {		p++;	    }	} else {	    *p = '\0';		/* Terminate line */	    /*	    **	OK we now have a line.	    **	Load it as 'p' and parse it.	    */	    p = line;	    if (p[0] != '-' && p[0] != '1') {		stop = TRUE;	    }	    rcode = (p[0] == '-') ? &p[1] : p;	    ndx_str = fname = NULL;	    len = strlen(p);	    for (i = 0; i < len; i++) {		if (p[i] == ':') {		    p[i] = '\0';		    if (!ndx_str) {			fname = ndx_str = &p[i+1];		    } else {			fname = &p[i+1];			break;		    }		}	    }	    if (ndx_str) {		ndx = atoi(ndx_str);		if (prev_ndx != ndx) {		    if (prev_ndx != -100) {			HTSprintf0(&buf, "</DL></DL>\n");			(*Target->isa->put_block)(Target, buf, strlen(buf));		    }		    if (ndx == 0) {			HTSprintf0(&buf,		  "<HR><DL><DT>Information/status<DD><DL><DT>\n");			(*Target->isa->put_block)(Target, buf, strlen(buf));		    } else {			HTSprintf0(&buf,	      "<HR><DL><DT>Entry %d:<DD><DL COMPACT><DT>\n", ndx);			(*Target->isa->put_block)(Target, buf, strlen(buf));		    }		    prev_ndx = ndx;		}	    } else {		HTSprintf0(&buf, "<DD>%s\n", rcode);		(*Target->isa->put_block)(Target, buf, strlen(buf));		continue;	    }	    if ((*rcode >= '2') && (*rcode <= '5') && (fname != ndx_str)) {		while (*fname == ' ') {		    fname++;	/* trim leading spaces */		}		for (fvalue = fname; *fvalue; fvalue++) {		    if (*fvalue == ':') {			*fvalue++ = '\0';			i = strlen(fname) - 1;			while (i >= 0 && fname[i] == ' ') {			    fname[i--] = '\0'; /* trim trailing */			}			break;		    }		}		if (fvalue) {		    while (*fvalue == ' ') {			fvalue++;	/* trim leading spaces */		    }		}		if (*fname) {		    for (fld = CSOfields; fld; fld = fld->next) {			if (!strcmp(fld->name, fname)) {			    if (fld->description) {				fname = fld->description;			    }			    break;			}		    }		    if (fld && fld->url) {			HTSprintf0(&buf,				"<DT><I>%s</I><DD><A HREF=\"%s\">%s</A>\n",				fname, fvalue, fvalue);			(*Target->isa->put_block)(Target, buf, strlen(buf));		    } else {			HTSprintf0(&buf, "<DT><I>%s</I><DD>", fname);			(*Target->isa->put_block)(Target, buf, strlen(buf));			buf[0] = '\0';			l = fvalue;			while (*l) {			    if (*l == '<') {				StrAllocCat(buf, "&lt;");				l++;			    } else if (*l == '>') {				StrAllocCat(buf, "&gt;");				l++;			    } else if (strncmp(l, "news:", 5) &&				       strncmp(l, "snews://", 8) &&				       strncmp(l, "nntp://", 7) &&				       strncmp(l, "snewspost:", 10) &&				       strncmp(l, "snewsreply:", 11) &&				       strncmp(l, "newspost:", 9) &&				       strncmp(l, "newsreply:", 10) &&				       strncmp(l, "ftp://", 6) &&				       strncmp(l, "file:/", 6) &&				       strncmp(l, "finger://", 9) &&				       strncmp(l, "http://", 7) &&				       strncmp(l, "https://", 8) &&				       strncmp(l, "wais://", 7) &&				       strncmp(l, "mailto:", 7) &&				       strncmp(l, "cso://", 6) &&				       strncmp(l, "gopher://", 9)) {				HTSprintf(&buf, "%c", *l++);			    } else {				StrAllocCat(buf, "<a href=\"");				StrAllocCopy(href, l);				StrAllocCat(buf, strtok(href, " \r\n\t,>)\""));				StrAllocCat(buf, "\">");				while (*l && !strchr(" \r\n\t,>)\"", *l)) {				    HTSprintf(&buf, "%c", *l++);				}				StrAllocCat(buf, "</a>");				FREE(href);			    }			}			StrAllocCat(buf, "\n");			(*Target->isa->put_block)(Target, buf, strlen(buf));		    }		} else {		    HTSprintf0(&buf, "<DD>");		    (*Target->isa->put_block)(Target, buf, strlen(buf));		    buf[0] = '\0';		    l = fvalue;		    while (*l) {			if (*l == '<') {			    StrAllocCat(buf, "&lt;");			    l++;			} else if (*l == '>') {			    StrAllocCat(buf, "&gt;");			    l++;			} else if (strncmp(l, "news:", 5) &&				   strncmp(l, "snews://", 8) &&				   strncmp(l, "nntp://", 7) &&				   strncmp(l, "snewspost:", 10) &&				   strncmp(l, "snewsreply:", 11) &&				   strncmp(l, "newspost:", 9) &&				   strncmp(l, "newsreply:", 10) &&				   strncmp(l, "ftp://", 6) &&				   strncmp(l, "file:/", 6) &&				   strncmp(l, "finger://", 9) &&				   strncmp(l, "http://", 7) &&				   strncmp(l, "https://", 8) &&				   strncmp(l, "wais://", 7) &&				   strncmp(l, "mailto:", 7) &&				   strncmp(l, "cso://", 6) &&				   strncmp(l, "gopher://", 9)) {			    HTSprintf(&buf, "%c", *l++);			} else {			    StrAllocCat(buf, "<a href=\"");			    StrAllocCopy(href, l);			    StrAllocCat(buf, strtok(href, " \r\n\t,>)\""));			    StrAllocCat(buf, "\">");			    while (*l && !strchr(" \r\n\t,>)\"", *l)) {				HTSprintf(&buf, "%c", *l++);			    }			    StrAllocCat(buf, "</a>");			    FREE(href);			}		    }		    StrAllocCat(buf, "\n");		    (*Target->isa->put_block)(Target, buf, strlen(buf));		}	    } else {		HTSprintf0(&buf, "<DD>%s\n", fname ? fname : rcode );		(*Target->isa->put_block)(Target, buf, strlen(buf));	    }	}    }end_CSOreport:    if (prev_ndx != -100) {	HTSprintf0(&buf, "</DL></DL>\n");	(*Target->isa->put_block)(Target, buf, strlen(buf));    }    FREE(buf);    return 0;}