CTRACE(tfp, "HTGopher: Unable to connect to remote host for `%s'.\n", arg);
CTRACE((tfp, "HTGopher: Unable to connect to remote host for `%s'.\n", arg));
PRIVATE int HTLoadGopher ARGS4(	CONST char *,		arg,	HTParentAnchor *,	anAnchor,	HTFormat,		format_out,	HTStream*,		sink){    char *command;			/* The whole command */    int status;				/* tcp return */    char gtype;				/* Gopher Node type */    char * selector;			/* Selector string */    if (!acceptable_inited)	 init_acceptable();    if (!arg)	return -3;		/* Bad if no name sepcified	*/    if (!*arg)	return -2;		/* Bad if name had zero length	*/    CTRACE(tfp, "HTGopher: Looking for %s\n", arg);    /*    **	If it's a port 105 GOPHER_CSO gtype with no ISINDEX token ('?'),    **	use the form-based CSO gateway (otherwise, return an ISINDEX    **	cover page or do the ISINDEX search). - FM    */    {	int len;	if ((len = strlen(arg)) > 5) {	    if (0 == strcmp((CONST char *)&arg[len-6], ":105/2")) {		/* Use CSO gateway. */		CTRACE(tfp, "HTGopher: Passing to CSO/PH gateway.\n");		return HTLoadCSO(arg, anAnchor, format_out, sink);	    }	}    }    /*    **	If it's a port 79/0[/...] URL, use the finger gateway. - FM    */    if (strstr(arg, ":79/0") != NULL) {#ifndef DISABLE_FINGER	CTRACE(tfp, "HTGopher: Passing to finger gateway.\n");	return HTLoadFinger(arg, anAnchor, format_out, sink);#else /* finger is disabled */	HTAlert(gettext("Unable to access document!"));	return HT_NOT_LOADED;#endif /* DISABLE_FINGER */    }    /*    **	Get entity type, and selector string.    */    {	char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);	gtype = '1';		/* Default = menu */	selector = p1;	if ((*selector++=='/') && (*selector)) {	/* Skip first slash */	    gtype = *selector++;			/* Pick up gtype */	}	if (gtype == GOPHER_INDEX) {	    char * query;	    /*	    **	Search is allowed.	    */	    HTAnchor_setIndex(anAnchor, anAnchor->address);	    query = strchr(selector, '?');	/* Look for search string */	    if (!query || !query[1]) {		/* No search required */		target = HTML_new(anAnchor, format_out, sink);		targetClass = *target->isa;		display_index(arg, anAnchor);	/* Display "cover page" */		return HT_LOADED;		/* Local function only */	    }	    *query++ = '\0';			/* Skip '?'	*/	    command =		    (char *)malloc(strlen(selector)+ 1 + strlen(query)+ 2 + 1);	      if (command == NULL)		  outofmem(__FILE__, "HTLoadGopher");	    de_escape(command, selector);	/* Bug fix TBL 921208 */	    strcat(command, "\t");	    {					/* Remove plus signs 921006 */		char *p;		for (p=query; *p; p++) {		    if (*p == '+') *p = ' ';		}	    }	    de_escape(&command[strlen(command)], query);/* bug fix LJM 940415 */	} else if (gtype == GOPHER_CSO) {	    char * query;	    /*	    **	Search is allowed.	    */	    query = strchr(selector, '?');	/* Look for search string */	    if (!query || !query[1]) {		/* No search required */		target = HTML_new(anAnchor, format_out, sink);		targetClass = *target->isa;		display_cso(arg, anAnchor);	/* Display "cover page" */		return HT_LOADED;		/* Local function only */	    }	    HTAnchor_setIndex(anAnchor, anAnchor->address);	    *query++ = '\0';			/* Skip '?'	*/	    command = (char *)malloc(strlen("query")+1 + strlen(query)+2+1);	      if (command == NULL)		  outofmem(__FILE__, "HTLoadGopher");	    de_escape(command, selector);	/* Bug fix TBL 921208 */	    strcpy(command, "query ");	    {					/* Remove plus signs 921006 */		char *p;		for (p=query; *p; p++) {		    if (*p == '+') *p = ' ';		}	    }	    de_escape(&command[strlen(command)], query);/* bug fix LJM 940415 */	} else {				/* Not index */	    command = (char *)malloc(strlen(selector)+2+1);	    if (command == NULL)		outofmem(__FILE__, "HTLoadGopher");	    de_escape(command, selector);	}	FREE(p1);    }    {	char * p = command + strlen(command);	*p++ = CR;		/* Macros to be correct on Mac */	*p++ = LF;	*p++ = '\0';    }    /*    **	Set up a socket to the server for the data.    */    status = HTDoConnect (arg, "gopher", GOPHER_PORT, &s);    if (status == HT_INTERRUPTED) {	/*	**  Interrupt cleanly.	*/	CTRACE(tfp, "HTGopher: Interrupted on connect; recovering cleanly.\n");	_HTProgress (CONNECTION_INTERRUPTED);	FREE(command);	return HT_NOT_LOADED;    }    if (status < 0) {	CTRACE(tfp, "HTGopher: Unable to connect to remote host for `%s'.\n",		    arg);	FREE(command);	return HTInetStatus("connect");    }    HTInitInput(s);		/* Set up input buffering */    CTRACE(tfp, "HTGopher: Connected, writing command `%s' to socket %d\n",		command, s);#ifdef NOT_ASCII    {	char * p;	for (p = command; *p; p++) {	    *p = TOASCII(*p);	}    }#endif    _HTProgress (GOPHER_SENDING_REQUEST);    status = NETWRITE(s, command, (int)strlen(command));    FREE(command);    if (status < 0) {	CTRACE(tfp, "HTGopher: Unable to send command.\n");	return HTInetStatus("send");    }    _HTProgress (GOPHER_SENT_REQUEST);    /*    **	Now read the data from the socket.    */    switch (gtype) {    case GOPHER_TEXT :	HTParseSocket(WWW_PLAINTEXT, format_out, anAnchor, s, sink);	break;    case GOPHER_HTML :    case GOPHER_CHTML :	HTParseSocket(WWW_HTML, format_out, anAnchor, s, sink);	break;    case GOPHER_GIF:    case GOPHER_IMAGE:    case GOPHER_PLUS_IMAGE:	HTParseSocket(HTAtom_for("image/gif"),			   format_out, anAnchor, s, sink);	break;    case GOPHER_MENU :    case GOPHER_INDEX :	target = HTML_new(anAnchor, format_out, sink);	targetClass = *target->isa;	parse_menu(arg, anAnchor);	break;    case GOPHER_CSO:	target = HTML_new(anAnchor, format_out, sink);	targetClass = *target->isa;	parse_cso(arg, anAnchor);	break;    case GOPHER_SOUND :    case GOPHER_PLUS_SOUND :	HTParseSocket(WWW_AUDIO, format_out, anAnchor, s, sink);	break;    case GOPHER_PLUS_MOVIE:	HTParseSocket(HTAtom_for("video/mpeg"), format_out, anAnchor, s, sink);	break;    case GOPHER_PLUS_PDF:	HTParseSocket(HTAtom_for("application/pdf"), format_out, anAnchor,				  s, sink);	break;    case GOPHER_MACBINHEX:    case GOPHER_PCBINARY:    case GOPHER_UUENCODED:    case GOPHER_BINARY:    default:	/*	**  Specifying WWW_UNKNOWN forces dump to local disk.	*/	HTParseSocket (WWW_UNKNOWN, format_out, anAnchor, s, sink);	break;    } /* switch(gtype) */    NETCLOSE(s);    return HT_LOADED;}