Make C_ (gettext used in completions) return wcstring

This commit is contained in:
ridiculousfish 2014-10-30 18:19:47 -07:00
parent fa854d7a01
commit 16459099af
5 changed files with 16 additions and 12 deletions

View file

@ -232,6 +232,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
/* If we can use this function, return whether we were able to access it */ /* If we can use this function, return whether we were able to access it */
if (use_cached) if (use_cached)
{ {
assert(func != NULL);
return func->is_internalized || func->access.accessible; return func->is_internalized || func->access.accessible;
} }
} }

View file

@ -613,7 +613,7 @@ static int builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode, int u
wcstring seq2; wcstring seq2;
if (get_terminfo_sequence(*seq++, &seq2)) if (get_terminfo_sequence(*seq++, &seq2))
{ {
input_mapping_erase(seq2.c_str(), mode); input_mapping_erase(seq2, mode);
} }
else else
{ {

View file

@ -255,7 +255,6 @@ char *wcs2str(const wchar_t *in)
{ {
if (! in) if (! in)
return NULL; return NULL;
char *out;
size_t desired_size = MAX_UTF8_BYTES*wcslen(in)+1; size_t desired_size = MAX_UTF8_BYTES*wcslen(in)+1;
char local_buff[512]; char local_buff[512];
if (desired_size <= sizeof local_buff / sizeof *local_buff) if (desired_size <= sizeof local_buff / sizeof *local_buff)
@ -277,7 +276,7 @@ char *wcs2str(const wchar_t *in)
else else
{ {
// here we fall into the bad case of allocating a buffer probably much larger than necessary // here we fall into the bad case of allocating a buffer probably much larger than necessary
out = (char *)malloc(MAX_UTF8_BYTES*wcslen(in)+1); char *out = (char *)malloc(MAX_UTF8_BYTES*wcslen(in)+1);
if (!out) if (!out)
{ {
DIE_MEM(); DIE_MEM();

View file

@ -101,9 +101,15 @@
response) response)
*/ */
#ifdef USE_GETTEXT #ifdef USE_GETTEXT
#define C_(wstr) ((wcscmp(wstr, L"")==0)?L"":wgettext(wstr)) static const wchar_t *C_(const wcstring &s)
{
return s.empty() ? L"" : wgettext(s);
}
#else #else
#define C_(string) (string) static const wcstring &C_(const wcstring &s)
{
return s;
}
#endif #endif
/* Testing apparatus */ /* Testing apparatus */
@ -158,10 +164,9 @@ typedef struct complete_entry_opt
/** Completion flags */ /** Completion flags */
complete_flags_t flags; complete_flags_t flags;
const wchar_t *localized_desc() const const wcstring localized_desc() const
{ {
const wchar_t *tmp = desc.c_str(); return C_(desc);
return C_(tmp);
} }
} complete_entry_opt_t; } complete_entry_opt_t;
@ -1535,7 +1540,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop
if (o->short_opt != L'\0' && if (o->short_opt != L'\0' &&
short_ok(str, o->short_opt, iter->short_opt_str)) short_ok(str, o->short_opt, iter->short_opt_str))
{ {
const wchar_t *desc = o->localized_desc(); const wcstring desc = o->localized_desc();
wchar_t completion[2]; wchar_t completion[2];
completion[0] = o->short_opt; completion[0] = o->short_opt;
completion[1] = 0; completion[1] = 0;
@ -2110,7 +2115,7 @@ void complete_print(wcstring &out)
for (std::vector<const completion_entry_t *>::const_iterator iter = all_completions.begin(); iter != all_completions.end(); ++iter) for (std::vector<const completion_entry_t *>::const_iterator iter = all_completions.begin(); iter != all_completions.end(); ++iter)
{ {
const completion_entry_t *e = *iter; const completion_entry_t *e = *iter;
const option_list_t options = e->get_options(); const option_list_t &options = e->get_options();
for (option_list_t::const_iterator oiter = options.begin(); oiter != options.end(); ++oiter) for (option_list_t::const_iterator oiter = options.begin(); oiter != options.end(); ++oiter)
{ {
const complete_entry_opt_t *o = &*oiter; const complete_entry_opt_t *o = &*oiter;
@ -2146,7 +2151,7 @@ void complete_print(wcstring &out)
append_switch(out, append_switch(out,
L"description", L"description",
C_(o->desc.c_str())); C_(o->desc));
append_switch(out, append_switch(out,
L"arguments", L"arguments",

View file

@ -978,7 +978,6 @@ env_var_t env_get_string(const wcstring &key, env_mode_flags_t mode)
scoped_lock lock(env_lock); scoped_lock lock(env_lock);
env_node_t *env = search_local ? top : global_env; env_node_t *env = search_local ? top : global_env;
wcstring result;
while (env != NULL) while (env != NULL)
{ {