Skip to content

Commit

Permalink
Merge branch 'release-1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
acuD1 committed Jul 1, 2020
2 parents 6ee44e9 + 911ffc4 commit 460b7c3
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 125 deletions.
4 changes: 2 additions & 2 deletions .build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Build information, patch level is incremented at compilation.

RELEASE = 1
VERSION = 0
PATCH = 15
VERSION = 1
PATCH = 0
4 changes: 3 additions & 1 deletion includes/command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: user42 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/08/04 14:09:42 by fcatusse #+# #+# */
/* Updated: 2020/05/19 15:50:17 by fcatusse ### ########.fr */
/* Updated: 2020/05/24 16:57:25 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -74,6 +74,8 @@ int64_t last_cmd_back(t_read *term, ssize_t i);
char *get_home_value(t_core *shell);
void goto_reverse(t_read *term, const char *buff_tmp);
void walking_history(const char *buff, t_read *term, t_lst **history);
ssize_t get_history_value(char *var);
ssize_t check_exp_error(t_lst *w, ssize_t n);

/*
** SUBPROMPT/MULTILINE
Expand Down
2 changes: 1 addition & 1 deletion includes/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*/

# define CREDIT "arsciand, fcatusse, mpivet-p and guvillat\n"
# define PS1 "'42sh-1.0$ '"
# define PS1 "'42sh-1.1$ '"
# define PS2 "'> '"
# define BUFF_SIZE 4096
# define READ_SIZE 8
Expand Down
3 changes: 2 additions & 1 deletion includes/sh42.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ int8_t write_heredoc(t_redir *ptr);
** ===========================================================================
*/

void sigint_special_handler(void);
void sigint_handler(int sig_num);
void init_signals(void);
void sigint_special_handler(void);
void send_hup(t_core *shell);

