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)
{
const wchar_t *seq2 = input_terminfo_get_sequence(seq);
if (seq2)
wcstring seq2;
if (input_terminfo_get_sequence(seq, &seq2))
{
input_mapping_add(seq2, cmd);
input_mapping_add(seq2.c_str(), cmd);
}
else
{

View File

@ -241,17 +241,14 @@ static void input_terminfo_init();
Returns the function description for the given function code.
*/
void input_mapping_add(const wchar_t *sequence,
const wchar_t *command)
void input_mapping_add(const wchar_t *sequence, const wchar_t *command)
{
size_t i;
CHECK(sequence,);
CHECK(command,);
// debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
for (i=0; i<mapping_list.size(); i++)
for (size_t i=0; i<mapping_list.size(); i++)
{
input_mapping_t &m = mapping_list.at(i);
if (m.seq == sequence)
@ -774,12 +771,11 @@ static void input_terminfo_init()
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();
const char *res = 0;
static wcstring buff;
int err = ENOENT;
CHECK(name, 0);
@ -799,11 +795,11 @@ const wchar_t *input_terminfo_get_sequence(const wchar_t *name)
if (!res)
{
errno = err;
return 0;
}
buff = format_string(L"%s", res);
return buff.c_str();
return false;
}
*out_seq = format_string(L"%s", res);
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.
If no terminfo variable of the specified name could be found, return 0 and set errno to ENOENT.
If the terminfo variable does not have a value, return 0 and set errno to EILSEQ.
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 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 */
bool input_terminfo_get_name(const wcstring &seq, wcstring &name);