links

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

Commit: 33c5bf9ae974f23cb59657881bfa39d14cdfc83e
Parent: 19e882d4ec6d36b79307859c590a7b64bc0fd3bc
Author: Randy Palamar
Date:   Thu,  1 Dec 2022 20:11:57 -0700

links.h: remove term_charset(a) macro

Diffstat:
Mbfu.c | 151++++++++++++++++++++++++++-----------------------------------------------------
Mbookmark.c | 15+++++++--------
Mlistedit.c | 4++--
Mmenu.c | 11+++++------
Mobjreq.c | 18+++++++-----------
Mos_dep.c | 4++--
Msession.c | 16+++++++---------
Mtypes.c | 19+++++++------------
Murl.c | 6+++---
Mview.c | 41++++++++++++++---------------------------
10 files changed, 103 insertions(+), 182 deletions(-)

diff --git a/bfu.c b/bfu.c @@ -83,14 +83,6 @@ freeml(struct memory_list *ml) } static inline int -is_utf_8(struct terminal *term) -{ - if (!term_charset(term)) - return 1; - return 0; -} - -static inline int txtlen(struct terminal *term, unsigned char *s) { return strlen((char *)s); @@ -107,7 +99,7 @@ select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey, return 0; if (text) { text = stracpy(get_text_translation(text, term)); - charset_upcase_string(&text, term_charset(term)); + charset_upcase_string(&text, 0); } hotkey = get_text_translation(hotkey, term); while (1) { @@ -115,7 +107,7 @@ select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey, c = GET_TERM_CHAR(term, &hotkey); if (!c) break; - c = charset_upcase(c, term_charset(term)); + c = charset_upcase(c, 0); for (i = 0; i < n; i++) if (hotkeys[i] == c) continue; @@ -317,7 +309,7 @@ display_menu_txt(struct terminal *term, void *menu_) if (!c) break; if (!h - && charset_upcase(c, term_charset(term)) + && charset_upcase(c, 0) == menu->hotkeys[p]) { h = 1; set_char(term, menu->x + x + 2, s, c, @@ -490,8 +482,7 @@ mm: } else if (ev->x > ' ') { int i; for (i = 0; i < menu->ni; i++) { - if (charset_upcase(ev->x, - term_charset(win->term)) + if (charset_upcase(ev->x, 0) == menu->hotkeys[i]) { menu->selected = i; scroll_menu(menu, 0); @@ -584,9 +575,7 @@ display_mainmenu(struct terminal *term, void *menu_) c = GET_TERM_CHAR(term, &tmptext); if (!c) break; - if (!s - && charset_upcase(c, term_charset(term)) - == menu->hotkeys[i]) { + if (!s && charset_upcase(c, 0) == menu->hotkeys[i]) { s = 1; set_char(term, p, 0, c, COLOR_MAINMENU_HOTKEY); } else { @@ -713,8 +702,7 @@ go_right: int i; s = 1; for (i = 0; i < menu->ni; i++) { - if (charset_upcase(ev->x, - term_charset(win->term)) + if (charset_upcase(ev->x, 0) == menu->hotkeys[i]) { menu->selected = i; s = 2; @@ -927,7 +915,7 @@ static unsigned char * dlg_get_history_string(struct terminal *term, struct history_item *hi, int l) { unsigned char *s; - int ch = term_charset(term); + int ch = 0; s = convert(0, ch, hi->str, NULL); if (strlen(cast_const_char s) >= (size_t)l) s[l - 1] = 0; @@ -987,26 +975,19 @@ dlg_mouse(struct dialog_data *dlg, struct dialog_item_data *di, case D_FIELD_PASS: if (ev->y != di->y || ev->x < di->x || ev->x >= di->x + di->l) return 0; - if (!is_utf_8(dlg->win->term)) { - if ((size_t)(di->cpos = di->vpos + ev->x - di->x) - > strlen(cast_const_char di->cdata)) - di->cpos = - (int)strlen(cast_const_char di->cdata); - } else { - int p, u; - unsigned char *t = di->cdata; - p = di->x - di->vpos; - while (1) { - di->cpos = (int)(t - di->cdata); - if (!*t) - break; - GET_UTF_8(t, u); - if (!u) - continue; - p++; - if (p > ev->x) - break; - } + int p, u; + unsigned char *t = di->cdata; + p = di->x - di->vpos; + while (1) { + di->cpos = (int)(t - di->cdata); + if (!*t) + break; + GET_UTF_8(t, u); + if (!u) + continue; + p++; + if (p > ev->x) + break; } if (dlg->selected != di - dlg->items) { x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0); @@ -1243,28 +1224,18 @@ dialog_func(struct window *win, struct links_event *ev, int fwd) if (ev->x == KBD_RIGHT) { if ((size_t)di->cpos < strlen(cast_const_char di->cdata)) { - if (!is_utf_8(term)) - di->cpos++; - else { - int u; - unsigned char *p = - di->cdata + di->cpos; - GET_UTF_8(p, u); - di->cpos = (int)(p - di->cdata); - } + int u; + unsigned char *p = di->cdata + di->cpos; + GET_UTF_8(p, u); + di->cpos = (int)(p - di->cdata); } goto dsp_f; } if (ev->x == KBD_LEFT) { if (di->cpos > 0) { - if (!is_utf_8(term)) - di->cpos--; - else { - unsigned char *p = - di->cdata + di->cpos; - BACK_UTF_8(p, di->cdata); - di->cpos = (int)(p - di->cdata); - } + unsigned char *p = di->cdata + di->cpos; + BACK_UTF_8(p, di->cdata); + di->cpos = (int)(p - di->cdata); } goto dsp_f; } @@ -1281,13 +1252,7 @@ dialog_func(struct window *win, struct links_event *ev, int fwd) } if (ev->x >= ' ' && !(ev->y & (KBD_CTRL | KBD_ALT))) { unsigned char *u; - unsigned char p[2] = { 0, 0 }; - if (!is_utf_8(term)) { - p[0] = (unsigned char)ev->x; - u = p; - } else { - u = encode_utf_8(ev->x); - } + u = encode_utf_8(ev->x); if (strlen(cast_const_char di->cdata) + strlen(cast_const_char u) < (size_t)di->item->dlen) { @@ -1307,17 +1272,15 @@ dialog_func(struct window *win, struct links_event *ev, int fwd) if (ev->x == KBD_BS) { if (di->cpos) { int s = 1; - if (is_utf_8(term)) { - unsigned u; - unsigned char *p, *pp; - p = di->cdata; + unsigned u; + unsigned char *p, *pp; + p = di->cdata; a: - pp = p; - GET_UTF_8(p, u); - if (p < di->cdata + di->cpos) - goto a; - s = (int)(p - pp); - } + pp = p; + GET_UTF_8(p, u); + if (p < di->cdata + di->cpos) + goto a; + s = (int)(p - pp); memmove( di->cdata + di->cpos - s, di->cdata + di->cpos, @@ -1332,15 +1295,10 @@ a: if ((size_t)di->cpos < strlen(cast_const_char di->cdata)) { int s = 1; - if (is_utf_8(term)) { - unsigned u; - unsigned char *p = - di->cdata + di->cpos; - GET_UTF_8(p, u); - s = (int)(p - - (di->cdata - + di->cpos)); - } + unsigned u; + unsigned char *p = di->cdata + di->cpos; + GET_UTF_8(p, u); + s = (int)(p - (di->cdata + di->cpos)); memmove( di->cdata + di->cpos, di->cdata + di->cpos + s, @@ -1448,9 +1406,8 @@ gh: dlg->dlg->items[i].text, term); if (dlg->dlg->items[i].type == D_BUTTON && charset_upcase(GET_TERM_CHAR(term, &tx), - term_charset(term)) - == charset_upcase( - ev->x, term_charset(term))) + 0) + == charset_upcase(ev->x, 0)) goto sel; } if (ev->x == KBD_ENTER) { @@ -1745,14 +1702,9 @@ max_text_width(struct terminal *term, unsigned char *text, int *width, do { int c = 0; while (*text && *text != '\n') { - if (!is_utf_8(term)) { - text++; - c++; - } else { - int u; - GET_UTF_8(text, u); - c++; - } + int u; + GET_UTF_8(text, u); + c++; } if (c > *width) *width = c; @@ -1767,14 +1719,9 @@ min_text_width(struct terminal *term, unsigned char *text, int *width, do { int c = 0; while (*text && *text != '\n' && *text != ' ') { - if (!is_utf_8(term)) { - text++; - c++; - } else { - int u; - GET_UTF_8(text, u); - c++; - } + int u; + GET_UTF_8(text, u); + c++; } if (c > *width) *width = c; @@ -2302,7 +2249,7 @@ add_to_history(struct terminal *term, struct history *h, unsigned char *t) if (!h || !t || !*t) return; if (term) - s = convert(term_charset(term), 0, t, NULL); + s = convert(0, 0, t, NULL); else s = t; l = strlen(cast_const_char s); diff --git a/bookmark.c b/bookmark.c @@ -129,15 +129,14 @@ bookmark_default_value(struct session *ses, unsigned char type) zelena->title = NULL; if (get_current_url(ses, txt, MAX_STR_LEN)) { if (ses->screen->f_data) { - zelena->url = - convert(term_charset(ses->term), 0, txt, NULL); + zelena->url = convert(0, 0, txt, NULL); clr_white(zelena->url); } else zelena->url = stracpy(txt); } /* ses->screen->f_data must exist here */ if (get_current_title(ses->screen, txt, MAX_STR_LEN)) { - zelena->title = convert(term_charset(ses->term), 0, txt, NULL); + zelena->title = convert(0, 0, txt, NULL); clr_white(zelena->title); } @@ -232,11 +231,11 @@ bookmark_edit_done(void *data) url = title + MAX_STR_LEN; free(item->title); - item->title = convert(term_charset(s->dlg->win->term), 0, title, NULL); + item->title = convert(0, 0, title, NULL); clr_white(item->title); free(item->url); - item->url = convert(term_charset(s->dlg->win->term), 0, url, NULL); + item->url = convert(0, 0, url, NULL); clr_white(item->url); s->fn(s->dlg, s->data, &item->head, &bookmark_ld); @@ -286,12 +285,12 @@ bookmark_edit_item(struct dialog_data *dlg, struct list *data, title = (unsigned char *)&d->items[a]; url = title + MAX_STR_LEN; - txt = convert(0, term_charset(dlg->win->term), item->title, NULL); + txt = convert(0, 0, item->title, NULL); clr_white(txt); safe_strncpy(title, txt, MAX_STR_LEN); free(txt); - txt = convert(0, term_charset(dlg->win->term), item->url, NULL); + txt = convert(0, 0, item->url, NULL); clr_white(txt); safe_strncpy(url, txt, MAX_STR_LEN); free(txt); @@ -393,7 +392,7 @@ bookmark_type_item(struct terminal *term, struct list *data, int x) add_to_strn(&txt, cast_uchar ")"); } - txt1 = convert(0, term_charset(term), txt, NULL); + txt1 = convert(0, 0, txt, NULL); clr_white(txt1); free(txt); return txt1; diff --git a/listedit.c b/listedit.c @@ -1061,7 +1061,7 @@ list_search_for_back(void *rd_, unsigned char *str) return; free(ld->search_word); - ld->search_word = to_utf8_upcase(str, term_charset(rd->dlg->win->term)); + ld->search_word = to_utf8_upcase(str, 0); ld->search_direction = -1; list_find_next(rd, ld->search_direction); @@ -1079,7 +1079,7 @@ list_search_for(void *rd_, unsigned char *str) return; free(ld->search_word); - ld->search_word = to_utf8_upcase(str, term_charset(rd->dlg->win->term)); + ld->search_word = to_utf8_upcase(str, 0); ld->search_direction = 1; list_find_next(rd, ld->search_direction); diff --git a/menu.c b/menu.c @@ -1054,7 +1054,7 @@ check_proxy_noproxy(struct dialog_data *dlg, struct dialog_item_data *di, int (*save)(int, unsigned char *, unsigned char *)) { unsigned char *result = xmalloc(MAX_STR_LEN); - if (save(term_charset(dlg->win->term), result, di->cdata)) { + if (save(0, result, di->cdata)) { free(result); msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER, TEXT_(T_BAD_PROXY_SYNTAX), MSG_BOX_END, NULL, 1, @@ -1081,15 +1081,14 @@ static int proxy_ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di) { struct terminal *term = dlg->win->term; - int charset = term_charset(term); int op = proxies.only_proxies; int r = ok_dialog(dlg, di); if (r) return r; - save_proxy(charset, proxies.http_proxy, http_proxy); - save_proxy(charset, proxies.https_proxy, https_proxy); - save_proxy(charset, proxies.socks_proxy, socks_proxy); - save_noproxy_list(charset, proxies.no_proxy, no_proxy); + save_proxy(0, proxies.http_proxy, http_proxy); + save_proxy(0, proxies.https_proxy, https_proxy); + save_proxy(0, proxies.socks_proxy, socks_proxy); + save_noproxy_list(0, proxies.no_proxy, no_proxy); if (!proxies.only_proxies) { /* parsing duplicated in make_connection */ diff --git a/objreq.c b/objreq.c @@ -119,13 +119,10 @@ auth_ok(struct dialog_data *dlg, struct dialog_item_data *item) get_dialog_data(dlg); ses = list_struct(dlg->win->term->windows.prev, struct window) ->data; - get_convert_table( - rq->ce_internal->head, term_charset(dlg->win->term), - ses->ds.assume_cp, &net_cp, NULL, ses->ds.hard_assume); - uid = - convert(term_charset(dlg->win->term), net_cp, a->uid, NULL); - passwd = convert(term_charset(dlg->win->term), net_cp, - a->passwd, NULL); + get_convert_table(rq->ce_internal->head, 0, ses->ds.assume_cp, + &net_cp, NULL, ses->ds.hard_assume); + uid = convert(0, net_cp, a->uid, NULL); + passwd = convert(0, net_cp, a->passwd, NULL); add_auth(rq->url, a->realm, uid, passwd, a->proxy); free(uid); free(passwd); @@ -151,9 +148,8 @@ auth_window(struct object_request *rq, unsigned char *realm) if (!(term = find_terminal(rq->term))) return -1; ses = list_struct(term->windows.prev, struct window)->data; - get_convert_table(rq->ce_internal->head, term_charset(term), - ses->ds.assume_cp, &net_cp, NULL, - ses->ds.hard_assume); + get_convert_table(rq->ce_internal->head, 0, ses->ds.assume_cp, &net_cp, + NULL, ses->ds.hard_assume); if (rq->ce_internal->http_code == 407) { unsigned char *h = get_proxy_string(rq->url); if (!h) @@ -171,7 +167,7 @@ auth_window(struct object_request *rq, unsigned char *realm) free(port); } } - urealm = convert(term_charset(term), net_cp, realm, NULL); + urealm = convert(0, net_cp, realm, NULL); d = xmalloc( sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct auth_dialog) diff --git a/os_dep.c b/os_dep.c @@ -449,7 +449,7 @@ get_clipboard_text(struct terminal *term) { if (!clipboard) return NULL; - return convert(0, term_charset(term), clipboard, NULL); + return convert(0, 0, clipboard, NULL); } /* links -> clipboard */ @@ -457,7 +457,7 @@ void set_clipboard_text(struct terminal *term, unsigned char *data) { free(clipboard); - clipboard = convert(term_charset(term), 0, data, NULL); + clipboard = convert(0, 0, data, NULL); } int diff --git a/session.c b/session.c @@ -1939,12 +1939,10 @@ html_interpret(struct f_data_c *fd, int report_status) } memset(&o, 0, sizeof(struct document_options)); ds2do(&fd->ses->ds, &o, fd->ses->term->spec->col); - if (!casecmp(fd->loc->url, cast_uchar "file://", 7) && !o.hard_assume) { - o.assume_cp = term_charset(fd->ses->term); - } - if (fd->parent && fd->parent->f_data && !o.hard_assume) { + if (!casecmp(fd->loc->url, cast_uchar "file://", 7) && !o.hard_assume) + o.assume_cp = 0; + if (fd->parent && fd->parent->f_data && !o.hard_assume) o.assume_cp = fd->parent->f_data->cp; - } o.gamma_stamp = 0; o.plain = fd->vs->plain; if (o.plain == 1 && !o.break_long_lines) { @@ -1964,7 +1962,7 @@ html_interpret(struct f_data_c *fd, int report_status) o.col = fd->ses->term->spec->col; else o.col = 0; - o.cp = term_charset(fd->ses->term); + o.cp = 0; } else { o.col = 3; o.cp = 0; @@ -3109,7 +3107,7 @@ void goto_url(void *ses_, unsigned char *url) { struct session *ses = (struct session *)ses_; - unsigned char *u = convert(term_charset(ses->term), 0, url, NULL); + unsigned char *u = convert(0, 0, url, NULL); goto_url_utf8(ses, u); free(u); } @@ -3153,8 +3151,8 @@ ses_imgmap(struct session *ses) d_opt = &fd->f_data->opt; if (get_image_map(ses->rq->ce->head, start, start + len, ses->goto_position, &menu, &ml, ses->imgmap_href_base, - ses->imgmap_target_base, term_charset(ses->term), - ses->ds.assume_cp, ses->ds.hard_assume, 0)) { + ses->imgmap_target_base, 0, ses->ds.assume_cp, + ses->ds.hard_assume, 0)) { ses_abort_1st_state_loading(ses); return; } diff --git a/types.c b/types.c @@ -144,7 +144,7 @@ assoc_type_item(struct terminal *term, struct list *data, int x) if (item->prog) add_to_strn(&txt, item->prog); } - txt1 = convert(assoc_ld.codepage, term_charset(term), txt, NULL); + txt1 = convert(assoc_ld.codepage, 0, txt, NULL); free(txt); return txt1; @@ -255,18 +255,15 @@ assoc_edit_done(void *data) ct = label + MAX_STR_LEN; prog = ct + MAX_STR_LEN; - txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, label, - NULL); + txt = convert(0, assoc_ld.codepage, label, NULL); free(item->label); item->label = txt; - txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, ct, - NULL); + txt = convert(0, assoc_ld.codepage, ct, NULL); free(item->ct); item->ct = txt; - txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, prog, - NULL); + txt = convert(0, assoc_ld.codepage, prog, NULL); free(item->prog); item->prog = txt; @@ -552,7 +549,7 @@ ext_type_item(struct terminal *term, struct list *data, int x) txt = stracpy(item->ext); add_to_strn(&txt, cast_uchar ": "); add_to_strn(&txt, item->ct); - txt1 = convert(assoc_ld.codepage, term_charset(term), txt, NULL); + txt1 = convert(assoc_ld.codepage, 0, txt, NULL); free(txt); return txt1; @@ -632,13 +629,11 @@ ext_edit_done(void *data) ext = (unsigned char *)&d->items[5]; ct = ext + MAX_STR_LEN; - txt = convert(term_charset(s->dlg->win->term), ext_ld.codepage, ext, - NULL); + txt = convert(0, ext_ld.codepage, ext, NULL); free(item->ext); item->ext = txt; - txt = - convert(term_charset(s->dlg->win->term), ext_ld.codepage, ct, NULL); + txt = convert(0, ext_ld.codepage, ct, NULL); free(item->ct); item->ct = txt; diff --git a/url.c b/url.c @@ -1327,9 +1327,9 @@ display_url_or_host(struct terminal *term, unsigned char *url, int warn_idn, url_dec = idn_encode_host(url, (int)strlen((char *)url), separator, 1); is_idn = strcmp((char *)url_dec, (char *)url); - url_conv = convert(0, term_charset(term), url_dec, NULL); + url_conv = convert(0, 0, url_dec, NULL); free(url_dec); - url_conv2 = convert(term_charset(term), 0, url_conv, NULL); + url_conv2 = convert(0, 0, url_conv, NULL); if (!just_host) url_enc = idn_encode_url(url_conv2, 0); else @@ -1349,7 +1349,7 @@ display_url_or_host(struct terminal *term, unsigned char *url, int warn_idn, url_conv = NULL; } } else - ret = convert(0, term_charset(term), url, NULL); + ret = convert(0, 0, url, NULL); free(url); free(url_conv); free(url_enc); diff --git a/view.c b/view.c @@ -600,7 +600,6 @@ cont:; static int get_searched(struct f_data_c *scr, struct point **pt, int *pl) { - int utf8 = term_charset(scr->ses->term) == 0; struct f_data *f = scr->f_data; int xp = scr->xp; int yp = scr->yp; @@ -633,18 +632,12 @@ get_searched(struct f_data_c *scr, struct point **pt, int *pl) c: continue; } - if (!utf8) { - for (i = 1; i < l; i++) - if (f->search_chr[s1 + i] != w[i]) - goto c; - } else { - ww = w; - for (i = 0; i < l; i++) { - unsigned cc; - GET_UTF_8(ww, cc); - if (f->search_chr[s1 + i] != cc) - goto c; - } + ww = w; + for (i = 0; i < l; i++) { + unsigned cc; + GET_UTF_8(ww, cc); + if (f->search_chr[s1 + i] != cc) + goto c; } for (i = 0; i < l; i++) { struct search *sr = search_lookup(f, s1 + i); @@ -961,14 +954,10 @@ draw_form_entry(struct terminal *t, struct f_data_c *f, struct link *l) s = cast_uchar ""; for (i = 0; i < l->n; i++) { unsigned chr; - if (!*s) { + if (!*s) chr = '_'; - } else { - if (!term_charset(t)) { - GET_UTF_8(s, chr); - } else - chr = *s++; - } + else + GET_UTF_8(s, chr); x = l->pos[i].x + xp - vx; y = l->pos[i].y + yp - vy; if (x >= xp && y >= yp && x < xp + xw && y < yp + yw) @@ -1957,9 +1946,7 @@ bnd: cast_uchar "; charset="); add_to_str(data, len, - get_cp_mime_name( - term_charset( - ses->term))); + get_cp_mime_name(0)); } free(ct); } @@ -2098,7 +2085,7 @@ get_form_url(struct session *ses, struct f_data_c *f, struct form_control *form, if (!form->action) return NULL; get_succesful_controls(f, form, &submit); - cp_from = term_charset(ses->term); + cp_from = 0; cp_to = f->f_data->cp; if (form->method == FM_GET || form->method == FM_POST) encode_controls(&submit, &data, &len, cp_from, cp_to); @@ -2970,7 +2957,7 @@ search_for_back(void *ses_, unsigned char *str) free(ses->search_word); ses->search_word = stracpy(str); clr_spaces(ses->search_word, 0); - charset_upcase_string(&ses->search_word, term_charset(ses->term)); + charset_upcase_string(&ses->search_word, 0); free(ses->last_search_word); ses->last_search_word = stracpy(ses->search_word); ses->search_direction = -1; @@ -2987,7 +2974,7 @@ search_for(void *ses_, unsigned char *str) free(ses->search_word); ses->search_word = stracpy(str); clr_spaces(ses->search_word, 0); - charset_upcase_string(&ses->search_word, term_charset(ses->term)); + charset_upcase_string(&ses->search_word, 0); free(ses->last_search_word); ses->last_search_word = stracpy(ses->search_word); ses->search_direction = 1; @@ -3965,7 +3952,7 @@ save_url(void *ses_, unsigned char *url) { struct session *ses = (struct session *)ses_; unsigned char *u1, *u2; - u1 = convert(term_charset(ses->term), 0, url, NULL); + u1 = convert(0, 0, url, NULL); u2 = translate_url(u1, ses->term->cwd); free(u1); if (!u2) {