aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-10-06 13:08:57 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-10-06 13:08:57 -0700
commitdd91779442125ca46a434cd94cc51ae32e43bee1 (patch)
treee023ebb7a8a0e6f9c6c4a394158773ced0c98a82 /builtin.cpp
parente58b73179f4727c79465c6f273aef377b9bb8bee (diff)
parentfab7299d49492ce548d4ceed66d3acbd05dd99c7 (diff)
Merge branch 'master' into ast_no_templates
Conflicts: configure.ac exec.cpp
Diffstat (limited to 'builtin.cpp')
-rw-r--r--builtin.cpp59
1 files changed, 36 insertions, 23 deletions
diff --git a/builtin.cpp b/builtin.cpp
index 90fb099b..06c9a9b8 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -1600,30 +1600,43 @@ static int builtin_echo(parser_t &parser, wchar_t **argv)
bool print_newline = true, print_spaces = true, interpret_special_chars = false;
while (*argv)
{
- if (! wcscmp(*argv, L"-n"))
+ wchar_t *s = *argv, c = *s;
+ if (c == L'-')
{
- print_newline = false;
- }
- else if (! wcscmp(*argv, L"-e"))
- {
- interpret_special_chars = true;
- }
- else if (! wcscmp(*argv, L"-ne"))
- {
- print_newline = false;
- interpret_special_chars = true;
- }
- else if (! wcscmp(*argv, L"-s"))
- {
- // fish-specific extension, which we should try to nix
- print_spaces = false;
- }
- else if (! wcscmp(*argv, L"-E"))
- {
- interpret_special_chars = false;
+ /* Ensure that option is valid */
+ for (++s, c = *s; c != L'\0'; c = *(++s))
+ {
+ if (c != L'n' && c != L'e' && c != L's' && c != L'E')
+ {
+ goto invalid_echo_option;
+ }
+ }
+
+ /* Parse option */
+ for (s = *argv, ++s, c = *s; c != L'\0'; c = *(++s))
+ {
+ switch (c)
+ {
+ case L'n':
+ print_newline = false;
+ break;
+ case L'e':
+ 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
{
+ invalid_echo_option:
break;
}
argv++;
@@ -3016,7 +3029,7 @@ static int builtin_source(parser_t &parser, wchar_t ** argv)
if ((fd = wopen_cloexec(argv[1], O_RDONLY)) == -1)
{
append_format(stderr_buffer, _(L"%ls: Error encountered while sourcing file '%ls':\n"), argv[0], argv[1]);
- builtin_wperror(L".");
+ builtin_wperror(L"source");
return STATUS_BUILTIN_ERROR;
}
@@ -3024,7 +3037,7 @@ static int builtin_source(parser_t &parser, wchar_t ** argv)
{
close(fd);
append_format(stderr_buffer, _(L"%ls: Error encountered while sourcing file '%ls':\n"), argv[0], argv[1]);
- builtin_wperror(L".");
+ builtin_wperror(L"source");
return STATUS_BUILTIN_ERROR;
}
@@ -4110,7 +4123,6 @@ int builtin_parse(parser_t &parser, wchar_t **argv)
*/
static const builtin_data_t builtin_datas[]=
{
- { L".", &builtin_source, N_(L"Evaluate contents of file") },
{ L"[", &builtin_test, N_(L"Test a condition") },
{ L"and", &builtin_generic, N_(L"Execute command if previous command suceeded") },
{ L"begin", &builtin_begin, N_(L"Create a block of code") },
@@ -4151,6 +4163,7 @@ static const builtin_data_t builtin_datas[]=
{ L"return", &builtin_return, N_(L"Stop the currently evaluated function") },
{ L"set", &builtin_set, N_(L"Handle environment variables") },
{ L"set_color", &builtin_set_color, N_(L"Set the terminal color") },
+ { L"source", &builtin_source, N_(L"Evaluate contents of file") },
{ L"status", &builtin_status, N_(L"Return status information about fish") },
{ L"switch", &builtin_switch, N_(L"Conditionally execute a block of commands") },
{ L"test", &builtin_test, N_(L"Test a condition") },