diff options
| author | _ov4 <ov4@ov4.org> | 2026-09-15 12:00:24 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-09-15 12:00:24 +0000 |
| commit | a6b19b1f4ce89c7daa94f47d7927a0954c0c019e (patch) | |
| tree | d09e9b8b73ef5c34e3f5632819a75b720d5e9f05 | |
| parent | 3980d30d28951edcc34d16758d549bc4d4ab193e (diff) | |
add AND/OR support and fix nullptr
| -rw-r--r-- | module-test/return_value.cc | 2 | ||||
| -rw-r--r-- | src/eval.cc | 27 |
2 files changed, 23 insertions, 6 deletions
diff --git a/module-test/return_value.cc b/module-test/return_value.cc index f80172f..b862f6d 100644 --- a/module-test/return_value.cc +++ b/module-test/return_value.cc @@ -1,6 +1,6 @@ /* return specific value - $ g++ module-test/return_value.cc -std=c++23 + $ g++ module-test/return_value.cc -o module-test/return_value.o -std=c++23 */ #include <iostream> diff --git a/src/eval.cc b/src/eval.cc index 9c0210d..0192ab7 100644 --- a/src/eval.cc +++ b/src/eval.cc @@ -44,6 +44,8 @@ int eval_exe(string s, bool is_aync) } parseline(cmdline, argv); + if (argv == nullptr || argv[0] == nullptr) return 0; + if (exe_bultin_command(argv)) return 0; // block_io signals can stop shell @@ -113,12 +115,19 @@ int eval_exe(string s, bool is_aync) sigprocmask(SIG_SETMASK, &prev_with_sigchld_blocked, NULL); waitfg(pid); sigprocmask(SIG_SETMASK, &prev, NULL); + + return exit_code; } else // background { addjob(pid, BG, cmdline); sigprocmask(SIG_SETMASK, &prev, NULL); cout << "[" << pid2jid(pid) << "] (" << pid << ") " << cmdline; + + // POSIX: + // async command returns 0 immediately + // TODO: recurring async + return 0; } @@ -126,23 +135,31 @@ int eval_exe(string s, bool is_aync) return 0; } -void eval_tree_cd(size_t i, const T_lexer &lexer_instance) +int eval_tree_cd(size_t i, const T_lexer &lexer_instance) { // TODO: async + + int ret = -1; + if (lexer_instance.ast[i].token_type == TEXT) { - eval_exe(lexer_instance.ast[i].command_text, false); - return; + ret = eval_exe(lexer_instance.ast[i].command_text, false); + return ret; } + if (lexer_instance.ast[i].left != string::npos) { - eval_tree_cd(lexer_instance.ast[i].left, lexer_instance); + ret = eval_tree_cd(lexer_instance.ast[i].left, lexer_instance); } if (lexer_instance.ast[i].right != string::npos) { - eval_tree_cd(lexer_instance.ast[i].right, lexer_instance); + if (lexer_instance.ast[i].token_type == LOGIC_AND && ret != 0) return ret; + if (lexer_instance.ast[i].token_type == LOGIC_OR && ret == 0) return ret; + + ret = eval_tree_cd(lexer_instance.ast[i].right, lexer_instance); } + return ret; } /* |
