Eliminate a static string from input_terminfo_get_sequence

This commit is contained in:
ridiculousfish 2013-04-15 13:07:17 -07:00
parent 1c5556334d
commit bcf3accb74
3 changed files with 14 additions and 18 deletions

View File

@ -471,10 +471,10 @@ static int builtin_bind_add(const wchar_t *seq, const wchar_t *cmd, int terminfo
if (terminfo) if (terminfo)
{ {
const wchar_t *seq2 = input_terminfo_get_sequence(seq); wcstring seq2;
if (seq2) if (input_terminfo_get_sequence(seq, &seq2))
{ {
input_mapping_add(seq2, cmd); input_mapping_add(seq2.c_str(), cmd);
} }
else else
{ {

View File

@ -241,17 +241,14 @@ static void input_terminfo_init();
Returns the function description for the given function code. Returns the function description for the given function code.
*/ */
void input_mapping_add(const wchar_t *sequence, void input_mapping_add(const wchar_t *sequence, const wchar_t *command)
const wchar_t *command)
{ {
size_t i;
CHECK(sequence,); CHECK(sequence,);
CHECK(command,); CHECK(command,);
// debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) ); // debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
for (size_t i=0; i<mapping_list.size(); i++)
for (i=0; i<mapping_list.size(); i++)
{ {
input_mapping_t &m = mapping_list.at(i); input_mapping_t &m = mapping_list.at(i);
if (m.seq == sequence) if (m.seq == sequence)
@ -774,12 +771,11 @@ static void input_terminfo_init()
terminfo_mappings.insert(terminfo_mappings.end(), tinfos, tinfos + count); terminfo_mappings.insert(terminfo_mappings.end(), tinfos, tinfos + count);
} }
const wchar_t *input_terminfo_get_sequence(const wchar_t *name) bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq)
{ {
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
const char *res = 0; const char *res = 0;
static wcstring buff;
int err = ENOENT; int err = ENOENT;
CHECK(name, 0); CHECK(name, 0);
@ -799,11 +795,11 @@ const wchar_t *input_terminfo_get_sequence(const wchar_t *name)
if (!res) if (!res)
{ {
errno = err; errno = err;
return 0; return false;
} }
buff = format_string(L"%s", res); *out_seq = format_string(L"%s", res);
return buff.c_str(); return true;
} }

View File

@ -117,10 +117,10 @@ bool input_mapping_get(const wcstring &sequence, wcstring &cmd);
/** /**
Return the sequence for the terminfo variable of the specified name. Return the sequence for the terminfo variable of the specified name.
If no terminfo variable of the specified name could be found, return 0 and set errno to ENOENT. If no terminfo variable of the specified name could be found, return false and set errno to ENOENT.
If the terminfo variable does not have a value, return 0 and set errno to EILSEQ. If the terminfo variable does not have a value, return false and set errno to EILSEQ.
*/ */
const wchar_t *input_terminfo_get_sequence(const wchar_t *name); bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq);
/** Return the name of the terminfo variable with the specified sequence */ /** Return the name of the terminfo variable with the specified sequence */
bool input_terminfo_get_name(const wcstring &seq, wcstring &name); bool input_terminfo_get_name(const wcstring &seq, wcstring &name);