/*
** ===========================================================================
Expand Down
2 changes: 1 addition & 1 deletion shared_libft
2 changes: 1 addition & 1 deletion srcs/builtins/fc/fc_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: arsciand <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/27 15:06:02 by fcatusse #+# #+# */
/* Updated: 2020/05/21 09:28:39 by fcatusse ### ########.fr */
/* Updated: 2020/05/30 18:57:14 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
4 changes: 2 additions & 2 deletions srcs/builtins/fc/fc_specifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: user42 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/05 19:05:56 by fcatusse #+# #+# */
/* Updated: 2020/05/21 09:07:56 by fcatusse ### ########.fr */
/* Updated: 2020/05/30 18:57:31 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -128,6 +128,6 @@ int8_t select_specifier(t_core *shell, char **av)
while (replace_pattern(shell, pat, rep) == SUCCESS)
;
ft_strdel(&pat);
print_and_exec(shell, STDIN_FILENO);
print_and_exec(shell, STDERR_FILENO);
return (SUCCESS);
}
14 changes: 10 additions & 4 deletions srcs/builtins/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "sh42.h"
#include <unistd.h>

static void print_longjob(t_job *job)
static void print_longjob(t_job *job)
{
static char running[] = "Running\n";
t_process *process;
Expand All @@ -38,7 +38,7 @@ static void print_longjob(t_job *job)
}
}

static void print_job(t_job *job, u_int64_t opt, const char *name)
static void print_job(t_job *job, u_int64_t opt, const char *name)
{
if (!job)
{
Expand All @@ -59,7 +59,13 @@ static void print_job(t_job *job, u_int64_t opt, const char *name)
, get_last_stop_status(job), job->command);
}

int8_t builtin_jobs(t_core *shell, t_process *process)
static int8_t jobs_invalid_opt(u_int64_t opt)
{
print_usage("42sh: jobs", opt & 0xFF, "jobs [-lp] [jobspec ...]");
return (2);
}

int8_t builtin_jobs(t_core *shell, t_process *process)
{
t_lst *job_list;
t_job *job;
Expand All @@ -73,7 +79,7 @@ int8_t builtin_jobs(t_core *shell, t_process *process)
if (shell->launched_jobs)
update_status(shell);
if ((opt = ft_get_options((int)argc, process->av, "lp")) & (1ULL << 63))
print_usage("42sh: jobs", opt & 0xFF, "jobs [-lp] [jobspec ...]");
return(jobs_invalid_opt(opt));
while (i == argc && job_list)
{
print_job(job_list->content, opt, NULL);
Expand Down
92 changes: 37 additions & 55 deletions srcs/builtins/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,43 @@
/* By: arsciand <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/20 17:50:06 by mpivet-p #+# #+# */
/* Updated: 2020/05/23 19:40:01 by arsciand ### ########.fr */
/* Updated: 2020/05/28 15:51:53 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

#include "sh42.h"
#include <unistd.h>

static int32_t get_opt_test(size_t argc, char **argv, int8_t diff)
static int32_t get_opt_test(char *str)
{
static char *op[NB_TESTBLT] = {"-b", "-c", "-d", "-e", "-f", "-g", "-L"
, "-p", "-r", "-S", "-s", "-u", "-w", "-x", "-z", "=", "!=", "-eq"
, "-ne", "-ge", "-lt", "-le"};
size_t i;

i = 0;
if (argc > 2 + (size_t)diff && argv[2 + (size_t)diff])
while (i < NB_TESTBLT)
{
while (i < NB_TESTBLT)
{
if (ft_strcmp(op[i], argv[((i <= Z_UNATEST) ? 1 : 2) + diff]) == 0)
return ((int32_t)i);
i++;
}
if (ft_strcmp(op[i], str) == 0)
return ((int32_t)i);
i++;
}
return (FAILURE);
}

static void parse_testblt_handler
(char **argv, int8_t diff, int64_t num, u_int8_t status)
{
num = atol(argv[1] + diff);
if (status ^ TEST_INT_EXP)
if (status == TEST_INT_EXP)
ft_dprintf(2, "42sh: test: %s: integer expression expected\n"
, num != SUCCESS
, (ft_atol(argv[1 + diff], &num) != SUCCESS)
? argv[1 + diff] : argv[3 + diff]);
else if (status ^ TEST_ARG)
else if (status == TEST_ARG)
ft_dprintf(STDERR_FILENO, "42sh: test: too many arguments\n");
else if (status ^ TEST_BIN)
else if (status == TEST_BIN)
ft_dprintf(STDERR_FILENO, "42sh: test: %s: %s operator expected\n"
, argv[1 + diff], "binary");
else if (status ^ TEST_UNA)
else if (status == TEST_UNA)
ft_dprintf(STDERR_FILENO, "42sh: test: %s: %s operator expected\n"
, argv[1 + diff], "unary");
}
Expand All @@ -57,28 +53,26 @@ static int8_t parse_testblt
int64_t num;

num = 0;
if ((*opt = get_opt_test(argc, argv, diff)) > DIFF_BINTEST
&& ((argc > 2 + (size_t)diff && (num = atol(argv[1 + diff])) != SUCCESS)
|| (argc > 3 + (size_t)diff
&& ft_atol(argv[3 + diff], &num) != SUCCESS)))
{
parse_testblt_handler(argv, diff, num, TEST_INT_EXP);
return (FAILURE);
}
if ((argc > 4 + (size_t)diff && *opt > Z_UNATEST)
|| (argc > 3 + (size_t)diff && *opt <= Z_UNATEST && *opt >= 0))
{
if ((int)argc > 4 + diff)
parse_testblt_handler(argv, diff, num, TEST_ARG);
return (FAILURE);
}
if (*opt < 0 || (*opt > Z_UNATEST && argc < 4 + (size_t)diff)
|| (*opt <= Z_UNATEST && *opt >= 0 && argc > 3 + (size_t)diff))
else if ((int)argc == 4 + diff)
{
parse_testblt_handler(argv, diff, num,
(*opt <= Z_UNATEST) ? TEST_BIN : TEST_UNA);
return (FAILURE);
if ((*opt = get_opt_test(argv[2 + diff])) == FAILURE
|| *opt <= Z_UNATEST)
parse_testblt_handler(argv, diff, num, TEST_BIN);
else if (*opt >= EQ_BINTEST && *opt <= LE_BINTEST
&& (ft_atol(argv[1 + diff], &num) != SUCCESS
|| ft_atol(argv[3 + diff], &num) != SUCCESS))
parse_testblt_handler(argv, diff, num, TEST_INT_EXP);
else
return (SUCCESS);
}
return (SUCCESS);
else if ((int)argc == 3 + diff
&& (*opt = get_opt_test(argv[1 + diff])) == FAILURE)
parse_testblt_handler(argv, diff, num, TEST_UNA);
else
return (SUCCESS);
return (FAILURE);
}

static int8_t comp_tests(const char *s1, const char *s2, int32_t opt)
Expand All @@ -91,11 +85,10 @@ static int8_t comp_tests(const char *s1, const char *s2, int32_t opt)
return (((ft_strcmp(s1, s2) == 0)
? 1 : 0) ^ (int8_t)(DIFF_BINTEST - opt));
}
ft_dprintf(STDERR_FILENO, "s1 = |%s| , s2 = |%s|\n", s1, s2);
n1 = atol(s1);
ft_dprintf(STDERR_FILENO, "?\n");
n2 = atol(s2);
ft_dprintf(STDERR_FILENO, "?\n");
if (!s1 || !s2)
return (1);
ft_atol(s1, &n1);
ft_atol(s2, &n2);
if (opt == EQ_BINTEST || opt == NE_BINTEST)
return ((n1 == n2) ^ (int8_t)(NE_BINTEST - opt));
if (opt == GE_BINTEST || opt == LT_BINTEST)
Expand All @@ -109,32 +102,21 @@ int8_t builtin_test(t_core *shell, t_process *process)
{
int32_t opt;
size_t argc;
int diff;
int8_t diff;

(void)shell;
argc = ft_tablen(process->av);
diff = (argc > 1 && process->av[1]
&& ft_strcmp(process->av[1], "!") == 0) ? 1 : 0;
ft_dprintf(STDERR_FILENO, "DIFF= |%d|\n", diff);
&& ft_strcmp(process->av[1], "!") == 0) ? 1 : 0;
if (argc < 3 + (size_t)diff)
{
return (((argc < 2 + (size_t)diff
|| process->av[1 + diff][0] == 0) ? 1 : 0) ^ diff);
}
parse_testblt(argc, process->av, diff, &opt);
if (parse_testblt(argc, process->av, diff, &opt) == FAILURE)
return (2);
if (opt <= Z_UNATEST && opt != FAILURE)
return (path_tests(process->av[2 + diff], opt) ^ diff);
if (opt != FAILURE)
{
if (!process->av[3 + diff])
{
ft_dprintf(STDERR_FILENO,
"BREF REVOIR LE PARSING ERREUR ET AJOUTER LA PROTECTION\n42sh: test: %s: unary operator expected\n", process->av[1 + diff]);
return (0);
}
ft_dprintf(STDERR_FILENO, "s2?????? = |%s|\n", process->av[3 + diff]);
return (comp_tests(process->av[1 + diff]
return (comp_tests(process->av[1 + diff]
, process->av[3 + diff], opt) ^ diff);
}
return (2);
}
2 changes: 1 addition & 1 deletion srcs/cmdline/action_keys/move_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: user42 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 14:36:52 by fcatusse #+# #+# */
/* Updated: 2020/05/21 13:35:17 by fcatusse ### ########.fr */
/* Updated: 2020/05/28 08:47:29 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion srcs/cmdline/action_keys/tab_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: fcatusse <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/05 12:40:04 by fcatusse #+# #+# */
/* Updated: 2020/05/14 16:36:07 by fcatusse ### ########.fr */
/* Updated: 2020/05/28 15:24:46 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
16 changes: 10 additions & 6 deletions srcs/cmdline/auto_c/ac_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: user42 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/01 17:26:51 by fcatusse #+# #+# */
/* Updated: 2020/05/12 11:14:13 by fcatusse ### ########.fr */
/* Updated: 2020/05/30 18:10:13 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,8 +16,8 @@

static void add_builtin_lst(t_auto_comp *ac, const char *cmd)
{
static char *blt_names[14] = {"set", "unset", "export", "exit", "cd"
, "echo", "pwd", "type", "fg", "jobs", "bg", "hash", "fc", "test"};
static char *blt_names[14] = {"set ", "unset ", "export ", "exit ", "cd "
, "echo ", "pwd ", "type ", "fg ", "jobs ", "bg ", "hash ", "fc ", "test "};
size_t i;

i = 0;
Expand All @@ -37,10 +37,12 @@ static void add_builtin_lst(t_auto_comp *ac, const char *cmd)
static void fill_bin_lst(char *input, t_auto_comp *ac, char **path)
{
struct dirent *data;
char *tmp;
DIR *dir;
ssize_t i;

i = -1;
tmp = NULL;
while (path[++i] && is_dir(path[i]))
{
dir = opendir(path[i]);
Expand All @@ -49,10 +51,12 @@ static void fill_bin_lst(char *input, t_auto_comp *ac, char **path)
if ((!*input || ft_isstart(data->d_name, input))
&& is_a_blt(data->d_name) == -1 && !ft_isstart(data->d_name, "."))
{
ft_lstappend(&ac->lst, ft_lstnew(data->d_name,
sizeof(char) * (ft_strlen(data->d_name) + 1)));
tmp = ft_strjoin(data->d_name, " ");
ft_lstappend(&ac->lst, ft_lstnew(tmp,
sizeof(char) * (ft_strlen(tmp) + 1)));
ac->lst_size++;
ac->max_len = get_max_len(ac->max_len, ft_strlen(data->d_name));
ac->max_len = get_max_len(ac->max_len, ft_strlen(tmp));
ft_strdel(&tmp);
}
}
closedir(dir);
Expand Down
2 changes: 1 addition & 1 deletion srcs/cmdline/auto_c/ac_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: fcatusse <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/05 16:32:18 by fcatusse #+# #+# */
/* Updated: 2020/05/12 17:37:38 by fcatusse ### ########.fr */
/* Updated: 2020/05/28 08:19:12 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
11 changes: 10 additions & 1 deletion srcs/cmdline/auto_c/ac_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: arsciand <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/10 15:13:52 by fcatusse #+# #+# */
/* Updated: 2020/05/14 17:11:05 by fcatusse ### ########.fr */
/* Updated: 2020/05/29 11:46:32 by fcatusse ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,7 +19,16 @@ u_int8_t last_is_slash(char *str)

i = ft_strlen(str);
if (str[i - 1] != '/')
{
if (str[i - 1] == '.')
{
if (i >= 2 && str[i - 2] == '.')
return (FALSE);
else
return (TRUE);
}
return (FALSE);
}
return (TRUE);
}

Expand Down
Loading

0 comments on commit 460b7c3

Please sign in to comment.