links

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

Commit: a81ea9fdf699ac2f2428b1d2f421dbd02d963445
Parent: c49f83269636906033bcf8069fcfd92ae5e06112
Author: opask
Date:   Sun, 19 Aug 2018 18:15:22 -0600

simplification in charsets.c

Diffstat:
Mbfu.c | 10+++++-----
Mblock.c | 2+-
Mbookmark.c | 35++++++++++++++++-------------------
Mcharsets.c | 116+++++++++++++++++--------------------------------------------------------------
Mcodepage.inc | 8++------
Mdefault.c | 4+---
Mhtml.c | 11++++++-----
Mhtml_r.c | 8++++----
Mlinks.h | 10+++-------
Mmain.c | 3+--
Mmenu.c | 18++++++++----------
Mos_dep.c | 4++--
Msession.c | 2+-
Mterminal.c | 14+++++++-------
Murl.c | 6+++---
Mview.c | 36+++++++++++++++++++-----------------
Mx.c | 14++++++--------
17 files changed, 109 insertions(+), 192 deletions(-)

diff --git a/bfu.c b/bfu.c @@ -79,14 +79,14 @@ static inline int is_utf_8(struct terminal *term) if (F) return 1; #endif - if (term_charset(term) == utf8_table) + if (!term_charset(term)) return 1; return 0; } static inline int ttxtlen(struct terminal *term, unsigned char *s) { - if (term_charset(term) == utf8_table) + if (!term_charset(term)) return strlen_utf8(s); return (int)strlen(cast_const_char s); } @@ -1096,10 +1096,10 @@ static unsigned char *dlg_get_history_string(struct terminal *term, struct histo { unsigned char *s; int ch = term_charset(term); - s = convert(utf8_table, ch, hi->str, NULL); + s = convert(0, ch, hi->str, NULL); if (strlen(cast_const_char s) >= (size_t)l) s[l - 1] = 0; - if (ch == utf8_table) { + if (!ch) { int r = (int)strlen(cast_const_char s); unsigned char *p = s; while (r) { @@ -2259,7 +2259,7 @@ void add_to_history(struct terminal *term, struct history *h, unsigned char *t) size_t l; if (!h || !t || !*t) return; if (term) { - s = convert(term_charset(term), utf8_table, t, NULL); + s = convert(term_charset(term), 0, t, NULL); } else { s = t; } diff --git a/block.c b/block.c @@ -344,7 +344,7 @@ int is_url_blocked(unsigned char *url) void init_blocks(void) { - blocks_ld.codepage = utf8_table; + blocks_ld.codepage = 0; } void free_blocks(void) diff --git a/bookmark.c b/bookmark.c @@ -56,8 +56,8 @@ static struct list_description bookmark_ld = { bookmark_type_item, /* no codepage translations (bookmarks are internally in UTF8) */ bookmark_find_item, &bookmark_search_history, - 0, /* this is set in init_bookmarks function */ - 15, /* # of items in main window */ + 0, /* codepage */ + 15, /* # of items in main window */ T_BOOKMARK, T_BOOKMARKS_ALREADY_IN_USE, T_BOOKMARK_MANAGER, @@ -124,7 +124,7 @@ static void *bookmark_default_value(struct session *ses, unsigned char type) { if (ses->screen->f_data) { - zelena->url=convert(term_charset(ses->term),bookmark_ld.codepage,txt,NULL); + zelena->url = convert(term_charset(ses->term), 0, txt, NULL); clr_white(zelena->url); } else @@ -132,7 +132,7 @@ static void *bookmark_default_value(struct session *ses, unsigned char type) } if (get_current_title(ses->screen,txt,MAX_STR_LEN)) /* ses->screen->f_data must exist here */ { - zelena->title=convert(term_charset(ses->term),bookmark_ld.codepage,txt,NULL); + zelena->title = convert(term_charset(ses->term), 0, txt, NULL); clr_white(zelena->title); } @@ -220,11 +220,11 @@ static void bookmark_edit_done(void *data) url = title + MAX_STR_LEN; free(item->title); - item->title = convert(term_charset(s->dlg->win->term), bookmark_ld.codepage, title, NULL); + item->title = convert(term_charset(s->dlg->win->term), 0, title, NULL); clr_white(item->title); free(item->url); - item->url = convert(term_charset(s->dlg->win->term), bookmark_ld.codepage, url, NULL); + item->url = convert(term_charset(s->dlg->win->term), 0, url, NULL); clr_white(item->url); s->fn(s->dlg, s->data, &item->head, &bookmark_ld); @@ -269,12 +269,12 @@ static void bookmark_edit_item(struct dialog_data *dlg, struct list *data, void { unsigned char *txt; - txt = convert(bookmark_ld.codepage, term_charset(dlg->win->term), item->title, NULL); + txt = convert(0, term_charset(dlg->win->term), item->title, NULL); clr_white(txt); safe_strncpy(title, txt, MAX_STR_LEN); free(txt); - txt = convert(bookmark_ld.codepage, term_charset(dlg->win->term), item->url, NULL); + txt = convert(0, term_charset(dlg->win->term), item->url, NULL); clr_white(txt); safe_strncpy(url, txt, MAX_STR_LEN); free(txt); @@ -380,7 +380,7 @@ static unsigned char *bookmark_type_item(struct terminal *term, struct list *dat add_to_strn(&txt, cast_uchar ")"); } - txt1 = convert(bookmark_ld.codepage, term_charset(term), txt, NULL); + txt1 = convert(0, term_charset(term), txt, NULL); clr_white(txt1); free(txt); return txt1; @@ -479,13 +479,13 @@ static void add_bookmark(unsigned char *title, unsigned char *url, int depth) b = xmalloc(sizeof(struct bookmark_list)); dop = mem_calloc(sizeof(struct document_options)); - dop->cp = bookmark_ld.codepage; + dop->cp = 0; - b->title = convert(bookmarks_codepage, bookmark_ld.codepage, title, dop); + b->title = convert(0, 0, title, dop); clr_white(b->title); if (url) { - b->url = convert(bookmarks_codepage, bookmark_ld.codepage, url, NULL); + b->url = stracpy(url); clr_white(b->url); b->head.type = 0; } else { @@ -632,11 +632,10 @@ void init_bookmarks(void) safe_strncpy(e, cast_uchar "bookmarks.html", MAX_STR_LEN - (e - bookmarks_file)); } - bookmark_ld.codepage = utf8_table; load_bookmarks(NULL); } -void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file, int new_bookmarks_codepage) +void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file) { unsigned char *buf; if (test_list_window_in_use(&bookmark_ld, ses->term)) @@ -651,13 +650,11 @@ void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file, in free(buf); free_bookmarks(); safe_strncpy(bookmarks_file, new_bookmarks_file, MAX_STR_LEN); - bookmarks_codepage = new_bookmarks_codepage; load_bookmarks(ses); reinit_list_window(&bookmark_ld); } else { save_only: safe_strncpy(bookmarks_file, new_bookmarks_file, MAX_STR_LEN); - bookmarks_codepage = new_bookmarks_codepage; bookmark_ld.modified = 1; save_bookmarks(ses); } @@ -738,7 +735,7 @@ static void save_bookmarks(struct session *ses) if (b->head.type & 1) { unsigned char *txt, *txt1; - txt = convert(bookmark_ld.codepage, bookmarks_codepage, b->title, NULL); + txt = stracpy(b->title); clr_white(txt); txt1 = convert_to_entity_string(txt); add_to_str(&data, &l, cast_uchar " <DT><H3>"); @@ -749,9 +746,9 @@ static void save_bookmarks(struct session *ses) depth++; } else { unsigned char *txt1, *txt2, *txt11; - txt1 = convert(bookmark_ld.codepage, bookmarks_codepage, b->title, NULL); + txt1 = stracpy(b->title); clr_white(txt1); - txt2 = convert(bookmark_ld.codepage, bookmarks_codepage, b->url, NULL); + txt2 = stracpy(b->url); clr_white(txt2); txt11 = convert_to_entity_string(txt1); add_to_str(&data, &l, cast_uchar " <DT><A HREF=\""); diff --git a/charsets.c b/charsets.c @@ -5,17 +5,9 @@ #include "links.h" -int utf8_table; - -struct table_entry { - unsigned char c; - int u; -}; - struct codepage_desc { const char *name; const char * const *aliases; - const struct table_entry *table; }; #include "codepage.inc" @@ -86,13 +78,6 @@ static void new_translation_table(struct conv_table *p) } } -static const unsigned short strange_chars[32] = { - 0x20ac, 0x0000, 0x002a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, - 0x005e, 0x2030, 0x0160, 0x003c, 0x0152, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0060, 0x0027, 0x0022, 0x0022, 0x002a, 0x2013, 0x2014, - 0x007e, 0x2122, 0x0161, 0x003e, 0x0153, 0x0000, 0x0000, 0x0000, -}; - #define U_EQUAL(a, b) unicode_7b[a].x == (b) #define U_ABOVE(a, b) unicode_7b[a].x > (b) @@ -103,8 +88,6 @@ static int is_nbsp(int u) unsigned char *u2cp(int u, int to, int fallback) { - int j, s; - again: if (u < 0) return cast_uchar ""; if (u < 128) @@ -113,35 +96,16 @@ unsigned char *u2cp(int u, int to, int fallback) return cast_uchar strings[1]; if (u == 0xad) return cast_uchar strings[0]; - if (to == utf8_table) - return encode_utf_8(u); - if (u < 0xa0) { - u = strange_chars[u - 0x80]; - if (!u) - return NULL; - goto again; - } - for (j = 0; codepages[to].table[j].c; j++) - if (codepages[to].table[j].u == u) - return cast_uchar strings[codepages[to].table[j].c]; - if (!fallback) - return NULL; - BIN_SEARCH(N_UNICODE_7B, U_EQUAL, U_ABOVE, u, s); - if (s != -1) - return cast_uchar unicode_7b[s].s; - return NULL; + + return encode_utf_8(u); } int cp2u(unsigned ch, int from) { - const struct table_entry *e; - if (from == utf8_table) + if (!from) return ch; if (from < 0 || ch < 0x80) return ch; - for (e = codepages[from].table; e->c; e++) - if (e->c == ch) - return e->u; return -1; } @@ -236,17 +200,12 @@ static struct conv_table *get_translation_table_to_utf_8(int from) utf_table_init = 0; } else free_utf_table(); - if (from == utf8_table) { + if (!from) { for (i = 128; i < 256; i++) utf_table[i].u.str = stracpy(strings[i]); return utf_table; } for (i = 128; i < 256; i++) utf_table[i].u.str = NULL; - for (i = 0; codepages[from].table[i].c; i++) { - const int u = codepages[from].table[i].u; - if (!utf_table[codepages[from].table[i].c].u.str) - utf_table[codepages[from].table[i].c].u.str = stracpy(encode_utf_8(u)); - } for (i = 128; i < 256; i++) if (!utf_table[i].u.str) utf_table[i].u.str = stracpy(no_str); return utf_table; @@ -310,14 +269,14 @@ void free_conv_table(void) new_translation_table(table); } -struct conv_table *get_translation_table(int from, int to) +struct conv_table *get_translation_table(const int from, const int to) { int i; static int lfr = -1; static int lto = -1; if (from == -1 || to == -1) return NULL; - if (to == utf8_table) + if (!to) return get_translation_table_to_utf_8(from); if (table_init) { memset(table, 0, sizeof(struct conv_table) * 256); @@ -328,29 +287,11 @@ struct conv_table *get_translation_table(int from, int to) lfr = from; lto = to; new_translation_table(table); - if (from == utf8_table) { - int j; - for (j = 0; codepages[to].table[j].c; j++) - add_utf_8(table, codepages[to].table[j].u, - is_nbsp(codepages[to].table[j].u) ? - cast_uchar strings[1] : codepages[to].table[j].u == 0xad ? - cast_uchar strings[0] : cast_uchar strings[codepages[to].table[j].c]); + if (!from) for (i = 0; unicode_7b[i].x != -1; i++) if (unicode_7b[i].x >= 0x80) add_utf_8(table, unicode_7b[i].x, cast_uchar unicode_7b[i].s); - } else - for (i = 128; i < 256; i++) { - int j; - unsigned char *u; - for (j = 0; codepages[from].table[j].c; j++) - if (codepages[from].table[j].c == i) - goto f; - continue; -f: - if ((u = u2cp(codepages[from].table[j].u, to, 1))) - table[i].u.str = u; - } return table; } @@ -507,29 +448,26 @@ unsigned char *convert(int from, int to, unsigned char *c, struct document_optio need_table: ct = get_translation_table(from, to); - return convert_string(ct, c, (int)strlen(cast_const_char c), dopt); + return convert_string(ct, c, strlen((char *)c), dopt); } int get_cp_index(const unsigned char *n) { - int i, a, p, q, sl, ii = -1, ll = 0; - for (i = 0; codepages[i].name; i++) { - for (a = 0; codepages[i].aliases[a]; a++) { + 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[i].aliases[a][0])) { - for (q = 1; codepages[i].aliases[a][q]; q++) { - if (upcase(n[p+q]) != upcase(codepages[i].aliases[a][q])) goto fail; - } - sl = (int)strlen(cast_const_char codepages[i].aliases[a]); + 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 = i; + ii = 0; } } fail:; } - } - } return ii; } @@ -569,7 +507,8 @@ unsigned charset_upcase(unsigned ch, int cp) u = cp2u(ch, cp); BIN_SEARCH(array_elements(unicode_upcase), UP_EQUAL, UP_ABOVE, u, res); if (res == -1) return ch; - if (cp == utf8_table) return unicode_upcase[res].n; + if (!cp) + return unicode_upcase[res].n; str = u2cp(unicode_upcase[res].n, cp, 0); if (!str || !str[0] || str[1]) return ch; return str[0]; @@ -577,14 +516,14 @@ unsigned charset_upcase(unsigned ch, int cp) unsigned uni_upcase(unsigned ch) { - return charset_upcase(ch, utf8_table); + return charset_upcase(ch, 0); } void charset_upcase_string(unsigned char **chp, int cp) { unsigned char *ch = *chp; int i; - if (cp == utf8_table) { + if (!cp) { ch = unicode_upcase_string(ch); free(*chp); *chp = ch; @@ -612,7 +551,7 @@ unsigned char *unicode_upcase_string(unsigned char *ch) unsigned char *to_utf8_upcase(unsigned char *str, int cp) { unsigned char *str1, *str2; - str1 = convert(cp, utf8_table, str, NULL); + str1 = convert(cp, 0, str, NULL); str2 = unicode_upcase_string(str1); free(str1); return str2; @@ -658,13 +597,14 @@ int strlen_utf8(unsigned char *s) int cp_len(int cp, unsigned char *s) { - if (cp == utf8_table) return strlen_utf8(s); + if (!cp) + return strlen_utf8(s); return (int)strlen(cast_const_char s); } unsigned char *cp_strchr(int charset, unsigned char *str, unsigned chr) { - if (charset != utf8_table) { + if (charset) { if (chr >= 0x100) return NULL; return cast_uchar strchr(cast_const_char str, chr); @@ -677,11 +617,3 @@ unsigned char *cp_strchr(int charset, unsigned char *str, unsigned chr) if (c == chr) return o_str; } } - -void init_charset(void) -{ - utf8_table = get_cp_index(cast_uchar "UTF-8"); - if (utf8_table == -1) - internal("no UTF-8 charset"); - bookmarks_codepage = utf8_table; -} diff --git a/codepage.inc b/codepage.inc @@ -1,12 +1,8 @@ /* Automatically generated by gen-cp */ -static const struct table_entry table_utf_8 [] = { - { 0, 0 } -}; - static const char *aliases_utf_8 [] = {"utf-8", "utf8", NULL }; static const struct codepage_desc codepages [] = { - { "Unicode UTF-8", aliases_utf_8, table_utf_8 }, - { NULL, NULL, NULL } + { "Unicode UTF-8", aliases_utf_8 }, + { NULL, NULL } }; diff --git a/default.c b/default.c @@ -960,7 +960,7 @@ static unsigned char *lookup_cmd(struct option *o, unsigned char ***argv, int *a if (*argc >= 2) return cast_uchar "Too many parameters"; h = *(*argv)++; (*argc)--; - h2 = convert(get_commandline_charset(), utf8_table, h, NULL); + h2 = convert(get_commandline_charset(), 0, h, NULL); h3 = idn_encode_host(h2, (int)strlen(cast_const_char h2), cast_uchar ".", 0); if (!h3) h3 = stracpy(h2); free(h2); @@ -1548,7 +1548,6 @@ unsigned G_SCROLL_BAR_BAR_COLOR = G_DEFAULT_SCROLL_BAR_BAR_COLOR; unsigned G_SCROLL_BAR_FRAME_COLOR = G_DEFAULT_SCROLL_BAR_FRAME_COLOR; unsigned char bookmarks_file[MAX_STR_LEN]=""; -int bookmarks_codepage=0; /* changed to utf-8 table in init_charset() */ int save_history = 1; @@ -1654,7 +1653,6 @@ static struct option links_options[] = { {1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &G_SCROLL_BAR_BAR_COLOR, "scroll_bar_bar_color", "scroll-bar-bar-color"}, {1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &G_SCROLL_BAR_FRAME_COLOR, "scroll_bar_frame_color", "scroll-bar-frame-color"}, {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, bookmarks_file, "bookmarks_file", "bookmarks-file"}, - {1, gen_cmd, cp_rd, cp_wr, 0, 0, &bookmarks_codepage, "bookmarks_codepage", "bookmarks-codepage"}, {1, gen_cmd, num_rd, num_wr, 0, 1, &save_history, "save_url_history", "save-url-history"}, {1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_red_gamma, "display_red_gamma", "display-red-gamma"}, {1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_green_gamma, "display_green_gamma", "display-green-gamma"}, diff --git a/html.c b/html.c @@ -227,7 +227,7 @@ static unsigned char *get_url_val(unsigned char *e, unsigned char *name) get_attr_val_nl = 0; if (!a) return NULL; - if (d_opt->real_cp != utf8_table) { + if (d_opt->real_cp) { if (url_non_ascii(a)) goto need_convert; } @@ -649,11 +649,12 @@ static int put_chars_conv(unsigned char *c, int l) if (c[pp] != '&') { struct conv_table *t; int i; - if (pp + 3 <= l && c[pp] == 0xef && c[pp + 1] == 0xbb && c[pp + 2] == 0xbf && d_opt->real_cp == utf8_table) { + if (pp + 3 <= l && c[pp] == 0xef && c[pp + 1] == 0xbb && c[pp + 2] == 0xbf && !d_opt->real_cp) { pp += 3; continue; } - if ((d_opt->real_cp == d_opt->cp && d_opt->real_cp == utf8_table) || !convert_table) goto put_c; + if ((d_opt->real_cp == d_opt->cp && !d_opt->real_cp) || !convert_table) + goto put_c; t = convert_table; i = pp; decode: @@ -688,7 +689,7 @@ static int put_chars_conv(unsigned char *c, int l) if (bp + sl > CH_BUF) { flush1: put_chars_f(ff, buffer, bp); - if (d_opt->cp == utf8_table) { + if (!d_opt->cp) { while (bp) if ((buffer[--bp] & 0xc0) != 0x80) total++; } else { total += bp; @@ -701,7 +702,7 @@ static int put_chars_conv(unsigned char *c, int l) if (bp == CH_BUF) goto flush; } if (bp) put_chars_f(ff, buffer, bp); - if (d_opt->cp == utf8_table) { + if (!d_opt->cp) { while (bp) if ((buffer[--bp] & 0xc0) != 0x80) total++; } else { total += bp; diff --git a/html_r.c b/html_r.c @@ -611,7 +611,7 @@ static void put_chars(void *p_, unsigned char *c, int l) if (c[0] != ' ' || (c[1] && c[1] != ' ')) { last_tag_for_newline = &p->data->tags; } - if (d_opt->cp == utf8_table && !(format_.attr & AT_GRAPHICS)) { + if (!d_opt->cp && !(format_.attr & AT_GRAPHICS)) { int pl; unsigned char *cc; if (p->utf8_part_len) { @@ -684,7 +684,7 @@ static void put_chars(void *p_, unsigned char *c, int l) free(uni_c); return; } - if (d_opt->cp == utf8_table && !(format_.attr & AT_GRAPHICS)) { + if (!d_opt->cp && !(format_.attr & AT_GRAPHICS)) { set_hline_uni(p, p->cx, p->cy, ll, uni_c, ((fg&0x08)<<3)|(bg<<3)|(fg&0x07)); } else { @@ -1215,9 +1215,9 @@ void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned c if (d_opt->break_long_lines) implicit_pre_wrap = 1; if (d_opt->plain) *t = 0; if (screen->opt.plain == 2) { - screen->cp = utf8_table; + screen->cp = 0; screen->ass = -1; - convert_table = get_translation_table(utf8_table, screen->opt.cp); + convert_table = get_translation_table(0, screen->opt.cp); } else { convert_table = get_convert_table(head, screen->opt.cp, screen->opt.assume_cp, &screen->cp, &screen->ass, screen->opt.hard_assume); } diff --git a/links.h b/links.h @@ -2821,8 +2821,6 @@ extern tcount gamma_stamp; /* charsets.c */ -extern int utf8_table; - struct conv_table { int t; union { @@ -2831,7 +2829,7 @@ struct conv_table { } u; }; -struct conv_table *get_translation_table(int, int); +struct conv_table *get_translation_table(const int, const int); 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 *); @@ -2853,7 +2851,6 @@ unsigned char *to_utf8_upcase(unsigned char *str, int cp); int compare_case_utf8(unsigned char *u1, unsigned char *u2); int strlen_utf8(unsigned char *s); unsigned char *cp_strchr(int charset, unsigned char *str, unsigned chr); -void init_charset(void); unsigned get_utf_8(unsigned char **p); #define GET_UTF_8(s, c) \ @@ -2896,7 +2893,7 @@ static inline int utf8chrlen(unsigned char c) static inline unsigned GET_TERM_CHAR(struct terminal *term, unsigned char **str) { unsigned ch; - if (term_charset(term) == utf8_table) + if (!term_charset(term)) GET_UTF_8(*str, ch); else ch = *(*str)++; @@ -3620,7 +3617,6 @@ extern int menu_font_size; extern unsigned G_BFU_FG_COLOR, G_BFU_BG_COLOR, G_SCROLL_BAR_AREA_COLOR, G_SCROLL_BAR_BAR_COLOR, G_SCROLL_BAR_FRAME_COLOR; extern unsigned char bookmarks_file[MAX_STR_LEN]; -extern int bookmarks_codepage; extern int save_history; @@ -3793,7 +3789,7 @@ extern struct list bookmarks; void finalize_bookmarks(void); /* called, when exiting links */ void init_bookmarks(void); /* called at start */ -void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file, int new_bookmarks_codepage); +void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file); /* Launches bookmark manager */ void menu_bookmark_manager(struct terminal *, void *, void *); diff --git a/main.c b/main.c @@ -411,7 +411,7 @@ static void init(void) retval = RET_SYNTAX; goto tttt; } - uu = convert(get_commandline_charset(), utf8_table, u, NULL); + uu = convert(get_commandline_charset(), 0, u, NULL); if (!(uuu = translate_url(uu, wd = get_cwd()))) uuu = stracpy(uu); free(uu); request_object(NULL, uuu, NULL, PRI_MAIN, NC_RELOAD, ALLOW_ALL, end_dump, NULL, &dump_obj); @@ -423,7 +423,6 @@ static void init(void) /* Is called before gaphics driver init */ static void initialize_all_subsystems(void) { - init_charset(); set_sigcld(); init_home(); init_dns(); diff --git a/menu.c b/menu.c @@ -572,7 +572,8 @@ static void charset_sel_list(struct terminal *term, int ini, void (*set)(struct mi = new_menu(5); for (i = -def; (n = get_cp_name(i)); i++) { unsigned char *n, *r, *p; - if (!utf && i == utf8_table) continue; + if (!utf && !i) + continue; if (i == -1) { n = TEXT_(T_DEFAULT_CHARSET); r = stracpy(get_cp_name(term->default_character_set)); @@ -1342,7 +1343,7 @@ int save_proxy(int charset, unsigned char *result, unsigned char *proxy) return 0; } - proxy = convert(charset, utf8_table, proxy, NULL); + proxy = convert(charset, 0, proxy, NULL); url = stracpy(cast_uchar "proxy://"); add_to_strn(&url, proxy); @@ -1383,7 +1384,7 @@ int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy { unsigned char *res; - noproxy_list = convert(charset, utf8_table, noproxy_list, NULL); + noproxy_list = convert(charset, 0, noproxy_list, NULL); res = idn_encode_host(noproxy_list, (int)strlen(cast_const_char noproxy_list), cast_uchar ".,", 0); free(noproxy_list); if (!res) { @@ -2452,7 +2453,7 @@ static void menu_color(struct terminal *term, void *xxx, void *ses_) } static unsigned char new_bookmarks_file[MAX_STR_LEN]; -static int new_bookmarks_codepage; +static int new_bookmarks_codepage = 0; #ifdef G static unsigned char menu_font_str[4]; @@ -2485,10 +2486,8 @@ static void refresh_misc(void *ses_) } } #endif - if (strcmp(cast_const_char new_bookmarks_file, cast_const_char bookmarks_file) || new_bookmarks_codepage != bookmarks_codepage) - { - reinit_bookmarks(ses, new_bookmarks_file, new_bookmarks_codepage); - } + if (strcmp((char *)new_bookmarks_file, (char *)bookmarks_file)) + reinit_bookmarks(ses, new_bookmarks_file); } #ifdef G @@ -2615,7 +2614,6 @@ static void miscelaneous_options(struct terminal *term, void *xxx, void *ses_) if (anonymous&&!F) return; /* if you add something into text mode (or both text and graphics), remove this (and enable also miscelaneous_options in do_setup_menu) */ safe_strncpy(new_bookmarks_file,bookmarks_file,MAX_STR_LEN); - new_bookmarks_codepage=bookmarks_codepage; if (!F) { d = mem_calloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item)); } @@ -3295,7 +3293,7 @@ void query_file(struct session *ses, unsigned char *url, unsigned char *head, vo h = xmalloc(sizeof(struct does_file_exist_s)); fc = get_filename_from_url(url, head, 0); - file = convert(utf8_table, 0, fc, NULL); + file = stracpy(fc); free(fc); check_filename(&file); diff --git a/os_dep.c b/os_dep.c @@ -365,7 +365,7 @@ unsigned char *get_clipboard_text(struct terminal *term) #endif if (!clipboard) return NULL; - return convert(utf8_table, term_charset(term), clipboard, NULL); + return convert(0, term_charset(term), clipboard, NULL); } /* links -> clipboard */ @@ -378,7 +378,7 @@ void set_clipboard_text(struct terminal *term, unsigned char *data) } #endif free(clipboard); - clipboard = convert(term_charset(term), utf8_table, data, NULL); + clipboard = convert(term_charset(term), 0, data, NULL); } int clipboard_support(struct terminal *term) diff --git a/session.c b/session.c @@ -2628,7 +2628,7 @@ void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned void goto_url(void *ses_, unsigned char *url) { struct session *ses = (struct session *)ses_; - unsigned char *u = convert(term_charset(ses->term), utf8_table, url, NULL); + unsigned char *u = convert(term_charset(ses->term), 0, url, NULL); goto_url_utf8(ses, u); free(u); } diff --git a/terminal.c b/terminal.c @@ -625,11 +625,11 @@ struct terminal *init_term(int fdin, int fdout, void (*root_window)(struct windo static int process_utf_8(struct terminal *term, struct links_event *ev) { if (ev->ev == EV_KBD) { - if ((!F && term_charset(term) == utf8_table) + if ((!F && !term_charset(term)) #ifdef G - || (F && !(drv->flags & GD_UNICODE_KEYS) && g_kbd_codepage(drv) == utf8_table) + || (F && !(drv->flags & GD_UNICODE_KEYS) && !g_kbd_codepage(drv)) #endif - ) { + ) { size_t l; unsigned char *p; unsigned c; @@ -686,7 +686,7 @@ struct terminal *init_gfx_term(void (*root_window)(struct window *, struct links term->spec = &gfx_term; term->default_character_set = 0; safe_strncpy(term->cwd, cwd, MAX_CWD_LEN); - gfx_term.character_set = utf8_table; + gfx_term.character_set = 0; if (gfx_term.character_set == -1) gfx_term.character_set = 0; init_list(term->windows); term->handle_to_close = -1; @@ -981,8 +981,8 @@ static unsigned char frame_restrict[48] = { add_to_str(&a, &l, cast_uchar "m"); \ } \ if (c >= ' ' && c != 127 && (c != 155 || \ - (term_charset(term) != utf8_table && cp2u(155, term_charset(term)) != -1))) {\ - if (c < 128 || frm || term_charset(term) != utf8_table) {\ + (term_charset(term) && cp2u(155, term_charset(term)) != -1))) {\ + if (c < 128 || frm || term_charset(term)) { \ add_chr_to_str(&a, &l, (unsigned char)c); \ } else { \ /* \ @@ -1427,7 +1427,7 @@ void set_terminal_title(struct terminal *term, unsigned char *title) #ifdef SET_WINDOW_TITLE_UTF_8 { free(title); - title = convert(term_charset(term), utf8_table, term->title, NULL); + title = convert(term_charset(term), 0, term->title, NULL); } #endif if (!F) do_terminal_function(term, TERM_FN_TITLE, title); diff --git a/url.c b/url.c @@ -1200,9 +1200,9 @@ static unsigned char *display_url_or_host(struct terminal *term, unsigned char * else url_dec = idn_encode_host(url, (int)strlen((char *)url), separator, 1); is_idn = strcmp((char *)url_dec, (char *)url); - url_conv = convert(utf8_table, term_charset(term), url_dec, NULL); + url_conv = convert(0, term_charset(term), url_dec, NULL); free(url_dec); - url_conv2 = convert(term_charset(term), utf8_table, url_conv, NULL); + url_conv2 = convert(term_charset(term), 0, url_conv, NULL); if (!just_host) url_enc = idn_encode_url(url_conv2, 0); else @@ -1217,7 +1217,7 @@ static unsigned char *display_url_or_host(struct terminal *term, unsigned char * url_conv = NULL; } } else - ret = convert(utf8_table, term_charset(term), url, NULL); + ret = convert(0, term_charset(term), url, NULL); free(url); free(url_conv); free(url_enc); diff --git a/view.c b/view.c @@ -157,7 +157,7 @@ void sort_links(struct f_data *f) unsigned char *textptr_add(unsigned char *t, int i, int cp) { - if (cp != utf8_table) { + if (cp) { if ((size_t)i <= strlen(cast_const_char t)) return t + i; else return t + strlen(cast_const_char t); } else { @@ -168,7 +168,8 @@ unsigned char *textptr_add(unsigned char *t, int i, int cp) int textptr_diff(unsigned char *t2, unsigned char *t1, int cp) { - if (cp != utf8_table) return (int)(t2 - t1); + if (cp) + return (int)(t2 - t1); else { int i = 0; while (t2 > t1) { @@ -201,7 +202,8 @@ static struct line_info *format_text_uncached(unsigned char *text, int width, in continue; } if (!wrap || textptr_diff(text, b, cp) < width) { - if (cp != utf8_table) text++; + if (cp) + text++; else FWD_UTF_8(text); continue; } @@ -440,7 +442,7 @@ static int get_range(struct f_data *f, int y, int yw, int l, int *s1, int *s2) static int is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int *min, int *max) { - int utf8 = f->opt.cp == utf8_table; + int utf8 = f->opt.cp == 0; int found = 0; int l; int s1, s2; @@ -494,7 +496,7 @@ cont:; static int get_searched(struct f_data_c *scr, struct point **pt, int *pl) { - int utf8 = term_charset(scr->ses->term) == utf8_table; + int utf8 = term_charset(scr->ses->term) == 0; struct f_data *f = scr->f_data; int xp = scr->xp; int yp = scr->yp; @@ -747,7 +749,7 @@ static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link if (!*s) { ch = '_'; } else { - if (f->f_data->opt.cp != utf8_table) { + if (f->f_data->opt.cp) { ch = *s++; } else { GET_UTF_8(s, ch); @@ -779,7 +781,7 @@ static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link if (s >= ln->en) { ch = '_'; } else { - if (f->f_data->opt.cp != utf8_table) { + if (f->f_data->opt.cp) { ch = *s++; } else { GET_UTF_8(s, ch); @@ -821,7 +823,7 @@ static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link if (!*s) { chr = '_'; } else { - if (term_charset(t) == utf8_table) { + if (!term_charset(t)) { GET_UTF_8(s, chr); } else chr = *s++; @@ -1095,14 +1097,12 @@ int dump_to_file(struct f_data *fd, int h) if (c == 1) c = ' '; if (fd->data[y].d[x].at & ATTR_FRAME && c >= 176 && c < 224) c = frame_dumb[c - 176]; } - if (fd->opt.cp == utf8_table && c >= 0x80) { + if (!fd->opt.cp && c >= 0x80) { unsigned char *enc = encode_utf_8(c); strcpy(cast_char(buf + bptr), cast_const_char enc); bptr += (int)strlen(cast_const_char enc); } else - { buf[bptr++] = (unsigned char)c; - } if (bptr >= D_BUF - 7) { if (hard_write(h, buf, bptr) != bptr) goto fail; bptr = 0; @@ -2101,7 +2101,7 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin int ll; v = fs->value = xrealloc(fs->value, strlen(cast_const_char fs->value) + 12); - if (f->f_data->opt.cp != utf8_table) { + if (f->f_data->opt.cp) { nw = a_; a_[0] = (unsigned char)ev->x; a_[1] = 0; @@ -2134,7 +2134,8 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin goto done; } if (ev->x == KBD_LEFT) { - if (f->f_data->opt.cp != utf8_table) fs->state = fs->state ? fs->state - 1 : 0; + if (f->f_data->opt.cp) + fs->state = fs->state ? fs->state - 1 : 0; else { unsigned char *p = fs->value + fs->state; BACK_UTF_8(p, fs->value); @@ -2142,7 +2143,8 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin } } else if (ev->x == KBD_RIGHT) { if ((size_t)fs->state < strlen(cast_const_char fs->value)) { - if (f->f_data->opt.cp != utf8_table) fs->state = fs->state + 1; + if (f->f_data->opt.cp) + fs->state = fs->state + 1; else { unsigned char *p = fs->value + fs->state; FWD_UTF_8(p); @@ -2253,7 +2255,7 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin set_br_pos(f, l); if (!form->ro && fs->state) { int ll = 1; - if (f->f_data->opt.cp == utf8_table) { + if (!f->f_data->opt.cp) { unsigned char *p = fs->value + fs->state; BACK_UTF_8(p, fs->value); ll = (int)(fs->value + fs->state - p); @@ -2266,7 +2268,7 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin if (!F && ev->x == KBD_DEL && !f->last_captured) return 0; set_br_pos(f, l); - if (f->f_data->opt.cp == utf8_table) { + if (!f->f_data->opt.cp) { unsigned char *p = fs->value + fs->state; FWD_UTF_8(p); ll = (int)(p - (fs->value + fs->state)); @@ -3185,7 +3187,7 @@ void save_url(void *ses_, unsigned char *url) { struct session *ses = (struct session *)ses_; unsigned char *u1, *u2; - u1 = convert(term_charset(ses->term), utf8_table, url, NULL); + u1 = convert(term_charset(ses->term), 0, url, NULL); u2 = translate_url(u1, ses->term->cwd); free(u1); if (!u2) { diff --git a/x.c b/x.c @@ -320,7 +320,7 @@ static unsigned char *x_query_palette(void) static inline int trans_key(unsigned char * str, int table) { - if (table == utf8_table) { + if (!table) { int a; GET_UTF_8(str,a); return a; @@ -344,10 +344,8 @@ static int x_translate_key(struct graphics_device *gd, XKeyEvent *e,int *key,int if (get_window_info(gd)->xic) { Status status; - { - len = Xutf8LookupString(get_window_info(gd)->xic, e, cast_char str, str_size, &ks, &status); - } - table = utf8_table; + len = Xutf8LookupString(get_window_info(gd)->xic, e, cast_char str, str_size, &ks, &status); + table = 0; /*fprintf(stderr, "len: %d, ks %ld, status %d\n", len, ks, status);*/ } else len = XLookupString(e,cast_char str,str_size,&ks,&comp); @@ -1882,7 +1880,7 @@ retry_encode_ascii: if (!gd) internal("x_set_window_title called with NULL graphics_device pointer.\n"); - t = convert(utf8_table, output_encoding, title, NULL); + t = convert(0, output_encoding, title, NULL); clr_white(t); if (XSupportsLocale()) { @@ -1956,7 +1954,7 @@ static void selection_request(XEvent *event) if (!x_my_clipboard) str = stracpy(cast_uchar ""); else - str = convert(utf8_table, + str = convert(0, get_cp_index(cast_uchar "iso-8859-1"), x_my_clipboard, NULL); for (p = cast_uchar strchr((char *)str, 1); p; @@ -2042,7 +2040,7 @@ retry: x_my_clipboard = stracpy(buffer); else x_my_clipboard = convert(get_cp_index(cast_uchar "iso-8859-1"), - utf8_table, buffer, NULL); + 0, buffer, NULL); XFree(buffer); } else if (type_atom == x_utf8_string_atom) { type_atom = XA_STRING;