mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Make tok_first return a wcstring instead of a wchar_t*
This commit is contained in:
parent
7117c4a5ee
commit
6fc9e6f21e
4 changed files with 25 additions and 26 deletions
|
@ -3254,10 +3254,9 @@ static int builtin_fg(parser_t &parser, wchar_t **argv)
|
||||||
j->command_wcstr());
|
j->command_wcstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *ft = tok_first(j->command_wcstr());
|
const wcstring ft = tok_first(j->command_wcstr());
|
||||||
if (ft != 0)
|
if (! ft.empty())
|
||||||
env_set(L"_", ft, ENV_EXPORT);
|
env_set(L"_", ft.c_str(), ENV_EXPORT);
|
||||||
free(ft);
|
|
||||||
reader_write_title();
|
reader_write_title();
|
||||||
|
|
||||||
make_first(j);
|
make_first(j);
|
||||||
|
|
|
@ -2200,14 +2200,12 @@ void set_env_cmd_duration(struct timeval *after, struct timeval *before)
|
||||||
void reader_run_command(parser_t &parser, const wchar_t *cmd)
|
void reader_run_command(parser_t &parser, const wchar_t *cmd)
|
||||||
{
|
{
|
||||||
|
|
||||||
wchar_t *ft;
|
|
||||||
struct timeval time_before, time_after;
|
struct timeval time_before, time_after;
|
||||||
|
|
||||||
ft= tok_first(cmd);
|
wcstring ft = tok_first(cmd);
|
||||||
|
|
||||||
if (ft != 0)
|
if (! ft.empty())
|
||||||
env_set(L"_", ft, ENV_GLOBAL);
|
env_set(L"_", ft.c_str(), ENV_GLOBAL);
|
||||||
free(ft);
|
|
||||||
|
|
||||||
reader_write_title();
|
reader_write_title();
|
||||||
|
|
||||||
|
|
|
@ -642,24 +642,26 @@ const wchar_t *tok_string(tokenizer_t *tok)
|
||||||
return tok?tok->orig_buff:0;
|
return tok?tok->orig_buff:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *tok_first(const wchar_t *str)
|
wcstring tok_first(const wchar_t *str)
|
||||||
{
|
{
|
||||||
wchar_t *res=0;
|
wcstring result;
|
||||||
|
if (str)
|
||||||
CHECK(str, 0);
|
|
||||||
|
|
||||||
tokenizer_t t(str, TOK_SQUASH_ERRORS);
|
|
||||||
switch (tok_last_type(&t))
|
|
||||||
{
|
{
|
||||||
case TOK_STRING:
|
tokenizer_t t(str, TOK_SQUASH_ERRORS);
|
||||||
// fwprintf( stderr, L"Got token %ls\n", tok_last( &t ));
|
switch (tok_last_type(&t))
|
||||||
res = wcsdup(tok_last(&t));
|
{
|
||||||
break;
|
case TOK_STRING:
|
||||||
default:
|
{
|
||||||
break;
|
const wchar_t *tmp = tok_last(&t);
|
||||||
|
if (tmp != NULL)
|
||||||
|
result = tmp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tok_get_pos(tokenizer_t *tok)
|
int tok_get_pos(tokenizer_t *tok)
|
||||||
|
|
|
@ -156,9 +156,9 @@ const wchar_t *tok_string(tokenizer_t *tok);
|
||||||
convenience function, used to retrieve the first token of a
|
convenience function, used to retrieve the first token of a
|
||||||
string. This can be useful for error messages, etc.
|
string. This can be useful for error messages, etc.
|
||||||
|
|
||||||
The string should be freed. After use.
|
On failure, returns the empty string.
|
||||||
*/
|
*/
|
||||||
wchar_t *tok_first(const wchar_t *str);
|
wcstring tok_first(const wchar_t *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Indicates whether a character can be part of a string, or is a string separator.
|
Indicates whether a character can be part of a string, or is a string separator.
|
||||||
|
|
Loading…
Reference in a new issue