links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 118098f2f41c89fe40fcac123581b7b18e69ccd5
Parent: d60d2995dd87cc3b27ef6536021251fc6e5e64be
Author: opask
Date:   Sat, 26 Jan 2019 14:46:42 -0700

charsets.c: remove get_cp_index()

Diffstat:
Mcharsets.c | 20--------------------
Mdefault.c | 19++++++-------------
Mhtml_r.c | 10+---------
Mlinks.h | 1-
Mmain.c | 2+-
Mtypes.c | 15+++------------
Mx.c | 42++++++++----------------------------------
7 files changed, 19 insertions(+), 90 deletions(-)

diff --git a/charsets.c b/charsets.c @@ -388,26 +388,6 @@ need_table: return convert_string(ct, c, strlen((char *)c), dopt); } -int get_cp_index(const unsigned char *n) -{ - int a, p, q, sl, ii = -1, ll = 0; - for (a = 0; codepages[0].aliases[a]; a++) - for (p = 0; n[p]; p++) { - if (upcase(n[p]) == upcase(codepages[0].aliases[a][0])) { - for (q = 1; codepages[0].aliases[a][q]; q++) - if (upcase(n[p+q]) != upcase(codepages[0].aliases[a][q])) - goto fail; - sl = strlen((char *)codepages[0].aliases[a]); - if (sl > ll) { - ll = sl; - ii = 0; - } - } -fail:; - } - return ii; -} - unsigned char *get_cp_name(int index) { if (index < 0) diff --git a/default.c b/default.c @@ -533,13 +533,10 @@ static void str_wr(struct option *o, unsigned char **s, int *l) static unsigned char *cp_rd(struct option *o, unsigned char *c) { unsigned char *tok = get_token(&c); - unsigned char *e = NULL; - int i; if (!tok) return cast_uchar "Missing argument"; - if ((i = get_cp_index(tok)) == -1) e = cast_uchar "Unknown codepage"; - else *(int *)o->ptr = i; + *(int *)o->ptr = 0; free(tok); - return e; + return NULL; } static void cp_wr(struct option *o, unsigned char **s, int *l) @@ -667,8 +664,7 @@ static unsigned char *term_rd(struct option *o, unsigned char *c) if (!casestrcmp(w, cast_uchar "default")) i = -1; else - if ((i = get_cp_index(w)) == -1) - goto err_f; + i = 0; ts->character_set = i; free(w); ts->left_margin = 0; @@ -710,8 +706,7 @@ static unsigned char *term2_rd(struct option *o, unsigned char *c) if (!casestrcmp(w, cast_uchar "default")) i = -1; else - if ((i = get_cp_index(w)) == -1) - goto err_f; + i = 0; ts->character_set = i; free(w); return NULL; @@ -790,10 +785,8 @@ static unsigned char *dp_rd(struct option *o, unsigned char *c) goto err; if (!casestrcmp(cp, cast_uchar "default")) cc = -1; - else if ((cc = get_cp_index(cp)) == -1) { - free(cp); - goto err; - } + else + cc = 0; free(cp); dp->kbd_codepage = cc; dp->nosave = 0; diff --git a/html_r.c b/html_r.c @@ -1148,19 +1148,11 @@ struct conv_table *get_convert_table(unsigned char *head, int to, int def, int * unsigned char *p = head; while (from == -1 && (a = parse_http_header(p, cast_uchar "Content-Type", &p))) { if ((b = parse_header_param(a, cast_uchar "charset", 0))) { - from = get_cp_index(b); + from = 0; free(b); } free(a); } - if (from == -1 && (a = parse_http_header(head, cast_uchar "Content-Charset", NULL))) { - from = get_cp_index(a); - free(a); - } - if (from == -1 && (a = parse_http_header(head, cast_uchar "Charset", NULL))) { - from = get_cp_index(a); - free(a); - } if (aa) { *aa = from == -1; if (hard && !*aa) *aa = 2; diff --git a/links.h b/links.h @@ -2809,7 +2809,6 @@ int get_entity_number(unsigned char *st, int l); unsigned char *get_entity_string(unsigned char *, int, int); unsigned char *convert_string(struct conv_table *, unsigned char *, int, struct document_options *); unsigned char *convert(int from, int to, unsigned char *c, struct document_options *dopt); -int get_cp_index(const unsigned char *); unsigned char *get_cp_name(int); unsigned char *get_cp_mime_name(int); void free_conv_table(void); diff --git a/main.c b/main.c @@ -344,7 +344,7 @@ static void init(void) goto ttt; } fixup_g(); - if ((dds.assume_cp = get_cp_index(cast_uchar "ISO-8859-1")) == -1) dds.assume_cp = 0; + dds.assume_cp = 0; load_config(); if (proxies.only_proxies) reset_settings_for_tor(); diff --git a/types.c b/types.c @@ -1288,7 +1288,6 @@ unsigned char *get_filename_from_header(unsigned char *head) int extended = 0; unsigned char *ct, *x, *y, *codepage; int ly; - int cp_idx; if ((ct = parse_http_header(head, cast_uchar "Content-Disposition", NULL))) { x = parse_header_param(ct, cast_uchar "filename*", 1); if (x) @@ -1339,17 +1338,9 @@ no_extended: free(x); x = y; - cp_idx = -1; - if (codepage) { - cp_idx = get_cp_index(codepage); - free(codepage); - } - if (cp_idx < 0) { - cp_idx = get_cp_index(cast_uchar "iso-8859-1"); - if (cp_idx < 0) - cp_idx = 0; - } - y = convert(cp_idx, 0, x, NULL); + free(codepage); + + y = convert(0, 0, x, NULL); free(x); x = y; diff --git a/x.c b/x.c @@ -92,7 +92,6 @@ static int x_display_height, x_display_width; /* screen dimensions */ static unsigned long x_black_pixel; /* black pixel */ static int x_depth, x_bitmap_bpp; /* bits per pixel and bytes per pixel */ static int x_bitmap_scanline_pad; /* bitmap scanline_padding in bytes */ -static int x_input_encoding; /* locales encoding */ static int x_bitmap_bit_order; static unsigned char x_have_palette; @@ -324,7 +323,7 @@ static int x_translate_key(struct graphics_device *dev, XKeyEvent *e,int *key,in static XComposeStatus comp = { NULL, 0 }; static unsigned char str[16]; #define str_size ((int)(sizeof(str) - 1)) - int table = x_input_encoding < 0 ? g_kbd_codepage(&x_driver) : x_input_encoding; + int table = 0; int len; if (get_window_info(dev)->xic) { @@ -921,14 +920,6 @@ static unsigned char *x_init_driver(unsigned char *param, unsigned char *display #if defined(LC_CTYPE) setlocale(LC_CTYPE, ""); #endif - x_input_encoding = -1; -#if defined(CODESET) - { - unsigned char *cp; - cp = cast_uchar nl_langinfo(CODESET); - x_input_encoding = get_cp_index(cp); - } -#endif if (!display || !*display) display = NULL; @@ -1227,9 +1218,6 @@ invalid_param: #endif } - if (x_input_encoding < 0 && !xim) - x_driver.flags |= GD_NEED_CODEPAGE; - x_fd = XConnectionNumber(x_display); set_handlers(x_fd, x_process_events, NULL, NULL); XSync(x_display, False); @@ -1803,19 +1791,11 @@ static void x_set_window_title(struct graphics_device *dev, unsigned char *title { unsigned char *t; XTextProperty windowName; - int output_encoding; Status ret; - if (XSupportsLocale()) - output_encoding = x_input_encoding >= 0 ? x_input_encoding : 0; - else { -retry_encode_ascii: - output_encoding = 0; - } - if (!dev) internal("x_set_window_title called with NULL graphics_device pointer.\n"); - t = convert(0, output_encoding, title, NULL); + t = convert(0, 0, title, NULL); clr_white(t); if (XSupportsLocale()) { @@ -1834,13 +1814,8 @@ retry_encode_ascii: &windowName); } #endif - if (ret < 0) { - if (output_encoding) { - free(t); - goto retry_encode_ascii; - } else - goto retry_print_ascii; - } + if (ret < 0) + goto retry_print_ascii; } else { retry_print_ascii: ret = XStringListToTextProperty((char**)(&t), 1, &windowName); @@ -1889,9 +1864,8 @@ static void selection_request(XEvent *event) if (!x_my_clipboard) str = stracpy(cast_uchar ""); else - str = convert(0, - get_cp_index(cast_uchar "iso-8859-1"), - x_my_clipboard, NULL); + str = convert(0, 0, x_my_clipboard, NULL); + for (p = cast_uchar strchr((char *)str, 1); p; p = cast_uchar strchr((char *)(str + 1), 1)) *p = 0xa0; @@ -1974,8 +1948,8 @@ static unsigned char *x_get_clipboard_text(void) if (type_atom == x_utf8_string_atom) x_my_clipboard = stracpy(buffer); else - x_my_clipboard = convert(get_cp_index(cast_uchar "iso-8859-1"), - 0, buffer, NULL); + x_my_clipboard = convert(0, 0, buffer, NULL); + XFree(buffer); } else if (type_atom == x_utf8_string_atom) { type_atom = XA_STRING;