about summary refs log tree commit diff stats
path: root/WWW/Library
Commit message (Collapse)AuthorAgeFilesLines
* snapshot of project "lynx", label v2-8-1dev_29Thomas E. Dickey1998-09-211-7/+8
|
* snapshot of project "lynx", label v2-8-1dev_28Thomas E. Dickey1998-09-1713-118/+93
|
* snapshot of project "lynx", label v2-8-1dev_26Thomas E. Dickey1998-09-139-194/+219
|
* snapshot of project "lynx", label v2-8-1dev_25Thomas E. Dickey1998-09-074-181/+54
|
* snapshot of project "lynx", label v2-8-1dev_23Thomas E. Dickey1998-08-293-73/+78
|
* snapshot of project "lynx", label v2-8-1dev_22Thomas E. Dickey1998-08-212-5/+21
|
* snapshot of project "lynx", label v2-8-1dev_21Thomas E. Dickey1998-08-151-2/+18
|
* snapshot of project "lynx", label v2-8-1dev_20Thomas E. Dickey1998-08-0689-853/+635
|
* snapshot of project "lynx", label v2-8-1dev_19Thomas E. Dickey1998-07-313-10/+4
|
* snapshot of project "lynx", label v2-8-1dev_18Thomas E. Dickey1998-07-2514-60/+70
|
* snapshot of project "lynx", label v2-8-1dev_17Thomas E. Dickey1998-06-2525-132/+41
|
* snapshot of project "lynx", label v2-8-1dev_14Thomas E. Dickey1998-06-0413-149/+88
|
* snapshot of project "lynx", label v2-8-1dev_13Thomas E. Dickey1998-05-243-118/+122
|
* snapshot of project "lynx", label v2-8-1dev_11Thomas E. Dickey1998-05-143-10/+11
|
* snapshot of project "lynx", label v2-8-1dev_10Thomas E. Dickey1998-05-1110-94/+56
|
* snapshot of project "lynx", label v2-8-1dev_9Thomas E. Dickey1998-05-037-18/+20
|
* snapshot of project "lynx", label v2-8-1dev_8Thomas E. Dickey1998-05-0212-140/+79
|
* snapshot of project "lynx", label v2-8-1dev_7Thomas E. Dickey1998-04-2336-1754/+941
|
* snapshot of project "lynx", label v2-8-1dev_6Thomas E. Dickey1998-04-184-24/+76
|
* snapshot of project "lynx", label v2-8-1dev_5Thomas E. Dickey1998-03-29104-1490/+1251
|
* snapshot of project "lynx", label v2-8-1dev_3Thomas E. Dickey1998-03-212-2/+59
|
* snapshot of project "lynx", label v2-8-1dev_2Thomas E. Dickey1998-03-1827-2153/+40
|
* snapshot of project "lynx", label v2-8pre_4Thomas E. Dickey1998-03-063-11/+7
|
* snapshot of project "lynx", label v2-8pre_3Thomas E. Dickey1998-03-041-7/+7
|
* snapshot of project "lynx", label v2-8pre_2Thomas E. Dickey1998-02-2829-56/+1555
|
* snapshot of project "lynx", label v2-7-1ac-0_117Thomas E. Dickey1998-02-2725-766/+550
|
* snapshot of project "lynx", label v2-7-1ac-0_115Thomas E. Dickey1998-02-1932-3198/+1297
|
* snapshot of project "lynx", label v2-7-1ac-0_114Thomas E. Dickey1998-02-139-755/+660
|
* snapshot of project "lynx", label v2-7-1ac-0_113Thomas E. Dickey1998-02-0530-5165/+6366
|
* snapshot of project "lynx", label v2-7-1ac-0_111Thomas E. Dickey1998-01-2816-608/+17
|
* snapshot of project "lynx", label v2-7-1ac_0-110Thomas E. Dickey1998-01-2255-390/+2405
|
* snapshot of project "lynx", label v2-7-1ac_0-106Thomas E. Dickey1998-01-0524-2019/+0
|
* snapshot of project "lynx", label v2-7-1ac_0-105Thomas E. Dickey1998-01-026-114/+182
|
* snapshot of project "lynx", label v2-7-1ac_0-102Thomas E. Dickey1997-12-185-17/+15
|
* snapshot of project "lynx", label v2-7-1ac_0-97Thomas E. Dickey1997-11-2414-149/+506
|
* snapshot of project "lynx", label v2-7-1ac_0-95Thomas E. Dickey1997-11-1717-308/+698
|
* snapshot of project "lynx", label v2-7-1ac_0-93Thomas E. Dickey1997-11-0711-117/+381
|
* snapshot of project "lynx", label v2-7-1ac_0-89Thomas E. Dickey1997-10-2714-72/+910
|
* snapshot of project "lynx", label v2-7-1ac_0-84Thomas E. Dickey1997-10-1719-138/+559
|
* snapshot of project "lynx", label v2-7-1ac_0-76Thomas E. Dickey1997-10-0633-439/+918
|
* snapshot of project "lynx", label v2-7-1ac_0-69Thomas E. Dickey1997-09-1918-132/+154
|
* snapshot of project "lynx", label v2-7-1ac_0-68Thomas E. Dickey1997-09-189-41/+36
|
* snapshot of project "lynx", label v2-7-1ac_0-67Thomas E. Dickey1997-09-162-4/+4
|
* snapshot of project "lynx", label v2-7-1ac_0-64Thomas E. Dickey1997-09-1213-59/+271
|
* snapshot of project "lynx", label v2-7-1ac_0-60Thomas E. Dickey1997-09-062-12/+25
|
* snapshot of project "lynx", label v2-7-1ac_0-58Thomas E. Dickey1997-09-031-0/+1
|
* snapshot of project "lynx", label v2-7-1ac_0-55Thomas E. Dickey1997-08-273-9/+14
|
* snapshot of project "lynx", label v2-7-1ac_0-52Thomas E. Dickey1997-08-1714-134/+982
|
* snapshot of project "lynx", label v2-7-1ac_0-48Thomas E. Dickey1997-08-071-4/+4
|
* snapshot of project "lynx", label v2-7-1ac_0-47Thomas E. Dickey1997-08-073-382/+390
|
{"rxvt-unicode", rxvt_unicode_keys, rxvt_unicode_funcs}, {"linux", linux_keys, linux_funcs}, {"xterm", xterm_keys, xterm_funcs}, {0, 0, 0}, }; static bool init_from_terminfo = false; static const char **keys; static const char **funcs; static int try_compatible(const char *term, const char *name, const char **tkeys, const char **tfuncs) { if (strstr(term, name)) { keys = tkeys; funcs = tfuncs; return 0; } return EUNSUPPORTED_TERM; } static int init_term_builtin(void) { int i; const char *term = getenv("TERM"); if (term) { for (i = 0; terms[i].name; i++) { if (!strcmp(terms[i].name, term)) { keys = terms[i].keys; funcs = terms[i].funcs; return 0; } } /* let's do some heuristic, maybe it's a compatible terminal */ if (try_compatible(term, "xterm", xterm_keys, xterm_funcs) == 0) return 0; if (try_compatible(term, "rxvt", rxvt_unicode_keys, rxvt_unicode_funcs) == 0) return 0; if (try_compatible(term, "linux", linux_keys, linux_funcs) == 0) return 0; if (try_compatible(term, "Eterm", eterm_keys, eterm_funcs) == 0) return 0; if (try_compatible(term, "screen", screen_keys, screen_funcs) == 0) return 0; /* let's assume that 'cygwin' is xterm compatible */ if (try_compatible(term, "cygwin", xterm_keys, xterm_funcs) == 0) return 0; } return EUNSUPPORTED_TERM; } //---------------------------------------------------------------------- // terminfo //---------------------------------------------------------------------- static char *read_file(const char *file) { FILE *f = fopen(file, "rb"); if (!f) return 0; struct stat st; if (fstat(fileno(f), &st) != 0) { fclose(f); return 0; } char *data = malloc(st.st_size); if (!data) { fclose(f); return 0; } if (fread(data, 1, st.st_size, f) != (size_t)st.st_size) { fclose(f); free(data); return 0; } fclose(f); return data; } static char *terminfo_try_path(const char *path, const char *term) { char tmp[4096]; // snprintf guarantee for older compilers assert(sizeof(tmp) > sizeof(path)+sizeof("/x/")+sizeof(term)+1); snprintf(tmp, sizeof(tmp), "%s/%c/%s", path, term[0], term); char *data = read_file(tmp); if (data) { return data; } // fallback to darwin specific dirs structure // snprintf guarantee above still applies snprintf(tmp, sizeof(tmp), "%s/%x/%s", path, term[0], term); return read_file(tmp); } void string_copy(char* dest, const char* src, int dest_capacity) { strncpy(dest, src, dest_capacity-1); dest[dest_capacity-1] = '\0'; } void string_append(char* dest, const char* src, int dest_capacity) { strncat(dest, src, dest_capacity); dest[dest_capacity-1] = '\0'; } static char *load_terminfo(void) { char tmp[4096]; const char *term = getenv("TERM"); if (!term) { return 0; } // if TERMINFO is set, no other directory should be searched const char *terminfo = getenv("TERMINFO"); if (terminfo) { return terminfo_try_path(terminfo, term); } // next, consider ~/.terminfo const char *home = getenv("HOME"); if (home) { // snprintf guarantee for older compilers assert(sizeof(tmp) > sizeof(home)+sizeof("/.terminfo")+1); string_copy(tmp, home, sizeof(tmp)); string_append(tmp, "/.terminfo", sizeof(tmp)); char *data = terminfo_try_path(tmp, term); if (data) return data; } // next, TERMINFO_DIRS const char *dirs = getenv("TERMINFO_DIRS"); if (dirs) { // snprintf guarantee for older compilers assert(sizeof(tmp) > sizeof(dirs)); string_copy(tmp, dirs, sizeof(tmp)); char *dir = strtok(tmp, ":"); while (dir) { const char *cdir = dir; if (strcmp(cdir, "") == 0) { cdir = "/usr/share/terminfo"; } char *data = terminfo_try_path(cdir, term); if (data) return data; dir = strtok(0, ":"); } } // fallback to /usr/share/terminfo return terminfo_try_path("/usr/share/terminfo", term); } #define TI_MAGIC 0432 #define TI_HEADER_LENGTH 12 #define TB_KEYS_NUM 22 static const char *terminfo_copy_string(char *data, int str, int table) { const int16_t off = *(int16_t*)(data + str); const char *src = data + table + off; int len = strlen(src); char *dst = malloc(len+1); memcpy(dst, src, len+1); return dst; } static const int16_t ti_funcs[] = { 28, 40, 16, 13, 5, 39, 36, 27, 26, 34, 89, 88, }; static const int16_t ti_keys[] = { 66, 68 /* apparently not a typo; 67 is F10 for whatever reason */, 69, 70, 71, 72, 73, 74, 75, 67, 216, 217, 77, 59, 76, 164, 82, 81, 87, 61, 79, 83, }; static int init_term(void) { int i; char *data = load_terminfo(); if (!data) { init_from_terminfo = false; return init_term_builtin(); } int16_t *header = (int16_t*)data; if ((header[1] + header[2]) % 2) { // old quirk to align everything on word boundaries header[2] += 1; } const int str_offset = TI_HEADER_LENGTH + header[1] + header[2] + 2 * header[3]; const int table_offset = str_offset + 2 * header[4]; keys = malloc(sizeof(const char*) * (TB_KEYS_NUM+1)); for (i = 0; i < TB_KEYS_NUM; i++) { keys[i] = terminfo_copy_string(data, str_offset + 2 * ti_keys[i], table_offset); } keys[TB_KEYS_NUM] = 0; funcs = malloc(sizeof(const char*) * T_FUNCS_NUM); // the last four entries are reserved for mouse, bracketed paste. because the table offset is // not there, the two entries have to fill in manually for (i = 0; i < T_FUNCS_NUM-4; i++) { funcs[i] = terminfo_copy_string(data, str_offset + 2 * ti_funcs[i], table_offset); } funcs[T_FUNCS_NUM-4] = "\033[?1000h"; funcs[T_FUNCS_NUM-3] = "\033[?1000l"; funcs[T_FUNCS_NUM-2] = "\033[?2004h"; funcs[T_FUNCS_NUM-1] = "\033[?2004l"; init_from_terminfo = true; free(data); return 0; } static void shutdown_term(void) { if (init_from_terminfo) { int i; for (i = 0; i < TB_KEYS_NUM; i++) { free((void*)keys[i]); } // the last four entries are reserved for mouse, bracketed paste. because the table offset // is not there, the two entries have to fill in manually and do not // need to be freed. for (i = 0; i < T_FUNCS_NUM-4; i++) { free((void*)funcs[i]); } free(keys); free(funcs); } }