diff --git a/42sh/includes/btree.h b/42sh/includes/btree.h new file mode 100644 index 00000000..5839155c --- /dev/null +++ b/42sh/includes/btree.h @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */ +/* Updated: 2016/12/05 11:53:30 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BTREE_H +# define BTREE_H + +# include "libft.h" + +struct s_btree +{ + void *item; + size_t content_size; + struct s_btree *left; + struct s_btree *right; +}; + +struct s_printdata +{ + int is_left; + int offset; + int depth; + int left; + int right; +}; + +typedef struct s_btree t_btree; +typedef struct s_printdata t_printdata; + +t_btree *btree_create_node(void const *item, size_t content_size); +void btree_insert_data( + t_btree **root, + void *item, + size_t content_size, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, + void *data_ref, int (*cmpf)(void *, void *)); +int btree_level_count(t_btree *root); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_print(int fd, t_btree *tree, char *(*printer)(void *)); +void btree_del(t_btree **root, void (*del)(void *, size_t)); +void btree_delone(t_btree **root, void (*del)(void *, size_t)); + +#endif diff --git a/42sh/includes/color.h b/42sh/includes/color.h new file mode 100644 index 00000000..96eea18e --- /dev/null +++ b/42sh/includes/color.h @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/25 13:36:48 by jhalford #+# #+# */ +/* Updated: 2016/12/09 22:09:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COLOR_H +# define COLOR_H +# include "libft.h" + +struct s_color +{ + char fg[7]; + char bg[7]; +}; + +typedef struct s_color t_color; + +# define FG_DEFAULT "\x1b[0m" +# define ON_BOLD "\x1b[1m" + +# define ON_UNDERLINED "\x1b[4m" +# define ON_INVERTED "\x1b[7m" + +# define FG_BLACK "\x1b[30m" +# define FG_RED "\x1b[31m" +# define FG_GREEN "\x1b[32m" +# define FG_YELLOW "\x1b[33m" +# define FG_BLUE "\x1b[34m" +# define FG_MAGENTA "\x1b[35m" +# define FG_CYAN "\x1b[36m" + +# define BG_BLACK "\x1b[40m" +# define BG_RED "\x1b[41m" +# define BG_GREEN "\x1b[42m" +# define BG_YELLOW "\x1b[43m" +# define BG_BLUE "\x1b[44m" +# define BG_MAGENTA "\x1b[45m" +# define BG_CYAN "\x1b[46m" +# define BG_DEFAULT "\x1b[49m" + +# define FBG_DEFAULT "\x1b[49m\x1b[20m" + +void ft_color_reset(void); +void ft_color_set(t_color color); + +void ft_color_mk(t_color *color, char fg[7], char bg[7]); +void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7]); + +#endif diff --git a/42sh/includes/dlst.h b/42sh/includes/dlst.h new file mode 100644 index 00000000..42d73729 --- /dev/null +++ b/42sh/includes/dlst.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dlst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */ +/* Updated: 2016/11/07 13:21:52 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef DLST_H +# define DLST_H + +struct s_dlist +{ + void *content; + size_t content_size; + struct s_dlist *next; + struct s_dlist *prev; +}; + +typedef struct s_dlist t_dlist; + +void ft_dlstadd_after(t_dlist **alst, t_dlist *new); +void ft_dlstadd_before(t_dlist **alst, t_dlist *new); +void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)); +void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t)); +int ft_dlstsize(t_dlist *list); +t_dlist *ft_dlstnew(void const *content, size_t content_size); +t_dlist *ft_dlstlast(t_dlist *list); +char *ft_dlsttostr(t_dlist *list); + +#endif diff --git a/42sh/includes/ft_printf.h b/42sh/includes/ft_printf.h new file mode 100644 index 00000000..6db739f4 --- /dev/null +++ b/42sh/includes/ft_printf.h @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftprintf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ +/* Updated: 2016/12/15 15:29:22 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_H +# define FT_PRINTF_H +# include "libft.h" +# include +# define ALL_FLAGS "#0- +" +# define ALL_CONVERSIONS "sSpdDioOuUxXcCb" + +typedef struct s_fmt t_fmt; +typedef struct s_conv t_conv; +typedef char *(t_converter)(t_fmt *fmt, va_list ap); +typedef void (t_pad_func)(char *str, t_fmt *fmt); + +struct s_conv +{ + char id; + char allowed_flags[6]; + char base[20]; + t_converter *converter; + t_pad_func *sharp_func; +}; + +struct s_fmt +{ + char flags[6]; + int width; + int precision; + char modifier[3]; + char conversion; + int valid; + t_conv conv; +}; + +int ft_vdprintf(int fd, const char *format, va_list ap); +int ft_fmtcalc(char **final, char **str, va_list ap); + +extern t_conv g_convs[]; + +t_fmt *ft_fmt_init(void); +void ft_fmt_print(t_fmt *fmt); +void ft_printf_color(int fd, char **final, char **str); + +t_fmt *ft_printf_parse(char **format, va_list ap); +void ft_printf_parse_flags(t_fmt *fmt, char **format); +void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap); +void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap); +void ft_printf_parse_modifiers(t_fmt *fmt, char **format); + +char *ft_transform(t_fmt *fmt, va_list ap); + +void ft_fmt_error_conv(char conv); +void ft_fmt_error_mod_conv(char *mod, char conv); +void ft_fmt_error_flag_conv(char flag, char conv); +void ft_fmt_error_flag_flag(char flag1, char flag2); + +void ft_fmt_simplify(t_fmt *fmt); +int ft_fmt_validate_conv(t_fmt *fmt); +void ft_fmt_validate_flags(t_fmt *fmt); +void ft_fmt_validate_mod(t_fmt *fmt); + +char *ft_signed_conversion(t_fmt *fmt, va_list ap); +char *ft_unsigned_conversion(t_fmt *fmt, va_list ap); +char *ft_str_conversion(t_fmt *fmt, va_list ap); +char *ft_char_conversion(t_fmt *fmt, va_list ap); + +void ft_pad_sharp_o(char *str, t_fmt *fmt); +void ft_pad_sharp_xb(char *str, t_fmt *fmt); +void ft_pad_left(char *str, t_fmt *fmt); +void ft_pad_right(char *str, t_fmt *fmt); +#endif diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index f8aeb60e..a9e83df6 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,209 +6,104 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */ -/* Updated: 2017/01/11 17:31:09 by jhalford ### ########.fr */ +/* Updated: 2017/01/19 16:47:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_READLINE_H # define FT_READLINE_H -# include "libft.h" -# include "ft_curs.h" +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include -/* - * Input-Key Mapping !!! LINUX Or MACOSX !!! -*/ +# define FLECHE_HAUT 4283163 +# define FLECHE_BAS 4348699 +# define FLECHE_GAUCHE 4479771 +# define FLECHE_DROITE 4414235 +# define TOUCHE_DELETE 2117294875 +# define TOUCHE_HOME 4741915 +# define TOUCHE_END 4610843 +# define TOUCHE_TAB 9 +# define TOUCHE_OPT_RIGHT 1130044187 +# define TOUCHE_OPT_LEFT 1146821403 +# define TOUCHE_OPT_UP 1096489755 +# define TOUCHE_OPT_DOWN 1113266971 +# define TOUCHE_OPT_V 10127586 +# define TOUCHE_OPT_C 42947 +# define TOUCHE_OPT_X 8948194 -//# define LINUX -# define MACOSX -# include "ft_input.h" - -/* - * Default offset for dynamic allocation -*/ - -# define RL_OFFSET 1024 - -/* - * Readline possible prompt -*/ - -# define RL_PROMPT_DEFAULT "$> " -# define RL_PROMPT_ESC "> " -# define RL_PROMPT_QUOTE "quote> " -# define RL_PROMPT_DQUOTE "double quote> " - -/* - * Bitset manipulation : X is the bitset and Y is the bit to manipulate - * IS : Is Y set in X - * NOT : Is Y not set in X - * SET : Set Y in X - * UNSET : Unset Y from X -*/ - -# define RL_IS(X, Y) (X & Y) -# define RL_NOT(X, Y) (!RL_IS(X, Y)) -# define RL_SET(X, Y) (X |= Y) -# define RL_UNSET(X, Y) (X &= ~Y) - -/* - * Possible bit for t_line.bitset - * - * FINISH : bit to terminate and flush the readline - * STACK : bit to stack the current line and begin another one - * INSERT : bit to toogle insert-mode/replace-mode - * SELECT : bit to toogle extend-video-area-mode/clear-video-area-mode - * ESC : bit to escape quoting and new line - * QUOTE : bit to toogle quote-terminated-mode/quote-not-terminated-mode - * DQUOTE : bit to toogle dquote-terminated-mode/dquote-not-terminated-mode - * QUOTING : Regroup ESC, QUOTE and DQUOTE -*/ - -# define RL_FINISH (1 << 0) -# define RL_STACK (1 << 1) -# define RL_INSERT (1 << 2) -# define RL_SELECT (1 << 3) -# define RL_ESC (1 << 4) -# define RL_QUOTE (1 << 5) -# define RL_DQUOTE (1 << 6) -# define RL_QUOTING (RL_ESC | RL_QUOTE | RL_DQUOTE) - -typedef struct s_data t_data; -typedef struct s_line t_line; -typedef struct s_input t_input; -typedef int (*t_input_function)(t_line *, long int); - -/* - * Interactive line data: - * - * bitset : global/local state and settings for readline - * prompt : current prompt - * input : destination buffer - * pos : cursor position in the destination buffer - * size : allocated size of the destination buffer - * used : actual used size in the destination buffer - * select : start position of the video (aka selected) area in the destination buffer - * clipboard : duplication of the copied/cuted part of the destination buffer - * stack : list of stacked line. (lines are stacked when a quoted (or escaped) new line appear) -*/ - -struct s_line +typedef struct s_line { - int bitset; - char *prompt; char *input; - char *clipboard; - int pos; - int size; - int used; - int select; - t_curs curs; - t_list *stack; - t_dlist *history; -}; + int prompt_size; +} t_line; -/* - * Input data: - * code : input identifier - * function : input handler -*/ - -struct s_input +typedef struct s_list_history { - long int code; - t_input_function function; -}; + char *str; + struct s_list_history *prev; + struct s_list_history *next; +} t_list_history; -# include "minishell.h" +long long ft_pow(int nbr, int power); +char *ft_strndup(char const *s, int n); +char *ft_strdupi(char const *s); +void ft_puttermcaps(char *str); +void ft_putnc(char c, int n); +int ft_size_term(void); +void ft_free_tabstr(char ***env); +int ft_is_whitespaces(char *str); +int ft_get_size_prev(char *str, size_t pos); +int ft_nb_line(char *str, size_t pos); +int ft_get_ind_prev(char *str, size_t pos); +void ft_found_next_word(char *str, size_t *pos); +void ft_move_to_beggin(char *str, size_t *pos); +int ft_nb_last_line(char *str, size_t pos); +void ft_found_prev_word(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); +int ft_readline(void); +struct termios *ft_stats_term_termcaps(void); +struct termios *ft_save_stats_term(void); +void ft_init_line(void); +void ft_read_it(int input, size_t *pos, char **str); +void ft_check_quotes(char **s, t_list_history *head); +int ft_check_quotes_num(char *s); +void ft_del_2(char **str, size_t *i); +void ft_del_1(char **str, size_t *i); +void ft_suppr_2(char **str, size_t *i); +void ft_suppr_1(char **str, size_t *i); +void ft_print(char **str, int ret, size_t *i); +void ft_move_to_line(int ret, size_t *pos, char *str); +void ft_get_head(t_list_history **head); +void ft_push_back_history(t_list_history **head, t_list_history *new); +t_list_history *ft_create_history_list(char *str); +void ft_curse_move(char *str); +void ft_move_suppr(char *str, size_t pos); +void ft_move_dell(char *str, size_t pos); +void ft_move_to_word(int ret, size_t *pos, char *str); +void ft_history(char **str, int ret, t_list_history **head); +void ft_move_term(int ret, size_t *pos, char *str); +void ft_move_left(size_t pos, char *str); +void ft_home_end(char *str, int ret, size_t *pos); +int ft_put(int nb); +char **ft_split_whitespaces(char const *s); +void ft_cxv(int ret, size_t *pos, char **str); +char *ft_lecture(t_list_history *head); +void ft_prompt(void); -/* - * Readline setup/cleanup/teardown -*/ - -int rl_setup(t_line *line); -int rl_cleanup(t_line *line); -void rl_teardown(t_line *line); -int rl_set_termios(int input_mode); - -/* - * Dynamic allocated buffer manipulation -*/ - -int input_maj(t_line *line, char *str, int size); -int input_move(t_line *line, char *str, int size); -void input_remove(t_line *line, int size); - -/* - * Readline internal function -*/ - -void rl_set_prompt(t_line *line); -void rl_put_prompt(t_line *line); -int rl_previous_word(t_line *line); -int rl_next_word(t_line *line); -int rl_clipboard_new(t_line *line); -int rl_clipboard_new_cut(t_line *line); -void rl_toogle_bitset(t_line *line, int set); -int rl_finish(t_line *line); -int rl_stack_line(t_line *line); -int rl_merge_line(t_line *line); - -/* - * Realine display functions: - * - * reset_display : Redraw the interactive buffer and replace the cursor - * based on t_line.input, t_line.pos and t_line.select . - * reset_display_ante : Redraw before the cursor position. - * reset_display_post : Redraw after the cursor position. -*/ - -void rl_reset_display(t_line *line); -void rl_reset_display_ante(t_line *line); -void rl_reset_display_post(t_line *line); - -/* - * input handler functions - * - * An handler use curs_ to manipulate the cursor position - * and recalc t_line.pos based on the cursor movement. - * - * An handler can also modify the content of the destination buffer. - * If it do so, it must reset all display that appear - * after the first index of that modification. - * If t_line.pos is that index, rl_reset_display_post can simply do the work. -*/ - -int rl_default_function(t_line *line, long int input); /* Not handled input */ -int rl_esc_function(t_line *line, long int input); /* Backslash */ -int rl_quote_function(t_line *line, long int input); /* Simple quote */ -int rl_dquote_function(t_line *line, long int input); /* Double quote */ -int rl_nl_function(t_line *line, long int input); /* New line */ -int rl_comp_function(t_line *line, long int input); /* Tabulation */ -int rl_left_function(t_line *line, long int input); /* Left move */ -int rl_right_function(t_line *line, long int input); /* Right move */ -int rl_wleft_function(t_line *line, long int input); /* Word left move */ -int rl_wright_function(t_line *line, long int input); /* Word right move */ -int rl_home_function(t_line *line, long int input); /* Home move */ -int rl_end_function(t_line *line, long int input); /* End move */ -int rl_pageup_function(t_line *line, long int input); /* Pageup move */ -int rl_pagedown_function(t_line *line, long int input); /* Pagedown move*/ -int rl_select_left_function(t_line *line, long int input); /* Left extend video area */ -int rl_select_right_function(t_line *line, long int input); /* Right extend video area */ -int rl_select_wleft_function(t_line *line, long int input); /* Word left extend video area */ -int rl_select_wright_function(t_line *line, long int input); /* Word right extend video area */ -int rl_select_home_function(t_line *line, long int input); /* Home extend video area */ -int rl_select_end_function(t_line *line, long int input); /* End extend video area */ -int rl_select_pageup_function(t_line *line, long int input); /* Pageup extend video area */ -int rl_select_pagedown_function(t_line *line, long int input); /* Pagedown extend video area */ -int rl_retarr_function(t_line *line, long int input); /* Remove before the cursor */ -int rl_suppr_function(t_line *line, long int input); /* Remove after the cursor */ -int rl_clear_function(t_line *line, long int input); /* Clear screen */ -int rl_copy_function(t_line *line, long int input); /* Copy selected area or current cursor line */ -int rl_cut_function(t_line *line, long int input); /* Cut selected area or current cursor line */ -int rl_paste_function(t_line *line, long int input); /* Paste copied/cuted area */ -int rl_insert_function(t_line *line, long int input); /* Toogle insert-mode/replacement-mode */ - -int ft_readline(); #endif diff --git a/42sh/src/line-editing/curs_single.c b/42sh/includes/ft_xattr.h similarity index 57% rename from 42sh/src/line-editing/curs_single.c rename to 42sh/includes/ft_xattr.h index a7c883a9..9afadc18 100644 --- a/42sh/src/line-editing/curs_single.c +++ b/42sh/includes/ft_xattr.h @@ -1,26 +1,21 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* curs_single.c :+: :+: :+: */ +/* ftxattr.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:04:53 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:40:41 by sbenning ### ########.fr */ +/* Created: 2016/11/07 13:24:05 by jhalford #+# #+# */ +/* Updated: 2016/11/07 13:24:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ft_curs.h" +#ifndef FT_XATTR_H +# define FT_XATTR_H +# define FT_XATTR_SIZE 10000 +# include +# include -/* - * Save cursor reference or return a previous saved reference -*/ - -t_curs *curs_single(t_curs *curs, int set) -{ - static t_curs *single; - - if (set) - single = curs; - return (single); -} +int ft_xattr_print(char *path); +int ft_xattr_count(char *path); +#endif diff --git a/42sh/src/line-editing/curs_clear.c b/42sh/includes/get_next_line.h similarity index 52% rename from 42sh/src/line-editing/curs_clear.c rename to 42sh/includes/get_next_line.h index cb3d0694..b63d0ac2 100644 --- a/42sh/src/line-editing/curs_clear.c +++ b/42sh/includes/get_next_line.h @@ -1,34 +1,31 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* curs_clear.c :+: :+: :+: */ +/* get_next_line.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:28:50 by sbenning #+# #+# */ -/* Updated: 2017/01/10 17:20:41 by jhalford ### ########.fr */ +/* Created: 2016/11/05 12:21:36 by jhalford #+# #+# */ +/* Updated: 2016/12/15 13:07:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ft_curs.h" +#ifndef GET_NEXT_LINE_H +# define GET_NEXT_LINE_H +# define BUFF_SIZE 32 -/* - * Clear screen and keep track of cursoe's coordonate -*/ +# include "libft.h" +# include +# include -void curs_clear(t_curs *curs) +typedef struct s_save t_save; + +struct s_save { - ft_putstr(tgetstr("cl", NULL)); - curs->li = 0; - curs->co = 0; -} + int fd; + char *str; +}; -/* - * Clear screen after cursor position without moving cursor -*/ +int get_next_line(int const fd, char **line); -void curs_clear_post(t_curs *curs) -{ - ft_putstr(tgetstr("cd", NULL)); - (void)curs; -} +#endif diff --git a/42sh/includes/libft.h b/42sh/includes/libft.h new file mode 100644 index 00000000..ecbe6bb5 --- /dev/null +++ b/42sh/includes/libft.h @@ -0,0 +1,162 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ +/* Updated: 2017/01/19 16:13:05 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# define STDIN 0 +# define STDOUT 1 +# define STDERR 2 +# define STDBUG 3 + +# define DG_MSG0 "{inv}{yel}%21s {bol}{blu}%-3d{eoc}" +# define DG_MSG1 ft_path_notdir(__FILE__), __LINE__ +# define DG(f, ...) ft_dprintf(STDBUG, DG_MSG0 f "{eoc}\n", DG_MSG1, ##__VA_ARGS__) + +# include "get_next_line.h" +# include "ft_xattr.h" +# include "mytime.h" +# include "lst.h" +# include "dlst.h" +# include "btree.h" +# include "color.h" + +# include +# include +# include +# include +# include +# include +# include + +# define FT_WS(x) (x == ' ' || x == '\t' || x == '\n') +# define FT_ABS(x) (((x) < 0) ? -(x) : (x)) +# define FT_NEG(x) (((x) < 0) ? 1 : 0) +# define FT_POS(x) (((x) > 0) ? 1 : 0) +# define FT_MIN(a, b) ((a) < (b) ? (a) : (b)) +# define FT_MAX(a, b) ((a) > (b) ? (a) : (b)) +# define FT_DIST(a, b) (FT_ABS((a) - (b))) + +typedef struct s_stof t_stof; +typedef struct s_stos t_stos; + +struct s_stos +{ + char *key; + char *val; +}; + +struct s_stof +{ + char *name; + int (*f)(); +}; + +void ft_debug(void); + +void *ft_memset(void *b, int c, size_t len); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memccpy(void *dst, const void *src, int c, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +size_t ft_strlen(const char *s); +char *ft_strdup(const char *s1); +char *ft_strcpy(char *dst, const char *src); +char *ft_strncpy(char *dst, const char *src, size_t len); +char *ft_strcat(char *s1, const char *s2); +char *ft_strncat(char *s1, const char *s2, size_t n); +size_t ft_strlcat(char *dst, const char *src, size_t size); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strstr(const char *big, const char *little); +char *ft_strnstr(const char *big, const char *little, size_t len); +int ft_strcmp(const char *s1, const char *s2); +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_atoi(const char *str); +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_toupper(int c); +int ft_tolower(int c); + +void *ft_memalloc(size_t size); +void ft_memdel(void **ap); +char *ft_strnew(size_t size); +void ft_strdel(char **as); +void ft_strclr(char *s); +void ft_striter(char *s, void (*f)(char *)); +void ft_striteri(char *s, void (*f)(unsigned int, char *)); +char *ft_strmap(char const *s, char (*f)(char)); +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +int ft_strequ(char const *s1, char const *s2); +int ft_strnequ(char const *s1, char const *s2, size_t n); +char *ft_strsub(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s); +char **ft_strsplit(char const *s, char c); +char *ft_itoa(int n); +int ft_putchar(int c); +void ft_putstr(char const *s); +void ft_putendl(char const *s); +void ft_putnbr(int n); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char const *s, int fd); +void ft_putendl_fd(char const *s, int fd); +void ft_putnbr_fd(int n, int fd); +void ft_putaddr(void *a); + +char *ft_strrev(char *str); +char **ft_strsplit(char const *s, char c); +char *ft_str3join(char const *s1, char const *s2, char const *s3); +char *ft_strcut(char *str, char *cut); +char **ft_split_whitespaces(char const *str); +char *ft_convert_base( + char *str, char *base_from, char *base_to, char *flags); +char *ft_strcatf(char *s1, const char *s2); +char *ft_strinsert(char *str, char c, int n); +int ft_strappend(char **dst, char *src); +char *ft_strbetween(char *start, char *end); +char *ft_strreplace(char **str, char *start, char *end, char *new); + +char *ft_itoa_base(int nbr, char *base, char *flags); +char *ft_lltoa_base(long long nbr, char *base, char *flags); +char *ft_ulltoa_base(unsigned long long nbr, char *base); +char *ft_uitoa_base(unsigned int nbr, char *base); +size_t ft_ilen(int n); +size_t ft_ilen_base(int n, int base); +size_t ft_uilen(unsigned int n); +size_t ft_lllen(long long n); +size_t ft_lllen_base(long long n, int base); +int ft_addrcmp(void *a, void *b); + +char **ft_sstradd(char **list, char *new); +void ft_sstrsort(char **list, int (*cmp)()); +void ft_sstrprint(char **list, char sep); +void ft_sstrprint_fd(int fd, char **list, char sep); +char **ft_sstrdup(char **list); +void ft_sstrdel(char **sstr, int index); +void ft_sstrfree(char **sstr); +char *ft_sstrcat(char **sstr, char sep); + +char *ft_path_notdir(char *path); + +int ft_printf(const char *format, ...); +int ft_dprintf(int fd, const char *format, ...); + +char *ft_getenv(char **env, char *key); + +void *ft_realloc(void *data, int size); +#endif diff --git a/42sh/includes/lst.h b/42sh/includes/lst.h new file mode 100644 index 00000000..ee4926df --- /dev/null +++ b/42sh/includes/lst.h @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ +/* Updated: 2016/12/12 14:59:12 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LST_H +# define LST_H + +# include "libft.h" + +struct s_list +{ + void *content; + size_t content_size; + struct s_list *next; +}; + +typedef struct s_list t_list; + +t_list *ft_lstnew(void const *content, size_t content_size); +void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); +void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); +void ft_lstadd(t_list **alst, t_list *new); +void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); +t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); + +t_list *ft_lstnew_range(int a, int b); +void ft_lsteadd(t_list **alst, t_list *new); +void ft_lstnadd(t_list **alst, t_list *new, int n); +void ft_lstsort(t_list **begin_list, int (*cmp)()); +void ft_lst_print(t_list *list, void (*printer)()); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lst_sorted_merge( + t_list **begin_list1, + t_list *begin_list2, + int (*cmp)()); +void ft_lst_sorted_insert( + t_list **begin_list, + t_list *insert, + int (*cmp)()); +void ft_lst_delif( + t_list **alist, + void *data_ref, + int (*cmp)(), + void (*del)(void *, size_t)); +void ft_lst_delsub( + t_list **alst, + t_list *sub, int (*cmp)(), + void (*del)(void *, size_t)); +void ft_lst_cfree(void *ptr, size_t size); +void ft_lst_bfree(void *ptr, size_t size); +t_list *ft_lst_filter( + t_list *lst, + void const *data_ref, + t_list *(*f)(t_list *elem, void const *)); +t_list *ft_lst_removeif( + t_list **alst, + void *data_ref, + int (*cmp)()); +t_list *ft_lst_find( + t_list *begin_list, + void *data_ref, + int (*cmp)()); +t_list *ft_lstpop(t_list **lst); +void ft_lst_merge(t_list **begin_list1, t_list *begin_list2); +void ft_lst_reverse(t_list **begin_list); + +int ft_diff(void *a, void *b); +t_list *ft_id(t_list *a); +t_list *ft_lst_at(t_list *list, unsigned int nbr); + +#endif diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 02b05202..2895c065 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* minishell.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/01/11 17:17:16 by jhalford ### ########.fr */ +/* Updated: 2017/01/19 15:21:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_clear_function.c b/42sh/includes/mytime.h similarity index 50% rename from 42sh/src/line-editing/rl_clear_function.c rename to 42sh/includes/mytime.h index 6782b79c..140e1100 100644 --- a/42sh/src/line-editing/rl_clear_function.c +++ b/42sh/includes/mytime.h @@ -1,32 +1,34 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* rl_clear_function.c :+: :+: :+: */ +/* mytime.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/09 13:34:29 by sbenning #+# #+# */ -/* Updated: 2017/01/10 17:46:00 by jhalford ### ########.fr */ +/* Created: 2016/11/25 11:43:12 by jhalford #+# #+# */ +/* Updated: 2016/11/25 20:26:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ft_readline.h" +#ifndef MYTIME_H +# define MYTIME_H +# include "libft.h" -int rl_clear_function(t_line *line, long int input) +struct s_mytime { - int pos; + char *year; + char *month; + char *day; + char *hour; + char *min; + char *sec; +}; - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - curs_clear(&line->curs); - rl_put_prompt(line); - pos = line->pos; - line->pos = 0; - if (line->used) - rl_reset_display_post(line); - if (pos) - curs_forward(&line->curs, pos); - line->pos = pos; - return (0); - (void)input; -} +typedef struct s_mytime t_mytime; + +int ft_time_isrecent(time_t event); + +t_mytime *ft_mytime_get(time_t epoch); +void ft_mytime_free(t_mytime **time); + +#endif diff --git a/42sh/obj/ast_free.o b/42sh/obj/ast_free.o new file mode 100644 index 00000000..d3bbdd4d Binary files /dev/null and b/42sh/obj/ast_free.o differ diff --git a/42sh/obj/builtin_bg.o b/42sh/obj/builtin_bg.o new file mode 100644 index 00000000..92476142 Binary files /dev/null and b/42sh/obj/builtin_bg.o differ diff --git a/42sh/obj/builtin_cd.o b/42sh/obj/builtin_cd.o new file mode 100644 index 00000000..dd1af953 Binary files /dev/null and b/42sh/obj/builtin_cd.o differ diff --git a/42sh/obj/builtin_echo.o b/42sh/obj/builtin_echo.o new file mode 100644 index 00000000..3f246bed Binary files /dev/null and b/42sh/obj/builtin_echo.o differ diff --git a/42sh/obj/builtin_env.o b/42sh/obj/builtin_env.o new file mode 100644 index 00000000..4dce0ec7 Binary files /dev/null and b/42sh/obj/builtin_env.o differ diff --git a/42sh/obj/builtin_exit.o b/42sh/obj/builtin_exit.o new file mode 100644 index 00000000..f08787f4 Binary files /dev/null and b/42sh/obj/builtin_exit.o differ diff --git a/42sh/obj/builtin_fg.o b/42sh/obj/builtin_fg.o new file mode 100644 index 00000000..9da2139c Binary files /dev/null and b/42sh/obj/builtin_fg.o differ diff --git a/42sh/obj/builtin_jobs.o b/42sh/obj/builtin_jobs.o new file mode 100644 index 00000000..1260e07f Binary files /dev/null and b/42sh/obj/builtin_jobs.o differ diff --git a/42sh/obj/builtin_setenv.o b/42sh/obj/builtin_setenv.o new file mode 100644 index 00000000..9b661b54 Binary files /dev/null and b/42sh/obj/builtin_setenv.o differ diff --git a/42sh/obj/builtin_unsetenv.o b/42sh/obj/builtin_unsetenv.o new file mode 100644 index 00000000..c95cd843 Binary files /dev/null and b/42sh/obj/builtin_unsetenv.o differ diff --git a/42sh/obj/command_getoutput.o b/42sh/obj/command_getoutput.o new file mode 100644 index 00000000..41121df3 Binary files /dev/null and b/42sh/obj/command_getoutput.o differ diff --git a/42sh/obj/copy_cut_paste.o b/42sh/obj/copy_cut_paste.o new file mode 100644 index 00000000..9d52813a Binary files /dev/null and b/42sh/obj/copy_cut_paste.o differ diff --git a/42sh/obj/data_exit.o b/42sh/obj/data_exit.o new file mode 100644 index 00000000..36f4b2ac Binary files /dev/null and b/42sh/obj/data_exit.o differ diff --git a/42sh/obj/data_init.o b/42sh/obj/data_init.o new file mode 100644 index 00000000..f0fc8aa9 Binary files /dev/null and b/42sh/obj/data_init.o differ diff --git a/42sh/obj/data_singleton.o b/42sh/obj/data_singleton.o new file mode 100644 index 00000000..a8b8ea35 Binary files /dev/null and b/42sh/obj/data_singleton.o differ diff --git a/42sh/obj/do_job_notification.o b/42sh/obj/do_job_notification.o new file mode 100644 index 00000000..9dd64dd4 Binary files /dev/null and b/42sh/obj/do_job_notification.o differ diff --git a/42sh/obj/exec_ampersand.o b/42sh/obj/exec_ampersand.o new file mode 100644 index 00000000..dad02cc2 Binary files /dev/null and b/42sh/obj/exec_ampersand.o differ diff --git a/42sh/obj/exec_and_if.o b/42sh/obj/exec_and_if.o new file mode 100644 index 00000000..2f946ae0 Binary files /dev/null and b/42sh/obj/exec_and_if.o differ diff --git a/42sh/obj/exec_command.o b/42sh/obj/exec_command.o new file mode 100644 index 00000000..17669529 Binary files /dev/null and b/42sh/obj/exec_command.o differ diff --git a/42sh/obj/exec_dgreat.o b/42sh/obj/exec_dgreat.o new file mode 100644 index 00000000..4f532928 Binary files /dev/null and b/42sh/obj/exec_dgreat.o differ diff --git a/42sh/obj/exec_great.o b/42sh/obj/exec_great.o new file mode 100644 index 00000000..49a86d0f Binary files /dev/null and b/42sh/obj/exec_great.o differ diff --git a/42sh/obj/exec_less.o b/42sh/obj/exec_less.o new file mode 100644 index 00000000..14dd6f73 Binary files /dev/null and b/42sh/obj/exec_less.o differ diff --git a/42sh/obj/exec_or_if.o b/42sh/obj/exec_or_if.o new file mode 100644 index 00000000..d317d0cb Binary files /dev/null and b/42sh/obj/exec_or_if.o differ diff --git a/42sh/obj/exec_pipe.o b/42sh/obj/exec_pipe.o new file mode 100644 index 00000000..69c57ed2 Binary files /dev/null and b/42sh/obj/exec_pipe.o differ diff --git a/42sh/obj/exec_semi.o b/42sh/obj/exec_semi.o new file mode 100644 index 00000000..183cd9e9 Binary files /dev/null and b/42sh/obj/exec_semi.o differ diff --git a/42sh/obj/ft_exec.o b/42sh/obj/ft_exec.o new file mode 100644 index 00000000..7ebb7d95 Binary files /dev/null and b/42sh/obj/ft_exec.o differ diff --git a/42sh/obj/ft_findexec.o b/42sh/obj/ft_findexec.o new file mode 100644 index 00000000..0e9cb040 Binary files /dev/null and b/42sh/obj/ft_findexec.o differ diff --git a/42sh/obj/ft_parse.o b/42sh/obj/ft_parse.o new file mode 100644 index 00000000..58763dbd Binary files /dev/null and b/42sh/obj/ft_parse.o differ diff --git a/42sh/obj/ft_post_tokenize.o b/42sh/obj/ft_post_tokenize.o new file mode 100644 index 00000000..692079e8 Binary files /dev/null and b/42sh/obj/ft_post_tokenize.o differ diff --git a/42sh/obj/ft_putast.o b/42sh/obj/ft_putast.o new file mode 100644 index 00000000..68bc619f Binary files /dev/null and b/42sh/obj/ft_putast.o differ diff --git a/42sh/obj/ft_putast2.o b/42sh/obj/ft_putast2.o new file mode 100644 index 00000000..93e88ec6 Binary files /dev/null and b/42sh/obj/ft_putast2.o differ diff --git a/42sh/obj/ft_split_whitespaces.o b/42sh/obj/ft_split_whitespaces.o new file mode 100644 index 00000000..f8ea70a7 Binary files /dev/null and b/42sh/obj/ft_split_whitespaces.o differ diff --git a/42sh/obj/ft_tokenize.o b/42sh/obj/ft_tokenize.o new file mode 100644 index 00000000..6c708728 Binary files /dev/null and b/42sh/obj/ft_tokenize.o differ diff --git a/42sh/obj/get_lexer_state.o b/42sh/obj/get_lexer_state.o new file mode 100644 index 00000000..2a093a6d Binary files /dev/null and b/42sh/obj/get_lexer_state.o differ diff --git a/42sh/obj/get_touch.o b/42sh/obj/get_touch.o new file mode 100644 index 00000000..1dc4f7e7 Binary files /dev/null and b/42sh/obj/get_touch.o differ diff --git a/42sh/obj/get_touch_toolz.o b/42sh/obj/get_touch_toolz.o new file mode 100644 index 00000000..efab3626 Binary files /dev/null and b/42sh/obj/get_touch_toolz.o differ diff --git a/42sh/obj/get_touch_toolz_2.o b/42sh/obj/get_touch_toolz_2.o new file mode 100644 index 00000000..dc0a06a0 Binary files /dev/null and b/42sh/obj/get_touch_toolz_2.o differ diff --git a/42sh/obj/is_builtin.o b/42sh/obj/is_builtin.o new file mode 100644 index 00000000..2161a2b4 Binary files /dev/null and b/42sh/obj/is_builtin.o differ diff --git a/42sh/obj/job_addprocess.o b/42sh/obj/job_addprocess.o new file mode 100644 index 00000000..23736aef Binary files /dev/null and b/42sh/obj/job_addprocess.o differ diff --git a/42sh/obj/job_cmp_id.o b/42sh/obj/job_cmp_id.o new file mode 100644 index 00000000..0dd4403a Binary files /dev/null and b/42sh/obj/job_cmp_id.o differ diff --git a/42sh/obj/job_format.o b/42sh/obj/job_format.o new file mode 100644 index 00000000..974c7a93 Binary files /dev/null and b/42sh/obj/job_format.o differ diff --git a/42sh/obj/job_format_head.o b/42sh/obj/job_format_head.o new file mode 100644 index 00000000..24ed7f23 Binary files /dev/null and b/42sh/obj/job_format_head.o differ diff --git a/42sh/obj/job_free.o b/42sh/obj/job_free.o new file mode 100644 index 00000000..36954c14 Binary files /dev/null and b/42sh/obj/job_free.o differ diff --git a/42sh/obj/job_getprocess.o b/42sh/obj/job_getprocess.o new file mode 100644 index 00000000..c92fdb89 Binary files /dev/null and b/42sh/obj/job_getprocess.o differ diff --git a/42sh/obj/job_getrank.o b/42sh/obj/job_getrank.o new file mode 100644 index 00000000..7dfe939a Binary files /dev/null and b/42sh/obj/job_getrank.o differ diff --git a/42sh/obj/job_is_completed.o b/42sh/obj/job_is_completed.o new file mode 100644 index 00000000..52ebf046 Binary files /dev/null and b/42sh/obj/job_is_completed.o differ diff --git a/42sh/obj/job_is_stopped.o b/42sh/obj/job_is_stopped.o new file mode 100644 index 00000000..8e64f72d Binary files /dev/null and b/42sh/obj/job_is_stopped.o differ diff --git a/42sh/obj/job_kill_all.o b/42sh/obj/job_kill_all.o new file mode 100644 index 00000000..85cac4ae Binary files /dev/null and b/42sh/obj/job_kill_all.o differ diff --git a/42sh/obj/job_notify_change.o b/42sh/obj/job_notify_change.o new file mode 100644 index 00000000..6db4d7e7 Binary files /dev/null and b/42sh/obj/job_notify_change.o differ diff --git a/42sh/obj/job_notify_new.o b/42sh/obj/job_notify_new.o new file mode 100644 index 00000000..b1f5b6a4 Binary files /dev/null and b/42sh/obj/job_notify_new.o differ diff --git a/42sh/obj/job_remove.o b/42sh/obj/job_remove.o new file mode 100644 index 00000000..5f68e0e7 Binary files /dev/null and b/42sh/obj/job_remove.o differ diff --git a/42sh/obj/job_update_id.o b/42sh/obj/job_update_id.o new file mode 100644 index 00000000..a0818cdd Binary files /dev/null and b/42sh/obj/job_update_id.o differ diff --git a/42sh/obj/job_update_status.o b/42sh/obj/job_update_status.o new file mode 100644 index 00000000..7e903dbb Binary files /dev/null and b/42sh/obj/job_update_status.o differ diff --git a/42sh/obj/job_wait.o b/42sh/obj/job_wait.o new file mode 100644 index 00000000..8eb10c59 Binary files /dev/null and b/42sh/obj/job_wait.o differ diff --git a/42sh/obj/launch_process.o b/42sh/obj/launch_process.o new file mode 100644 index 00000000..3fdab719 Binary files /dev/null and b/42sh/obj/launch_process.o differ diff --git a/42sh/obj/lexer_backslash.o b/42sh/obj/lexer_backslash.o new file mode 100644 index 00000000..0e3a6241 Binary files /dev/null and b/42sh/obj/lexer_backslash.o differ diff --git a/42sh/obj/lexer_default.o b/42sh/obj/lexer_default.o new file mode 100644 index 00000000..fce1b267 Binary files /dev/null and b/42sh/obj/lexer_default.o differ diff --git a/42sh/obj/lexer_delim.o b/42sh/obj/lexer_delim.o new file mode 100644 index 00000000..05d7ddac Binary files /dev/null and b/42sh/obj/lexer_delim.o differ diff --git a/42sh/obj/lexer_dquote.o b/42sh/obj/lexer_dquote.o new file mode 100644 index 00000000..29705224 Binary files /dev/null and b/42sh/obj/lexer_dquote.o differ diff --git a/42sh/obj/lexer_great.o b/42sh/obj/lexer_great.o new file mode 100644 index 00000000..6b6d3d0c Binary files /dev/null and b/42sh/obj/lexer_great.o differ diff --git a/42sh/obj/lexer_greatand.o b/42sh/obj/lexer_greatand.o new file mode 100644 index 00000000..842bca0c Binary files /dev/null and b/42sh/obj/lexer_greatand.o differ diff --git a/42sh/obj/lexer_less.o b/42sh/obj/lexer_less.o new file mode 100644 index 00000000..55ca67fa Binary files /dev/null and b/42sh/obj/lexer_less.o differ diff --git a/42sh/obj/lexer_lessand.o b/42sh/obj/lexer_lessand.o new file mode 100644 index 00000000..ef5abb8e Binary files /dev/null and b/42sh/obj/lexer_lessand.o differ diff --git a/42sh/obj/lexer_number.o b/42sh/obj/lexer_number.o new file mode 100644 index 00000000..001f4e8f Binary files /dev/null and b/42sh/obj/lexer_number.o differ diff --git a/42sh/obj/lexer_quote.o b/42sh/obj/lexer_quote.o new file mode 100644 index 00000000..ba0cf267 Binary files /dev/null and b/42sh/obj/lexer_quote.o differ diff --git a/42sh/obj/lexer_sep.o b/42sh/obj/lexer_sep.o new file mode 100644 index 00000000..0fc8b499 Binary files /dev/null and b/42sh/obj/lexer_sep.o differ diff --git a/42sh/obj/lexer_special.o b/42sh/obj/lexer_special.o new file mode 100644 index 00000000..497c3be6 Binary files /dev/null and b/42sh/obj/lexer_special.o differ diff --git a/42sh/obj/lexer_var.o b/42sh/obj/lexer_var.o new file mode 100644 index 00000000..0668ed3e Binary files /dev/null and b/42sh/obj/lexer_var.o differ diff --git a/42sh/obj/lexer_word.o b/42sh/obj/lexer_word.o new file mode 100644 index 00000000..1fe43cd1 Binary files /dev/null and b/42sh/obj/lexer_word.o differ diff --git a/42sh/obj/line_return_toolz.o b/42sh/obj/line_return_toolz.o new file mode 100644 index 00000000..ed542b13 Binary files /dev/null and b/42sh/obj/line_return_toolz.o differ diff --git a/42sh/obj/list_toolz.o b/42sh/obj/list_toolz.o new file mode 100644 index 00000000..cbbbc0f7 Binary files /dev/null and b/42sh/obj/list_toolz.o differ diff --git a/42sh/obj/main.o b/42sh/obj/main.o new file mode 100644 index 00000000..90b3f8ba Binary files /dev/null and b/42sh/obj/main.o differ diff --git a/42sh/obj/mark_job_as_running.o b/42sh/obj/mark_job_as_running.o new file mode 100644 index 00000000..c4363f82 Binary files /dev/null and b/42sh/obj/mark_job_as_running.o differ diff --git a/42sh/obj/move_to_line.o b/42sh/obj/move_to_line.o new file mode 100644 index 00000000..dcadb73a Binary files /dev/null and b/42sh/obj/move_to_line.o differ diff --git a/42sh/obj/parse_dgreat.o b/42sh/obj/parse_dgreat.o new file mode 100644 index 00000000..aa3d9954 Binary files /dev/null and b/42sh/obj/parse_dgreat.o differ diff --git a/42sh/obj/parse_dless.o b/42sh/obj/parse_dless.o new file mode 100644 index 00000000..8828a2d3 Binary files /dev/null and b/42sh/obj/parse_dless.o differ diff --git a/42sh/obj/parse_great.o b/42sh/obj/parse_great.o new file mode 100644 index 00000000..3f64649e Binary files /dev/null and b/42sh/obj/parse_great.o differ diff --git a/42sh/obj/parse_greatand.o b/42sh/obj/parse_greatand.o new file mode 100644 index 00000000..ea85f5b2 Binary files /dev/null and b/42sh/obj/parse_greatand.o differ diff --git a/42sh/obj/parse_less.o b/42sh/obj/parse_less.o new file mode 100644 index 00000000..7a14b146 Binary files /dev/null and b/42sh/obj/parse_less.o differ diff --git a/42sh/obj/parse_lessand.o b/42sh/obj/parse_lessand.o new file mode 100644 index 00000000..2d892b98 Binary files /dev/null and b/42sh/obj/parse_lessand.o differ diff --git a/42sh/obj/parse_separator.o b/42sh/obj/parse_separator.o new file mode 100644 index 00000000..0635d658 Binary files /dev/null and b/42sh/obj/parse_separator.o differ diff --git a/42sh/obj/parse_subshell.o b/42sh/obj/parse_subshell.o new file mode 100644 index 00000000..90ea1422 Binary files /dev/null and b/42sh/obj/parse_subshell.o differ diff --git a/42sh/obj/parse_word.o b/42sh/obj/parse_word.o new file mode 100644 index 00000000..22a0503c Binary files /dev/null and b/42sh/obj/parse_word.o differ diff --git a/42sh/obj/print_and_del.o b/42sh/obj/print_and_del.o new file mode 100644 index 00000000..92cf2afd Binary files /dev/null and b/42sh/obj/print_and_del.o differ diff --git a/42sh/obj/process_cmp_pid.o b/42sh/obj/process_cmp_pid.o new file mode 100644 index 00000000..a7d27a76 Binary files /dev/null and b/42sh/obj/process_cmp_pid.o differ diff --git a/42sh/obj/process_format.o b/42sh/obj/process_format.o new file mode 100644 index 00000000..208d854e Binary files /dev/null and b/42sh/obj/process_format.o differ diff --git a/42sh/obj/process_free.o b/42sh/obj/process_free.o new file mode 100644 index 00000000..7df5f946 Binary files /dev/null and b/42sh/obj/process_free.o differ diff --git a/42sh/obj/process_mark_status.o b/42sh/obj/process_mark_status.o new file mode 100644 index 00000000..ee809bea Binary files /dev/null and b/42sh/obj/process_mark_status.o differ diff --git a/42sh/obj/process_redirect.o b/42sh/obj/process_redirect.o new file mode 100644 index 00000000..233c6b13 Binary files /dev/null and b/42sh/obj/process_redirect.o differ diff --git a/42sh/obj/process_reset.o b/42sh/obj/process_reset.o new file mode 100644 index 00000000..980e0521 Binary files /dev/null and b/42sh/obj/process_reset.o differ diff --git a/42sh/obj/process_setexec.o b/42sh/obj/process_setexec.o new file mode 100644 index 00000000..00a361d8 Binary files /dev/null and b/42sh/obj/process_setexec.o differ diff --git a/42sh/obj/process_setgroup.o b/42sh/obj/process_setgroup.o new file mode 100644 index 00000000..a01b2e69 Binary files /dev/null and b/42sh/obj/process_setgroup.o differ diff --git a/42sh/obj/prompt.o b/42sh/obj/prompt.o new file mode 100644 index 00000000..8d0bcf53 Binary files /dev/null and b/42sh/obj/prompt.o differ diff --git a/42sh/obj/put_job_in_background.o b/42sh/obj/put_job_in_background.o new file mode 100644 index 00000000..ba69bfe9 Binary files /dev/null and b/42sh/obj/put_job_in_background.o differ diff --git a/42sh/obj/put_job_in_foreground.o b/42sh/obj/put_job_in_foreground.o new file mode 100644 index 00000000..d6b9d13d Binary files /dev/null and b/42sh/obj/put_job_in_foreground.o differ diff --git a/42sh/obj/quotes_gest.o b/42sh/obj/quotes_gest.o new file mode 100644 index 00000000..17f7be69 Binary files /dev/null and b/42sh/obj/quotes_gest.o differ diff --git a/42sh/obj/reader.o b/42sh/obj/reader.o new file mode 100644 index 00000000..9756cb12 Binary files /dev/null and b/42sh/obj/reader.o differ diff --git a/42sh/obj/readline.o b/42sh/obj/readline.o new file mode 100644 index 00000000..8daaf031 Binary files /dev/null and b/42sh/obj/readline.o differ diff --git a/42sh/obj/reduce_bquotes.o b/42sh/obj/reduce_bquotes.o new file mode 100644 index 00000000..3aaa01ac Binary files /dev/null and b/42sh/obj/reduce_bquotes.o differ diff --git a/42sh/obj/reduce_parens.o b/42sh/obj/reduce_parens.o new file mode 100644 index 00000000..9ee29c88 Binary files /dev/null and b/42sh/obj/reduce_parens.o differ diff --git a/42sh/obj/set_exitstatus.o b/42sh/obj/set_exitstatus.o new file mode 100644 index 00000000..2d772911 Binary files /dev/null and b/42sh/obj/set_exitstatus.o differ diff --git a/42sh/obj/shell_exit.o b/42sh/obj/shell_exit.o new file mode 100644 index 00000000..6692c8c1 Binary files /dev/null and b/42sh/obj/shell_exit.o differ diff --git a/42sh/obj/shell_get_avdata.o b/42sh/obj/shell_get_avdata.o new file mode 100644 index 00000000..a63d40ff Binary files /dev/null and b/42sh/obj/shell_get_avdata.o differ diff --git a/42sh/obj/shell_get_opts.o b/42sh/obj/shell_get_opts.o new file mode 100644 index 00000000..2a597e89 Binary files /dev/null and b/42sh/obj/shell_get_opts.o differ diff --git a/42sh/obj/shell_init.o b/42sh/obj/shell_init.o new file mode 100644 index 00000000..33567b4b Binary files /dev/null and b/42sh/obj/shell_init.o differ diff --git a/42sh/obj/sigchld_handler.o b/42sh/obj/sigchld_handler.o new file mode 100644 index 00000000..a85af3b4 Binary files /dev/null and b/42sh/obj/sigchld_handler.o differ diff --git a/42sh/obj/sigint_handler.o b/42sh/obj/sigint_handler.o new file mode 100644 index 00000000..859a658d Binary files /dev/null and b/42sh/obj/sigint_handler.o differ diff --git a/42sh/obj/sigtstp_handler.o b/42sh/obj/sigtstp_handler.o new file mode 100644 index 00000000..bff39d8c Binary files /dev/null and b/42sh/obj/sigtstp_handler.o differ diff --git a/42sh/obj/sigttin_handler.o b/42sh/obj/sigttin_handler.o new file mode 100644 index 00000000..f6fdc33e Binary files /dev/null and b/42sh/obj/sigttin_handler.o differ diff --git a/42sh/obj/sigttou_handler.o b/42sh/obj/sigttou_handler.o new file mode 100644 index 00000000..17056d95 Binary files /dev/null and b/42sh/obj/sigttou_handler.o differ diff --git a/42sh/obj/token_append.o b/42sh/obj/token_append.o new file mode 100644 index 00000000..8b1dede7 Binary files /dev/null and b/42sh/obj/token_append.o differ diff --git a/42sh/obj/token_cmp_type.o b/42sh/obj/token_cmp_type.o new file mode 100644 index 00000000..c5d367ac Binary files /dev/null and b/42sh/obj/token_cmp_type.o differ diff --git a/42sh/obj/token_expand_var.o b/42sh/obj/token_expand_var.o new file mode 100644 index 00000000..134684b1 Binary files /dev/null and b/42sh/obj/token_expand_var.o differ diff --git a/42sh/obj/token_free.o b/42sh/obj/token_free.o new file mode 100644 index 00000000..de97febb Binary files /dev/null and b/42sh/obj/token_free.o differ diff --git a/42sh/obj/token_init.o b/42sh/obj/token_init.o new file mode 100644 index 00000000..4bb6a561 Binary files /dev/null and b/42sh/obj/token_init.o differ diff --git a/42sh/obj/token_print.o b/42sh/obj/token_print.o new file mode 100644 index 00000000..3170b433 Binary files /dev/null and b/42sh/obj/token_print.o differ diff --git a/42sh/obj/toolz.o b/42sh/obj/toolz.o new file mode 100644 index 00000000..fc363746 Binary files /dev/null and b/42sh/obj/toolz.o differ diff --git a/42sh/obj/toolz2.o b/42sh/obj/toolz2.o new file mode 100644 index 00000000..f267b6a3 Binary files /dev/null and b/42sh/obj/toolz2.o differ diff --git a/42sh/obj/toolz_parseur.o b/42sh/obj/toolz_parseur.o new file mode 100644 index 00000000..6cc49122 Binary files /dev/null and b/42sh/obj/toolz_parseur.o differ diff --git a/42sh/obj/toolz_termcaps.o b/42sh/obj/toolz_termcaps.o new file mode 100644 index 00000000..c5c7fe9b Binary files /dev/null and b/42sh/obj/toolz_termcaps.o differ diff --git a/42sh/src/line-editing/copy_cut_paste.c b/42sh/src/line-editing/copy_cut_paste.c new file mode 100644 index 00000000..eebce795 --- /dev/null +++ b/42sh/src/line-editing/copy_cut_paste.c @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* copy_cut_paste.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:34 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void ft_v(char *tmp, size_t *pos, char **str) +{ + int i; + int j; + int len; + + i = 0; + j = 0; + len = *pos; + if (!tmp) + return ; + while (tmp[i]) + { + *str = ft_realloc_imput(*str, tmp[i], *pos); + ++(*pos); + ++i; + } + ft_putstr((*str) + *pos - i); + if (ft_nb_last_line(*str, *pos) == ft_size_term() - 1) + { + ft_putchar(' '); + ft_putchar('\b'); + } + *pos = ft_strlen(*str); + ft_move_to_beggin(*str, pos); + *pos = len; + write(1, *str, *pos); +} + +static void ft_x(char **tmp, size_t *pos, char **str) +{ + int i; + + i = ft_strlen(*str) - 1; + if (*tmp) + ft_strdel(tmp); + *tmp = ft_strdup(&(*str)[(*pos)]); + while (i >= 0 && i >= (int)*pos) + { + *str = ft_remove_imput(*str, i); + --i; + } + ft_move_to_beggin(*str, pos); + ft_puttermcaps("cd"); + ft_putstr(*str); + *pos = ft_strlen(*str); +} + +void ft_cxv(int ret, size_t *pos, char **str) +{ + static char *tmp = NULL; + + if (!*str) + return ; + if (ret == TOUCHE_OPT_X) + ft_x(&tmp, pos, str); + else if (ret == TOUCHE_OPT_C) + { + if (tmp) + ft_strdel(&tmp); + tmp = ft_strdup(&(*str)[(*pos)]); + } + else if (ret == TOUCHE_OPT_V) + ft_v(tmp, pos, str); +} diff --git a/42sh/src/line-editing/curs_ask.c b/42sh/src/line-editing/curs_ask.c deleted file mode 100644 index e465b8c7..00000000 --- a/42sh/src/line-editing/curs_ask.c +++ /dev/null @@ -1,57 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_ask.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:03:49 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:47:13 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Read the line number for cursor's coordonate -*/ - -int curs_li_ask(void) -{ - char buff; - int li; - - li = 0; - buff = 0; - while (buff != ';') - { - buff = 0; - if (read(0, &buff, 1) < 0) - return (-1); - if (ft_isdigit(buff)) - li = li * 10 + (buff - '0'); - } - return (li); -} - -/* - * Read the colomn number for cursor's coordonate -*/ - -int curs_co_ask(void) -{ - char buff; - int co; - - co = 0; - buff = 0; - while (buff != 'R') - { - buff = 0; - if (read(0, &buff, 1) < 0) - return (-1); - if (ft_isdigit(buff)) - co = co * 10 + (buff - '0'); - } - return (co); -} diff --git a/42sh/src/line-editing/curs_move.c b/42sh/src/line-editing/curs_move.c deleted file mode 100644 index d96d0ec1..00000000 --- a/42sh/src/line-editing/curs_move.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_forward.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:21:08 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:56:41 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Move the cursor forward (right/down) -*/ - -void curs_forward(t_curs *curs, int offset) -{ - int size; - int div; - int mod; - - size = (curs->li * curs->win_co + curs->co) + offset; - div = size / curs->win_co; - mod = size % curs->win_co; - curs_goto(curs, div, mod); -} - -/* - * Move the cursor backward (left/up) -*/ - -void curs_backward(t_curs *curs, int offset) -{ - int size; - int div; - int mod; - - size = (curs->li * curs->win_co + curs->co) - offset; - div = size / curs->win_co; - mod = size % curs->win_co; - curs_goto(curs, div, mod); -} diff --git a/42sh/src/line-editing/curs_setup.c b/42sh/src/line-editing/curs_setup.c deleted file mode 100644 index c9842a54..00000000 --- a/42sh/src/line-editing/curs_setup.c +++ /dev/null @@ -1,82 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_setup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 16:36:43 by sbenning #+# #+# */ -/* Updated: 2017/01/11 13:55:42 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Set coordonate cursor data - * "\033[6n" ask for terminal to write on standard entry the cursor's coordonate -*/ - -int curs_coo_setup(t_curs *curs) -{ - ft_putstr("\033[6n"); - curs->li = curs_li_ask() - 1; - curs->co = curs_co_ask() - 1; - return ((curs->li < 0 || curs->co < 0 ? -1 : 0)); -} - -/* - * Set windows cursor data -*/ - -void curs_win_setup(t_curs *curs) -{ - struct winsize ws; - - ioctl(0, TIOCGWINSZ, &ws); - curs->win_li = ws.ws_row; - curs->win_co = ws.ws_col; -} - -/* - * Reset saved cursor data -*/ - -void curs_reset(int sig) -{ - t_curs *curs; - - curs = curs_single(NULL, 0); - curs_win_setup(curs); - curs_coo_setup(curs); - return ; - (void)sig; -} - -/* - * Save the cursor reference, init termcap and set cursor data -*/ - -int curs_setup(t_curs *curs) -{ - curs_single(curs, 1); - signal(SIGWINCH, curs_reset); - if (tgetent(NULL, "xterm") != 1) - return (-1); - if (curs_term_setup() < 0) - return (-1); - curs_win_setup(curs); - if (curs_coo_setup(curs) < 0) - return (-1); - return (0); -} - -/* - * Erase cursor data and reset terminal -*/ - -int curs_cleanup(t_curs *curs) -{ - ft_bzero(curs, sizeof(t_curs)); - return (curs_term_cleanup()); -} diff --git a/42sh/src/line-editing/curs_term_setup.c b/42sh/src/line-editing/curs_term_setup.c deleted file mode 100644 index 9a18bc72..00000000 --- a/42sh/src/line-editing/curs_term_setup.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_term_setup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 16:50:26 by sbenning #+# #+# */ -/* Updated: 2017/01/11 13:55:40 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Return a static termios structure reference -*/ - -static struct termios *curs_term(void) -{ - static struct termios term; - - return (&term); -} - -/* - * Save the current termios state and set termios to RAW -*/ - -int curs_term_setup(void) -{ - struct termios *single; - struct termios term; - - single = curs_term(); - if (tcgetattr(0, single) < 0) - return (-1); - term = *single; - term.c_lflag &= ~(ECHO | ICANON | ISIG); - term.c_cc[VTIME] = 0; - term.c_cc[VMIN] = 1; - if (tcsetattr(0, TCSADRAIN, &term) < 0) - return (-1); - return (0); -} - -/* - * Set termios to the saved state -*/ - -int curs_term_cleanup(void) -{ - struct termios *single; - struct termios term; - - single = curs_term(); - term = *single; - term.c_lflag |= ECHO | ICANON | ISIG; - if (tcsetattr(0, TCSADRAIN, single) < 0) - return (-1); - return (0); -} diff --git a/42sh/src/line-editing/curs_write.c b/42sh/src/line-editing/curs_write.c deleted file mode 100644 index efe19c72..00000000 --- a/42sh/src/line-editing/curs_write.c +++ /dev/null @@ -1,63 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_write.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:52:20 by sbenning #+# #+# */ -/* Updated: 2016/12/09 17:03:41 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Write some buffer to stdout and recalc coordonate (go to next line and scroll if necessary) -*/ - -void curs_write(t_curs *curs, char *str, size_t len) -{ - int size; - int div; - int mod; - - size = (curs->li * curs->win_co + curs->co) + len; - div = size / curs->win_co; - mod = size % curs->win_co; - write(1, str, len); - curs_goto(curs, div, mod); -} - -/* - * curs_write in video mode -*/ - -void curs_video_write(t_curs *curs, char *str, size_t len) -{ - ft_putstr(tgetstr("so", NULL)); - curs_write(curs, str, len); - ft_putstr(tgetstr("me", NULL)); -} - -/* - * curs_write in video mode without moving the cursor -*/ - -void curs_video_write_static(t_curs *curs, char *str, size_t len) -{ - ft_putstr(tgetstr("so", NULL)); - curs_write(curs, str, len); - ft_putstr(tgetstr("me", NULL)); - curs_backward(curs, len); -} - -/* - * curs_write without moving the cursor -*/ - -void curs_write_static(t_curs *curs, char *str, size_t len) -{ - curs_write(curs, str, len); - curs_backward(curs, len); -} diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/src/line-editing/ft_readline.c deleted file mode 100644 index 90620a39..00000000 --- a/42sh/src/line-editing/ft_readline.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_readline.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */ -/* Updated: 2017/01/11 17:35:14 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -static t_input g_input[] = {\ - {RL_NL_CODE, rl_nl_function},\ - {RL_COMP_CODE, rl_comp_function},\ - {RL_INSERT_CODE, rl_insert_function},\ - {RL_CLEAR_CODE, rl_clear_function},\ - {RL_RETARR_CODE, rl_retarr_function},\ - {RL_SUPPR_CODE, rl_suppr_function},\ - {RL_ESC_CODE, rl_esc_function},\ - {RL_QUOTE_CODE, rl_quote_function},\ - {RL_DQUOTE_CODE, rl_dquote_function},\ - {RL_LEFT_CODE, rl_left_function},\ - {RL_SELECT_LEFT_CODE, rl_select_left_function},\ - {RL_RIGHT_CODE, rl_right_function},\ - {RL_SELECT_RIGHT_CODE, rl_select_right_function},\ - {RL_WLEFT_CODE, rl_wleft_function},\ - {RL_SELECT_WLEFT_CODE, rl_select_wleft_function},\ - {RL_WRIGHT_CODE, rl_wright_function},\ - {RL_SELECT_WRIGHT_CODE, rl_select_wright_function},\ - {RL_HOME_CODE, rl_home_function},\ - {RL_SELECT_HOME_CODE, rl_select_home_function},\ - {RL_END_CODE, rl_end_function},\ - {RL_SELECT_END_CODE, rl_select_end_function},\ - {RL_PAGEUP_CODE, rl_pageup_function},\ - {RL_SELECT_PAGEUP_CODE, rl_select_pageup_function},\ - {RL_PAGEDOWN_CODE, rl_pagedown_function},\ - {RL_SELECT_PAGEDOWN_CODE, rl_select_pagedown_function},\ - {RL_COPY_CODE, rl_copy_function},\ - {RL_CUT_CODE, rl_cut_function},\ - {RL_PASTE_CODE, rl_paste_function},\ - {0x0, rl_default_function}\ -}; - -static t_input_function rl_get_function(long int input) -{ - int i; - - i = -1; - while (g_input[++i].code) - { - if (input == g_input[i].code) - break ; - } - return (g_input[i].function); -} - -static long int rl_read(void) -{ - long int input; - - ft_bzero(&input, sizeof(long int)); - if (read(0, &input, sizeof(long int)) < 0) - return (0); - return (input); -} - -static int rl_loop(t_line *line) -{ - long int input; - int ret; - - rl_put_prompt(line); - while (42) - { - input = rl_read(); - if (input == 0) - continue ; - rl_toogle_bitset(line, 0); - if (rl_get_function(input)(line, input) < 0) - return (-1); - if ((ret = rl_finish(line))) - break ; - rl_toogle_bitset(line, 1); - } - return ((ret < 0 ? -1 : 0)); -} - -int ft_readline() -{ - t_line *line; - - line = &data_singleton()->line; - if (rl_setup(line) < 0) - return (-1); - if (rl_loop(line) < 0) - { - rl_teardown(line); - return (-1); - } - if (rl_cleanup(line) < 0) - return (-1); - return (0); -} diff --git a/42sh/src/line-editing/ft_split_whitespaces.c b/42sh/src/line-editing/ft_split_whitespaces.c new file mode 100644 index 00000000..ccca5b34 --- /dev/null +++ b/42sh/src/line-editing/ft_split_whitespaces.c @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 17:52:52 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:38 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static char *ft_strdupi_w(char const *s) +{ + int i; + char *str; + + i = 0; + while (s[i] && s[i] != ' ' && s[i] != '\t') + i++; + str = (char *)malloc(sizeof(char) * (i + 1)); + if (str) + { + str[i--] = '\0'; + while (i >= 0) + { + str[i] = s[i]; + i--; + } + } + return (str); +} + +static int ft_len_words(char const *s) +{ + int i; + int len; + + i = 0; + len = 0; + while (s[i]) + { + if ((i == 0 && s[i] != ' ' && s[i] != '\t') || ((s[i] != ' ' + && s[i] != '\t') && (s[i - 1] == ' ' || s[i - 1] == '\t'))) + len++; + i++; + } + return (len); +} + +char **ft_split_whitespaces(char const *s) +{ + int i; + char **str; + int j; + + str = NULL; + if (!(s)) + return (str); + str = (char **)malloc(sizeof(char *) * (ft_len_words(s) + 1)); + i = 0; + j = 0; + if (!(str)) + return (str); + while (s[i]) + { + if ((i == 0 && s[i] != ' ' && s[i] != '\t') || ((s[i] != ' ' + && s[i] != '\t') && (s[i - 1] == ' ' || s[i - 1] == '\t'))) + { + str[j] = ft_strdupi_w((s + i)); + j++; + } + i++; + } + str[j] = NULL; + return (str); +} diff --git a/42sh/src/line-editing/get_touch.c b/42sh/src/line-editing/get_touch.c new file mode 100644 index 00000000..d1d46075 --- /dev/null +++ b/42sh/src/line-editing/get_touch.c @@ -0,0 +1,92 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_touch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:49 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int ft_lecture_3(int ret, char **str, size_t *i) +{ + if (ret == 127 && (*i) > 0) + { + if ((*str)[*i - 1] != '\n') + ft_suppr_1(str, i); + else + ft_suppr_2(str, i); + } + else if (ret == TOUCHE_DELETE && (*str) && (*i) < ft_strlen((*str))) + { + if ((*str)[*i] != '\n') + ft_del_1(str, i); + else + ft_del_2(str, i); + } + else + return (0); + return (1); +} + +static int ft_lecture_2(int ret, char **str, size_t *i) +{ + if (ret == TOUCHE_OPT_LEFT || ret == TOUCHE_OPT_RIGHT) + ft_move_to_word(ret, i, *str); + else if (ret == TOUCHE_OPT_X || ret == TOUCHE_OPT_C + || ret == TOUCHE_OPT_V) + ft_cxv(ret, i, str); + else if (ret == FLECHE_DROITE || ret == FLECHE_GAUCHE) + ft_move_term(ret, i, *str); + else if (ret == TOUCHE_OPT_UP || ret == TOUCHE_OPT_DOWN) + ft_move_to_line(ret, i, *str); + else if (ft_isprint(ret)) + ft_print(str, ret, i); + else + return (0); + return (1); +} + +char *ft_lecture(t_list_history *head) +{ + char *str; + int ret; + size_t i; + + str = NULL; + i = 0; + while (42) + { + ret = 0; + read(0, &ret, sizeof(int)); +// if (ret == TOUCHE_TAB) +// ret = ft_completion(&str, &i); + if (ft_lecture_2(ret, &str, &i)) + continue ; + else if (ret == FLECHE_BAS || ret == FLECHE_HAUT) + { + if (str) + ft_putstr(str + i); + ft_history(&str, ret, &head); + if (str) + i = ft_strlen(str); + else + i = 0; + } + else if (ret == TOUCHE_HOME || ret == TOUCHE_END) + ft_home_end(str, ret, &i); + else if (ft_lecture_3(ret, &str, &i)) + continue ; + else if (ret == 10) + break ; + else if (ft_isascii(ret) == 0) + ft_read_it(ret, &i, &str); + } + if (str) + ft_putstr(str + i); + return (str); +} diff --git a/42sh/src/line-editing/get_touch_toolz.c b/42sh/src/line-editing/get_touch_toolz.c new file mode 100644 index 00000000..8a715fcc --- /dev/null +++ b/42sh/src/line-editing/get_touch_toolz.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_touch_toolz.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:45 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void ft_history_2(char **str, int ret, t_list_history **head) +{ + if (*str) + { + ft_curse_move(*str); + ft_strdel(str); + } + if (ret == FLECHE_BAS) + { + if ((*head)->next) + (*head) = (*head)->next; + if (!(*head)->str) + *str = NULL; + else + *str = ft_strdup((*head)->str); + if (*str) + ft_putstr(*str); + } +} + +void ft_history(char **str, int ret, t_list_history **head) +{ + if (!*head) + return ; + ft_history_2(str, ret, head); + if (ret == FLECHE_HAUT) + { + if ((*head)->prev) + (*head) = (*head)->prev; + if (!(*head)->str) + *str = NULL; + else + *str = ft_strdup((*head)->str); + if (*str) + ft_putstr(*str); + } +} + +void ft_move_to_word(int ret, size_t *pos, char *str) +{ + if (!str) + return ; + if (ret == TOUCHE_OPT_LEFT) + ft_found_prev_word(str, pos); + else if (ret == TOUCHE_OPT_RIGHT) + ft_found_next_word(str, pos); +} diff --git a/42sh/src/line-editing/get_touch_toolz_2.c b/42sh/src/line-editing/get_touch_toolz_2.c new file mode 100644 index 00000000..778ac3d4 --- /dev/null +++ b/42sh/src/line-editing/get_touch_toolz_2.c @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_touch_toolz_2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:41 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int ft_put(int nb) +{ + write(1, &nb, 1); + return (1); +} + +void ft_home_end(char *str, int ret, size_t *pos) +{ + if (ret == TOUCHE_END && str) + { + ft_putstr(str + *pos); + (*pos) = ft_strlen(str); + } + else if (ret == TOUCHE_HOME) + ft_move_to_beggin(str, pos); +} + + +void ft_move_left(size_t pos, char *str) +{ + int i; + int nb; + int prompt_size; + + prompt_size = data_singleton()->line.prompt_size; + i = 1; + nb = ft_nb_last_line(str, pos - 1) + 3; + while (i < nb) + { + ft_puttermcaps("nd"); + ++i; + } + if (!(pos - i) || i == 1) + { + while (--prompt_size + 3) + ft_puttermcaps("nd"); + } +} + +void ft_move_term(int ret, size_t *pos, char *str) +{ + int len; + int str_len; + + len = 0; + str_len = 0; + if (ret == FLECHE_DROITE && str && ft_strlen(str) > *pos + && str[(*pos)] == '\n') + { + ft_puttermcaps("do"); + ++(*pos); + } + else if (ret == FLECHE_GAUCHE && *pos > 0 + && str[(*pos) - 1] == '\n') + { + ft_puttermcaps("up"); + --(*pos); + str_len = ft_nb_line(str, *pos - 1); + len = ft_get_size_prev(str, *pos - 1) - (ft_size_term() * str_len); + if (ft_get_ind_prev(str, *pos - 1) == 0) + len += data_singleton()->line.prompt_size + 2; + while (--len + 1) + ft_puttermcaps("nd"); + } + else if (ret == FLECHE_DROITE && str && ft_strlen(str) > *pos) + { + ft_putchar(str[*pos]); + ++(*pos); + if (ft_nb_last_line(str, *pos) == ft_size_term() - 1) + { + ft_putchar(' '); + ft_putchar('\b'); + } + } + else if (ret == FLECHE_GAUCHE && *pos > 0) + { + ft_puttermcaps("le"); + --(*pos); + } +} diff --git a/42sh/src/line-editing/libftprintf.a b/42sh/src/line-editing/libftprintf.a new file mode 100644 index 00000000..430239f1 Binary files /dev/null and b/42sh/src/line-editing/libftprintf.a differ diff --git a/42sh/src/line-editing/line_return_toolz.c b/42sh/src/line-editing/line_return_toolz.c new file mode 100644 index 00000000..7a2e60ef --- /dev/null +++ b/42sh/src/line-editing/line_return_toolz.c @@ -0,0 +1,143 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* line_return_toolz.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/06 14:32:12 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:54 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int ft_found_prev_char(char *str, size_t i) +{ + while (i) + { + if (str[i] == '\n') + return (1); + --i; + } + return (0); +} + +void ft_move_dell(char *str, size_t pos) +{ + size_t i; + int count; + + count = 1; + i = 0; + while (str[i + pos + 1]) + { + if (str[i + pos] == '\n') + ++count; + ++i; + } + while (i && str[i + pos + 1] != '\n') + { + ft_puttermcaps("le"); + --i; + } + if (i) + { + while (i && count) + { + if (str[i + pos + 1] == '\n') + { + ft_puttermcaps("up"); + --count; + } + --i; + } + while (pos && str[pos] != '\n') + { + ft_puttermcaps("nd"); + --pos; + } + } +} + +void ft_move_suppr(char *str, size_t pos) +{ + size_t i; + int count; + int prompt_size; + + prompt_size = data_singleton()->line.prompt_size; + count = 0; + i = 0; + while (str[i + pos]) + { + if (str[i + pos] == '\n') + ++count; + ++i; + } + while (i && str[i + pos] != '\n') + { + ft_puttermcaps("le"); + --i; + } + if (i) + { + while (i && count) + { + if (str[i + pos] == '\n') + { + ft_puttermcaps("up"); + --count; + } + --i; + } + if (pos > 2) + pos -= 2; + if (!ft_found_prev_char(str, pos)) + { + while (--prompt_size + 3) + ft_puttermcaps("nd"); + } + while (pos && str[pos] != '\n') + { + ft_puttermcaps("nd"); + --pos; + } + } +} + +void ft_curse_move(char *str) +{ + int i; + int count; + int prompt_size; + + prompt_size = data_singleton()->line.prompt_size; + count = 0; + i = 0; + while (str[i]) + { + if (str[i] == '\n') + { + count += ft_nb_line(str, i - 1); + count++; + } + ++i; + } + while (i && str[i] != '\n') + { + ft_putchar('\b'); + --i; + } + if (count) + { + while (count) + { + ft_puttermcaps("up"); + --count; + } + while (--prompt_size + 2) + ft_puttermcaps("nd"); + } + ft_puttermcaps("cd"); +} diff --git a/42sh/src/line-editing/list_toolz.c b/42sh/src/line-editing/list_toolz.c new file mode 100644 index 00000000..47a389a2 --- /dev/null +++ b/42sh/src/line-editing/list_toolz.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list_toolz.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:42:57 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_list_history *ft_create_history_list(char *str) +{ + t_list_history *list; + + list = (t_list_history *)malloc(sizeof(t_list_history)); + if (!list) + return (NULL); + if (!str) + list->str = NULL; + else + list->str = ft_strdup(str); + list->prev = NULL; + list->next = NULL; + return (list); +} + +void ft_push_back_history(t_list_history **head, t_list_history *new) +{ + if (!*head) + { + *head = new; + (*head)->prev = ft_create_history_list(NULL); + (*head)->prev->next = (*head); + (*head)->next = ft_create_history_list(NULL); + (*head)->next->prev = (*head); + (*head) = (*head)->next; + return ; + } + while ((*head)->next) + (*head) = (*head)->next; + new->prev = (*head)->prev; + (*head)->prev->next = new; + new->next = (*head); + (*head)->prev = new; +} + +void ft_get_head(t_list_history **head) +{ + if (head && *head) + { + while ((*head)->next && (*head)->next->str) + (*head) = (*head)->next; + } +} diff --git a/42sh/src/line-editing/move_to_line.c b/42sh/src/line-editing/move_to_line.c new file mode 100644 index 00000000..ec451eae --- /dev/null +++ b/42sh/src/line-editing/move_to_line.c @@ -0,0 +1,99 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move_to_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:01 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void ft_up(size_t *pos, char *str) +{ + int i; + int j; + int len; + int tmp; + int size_window; + + size_window = ft_size_term(); + i = 0; + len = 0; + j = 0; + if (!*pos) + return ; + while (len < size_window && *pos - i) + { + if (i && str[*pos - i] == '\n') + { + ft_puttermcaps("up"); + tmp = ft_nb_last_line(str, *pos - 1 - i) + 3; + if (ft_get_ind_prev(str, *pos - 1 - i)) + tmp -= 2; + while (j < tmp - 1) + { + ft_puttermcaps("nd"); + ++j; + } + if (!ft_get_ind_prev(str, *pos - 1 - i)) + ft_putchar('\b'); + len += ft_size_term() - tmp; + } + else + { + ft_putchar('\b'); + len++; + } + i++; + } + if (!(*pos - i)) + { + (*pos) = 0; + return ; + } + if (j) + { + ft_puttermcaps("nd"); + ++(*pos); + } + *pos -= i; +} + +static void ft_down(size_t *pos, char *str) +{ + int len; + int size_window; + char boolean; + + len = 0; + boolean = 0; + size_window = ft_size_term(); + while (str[*pos] && len < size_window) + { + if (str[*pos] == '\n' && !boolean) + { + len += size_window - ft_nb_last_line(str, *pos - 1) - 2; + boolean = 1; + } + else if (str[*pos] == '\n' && boolean) + return ; + else + ++len; + ft_putchar(str[*pos]); + ++(*pos); + } +} + +void ft_move_to_line(int ret, size_t *pos, char *str) +{ + if (!str) + return ; + if (ret == TOUCHE_OPT_UP) + ft_up(pos, str); + else if (ret == TOUCHE_OPT_DOWN) + ft_down(pos, str); +} diff --git a/42sh/src/line-editing/print_and_del.c b/42sh/src/line-editing/print_and_del.c new file mode 100644 index 00000000..2aea0b92 --- /dev/null +++ b/42sh/src/line-editing/print_and_del.c @@ -0,0 +1,138 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_and_del.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ +/* Updated: 2017/01/19 18:08:54 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" +/* +void ft_print(char **str, int ret, size_t *i) +{ + int j; + + j = 0; + *str = ft_realloc_imput(*str, ret, *i); + while (*((*str) + *i + j) && *((*str) + *i + j) != '\n') + { + ft_putchar(*((*str) + *i + j)); + ++j; + } + ft_putnc('\b', j - 1); + ++(*i); +} +*/ +void ft_print(char **str, int ret, size_t *i) +{ + size_t len; + size_t tmp_len; + char boolean; + char boolean2; + + len = 0; + boolean = 0; + boolean2 = 0; + *str = ft_realloc_imput(*str, ret, *i); + tmp_len = ft_strlen(*str); + ft_puttermcaps("cd"); + write(1, *str + *i, 1); + if ((ft_nb_last_line(*str, *i + 1) + + (len % ft_size_term()) == ft_size_term() - 1) && (*str)[*i + 1] == '\n') + { + ft_putchar(' '); + boolean2 = 1; + } + if ((*str)[*i + 1] == '\n' && (*str)[*i + 2] && ft_strlen(*str) > *i + 2) + write(1, *str + *i + 1, ft_strlen(*str + *i + 2)); + else + write(1, *str + *i + 1, ft_strlen(*str + *i + 1)); + ++(*i); + while ((*str)[*i + len] && (*str)[*i + len] != '\n') + ++len; + if ((*i && !(ft_nb_last_line(*str, *i) + + (len % ft_size_term()))) || ft_nb_last_line(*str, *i) + + (len % ft_size_term()) == ft_size_term() - 1) + { + --(tmp_len); + ft_move_to_beggin(*str, &tmp_len); + boolean = 1; + } + else + ft_move_to_beggin(*str, &tmp_len); + if (boolean2) + ft_puttermcaps("up"); + write(1, *str, *i); + if (boolean) + ft_putstr(" \b"); +} + +void ft_suppr_1(char **str, size_t *i) +{ + int j; + + j = 0; + write(1, "\b", 1); + while (*((*str) + *i + j) && *((*str) + *i + j) != '\n') + { + ft_putchar(*((*str) + *i + j)); + ++j; + } + --(*i); + write(1, " ", 1); + if (ft_nb_last_line(*str, *i) + j == ft_size_term() - 2) + { + ft_puttermcaps("nd"); + ft_putnc('\b', j); + } + else + ft_putnc('\b', j + 1); + *str = ft_remove_imput((*str), (*i)); +} + +void ft_suppr_2(char **str, size_t *i) +{ + int j; + + j = 0; + ft_puttermcaps("up"); + ft_move_left(*i - 1, *str); + ft_puttermcaps("cd"); + ft_putstr(*str + *i); + ft_move_suppr(*str, *i); + --(*i); + *str = ft_remove_imput((*str), (*i)); +} + +void ft_del_1(char **str, size_t *i) +{ + int j; + + j = 0; + while (*((*str) + *i + j + 1) && *((*str) + *i + j + 1) != '\n') + { + ft_putchar(*((*str) + *i + j + 1)); + ++j; + } + write(1, " ", 1); + if (ft_nb_last_line(*str, *i) + j == ft_size_term() - 2) + ft_putnc('\b', j); + else + ft_putnc('\b', j + 1); + (*str) = ft_remove_imput((*str), (*i)); +} + +void ft_del_2(char **str, size_t *i) +{ + int j; + + j = 1; + ft_puttermcaps("cd"); + ft_putstr(*str + *i + 1); + ft_move_dell(*str, *i); + *str = ft_remove_imput((*str), (*i)); +} diff --git a/42sh/src/line-editing/prompt.c b/42sh/src/line-editing/prompt.c new file mode 100644 index 00000000..f72dbc7a --- /dev/null +++ b/42sh/src/line-editing/prompt.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* prompt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:48:32 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +/* ft_printf de la lib bug avec unicode */ + +static void ft_get_date(void) +{ + time_t t; + struct tm tm; + + t = time(NULL); + tm = *localtime(&t); + ft_putstr("\033[22;32m"); + printf("%.2d:%.2d:%.2d ", tm.tm_hour, tm.tm_min, tm.tm_sec); + fflush(NULL); + if (tm.tm_hour >= 8 && tm.tm_hour < 20) + printf("\033[22;33m%C ", L'☀'); + else + printf("\033[22;33m%C ", L'★'); + fflush(NULL); +} + +static int ft_currend_dir(void) +{ + int i; + int j; + char **env; + + i = 0; + env = data_singleton()->env; + while (ft_strncmp(env[i], "PWD=", 4)) + ++i; + j = ft_strlen(env[i]); + while (j && env[i][j] != '/') + --j; + ft_putstr(env[i] + j + 1); + return (ft_strlen(env[i] + j + 1)); +} + +void ft_prompt(void) +{ + int ret; + + ft_get_date(); + ft_putstr("\033[22;36m"); + ret = ft_currend_dir(); + ft_putstr("\033[22;33m"); + printf(" %C", L'›'); + fflush(NULL); + ft_putstr("\033[22;37m"); + data_singleton()->line.prompt_size = ret + 12; +} diff --git a/42sh/src/line-editing/quotes_gest.c b/42sh/src/line-editing/quotes_gest.c new file mode 100644 index 00000000..f5ca96e9 --- /dev/null +++ b/42sh/src/line-editing/quotes_gest.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* quotes_gest.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:10 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int ft_check_quotes_num(char *s) +{ + int i; + char simp; + char doub; + + i = 0; + simp = 0; + doub = 0; + while (s[i]) + { + if (s[i] == '\'') + { + simp = 1; + ++i; + while (s[i] && s[i] != '\'') + ++i; + if (s[i] == '\'') + simp = 0; + } + else if (s[i] == '"') + { + doub = 1; + ++i; + while (s[i] && s[i] != '"') + ++i; + if (s[i] == '"') + doub = 0; + } + if (s[i]) + ++i; + } + if (doub) + return (2); + else if (simp) + return (1); + return (0); +} + +void ft_check_quotes(char **s, t_list_history *head) +{ + int ret; + char *tmp; + char *tmp2; + int prompt_size_mem; + + if (!*s) + return ; + while ((ret = (ft_check_quotes_num(*s)))) + { + if (ret == 1) + ft_putstr("squote> "); + else if (ret == 2) + ft_putstr("dquote> "); + tmp = *s; + *s = ft_strjoin(*s, "\n"); + ft_strdel(&tmp); + tmp = *s; + prompt_size_mem = data_singleton()->line.prompt_size; + tmp2 = ft_lecture(head); + data_singleton()->line.prompt_size = prompt_size_mem; + ft_putchar('\n'); + if (!tmp2) + continue ; + *s = ft_strjoin(tmp, tmp2); + ft_strdel(&tmp); + ft_strdel(&tmp2); + } +} diff --git a/42sh/src/line-editing/reader.c b/42sh/src/line-editing/reader.c new file mode 100644 index 00000000..48bc68e7 --- /dev/null +++ b/42sh/src/line-editing/reader.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* reader.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:13 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void ft_read_it_2(int input, char t[5]) +{ + t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0'; + if (t[3]) + input = input % ft_pow(256, 3); + t[2] = (input / ft_pow(256, 2)) ? (input / ft_pow(256, 2)) : '\0'; + if (t[2]) + input = input % ft_pow(256, 2); + t[1] = (input / ft_pow(256, 1)) ? (input / ft_pow(256, 1)) : '\0'; + if (t[1]) + input = input % ft_pow(256, 1); + t[0] = (input / ft_pow(256, 0)) ? (input / ft_pow(256, 0)) : '\0'; + if (t[0]) + input = input % ft_pow(256, 0); + t[4] = '\0'; +} + +void ft_read_it(int input, size_t *pos, char **str) +{ + int i; + int j; + char t[5]; + + j = 0; + i = 0; + if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || input == 126 || + input == 993090331 || input == 925981467 || input == 21298 || + input == 892427035 || input == 8270395 || input == 942758683 || + input == 993090331 || input == 18489 || input == 17977) + + return ; + ft_read_it_2(input, t); + while (i < 4 && t[i] == '\0') + ++i; + while (i < 4) + { + if (t[i]) + { + *str = ft_realloc_imput(*str, t[i], *pos); + ++(*pos); + ++j; + } + ++i; + } + ft_putstr((*str) + (*pos) - j); + ft_putnc('\b', ft_strlen((*str)) - ((*pos))); +} diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c new file mode 100644 index 00000000..40c33543 --- /dev/null +++ b/42sh/src/line-editing/readline.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* readline.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:16 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_init_line(void) +{ + data_singleton()->line.input = NULL; + data_singleton()->line.prompt_size = 0; +} + +struct termios *ft_save_stats_term(void) +{ + static struct termios *term_save = NULL; + + if (!term_save) + { + term_save = (struct termios *)malloc(sizeof(struct termios)); + tcgetattr(0, term_save); + } + return (term_save); +} + +struct termios *ft_stats_term_termcaps(void) +{ + static struct termios *term = NULL; + + if (!term) + { + term = (struct termios *)malloc(sizeof(struct termios)); + tcgetattr(0, term); + (*term).c_lflag &= ~(ECHO | ICANON | ISIG); + (*term).c_cc[VMIN] = 1; + (*term).c_cc[VTIME] = 0; + } + return (term); +} + +int ft_readline(void) +{ + static t_list_history *head = NULL; + + ft_prompt(); + if (tcsetattr(0, TCSADRAIN, ft_stats_term_termcaps()) == -1) + return (-1); + data_singleton()->line.input = ft_lecture(head); + ft_putstr("\n"); + ft_check_quotes(&data_singleton()->line.input, head); + if (data_singleton()->line.input) + ft_push_back_history(&head, ft_create_history_list(data_singleton()->line.input)); + if (tcsetattr(0, TCSADRAIN, ft_save_stats_term()) == -1) + return (-1); + return (0); +} diff --git a/42sh/src/line-editing/rl_bitset.c b/42sh/src/line-editing/rl_bitset.c deleted file mode 100644 index 60190f51..00000000 --- a/42sh/src/line-editing/rl_bitset.c +++ /dev/null @@ -1,71 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_bitset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 10:31:34 by sbenning #+# #+# */ -/* Updated: 2016/12/12 13:26:06 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -static void rl_toogle_esc(t_line *line, int set) -{ - static int esc; - - if (!set) - esc = RL_IS(line->bitset, RL_ESC); - else if (set && esc) - { - RL_UNSET(line->bitset, RL_ESC); - esc = 0; - } -} - -static void rl_toogle_select(t_line *line, int set) -{ - static int select; - - if (!set) - select = RL_IS(line->bitset, RL_SELECT); - else if (set &&\ - ((select && RL_NOT(line->bitset, RL_SELECT)) ||\ - (!select && RL_IS(line->bitset, RL_SELECT)))) - rl_reset_display(line); -} - -void rl_toogle_bitset(t_line *line, int set) -{ - rl_toogle_esc(line, set); - rl_toogle_select(line, set); -} - -int rl_finish(t_line *line) -{ - int finish; - int stack; - - stack = RL_IS(line->bitset, RL_STACK); - finish = RL_IS(line->bitset, RL_FINISH); - if (!stack && !finish) - return (0); - rl_end_function(line, 0); - write(1, "\n", 1); - if (stack) - { - RL_UNSET(line->bitset, RL_STACK); - if (rl_stack_line(line) < 0) - return (-1); - } - if (finish) - return (1); - if (curs_coo_setup(&line->curs) < 0) - return (-1); - rl_set_prompt(line); - rl_put_prompt(line); - return (0); -} - diff --git a/42sh/src/line-editing/rl_clipboard_function.c b/42sh/src/line-editing/rl_clipboard_function.c deleted file mode 100644 index 5b884d97..00000000 --- a/42sh/src/line-editing/rl_clipboard_function.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_clipboard_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:32:11 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:34:12 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_copy_function(t_line *line, long int input) -{ - if (line->clipboard) - ft_memdel((void **)&line->clipboard); - if (rl_clipboard_new(line) < 0) - return (-1); - return (0); - (void)input; -} - -int rl_cut_function(t_line *line, long int input) -{ - if (line->clipboard) - ft_memdel((void **)&line->clipboard); - if (rl_clipboard_new_cut(line) < 0) - return (-1); - rl_reset_display_post(line); - return (0); - (void)input; -} - -int rl_paste_function(t_line *line, long int input) -{ - int len; - - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (!line->clipboard) - return (0); - len = ft_strlen(line->clipboard); - if (!len) - return (0); - if (RL_IS(line->bitset, RL_INSERT)) - { - if (input_move(line, line->clipboard, len) < 0) - return (-1); - } - else - { - if (input_maj(line, line->clipboard, len) < 0) - return (-1); - } - rl_reset_display_post(line); - curs_forward(&line->curs, len); - line->pos += len; - return (0); - (void)input; -} diff --git a/42sh/src/line-editing/rl_clipboard_utility.c b/42sh/src/line-editing/rl_clipboard_utility.c deleted file mode 100644 index 86b1987e..00000000 --- a/42sh/src/line-editing/rl_clipboard_utility.c +++ /dev/null @@ -1,95 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_clipboard.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/09 14:04:33 by sbenning #+# #+# */ -/* Updated: 2016/12/09 15:57:47 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_clipboard_new_selected(t_line *line) -{ - int start; - int size; - - RL_UNSET(line->bitset, RL_SELECT); - start = (line->select > line->pos) ? line->pos : line->select; - size = (line->select > line->pos ? line->select - line->pos : line->pos - line->select); - if ((line->clipboard = ft_strsub(line->input, start, (size_t)size)) == NULL) - return (-1); - return (0); -} - -int rl_clipboard_new_selected_cut(t_line *line) -{ - int start; - int size; - - RL_UNSET(line->bitset, RL_SELECT); - start = (line->select > line->pos) ? line->pos : line->select; - size = (line->select > line->pos ? line->select - line->pos : line->pos - line->select); - if ((line->clipboard = ft_strsub(line->input, start, (size_t)size)) == NULL) - return (-1); - if (line->pos != start) - { - curs_backward(&line->curs, line->pos - start); - line->pos = line->pos - (line->pos - start); - } - input_remove(line, -size); - return (0); -} - -int rl_clipboard_new(t_line *line) -{ - int start; - int real_pos; - int size; - - if (RL_IS(line->bitset, RL_SELECT)) - return (rl_clipboard_new_selected(line)); - size = line->curs.win_co; - RL_UNSET(line->bitset, RL_SELECT); - real_pos = line->pos + ft_strlen(line->prompt); - start = (real_pos / line->curs.win_co) * line->curs.win_co; - if (start) - start -= ft_strlen(line->prompt); - else - size -= ft_strlen(line->prompt); - if ((line->clipboard = ft_strsub(line->input, start, size)) == NULL) - return (-1); - return (0); -} - -int rl_clipboard_new_cut(t_line *line) -{ - int start; - int real_pos; - int size; - - if (RL_IS(line->bitset, RL_SELECT)) - return (rl_clipboard_new_selected_cut(line)); - size = line->curs.win_co; - RL_UNSET(line->bitset, RL_SELECT); - real_pos = line->pos + ft_strlen(line->prompt); - start = (real_pos / line->curs.win_co) * line->curs.win_co; - if (start) - start -= ft_strlen(line->prompt); - else - size -= ft_strlen(line->prompt); - if ((line->clipboard = ft_strsub(line->input, start, size)) == NULL) - return (-1); - if (line->pos != start) - { - curs_backward(&line->curs, line->pos - start); - line->pos = line->pos - (line->pos - start); - } - if (size > line->used - start) - size = line->used - start; - input_remove(line, -size); - return (0); -} diff --git a/42sh/src/line-editing/rl_comp_function.c b/42sh/src/line-editing/rl_comp_function.c deleted file mode 100644 index dd1d9729..00000000 --- a/42sh/src/line-editing/rl_comp_function.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_comp_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 10:49:03 by sbenning #+# #+# */ -/* Updated: 2017/01/10 11:51:19 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -static int ft_autocomp(t_data *data) -{ - return (0); - int li; - int co; - - li = data->line.curs.li; - co = data->line.curs.co; - ft_putstr("\nTeeeeeeest"); - data->line.input = ft_strjoin(data->line.input, " JOIN "); - curs_goto(&data->line.curs, li, co + 6); - return (0); -} - -int rl_comp_function(t_line *line, long int input) -{ - t_data *data; - - data = data_singleton(); - if (ft_autocomp(data) < 0) - return (-1); - line->size = ft_strlen(line->input); - line->used = line->size; - curs_reset(0); - return (0); - (void)input; -} diff --git a/42sh/src/line-editing/rl_default_function.c b/42sh/src/line-editing/rl_default_function.c deleted file mode 100644 index 5c953981..00000000 --- a/42sh/src/line-editing/rl_default_function.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_default_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 18:30:38 by sbenning #+# #+# */ -/* Updated: 2016/12/12 11:50:26 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_default_function(t_line *line, long int input) -{ - if (!ft_isprint(input)) - return (0); - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (RL_IS(line->bitset, RL_INSERT)) - { - if (input_move(line, (char *)&input, sizeof(char)) < 0) - return (-1); - } - else - { - if (input_maj(line, (char *)&input, sizeof(char)) < 0) - return (-1); - } - rl_reset_display_post(line); - curs_forward(&line->curs, sizeof(char)); - line->pos += 1; -/* curs_write(&line->curs, (char *)&input, sizeof(char)); - line->pos += 1; - rl_reset_display_post(line); -*/ return (0); -} diff --git a/42sh/src/line-editing/rl_display.c b/42sh/src/line-editing/rl_display.c deleted file mode 100644 index 26f787f5..00000000 --- a/42sh/src/line-editing/rl_display.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_display.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 18:38:39 by sbenning #+# #+# */ -/* Updated: 2016/12/10 11:52:18 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -void rl_reset_display_post(t_line *line) -{ - size_t len; - - len = ft_strlen(line->input + line->pos); - curs_clear_post(&line->curs); - if (len == 0) - return ; - if (RL_NOT(line->bitset, RL_SELECT) || (RL_IS(line->bitset, RL_SELECT) && line->select < line->pos)) - { - curs_write_static(&line->curs, line->input + line->pos, len); - return; - } - if (line->select == line->used) - { - curs_video_write_static(&line->curs, line->input + line->pos, len); - return ; - } - curs_video_write(&line->curs, line->input + line->pos, line->select - line->pos); - curs_write(&line->curs, line->input + line->select, line->used - line->select); - curs_backward(&line->curs, line->used - line->pos); -} - -void rl_reset_display_ante(t_line *line) -{ - if (!line->pos) - return ; - curs_backward(&line->curs, line->pos); - if (RL_NOT(line->bitset, RL_SELECT) || (RL_IS(line->bitset, RL_SELECT) && line->select > line->pos)) - { - curs_write(&line->curs, line->input, line->pos); - return ; - } - if (line->select == 0) - { - curs_video_write(&line->curs, line->input, line->pos); - return ; - } - curs_write(&line->curs, line->input, line->select); - curs_video_write(&line->curs, line->input + line->select, line->pos - line->select); -} - -void rl_reset_display(t_line *line) -{ - rl_reset_display_ante(line); - rl_reset_display_post(line); -} diff --git a/42sh/src/line-editing/rl_dynamic_buffer.c b/42sh/src/line-editing/rl_dynamic_buffer.c deleted file mode 100644 index d6f1a673..00000000 --- a/42sh/src/line-editing/rl_dynamic_buffer.c +++ /dev/null @@ -1,99 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* input_buffer.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 18:42:31 by sbenning #+# #+# */ -/* Updated: 2016/12/12 10:28:59 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - - -int input_extend(t_line *line, int size) -{ - char *tmp; - - size = (RL_OFFSET > size ? RL_OFFSET : size) + line->size; - if ((tmp = ft_strnew(size)) == NULL) - return (-1); - if (line->input) - { - ft_memcpy(tmp, line->input, line->size); - free(line->input); - } - line->input = tmp; - line->size = size; - return (0); -} - -int rl_dynamic_buffer_extend(t_line *line, int size) -{ - return (input_extend(line, size)); -} - -int input_maj(t_line *line, char *str, int size) -{ - if (line->used + size >= line->size) - { - if (rl_dynamic_buffer_extend(line, size) < 0) - return (-1); - } - ft_memcpy(line->input + line->pos, str, size); - if (line->pos + size > line->used) - line->used = line->pos + size; - return (0); -} - -int input_move(t_line *line, char *str, int size) -{ - char *dup; - - if (line->used + size >= line->size) - { - if (rl_dynamic_buffer_extend(line, size) < 0) - return (-1); - } - if ((dup = ft_strdup(line->input + line->pos)) == NULL) - return (-1); - ft_memcpy(line->input + line->pos, str, size); - ft_memcpy(line->input + line->pos + size, dup, ft_strlen(dup)); - free(dup); - line->used += size; - return (0); -} - -void input_remove(t_line *line, int size) -{ - char *start; - - if (size < 0) - { - start = line->input + line->pos; - size *= -1; - } - else - start = (line->input + line->pos) - size; - ft_strcpy(start, start + size); - line->used -= size; - ft_bzero(line->input + line->used, line->size - line->used); -} - - -int rl_dynamic_buffer_replace(t_line *line, char *str, int size) -{ - return (input_maj(line, str, size)); -} - -int rl_dynamic_buffer_insert(t_line *line, char *str, int size) -{ - return (input_move(line, str, size)); -} - -void rl_dynamic_buffer_remove(t_line *line, int size) -{ - input_remove(line, size); -} diff --git a/42sh/src/line-editing/rl_long_move_function.c b/42sh/src/line-editing/rl_long_move_function.c deleted file mode 100644 index 5769b90e..00000000 --- a/42sh/src/line-editing/rl_long_move_function.c +++ /dev/null @@ -1,65 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_long_move_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:55:48 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:57:16 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_home_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (!line->pos) - return (0); - curs_backward(&line->curs, line->pos); - line->pos = 0; - return (0); - (void)input; -} - -int rl_end_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (line->pos == line->used) - return (0); - curs_forward(&line->curs, line->used - line->pos); - line->pos = line->used; - return (0); - (void)input; -} - -int rl_select_home_function(t_line *line, long int input) -{ - int ret; - - if (!line->pos) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_home_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_post(line); - return (ret); -} - -int rl_select_end_function(t_line *line, long int input) -{ - int ret; - - if (line->pos == line->used) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_end_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_ante(line); - return (ret); -} diff --git a/42sh/src/line-editing/rl_merge_line.c b/42sh/src/line-editing/rl_merge_line.c deleted file mode 100644 index ed0b0ea3..00000000 --- a/42sh/src/line-editing/rl_merge_line.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_merge_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/09 01:25:03 by sbenning #+# #+# */ -/* Updated: 2016/12/12 11:34:02 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_merge_line(t_line *line) -{ - t_list *next; - char *chunk; - size_t size; - - while (line->stack) - { - next = line->stack->next; - chunk = (char *)line->stack->content; - size = line->stack->content_size - 1; - if (input_maj(line, chunk, size) < 0) - return (-1); - line->pos += size; - /* if (next) - { - if (input_maj(line, "\n", 1) < 0) - return (-1); - line->pos += 1; - } - */ free(chunk); - free(line->stack); - line->stack = next; - } - return (0); -} diff --git a/42sh/src/line-editing/rl_page_move_function.c b/42sh/src/line-editing/rl_page_move_function.c deleted file mode 100644 index efd20d87..00000000 --- a/42sh/src/line-editing/rl_page_move_function.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_page_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:39:57 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:42:37 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_pagedown_function(t_line *line, long int input) -{ - int len; - - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (line->pos == line->used) - return (0); - len = line->used - line->pos; - len = (line->curs.win_co > len ? len : line->curs.win_co); - curs_forward(&line->curs, len); - line->pos += len; - return (0); - (void)input; -} - -int rl_pageup_function(t_line *line, long int input) -{ - int len; - - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (!line->pos) - return (0); - len = (line->curs.win_co > line->pos ? line->pos : line->curs.win_co); - curs_backward(&line->curs, len); - line->pos -= len; - return (0); - (void)input; -} - -int rl_select_pagedown_function(t_line *line, long int input) -{ - int ret; - - if (line->pos == line->used) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_pagedown_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_ante(line); - return (ret); -} - -int rl_select_pageup_function(t_line *line, long int input) -{ - int ret; - - if (!line->pos) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_pageup_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_post(line); - return (ret); -} diff --git a/42sh/src/line-editing/rl_prompt.c b/42sh/src/line-editing/rl_prompt.c deleted file mode 100644 index 3dc9e4f0..00000000 --- a/42sh/src/line-editing/rl_prompt.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_prompt.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/09 01:45:09 by sbenning #+# #+# */ -/* Updated: 2017/01/10 16:41:28 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" -#include "job_control.h" - -void rl_set_prompt(t_line *line) -{ - if (RL_IS(line->bitset, RL_ESC)) - line->prompt = RL_PROMPT_ESC; - else if (RL_IS(line->bitset, RL_QUOTE)) - line->prompt = RL_PROMPT_QUOTE; - else if (RL_IS(line->bitset, RL_DQUOTE)) - line->prompt = RL_PROMPT_DQUOTE; - else - line->prompt = RL_PROMPT_DEFAULT; -} - -void rl_put_prompt(t_line *line) -{ - curs_write(&line->curs, line->prompt, ft_strlen(line->prompt)); -} diff --git a/42sh/src/line-editing/rl_quoting_function.c b/42sh/src/line-editing/rl_quoting_function.c deleted file mode 100644 index 57ce891e..00000000 --- a/42sh/src/line-editing/rl_quoting_function.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_quoting_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:35:25 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:36:41 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_esc_function(t_line *line, long int input) -{ - if (RL_NOT(line->bitset, RL_ESC)) - RL_SET(line->bitset, RL_ESC); - return (rl_default_function(line, input)); -} - -int rl_quote_function(t_line *line, long int input) -{ - if (RL_NOT(line->bitset, RL_ESC)) - { - if (RL_IS(line->bitset, RL_QUOTE)) - RL_UNSET(line->bitset, RL_QUOTE); - else - RL_SET(line->bitset, RL_QUOTE); - } - return (rl_default_function(line, input)); -} - -int rl_dquote_function(t_line *line, long int input) -{ - if (RL_NOT(line->bitset, RL_ESC)) - { - if (RL_IS(line->bitset, RL_DQUOTE)) - RL_UNSET(line->bitset, RL_DQUOTE); - else - RL_SET(line->bitset, RL_DQUOTE); - } - return (rl_default_function(line, input)); -} diff --git a/42sh/src/line-editing/rl_remove_function.c b/42sh/src/line-editing/rl_remove_function.c deleted file mode 100644 index feeab949..00000000 --- a/42sh/src/line-editing/rl_remove_function.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_remove_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:45:08 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:46:39 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_retarr_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (!line->pos) - return (0); - input_remove(line, 1); - curs_backward(&line->curs, 1); - line->pos -= 1; - rl_reset_display_post(line); - return (0); - (void)input; -} - -int rl_suppr_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (line->pos == line->used) - return (0); - input_remove(line, -1); - rl_reset_display_post(line); - return (0); - (void)input; -} diff --git a/42sh/src/line-editing/rl_setup.c b/42sh/src/line-editing/rl_setup.c deleted file mode 100644 index 3e68d63a..00000000 --- a/42sh/src/line-editing/rl_setup.c +++ /dev/null @@ -1,46 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_setup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 18:07:47 by sbenning #+# #+# */ -/* Updated: 2017/01/11 17:35:12 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_setup(t_line *line) -{ - if (SHELL_HAS_JOBC(data_singleton()->opts)) - do_job_notification(); - data_singleton()->opts &= ~SHELL_MODE_MASK; - data_singleton()->opts |= SHELL_MODE_INPUT; - ft_bzero(line, sizeof(t_line)); - if (curs_setup(&line->curs) < 0) - return (-1); - RL_SET(line->bitset, RL_INSERT); - rl_set_prompt(line); - return (0); -} - -int rl_cleanup(t_line *line) -{ - data_singleton()->opts &= ~SHELL_MODE_MASK; - data_singleton()->opts |= SHELL_MODE_EXEC; - if (curs_cleanup(&line->curs) < 0) - return (-1); - if (rl_merge_line(line) < 0) - return (-1); - return (0); -} - -void rl_teardown(t_line *line) -{ - rl_cleanup(line); - if (line->input) - ft_memdel((void **)&line->input); - line->pos = 0; -} diff --git a/42sh/src/line-editing/rl_short_move_function.c b/42sh/src/line-editing/rl_short_move_function.c deleted file mode 100644 index 8399cf19..00000000 --- a/42sh/src/line-editing/rl_short_move_function.c +++ /dev/null @@ -1,65 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_move_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:53:18 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:54:52 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_left_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (!line->pos) - return (0); - curs_backward(&line->curs, 1); - line->pos -= 1; - return (0); - (void)input; -} - -int rl_right_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - if (line->pos == line->used) - return (0); - curs_forward(&line->curs, 1); - line->pos += 1; - return (0); - (void)input; -} - -int rl_select_left_function(t_line *line, long int input) -{ - int ret; - - if (!line->pos) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_left_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_post(line); - return (ret); -} - -int rl_select_right_function(t_line *line, long int input) -{ - int ret; - - if (line->pos == line->used) - return (0); - if (!RL_IS(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_right_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_ante(line); - return (ret); -} diff --git a/42sh/src/line-editing/rl_stack_line.c b/42sh/src/line-editing/rl_stack_line.c deleted file mode 100644 index 3e1a538b..00000000 --- a/42sh/src/line-editing/rl_stack_line.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_stack_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/09 01:06:54 by sbenning #+# #+# */ -/* Updated: 2017/01/10 13:07:37 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_stack_line(t_line *line) -{ - t_list *elem; - - elem = ft_lstnew(line->input, line->used + 1); - if (elem == NULL) - return (-1); - ft_lsteadd(&line->stack, elem); - ft_memdel((void **)&line->input); - line->pos = 0; - line->size = 0; - line->used = 0; - if (RL_NOT(line->bitset, RL_ESC)) - return (0); - elem = ft_lstnew("\n", 2); - if (elem == NULL) - return (-1); - ft_lsteadd(&line->stack, elem); - return (0); -} diff --git a/42sh/src/line-editing/rl_state_function.c b/42sh/src/line-editing/rl_state_function.c deleted file mode 100644 index 200961d8..00000000 --- a/42sh/src/line-editing/rl_state_function.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_state_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 13:00:59 by sbenning #+# #+# */ -/* Updated: 2016/12/12 13:01:51 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_insert_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_INSERT)) - RL_UNSET(line->bitset, RL_INSERT); - else - RL_SET(line->bitset, RL_INSERT); - return (0); - (void)input; -} - -int rl_nl_function(t_line *line, long int input) -{ - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - RL_SET(line->bitset, RL_STACK); - if (RL_NOT(line->bitset, RL_QUOTING)) - RL_SET(line->bitset, RL_FINISH); - return (0); - (void)input; -} diff --git a/42sh/src/line-editing/rl_word_move_function.c b/42sh/src/line-editing/rl_word_move_function.c deleted file mode 100644 index 205d9046..00000000 --- a/42sh/src/line-editing/rl_word_move_function.c +++ /dev/null @@ -1,67 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_word_function.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:47:31 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:51:53 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_wleft_function(t_line *line, long int input) -{ - size_t len; - - if (!line->pos) - return (0); - len = rl_previous_word(line); - curs_backward(&line->curs, len); - line->pos -= len; - return (0); - (void)input; -} - -int rl_wright_function(t_line *line, long int input) -{ - size_t len; - - if (line->pos == line->used) - return (0); - len = rl_next_word(line); - curs_forward(&line->curs, len); - line->pos += len; - return (0); - (void)input; -} - -int rl_select_wleft_function(t_line *line, long int input) -{ - int ret; - - if (!line->pos) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_wleft_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_post(line); - return (ret); -} - -int rl_select_wright_function(t_line *line, long int input) -{ - int ret; - - if (line->pos == line->used) - return (0); - if (RL_NOT(line->bitset, RL_SELECT)) - line->select = line->pos; - ret = rl_wright_function(line, input); - RL_SET(line->bitset, RL_SELECT); - rl_reset_display_ante(line); - return (ret); -} diff --git a/42sh/src/line-editing/rl_word_utility.c b/42sh/src/line-editing/rl_word_utility.c deleted file mode 100644 index 46010b9f..00000000 --- a/42sh/src/line-editing/rl_word_utility.c +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_word_utility.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 12:48:07 by sbenning #+# #+# */ -/* Updated: 2016/12/12 12:50:44 by sbenning ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -int rl_previous_word(t_line *line) -{ - int i; - int len; - - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - i = 0; - while (line->input[i] && i < line->pos) - { - if (!i && line->input[i] != ' ') - len = i; - if (i && line->input[i - 1] == ' ' && line->input[i] != ' ') - len = i; - i++; - } - return (line->pos - len); -} - -int rl_next_word(t_line *line) -{ - int i; - int flag; - - if (RL_IS(line->bitset, RL_SELECT)) - RL_UNSET(line->bitset, RL_SELECT); - i = line->pos; - flag = 0; - while (line->input[i] && (line->input[i] == ' ' || !flag)) - { - if (line->input[i] == ' ') - flag = 1; - i++; - } - return (i - line->pos); -} - diff --git a/42sh/src/line-editing/toolz.c b/42sh/src/line-editing/toolz.c new file mode 100644 index 00000000..45bab9f5 --- /dev/null +++ b/42sh/src/line-editing/toolz.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* toolz.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:28 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_putnc(char c, int n) +{ + int i; + + i = 0; + while (i < n) + { + write(1, &c, 1); + ++i; + } +} + +void ft_free_tabstr(char ***env) +{ + int i; + + i = 0; + while ((*env)[i]) + { + free((*env)[i]); + ++i; + } + free(*env); + env = NULL; +} + +int ft_is_whitespaces(char *str) +{ + int i; + + i = 0; + while (str[i]) + { + if (str[i] != '\t' || str[i] != ' ') + return (1); + ++i; + } + return (0); +} + + +char *ft_strndup(char const *s, int n) +{ + int i; + char *str; + + i = 0; + str = (char *)malloc(sizeof(char) * (n + 1)); + if (str) + { + while (i < n) + { + str[i] = s[i]; + i++; + } + str[i] = '\0'; + } + return (str); +} + +char *ft_strdupi(char const *s) +{ + int i; + char *str; + + i = 0; + while (s[i] && s[i] != ';' && s[i] != '>' && s[i] != '<' + && ft_strncmp(s + i, "||", 2)) + i++; + str = (char *)malloc(sizeof(char) * (i + 1)); + if (str) + { + str[i--] = '\0'; + while (i >= 0) + { + str[i] = s[i]; + i--; + } + } + return (str); +} diff --git a/42sh/src/line-editing/curs_goto.c b/42sh/src/line-editing/toolz2.c similarity index 50% rename from 42sh/src/line-editing/curs_goto.c rename to 42sh/src/line-editing/toolz2.c index 389c982d..bb667269 100644 --- a/42sh/src/line-editing/curs_goto.c +++ b/42sh/src/line-editing/toolz2.c @@ -1,31 +1,44 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* curs_goto.c :+: :+: :+: */ +/* toolz2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ +/* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:10:22 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:58:26 by sbenning ### ########.fr */ +/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:32 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ft_curs.h" +#include "minishell.h" -/* - * Move the cursor to the given coordonate // scroll screen if line is unreachable -*/ - -void curs_goto(t_curs *curs, int li, int co) +void ft_puttermcaps(char *str) { - if (co >= curs->win_co) - co = curs->win_co - 1; - if (li >= curs->win_li) - { - ft_putstr(tgetstr("sf", NULL)); - li = curs->win_li - 1; - } - ft_putstr(tgoto(tgetstr("cm", NULL), co, li)); - curs->li = li; - curs->co = co; + char *res; + char *env; + + env = getenv("TERM"); + if ((res = tgetstr(str, &env)) == NULL) + return ; + tputs(res, 0, ft_put); +} + +int ft_size_term(void) +{ + return (tgetnum("co")); +} + +long long ft_pow(int nbr, int power) +{ + int i; + long long ret; + + i = 0; + ret = 1; + while (i < power) + { + ret *= nbr; + i++; + } + return (ret); } diff --git a/42sh/src/line-editing/toolz_parseur.c b/42sh/src/line-editing/toolz_parseur.c new file mode 100644 index 00000000..55c1881c --- /dev/null +++ b/42sh/src/line-editing/toolz_parseur.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* toolz_parseur.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:19 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +char *ft_realloc_imput(char *str, int a, size_t pos) +{ + int i; + char tmp[2]; + char *str_tmp; + char *new_str; + + i = 0; + tmp[0] = (char)a; + tmp[1] = '\0'; + if (!str) + { + new_str = ft_strdup(tmp); + return (new_str); + } + str_tmp = ft_strndup(str, pos); + new_str = ft_strjoin(str_tmp, tmp); + free(str_tmp); + str_tmp = ft_strjoin(new_str, str + pos); + free(new_str); + free(str); + return (str_tmp); +} + +char *ft_remove_imput(char *str, size_t pos) +{ + int i; + char *new_str; + char *new_str2; + + i = 0; + if (!str) + return (str); + new_str = ft_strndup(str, pos); + new_str2 = ft_strjoin(new_str, &str[pos + 1]); + free(str); + free(new_str); + return (new_str2); +} + +static int ft_found_prev_word_pos(char *str, size_t *pos) +{ + size_t tmp; + + tmp = *pos; + while ((tmp) && (str[tmp] == ' ' || str[tmp] == '\n')) + --tmp; + while ((tmp) && str[tmp] != ' ' && str[tmp] != '\n') + --tmp; + return (tmp); +} + +void ft_found_prev_word(char *str, size_t *pos) +{ + size_t tmp; + + tmp = *pos; + ft_move_to_beggin(str, pos); + *pos = tmp; + tmp = ft_found_prev_word_pos(str, pos); + write(1, str, tmp); + *pos = tmp; +} + +void ft_found_next_word(char *str, size_t *pos) +{ + while (str[(*pos)] == ' ' || str[(*pos)] == '\n') + { + ft_putchar(str[(*pos)]); + ++(*pos); + } + while (str[(*pos)] && str[(*pos)] != ' ' && str[(*pos)] != '\n') + { + ft_putchar(str[(*pos)]); + ++(*pos); + } +} diff --git a/42sh/src/line-editing/toolz_termcaps.c b/42sh/src/line-editing/toolz_termcaps.c new file mode 100644 index 00000000..4607aeab --- /dev/null +++ b/42sh/src/line-editing/toolz_termcaps.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* toolz_termcaps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */ +/* Updated: 2017/01/19 16:43:23 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int ft_get_ind_prev(char *str, size_t pos) +{ + while (pos && str[pos] != '\n') + --pos; + return (pos); +} + +int ft_get_size_prev(char *str, size_t pos) +{ + size_t len; + + len = 0; + while (pos && str[pos] != '\n') + { + --pos; + ++len; + } + return (len); +} + +int ft_nb_line(char *str, size_t pos) +{ + int len; + + len = 0; + if (!ft_get_ind_prev(str, pos)) + len += data_singleton()->line.prompt_size; + len += ft_get_size_prev(str, pos); + return (len / ft_size_term()); +} + +int ft_nb_last_line(char *str, size_t pos) +{ + int len; + + len = 0; + if (!ft_get_ind_prev(str, pos)) + len += data_singleton()->line.prompt_size; + len += ft_get_size_prev(str, pos); + return (len % ft_size_term()); +} + +void ft_move_to_beggin(char *str, size_t *pos) +{ + size_t str_len; + int prompt_size; + + prompt_size = data_singleton()->line.prompt_size; + str_len = 0; + if (!str) + return ; + if (str[*pos] == '\n') + { + ft_putchar('\b'); + --(*pos); + } + while (*pos && str[*pos] != '\n') + { + ft_putchar('\b'); + --(*pos); + } + while (*pos && --prompt_size + 2) + ft_puttermcaps("nd"); + while (*pos) + { + if (str[*pos] == '\n') + { + str_len = ft_nb_line(str, *pos - 1) + 1; + while (str_len) + { + ft_puttermcaps("up"); + --str_len; + } + } + --(*pos); + } +} diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 1829cbd1..5a0791ae 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* data_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/01/11 14:03:16 by jhalford ### ########.fr */ +/* Updated: 2017/01/19 16:26:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,6 @@ int data_init(void) t_data *data; data = data_singleton(); - data->line.input = NULL; data->env = ft_sstrdup(environ); data->opts = SHELL_OPTS_JOBC; diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 27e00034..0a8c2043 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/01/12 14:02:30 by jhalford ### ########.fr */ +/* Updated: 2017/01/19 16:46:55 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,7 @@ int shell_single_command(char *command) int main(int ac, char **av) { + setlocale(LC_ALL, ""); DG("{inv}{bol}{gre}start of shell{eoc} job_control is %s", data_singleton()->opts & SHELL_OPTS_JOBC ? "ON" : "OFF"); shell_init(ac, av); if (data_singleton()->opts & SHELL_OPTS_LC)