BOOL utf_flag = (LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8);
BOOL utf_flag = (BOOL)(LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8); BOOL hl1_drawn = NO;
PUBLIC void highlight ARGS3(	int,		flag,	int,		cur,	char *,		target){    char buffer[200];    int i;    char tmp[7];#if defined(FANCY_CURSES) || defined(USE_SLANG)    char *cp;    char *theData = NULL;    char *Data = NULL;    int Offset, HitOffset, tLen;    int LenNeeded;    BOOL TargetEmphasisON = FALSE;#endif    BOOL utf_flag = (LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8);#if defined(USE_COLOR_STYLE) && !defined(NO_HILIT_FIX)    BOOL hl2_drawn=FALSE;	/* whether links[cur].hightext2 is already drawn				   properly */#endif    tmp[0] = tmp[1] = tmp[2] = '\0';    /*     *	Bugs in the history code might cause -1 to be sent for cur, which     *	yields a crash when LYstrncpy() is called with a nonsense pointer.     *	As far as I know, such bugs have been squashed, but if they should     *	reappear, this works around them. - FM     */    if (cur < 0)	cur = 0;    if (nlinks > 0) {#if  defined(USE_COLOR_STYLE) && !defined(NO_HILIT_FIX)	if (flag == ON || links[cur].type == WWW_FORM_LINK_TYPE)#endif	{#ifdef USE_COLOR_STYLE#define LXP (links[cur].lx)#define LYP (links[cur].ly)#endif	move(links[cur].ly, links[cur].lx);#ifndef USE_COLOR_STYLE	lynx_start_link_color (flag == ON, links[cur].inUnderline);#else	if (flag == ON) {	    LynxChangeStyle(s_alink, STACK_ON, 0);	} else {	    int s, x;		/*		 *  This is where we try to restore the original style when		 *  a link is unhighlighted.  The purpose of cached_styles[][]		 *  is to save the original style just for this case.		 *  If it doesn't have a color change saved at just the right		 *  position, we look at preceding positions in the same line		 *  until we find one.		 */	    if (LYP >= 0 && LYP < CACHEH && LXP >= 0 && LXP < CACHEW) {		s = cached_styles[LYP][LXP];		if (s == 0) {		    for (x = LXP-1; x >= 0; x--) {			if (cached_styles[LYP][x]) {			    if (cached_styles[LYP][x] > 0) {				s = cached_styles[LYP][x];				cached_styles[LYP][LXP] = s;			    }			    break;			}		    }		    if (s == 0)			s = s_a;		}	    } else {		s = s_a;	    }	    LynxChangeStyle(s, STACK_ON, 0);	}#endif	}	if (links[cur].type == WWW_FORM_LINK_TYPE) {	    int len;	    int avail_space = (LYcols - links[cur].lx) - 1;	    LYstrncpy(buffer,		      (links[cur].hightext ?		       links[cur].hightext : ""),		      (avail_space > links[cur].form->size ?				      links[cur].form->size : avail_space));	    addstr(buffer);	    len = strlen(buffer);	    for (; len < links[cur].form->size && len < avail_space; len++)		addch('_');	} else {#if defined(USE_COLOR_STYLE) && !defined(NO_HILIT_FIX)	    if (flag == OFF) {		hl2_drawn = TRUE;		redraw_lines_of_link(cur);	    } else#endif	    {	    /*	     *	Copy into the buffer only what will fit	     *	within the width of the screen.	     */	    LYmbcsstrncpy(buffer,			  (links[cur].hightext ?			   links[cur].hightext : ""),			  (sizeof(buffer) - 1),			  ((LYcols - 1) - links[cur].lx),			  utf_flag);	    addstr(buffer);	    }	}	/*	 *  Display a second line as well.	 */	if ( links[cur].hightext2 && links[cur].ly < display_lines#if defined(USE_COLOR_STYLE) && !defined(NO_HILIT_FIX)	  && hl2_drawn == FALSE#endif	) {	    lynx_stop_link_color (flag == ON, links[cur].inUnderline);	    move((links[cur].ly + 1), links[cur].hightext2_offset);#ifndef USE_COLOR_STYLE	    lynx_start_link_color (flag == ON, links[cur].inUnderline);#else	    LynxChangeStyle(flag == ON ? s_alink : s_a, ABS_ON, 0);#endif	    for (i = 0; (tmp[0] = links[cur].hightext2[i]) != '\0' &&			i+links[cur].hightext2_offset < LYcols; i++) {		if (!IsSpecialAttrChar(links[cur].hightext2[i])) {		    /*		     *	For CJK strings, by Masanobu Kimura.		     */		    if (HTCJK != NOCJK && !isascii(tmp[0])) {			tmp[1] = links[cur].hightext2[++i];			addstr(tmp);			tmp[1] = '\0';		    } else {			addstr(tmp);		    }		 }	    }	}#if defined(USE_COLOR_STYLE) && !defined(NO_HILIT_FIX)	if ( hl2_drawn == FALSE )#endif	lynx_stop_link_color (flag == ON, links[cur].inUnderline);#if defined(FANCY_CURSES) || defined(USE_SLANG)	/*	 *  If we have an emphasized WHEREIS hit in the highlighted	 *  text, restore the emphasis.  Note that we never emphasize	 *  the first and last characters of the highlighted text when	 *  we are making the link current, so the link attributes for	 *  the current link will persist at the beginning and end,	 *  providing an indication to the user that it has been made	 *  current.   Also note that we use HText_getFirstTargetInLine()	 *  to determine if there's a hit in the HText structure line	 *  containing the link, and if so, get back a copy of the line	 *  starting at that first hit (which might be before or after	 *  our link), and with all IsSpecial characters stripped, so we	 *  don't need to deal with them here. - FM	 */	if (target && *target && (links[cur].type & WWW_LINK_TYPE) &&	    links[cur].hightext && *links[cur].hightext &&	    HText_getFirstTargetInLine(HTMainText,				       links[cur].anchor_line_num,				       utf_flag,				       (int *)&Offset,				       (int *)&tLen,				       (char **)&theData,				       target)) {	    int itmp, written, len, y, offset;	    char *data;	    int tlen = strlen(target);	    int hlen, hLen;	    int hLine = links[cur].ly, hoffset = links[cur].lx;	    size_t utf_extra = 0;	    /*	     *	Copy into the buffer only what will fit	     *	up to the right border of the screen. - FM	     */	    LYmbcsstrncpy(buffer,			  (links[cur].hightext ?			   links[cur].hightext : ""),			  (sizeof(buffer) - 1),			  ((LYcols - 1) - links[cur].lx),			  utf_flag);	    hlen = strlen(buffer);	    hLen = ((HTCJK != NOCJK || utf_flag) ?		  LYmbcsstrlen(buffer, utf_flag) : hlen);	    /*	     *	Break out if the first hit in the line	     *	starts after this link. - FM	     */	    if (Offset >= (hoffset + hLen)) {		goto highlight_search_hightext2;	    }	    /*	     *	Recursively skip hits that end before this link, and	     *	break out if there is no hit beyond those. - FM	     */	    Data = theData;	    while ((Offset < hoffset) &&		   ((Offset + tLen) <= hoffset)) {		data = (Data + tlen);		offset = (Offset + tLen);		if ((case_sensitive ?		     (cp = LYno_attr_mbcs_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL :		     (cp = LYno_attr_mbcs_case_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL) &&		    (offset + LenNeeded) < LYcols) {		    Data = cp;		    Offset = (offset + HitOffset);		} else {		    goto highlight_search_hightext2;		}	    }	    data = buffer;	    offset = hoffset;	    /*	     *	If the hit starts before the hightext, and ends	     *	in or beyond the hightext, restore the emphasis,	     *	skipping the first and last characters of the	     *	hightext if we're making the link current. - FM	     */	    if ((Offset < offset) &&		((Offset + tLen) > offset)) {		itmp = 0;		written = 0;		len = (tlen - (offset - Offset));		/*		 *  Go to the start of the hightext and		 *  handle its first character. - FM		 */		move(hLine, offset);		tmp[0] = data[itmp];		if (utf_flag && !isascii(tmp[0])) {		    if ((*tmp & 0xe0) == 0xc0) {			utf_extra = 1;		    } else if ((*tmp & 0xf0) == 0xe0) {			utf_extra = 2;		    } else if ((*tmp & 0xf8) == 0xf0) {			utf_extra = 3;		    } else if ((*tmp & 0xfc) == 0xf8) {			utf_extra = 4;		    } else if ((*tmp & 0xfe) == 0xfc) {			utf_extra = 5;		    } else {			/*			 *  Garbage.			 */			utf_extra = 0;		    }		    if (strlen(&data[itmp+1]) < utf_extra) {			/*			 *  Shouldn't happen.			 */			utf_extra = 0;		    }		}		if (utf_extra) {		    LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);		    itmp += utf_extra;		    /*		     *	Start emphasis immediately if we are		     *	making the link non-current. - FM		     */		    if (flag != ON) {			LYstartTargetEmphasis();			TargetEmphasisON = TRUE;			addstr(tmp);		    } else {			move(hLine, (offset + 1));		    }		    tmp[1] = '\0';		    written += (utf_extra + 1);		    utf_extra = 0;		} else if (HTCJK != NOCJK && !isascii(tmp[0])) {		    /*		     *	For CJK strings, by Masanobu Kimura.		     */		    tmp[1] = data[++itmp];		    /*		     *	Start emphasis immediately if we are		     *	making the link non-current. - FM		     */		    if (flag != ON) {			LYstartTargetEmphasis();			TargetEmphasisON = TRUE;			addstr(tmp);		    } else {			move(hLine, (offset + 1));		    }		    tmp[1] = '\0';		    written += 2;		} else {		    /*		     *	Start emphasis immediately if we are making		     *	the link non-current. - FM		     */		    if (flag != ON) {			LYstartTargetEmphasis();			TargetEmphasisON = TRUE;			addstr(tmp);		    } else {			move(hLine, (offset + 1));		    }		    written++;		}		itmp++;		/*		 *  Start emphasis after the first character		 *  if we are making the link current and this		 *  is not the last character. - FM		 */		if (!TargetEmphasisON &&		    data[itmp] != '\0') {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		}		/*		 *  Handle the remaining characters. - FM		 */		for (;		     written < len && (tmp[0] = data[itmp]) != '\0';		     itmp++)  {		    /*		     *	Print all the other target chars, except		     *	the last character if it is also the last		     *	character of hightext and we are making		     *	the link current. - FM		     */		    if (utf_flag && !isascii(tmp[0])) {			if ((*tmp & 0xe0) == 0xc0) {			    utf_extra = 1;			} else if ((*tmp & 0xf0) == 0xe0) {			    utf_extra = 2;			} else if ((*tmp & 0xf8) == 0xf0) {			    utf_extra = 3;			} else if ((*tmp & 0xfc) == 0xf8) {			    utf_extra = 4;			} else if ((*tmp & 0xfe) == 0xfc) {			    utf_extra = 5;			} else {			    /*			     *	Garbage.			     */			    utf_extra = 0;			}			if (strlen(&data[itmp+1]) < utf_extra) {			    /*			     *	Shouldn't happen.			     */			    utf_extra = 0;			}		    }		    if (utf_extra) {			LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);			itmp += utf_extra;			/*			 *  Make sure we don't restore emphasis to			 *  the last character of hightext if we			 *  are making the link current. - FM			 */			if (flag == ON && data[(itmp + 1)] == '\0') {			    LYstopTargetEmphasis();			    TargetEmphasisON = FALSE;			    LYGetYX(y, offset);			    move(hLine, (offset + 1));			} else {			    addstr(tmp);			}			tmp[1] = '\0';			written += (utf_extra + 1);			utf_extra = 0;		    } else if (HTCJK != NOCJK && !isascii(tmp[0])) {			/*			 *  For CJK strings, by Masanobu Kimura.			 */			tmp[1] = data[++itmp];			/*			 *  Make sure we don't restore emphasis to			 *  the last character of hightext if we			 *  are making the link current. - FM			 */			if (flag == ON && data[(itmp + 1)] == '\0') {			    LYstopTargetEmphasis();			    TargetEmphasisON = FALSE;			    LYGetYX(y, offset);			    move(hLine, (offset + 1));			} else {			    addstr(tmp);			}			tmp[1] = '\0';			written += 2;		    } else {			/*			 *  Make sure we don't restore emphasis to			 *  the last character of hightext if we			 *  are making the link current. - FM			 */			if (flag == ON && data[(itmp + 1)] == '\0') {			    LYstopTargetEmphasis();			    TargetEmphasisON = FALSE;			    LYGetYX(y, offset);			    move(hLine, (offset + 1));			} else {			    addstr(tmp);			}			written++;		    }		}		/*		 *  Stop the emphasis if we haven't already, then		 *  reset the offset to our current position in		 *  the line, and if that is beyond the link, or		 *  or we are making the link current and it is		 *  the last character of the hightext, we are		 *  done. - FM		 */		if (TargetEmphasisON) {		    LYstopTargetEmphasis();		    TargetEmphasisON = FALSE;		}		LYGetYX(y, offset);		if (offset >=		    (hoffset +		     (flag == ON ? (hLen - 1) : hLen)))  {		    goto highlight_search_hightext2;		}		/*		 *  See if we have another hit that starts		 *  within the hightext. - FM		 */		data = (Data + (offset - Offset));		if (!utf_flag) {		    data = Data + (offset - Offset);		} else {		    data = LYmbcs_skip_glyphs(Data,					      (offset - Offset),					      utf_flag);		}		if ((case_sensitive ?		     (cp = LYno_attr_mbcs_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL :		     (cp = LYno_attr_mbcs_case_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL) &&		    (offset + LenNeeded) < LYcols) {		    /*		     *	If the hit starts after the end of the hightext,		     *	or we are making the link current and the hit		     *	starts at its last character, we are done. - FM		     */		    if ((HitOffset + offset) >=			(hoffset +			 (flag == ON ? (hLen - 1) : hLen)))  {			goto highlight_search_hightext2;		    }		    /*		     *	Set up the data and offset for the hit, and let		     *	the code for within hightext hits handle it. - FM		     */		    Data = cp;		    Offset = (offset + HitOffset);		    data = buffer;		    offset = hoffset;		    goto highlight_hit_within_hightext;		}		goto highlight_search_hightext2;	    }highlight_hit_within_hightext:	    /*	     *	If we get to here, the hit starts within the	     *	hightext.  If we are making the link current	     *	and it's the last character in the hightext,	     *	we are done.  Otherwise, move there and start	     *	restoring the emphasis. - FM	     */	    if ((Offset - offset) >		(flag == ON ? (hLen - 1) : hLen))  {		goto highlight_search_hightext2;	    }	    if (!utf_flag) {		data += (Offset - offset);	    } else {		refresh();		data = LYmbcs_skip_glyphs(data,					  (Offset - offset),					  utf_flag);	    }	    offset = Offset;	    itmp = 0;	    written = 0;	    len = tlen;	    /*	     *	Go to the start of the hit and	     *	handle its first character. - FM	     */	    move(hLine, offset);	    tmp[0] = data[itmp];	    if (utf_flag && !isascii(tmp[0])) {		if ((*tmp & 0xe0) == 0xc0) {		    utf_extra = 1;		} else if ((*tmp & 0xf0) == 0xe0) {		    utf_extra = 2;		} else if ((*tmp & 0xf8) == 0xf0) {		    utf_extra = 3;		} else if ((*tmp & 0xfc) == 0xf8) {		    utf_extra = 4;		} else if ((*tmp & 0xfe) == 0xfc) {		    utf_extra = 5;		} else {		    /*		     *	Garbage.		     */		    utf_extra = 0;		}		if (strlen(&data[itmp+1]) < utf_extra) {		    /*		     *	Shouldn't happen.		     */		    utf_extra = 0;		}	    }	    if (utf_extra) {		LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);		itmp += utf_extra;		/*		 *  Start emphasis immediately if we are making		 *  the link non-current, or we are making it		 *  current but this is not the first or last		 *  character of the hightext. - FM		 */		if (flag != ON ||		    (offset > hoffset && data[itmp+1] != '\0')) {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    addstr(tmp);		} else {		    move(hLine, (offset + 1));		}		tmp[1] = '\0';		written += (utf_extra + 1);		utf_extra = 0;	    } else if (HTCJK != NOCJK && !isascii(tmp[0])) {		/*		 *  For CJK strings, by Masanobu Kimura.		 */		tmp[1] = data[++itmp];		/*		 *  Start emphasis immediately if we are making		 *  the link non-current, or we are making it		 *  current but this is not the first or last		 *  character of the hightext. - FM		 */		if (flag != ON ||		    (offset > hoffset && data[itmp+1] != '\0')) {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    addstr(tmp);		} else {		    move(hLine, (offset + 1));		}		tmp[1] = '\0';		written += 2;	    } else {		/*		 *  Start emphasis immediately if we are making		 *  the link non-current, or we are making it		 *  current but this is not the first or last		 *  character of the hightext. - FM		 */		if (flag != ON ||		    (offset > hoffset && data[itmp+1] != '\0')) {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    addstr(tmp);		} else {		    move(hLine, (offset + 1));		}		written++;	    }	    itmp++;	    /*	     *	Start emphasis after the first character	     *	if we are making the link current and this	     *	is not the last character. - FM	     */	    if (!TargetEmphasisON &&		data[itmp] != '\0') {		LYstartTargetEmphasis();		TargetEmphasisON = TRUE;	    }	    for (;		 written < len && (tmp[0] = data[itmp]) != '\0';		 itmp++)  {		/*		 *  Print all the other target chars, except		 *  the last character if it is also the last		 *  character of hightext and we are making		 *  the link current. - FM		 */		if (utf_flag && !isascii(tmp[0])) {		    if ((*tmp & 0xe0) == 0xc0) {			utf_extra = 1;		    } else if ((*tmp & 0xf0) == 0xe0) {			utf_extra = 2;		    } else if ((*tmp & 0xf8) == 0xf0) {			utf_extra = 3;		    } else if ((*tmp & 0xfc) == 0xf8) {			utf_extra = 4;		    } else if ((*tmp & 0xfe) == 0xfc) {			utf_extra = 5;		    } else {			/*			 *  Garbage.			 */			utf_extra = 0;		    }		    if (strlen(&data[itmp+1]) < utf_extra) {			/*			 *  Shouldn't happen.			 */			utf_extra = 0;		    }		}		if (utf_extra) {		    LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);		    itmp += utf_extra;		    /*		     *	Make sure we don't restore emphasis to		     *	the last character of hightext if we		     *	are making the link current. - FM		     */		    if (flag == ON && data[(itmp + 1)] == '\0') {			LYstopTargetEmphasis();			TargetEmphasisON = FALSE;			LYGetYX(y, offset);			move(hLine, (offset + 1));		    } else {			addstr(tmp);		    }		    tmp[1] = '\0';		    written += (utf_extra + 1);		    utf_extra = 0;		} else if (HTCJK != NOCJK && !isascii(tmp[0])) {		    /*		     *	For CJK strings, by Masanobu Kimura.		     */		    tmp[1] = data[++itmp];		    /*		     *	Make sure we don't restore emphasis to		     *	the last character of hightext if we		     *	are making the link current. - FM		     */		    if (flag == ON && data[(itmp + 1)] == '\0') {			LYstopTargetEmphasis();			TargetEmphasisON = FALSE;			LYGetYX(y, offset);			move(hLine, (offset + 1));		    } else {			addstr(tmp);		    }		    tmp[1] = '\0';		    written += 2;		} else {		    /*		     *	Make sure we don't restore emphasis to		     *	the last character of hightext if we		     *	are making the link current. - FM		     */		    if (flag == ON && data[(itmp + 1)] == '\0') {			LYstopTargetEmphasis();			TargetEmphasisON = FALSE;			LYGetYX(y, offset);			move(hLine, (offset + 1));		    } else {			addstr(tmp);		    }		    written++;		}	    }	    /*	     *	Stop the emphasis if we haven't already, then reset	     *	the offset to our current position in the line, and	     *	if that is beyond the link, or we are making the link	     *	current and it is the last character in the hightext,	     *	we are done. - FM	     */	    if (TargetEmphasisON) {		LYstopTargetEmphasis();		TargetEmphasisON = FALSE;	    }	    LYGetYX(y, offset);	    if (offset >=		(hoffset + (flag == ON ? (hLen - 1) : hLen))) {		goto highlight_search_hightext2;	    }	    /*	     *	See if we have another hit that starts	     *	within the hightext. - FM	     */	    if (!utf_flag) {		data = Data + (offset - Offset);	    } else {		data = LYmbcs_skip_glyphs(Data,					  (offset - Offset),					  utf_flag);	    }	    if ((case_sensitive ?		 (cp = LYno_attr_mbcs_strstr(data,					     target,					     utf_flag,					     &HitOffset,					     &LenNeeded)) != NULL :		 (cp = LYno_attr_mbcs_case_strstr(data,					     target,					     utf_flag,					     &HitOffset,					     &LenNeeded)) != NULL) &&		(offset + LenNeeded) < LYcols) {		/*		 *  If the hit starts after the end of the hightext,		 *  or we are making the link current and the hit		 *  starts at its last character, we are done. - FM		 */		if ((HitOffset + offset) >=		    (hoffset +		     (flag == ON ? (hLen - 1) : hLen)))  {		    goto highlight_search_hightext2;		}		/*		 *  If the target extends beyond our buffer, emphasize		 *  everything in the hightext starting at this hit.		 *  Otherwise, set up the data and offsets, and loop		 *  back. - FM		 */		if ((HitOffset + (offset + tLen)) >=		    (hoffset + hLen)) {		    offset = (HitOffset + offset);		    if (!utf_flag) {			data = buffer + (offset - hoffset);		    } else {			refresh();			data = LYmbcs_skip_glyphs(buffer,						  (offset - hoffset),						  utf_flag);		    }		    move(hLine, offset);		    itmp = 0;		    written = 0;		    len = strlen(data);		    /*		     *	Turn the emphasis back on. - FM		     */		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    for (;			 written < len && (tmp[0] = data[itmp]) != '\0';			 itmp++)  {			/*			 *  Print all the other target chars, except			 *  the last character if it is also the last			 *  character of hightext and we are making			 *  the link current. - FM			 */			if (utf_flag && !isascii(tmp[0])) {			    if ((*tmp & 0xe0) == 0xc0) {				utf_extra = 1;			    } else if ((*tmp & 0xf0) == 0xe0) {				utf_extra = 2;			    } else if ((*tmp & 0xf8) == 0xf0) {				utf_extra = 3;			    } else if ((*tmp & 0xfc) == 0xf8) {				utf_extra = 4;			    } else if ((*tmp & 0xfe) == 0xfc) {				utf_extra = 5;			    } else {				/*				 *  Garbage.				 */				utf_extra = 0;			    }			    if (strlen(&data[itmp+1]) < utf_extra) {				/*				 *  Shouldn't happen.				 */				utf_extra = 0;			    }			}			if (utf_extra) {			    LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);			    itmp += utf_extra;			    /*			     *	Make sure we don't restore emphasis to			     *	the last character of hightext if we			     *	are making the link current. - FM			     */			    if (flag == ON && data[(itmp + 1)] == '\0') {				LYstopTargetEmphasis();				TargetEmphasisON = FALSE;				LYGetYX(y, offset);				move(hLine, (offset + 1));			    } else {				addstr(tmp);			    }			    tmp[1] = '\0';			    written += (utf_extra + 1);			    utf_extra = 0;			} else if (HTCJK != NOCJK && !isascii(tmp[0])) {			    /*			     *	For CJK strings, by Masanobu Kimura.			     */			    tmp[1] = data[++itmp];			    /*			     *	Make sure we don't restore emphasis to			     *	the last character of hightext if we			     *	are making the link current. - FM			     */			    if (flag == ON && data[(itmp + 1)] == '\0') {				LYstopTargetEmphasis();				TargetEmphasisON = FALSE;			    } else {				addstr(tmp);			    }			    tmp[1] = '\0';			    written += 2;			} else {			    /*			     *	Make sure we don't restore emphasis to			     *	the last character of hightext if we			     *	are making the link current. - FM			     */			    if (flag == ON && data[(itmp + 1)] == '\0') {				LYstopTargetEmphasis();				TargetEmphasisON = FALSE;			    } else {				addstr(tmp);			    }			    written++;			}		    }		    /*		     *	Turn off the emphasis if we haven't already,		     *	and then we're done. - FM		     */		    if (TargetEmphasisON) {			LYstopTargetEmphasis();		    }		    goto highlight_search_hightext2;		} else {		    Data = cp;		    Offset = (offset + HitOffset);		    data = buffer;		    offset = hoffset;		    goto highlight_hit_within_hightext;		}	    }	    goto highlight_search_hightext2;	}highlight_search_hightext2:	if (target && *target && (links[cur].type & WWW_LINK_TYPE) &&	    links[cur].hightext2 && *links[cur].hightext2 &&	    links[cur].ly < display_lines &&	    HText_getFirstTargetInLine(HTMainText,				       (links[cur].anchor_line_num + 1),				       utf_flag,				       (int *)&Offset,				       (int *)&tLen,				       (char **)&theData,				       target)) {	    int itmp, written, len, y, offset;	    char *data;	    int tlen = strlen(target);	    int hlen, hLen;	    int hLine = (links[cur].ly + 1);	    int hoffset = links[cur].hightext2_offset;	    size_t utf_extra = 0;	    /*	     *	Copy into the buffer only what will fit	     *	up to the right border of the screen. - FM	     */	    LYmbcsstrncpy(buffer,			  (links[cur].hightext2 ?			   links[cur].hightext2 : ""),			  (sizeof(buffer) - 1),			  ((LYcols - 1) - links[cur].hightext2_offset),			  utf_flag);	    hlen = strlen(buffer);	    hLen = ((HTCJK != NOCJK || utf_flag) ?		  LYmbcsstrlen(buffer, utf_flag) : hlen);	    /*	     *	Break out if the first hit in the line	     *	starts after this link. - FM	     */	    if (Offset >= (hoffset + hLen)) {		goto highlight_search_done;	    }	    /*	     *	Recursively skip hits that end before this link, and	     *	break out if there is no hit beyond those. - FM	     */	    Data = theData;	    while ((Offset < hoffset) &&		   ((Offset + tLen) <= hoffset)) {		data = (Data + tlen);		offset = (Offset + tLen);		if ((case_sensitive ?		     (cp = LYno_attr_mbcs_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL :		     (cp = LYno_attr_mbcs_case_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL) &&		    (offset + LenNeeded) < LYcols) {		    Data = cp;		    Offset = (offset + HitOffset);		} else {		    goto highlight_search_done;		}	    }	    data = buffer;	    offset = hoffset;	    /*	     *	If the hit starts before the hightext2, and ends	     *	in or beyond the hightext2, restore the emphasis,	     *	skipping the first and last characters of the	     *	hightext2 if we're making the link current. - FM	     */	    if ((Offset < offset) &&		((Offset + tLen) > offset)) {		itmp = 0;		written = 0;		len = (tlen - (offset - Offset));		/*		 *  Go to the start of the hightext2 and		 *  handle its first character. - FM		 */		move(hLine, offset);		tmp[0] = data[itmp];		if (utf_flag && !isascii(tmp[0])) {		    if ((*tmp & 0xe0) == 0xc0) {			utf_extra = 1;		    } else if ((*tmp & 0xf0) == 0xe0) {			utf_extra = 2;		    } else if ((*tmp & 0xf8) == 0xf0) {			utf_extra = 3;		    } else if ((*tmp & 0xfc) == 0xf8) {			utf_extra = 4;		    } else if ((*tmp & 0xfe) == 0xfc) {			utf_extra = 5;		    } else {			/*			 *  Garbage.			 */			utf_extra = 0;		    }		    if (strlen(&data[itmp+1]) < utf_extra) {			/*			 *  Shouldn't happen.			 */			utf_extra = 0;		    }		}		if (utf_extra) {		    LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);		    itmp += utf_extra;		    /*		     *	Start emphasis immediately if we are		     *	making the link non-current. - FM		     */		    if (flag != ON) {			LYstartTargetEmphasis();			TargetEmphasisON = TRUE;			addstr(tmp);		    } else {			move(hLine, (offset + 1));		    }		    tmp[1] = '\0';		    written += (utf_extra + 1);		    utf_extra = 0;		} else if (HTCJK != NOCJK && !isascii(tmp[0])) {		    /*		     *	For CJK strings, by Masanobu Kimura.		     */		    tmp[1] = data[++itmp];		    /*		     *	Start emphasis immediately if we are		     *	making the link non-current. - FM		     */		    if (flag != ON) {			LYstartTargetEmphasis();			TargetEmphasisON = TRUE;			addstr(tmp);		    } else {			move(hLine, (offset + 1));		    }		    tmp[1] = '\0';		    written += 2;		} else {		    /*		     *	Start emphasis immediately if we are making		     *	the link non-current. - FM		     */		    if (flag != ON) {			LYstartTargetEmphasis();			TargetEmphasisON = TRUE;			addstr(tmp);		    } else {			move(hLine, (offset + 1));		    }		    written++;		}		itmp++;		/*		 *  Start emphasis after the first character		 *  if we are making the link current and this		 *  is not the last character. - FM		 */		if (!TargetEmphasisON &&		    data[itmp] != '\0') {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		}		/*		 *  Handle the remaining characters. - FM		 */		for (;		     written < len && (tmp[0] = data[itmp]) != '\0';		     itmp++)  {		    /*		     *	Print all the other target chars, except		     *	the last character if it is also the last		     *	character of hightext2 and we are making		     *	the link current. - FM		     */		    if (utf_flag && !isascii(tmp[0])) {			if ((*tmp & 0xe0) == 0xc0) {			    utf_extra = 1;			} else if ((*tmp & 0xf0) == 0xe0) {			    utf_extra = 2;			} else if ((*tmp & 0xf8) == 0xf0) {			    utf_extra = 3;			} else if ((*tmp & 0xfc) == 0xf8) {			    utf_extra = 4;			} else if ((*tmp & 0xfe) == 0xfc) {			    utf_extra = 5;			} else {			    /*			     *	Garbage.			     */			    utf_extra = 0;			}			if (strlen(&data[itmp+1]) < utf_extra) {			    /*			     *	Shouldn't happen.			     */			    utf_extra = 0;			}		    }		    if (utf_extra) {			LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);			itmp += utf_extra;			/*			 *  Make sure we don't restore emphasis to			 *  the last character of hightext2 if we			 *  are making the link current. - FM			 */			if (flag == ON && data[(itmp + 1)] == '\0') {			    LYstopTargetEmphasis();			    TargetEmphasisON = FALSE;			    LYGetYX(y, offset);			    move(hLine, (offset + 1));			} else {			    addstr(tmp);			}			tmp[1] = '\0';			written += (utf_extra + 1);			utf_extra = 0;		    } else if (HTCJK != NOCJK && !isascii(tmp[0])) {			/*			 *  For CJK strings, by Masanobu Kimura.			 */			tmp[1] = data[++itmp];			/*			 *  Make sure we don't restore emphasis to			 *  the last character of hightext2 if we			 *  are making the link current. - FM			 */			if (flag == ON && data[(itmp + 1)] == '\0') {			    LYstopTargetEmphasis();			    TargetEmphasisON = FALSE;			    LYGetYX(y, offset);			    move(hLine, (offset + 1));			} else {			    addstr(tmp);			}			tmp[1] = '\0';			written += 2;		    } else {			/*			 *  Make sure we don't restore emphasis to			 *  the last character of hightext2 if we			 *  are making the link current. - FM			 */			if (flag == ON && data[(itmp + 1)] == '\0') {			    LYstopTargetEmphasis();			    TargetEmphasisON = FALSE;			    LYGetYX(y, offset);			    move(hLine, (offset + 1));			} else {			    addstr(tmp);			}			written++;		    }		}		/*		 *  Stop the emphasis if we haven't already, then		 *  reset the offset to our current position in		 *  the line, and if that is beyond the link, or		 *  or we are making the link current and it is		 *  the last character of the hightext2, we are		 *  done. - FM		 */		if (TargetEmphasisON) {		    LYstopTargetEmphasis();		    TargetEmphasisON = FALSE;		}		LYGetYX(y, offset);		if (offset >=		    (hoffset +		     (flag == ON ? (hLen - 1) : hLen)))  {		    goto highlight_search_done;		}		/*		 *  See if we have another hit that starts		 *  within the hightext2. - FM		 */		if (!utf_flag) {		    data = Data + (offset - Offset);		} else {		    data = LYmbcs_skip_glyphs(Data,					      (offset - Offset),					      utf_flag);		}		if ((case_sensitive ?		     (cp = LYno_attr_mbcs_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL :		     (cp = LYno_attr_mbcs_case_strstr(data,						 target,						 utf_flag,						 &HitOffset,						 &LenNeeded)) != NULL) &&		    (offset + LenNeeded) < LYcols) {		    /*		     *	If the hit starts after the end of the hightext2,		     *	or we are making the link current and the hit		     *	starts at its last character, we are done. - FM		     */		    if ((HitOffset + offset) >=			(hoffset +			 (flag == ON ? (hLen - 1) : hLen)))  {			goto highlight_search_done;		    }		    /*		     *	Set up the data and offset for the hit, and let		     *	the code for within hightext2 hits handle it. - FM		     */		    Data = cp;		    Offset = (offset + HitOffset);		    data = buffer;		    offset = hoffset;		    goto highlight_hit_within_hightext2;		}		goto highlight_search_done;	    }highlight_hit_within_hightext2:	    /*	     *	If we get to here, the hit starts within the	     *	hightext2.  If we are making the link current	     *	and it's the last character in the hightext2,	     *	we are done.  Otherwise, move there and start	     *	restoring the emphasis. - FM	     */	    if ((Offset - offset) >		(flag == ON ? (hLen - 1) : hLen))  {		goto highlight_search_done;	    }	    if (!utf_flag) {		data += (Offset - offset);	    } else {		refresh();		data = LYmbcs_skip_glyphs(data,					  (Offset - offset),					  utf_flag);	    }	    offset = Offset;	    itmp = 0;	    written = 0;	    len = tlen;	    /*	     *	Go to the start of the hit and	     *	handle its first character. - FM	     */	    move(hLine, offset);	    tmp[0] = data[itmp];	    if (utf_flag && !isascii(tmp[0])) {		if ((*tmp & 0xe0) == 0xc0) {		    utf_extra = 1;		} else if ((*tmp & 0xf0) == 0xe0) {		    utf_extra = 2;		} else if ((*tmp & 0xf8) == 0xf0) {		    utf_extra = 3;		} else if ((*tmp & 0xfc) == 0xf8) {		    utf_extra = 4;		} else if ((*tmp & 0xfe) == 0xfc) {		    utf_extra = 5;		} else {		    /*		     *	Garbage.		     */		    utf_extra = 0;		}		if (strlen(&data[itmp+1]) < utf_extra) {		    /*		     *	Shouldn't happen.		     */		    utf_extra = 0;		}	    }	    if (utf_extra) {		LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);		itmp += utf_extra;		/*		 *  Start emphasis immediately if we are making		 *  the link non-current, or we are making it		 *  current but this is not the first or last		 *  character of the hightext2. - FM		 */		if (flag != ON ||		    (offset > hoffset && data[itmp+1] != '\0')) {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    addstr(tmp);		} else {		    move(hLine, (offset + 1));		}		tmp[1] = '\0';		written += (utf_extra + 1);		utf_extra = 0;	    } else if (HTCJK != NOCJK && !isascii(tmp[0])) {		/*		 *  For CJK strings, by Masanobu Kimura.		 */		tmp[1] = data[++itmp];		/*		 *  Start emphasis immediately if we are making		 *  the link non-current, or we are making it		 *  current but this is not the first or last		 *  character of the hightext2. - FM		 */		if (flag != ON ||		    (offset > hoffset && data[itmp+1] != '\0')) {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    addstr(tmp);		} else {		    move(hLine, (offset + 1));		}		tmp[1] = '\0';		written += 2;	    } else {		/*		 *  Start emphasis immediately if we are making		 *  the link non-current, or we are making it		 *  current but this is not the first or last		 *  character of the hightext2. - FM		 */		if (flag != ON ||		    (offset > hoffset && data[itmp+1] != '\0')) {		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    addstr(tmp);		} else {		    move(hLine, (offset + 1));		}		written++;	    }	    itmp++;	    /*	     *	Start emphasis after the first character	     *	if we are making the link current and this	     *	is not the last character. - FM	     */	    if (!TargetEmphasisON &&		data[itmp] != '\0') {		LYstartTargetEmphasis();		TargetEmphasisON = TRUE;	    }	    for (;		 written < len && (tmp[0] = data[itmp]) != '\0';		 itmp++)  {		/*		 *  Print all the other target chars, except		 *  the last character if it is also the last		 *  character of hightext2 and we are making		 *  the link current. - FM		 */		if (utf_flag && !isascii(tmp[0])) {		    if ((*tmp & 0xe0) == 0xc0) {			utf_extra = 1;		    } else if ((*tmp & 0xf0) == 0xe0) {			utf_extra = 2;		    } else if ((*tmp & 0xf8) == 0xf0) {			utf_extra = 3;		    } else if ((*tmp & 0xfc) == 0xf8) {			utf_extra = 4;		    } else if ((*tmp & 0xfe) == 0xfc) {			utf_extra = 5;		    } else {			/*			 *  Garbage.			 */			utf_extra = 0;		    }		    if (strlen(&data[itmp+1]) < utf_extra) {			/*			 *  Shouldn't happen.			 */			utf_extra = 0;		    }		}		if (utf_extra) {		    LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);		    itmp += utf_extra;		    /*		     *	Make sure we don't restore emphasis to		     *	the last character of hightext2 if we		     *	are making the link current. - FM		     */		    if (flag == ON && data[(itmp + 1)] == '\0') {			LYstopTargetEmphasis();			TargetEmphasisON = FALSE;			LYGetYX(y, offset);			move(hLine, (offset + 1));		    } else {			addstr(tmp);		    }		    tmp[1] = '\0';		    written += (utf_extra + 1);		    utf_extra = 0;		} else if (HTCJK != NOCJK && !isascii(tmp[0])) {		    /*		     *	For CJK strings, by Masanobu Kimura.		     */		    tmp[1] = data[++itmp];		    /*		     *	Make sure we don't restore emphasis to		     *	the last character of hightext2 if we		     *	are making the link current. - FM		     */		    if (flag == ON && data[(itmp + 1)] == '\0') {			LYstopTargetEmphasis();			TargetEmphasisON = FALSE;			LYGetYX(y, offset);			move(hLine, (offset + 1));		    } else {			addstr(tmp);		    }		    tmp[1] = '\0';		    written += 2;		} else {		    /*		     *	Make sure we don't restore emphasis to		     *	the last character of hightext2 if we		     *	are making the link current. - FM		     */		    if (flag == ON && data[(itmp + 1)] == '\0') {			LYstopTargetEmphasis();			TargetEmphasisON = FALSE;			LYGetYX(y, offset);			move(hLine, (offset + 1));		    } else {			addstr(tmp);		    }		    written++;		}	    }	    /*	     *	Stop the emphasis if we haven't already, then reset	     *	the offset to our current position in the line, and	     *	if that is beyond the link, or we are making the link	     *	current and it is the last character in the hightext2,	     *	we are done. - FM	     */	    if (TargetEmphasisON) {		LYstopTargetEmphasis();		TargetEmphasisON = FALSE;	    }	    LYGetYX(y, offset);	    if (offset >=		(hoffset + (flag == ON ? (hLen - 1) : hLen))) {		goto highlight_search_done;	    }	    /*	     *	See if we have another hit that starts	     *	within the hightext2. - FM	     */	    if (!utf_flag) {		data = (Data + (offset - Offset));	    } else {		data = LYmbcs_skip_glyphs(Data,					  (offset - Offset),					  utf_flag);	    }	    if ((case_sensitive ?		 (cp = LYno_attr_mbcs_strstr(data,					     target,					     utf_flag,					     &HitOffset,					     &LenNeeded)) != NULL :		 (cp = LYno_attr_mbcs_case_strstr(data,					     target,					     utf_flag,					     &HitOffset,					     &LenNeeded)) != NULL) &&		(offset + LenNeeded) < LYcols) {		/*		 *  If the hit starts after the end of the hightext2,		 *  or we are making the link current and the hit		 *  starts at its last character, we are done. - FM		 */		if ((HitOffset + offset) >=		    (hoffset +		     (flag == ON ? (hLen - 1) : hLen)))  {		    goto highlight_search_done;		}		/*		 *  If the target extends beyond our buffer, emphasize		 *  everything in the hightext2 starting at this hit.		 *  Otherwise, set up the data and offsets, and loop		 *  back. - FM		 */		if ((HitOffset + (offset + tLen)) >=		    (hoffset + hLen)) {		    offset = (HitOffset + offset);		    if (!utf_flag) {			data = buffer + (offset - hoffset);		    } else {			refresh();			data = LYmbcs_skip_glyphs(buffer,						  (offset - hoffset),						  utf_flag);		    }		    move(hLine, offset);		    itmp = 0;		    written = 0;		    len = strlen(data);		    /*		     *	Turn the emphasis back on. - FM		     */		    LYstartTargetEmphasis();		    TargetEmphasisON = TRUE;		    for (;			 written < len && (tmp[0] = data[itmp]) != '\0';			 itmp++)  {			/*			 *  Print all the other target chars, except			 *  the last character if it is also the last			 *  character of hightext2 and we are making			 *  the link current. - FM			 */			if (utf_flag && !isascii(tmp[0])) {			    if ((*tmp & 0xe0) == 0xc0) {				utf_extra = 1;			    } else if ((*tmp & 0xf0) == 0xe0) {				utf_extra = 2;			    } else if ((*tmp & 0xf8) == 0xf0) {				utf_extra = 3;			    } else if ((*tmp & 0xfc) == 0xf8) {				utf_extra = 4;			    } else if ((*tmp & 0xfe) == 0xfc) {				utf_extra = 5;			    } else {				/*				 *  Garbage.				 */				utf_extra = 0;			    }			    if (strlen(&data[itmp+1]) < utf_extra) {				/*				 *  Shouldn't happen.				 */				utf_extra = 0;			    }			}			if (utf_extra) {			    LYstrncpy(&tmp[1], &data[itmp+1], utf_extra);			    itmp += utf_extra;			    /*			     *	Make sure we don't restore emphasis to			     *	the last character of hightext2 if we			     *	are making the link current. - FM			     */			    if (flag == ON && data[(itmp + 1)] == '\0') {				LYstopTargetEmphasis();				TargetEmphasisON = FALSE;				LYGetYX(y, offset);				move(hLine, (offset + 1));			    } else {				addstr(tmp);			    }			    tmp[1] = '\0';			    written += (utf_extra + 1);			    utf_extra = 0;			} else if (HTCJK != NOCJK && !isascii(tmp[0])) {			    /*			     *	For CJK strings, by Masanobu Kimura.			     */			    tmp[1] = data[++itmp];			    /*			     *	Make sure we don't restore emphasis to			     *	the last character of hightext2 if we			     *	are making the link current. - FM			     */			    if (flag == ON && data[(itmp + 1)] == '\0') {				LYstopTargetEmphasis();				TargetEmphasisON = FALSE;			    } else {				addstr(tmp);			    }			    tmp[1] = '\0';			    written += 2;			} else {			    /*			     *	Make sure we don't restore emphasis to			     *	the last character of hightext2 if we			     *	are making the link current. - FM			     */			    if (flag == ON && data[(itmp + 1)] == '\0') {				LYstopTargetEmphasis();				TargetEmphasisON = FALSE;			    } else {				addstr(tmp);			    }			    written++;			}		    }		    /*		     *	Turn off the emphasis if we haven't already,		     *	and then we're done. - FM		     */		    if (TargetEmphasisON) {			LYstopTargetEmphasis();		    }		    goto highlight_search_done;		} else {		    Data = cp;		    Offset = (offset + HitOffset);		    data = buffer;		    offset = hoffset;		    goto highlight_hit_within_hightext2;		}	    }	    goto highlight_search_done;	}highlight_search_done:	FREE(theData);	if (!LYShowCursor)	    /*	     *	Get cursor out of the way.	     */	    move((LYlines - 1), (LYcols - 1));	else#endif /* FANCY CURSES || USE_SLANG */	    /*	     *	Never hide the cursor if there's no FANCY CURSES or SLANG.	     */	    move(links[cur].ly,		 ((links[cur].lx > 0) ? (links[cur].lx - 1) : 0));	if (flag)	    refresh();    }    return;}