mirror of
https://github.com/Savapitech/42sh.git
synced 2026-03-18 21:50:35 +01:00
Add -e
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -21,5 +21,6 @@ typedef struct {
|
||||
uint8_t flags;
|
||||
char *script_file;
|
||||
char *cmd;
|
||||
bool exit_failure;
|
||||
} opt_t;
|
||||
#endif /* COMMON_H */
|
||||
|
||||
10
src/main.c
10
src/main.c
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user