📄 lyutils.c
字号:
/* * 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])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -