use an enumeration to be easy to read
This commit is contained in:
parent
b2327ff334
commit
5070706b3d
17
src/loop.c
17
src/loop.c
@ -66,41 +66,42 @@ void loop() {
|
|||||||
|
|
||||||
StringArray *args = create_string_array();
|
StringArray *args = create_string_array();
|
||||||
|
|
||||||
int get_file_name = 0;
|
enum FileType {FileType_none, FileType_stdout, FileType_stderr};
|
||||||
|
enum FileType get_file_name = FileType_none;
|
||||||
Redirect out = {.fd = 1, .fd_new = -1, .fd_copy = -1, .filename = NULL, .append = false};
|
Redirect out = {.fd = 1, .fd_new = -1, .fd_copy = -1, .filename = NULL, .append = false};
|
||||||
Redirect err = {.fd = 2, .fd_new = -1, .fd_copy = -1, .filename = NULL, .append = false};
|
Redirect err = {.fd = 2, .fd_new = -1, .fd_copy = -1, .filename = NULL, .append = false};
|
||||||
|
|
||||||
char *saveptr = NULL;
|
char *saveptr = NULL;
|
||||||
char *token = strtok_r(line, " ", &saveptr);
|
char *token = strtok_r(line, " ", &saveptr);
|
||||||
while (token) {
|
while (token) {
|
||||||
if (get_file_name == 1) {
|
if (get_file_name == FileType_stdout) {
|
||||||
// get file name for stdout redirect
|
// get file name for stdout redirect
|
||||||
set_filename(&out, token);
|
set_filename(&out, token);
|
||||||
get_file_name = 0;
|
get_file_name = FileType_none;
|
||||||
}
|
}
|
||||||
else if (get_file_name == 2) {
|
else if (get_file_name == 2) {
|
||||||
// get file name for stderr redirect
|
// get file name for stderr redirect
|
||||||
set_filename(&err, token);
|
set_filename(&err, token);
|
||||||
get_file_name = 0;
|
get_file_name = FileType_none;
|
||||||
}
|
}
|
||||||
else if (strcmp(token, ">") == 0 || strcmp(token, "1>") == 0) {
|
else if (strcmp(token, ">") == 0 || strcmp(token, "1>") == 0) {
|
||||||
// redirect stdout and overwrite
|
// redirect stdout and overwrite
|
||||||
get_file_name = 1;
|
get_file_name = FileType_stdout;
|
||||||
out.append = false;
|
out.append = false;
|
||||||
}
|
}
|
||||||
else if (strcmp(token, ">>") == 0 || strcmp(token, "1>>") == 0) {
|
else if (strcmp(token, ">>") == 0 || strcmp(token, "1>>") == 0) {
|
||||||
// redirect stdout and append
|
// redirect stdout and append
|
||||||
get_file_name = 1;
|
get_file_name = FileType_stdout;
|
||||||
out.append = true;
|
out.append = true;
|
||||||
}
|
}
|
||||||
else if (strcmp(token, "2>") == 0) {
|
else if (strcmp(token, "2>") == 0) {
|
||||||
// redirect stdout and overwrite
|
// redirect stdout and overwrite
|
||||||
get_file_name = 2;
|
get_file_name = FileType_stderr;
|
||||||
err.append = false;
|
err.append = false;
|
||||||
}
|
}
|
||||||
else if (strcmp(token, "2>>") == 0) {
|
else if (strcmp(token, "2>>") == 0) {
|
||||||
// redirect stdout and append
|
// redirect stdout and append
|
||||||
get_file_name = 2;
|
get_file_name = FileType_stderr;
|
||||||
err.append = true;
|
err.append = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user