aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser.cpp
diff options
context:
space:
mode:
authorGravatar Cheer Xiao <xiaqqaix@gmail.com>2013-01-15 16:18:03 +0800
committerGravatar Cheer Xiao <xiaqqaix@gmail.com>2013-01-17 15:55:05 +0800
commit4b6bd7cae5e731f8e2bafeabca59e5aaabd6749d (patch)
treefa8330fdeb42b37584c42fcdbf7f3c54c6d6ee2b /parser.cpp
parent6f35792c74612f4b754125a5cfe9c96baa7854b9 (diff)
Split out io_file_t
Diffstat (limited to 'parser.cpp')
-rw-r--r--parser.cpp81
1 files changed, 37 insertions, 44 deletions
diff --git a/parser.cpp b/parser.cpp
index 1329cea6..f2ed3f2d 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -1568,67 +1568,60 @@ void parser_t::parse_job_argument_list(process_t *p,
_(L"Invalid IO redirection"));
tok_next(tok);
}
- else
+ else if (type == TOK_REDIRECT_FD)
{
+ if (target == L"-")
+ {
+ new_io.reset(new io_close_t(fd));
+ }
+ else
+ {
+ wchar_t *end;
+
+ errno = 0;
+
+ int old_fd = fish_wcstoi(target.c_str(), &end, 10);
+
+ if (old_fd < 0 || errno || *end)
+ {
+ error(SYNTAX_ERROR,
+ tok_get_pos(tok),
+ _(L"Requested redirection to something that is not a file descriptor %ls"),
+ target.c_str());
+ tok_next(tok);
+ }
+ else
+ {
+ new_io.reset(new io_fd_t(fd, old_fd));
+ }
+ }
+ }
+ else
+ {
+ int flags = 0;
switch (type)
{
case TOK_REDIRECT_APPEND:
- new_io.reset(new io_data_t(IO_FILE, fd));
- new_io->param2.flags = O_CREAT | O_APPEND | O_WRONLY;
- new_io->set_filename(target);
+ flags = O_CREAT | O_APPEND | O_WRONLY;
break;
case TOK_REDIRECT_OUT:
- new_io.reset(new io_data_t(IO_FILE, fd));
- new_io->param2.flags = O_CREAT | O_WRONLY | O_TRUNC;
- new_io->set_filename(target);
+ flags = O_CREAT | O_WRONLY | O_TRUNC;
break;
case TOK_REDIRECT_NOCLOB:
- new_io.reset(new io_data_t(IO_FILE, fd));
- new_io->param2.flags = O_CREAT | O_EXCL | O_WRONLY;
- new_io->set_filename(target);
+ flags = O_CREAT | O_EXCL | O_WRONLY;
break;
case TOK_REDIRECT_IN:
- new_io.reset(new io_data_t(IO_FILE, fd));
- new_io->param2.flags = O_RDONLY;
- new_io->set_filename(target);
+ flags = O_RDONLY;
break;
- case TOK_REDIRECT_FD:
- {
- if (target == L"-")
- {
- new_io.reset(new io_close_t(fd));
- }
- else
- {
- wchar_t *end;
-
- errno = 0;
-
- int old_fd = fish_wcstoi(target.c_str(), &end, 10);
-
- if (old_fd < 0 || errno || *end)
- {
- error(SYNTAX_ERROR,
- tok_get_pos(tok),
- _(L"Requested redirection to something that is not a file descriptor %ls"),
- target.c_str());
-
- tok_next(tok);
- }
- else
- {
- new_io.reset(new io_fd_t(fd, old_fd));
- }
- }
- break;
- }
}
-
+ io_file_t *new_io_file = new io_file_t(fd, NULL, flags);
+ new_io_file->set_filename(target);
+ new_io.reset(new_io_file);
}
}