(GotHost ? "resolved" : "timed out"));
(GotHost ? "resolved" : "timed out")));
PUBLIC BOOLEAN LYExpandHostForURL ARGS3(	char **,	AllocatedString,	char *,		prefix_list,	char *,		suffix_list){    char DomainPrefix[80], *StartP, *EndP;    char DomainSuffix[80], *StartS, *EndS;    char *Str = NULL, *StrColon = NULL, *MsgStr = NULL;    char *Host = NULL, *HostColon = NULL, *host = NULL;    char *Path = NULL;    char *Fragment = NULL;    BOOLEAN GotHost = FALSE;    BOOLEAN Startup = (helpfilepath == NULL);    /*     *	If it's a NULL or zero-length string,     *	or if it begins with a slash or hash,     *	don't continue pointlessly. - FM     */    if (!(*AllocatedString) || *AllocatedString[0] == '\0' ||	*AllocatedString[0] == '/' || *AllocatedString[0] == '#') {	return GotHost;    }    /*     *	If it's a partial or relative path,     *	don't continue pointlessly. - FM     */    if (!strncmp(*AllocatedString, "..", 2) ||	!strncmp(*AllocatedString, "./", 2)) {	return GotHost;    }    /*     *	Make a clean copy of the string, and trim off the     *	path if one is present, but save the information     *	so we can restore the path after filling in the     *	Host[:port] field. - FM     */    StrAllocCopy(Str, *AllocatedString);    if ((Path = strchr(Str, '/')) != NULL) {	/*	 *  Have a path.  Any fragment should	 *  already be included in Path. - FM	 */	*Path = '\0';    } else if ((Fragment = strchr(Str, '#')) != NULL) {	/*	 *  No path, so check for a fragment and	 *  trim that, to be restored after filling	 *  in the Host[:port] field. - FM	 */	*Fragment = '\0';    }    /*     *	If the potential host string has a colon, assume it     *	begins a port field, and trim it off, but save the     *	information so we can restore the port field after     *	filling in the host field. - FM     */    if ((StrColon = strrchr(Str, ':')) != NULL &&	isdigit((unsigned char)StrColon[1])) {	if (StrColon == Str) {	    FREE(Str);	    return GotHost;	}	*StrColon = '\0';    }    /*     *	Do a DNS test on the potential host field     *	as presently trimmed. - FM     */    StrAllocCopy(host, Str);    HTUnEscape(host);    if (LYCursesON) {	StrAllocCopy(MsgStr, WWW_FIND_MESSAGE);	StrAllocCat(MsgStr, host);	StrAllocCat(MsgStr, FIRST_SEGMENT);	HTProgress(MsgStr);    } else if (Startup && !dump_output_immediately) {	fprintf(stdout, "%s '%s'%s\n", WWW_FIND_MESSAGE, host, FIRST_SEGMENT);    }#ifndef DJGPP    if (LYGetHostByName(host) != NULL)#else    if (resolve(host) != 0)#endif /* DJGPP */    {	/*	 *  Clear any residual interrupt. - FM	 */	if (LYCursesON && HTCheckForInterrupt()) {	    CTRACE(tfp, "LYExpandHostForURL: Ignoring interrupt because '%s' resolved.\n",			host);	}	/*	 *  Return success. - FM	 */	GotHost = TRUE;	FREE(host);	FREE(Str);	FREE(MsgStr);	return GotHost;#ifndef DJGPP    } else if (LYCursesON && (lynx_nsl_status == HT_INTERRUPTED)) {#else /* DJGPP */    } else if (LYCursesON && HTCheckForInterrupt()) {#endif /* DJGPP */	/*	 *  Give the user chance to interrupt lookup cycles. - KW & FM	 */	CTRACE(tfp, "LYExpandHostForURL: Interrupted while '%s' failed to resolve.\n",		    host);	/*	 *  Return failure. - FM	 */	FREE(host);	FREE(Str);	FREE(MsgStr);	return FALSE;    }    /*     *	Set the first prefix, making it a zero-length string     *	if the list is NULL or if the potential host field     *	ends with a dot. - FM     */    StartP = ((prefix_list && Str[strlen(Str)-1] != '.') ?					     prefix_list : "");    /*     *	If we have a prefix, but the allocated string is     *	one of the common host prefixes, make our prefix     *	a zero-length string. - FM     */    if (*StartP && *StartP != '.') {	if (!strncasecomp(*AllocatedString, "www.", 4) ||	    !strncasecomp(*AllocatedString, "ftp.", 4) ||	    !strncasecomp(*AllocatedString, "gopher.", 7) ||	    !strncasecomp(*AllocatedString, "wais.", 5) ||	    !strncasecomp(*AllocatedString, "cso.", 4) ||	    !strncasecomp(*AllocatedString, "ns.", 3) ||	    !strncasecomp(*AllocatedString, "ph.", 3) ||	    !strncasecomp(*AllocatedString, "finger.", 7) ||	    !strncasecomp(*AllocatedString, "news.", 5) ||	    !strncasecomp(*AllocatedString, "nntp.", 5)) {	    StartP = "";	}    }    while ((*StartP) && (WHITE(*StartP) || *StartP == ',')) {	StartP++;	/* Skip whitespace and separators */    }    EndP = StartP;    while (*EndP && !WHITE(*EndP) && *EndP != ',') {	EndP++;		/* Find separator */    }    LYstrncpy(DomainPrefix, StartP, (EndP - StartP));    /*     *	Test each prefix with each suffix. - FM     */    do {	/*	 *  Set the first suffix, making it a zero-length string	 *  if the list is NULL or if the potential host field	 *  begins with a dot. - FM	 */	StartS = ((suffix_list && *Str != '.') ?				   suffix_list : "");	while ((*StartS) && (WHITE(*StartS) || *StartS == ',')) {	    StartS++;	/* Skip whitespace and separators */	}	EndS = StartS;	while (*EndS && !WHITE(*EndS) && *EndS != ',') {	    EndS++;	/* Find separator */	}	LYstrncpy(DomainSuffix, StartS, (EndS - StartS));	/*	 *  Create domain names and do DNS tests. - FM	 */	do {	    StrAllocCopy(Host, DomainPrefix);	    StrAllocCat(Host, ((*Str == '.') ? (Str + 1) : Str));	    if (Host[strlen(Host)-1] == '.') {		Host[strlen(Host)-1] = '\0';	    }	    StrAllocCat(Host, DomainSuffix);	    if ((HostColon = strrchr(Host, ':')) != NULL &&		isdigit((unsigned char)HostColon[1])) {		*HostColon = '\0';	    }	    StrAllocCopy(host, Host);	    HTUnEscape(host);	    if (LYCursesON) {		StrAllocCopy(MsgStr, WWW_FIND_MESSAGE);		StrAllocCat(MsgStr, host);		StrAllocCat(MsgStr, GUESSING_SEGMENT);		HTProgress(MsgStr);	    } else if (Startup && !dump_output_immediately) {		fprintf(stdout, "%s '%s'%s\n", WWW_FIND_MESSAGE, host, GUESSING_SEGMENT);	    }#ifndef DJGPP	    GotHost = (LYGetHostByName(host) != NULL);#else	    GotHost = (resolve(host) != 0);#endif /* DJGPP */	    if (HostColon != NULL) {		*HostColon = ':';	    }	    if (GotHost == FALSE) {		/*		 *  Give the user chance to interrupt lookup cycles. - KW		 */#ifndef DJGPP		if (LYCursesON && (lynx_nsl_status == HT_INTERRUPTED))#else /* DJGPP */		if (LYCursesON && HTCheckForInterrupt())#endif /* DJGPP */		{		    CTRACE(tfp, "LYExpandHostForURL: Interrupted while '%s' failed to resolve.\n",				host);		    FREE(Str);		    FREE(MsgStr);		    FREE(Host);		    FREE(host);		    return FALSE; /* We didn't find a valid name. */		}		/*		 *  Advance to the next suffix, or end of suffix list. - FM		 */		StartS = ((*EndS == '\0') ? EndS : (EndS + 1));		while ((*StartS) && (WHITE(*StartS) || *StartS == ',')) {		    StartS++;	/* Skip whitespace and separators */		}		EndS = StartS;		while (*EndS && !WHITE(*EndS) && *EndS != ',') {		    EndS++;	/* Find separator */		}		LYstrncpy(DomainSuffix, StartS, (EndS - StartS));	    }	}  while ((GotHost == FALSE) && (*DomainSuffix != '\0'));	if (GotHost == FALSE) {	   /*	    *  Advance to the next prefix, or end of prefix list. - FM	    */	   StartP = ((*EndP == '\0') ? EndP : (EndP + 1));	   while ((*StartP) && (WHITE(*StartP) || *StartP == ',')) {	       StartP++;	/* Skip whitespace and separators */	   }	   EndP = StartP;	   while (*EndP && !WHITE(*EndP) && *EndP != ',') {	       EndP++;		/* Find separator */	   }	   LYstrncpy(DomainPrefix, StartP, (EndP - StartP));	}    } while ((GotHost == FALSE) && (*DomainPrefix != '\0'));    /*     *	If a test passed, restore the port field if we had one     *	and there is no colon in the expanded host, and the path     *	if we had one, and reallocate the original string with     *	the expanded Host[:port] field included. - FM     */    if (GotHost) {	if (StrColon && strchr(Host, ':') == NULL) {	    *StrColon = ':';	    StrAllocCat(Host, StrColon);	}	if (Path) {	    *Path = '/';	    StrAllocCat(Host, Path);	} else if (Fragment) {	    StrAllocCat(Host, "/");	    *Fragment = '#';	    StrAllocCat(Host, Fragment);	}	StrAllocCopy(*AllocatedString, Host);    }    /*     *	Clear any residual interrupt. - FM     */    if (LYCursesON && HTCheckForInterrupt()) {	CTRACE(tfp, "LYExpandHostForURL: Ignoring interrupt because '%s' %s.\n",		    host,		    (GotHost ? "resolved" : "timed out"));    }    /*     *	Clean up and return the last test result. - FM     */    FREE(Str);    FREE(MsgStr);    FREE(Host);    FREE(host);    return GotHost;}