Commit: c02ea59978663ff6826ec78e734077c7859a7ec9
Parent: 33c5bf9ae974f23cb59657881bfa39d14cdfc83e
Author: Randy Palamar
Date: Thu, 1 Dec 2022 21:26:01 -0700
cleanup some convert() calls
if dopt == NULL then convert is equivalent to stracpy()
Diffstat:
10 files changed, 35 insertions(+), 58 deletions(-)
diff --git a/bfu.c b/bfu.c
@@ -916,7 +916,7 @@ dlg_get_history_string(struct terminal *term, struct history_item *hi, int l)
{
unsigned char *s;
int ch = 0;
- s = convert(0, ch, hi->str, NULL);
+ s = stracpy(hi->str);
if (strlen(cast_const_char s) >= (size_t)l)
s[l - 1] = 0;
if (!ch) {
@@ -2242,23 +2242,16 @@ msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title,
void
add_to_history(struct terminal *term, struct history *h, unsigned char *t)
{
- unsigned char *s;
struct history_item *hi, *hs = NULL;
struct list_head *lhs;
size_t l;
if (!h || !t || !*t)
return;
- if (term)
- s = convert(0, 0, t, NULL);
- else
- s = t;
- l = strlen(cast_const_char s);
+ l = strlen(cast_const_char t);
if (l > INT_MAX - sizeof(struct history_item))
overalloc();
hi = xmalloc(sizeof(struct history_item) + l);
- memcpy(hi->str, s, l + 1);
- if (term)
- free(s);
+ memcpy(hi->str, t, l + 1);
if (term)
foreach (struct history_item, hs, lhs, h->items)
if (!strcmp(cast_const_char hs->str,
diff --git a/bookmark.c b/bookmark.c
@@ -129,14 +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(0, 0, txt, NULL);
+ zelena->url = stracpy(txt);
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(0, 0, txt, NULL);
+ zelena->title = stracpy(txt);
clr_white(zelena->title);
}
@@ -231,11 +231,11 @@ bookmark_edit_done(void *data)
url = title + MAX_STR_LEN;
free(item->title);
- item->title = convert(0, 0, title, NULL);
+ item->title = stracpy(title);
clr_white(item->title);
free(item->url);
- item->url = convert(0, 0, url, NULL);
+ item->url = stracpy(url);
clr_white(item->url);
s->fn(s->dlg, s->data, &item->head, &bookmark_ld);
@@ -285,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, 0, item->title, NULL);
+ txt = stracpy(item->title);
clr_white(txt);
safe_strncpy(title, txt, MAX_STR_LEN);
free(txt);
- txt = convert(0, 0, item->url, NULL);
+ txt = stracpy(item->url);
clr_white(txt);
safe_strncpy(url, txt, MAX_STR_LEN);
free(txt);
@@ -392,7 +392,7 @@ bookmark_type_item(struct terminal *term, struct list *data, int x)
add_to_strn(&txt, cast_uchar ")");
}
- txt1 = convert(0, 0, txt, NULL);
+ txt1 = stracpy(txt);
clr_white(txt1);
free(txt);
return txt1;
@@ -494,7 +494,7 @@ add_bookmark(unsigned char *title, unsigned char *url, int depth)
dop = mem_calloc(sizeof(struct document_options));
dop->cp = 0;
- b->title = convert(0, 0, title, dop);
+ b->title = stracpy(title);
clr_white(b->title);
if (url) {
diff --git a/charsets.c b/charsets.c
@@ -448,7 +448,7 @@ unsigned char *
to_utf8_upcase(unsigned char *str, int cp)
{
unsigned char *str1, *str2;
- str1 = convert(cp, 0, str, NULL);
+ str1 = stracpy(str);
str2 = unicode_upcase_string(str1);
free(str1);
return str2;
diff --git a/menu.c b/menu.c
@@ -987,7 +987,7 @@ save_proxy(int charset, unsigned char *result, unsigned char *proxy)
return 0;
}
- proxy = convert(charset, 0, proxy, NULL);
+ proxy = stracpy(proxy);
url = stracpy(cast_uchar "proxy://");
add_to_strn(&url, proxy);
@@ -1033,7 +1033,7 @@ save_noproxy_list(int charset, unsigned char *result,
{
unsigned char *res;
- noproxy_list = convert(charset, 0, noproxy_list, NULL);
+ noproxy_list = stracpy(noproxy_list);
res = idn_encode_host(noproxy_list,
(int)strlen(cast_const_char noproxy_list),
cast_uchar ".,", 0);
diff --git a/objreq.c b/objreq.c
@@ -121,8 +121,8 @@ auth_ok(struct dialog_data *dlg, struct dialog_item_data *item)
->data;
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);
+ uid = stracpy(a->uid);
+ passwd = stracpy(a->passwd);
add_auth(rq->url, a->realm, uid, passwd, a->proxy);
free(uid);
free(passwd);
@@ -167,7 +167,7 @@ auth_window(struct object_request *rq, unsigned char *realm)
free(port);
}
}
- urealm = convert(0, net_cp, realm, NULL);
+ urealm = stracpy(realm);
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, 0, clipboard, NULL);
+ return stracpy(clipboard);
}
/* links -> clipboard */
@@ -457,7 +457,7 @@ void
set_clipboard_text(struct terminal *term, unsigned char *data)
{
free(clipboard);
- clipboard = convert(0, 0, data, NULL);
+ clipboard = stracpy(data);
}
int
diff --git a/session.c b/session.c
@@ -3107,7 +3107,7 @@ void
goto_url(void *ses_, unsigned char *url)
{
struct session *ses = (struct session *)ses_;
- unsigned char *u = convert(0, 0, url, NULL);
+ unsigned char *u = stracpy(url);
goto_url_utf8(ses, u);
free(u);
}
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, 0, txt, NULL);
+ txt1 = stracpy(txt);
free(txt);
return txt1;
@@ -255,15 +255,15 @@ assoc_edit_done(void *data)
ct = label + MAX_STR_LEN;
prog = ct + MAX_STR_LEN;
- txt = convert(0, assoc_ld.codepage, label, NULL);
+ txt = stracpy(label);
free(item->label);
item->label = txt;
- txt = convert(0, assoc_ld.codepage, ct, NULL);
+ txt = stracpy(ct);
free(item->ct);
item->ct = txt;
- txt = convert(0, assoc_ld.codepage, prog, NULL);
+ txt = stracpy(prog);
free(item->prog);
item->prog = txt;
@@ -538,7 +538,7 @@ ext_copy_item(struct list *in, struct list *out)
static unsigned char *
ext_type_item(struct terminal *term, struct list *data, int x)
{
- unsigned char *txt, *txt1;
+ unsigned char *txt;
struct extension *item;
if (data == &extensions)
@@ -549,10 +549,8 @@ 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, 0, txt, NULL);
- free(txt);
- return txt1;
+ return txt;
}
void
@@ -629,11 +627,11 @@ ext_edit_done(void *data)
ext = (unsigned char *)&d->items[5];
ct = ext + MAX_STR_LEN;
- txt = convert(0, ext_ld.codepage, ext, NULL);
+ txt = stracpy(ext);
free(item->ext);
item->ext = txt;
- txt = convert(0, ext_ld.codepage, ct, NULL);
+ txt = stracpy(ct);
free(item->ct);
item->ct = txt;
@@ -1446,15 +1444,9 @@ no_extended:
ly = 0;
add_conv_str(&y, &ly, x, (int)strlen(cast_const_char x), -2);
free(x);
- x = y;
-
free(codepage);
- y = convert(0, 0, x, NULL);
- free(x);
- x = y;
-
- for (y = x; *y; y++)
+ for (x = y; *y; y++)
if (dir_sep(*y))
*y = '-';
return x;
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, 0, url_dec, NULL);
+ url_conv = stracpy(url_dec);
free(url_dec);
- url_conv2 = convert(0, 0, url_conv, NULL);
+ url_conv2 = stracpy(url_conv);
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, 0, url, NULL);
+ ret = stracpy(url);
free(url);
free(url_conv);
free(url_enc);
diff --git a/view.c b/view.c
@@ -1877,11 +1877,7 @@ encode_controls(struct list_head *l, unsigned char **data, int *len,
lst = 1;
encode_string(sv->name, data, len);
*len = add_chr_to_str(data, *len, '=');
- if (sv->type == FC_TEXT || sv->type == FC_PASSWORD
- || sv->type == FC_TEXTAREA)
- p2 = convert(cp_from, cp_to, p, NULL);
- else
- p2 = stracpy(p);
+ p2 = stracpy(p);
encode_string(p2, data, len);
free(p2);
}
@@ -1953,11 +1949,7 @@ bnd:
}
add_to_str(data, len, cast_uchar "\r\n\r\n");
if (sv->type != FC_FILE_UPLOAD) {
- if (sv->type == FC_TEXT || sv->type == FC_PASSWORD
- || sv->type == FC_TEXTAREA)
- p = convert(cp_from, cp_to, sv->value, NULL);
- else
- p = stracpy(sv->value);
+ p = stracpy(sv->value);
add_to_str(data, len, p);
free(p);
} else {
@@ -3952,7 +3944,7 @@ save_url(void *ses_, unsigned char *url)
{
struct session *ses = (struct session *)ses_;
unsigned char *u1, *u2;
- u1 = convert(0, 0, url, NULL);
+ u1 = stracpy(url);
u2 = translate_url(u1, ses->term->cwd);
free(u1);
if (!u2) {