some norme, builtin_read refactoring
This commit is contained in:
parent
29f0b5835f
commit
85fbbe3d8a
16 changed files with 149 additions and 222 deletions
|
|
@ -30,7 +30,6 @@ OBJ_DIR = objs/
|
||||||
|
|
||||||
SRC_BASE = \
|
SRC_BASE = \
|
||||||
builtin/bt_read_get.c\
|
builtin/bt_read_get.c\
|
||||||
builtin/bt_read_parse.c\
|
|
||||||
builtin/bt_read_term.c\
|
builtin/bt_read_term.c\
|
||||||
builtin/builtin_cd.c\
|
builtin/builtin_cd.c\
|
||||||
builtin/builtin_echo.c\
|
builtin/builtin_echo.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 00:48:28 by ariard ### ########.fr */
|
/* Updated: 2017/03/15 18:44:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,8 +26,10 @@ int builtin_env(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_echo(const char *path, char *const argv[], char *const envp[]);
|
int builtin_echo(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_cd(const char *path, char *const argv[], char *const envp[]);
|
int builtin_cd(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_exit(const char *path, char *const argv[], char *const envp[]);
|
int builtin_exit(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_setenv(const char *path, char *const argv[], char *const envp[]);
|
int builtin_setenv(
|
||||||
int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]);
|
const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int builtin_unsetenv(
|
||||||
|
const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_jobs(const char *path, char *const av[], char *const envp[]);
|
int builtin_jobs(const char *path, char *const av[], char *const envp[]);
|
||||||
int builtin_fg(const char *path, char *const av[], char *const envp[]);
|
int builtin_fg(const char *path, char *const av[], char *const envp[]);
|
||||||
int builtin_bg(const char *path, char *const av[], char *const envp[]);
|
int builtin_bg(const char *path, char *const av[], char *const envp[]);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 19:57:25 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 19:13:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -44,15 +44,6 @@ struct s_read
|
||||||
char *input;
|
char *input;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_readopt
|
|
||||||
{
|
|
||||||
char letter;
|
|
||||||
t_flag flag;
|
|
||||||
int (*get)(t_read *data, char *arg);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern t_readopt g_readtab[];
|
|
||||||
|
|
||||||
int builtin_read(const char *path, char *const av[], char *const envp[]);
|
int builtin_read(const char *path, char *const av[], char *const envp[]);
|
||||||
|
|
||||||
int bt_read_init(t_read *data, char **av);
|
int bt_read_init(t_read *data, char **av);
|
||||||
|
|
@ -61,10 +52,10 @@ struct termios bt_read_term(int init);
|
||||||
int bt_read_terminit(t_read *data);
|
int bt_read_terminit(t_read *data);
|
||||||
int bt_read_exit(t_read *data);
|
int bt_read_exit(t_read *data);
|
||||||
|
|
||||||
int bt_read_getdelim(t_read *data, char *arg);
|
int bt_read_getdelim(char ***argv, t_read *data);
|
||||||
int bt_read_getnchars(t_read *data, char *arg);
|
int bt_read_getnchars(char ***argv, t_read *data);
|
||||||
int bt_read_getprompt(t_read *data, char *arg);
|
int bt_read_getprompt(char ***argv, t_read *data);
|
||||||
int bt_read_gettimeout(t_read *data, char *arg);
|
int bt_read_gettimeout(char ***argv, t_read *data);
|
||||||
int bt_read_getfd(t_read *data, char *arg);
|
int bt_read_getfd(char ***argv, t_read *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 13:47:27 by gwojda ### ########.fr */
|
/* Updated: 2017/03/15 18:46:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -120,7 +120,8 @@ int completion(long int key);
|
||||||
void c_init(t_data *s, long int input);
|
void c_init(t_data *s, long int input);
|
||||||
int c_matching(t_data *s, t_comp *c);
|
int c_matching(t_data *s, t_comp *c);
|
||||||
int c_seek_binary(t_data *s, t_comp *c);
|
int c_seek_binary(t_data *s, t_comp *c);
|
||||||
int c_seek_files(t_data *s, t_comp *c, char *current_word);
|
int c_seek_files(
|
||||||
|
t_data *s, t_comp *c, char *current_word);
|
||||||
int c_parser(t_comp *c, char *path, char *name);
|
int c_parser(t_comp *c, char *path, char *name);
|
||||||
int c_sizing(t_comp *c);
|
int c_sizing(t_comp *c);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 16:35:30 by gwojda ### ########.fr */
|
/* Updated: 2017/03/15 19:13:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef EXEC_H
|
#ifndef EXEC_H
|
||||||
# define EXEC_H
|
# define EXEC_H
|
||||||
|
|
||||||
|
# include "types.h"
|
||||||
|
# include "job_control.h"
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
/* # include "types.h" */
|
|
||||||
/* # include "minishell.h" */
|
|
||||||
|
|
||||||
# define PIPE_READ 0
|
# define PIPE_READ 0
|
||||||
# define PIPE_WRITE 1
|
# define PIPE_WRITE 1
|
||||||
|
|
@ -31,7 +31,6 @@
|
||||||
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
||||||
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
||||||
|
|
||||||
/* # define EXEC_BG (1 << 1) */
|
|
||||||
# define EXEC_AND_IF (1 << 2)
|
# define EXEC_AND_IF (1 << 2)
|
||||||
# define EXEC_OR_IF (1 << 3)
|
# define EXEC_OR_IF (1 << 3)
|
||||||
# define EXEC_IF_BRANCH (1 << 4)
|
# define EXEC_IF_BRANCH (1 << 4)
|
||||||
|
|
@ -122,6 +121,15 @@ struct s_process
|
||||||
t_flag attrs;
|
t_flag attrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct s_job
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
pid_t pgid;
|
||||||
|
t_flag attrs;
|
||||||
|
t_list *first_process;
|
||||||
|
struct termios tmodes;
|
||||||
|
};
|
||||||
|
|
||||||
struct s_exec
|
struct s_exec
|
||||||
{
|
{
|
||||||
t_job job;
|
t_job job;
|
||||||
|
|
@ -161,8 +169,6 @@ void redir_free(void *data, size_t content_size);
|
||||||
|
|
||||||
char **token_to_argv(t_ld *ld, int do_match);
|
char **token_to_argv(t_ld *ld, int do_match);
|
||||||
|
|
||||||
/* int add_new_job(t_job *job); */
|
|
||||||
|
|
||||||
int error_badidentifier(char *name);
|
int error_badidentifier(char *name);
|
||||||
t_btree *is_function(t_process *p);
|
t_btree *is_function(t_process *p);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */
|
/* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */
|
||||||
/* Updated: 2017/01/19 21:53:40 by ariard ### ########.fr */
|
/* Updated: 2017/03/15 18:47:56 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
typedef struct s_curs t_curs;
|
typedef struct s_curs t_curs;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cursor data : cursor's coordonate and windows size
|
** Cursor data : cursor's coordonate and windows size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct s_curs
|
struct s_curs
|
||||||
|
|
@ -36,13 +36,13 @@ struct s_curs
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cursor reference singleton
|
** Cursor reference singleton
|
||||||
*/
|
*/
|
||||||
|
|
||||||
t_curs *curs_single(t_curs *curs, int set);
|
t_curs *curs_single(t_curs *curs, int set);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cursor setup
|
** Cursor setup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int curs_li_ask(void);
|
int curs_li_ask(void);
|
||||||
|
|
@ -54,20 +54,20 @@ int curs_coo_setup(t_curs *curs);
|
||||||
int curs_setup(t_curs *curs);
|
int curs_setup(t_curs *curs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cursor cleanup
|
** Cursor cleanup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int curs_term_cleanup(void);
|
int curs_term_cleanup(void);
|
||||||
int curs_cleanup(t_curs *curs);
|
int curs_cleanup(t_curs *curs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cursor's data reset
|
** Cursor's data reset
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void curs_reset(int sig);
|
void curs_reset(int sig);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cursor manipulation function
|
** Cursor manipulation function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void curs_clear(t_curs *curs);
|
void curs_clear(t_curs *curs);
|
||||||
|
|
@ -78,6 +78,7 @@ void curs_backward(t_curs *curs, int offset);
|
||||||
void curs_write(t_curs *curs, char *str, size_t len);
|
void curs_write(t_curs *curs, char *str, size_t len);
|
||||||
void curs_write_static(t_curs *curs, char *str, size_t len);
|
void curs_write_static(t_curs *curs, char *str, size_t len);
|
||||||
void curs_video_write(t_curs *curs, char *str, size_t len);
|
void curs_video_write(t_curs *curs, char *str, size_t len);
|
||||||
void curs_video_write_static(t_curs *curs, char *str, size_t len);
|
void curs_video_write_static(
|
||||||
|
t_curs *curs, char *str, size_t len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */
|
/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */
|
||||||
/* Updated: 2017/02/03 15:18:27 by ariard ### ########.fr */
|
/* Updated: 2017/03/15 18:51:31 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,34 +19,34 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# ifdef LINUX
|
# ifdef LINUX
|
||||||
# define RL_INSERT_CODE 0x7e325b1b /* Insert */
|
# define RL_INSERT_CODE 0x7e325b1b
|
||||||
# define RL_CLEAR_CODE 0xc /* Ctrl+L */
|
# define RL_CLEAR_CODE 0xc
|
||||||
# define RL_NL_CODE 0xa /* Enter */
|
# define RL_NL_CODE 0xa
|
||||||
# define RL_COMP_CODE 0x9 /* Tab */
|
# define RL_COMP_CODE 0x9
|
||||||
# define RL_LEFT_CODE 0x445b1b /* Left */
|
# define RL_LEFT_CODE 0x445b1b
|
||||||
# define RL_RIGHT_CODE 0x435b1b /* Right */
|
# define RL_RIGHT_CODE 0x435b1b
|
||||||
# define RL_WLEFT_CODE 0x44323b315b1b /* Maj+Left */
|
# define RL_WLEFT_CODE 0x44323b315b1b
|
||||||
# define RL_WRIGHT_CODE 0x43323b315b1b /* Maj+Right */
|
# define RL_WRIGHT_CODE 0x43323b315b1b
|
||||||
# define RL_HOME_CODE 0x485b1b /* Home */
|
# define RL_HOME_CODE 0x485b1b
|
||||||
# define RL_END_CODE 0x465b1b /* End */
|
# define RL_END_CODE 0x465b1b
|
||||||
# define RL_PAGEUP_CODE 0x7e355b1b /* PageUp */
|
# define RL_PAGEUP_CODE 0x7e355b1b
|
||||||
# define RL_PAGEDOWN_CODE 0x7e365b1b /* PageDown */
|
# define RL_PAGEDOWN_CODE 0x7e365b1b
|
||||||
# define RL_SELECT_RIGHT_CODE 0x43333b315b1b /* Alt+Right */
|
# define RL_SELECT_RIGHT_CODE 0x43333b315b1b
|
||||||
# define RL_SELECT_LEFT_CODE 0x44333b315b1b /* Alt+Left */
|
# define RL_SELECT_LEFT_CODE 0x44333b315b1b
|
||||||
# define RL_SELECT_PAGEUP_CODE 0x7e333b355b1b /* Alt+PageUp */
|
# define RL_SELECT_PAGEUP_CODE 0x7e333b355b1b
|
||||||
# define RL_SELECT_PAGEDOWN_CODE 0x7e333b365b1b /* Alt+PageDown */
|
# define RL_SELECT_PAGEDOWN_CODE 0x7e333b365b1b
|
||||||
# define RL_SELECT_HOME_CODE 0x48333b315b1b /* Alt+Home */
|
# define RL_SELECT_HOME_CODE 0x48333b315b1b
|
||||||
# define RL_SELECT_END_CODE 0x46333b315b1b /* Alt+End */
|
# define RL_SELECT_END_CODE 0x46333b315b1b
|
||||||
# define RL_SELECT_WRIGHT_CODE 0x43343b315b1b /* Alt+Maj+Right */
|
# define RL_SELECT_WRIGHT_CODE 0x43343b315b1b
|
||||||
# define RL_SELECT_WLEFT_CODE 0x44343b315b1b /* Alt+Maj+Left */
|
# define RL_SELECT_WLEFT_CODE 0x44343b315b1b
|
||||||
# define RL_RETARR_CODE 0x7f /* RetArr */
|
# define RL_RETARR_CODE 0x7f
|
||||||
# define RL_SUPPR_CODE 0x7e335b1b /* Suppr */
|
# define RL_SUPPR_CODE 0x7e335b1b
|
||||||
# define RL_ESC_CODE 0x5c /* Escape `\` */
|
# define RL_ESC_CODE 0x5c
|
||||||
# define RL_QUOTE_CODE 0x27 /* Quote `'` */
|
# define RL_QUOTE_CODE 0x27
|
||||||
# define RL_DQUOTE_CODE 0x22 /* Double Quote `"` */
|
# define RL_DQUOTE_CODE 0x22
|
||||||
# define RL_COPY_CODE 0x631b /* Alt+C */
|
# define RL_COPY_CODE 0x631b
|
||||||
# define RL_CUT_CODE 0x781b /* Alt+X */
|
# define RL_CUT_CODE 0x781b
|
||||||
# define RL_PASTE_CODE 0x761b /* Alt+V */
|
# define RL_PASTE_CODE 0x761b
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifdef MACOSX
|
# ifdef MACOSX
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/14 13:47:09 by gwojda ### ########.fr */
|
/* Updated: 2017/03/15 18:52:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -57,13 +57,6 @@
|
||||||
|
|
||||||
# define CORRUPT 1
|
# define CORRUPT 1
|
||||||
|
|
||||||
/* # define IS_QUOTES (1 << 0) */
|
|
||||||
/* # define IS_BQUOTES (1 << 1) */
|
|
||||||
/* # define IS_DQUOTES (1 << 2) */
|
|
||||||
/* # define IS_BSLASH (1 << 3) */
|
|
||||||
/* # define IS_ACCOLADE (1 << 4) */
|
|
||||||
/* # define IS_BRACKET (1 << 5) */
|
|
||||||
|
|
||||||
# define STR data_singleton()->line.input
|
# define STR data_singleton()->line.input
|
||||||
# define POS data_singleton()->line.pos
|
# define POS data_singleton()->line.pos
|
||||||
|
|
||||||
|
|
@ -113,7 +106,8 @@ void ft_get_next_str(char *str, size_t *pos);
|
||||||
void ft_putall_current_str(char *str, size_t *pos);
|
void ft_putall_current_str(char *str, size_t *pos);
|
||||||
void ft_current_str(char *str, size_t pos);
|
void ft_current_str(char *str, size_t pos);
|
||||||
int ft_strlen_next(char *str, size_t pos);
|
int ft_strlen_next(char *str, size_t pos);
|
||||||
void ft_push_back_history(t_list_history **head, t_list_history *new);
|
void ft_push_back_history(
|
||||||
|
t_list_history **head, t_list_history *new);
|
||||||
void ft_prompt(void);
|
void ft_prompt(void);
|
||||||
char *ft_remove_imput(char *str, size_t pos);
|
char *ft_remove_imput(char *str, size_t pos);
|
||||||
char *ft_realloc_imput(char *str, int a, size_t pos);
|
char *ft_realloc_imput(char *str, int a, size_t pos);
|
||||||
|
|
@ -121,7 +115,8 @@ char *ft_strdupi(char const *s);
|
||||||
char *ft_strndup(char const *s, int n);
|
char *ft_strndup(char const *s, int n);
|
||||||
t_list_history *ft_create_history_list(char *str);
|
t_list_history *ft_create_history_list(char *str);
|
||||||
char *ft_strdupi_w(char const *s);
|
char *ft_strdupi_w(char const *s);
|
||||||
void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len);
|
void ft_realloc_str_history(
|
||||||
|
char **str, size_t pos, int nb_his, int len);
|
||||||
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||||
long long ft_pow(int nbr, int power);
|
long long ft_pow(int nbr, int power);
|
||||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/14 23:14:14 by wescande ### ########.fr */
|
/* Updated: 2017/03/15 18:52:34 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ typedef struct s_bquote
|
||||||
*/
|
*/
|
||||||
char **glob(char *str, unsigned char *esc,
|
char **glob(char *str, unsigned char *esc,
|
||||||
unsigned char *dbl_esc, int do_match);
|
unsigned char *dbl_esc, int do_match);
|
||||||
void esc_print(char *str, unsigned char *esc);
|
void esc_print(char *str, unsigned char *esc);
|
||||||
int word_is_assignment(char **content);
|
int word_is_assignment(char **content);
|
||||||
void *tab_esc_copy(void *content);
|
void *tab_esc_copy(void *content);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/18 11:10:14 by gwojda #+# #+# */
|
/* Created: 2017/02/18 11:10:14 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/19 10:59:19 by gwojda ### ########.fr */
|
/* Updated: 2017/03/15 18:54:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,12 +23,12 @@ typedef struct s_hash
|
||||||
char *path;
|
char *path;
|
||||||
} t_hash;
|
} t_hash;
|
||||||
|
|
||||||
int ft_add_hash(t_process *p);
|
int ft_add_hash(t_process *p);
|
||||||
int ft_hash(t_process *p);
|
int ft_hash(t_process *p);
|
||||||
int ft_is_hash(t_process *p);
|
int ft_is_hash(t_process *p);
|
||||||
int ft_hash_str(char *str);
|
int ft_hash_str(char *str);
|
||||||
|
|
||||||
void ft_hash_free(void *ptr, size_t size);
|
void ft_hash_free(void *ptr, size_t size);
|
||||||
void ft_free_hash_table(void);
|
void ft_free_hash_table(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:29:42 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 20:31:07 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,8 +16,9 @@
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
# include <termios.h>
|
# include <termios.h>
|
||||||
# include "libft.h"
|
/* # include "libft.h" */
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
|
# include "exec.h"
|
||||||
|
|
||||||
# define JOB_NOTIFIED (1 << 0)
|
# define JOB_NOTIFIED (1 << 0)
|
||||||
# define JOB_BG (1 << 1)
|
# define JOB_BG (1 << 1)
|
||||||
|
|
@ -27,15 +28,6 @@
|
||||||
|
|
||||||
# define JOBS_OPTS_L (1 << 0)
|
# define JOBS_OPTS_L (1 << 0)
|
||||||
|
|
||||||
struct s_job
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
pid_t pgid;
|
|
||||||
t_flag attrs;
|
|
||||||
t_list *first_process;
|
|
||||||
struct termios tmodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct s_jobc
|
struct s_jobc
|
||||||
{
|
{
|
||||||
t_list *first_job;
|
t_list *first_job;
|
||||||
|
|
@ -44,8 +36,6 @@ struct s_jobc
|
||||||
struct termios shell_tmodes;
|
struct termios shell_tmodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
# include "exec.h"
|
|
||||||
|
|
||||||
t_list *job_getprocess(pid_t pid);
|
t_list *job_getprocess(pid_t pid);
|
||||||
int job_addprocess(t_process *p);
|
int job_addprocess(t_process *p);
|
||||||
void job_update_id(void);
|
void job_update_id(void);
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 938a355bac5f6d4c7941968d3ef0da0d984a9329
|
Subproject commit 0c1dbf5b89c99612c49d6fd63dd25d0310bad3d9
|
||||||
|
|
@ -6,38 +6,50 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 18:11:36 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 21:15:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int bt_read_getdelim(t_read *data, char *arg)
|
int bt_read_getdelim(char ***av, t_read *data)
|
||||||
{
|
{
|
||||||
data->delim = *arg;
|
if (!av || !*av)
|
||||||
|
return (1);
|
||||||
|
data->delim = ***av;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_read_getnchars(t_read *data, char *arg)
|
int bt_read_getnchars(char ***av, t_read *data)
|
||||||
{
|
{
|
||||||
data->nchars = ft_atoi(arg);
|
if (!av || !*av)
|
||||||
|
return (1);
|
||||||
|
data->nchars = ft_atoi(**av);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_read_getprompt(t_read *data, char *arg)
|
int bt_read_getprompt(char ***av, t_read *data)
|
||||||
{
|
{
|
||||||
data->prompt = arg;
|
DG("getting prompt");
|
||||||
|
if (!av || !*av || !**av)
|
||||||
|
return (1);
|
||||||
|
data->prompt = **av;
|
||||||
|
DG("got prompt [%s]", data->prompt);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_read_gettimeout(t_read *data, char *arg)
|
int bt_read_gettimeout(char ***av, t_read *data)
|
||||||
{
|
{
|
||||||
data->timeout = ft_atoi(arg);
|
if (!av || !*av)
|
||||||
|
return (1);
|
||||||
|
data->timeout = ft_atoi(**av);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_read_getfd(t_read *data, char *arg)
|
int bt_read_getfd(char ***av, t_read *data)
|
||||||
{
|
{
|
||||||
data->fd = ft_atoi(arg);
|
if (!av || !*av)
|
||||||
|
return (1);
|
||||||
|
data->fd = ft_atoi(**av);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* bt_read_parse.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/01/27 18:25:22 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/05 15:28:10 by wescande ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
static t_readopt *bt_read_getopt(char letter)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (g_readtab[i].letter)
|
|
||||||
{
|
|
||||||
if (g_readtab[i].letter == letter)
|
|
||||||
return (&g_readtab[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bt_read_parse(t_read *data, char **av)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
t_readopt *opt;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (av[i])
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
if (av[i][j++] == '-')
|
|
||||||
{
|
|
||||||
if (av[i][j] == '-' && av[i][j + 1] == 0)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
while (av[i][j])
|
|
||||||
{
|
|
||||||
if (!(opt = bt_read_getopt(av[i][j])))
|
|
||||||
{
|
|
||||||
ft_dprintf(2, "{red}%s: bad option: %c{eoc}\n", SHELL_NAME, av[i][j]);
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
data->opts |= opt->flag;
|
|
||||||
if (opt->get)
|
|
||||||
{
|
|
||||||
(*opt->get)(data, av[++i]);
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
data->names = av[i] ? av + i : NULL;
|
|
||||||
// DG("read_opts: %b", data->opts);
|
|
||||||
DG("\ndelim=%c\nnchars=%i\nprompt=%s\ntimeout=%i\nfd=%i",
|
|
||||||
data->delim, data->nchars, data->prompt, data->timeout, data->fd);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bt_read_init(t_read *data, char **av)
|
|
||||||
{
|
|
||||||
data->opts = 0;
|
|
||||||
data->delim = '\n';
|
|
||||||
data->nchars = -1;
|
|
||||||
data->prompt = NULL;
|
|
||||||
data->fd = 0;
|
|
||||||
data->input = NULL;
|
|
||||||
if ((bt_read_parse(data, av)))
|
|
||||||
return (1);
|
|
||||||
if (data->names)
|
|
||||||
DG("%s,%s", data->names[0], data->names[1]);
|
|
||||||
bt_read_terminit(data);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
|
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 13:56:47 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 21:23:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,9 +27,7 @@ int bt_read_terminit(t_read *data)
|
||||||
|
|
||||||
(void)data;
|
(void)data;
|
||||||
term = bt_read_term(1);
|
term = bt_read_term(1);
|
||||||
term.c_lflag &= ~(ICANON);
|
term.c_lflag &= ~(ICANON | ECHO);
|
||||||
if (data->opts & READ_OPT_LS)
|
|
||||||
term.c_lflag &= ~(ECHO);
|
|
||||||
if (data->opts & READ_OPT_LT)
|
if (data->opts & READ_OPT_LT)
|
||||||
{
|
{
|
||||||
term.c_cc[VTIME] = data->timeout * 10;
|
term.c_cc[VTIME] = data->timeout * 10;
|
||||||
|
|
|
||||||
|
|
@ -6,29 +6,46 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 18:08:35 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 21:22:34 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_readopt g_readtab[] =
|
t_cliopts g_read_opts[] =
|
||||||
{
|
{
|
||||||
/* {'a', READ_OPT_LA, NULL}, */
|
{'d', NULL, READ_OPT_LD, 0, bt_read_getdelim},
|
||||||
{'d', READ_OPT_LD, bt_read_getdelim},
|
{'n', NULL, READ_OPT_LN, 0, bt_read_getnchars},
|
||||||
/* {'e', READ_OPT_LE, NULL}, */
|
{'p', NULL, READ_OPT_LP, 0, bt_read_getprompt},
|
||||||
/* {'i', READ_OPT_LI, NULL}, */
|
{'r', NULL, READ_OPT_LR, 0, NULL},
|
||||||
{'n', READ_OPT_LN, bt_read_getnchars},
|
{'s', NULL, READ_OPT_LS, 0, NULL},
|
||||||
/* {'N', READ_OPT_UN, bt_read_getnchars}, */
|
{'t', NULL, READ_OPT_LT, 0, bt_read_gettimeout},
|
||||||
{'p', READ_OPT_LP, bt_read_getprompt},
|
{'u', NULL, READ_OPT_LU, 0, bt_read_getfd},
|
||||||
{'r', READ_OPT_LR, NULL},
|
{0, 0, 0, 0, 0},
|
||||||
{'s', READ_OPT_LS, NULL},
|
|
||||||
{'t', READ_OPT_LT, bt_read_gettimeout},
|
|
||||||
{'u', READ_OPT_LU, bt_read_getfd},
|
|
||||||
{0, 0, 0},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void bt_read_usage(void)
|
||||||
|
{
|
||||||
|
ft_dprintf(2, "{red}read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]{eoc}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int bt_read_init(t_read *data, char **av)
|
||||||
|
{
|
||||||
|
data->opts = 0;
|
||||||
|
data->delim = '\n';
|
||||||
|
data->nchars = -1;
|
||||||
|
data->prompt = NULL;
|
||||||
|
data->fd = 0;
|
||||||
|
data->timeout = 0;
|
||||||
|
data->input = NULL;
|
||||||
|
data->names = NULL;
|
||||||
|
if ((cliopts_get(av, g_read_opts, data)))
|
||||||
|
return(ft_perror());
|
||||||
|
if (data->names)
|
||||||
|
DG("%s,%s", data->names[0], data->names[1]);
|
||||||
|
bt_read_terminit(data);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
int bt_read_loop(t_read *data)
|
int bt_read_loop(t_read *data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -44,7 +61,8 @@ int bt_read_loop(t_read *data)
|
||||||
if (read(data->fd, buf, 1) <= 0)
|
if (read(data->fd, buf, 1) <= 0)
|
||||||
return (1);
|
return (1);
|
||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
DG("got input [%x]", *buf);
|
if (!(data->opts &READ_OPT_LS))
|
||||||
|
ft_putchar(*buf);
|
||||||
if (!esc && *buf == data->delim)
|
if (!esc && *buf == data->delim)
|
||||||
break ;
|
break ;
|
||||||
esc = esc ? 0 : !(data->opts & READ_OPT_LR) && (*buf == '\\');
|
esc = esc ? 0 : !(data->opts & READ_OPT_LR) && (*buf == '\\');
|
||||||
|
|
@ -54,7 +72,6 @@ int bt_read_loop(t_read *data)
|
||||||
if ((data->opts & READ_OPT_LN) && ++i >= data->nchars)
|
if ((data->opts & READ_OPT_LN) && ++i >= data->nchars)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
ft_putchar('\n');
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,24 +79,23 @@ int bt_read_assign(t_read *data)
|
||||||
{
|
{
|
||||||
char *input;
|
char *input;
|
||||||
char **names;
|
char **names;
|
||||||
char *IFS;
|
char *ifs;
|
||||||
char *start;
|
char *start;
|
||||||
|
|
||||||
input = data->input;
|
input = data->input;
|
||||||
names = data->names ? data->names : (char*[]){"REPLY", NULL};
|
names = data->names ? data->names : (char*[]){"REPLY", NULL};
|
||||||
IFS = ft_getenv(data_singleton()->env, "IFS");
|
ifs = ft_getenv(data_singleton()->env, "IFS");
|
||||||
start = input;
|
start = input;
|
||||||
while (*start && *names)
|
while (*start && *names)
|
||||||
{
|
{
|
||||||
if (!(names[1]) || !IFS)
|
if (!(names[1]) || !ifs)
|
||||||
{
|
{
|
||||||
DG("setting env: %s=%x%x%x", *names, *start, start[1],start[2]);
|
|
||||||
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
|
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
while (*input && !ft_strchr(IFS, *input))
|
while (*input && !ft_strchr(ifs, *input))
|
||||||
input++;
|
input++;
|
||||||
while (input && ft_strchr(IFS, *input))
|
while (input && ft_strchr(ifs, *input))
|
||||||
*(input++) = 0;
|
*(input++) = 0;
|
||||||
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
|
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
|
||||||
start = input;
|
start = input;
|
||||||
|
|
@ -102,6 +118,9 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
|
||||||
ret = 1;
|
ret = 1;
|
||||||
else if (bt_read_assign(&data))
|
else if (bt_read_assign(&data))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
bt_read_exit(&data);
|
if (ret != 0)
|
||||||
|
bt_read_usage();
|
||||||
|
if (ret != 2)
|
||||||
|
bt_read_exit(&data);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue