This commit is contained in:
savalet
2025-05-09 17:07:43 +02:00
parent 319435e8ba
commit 54ebb04ac7
4 changed files with 10 additions and 6 deletions

View File

@@ -24,7 +24,7 @@
- [x] `||`/`&&`
- [x] script with shebangs
- [x] `-c` eval argument
- [ ] `-e` exit on failure
- [x] `-e` exit on failure
- [x] `-h` help (open man?)
- [x] globbing
- [x] var interpreter

View File

@@ -21,5 +21,6 @@ typedef struct {
uint8_t flags;
char *script_file;
char *cmd;
bool exit_failure;
} opt_t;
#endif /* COMMON_H */

View File

@@ -14,7 +14,7 @@
#include "debug.h"
#include "shell.h"
const char OPT_FLAGS[] = "hc:";
const char OPT_FLAGS[] = "hec:";
static
void print_usages(FILE *file, char *bin)
@@ -34,6 +34,9 @@ bool parse_args(opt_t *opt, int ac, char **av)
case 'c':
opt->cmd = strdup(optarg);
break;
case 'e':
opt->exit_failure = true;
break;
default:
return print_usages(stderr, av[0]), false;
}
@@ -41,15 +44,14 @@ bool parse_args(opt_t *opt, int ac, char **av)
if (optind < ac) {
opt->script_file = av[optind];
U_DEBUG("Script file [%s]\n", opt->script_file);
} else {
U_DEBUG_MSG("No script file provided.\n");
}
return true;
}
int main(int ac, char **av, char **env)
{
opt_t opt = { 0, .script_file = nullptr, .cmd = nullptr };
opt_t opt = { 0, .script_file = nullptr, .cmd = nullptr,
.exit_failure = false };
int result;
U_DEBUG_MSG("Debug mode altivated.\n");

View File

@@ -61,7 +61,6 @@ bool change_shell_command(buff_t *buff, exec_ctx_t *exec_ctx)
buff->sz = 0;
if (!readline(exec_ctx, buff))
return false;
U_DEBUG("BUFF SZ [%lu]\n", buff->sz);
if (!buff->sz)
return false;
tmp_buff = buff->str;
@@ -93,6 +92,8 @@ int shell_loop(int is_a_tty, exec_ctx_t *exec_ctx)
write_prompt(is_a_tty, exec_ctx);
if (!change_shell_command(&buff, exec_ctx))
return free(buff.str), exec_ctx->history->last_exit_code;
if (exec_ctx->opt->exit_failure && exec_ctx->history->last_exit_code)
return free(buff.str), exec_ctx->history->last_exit_code;
}
return free(buff.str), exec_ctx->history->last_exit_code;
}