📄 lyutils.c
字号:
#include "HTUtils.h"#include "tcp.h"#include <ctype.h>#include "HTParse.h"#include "HTAccess.h"#include "HTCJK.h"#include "HTAlert.h"#include "LYCurses.h"#include "LYUtils.h"#include "LYStrings.h"#include "LYGlobalDefs.h"#include "LYSignal.h"#include "GridText.h"#include "LYCharSets.h"#ifdef DOSPATH#include "HTDOS.h"#endif#ifdef VMS#include <descrip.h>#include <libclidef.h>#include <lib$routines.h>#include "HTVMSUtils.h"#endif /* VMS */#if HAVE_UTMP#include <pwd.h>#ifdef UTMPX_FOR_UTMP#include <utmpx.h>#define utmp utmpx#ifdef UTMP_FILE#undef UTMP_FILE#endif /* UTMP_FILE */#define UTMP_FILE UTMPX_FILE#else#include <utmp.h>#endif /* UTMPX_FOR_UTMP */#endif /* HAVE_UTMP */#if NEED_PTEM_H/* they neglected to define struct winsize in termios.h -- it's only in * termio.h and ptem.h (the former conflicts with other definitions). */#include <sys/stream.h>#include <sys/ptem.h>#endif#include "LYLeaks.h"#ifdef USE_COLOR_STYLE#include "AttrList.h"#include "LYHash.h"#include "LYStyle.h"#endif#undef hline /* FIXME: this is a curses feature used as a variable here */#ifdef SVR4_BSDSELECTextern int BSDselect PARAMS((int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval * timeout));#ifdef select#undef select#endif /* select */#define select BSDselect#ifdef SOCKS#ifdef Rselect#undef Rselect#endif /* Rselect */#define Rselect BSDselect#endif /* SOCKS */#endif /* SVR4_BSDSELECT */#ifndef FD_SETSIZE#define FD_SETSIZE 256#endif /* !FD_SETSIZE */#ifndef UTMP_FILE#if defined(__FreeBSD__) || defined(__bsdi__)#define UTMP_FILE _PATH_UTMP#else#define UTMP_FILE "/etc/utmp"#endif /* __FreeBSD__ || __bsdi__ */#endif /* !UTMP_FILE */#define FREE(x) if (x) {free(x); x = NULL;}extern HTkcode kanji_code;extern BOOLEAN LYHaveCJKCharacterSet;extern HTCJKlang HTCJK;PRIVATE HTList * localhost_aliases = NULL; /* Hosts to treat as local */PRIVATE char *HomeDir = NULL; /* HOME directory */PUBLIC HTList * sug_filenames = NULL; /* Suggested filenames *//* * Highlight (or unhighlight) a given link. */PUBLIC void highlight ARGS3( int, flag, int, cur, char *, target){ char buffer[200]; int i; char tmp[7], *cp; char *theData = NULL; char *Data = NULL; int Offset, HitOffset, tLen; int LenNeeded; BOOL TargetEmphasisON = FALSE; BOOL utf_flag = (LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8); 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) {#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, ABS_ON, 0); } else { /* the logic is flawed here - no provision is made for links that ** aren't coloured as [s_a] by default - rjp */ if (LYP >= 0 && LYP < CACHEH && LXP >= 0 && LXP < CACHEW && cached_styles[LYP][LXP]) { LynxChangeStyle(cached_styles[LYP][LXP], ABS_ON, 0); } else { LynxChangeStyle(s_a, ABS_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 { /* * 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) { 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); } } } } 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -