Skip to content

Commit

Permalink
exit init
Browse files Browse the repository at this point in the history
  • Loading branch information
zakissimo committed Dec 30, 2022
1 parent 839360a commit 8174fb5
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 68 deletions.
72 changes: 72 additions & 0 deletions exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/30 11:56:08 by zhabri #+# #+# */
/* Updated: 2022/12/30 12:40:23 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft/includes/libft.h"
#include "minishell.h"

bool str_is_numeric(char *str)
{
int i;

i = 0;
while (str[i])
if (!ft_isdigit(str[i++]))
return (false);
return (true);
}

bool overflows_llong(char *str)
{
bool is_neg;
int len;

is_neg = false;
if (str[0] == '-' || str[0] == '+')
{
if (str[0] == '-')
is_neg = true;
str++;
}
len = ft_strlen(str);
if (len > 19)
return (true);
else if (len < 19)
return (false);
if (!is_neg && ft_strncmp(str, "9223372036854775807", 19) > 0)
return (true);
if (is_neg && ft_strncmp(str, "9223372036854775808", 19) > 0)
return (true);
return (false);
}

bool exit_parent(void)
{
t_cmd *cmd;
char **cmd_split;

if (ft_lstsize(g_glob->cmds) == 1)
{
cmd = ((t_cmd *)(*g_glob->cmds)->content);
cmd_split = ft_split(cmd->str, ' ');
if (!ft_strncmp(cmd_split[0], "exit", 5))
//TODO if cmd_split[1] exists it needs to be:
// 1- numeric
// 2- lower than LLMAX higer than LLMIN
// cmd_split[2] is NULL
// Always print exit in stderr
// Always change g_glob->ret according to the following:
// 1- If the numeric argument is OK change to it
// 2- If its not numeric change to 2 print error and exit
// 3- Change to 1 if too many print error dont exit
}
}
// TODO: IF IN CHILD never exit but change g_glob->ret
37 changes: 37 additions & 0 deletions ft_atoll.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/22 10:25:53 by zhabri #+# #+# */
/* Updated: 2022/12/30 12:35:19 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

long long ft_atoll(const char *nptr)
{
int i;
long long nb;
int neg;

i = 0;
nb = 0;
neg = 1;
if (nptr[i] == '-' || nptr[i] == '+')
{
if (nptr[i] == '-')
neg = -1;
i++;
}
while (ft_isdigit(nptr[i]))
{
nb *= 10;
nb += nptr[i] - '0';
i++;
}
return (nb * neg);
}
5 changes: 3 additions & 2 deletions minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 11:49:37 by zhabri #+# #+# */
/* Updated: 2022/12/29 14:12:32 by zhabri ### ########.fr */
/* Updated: 2022/12/30 12:16:26 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include "libft/includes/libft.h"

t_glob *g_glob;

Expand Down Expand Up @@ -61,7 +62,7 @@ void event_loop(void)
input = readline("minishell> ");
if (input == NULL)
{
printf("exit\n");
ft_putstr_fd("exit\n", 2);
break ;
}
if (*input == '\0')
Expand Down
133 changes: 67 additions & 66 deletions minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/27 20:30:45 by zhabri #+# #+# */
/* Updated: 2022/12/29 14:04:35 by zhabri ### ########.fr */
/* Updated: 2022/12/30 12:36:35 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -75,70 +75,71 @@ typedef struct s_glob

extern t_glob *g_glob;

void handle_sigquit(void);
void handle_sigint(void);
void reset_g_glob(void);
char *get_limiter(t_token *token);
char *name_generator(void);
void init_g_glob(void);
void ignore_sig(int sig);
void final_clean_up(void);
void free_null(void *var);
void init_input(char *str);
char *get_first(void);
bool ft_open_out(t_cmd *node, t_token *token);
bool ft_open_in(t_cmd *node, t_token *token);
void split_cmds(void);
void scan_heredocs(void);
void unlink_heredocs(void);
void add_to_tab(char **tab, char *str);
void free_tab(void *t);
void get_cmd(void);
void free_op_list(void);
void get_args(void);
void get_after_op(void);
int ft_isprint_nospace(int c);
int ft_isprint_nospace_nodollar(int c);
void print_cmds(void);
void clear_cmds(void);
void print_nodes(void *n);
void find_var(t_token *token, char *input);
void free_token_str(void *n);
void print_label(t_label label);
char *remove_quotes(char *str);
int find_quote(const char *s, char c);
char *ft_strjoinf(char *s1, char const *s2);
char *ft_strtrimf(char *s1, char const *set);
void get_ops(const char *input, t_list **head);
int pipe_error(void);
int op_error(void);
void clear_cmd(void *curr);
t_cmd *init_cmd_token(int in, int out, char *str, bool reset);
void lst_dellast(t_list **lst, void (*del)(void *));
char *op_error_trimmed(t_list *curr);
void expand(t_token *var);
t_list **str_tab_to_list(char **tab);
int quote_error(const char *input);
int get_longest_str(char *s1, char *s2);
void insert_node(t_list **head, t_list *node, int idx);
int skip_if_quotes(const char *s, int i);
char **ft_split_quotes(char const *s, char *sep);
void add_cmd(t_token *token, t_list **cmds, bool *pb);
void pipex(void);
void child(t_cmd *cmd, int *pipes, int *children_pid);
void close_pipes(int *pipes);
char **envp_list_to_tab(void);
void clean_exit(int *children_pid);
void print_cmd_not_found(char *str);
void eof_limiter_not_found(char *here_doc_entry, char *limiter);
void init_sig_callbacks(int process);
void exit_on_permission(char **cmd_split, \
int *pipes, int *children_pid);
void exit_on_bad_cmd(char **cmd_split, \
int *pipes, char *cmd, int *children_pid);
void free_tab_bis(void *t);
void get_sum(char *cmd, char **ret, int *pipes);
char *get_path(char *cmd);
void change_sig_handling(char *cmd, int *pipes);
long long ft_atoll(const char *nptr);
void handle_sigquit(void);
void handle_sigint(void);
void reset_g_glob(void);
char *get_limiter(t_token *token);
char *name_generator(void);
void init_g_glob(void);
void ignore_sig(int sig);
void final_clean_up(void);
void free_null(void *var);
void init_input(char *str);
char *get_first(void);
bool ft_open_out(t_cmd *node, t_token *token);
bool ft_open_in(t_cmd *node, t_token *token);
void split_cmds(void);
void scan_heredocs(void);
void unlink_heredocs(void);
void add_to_tab(char **tab, char *str);
void free_tab(void *t);
void get_cmd(void);
void free_op_list(void);
void get_args(void);
void get_after_op(void);
int ft_isprint_nospace(int c);
int ft_isprint_nospace_nodollar(int c);
void print_cmds(void);
void clear_cmds(void);
void print_nodes(void *n);
void find_var(t_token *token, char *input);
void free_token_str(void *n);
void print_label(t_label label);
char *remove_quotes(char *str);
int find_quote(const char *s, char c);
char *ft_strjoinf(char *s1, char const *s2);
char *ft_strtrimf(char *s1, char const *set);
void get_ops(const char *input, t_list **head);
int pipe_error(void);
int op_error(void);
void clear_cmd(void *curr);
t_cmd *init_cmd_token(int in, int out, char *str, bool reset);
void lst_dellast(t_list **lst, void (*del)(void *));
char *op_error_trimmed(t_list *curr);
void expand(t_token *var);
t_list **str_tab_to_list(char **tab);
int quote_error(const char *input);
int get_longest_str(char *s1, char *s2);
void insert_node(t_list **head, t_list *node, int idx);
int skip_if_quotes(const char *s, int i);
char **ft_split_quotes(char const *s, char *sep);
void add_cmd(t_token *token, t_list **cmds, bool *pb);
void pipex(void);
void child(t_cmd *cmd, int *pipes, int *children_pid);
void close_pipes(int *pipes);
char **envp_list_to_tab(void);
void clean_exit(int *children_pid);
void print_cmd_not_found(char *str);
void eof_limiter_not_found(char *here_doc_entry, char *limiter);
void init_sig_callbacks(int process);
void exit_on_permission(char **cmd_split, \
int *pipes, int *children_pid);
void exit_on_bad_cmd(char **cmd_split, \
int *pipes, char *cmd, int *children_pid);
void free_tab_bis(void *t);
void get_sum(char *cmd, char **ret, int *pipes);
char *get_path(char *cmd);
void change_sig_handling(char *cmd, int *pipes);

#endif

0 comments on commit 8174fb5

Please sign in to comment.