mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Refactored builtin_echo with better argument parsing.
This commit is contained in:
parent
97ea61a407
commit
061b872498
1 changed files with 33 additions and 20 deletions
53
builtin.cpp
53
builtin.cpp
|
@ -1598,30 +1598,43 @@ static int builtin_echo(parser_t &parser, wchar_t **argv)
|
||||||
bool print_newline = true, print_spaces = true, interpret_special_chars = false;
|
bool print_newline = true, print_spaces = true, interpret_special_chars = false;
|
||||||
while (*argv)
|
while (*argv)
|
||||||
{
|
{
|
||||||
if (! wcscmp(*argv, L"-n"))
|
wchar_t *s = *argv, c = *s;
|
||||||
|
if (c == L'-')
|
||||||
{
|
{
|
||||||
print_newline = false;
|
/* Ensure that option is valid */
|
||||||
}
|
for (++s, c = *s; c != L'\0'; c = *(++s))
|
||||||
else if (! wcscmp(*argv, L"-e"))
|
{
|
||||||
{
|
if (c != L'n' && c != L'e' && c != L's' && c != L'E')
|
||||||
interpret_special_chars = true;
|
{
|
||||||
}
|
goto invalid_echo_option;
|
||||||
else if (! wcscmp(*argv, L"-ne"))
|
}
|
||||||
{
|
}
|
||||||
print_newline = false;
|
|
||||||
interpret_special_chars = true;
|
/* Parse option */
|
||||||
}
|
for (s = *argv, ++s, c = *s; c != L'\0'; c = *(++s))
|
||||||
else if (! wcscmp(*argv, L"-s"))
|
{
|
||||||
{
|
switch (c)
|
||||||
// fish-specific extension, which we should try to nix
|
{
|
||||||
print_spaces = false;
|
case L'n':
|
||||||
}
|
print_newline = false;
|
||||||
else if (! wcscmp(*argv, L"-E"))
|
break;
|
||||||
{
|
case L'e':
|
||||||
interpret_special_chars = false;
|
interpret_special_chars = true;
|
||||||
|
break;
|
||||||
|
case L's':
|
||||||
|
// fish-specific extension,
|
||||||
|
// which we should try to nix
|
||||||
|
print_spaces = false;
|
||||||
|
break;
|
||||||
|
case L'E':
|
||||||
|
interpret_special_chars = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
invalid_echo_option:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
argv++;
|
argv++;
|
||||||
|
|
Loading…
Reference in a new issue