lyutils.c

来自「基于rtos开发的浏览器!」· C语言 代码 · 共 2,700 行 · 第 1/5 页

C
2,700
字号
		    /*		     *	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);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?