Merge 42sh with full history
This commit is contained in:
commit
4ccfb89154
519 changed files with 24667 additions and 0 deletions
20
42sh/.gitignore
vendored
Normal file
20
42sh/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
minishell
|
||||||
|
21sh
|
||||||
|
42sh
|
||||||
|
out
|
||||||
|
STDBUG
|
||||||
|
debug
|
||||||
|
.42sh_history
|
||||||
|
*.dSYM
|
||||||
|
.script.sh.swp
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*.o
|
||||||
|
*.swn
|
||||||
|
STDBUG
|
||||||
|
STDEBUG
|
||||||
|
display_env
|
||||||
|
read_on_stdin
|
||||||
|
write_on_stderr
|
||||||
|
write_on_stdout
|
||||||
|
write_on_stdout_and_stderr
|
||||||
3
42sh/.gitmodules
vendored
Normal file
3
42sh/.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "libft"]
|
||||||
|
path = libft
|
||||||
|
url = https://github.com/jzck/libft.git
|
||||||
48
42sh/.tags
Normal file
48
42sh/.tags
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
HAS_CDOPT_L src/builtin/builtin_cd.c /^#define HAS_CDOPT_L(x) (x & CD_OPT_L)$/
|
||||||
|
HAS_CDOPT_P src/builtin/builtin_cd.c /^#define HAS_CDOPT_P(x) (x & CD_OPT_P)$/
|
||||||
|
Mmain src/main/main.c /^int main(void)$/
|
||||||
|
builtin_cd src/builtin/builtin_cd.c /^int builtin_cd(char **av, char ***env_p)$/
|
||||||
|
builtin_cd_opts src/builtin/builtin_cd.c /^int builtin_cd_opts(char **av, int *opts)$/
|
||||||
|
builtin_cd_special src/builtin/builtin_cd.c /^char *builtin_cd_special(char **av, char **env)$/
|
||||||
|
builtin_echo src/builtin/builtin_echo.c /^int builtin_echo(char **av, char ***env_p)$/
|
||||||
|
builtin_env src/builtin/builtin_env.c /^int builtin_env(char **av, char ***env_p)$/
|
||||||
|
builtin_exit src/builtin/builtin_exit.c /^int builtin_exit(char **av, char ***env_p)$/
|
||||||
|
builtin_setenv src/builtin/builtin_setenv.c /^int builtin_setenv(char **av, char ***env_p)$/
|
||||||
|
builtin_unsetenv src/builtin/builtin_unsetenv.c /^int builtin_unsetenv(char **av, char ***env_p)$/
|
||||||
|
ft_builtin src/builtin/builtin.c /^int ft_builtin(char **av, char ***env_p)$/
|
||||||
|
ft_clear_line src/line-editing/ft_clear_line.c /^int ft_clear_line(t_data *data, t_dlist **input_c/
|
||||||
|
ft_cmd_exec src/minishell-exec/ft_cmd.c /^int ft_cmd_exec(char *execpath, char **argv, char/
|
||||||
|
ft_cmd_getav src/minishell-exec/ft_cmd.c /^char **ft_cmd_getav(char *cmd)$/
|
||||||
|
ft_cmd_process src/minishell-exec/ft_cmd.c /^int ft_cmd_process(char **argv, char ***env_p)$/
|
||||||
|
ft_cursor_left src/line-editing/ft_cursor_left.c /^int ft_cursor_left(t_data *data, t_dlist **input_/
|
||||||
|
ft_cursor_right src/line-editing/ft_cursor_right.c /^int ft_cursor_right(t_data *data, t_dlist **input/
|
||||||
|
ft_env_getval src/main/lib_env.c /^char *ft_env_getval(char **env, char *key)$/
|
||||||
|
ft_expand_dollar src/main/lib_expansion.c /^void ft_expand_dollar(char **av, char **env)$/
|
||||||
|
ft_history_add src/line-editing/ft_history_add.c /^int ft_history_add(t_data *data, t_dlist *input_c/
|
||||||
|
ft_history_down src/line-editing/ft_history_down.c /^int ft_history_down(t_data *data, t_dlist **input/
|
||||||
|
ft_history_up src/line-editing/ft_history_up.c /^int ft_history_up(t_data *data, t_dlist **input_c/
|
||||||
|
ft_input_is_escaped src/line-editing/ft_input_is_escaped.c /^int ft_input_is_escaped(t_dlist *input_chain)$/
|
||||||
|
ft_interactive_sh src/line-editing/ft_interactive_sh.c /^int ft_interactive_sh(t_data *data)$/
|
||||||
|
ft_key_basic src/line-editing/ft_key_basic.c /^int ft_key_basic(t_data *data, t_dlist **input_cha/
|
||||||
|
ft_key_ctrl_d src/line-editing/ft_key_ctrl_d.c /^int ft_key_ctrl_d(t_data *data, t_dlist **input_c/
|
||||||
|
ft_key_del src/line-editing/ft_key_del.c /^int ft_key_del(t_data *data, t_dlist **input_chai/
|
||||||
|
ft_key_enter src/line-editing/ft_key_enter.c /^int ft_key_enter(t_data *data, t_dlist **input_ch/
|
||||||
|
ft_line_end src/line-editing/ft_line_end.c /^int ft_line_end(t_data *data, t_dlist **input_cha/
|
||||||
|
ft_line_go_down src/line-editing/ft_line_down.c /^int ft_line_go_down(t_dlist **input_chain)$/
|
||||||
|
ft_line_go_up src/line-editing/ft_line_up.c /^int ft_line_go_up(t_dlist **input_chain)$/
|
||||||
|
ft_line_start src/line-editing/ft_line_start.c /^int ft_line_start(t_data *data, t_dlist **input_c/
|
||||||
|
ft_path_access src/main/lib_path.c /^int ft_path_access(char *execpath, char *execname/
|
||||||
|
ft_path_findexec src/main/lib_path.c /^char *ft_path_findexec(char **path, char *execname/
|
||||||
|
ft_prompt src/line-editing/ft_prompt.c /^int ft_prompt(void)$/
|
||||||
|
ft_tc_init src/line-editing/ft_tc_init.c /^int ft_tc_init(t_data *data)$/
|
||||||
|
ft_tokenize src/token/ft_tokenize.c /^int ft_tokenize(t_list **alst, char *str)$/
|
||||||
|
ft_word_left src/line-editing/ft_word_left.c /^int ft_word_left(t_data *data, t_dlist **input_ch/
|
||||||
|
ft_word_right src/line-editing/ft_word_right.c /^int ft_word_right(t_data *data, t_dlist **input_c/
|
||||||
|
is_separator src/token/token_getnext.c /^static int is_separator(char c)$/
|
||||||
|
is_stop_char src/token/token_getnext.c /^static int is_stop_char(char c)$/
|
||||||
|
sig_handler src/main/sig_handler.c /^void sig_handler(int signo)$/
|
||||||
|
token_append src/token/token_append.c /^int token_append(t_token *token, char c)$/
|
||||||
|
token_free src/token/token_free.c /^void token_free(void *data, size_t size)$/
|
||||||
|
token_getnext src/token/token_getnext.c /^t_token *token_getnext(int *pos, char *line)$/
|
||||||
|
token_init src/token/token_init.c /^t_token *token_init()$/
|
||||||
|
token_print src/token/token_print.c /^void token_print(t_list *lst)$/
|
||||||
375
42sh/Makefile
Normal file
375
42sh/Makefile
Normal file
|
|
@ -0,0 +1,375 @@
|
||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
|
# Updated: 2017/03/29 17:03:53 by ariard ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = 42sh
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
FLAGS = -Wall -Wextra -Werror
|
||||||
|
D_FLAGS = -g
|
||||||
|
|
||||||
|
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||||
|
|
||||||
|
LIBFT_DIR = libft/
|
||||||
|
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
||||||
|
LIBFT_INC = $(LIBFT_DIR)includes/
|
||||||
|
|
||||||
|
LIBS = -ltermcap
|
||||||
|
|
||||||
|
SRC_DIR = src/
|
||||||
|
INC_DIR = includes/
|
||||||
|
OBJ_DIR = objs/
|
||||||
|
|
||||||
|
SRC_BASE = \
|
||||||
|
builtin/bt_env_opt.c\
|
||||||
|
builtin/bt_read_get.c\
|
||||||
|
builtin/bt_read_term.c\
|
||||||
|
builtin/builtin_cd.c\
|
||||||
|
builtin/builtin_echo.c\
|
||||||
|
builtin/builtin_env.c\
|
||||||
|
builtin/builtin_exit.c\
|
||||||
|
builtin/builtin_export.c\
|
||||||
|
builtin/builtin_func.c\
|
||||||
|
builtin/builtin_hash.c\
|
||||||
|
builtin/builtin_history.c\
|
||||||
|
builtin/builtin_math.c\
|
||||||
|
builtin/builtin_read.c\
|
||||||
|
builtin/builtin_setenv.c\
|
||||||
|
builtin/builtin_unset.c\
|
||||||
|
builtin/builtin_unsetenv.c\
|
||||||
|
builtin/is_builtin.c\
|
||||||
|
completion/c_arrow.c\
|
||||||
|
completion/c_clear.c\
|
||||||
|
completion/c_find_abspath.c\
|
||||||
|
completion/c_find_binary.c\
|
||||||
|
completion/c_find_env.c\
|
||||||
|
completion/c_find_files.c\
|
||||||
|
completion/c_init.c\
|
||||||
|
completion/c_match.c\
|
||||||
|
completion/c_match_glob.c\
|
||||||
|
completion/c_match_update.c\
|
||||||
|
completion/c_misc.c\
|
||||||
|
completion/c_output.c\
|
||||||
|
completion/c_parser.c\
|
||||||
|
completion/c_pathsolver.c\
|
||||||
|
completion/c_printer.c\
|
||||||
|
completion/c_sizing.c\
|
||||||
|
completion/c_terminal.c\
|
||||||
|
completion/completion.c\
|
||||||
|
exec/ast_free.c\
|
||||||
|
exec/bad_fd.c\
|
||||||
|
exec/exec_ampersand.c\
|
||||||
|
exec/exec_and_if.c\
|
||||||
|
exec/exec_bang.c\
|
||||||
|
exec/exec_case_branch.c\
|
||||||
|
exec/exec_destroy.c\
|
||||||
|
exec/exec_elif.c\
|
||||||
|
exec/exec_else.c\
|
||||||
|
exec/exec_func.c\
|
||||||
|
exec/exec_init.c\
|
||||||
|
exec/exec_leaf.c\
|
||||||
|
exec/exec_or_if.c\
|
||||||
|
exec/exec_pipe.c\
|
||||||
|
exec/exec_semi.c\
|
||||||
|
exec/exec_var.c\
|
||||||
|
exec/fd_is_valid.c\
|
||||||
|
exec/ft_exec.c\
|
||||||
|
exec/ft_findexec.c\
|
||||||
|
exec/is_function.c\
|
||||||
|
exec/mark_process_status.c\
|
||||||
|
exec/node_copy.c\
|
||||||
|
exec/pfree_cmd.c\
|
||||||
|
exec/pfree_cond.c\
|
||||||
|
exec/pfree_func.c\
|
||||||
|
exec/pfree_list.c\
|
||||||
|
exec/pfree_subshell.c\
|
||||||
|
exec/plaunch_brace.c\
|
||||||
|
exec/plaunch_builtin.c\
|
||||||
|
exec/plaunch_case.c\
|
||||||
|
exec/plaunch_empty.c\
|
||||||
|
exec/plaunch_file.c\
|
||||||
|
exec/plaunch_for.c\
|
||||||
|
exec/plaunch_function.c\
|
||||||
|
exec/plaunch_if.c\
|
||||||
|
exec/plaunch_subshell.c\
|
||||||
|
exec/plaunch_until.c\
|
||||||
|
exec/plaunch_while.c\
|
||||||
|
exec/process_launch.c\
|
||||||
|
exec/process_redirect.c\
|
||||||
|
exec/process_set.c\
|
||||||
|
exec/process_setgroup.c\
|
||||||
|
exec/process_setsig.c\
|
||||||
|
exec/pset_brace.c\
|
||||||
|
exec/pset_case.c\
|
||||||
|
exec/pset_cmd.c\
|
||||||
|
exec/pset_for.c\
|
||||||
|
exec/pset_if.c\
|
||||||
|
exec/pset_subshell.c\
|
||||||
|
exec/pset_until.c\
|
||||||
|
exec/pset_while.c\
|
||||||
|
exec/redir_copy.c\
|
||||||
|
exec/redir_free.c\
|
||||||
|
exec/redirect_dgreat.c\
|
||||||
|
exec/redirect_dless.c\
|
||||||
|
exec/redirect_great.c\
|
||||||
|
exec/redirect_greatand.c\
|
||||||
|
exec/redirect_less.c\
|
||||||
|
exec/redirect_lessand.c\
|
||||||
|
exec/set_exitstatus.c\
|
||||||
|
exec/token_to_argv.c\
|
||||||
|
glob/command_getoutput.c\
|
||||||
|
glob/dir_glob.c\
|
||||||
|
glob/esc_print.c\
|
||||||
|
glob/expand_bquote.c\
|
||||||
|
glob/expand_brace.c\
|
||||||
|
glob/expand_esc.c\
|
||||||
|
glob/expand_home.c\
|
||||||
|
glob/expand_var.c\
|
||||||
|
glob/ft_strsplit_esc.c\
|
||||||
|
glob/ft_strsplit_spe.c\
|
||||||
|
glob/gen_tab_esc.c\
|
||||||
|
glob/glob.c\
|
||||||
|
glob/is_char_esc.c\
|
||||||
|
glob/lib_perso/ft_ld_back.c\
|
||||||
|
glob/lib_perso/ft_ld_clear.c\
|
||||||
|
glob/lib_perso/ft_ld_copy.c\
|
||||||
|
glob/lib_perso/ft_ld_del.c\
|
||||||
|
glob/lib_perso/ft_ld_front.c\
|
||||||
|
glob/lib_perso/ft_ld_new.c\
|
||||||
|
glob/lib_perso/ft_ld_order.c\
|
||||||
|
glob/lib_perso/ft_ld_pushback.c\
|
||||||
|
glob/lib_perso/ft_ld_pushfront.c\
|
||||||
|
glob/lib_perso/ft_ld_reverse.c\
|
||||||
|
glob/lib_perso/ft_ld_size.c\
|
||||||
|
glob/lib_perso/ft_ld_swap.c\
|
||||||
|
glob/lib_perso/ft_ld_to_tab.c\
|
||||||
|
glob/lib_perso/ft_memrealloc.c\
|
||||||
|
glob/lib_perso/ft_strjoinf.c\
|
||||||
|
glob/lib_perso/ft_strsubf.c\
|
||||||
|
glob/lib_perso/ft_tabdel.c\
|
||||||
|
glob/lib_perso/ft_tablen.c\
|
||||||
|
glob/match_pattern.c\
|
||||||
|
glob/tab_esc_copy.c\
|
||||||
|
glob/word_is_assignment.c\
|
||||||
|
hash_table/ft_add_hash.c\
|
||||||
|
hash_table/hash.c\
|
||||||
|
hash_table/hash_free.c\
|
||||||
|
hash_table/hash_str.c\
|
||||||
|
hash_table/is_hash.c\
|
||||||
|
history/add_str_in_history.c\
|
||||||
|
history/history.c\
|
||||||
|
history/history_parsing.c\
|
||||||
|
history/history_parsing_toolz.c\
|
||||||
|
history/history_parsing_toolz_2.c\
|
||||||
|
history/list_toolz.c\
|
||||||
|
history/surch_in_history.c\
|
||||||
|
job_control/builtin_bg.c\
|
||||||
|
job_control/builtin_fg.c\
|
||||||
|
job_control/builtin_jobs.c\
|
||||||
|
job_control/do_job_notification.c\
|
||||||
|
job_control/has_running_job.c\
|
||||||
|
job_control/has_stopped_job.c\
|
||||||
|
job_control/job_addprocess.c\
|
||||||
|
job_control/job_cmp_id.c\
|
||||||
|
job_control/job_format.c\
|
||||||
|
job_control/job_format_head.c\
|
||||||
|
job_control/job_free.c\
|
||||||
|
job_control/job_getprocess.c\
|
||||||
|
job_control/job_getrank.c\
|
||||||
|
job_control/job_hup_all.c\
|
||||||
|
job_control/job_is_completed.c\
|
||||||
|
job_control/job_is_stopped.c\
|
||||||
|
job_control/job_notify_change.c\
|
||||||
|
job_control/job_notify_new.c\
|
||||||
|
job_control/job_remove.c\
|
||||||
|
job_control/job_run.c\
|
||||||
|
job_control/job_update_id.c\
|
||||||
|
job_control/job_update_status.c\
|
||||||
|
job_control/job_wait.c\
|
||||||
|
job_control/jobc_destroy.c\
|
||||||
|
job_control/jobc_init.c\
|
||||||
|
job_control/mark_job_as_running.c\
|
||||||
|
job_control/pprint_brace.c\
|
||||||
|
job_control/pprint_case.c\
|
||||||
|
job_control/pprint_cmd.c\
|
||||||
|
job_control/pprint_for.c\
|
||||||
|
job_control/pprint_function.c\
|
||||||
|
job_control/pprint_if.c\
|
||||||
|
job_control/pprint_subshell.c\
|
||||||
|
job_control/pprint_until.c\
|
||||||
|
job_control/pprint_while.c\
|
||||||
|
job_control/process_cmp_pid.c\
|
||||||
|
job_control/process_format.c\
|
||||||
|
job_control/process_free.c\
|
||||||
|
job_control/put_job_in_background.c\
|
||||||
|
job_control/put_job_in_foreground.c\
|
||||||
|
job_control/sigchld_handler.c\
|
||||||
|
job_control/sigint_handler.c\
|
||||||
|
job_control/sigtstp_handler.c\
|
||||||
|
job_control/sigttin_handler.c\
|
||||||
|
job_control/sigttou_handler.c\
|
||||||
|
lexer/do_lexer_routine.c\
|
||||||
|
lexer/get_lexer_stack.c\
|
||||||
|
lexer/get_lexer_stack2.c\
|
||||||
|
lexer/get_reserved_words.c\
|
||||||
|
lexer/get_state_global.c\
|
||||||
|
lexer/get_state_redir.c\
|
||||||
|
lexer/insert_newline.c\
|
||||||
|
lexer/isrw_delim.c\
|
||||||
|
lexer/keep_last_type.c\
|
||||||
|
lexer/lexer_backslash.c\
|
||||||
|
lexer/lexer_bquote.c\
|
||||||
|
lexer/lexer_curly_braces.c\
|
||||||
|
lexer/lexer_default.c\
|
||||||
|
lexer/lexer_delim.c\
|
||||||
|
lexer/lexer_destroy.c\
|
||||||
|
lexer/lexer_dquote.c\
|
||||||
|
lexer/lexer_end.c\
|
||||||
|
lexer/lexer_great.c\
|
||||||
|
lexer/lexer_heredoc.c\
|
||||||
|
lexer/lexer_init.c\
|
||||||
|
lexer/lexer_less.c\
|
||||||
|
lexer/lexer_lex.c\
|
||||||
|
lexer/lexer_newline.c\
|
||||||
|
lexer/lexer_number.c\
|
||||||
|
lexer/lexer_paren.c\
|
||||||
|
lexer/lexer_quote.c\
|
||||||
|
lexer/lexer_sep.c\
|
||||||
|
lexer/lexer_word.c\
|
||||||
|
lexer/token_append.c\
|
||||||
|
lexer/token_cmp_type.c\
|
||||||
|
lexer/token_free.c\
|
||||||
|
lexer/token_init.c\
|
||||||
|
line_editing/control_features.c\
|
||||||
|
line_editing/copy_cut_paste/copy_cut_paste.c\
|
||||||
|
line_editing/copy_cut_paste/underline_down.c\
|
||||||
|
line_editing/copy_cut_paste/underline_end.c\
|
||||||
|
line_editing/copy_cut_paste/underline_function.c\
|
||||||
|
line_editing/copy_cut_paste/underline_home.c\
|
||||||
|
line_editing/copy_cut_paste/underline_left.c\
|
||||||
|
line_editing/copy_cut_paste/underline_reset.c\
|
||||||
|
line_editing/copy_cut_paste/underline_right.c\
|
||||||
|
line_editing/copy_cut_paste/underline_up.c\
|
||||||
|
line_editing/ft_prompt.c\
|
||||||
|
line_editing/get_key.c\
|
||||||
|
line_editing/init_line/init_history.c\
|
||||||
|
line_editing/init_line/init_line.c\
|
||||||
|
line_editing/init_line/init_termcaps.c\
|
||||||
|
line_editing/lib_line_editing/ft_nb_line.c\
|
||||||
|
line_editing/lib_line_editing/tool_line.c\
|
||||||
|
line_editing/lib_line_editing/tool_line_2.c\
|
||||||
|
line_editing/lib_line_editing/toolz.c\
|
||||||
|
line_editing/lib_line_editing/toolz2.c\
|
||||||
|
line_editing/lib_line_editing/toolz_parseur.c\
|
||||||
|
line_editing/lib_line_editing/toolz_termcaps.c\
|
||||||
|
line_editing/move_term/home_end.c\
|
||||||
|
line_editing/move_term/move_left_and_right.c\
|
||||||
|
line_editing/move_term/move_to_word.c\
|
||||||
|
line_editing/move_term/move_up_and_down.c\
|
||||||
|
line_editing/print_del_completion/completion.c\
|
||||||
|
line_editing/print_del_completion/print_and_del.c\
|
||||||
|
line_editing/print_del_completion/queue.c\
|
||||||
|
line_editing/readline.c\
|
||||||
|
line_editing/resize.c\
|
||||||
|
main/data_exit.c\
|
||||||
|
main/data_init.c\
|
||||||
|
main/data_singleton.c\
|
||||||
|
main/main.c\
|
||||||
|
main/shell_fds.c\
|
||||||
|
main/shell_init.c\
|
||||||
|
main/shell_sig.c\
|
||||||
|
parser/add_bang.c\
|
||||||
|
parser/add_case.c\
|
||||||
|
parser/add_cmd.c\
|
||||||
|
parser/add_condition.c\
|
||||||
|
parser/add_func.c\
|
||||||
|
parser/add_loop.c\
|
||||||
|
parser/add_number.c\
|
||||||
|
parser/add_redir.c\
|
||||||
|
parser/add_sep.c\
|
||||||
|
parser/add_subshell.c\
|
||||||
|
parser/aggregate_sym.c\
|
||||||
|
parser/build_tree.c\
|
||||||
|
parser/do_parser_routine.c\
|
||||||
|
parser/error_syntax.c\
|
||||||
|
parser/eval_sym.c\
|
||||||
|
parser/ft_parse.c\
|
||||||
|
parser/heredoc_parser.c\
|
||||||
|
parser/parser_destroy.c\
|
||||||
|
parser/parser_init.c\
|
||||||
|
parser/pop_stack.c\
|
||||||
|
parser/produce_sym.c\
|
||||||
|
parser/push_stack.c\
|
||||||
|
parser/redir_init.c\
|
||||||
|
parser/stack_init.c\
|
||||||
|
parser/sym_free.c\
|
||||||
|
parser/tree_func_free.c\
|
||||||
|
parser/tree_wrapper.c\
|
||||||
|
parser/read_stack.c
|
||||||
|
|
||||||
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
|
NB = $(words $(SRC_BASE))
|
||||||
|
INDEX = 0
|
||||||
|
|
||||||
|
all :
|
||||||
|
@make -C $(LIBFT_DIR)
|
||||||
|
@make -j $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
||||||
|
@$(CC) $(OBJS) -o $(NAME) \
|
||||||
|
-I $(INC_DIR) \
|
||||||
|
-I $(LIBFT_INC) \
|
||||||
|
$(LIBS) \
|
||||||
|
$(LIBFT_LIB) \
|
||||||
|
$(FLAGS) $(D_FLAGS)
|
||||||
|
@strip -x $@
|
||||||
|
@printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n"
|
||||||
|
|
||||||
|
$(LIBFT_LIB):
|
||||||
|
@make -C $(LIBFT_DIR)
|
||||||
|
|
||||||
|
$(OBJ_DIR) :
|
||||||
|
@mkdir -p $(OBJ_DIR)
|
||||||
|
@mkdir -p $(dir $(OBJS))
|
||||||
|
|
||||||
|
$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||||
|
@$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB)))))
|
||||||
|
@$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB)))))
|
||||||
|
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||||
|
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||||
|
@printf "\r\033[38;5;11m⌛ MAKE %10.10s : %2d%% \033[48;5;%dm%*s\033[0m%*s\033[48;5;255m \033[0m \033[38;5;11m %*.*s\033[0m\033[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) $(DELTA) "$@"
|
||||||
|
@$(CC) $(FLAGS) $(D_FLAGS) -MMD -c $< -o $@\
|
||||||
|
-I $(INC_DIR)\
|
||||||
|
-I $(LIBFT_INC)
|
||||||
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
||||||
|
clean: cleanlib
|
||||||
|
@rm -rf $(OBJ_DIR)
|
||||||
|
@printf "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K\n"
|
||||||
|
|
||||||
|
cleanlib:
|
||||||
|
@make -C $(LIBFT_DIR) clean
|
||||||
|
|
||||||
|
fclean: clean fcleanlib
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@printf "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K\n"
|
||||||
|
|
||||||
|
fcleanlib: cleanlib
|
||||||
|
@make -C $(LIBFT_DIR) fclean
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
relib: fcleanlib $(LIBFT_LIB)
|
||||||
|
|
||||||
|
.PHONY : fclean clean re relib cleanlib fcleanlib
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
107
42sh/README.md
Normal file
107
42sh/README.md
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
# 42sh
|
||||||
|
|
||||||
|
42sh school project.
|
||||||
|
|
||||||
|
By alao, ariard, gwojda, jhalford, wescande.
|
||||||
|
Final grade : 125/100
|
||||||
|
|
||||||
|
More than 10 000 lines of pure C, even the library was written by ourselves. No memory leaks, no crash were allowed. The most impressive project of the first cycle of 42 school cursus.
|
||||||
|
|
||||||
|
Mandatory part:
|
||||||
|
- Prompt without line edition.
|
||||||
|
- Builtins `cd`, `echo`, `exit`, `env`, `setenv`, `unsetenv` with there options.
|
||||||
|
- Executing simple commands with there parameters using `PATH`.
|
||||||
|
- Support for redirection `>`, `>>`, `<`and `|`.
|
||||||
|
- Logical operand `&&`and `||`.
|
||||||
|
- Separator `;`.
|
||||||
|
|
||||||
|
Optional feature (five of theses are mandatory to validate the project):
|
||||||
|
- Inhibitors `"`, `'`and `\`.
|
||||||
|
- Advanced redirections: aggregation of file output and heredoc `<<`.
|
||||||
|
- Globbing: `*`, `?`, `[]`, `{}`, etc.
|
||||||
|
- Backquotes \`.
|
||||||
|
- Subshell with operand `()`.
|
||||||
|
- Local variable and builtin `unset` and `export`.
|
||||||
|
- History with builtin `history`and `!` with options.
|
||||||
|
- Advanced line edition.
|
||||||
|
- File descriptors and builtin `read` with options.
|
||||||
|
- Dynamical autocompletion.
|
||||||
|
|
||||||
|
Optional feature highly appreciated:
|
||||||
|
- Job Control and builtins `job`, `fg`, `bg` and operand `&`.
|
||||||
|
- Shell Scripting in POSIX standards: for, while, until, if/elif/else, {}, bang (!), case, functions, variable assignements
|
||||||
|
|
||||||
|
## Shell / Subshell
|
||||||
|
|
||||||
|
## Line editing
|
||||||
|
|
||||||
|
Keys|Functions|
|
||||||
|
:-:|:--
|
||||||
|
<kbd>Opt</kbd>+<kbd>C</kbd><br><kbd>Opt</kbd>+<kbd>X</kbd><br><kbd>Opt</kbd>+<kbd>V</kbd>|Copy<br>Cut<br>Paste
|
||||||
|
<kbd>Opt</kbd>+<kbd><</kbd><br><kbd>Opt</kbd>+<kbd>></kbd>|Move per words.
|
||||||
|
<kbd>Opt</kbd>+<kbd>^</kbd><br><kbd>Opt</kbd>+<kbd>v</kbd>|Move per line.
|
||||||
|
<kbd>Ctrl</kbd>+<kbd>L</kbd>|Clear screen.
|
||||||
|
<kbd>Ctrl</kbd>+<kbd>C</kbd>|Terminate/Kill current foreground process.
|
||||||
|
<kbd>Ctrl</kbd>+<kbd>Z</kbd>|Suspend/Stop current foreground process.
|
||||||
|
|
||||||
|
## History
|
||||||
|
|
||||||
|
Keys|Functions|
|
||||||
|
:-:|:--
|
||||||
|
<kbd>^</kbd><br><kbd>v</kbd>|Browse the history.
|
||||||
|
<kbd>Ctrl</kbd>+<kbd>R</kbd>|Research function.
|
||||||
|
`!!`|Retype the last command.
|
||||||
|
`!n`|Retype the `n`(numerical value) command from the begin of history.
|
||||||
|
`!-n`|Retype the `-n`(numerical value) command from the last command.
|
||||||
|
`!name`|Search for a command beginning with `name`.
|
||||||
|
`!?name`|Search for a command which contain `name`.
|
||||||
|
|
||||||
|
## Autocompletion
|
||||||
|
|
||||||
|
Autocompletion works with binary, path and env variable.
|
||||||
|
Output is colored upon type.
|
||||||
|
Using arrows to navigate is supported.
|
||||||
|
Autorefreshing with a new input from the user: modification of the list of possibility.
|
||||||
|
|
||||||
|
Commands|Functions|
|
||||||
|
:-:|:--
|
||||||
|
`$> l[tab]`|Search for binary.
|
||||||
|
`$> ls s[tab]`|Search for path/files.
|
||||||
|
`$> $[tab]`|Search for variables in `env`.
|
||||||
|
|
||||||
|
## Globbing
|
||||||
|
|
||||||
|
Pattern|Behavior|
|
||||||
|
:-:|:--
|
||||||
|
`*`|Everything.
|
||||||
|
`**`|Match directory and sub-directory.
|
||||||
|
`?`|Single char.
|
||||||
|
`[a-z]`|Match range from `a` to `z`.
|
||||||
|
`[!a-z]` `[^a-z]`|Exclude range from `a` to `z`.
|
||||||
|
`{ab, ac}`|Match `ab` or `ac`.
|
||||||
|
|
||||||
|
## Hash table
|
||||||
|
|
||||||
|
Commands|Functions|
|
||||||
|
:-:|:--
|
||||||
|
`hash`|List the content of the hash table.
|
||||||
|
`hash -r`|Clear the memory of the hash table.
|
||||||
|
|
||||||
|
## Job Control
|
||||||
|
|
||||||
|
Commands|Functions|
|
||||||
|
:-:|:--
|
||||||
|
`jobs`|List all the current running jobs.
|
||||||
|
`fg`|Bring the most recent process to foreground.
|
||||||
|
`fg n`|Bring the specified jobs to foreground where `n` is the numerical value of the process found in `jobs`.
|
||||||
|
|
||||||
|
## scripting
|
||||||
|
`while compound-list ; do compound-list ; done`
|
||||||
|
`until compound-list ; do compound-list ; done`
|
||||||
|
`if compound-list ; then compound-list ; elif compound-list ; then compound-list ; else compound-list`
|
||||||
|
`for i in list ; do compound-list ; done`
|
||||||
|
`case pattern1 in ( pattern2 ) compound-list ;; ( pattern1) compound-list ;; esac`
|
||||||
|
`{ compound-list }`
|
||||||
|
`! command`
|
||||||
|
`func() { compound-list }`
|
||||||
|
`VAR="hello world"`
|
||||||
5
42sh/auteur
Normal file
5
42sh/auteur
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
alao
|
||||||
|
jhalford
|
||||||
|
ariard
|
||||||
|
gwojda
|
||||||
|
wescande
|
||||||
58
42sh/includes/builtin.h
Normal file
58
42sh/includes/builtin.h
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtin.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 20:40:22 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BUILTIN_H
|
||||||
|
# define BUILTIN_H
|
||||||
|
|
||||||
|
# include "types.h"
|
||||||
|
# include "libft.h"
|
||||||
|
# include "builtin_read.h"
|
||||||
|
|
||||||
|
struct s_env_data
|
||||||
|
{
|
||||||
|
t_flag flag;
|
||||||
|
char **av_data;
|
||||||
|
char **custom_env;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_env_data t_env_data;
|
||||||
|
|
||||||
|
t_execf *is_builtin(t_process *p);
|
||||||
|
int builtin_return_status(int ret, int status);
|
||||||
|
int builtin_export(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_unset(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_env(const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int bt_env_opt_u(char *opt_arg, t_env_data *data);
|
||||||
|
int bt_env_opt_i(char *opt_arg, t_env_data *data);
|
||||||
|
int builtin_echo(const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int builtin_cd(const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int builtin_exit(const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int builtin_setenv(
|
||||||
|
const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int builtin_unsetenv(
|
||||||
|
const char *path, char *const argv[], char *const envp[]);
|
||||||
|
int builtin_jobs(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_fg(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_bg(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_history(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_hash(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_math(const char *path, char *const av[], char *const envp[]);
|
||||||
|
int builtin_func(const char *path, char *const av[], char *const envp[]);
|
||||||
|
|
||||||
|
int bt_env_geti(char ***av, t_env_data *data);
|
||||||
|
|
||||||
|
void setwd(char *var);
|
||||||
|
char *bt_cd_get_cdpath(char *arg);
|
||||||
|
int bt_cd_process_dotdot(char *target);
|
||||||
|
int bt_cd_process_symlink(char *target);
|
||||||
|
|
||||||
|
#endif
|
||||||
59
42sh/includes/builtin_read.h
Normal file
59
42sh/includes/builtin_read.h
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtin_read.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 04:03:51 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BUILTIN_READ_H
|
||||||
|
# define BUILTIN_READ_H
|
||||||
|
|
||||||
|
# define BT_READ_LA (1 << 0)
|
||||||
|
# define BT_READ_LD (1 << 1)
|
||||||
|
# define BT_READ_LE (1 << 2)
|
||||||
|
# define BT_READ_LI (1 << 3)
|
||||||
|
# define BT_READ_LN (1 << 4)
|
||||||
|
# define BT_READ_UN (1 << 5)
|
||||||
|
# define BT_READ_LP (1 << 6)
|
||||||
|
# define BT_READ_LR (1 << 7)
|
||||||
|
# define BT_READ_LS (1 << 8)
|
||||||
|
# define BT_READ_LT (1 << 9)
|
||||||
|
# define BT_READ_LU (1 << 10)
|
||||||
|
# define BT_READ_INTER (1 << 11)
|
||||||
|
|
||||||
|
typedef struct s_read t_read;
|
||||||
|
typedef struct s_readopt t_readopt;
|
||||||
|
|
||||||
|
struct s_read
|
||||||
|
{
|
||||||
|
t_flag flag;
|
||||||
|
char **names;
|
||||||
|
char delim;
|
||||||
|
int nchars;
|
||||||
|
char *prompt;
|
||||||
|
int timeout;
|
||||||
|
int fd;
|
||||||
|
char *input;
|
||||||
|
};
|
||||||
|
|
||||||
|
int builtin_read(const char *path, char *const av[],
|
||||||
|
char *const envp[]);
|
||||||
|
|
||||||
|
int bt_read_init(t_read *data, char **av);
|
||||||
|
|
||||||
|
struct termios bt_read_term(int init);
|
||||||
|
int bt_read_terminit(t_read *data);
|
||||||
|
int bt_read_exit(t_read *data);
|
||||||
|
|
||||||
|
int bt_read_getdelim(char *opt_arg, t_read *data);
|
||||||
|
int bt_read_getnchars(char *opt_arg, t_read *data);
|
||||||
|
int bt_read_getprompt(char *opt_arg, t_read *data);
|
||||||
|
int bt_read_gettimeout(char *opt_argv, t_read *data);
|
||||||
|
int bt_read_getfd(char *opt_arg, t_read *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
199
42sh/includes/completion.h
Normal file
199
42sh/includes/completion.h
Normal file
|
|
@ -0,0 +1,199 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* completion.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
||||||
|
/* Updated: 2017/03/28 08:13:56 by alao ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef COMPLETION_H
|
||||||
|
# define COMPLETION_H
|
||||||
|
|
||||||
|
# include "minishell.h"
|
||||||
|
|
||||||
|
# define KP_U 4283163
|
||||||
|
# define KP_D 4348699
|
||||||
|
# define KP_L 4479771
|
||||||
|
# define KP_R 4414235
|
||||||
|
# define KP_T 9
|
||||||
|
# define KP_TS 5921563
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Autocompletion list for the valid candidates from the parser.
|
||||||
|
** id : ID of the item.
|
||||||
|
** name : Name of the item.
|
||||||
|
** type : Type of the item.
|
||||||
|
** len : Length of the name.
|
||||||
|
** cursor : Boolean to know which item is currently selected.
|
||||||
|
** next : Pointer to the next item of the list.
|
||||||
|
** prev : Pointer to the previous item of the list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct s_clst
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
char *name;
|
||||||
|
int type;
|
||||||
|
int len;
|
||||||
|
int cursor;
|
||||||
|
struct s_clst *next;
|
||||||
|
struct s_clst *prev;
|
||||||
|
} t_clst;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Autocompletion structure composed as follow:
|
||||||
|
** rcmd : The raw command from the begining to the cursor position.
|
||||||
|
** ircmd : Cursor position.
|
||||||
|
** cpath : Placeholder for the solved path. Later used for the parser.
|
||||||
|
** match : Part of the command to match when searching.
|
||||||
|
** home : Path to home for the ~ solving.
|
||||||
|
** pwd : Current folder to solve local path.
|
||||||
|
** start : See below.
|
||||||
|
** between : See below.
|
||||||
|
** trail : See below.
|
||||||
|
** cutpoint : See below.
|
||||||
|
** prompt : Size of the prompt.
|
||||||
|
** c_sx : Size of the longest word from the list.
|
||||||
|
** c_sy : Size of the list in number of item.
|
||||||
|
** c_pline : Number of item per line when printing.
|
||||||
|
** c_line : Number of line required to move to terminal up.
|
||||||
|
** win_x : Size of the window in length.
|
||||||
|
** win_y : Size of the window in height.
|
||||||
|
** m_size : Max size of the list in pagination.
|
||||||
|
** pos_x : Position of the element relative to the terminal in list mode (X).
|
||||||
|
** pos_y : Position of the element relative to the terminal in list mode (Y).
|
||||||
|
** key : The keypressed lastly.
|
||||||
|
** isfolder : If the match is a folder. boolean.
|
||||||
|
** lst : List of the item corresponding to the completion.
|
||||||
|
**
|
||||||
|
** The complete command is cutted as follow using the command as exemple:
|
||||||
|
**
|
||||||
|
** Exemple: [ ls / ; cd (tab) ; pwd ]
|
||||||
|
**
|
||||||
|
** (int)cutpoint
|
||||||
|
** |
|
||||||
|
** |
|
||||||
|
** Become: [ls / ;] [ ] [cd ] [ ; pwd]
|
||||||
|
** | | | |
|
||||||
|
** | | | |
|
||||||
|
** (char *)start (char *)between (char *)rcmd (char *)trail
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct s_comp
|
||||||
|
{
|
||||||
|
char *rcmd;
|
||||||
|
int ircmd;
|
||||||
|
char *cpath;
|
||||||
|
char *match;
|
||||||
|
char *home;
|
||||||
|
char *pwd;
|
||||||
|
char *start;
|
||||||
|
char *between;
|
||||||
|
char *trail;
|
||||||
|
int cutpoint;
|
||||||
|
int prompt;
|
||||||
|
int c_sx;
|
||||||
|
int c_sy;
|
||||||
|
int c_pline;
|
||||||
|
int c_line;
|
||||||
|
int win_x;
|
||||||
|
int win_y;
|
||||||
|
int m_size;
|
||||||
|
int pos_x;
|
||||||
|
int pos_y;
|
||||||
|
int key;
|
||||||
|
int isfolder;
|
||||||
|
int isrematch;
|
||||||
|
t_clst *lst;
|
||||||
|
} t_comp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Main autocompletion engine:
|
||||||
|
** completion : Main function.
|
||||||
|
** c_init : Initialization.
|
||||||
|
** c_matching : Dispatcher for binary or local files.
|
||||||
|
** c_rematch : Restart on keypress.
|
||||||
|
** c_glob_matching : Call for globbing completion.
|
||||||
|
** c_seek_binary : Search binary using env PATH.
|
||||||
|
** c_seek_files : Solve path and search.
|
||||||
|
** c_seek_env : Search in env for $(var)
|
||||||
|
** c_seek_abs_path : Determiner for absolute path
|
||||||
|
** c_parser : Parser.
|
||||||
|
** c_add_to_lst : Add new node to the list.
|
||||||
|
** c_sizing : Determine the size of the column/line.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int completion(long int key);
|
||||||
|
void c_init(t_data *s, long int input);
|
||||||
|
int c_matching(t_data *s, t_comp *c);
|
||||||
|
int c_rematch(t_comp *c, long int keypress);
|
||||||
|
int c_glob_matching(void);
|
||||||
|
int c_seek_binary(t_data *s, t_comp *c);
|
||||||
|
int c_seek_files(t_data *s, t_comp *c, char *current_word);
|
||||||
|
int c_seek_env(t_comp *c, char *current_word);
|
||||||
|
void c_seek_abs_path(t_comp *c, char *current_word);
|
||||||
|
int c_parser(t_comp *c, char *path, char *name);
|
||||||
|
void c_add_to_lst(t_comp *c, t_clst *node);
|
||||||
|
int c_sizing(t_comp *c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Output functions:
|
||||||
|
**
|
||||||
|
** c_dispatcher : Choose between clear, print or update from to the list
|
||||||
|
** c_updater : Output the result to struct data.
|
||||||
|
** c_keypress : Keypress handling.
|
||||||
|
** c_arrow : Arrow support.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int c_dispatcher(t_data *s);
|
||||||
|
int c_updater(t_comp *c, char *select);
|
||||||
|
int c_keypress(t_comp *c, long int key);
|
||||||
|
void c_arrow(t_comp *c, long int keypress);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Terminal functions:
|
||||||
|
**
|
||||||
|
** c_term_mv_down : Make space for the list.
|
||||||
|
** c_term_mv_back : Reset the cursor position.
|
||||||
|
** c_term_clear : Delete the list from the terminal.
|
||||||
|
** c_term_resize : Refresh win_x and win_y.
|
||||||
|
** c_printer : Printer of the list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void c_term_mv_down(t_comp *c);
|
||||||
|
void c_term_mv_back(t_comp *c);
|
||||||
|
void c_term_clear(t_comp *c);
|
||||||
|
int c_term_resize(t_comp *c);
|
||||||
|
void c_printer(t_comp *c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Support functions:
|
||||||
|
**
|
||||||
|
** c_clear : Memory clearing.
|
||||||
|
** c_clear_lst : List clearing.
|
||||||
|
** path_solver : Solve abstract path to absolute.
|
||||||
|
** c_exclusion_foldr : Check for match folder.
|
||||||
|
** ft_sstrlen : Return size of char **.
|
||||||
|
** ft_sstrtostr : Create char * from char ** with char *sep between.
|
||||||
|
** ft_add_escape : Add escape char to str.
|
||||||
|
** c_lst_id : Repair ID list.
|
||||||
|
** c_is_delim : Check char for specific one.
|
||||||
|
** c_strdupi : Dupe
|
||||||
|
*/
|
||||||
|
|
||||||
|
int c_clear(t_data *s);
|
||||||
|
int c_clear_lst(t_comp *c);
|
||||||
|
char *path_solver(t_comp *c, char *cmd, char *cwd);
|
||||||
|
int c_exclusion_folder(t_comp *c);
|
||||||
|
int ft_sstrlen(char **s);
|
||||||
|
char *ft_sstrtostr(char **s, char *sep);
|
||||||
|
char *ft_add_escape(char *str, char to_escape);
|
||||||
|
void c_lst_id(t_comp *c);
|
||||||
|
int c_is_delim(char c);
|
||||||
|
char *c_strdupi(char *s, int (*f)(char));
|
||||||
|
|
||||||
|
#endif
|
||||||
229
42sh/includes/exec.h
Normal file
229
42sh/includes/exec.h
Normal file
|
|
@ -0,0 +1,229 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* exec.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/29 11:03:30 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef EXEC_H
|
||||||
|
# define EXEC_H
|
||||||
|
|
||||||
|
# include "types.h"
|
||||||
|
# include "job_control.h"
|
||||||
|
# include <sys/stat.h>
|
||||||
|
|
||||||
|
# define IS_PIPESTART(p) ((p).fdin == STDIN)
|
||||||
|
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
||||||
|
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
||||||
|
|
||||||
|
# define EXEC_AND_IF (1 << 0)
|
||||||
|
# define EXEC_OR_IF (1 << 1)
|
||||||
|
# define EXEC_IF_BRANCH (1 << 2)
|
||||||
|
# define EXEC_CASE_BRANCH (1 << 3)
|
||||||
|
|
||||||
|
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
||||||
|
|
||||||
|
# define EXEC_IS_BG(j) (j & EXEC_BG)
|
||||||
|
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
|
||||||
|
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
|
||||||
|
# define EXEC_IS_OR_IF(j) (j & EXEC_OR_IF)
|
||||||
|
# define EXEC_IS_IF_BRANCH(j) (j & EXEC_IF_BRANCH)
|
||||||
|
# define EXEC_IS_CASE_BRANCH(j) (j & EXEC_CASE_BRANCH)
|
||||||
|
|
||||||
|
struct s_data_cmd
|
||||||
|
{
|
||||||
|
char **av;
|
||||||
|
char *path;
|
||||||
|
t_execf *execf;
|
||||||
|
struct stat *stat;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_data_cond
|
||||||
|
{
|
||||||
|
t_btree *condition;
|
||||||
|
t_btree *content;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_data_list
|
||||||
|
{
|
||||||
|
t_ld *token;
|
||||||
|
t_btree *content;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_data_tree
|
||||||
|
{
|
||||||
|
t_btree *content;
|
||||||
|
};
|
||||||
|
|
||||||
|
union u_process_data
|
||||||
|
{
|
||||||
|
struct s_data_cmd cmd;
|
||||||
|
struct s_data_tree subshell;
|
||||||
|
struct s_data_tree brace;
|
||||||
|
struct s_data_tree function;
|
||||||
|
struct s_data_cond d_while;
|
||||||
|
struct s_data_cond d_until;
|
||||||
|
struct s_data_tree d_if;
|
||||||
|
struct s_data_list d_for;
|
||||||
|
struct s_data_list d_case;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum e_process_state
|
||||||
|
{
|
||||||
|
PROCESS_COMPLETED,
|
||||||
|
PROCESS_SUSPENDED,
|
||||||
|
PROCESS_RUNNING,
|
||||||
|
PROCESS_CONTINUED,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum e_process_type
|
||||||
|
{
|
||||||
|
PROCESS_FUNCTION,
|
||||||
|
PROCESS_BUILTIN,
|
||||||
|
PROCESS_FILE,
|
||||||
|
PROCESS_SUBSHELL,
|
||||||
|
PROCESS_BRACE,
|
||||||
|
PROCESS_WHILE,
|
||||||
|
PROCESS_UNTIL,
|
||||||
|
PROCESS_IF,
|
||||||
|
PROCESS_FOR,
|
||||||
|
PROCESS_CASE,
|
||||||
|
PROCESS_EMPTY,
|
||||||
|
PROCESS_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_process_map
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int (*launch)();
|
||||||
|
int (*print)();
|
||||||
|
int (*free)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_process
|
||||||
|
{
|
||||||
|
t_process_type type;
|
||||||
|
t_process_data data;
|
||||||
|
t_process_map map;
|
||||||
|
t_process_state state;
|
||||||
|
pid_t pid;
|
||||||
|
int fdin;
|
||||||
|
int fdout;
|
||||||
|
int to_close;
|
||||||
|
t_list *redirs;
|
||||||
|
int status;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_job
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
pid_t pgid;
|
||||||
|
t_flag attrs;
|
||||||
|
t_list *first_process;
|
||||||
|
struct termios tmodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_exec
|
||||||
|
{
|
||||||
|
t_job job;
|
||||||
|
t_flag attrs;
|
||||||
|
int fdin;
|
||||||
|
t_list *op_stack;
|
||||||
|
char **case_pattern;
|
||||||
|
};
|
||||||
|
|
||||||
|
int exec_init(t_exec *exec);
|
||||||
|
int exec_destroy(t_exec *exec);
|
||||||
|
int process_fork(t_process *p);
|
||||||
|
int process_setgroup(t_process *p, pid_t pid);
|
||||||
|
void process_setsig(void);
|
||||||
|
void process_reset(t_process *p);
|
||||||
|
|
||||||
|
int fd_is_valid(int fd, int flag);
|
||||||
|
int bad_fd(int fd);
|
||||||
|
int process_redirect(t_process *p);
|
||||||
|
int redirect_great(t_redir *redir);
|
||||||
|
int redirect_less(t_redir *redir);
|
||||||
|
int redirect_dgreat(t_redir *redir);
|
||||||
|
int redirect_dless(t_redir *redir);
|
||||||
|
int redirect_greatand(t_redir *redir);
|
||||||
|
int redirect_lessand(t_redir *redir);
|
||||||
|
|
||||||
|
char *ft_findexec(char *path, char *file);
|
||||||
|
|
||||||
|
void set_exitstatus(int status, int override);
|
||||||
|
|
||||||
|
void ast_free(void *data, size_t content_size);
|
||||||
|
void *node_copy(void *data);
|
||||||
|
void *redir_copy(void *data);
|
||||||
|
|
||||||
|
void redir_free(void *data, size_t content_size);
|
||||||
|
|
||||||
|
char **token_to_argv(t_ld *ld, int do_match);
|
||||||
|
t_btree *is_function(t_process *p);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Mapping pour free les process
|
||||||
|
*/
|
||||||
|
void process_free(void *content, size_t content_size);
|
||||||
|
int pfree_cmd(t_process *p);
|
||||||
|
int pfree_cond(t_process *p);
|
||||||
|
int pfree_list(t_process *p);
|
||||||
|
int pfree_subshell(t_process *p);
|
||||||
|
int pfree_func(t_process *p);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Mapping pour launch les process
|
||||||
|
*/
|
||||||
|
int process_launch(t_process *p);
|
||||||
|
int plaunch_if(t_process *p);
|
||||||
|
int plaunch_while(t_process *p);
|
||||||
|
int plaunch_until(t_process *p);
|
||||||
|
int plaunch_for(t_process *p);
|
||||||
|
int plaunch_case(t_process *p);
|
||||||
|
int plaunch_file(t_process *p);
|
||||||
|
int plaunch_builtin(t_process *p);
|
||||||
|
int plaunch_subshell(t_process *p);
|
||||||
|
int plaunch_brace(t_process *p);
|
||||||
|
int plaunch_function(t_process *p);
|
||||||
|
int plaunch_empty(t_process *p);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Mapping pour set les process
|
||||||
|
*/
|
||||||
|
|
||||||
|
int process_set(t_process *p, t_btree *ast);
|
||||||
|
int pset_map(t_process *p, t_btree *ast);
|
||||||
|
int pset_cmd(t_process *p, t_btree *ast);
|
||||||
|
int pset_while(t_process *p, t_btree *ast);
|
||||||
|
int pset_until(t_process *p, t_btree *ast);
|
||||||
|
int pset_if(t_process *p, t_btree *ast);
|
||||||
|
int pset_for(t_process *p, t_btree *ast);
|
||||||
|
int pset_case(t_process *p, t_btree *ast);
|
||||||
|
int pset_subshell(t_process *p, t_btree *ast);
|
||||||
|
int pset_brace(t_process *p, t_btree *ast);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Mapping pour exec les process
|
||||||
|
*/
|
||||||
|
int ft_exec(t_btree **ast);
|
||||||
|
int exec_leaf(t_btree **ast);
|
||||||
|
int exec_semi(t_btree **ast);
|
||||||
|
int exec_ampersand(t_btree **ast);
|
||||||
|
int exec_or_if(t_btree **ast);
|
||||||
|
int exec_and_if(t_btree **ast);
|
||||||
|
int exec_pipe(t_btree **ast);
|
||||||
|
int exec_elif(t_btree **ast);
|
||||||
|
int exec_else(t_btree **ast);
|
||||||
|
int exec_var(t_btree **ast);
|
||||||
|
int exec_case_branch(t_btree **ast);
|
||||||
|
int exec_math(t_btree **ast);
|
||||||
|
int exec_bang(t_btree **ast);
|
||||||
|
int exec_func(t_btree **ast);
|
||||||
|
|
||||||
|
#endif
|
||||||
84
42sh/includes/ft_curs.h
Normal file
84
42sh/includes/ft_curs.h
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_curs.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */
|
||||||
|
/* Updated: 2017/03/23 00:03:16 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_CURS_H
|
||||||
|
# define FT_CURS_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
# include <signal.h>
|
||||||
|
# include <termios.h>
|
||||||
|
# include <term.h>
|
||||||
|
# include <curses.h>
|
||||||
|
|
||||||
|
typedef struct s_curs t_curs;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Cursor data : cursor's coordonate and windows size
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct s_curs
|
||||||
|
{
|
||||||
|
int co;
|
||||||
|
int li;
|
||||||
|
int win_co;
|
||||||
|
int win_li;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Cursor reference singleton
|
||||||
|
*/
|
||||||
|
|
||||||
|
t_curs *curs_single(t_curs *curs, int set);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Cursor setup
|
||||||
|
*/
|
||||||
|
|
||||||
|
int curs_li_ask(void);
|
||||||
|
int curs_co_ask(void);
|
||||||
|
|
||||||
|
int curs_term_setup(void);
|
||||||
|
void curs_win_setup(t_curs *curs);
|
||||||
|
int curs_coo_setup(t_curs *curs);
|
||||||
|
int curs_setup(t_curs *curs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Cursor cleanup
|
||||||
|
*/
|
||||||
|
|
||||||
|
int curs_term_cleanup(void);
|
||||||
|
int curs_cleanup(t_curs *curs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Cursor's data reset
|
||||||
|
*/
|
||||||
|
|
||||||
|
void curs_reset(int sig);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Cursor manipulation function
|
||||||
|
*/
|
||||||
|
|
||||||
|
void curs_clear(t_curs *curs);
|
||||||
|
void curs_clear_post(t_curs *curs);
|
||||||
|
void curs_goto(t_curs *curs, int li, int co);
|
||||||
|
void curs_forward(t_curs *curs, int offset);
|
||||||
|
void curs_backward(t_curs *curs, int offset);
|
||||||
|
void curs_write(t_curs *curs, char *str, size_t len);
|
||||||
|
void curs_write_static(t_curs *curs, char *str, size_t len);
|
||||||
|
void curs_video_write(t_curs *curs, char *str, size_t len);
|
||||||
|
void curs_video_write_static(
|
||||||
|
t_curs *curs, char *str, size_t len);
|
||||||
|
|
||||||
|
#endif
|
||||||
190
42sh/includes/ft_readline.h
Normal file
190
42sh/includes/ft_readline.h
Normal file
|
|
@ -0,0 +1,190 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_readline.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/29 17:41:14 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_READLINE_H
|
||||||
|
# define FT_READLINE_H
|
||||||
|
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
# include <termios.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <term.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/xattr.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <pwd.h>
|
||||||
|
# include <grp.h>
|
||||||
|
# include <uuid/uuid.h>
|
||||||
|
# include <time.h>
|
||||||
|
# include <dirent.h>
|
||||||
|
# include <locale.h>
|
||||||
|
|
||||||
|
# define FLECHE_HAUT 4283163
|
||||||
|
# define FLECHE_BAS 4348699
|
||||||
|
# define FLECHE_GAUCHE 4479771
|
||||||
|
# define FLECHE_DROITE 4414235
|
||||||
|
# define TOUCHE_DELETE 2117294875
|
||||||
|
# define TOUCHE_CTRL_C 3
|
||||||
|
# define TOUCHE_CTRL_D 4
|
||||||
|
# define TOUCHE_CTRL_L 12
|
||||||
|
# define TOUCHE_CTRL_R 18
|
||||||
|
# define TOUCHE_SUPPR 127
|
||||||
|
# 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 TOUCHE_F5 892427035
|
||||||
|
# define TOUCHE_F6 925981467
|
||||||
|
|
||||||
|
# define SIZE_LINE 16384
|
||||||
|
|
||||||
|
# define CORRUPT 1
|
||||||
|
|
||||||
|
# define ERROR_CNTL_R 1
|
||||||
|
|
||||||
|
typedef struct s_list_history
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
struct s_list_history *prev;
|
||||||
|
struct s_list_history *next;
|
||||||
|
} t_list_history;
|
||||||
|
|
||||||
|
typedef struct s_line
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char *input;
|
||||||
|
size_t pos;
|
||||||
|
char *copy_tmp;
|
||||||
|
size_t pos_tmp;
|
||||||
|
int prompt_size;
|
||||||
|
int list_size;
|
||||||
|
char opt;
|
||||||
|
char is_prompt;
|
||||||
|
t_list_history *list_end;
|
||||||
|
t_list_history *list_cur;
|
||||||
|
t_list_history *list_beg;
|
||||||
|
} t_line;
|
||||||
|
|
||||||
|
typedef struct s_key
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
int (*f)(char **str, size_t *pos);
|
||||||
|
} t_key;
|
||||||
|
|
||||||
|
typedef struct s_cpy
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
int (*f)(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
} t_cpy;
|
||||||
|
|
||||||
|
extern t_key g_keys[];
|
||||||
|
extern t_cpy g_cpy[];
|
||||||
|
|
||||||
|
void ft_reset_tab(char *tabl);
|
||||||
|
void ft_putnc(char c, int n);
|
||||||
|
int ft_nbr_len(int nbr);
|
||||||
|
void ft_puttermcaps(char *str);
|
||||||
|
void ft_get_beggin_with_curs(char *str, size_t *pos);
|
||||||
|
void ft_check_end_of_line(char *str, size_t pos);
|
||||||
|
int ft_size_term(void);
|
||||||
|
void ft_add_in_history_file(char *str);
|
||||||
|
void ft_get_beggin(char *str, size_t *pos);
|
||||||
|
void ft_get_next_str(char *str, size_t *pos);
|
||||||
|
void ft_putall_current_str(char *str, size_t *pos);
|
||||||
|
void ft_current_str(char *str, size_t pos);
|
||||||
|
int ft_strlen_next(char *str, size_t pos);
|
||||||
|
void ft_push_back_history(
|
||||||
|
t_list_history **head, t_list_history *new);
|
||||||
|
void ft_prompt(void);
|
||||||
|
char *ft_remove_imput(char *str, size_t pos);
|
||||||
|
char *ft_realloc_imput(char *str, int a, size_t pos);
|
||||||
|
char *ft_strdupi(char const *s);
|
||||||
|
char *ft_strndup(char const *s, int n);
|
||||||
|
t_list_history *ft_create_history_list(char *str);
|
||||||
|
char *ft_strdupi_w(char const *s);
|
||||||
|
void ft_realloc_str_history(
|
||||||
|
char **str, size_t pos, int nb_his, int len);
|
||||||
|
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||||
|
long long ft_pow(int nbr, int power);
|
||||||
|
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||||
|
char *ft_strget_history(char *str);
|
||||||
|
int ft_nb_last_line(char *str, size_t pos);
|
||||||
|
int ft_put(int nb);
|
||||||
|
void ft_check_line(void);
|
||||||
|
void ft_clear_window(void);
|
||||||
|
void free_history_list(t_list_history *head);
|
||||||
|
int ft_nb_of_line(char *str, size_t pos);
|
||||||
|
int ft_get_size_prev(char *str, size_t pos);
|
||||||
|
void sigwinch_resize(int sig);
|
||||||
|
size_t ft_hist_len(void);
|
||||||
|
int hist_is_delim(char c);
|
||||||
|
int ft_nb_last_line(char *str, size_t pos);
|
||||||
|
|
||||||
|
int underline_right(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
int underline_left(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
int underline_home(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
int underline_end(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
int underline_down(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
int underline_up(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
void underline_check_end_of_line(char *str, size_t pos);
|
||||||
|
void reset_term(char **str, size_t *pos);
|
||||||
|
void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp);
|
||||||
|
|
||||||
|
int ft_read_stdin(char **input);
|
||||||
|
|
||||||
|
int ft_end(char **str, size_t *pos);
|
||||||
|
int ft_home(char **str, size_t *pos);
|
||||||
|
int ft_move_right(char **str, size_t *pos);
|
||||||
|
int ft_move_left(char **str, size_t *pos);
|
||||||
|
int ft_up(char **str, size_t *pos);
|
||||||
|
int ft_down(char **str, size_t *pos);
|
||||||
|
int ft_buff_f6(char **str, size_t *pos);
|
||||||
|
int ft_control_d(char **str, size_t *pos);
|
||||||
|
int ft_control_c(char **str, size_t *pos);
|
||||||
|
int ft_control_l(char **str, size_t *pos);
|
||||||
|
int ft_del(char **str, size_t *pos);
|
||||||
|
int ft_suppr(char **str, size_t *pos);
|
||||||
|
int ft_surch_in_history(char **str, size_t *pos);
|
||||||
|
int ft_printall(char **str, size_t *pos);
|
||||||
|
int ft_history_down(char **str, size_t *pos);
|
||||||
|
int ft_history_up(char **str, size_t *pos);
|
||||||
|
int ft_found_next_word(char **str, size_t *pos);
|
||||||
|
int ft_found_prev_word(char **str, size_t *pos);
|
||||||
|
int ft_c(char **str, size_t *pos);
|
||||||
|
int ft_x(char **str, size_t *pos);
|
||||||
|
int ft_v(char **str, size_t *pos);
|
||||||
|
int ft_read_it(int input, size_t *pos, char **str);
|
||||||
|
int ft_print(int ret, char **str, size_t *pos);
|
||||||
|
|
||||||
|
int readline(int prompt, char **input);
|
||||||
|
int ft_completion(int ret, char **str, size_t *pos);
|
||||||
|
|
||||||
|
struct termios *ft_save_termios(int save);
|
||||||
|
|
||||||
|
char *ft_strdupi_w(char const *s);
|
||||||
|
|
||||||
|
void ft_add_str_in_history(char *str);
|
||||||
|
void ft_init_history(void);
|
||||||
|
int ft_history_parsing(int has_prompt, char **input);
|
||||||
|
struct termios *ft_save_termios(int save);
|
||||||
|
void ft_init_termios(void);
|
||||||
|
void readline_init(int prompt);
|
||||||
|
|
||||||
|
#endif
|
||||||
106
42sh/includes/glob.h
Normal file
106
42sh/includes/glob.h
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* glob.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 03:22:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GLOB_H
|
||||||
|
# define GLOB_H
|
||||||
|
|
||||||
|
# define CH(x) ((char **)(x)->content)
|
||||||
|
# define UCH(x) ((unsigned char **)(x)->content)
|
||||||
|
# define SCH(x) ((char **)(x).content)
|
||||||
|
# define SUCH(x) ((unsigned char **)(x).content)
|
||||||
|
|
||||||
|
typedef struct s_ld
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
struct s_ld *next;
|
||||||
|
struct s_ld *prev;
|
||||||
|
} t_ld;
|
||||||
|
|
||||||
|
typedef struct s_glob
|
||||||
|
{
|
||||||
|
short int found;
|
||||||
|
short int cur_dir;
|
||||||
|
char *pat;
|
||||||
|
unsigned char *esc;
|
||||||
|
unsigned char *esc2;
|
||||||
|
t_ld *match;
|
||||||
|
t_ld *match_tmp;
|
||||||
|
t_ld *m_pat;
|
||||||
|
} t_glob;
|
||||||
|
|
||||||
|
typedef struct s_expand
|
||||||
|
{
|
||||||
|
t_ld **wk;
|
||||||
|
char *str;
|
||||||
|
unsigned char *esc;
|
||||||
|
char **split;
|
||||||
|
unsigned char **m_esc;
|
||||||
|
char *s1;
|
||||||
|
} t_expand;
|
||||||
|
|
||||||
|
typedef struct s_bquote
|
||||||
|
{
|
||||||
|
t_ld **wk;
|
||||||
|
char *str;
|
||||||
|
unsigned char *esc;
|
||||||
|
unsigned char *esc2;
|
||||||
|
char *s1;
|
||||||
|
char *s2;
|
||||||
|
char *mid;
|
||||||
|
} t_bquote;
|
||||||
|
/*
|
||||||
|
** interface of glob.
|
||||||
|
*/
|
||||||
|
char **glob(char *str, unsigned char *esc,
|
||||||
|
unsigned char *dbl_esc, int do_match);
|
||||||
|
void esc_print(int fd, char *str, unsigned char *esc);
|
||||||
|
int word_is_assignment(char **content);
|
||||||
|
void *tab_esc_copy(void *content);
|
||||||
|
char *get_output(char *command);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return TRUE if char at str_pos in ini_str is escape.
|
||||||
|
** five the possibility to set if the char is esc or not.
|
||||||
|
*/
|
||||||
|
int is_char_esc(const unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos);
|
||||||
|
void set_char_esc_mode(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos, int mode);
|
||||||
|
void set_char_esc(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos);
|
||||||
|
void set_char_no_esc(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Internal function.
|
||||||
|
*/
|
||||||
|
unsigned char *ft_sub_esc(const unsigned char *esc, int start, int len);
|
||||||
|
unsigned char *dup_char_esc(const unsigned char *esc, const int size);
|
||||||
|
unsigned char *calc_expand_esc(const unsigned char *esc,
|
||||||
|
int nb_start, int *nb_middle, int *nb_end);
|
||||||
|
void modify_esc_split(unsigned char *esc_dest,
|
||||||
|
unsigned char *esc_src, int start, int len);
|
||||||
|
void expand_brace(t_glob *tglob);
|
||||||
|
void expand_bquote(t_glob *gl);
|
||||||
|
void expand_home(t_glob *gl, char *str);
|
||||||
|
void expand_var(t_glob *tglob);
|
||||||
|
void expand_home(t_glob *gl, char *str);
|
||||||
|
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||||
|
int dir_research(t_glob *tglob, char *p, char *pat, int *mode);
|
||||||
|
char **gen_tab(const char *pat, const unsigned char *esc,
|
||||||
|
const unsigned char *esc2, int dup);
|
||||||
|
char **ft_strsplit_spe(const char *str,
|
||||||
|
const unsigned char *esc, char c);
|
||||||
|
unsigned char **ft_strsplit_esc(const char *str,
|
||||||
|
const unsigned char *esc, char c);
|
||||||
|
|
||||||
|
#endif
|
||||||
34
42sh/includes/hash.h
Normal file
34
42sh/includes/hash.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* hash.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/18 11:10:14 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/19 16:37:44 by wescande ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef HASH_H
|
||||||
|
# define HASH_H
|
||||||
|
|
||||||
|
# define MAX_HASH 200
|
||||||
|
|
||||||
|
extern t_list *g_hash[MAX_HASH];
|
||||||
|
|
||||||
|
typedef struct s_hash
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
char *path;
|
||||||
|
} t_hash;
|
||||||
|
|
||||||
|
char *ft_add_hash(char *cmd);
|
||||||
|
char *ft_hash(char *cmd);
|
||||||
|
char *ft_is_hash(char *cmd);
|
||||||
|
int ft_hash_str(char *str);
|
||||||
|
|
||||||
|
void ft_hash_free(void *ptr, size_t size);
|
||||||
|
void ft_free_hash_table(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
97
42sh/includes/job_control.h
Normal file
97
42sh/includes/job_control.h
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* job_control.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/27 16:01:12 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef JOB_CONTROL_H
|
||||||
|
# define JOB_CONTROL_H
|
||||||
|
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/wait.h>
|
||||||
|
# include <termios.h>
|
||||||
|
# include "types.h"
|
||||||
|
# include "exec.h"
|
||||||
|
|
||||||
|
# define JOB_NOTIFIED (1 << 0)
|
||||||
|
# define JOB_BG (1 << 1)
|
||||||
|
|
||||||
|
# define JOB_IS_BG(j) (j & JOB_BG)
|
||||||
|
# define JOB_IS_FG(j) (!JOB_IS_BG(j))
|
||||||
|
|
||||||
|
# define JOBS_OPT_L (1 << 0)
|
||||||
|
|
||||||
|
struct s_jobc
|
||||||
|
{
|
||||||
|
t_list *first_job;
|
||||||
|
pid_t shell_pgid;
|
||||||
|
int current_id;
|
||||||
|
struct termios shell_tmodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
int jobc_init(t_jobc *jobc);
|
||||||
|
int jobc_destroy(t_jobc *jobc);
|
||||||
|
|
||||||
|
t_list *job_getprocess(pid_t pid);
|
||||||
|
int job_addprocess(t_process *p);
|
||||||
|
void job_update_id(void);
|
||||||
|
void job_update_rank(void);
|
||||||
|
|
||||||
|
int do_job_notification(void);
|
||||||
|
void job_notify_new(int id);
|
||||||
|
void job_format(t_job *j, int opts);
|
||||||
|
void job_format_head(t_job *j);
|
||||||
|
|
||||||
|
void job_update_status(void);
|
||||||
|
void mark_job_as_running (t_job *j);
|
||||||
|
int mark_process_status(pid_t pid, int status);
|
||||||
|
int job_is_stopped(t_job *job);
|
||||||
|
int job_is_completed(t_job *job);
|
||||||
|
int has_running_job(void);
|
||||||
|
int has_stopped_job(void);
|
||||||
|
|
||||||
|
void job_new(char **av, pid_t pid);
|
||||||
|
void job_run(t_job *job, int foreground);
|
||||||
|
int job_wait(int id);
|
||||||
|
void job_remove(int id);
|
||||||
|
void job_free(void *content, size_t content_size);
|
||||||
|
void job_hup_all(void);
|
||||||
|
|
||||||
|
int put_job_in_foreground(t_job *job, int cont);
|
||||||
|
int put_job_in_background(t_job *job, int cont);
|
||||||
|
|
||||||
|
int job_cmp_pid(t_job *job, pid_t *pid);
|
||||||
|
int job_cmp_id(t_job *job, int *id);
|
||||||
|
void job_getrank(int (*rank)[2]);
|
||||||
|
|
||||||
|
void sigchld_handler(int signo);
|
||||||
|
void sigint_handler(int signo);
|
||||||
|
void sigtstp_handler(int signo);
|
||||||
|
void sigttin_handler(int signo);
|
||||||
|
void sigttou_handler(int signo);
|
||||||
|
|
||||||
|
int process_cmp_pid(t_process *p, pid_t *pid);
|
||||||
|
void process_format(t_list **p, int firstp, int opts);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Mapping pour afficher les process
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pprint(t_process *p);
|
||||||
|
int pprint_subshell(t_process *p);
|
||||||
|
int pprint_brace(t_process *p);
|
||||||
|
int pprint_while(t_process *p);
|
||||||
|
int pprint_if(t_process *p);
|
||||||
|
int pprint_case(t_process *p);
|
||||||
|
int pprint_until(t_process *p);
|
||||||
|
int pprint_function(t_process *p);
|
||||||
|
int pprint_for(t_process *p);
|
||||||
|
int pprint_cmd(t_process *p);
|
||||||
|
|
||||||
|
#endif
|
||||||
119
42sh/includes/lexer.h
Normal file
119
42sh/includes/lexer.h
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lexer.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/27 19:19:22 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LEXER_H
|
||||||
|
# define LEXER_H
|
||||||
|
|
||||||
|
# include "minishell.h"
|
||||||
|
# include "libft.h"
|
||||||
|
# include "types.h"
|
||||||
|
|
||||||
|
enum e_lexstate
|
||||||
|
{
|
||||||
|
DEFAULT,
|
||||||
|
PAREN,
|
||||||
|
HEREDOC,
|
||||||
|
NEWLINE,
|
||||||
|
DELIM,
|
||||||
|
SEP,
|
||||||
|
WORD,
|
||||||
|
NUMBER,
|
||||||
|
LESS,
|
||||||
|
GREAT,
|
||||||
|
QUOTE,
|
||||||
|
DQUOTE,
|
||||||
|
BQUOTE,
|
||||||
|
BACKSLASH,
|
||||||
|
CURLY_BRACKETS,
|
||||||
|
END,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_token
|
||||||
|
{
|
||||||
|
t_type type;
|
||||||
|
char *data;
|
||||||
|
unsigned char *esc;
|
||||||
|
unsigned char *esc2;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_lexer
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int pos;
|
||||||
|
t_lexstate state;
|
||||||
|
t_list *stack;
|
||||||
|
t_list *heredoc_stack;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_rvwords
|
||||||
|
{
|
||||||
|
char *word;
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_post_tokenize(t_list **alst, char **str);
|
||||||
|
|
||||||
|
t_token *token_init();
|
||||||
|
int token_append(t_token *token, t_lexer *lexer,
|
||||||
|
short int esc, short int esc2);
|
||||||
|
int token_append_char(t_token *token, char c,
|
||||||
|
short int esc, short int esc2);
|
||||||
|
int token_append_str(t_token *token, char *str,
|
||||||
|
short int esc, short int esc2);
|
||||||
|
void token_free(void *data, size_t size);
|
||||||
|
int token_cmp_type(t_token *token, t_type *ref);
|
||||||
|
void token_print(t_list *lst);
|
||||||
|
|
||||||
|
int reduce_parens(t_list **alst, char *str);
|
||||||
|
int bquotes_expand(t_list **alst);
|
||||||
|
char *command_getoutput(char *command);
|
||||||
|
|
||||||
|
int ft_is_delim(char c);
|
||||||
|
int ft_is_delim_list(char c);
|
||||||
|
|
||||||
|
char *stack_to_prompt(t_list *stack);
|
||||||
|
t_lexstate get_state_global(t_lexer *lexer);
|
||||||
|
t_lexstate get_state_redir(t_lexer *lexer);
|
||||||
|
int get_lexer_stack(t_lexer lexer);
|
||||||
|
int get_lexer_stack2(t_lexer lexer);
|
||||||
|
int get_reserved_words(t_list *temp);
|
||||||
|
int isrw_delim(t_type type);
|
||||||
|
int keep_last_type(t_type *type, t_list *token);
|
||||||
|
int insert_newline(t_list **alst);
|
||||||
|
|
||||||
|
int do_lexer_routine(t_list **token, char *stream);
|
||||||
|
void lexer_init(t_lexer *lexer);
|
||||||
|
void lexer_destroy(t_lexer *lexer);
|
||||||
|
int lexer_lex(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_default(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_newline(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_heredoc(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_delim(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_sep(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_word(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_number(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_less(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_great(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_greatand(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_lessand(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_quote(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_dquote(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_bquote(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_backslash(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_paren(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_curly_braces(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_assignement_word(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_comment(t_list **alst, t_lexer *lexer);
|
||||||
|
int lexer_end(t_list **alst, t_lexer *lexer);
|
||||||
|
|
||||||
|
#endif
|
||||||
80
42sh/includes/minishell.h
Normal file
80
42sh/includes/minishell.h
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* minishell.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/27 15:55:04 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MINISHELL_H
|
||||||
|
# define MINISHELL_H
|
||||||
|
|
||||||
|
# define SHELL_NAME "minishell"
|
||||||
|
|
||||||
|
# include <dirent.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <signal.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <errno.h>
|
||||||
|
# include <limits.h>
|
||||||
|
|
||||||
|
# include "../libft/includes/libft.h"
|
||||||
|
# include "types.h"
|
||||||
|
# include "lexer.h"
|
||||||
|
# include "parser.h"
|
||||||
|
# include "ft_readline.h"
|
||||||
|
# include "job_control.h"
|
||||||
|
# include "exec.h"
|
||||||
|
# include "builtin.h"
|
||||||
|
# include "glob.h"
|
||||||
|
# include "completion.h"
|
||||||
|
# include "hash.h"
|
||||||
|
|
||||||
|
# define SH_MSG(s, ...) "{red}%s: " s "{eoc}\n", g_argv[0], ##__VA_ARGS__
|
||||||
|
# define SH_ERR(s, ...) ft_dprintf(STDERR, SH_MSG(s, ##__VA_ARGS__))
|
||||||
|
|
||||||
|
struct s_data
|
||||||
|
{
|
||||||
|
t_flag opts;
|
||||||
|
char **av_data;
|
||||||
|
char *c_arg;
|
||||||
|
int fd;
|
||||||
|
char **env;
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
t_line line;
|
||||||
|
t_lexer lexer;
|
||||||
|
t_list *fd_save[10];
|
||||||
|
t_parser parser;
|
||||||
|
t_comp *comp;
|
||||||
|
t_exec exec;
|
||||||
|
t_jobc jobc;
|
||||||
|
char **local_var;
|
||||||
|
t_list *lst_func;
|
||||||
|
char *binary;
|
||||||
|
};
|
||||||
|
|
||||||
|
t_data *data_singleton();
|
||||||
|
int shell_init(int ac, char **av, char **env);
|
||||||
|
void shell_exit(void);
|
||||||
|
int data_init(int ac, char **av, char **env);
|
||||||
|
void data_exit(void);
|
||||||
|
int get_c_arg(char *opt_arg, t_data *data);
|
||||||
|
|
||||||
|
void shell_sig_reset(void);
|
||||||
|
|
||||||
|
void shell_fds_init(void);
|
||||||
|
void shell_fds_destroy(void);
|
||||||
|
int shell_fds_pop(void);
|
||||||
|
int shell_fds_push(void);
|
||||||
|
void shell_fds_reset(void);
|
||||||
|
void shell_fds_destroy(void);
|
||||||
|
|
||||||
|
char *ft_putast(void *node);
|
||||||
|
void ft_putast2(void *node);
|
||||||
|
|
||||||
|
#endif
|
||||||
182
42sh/includes/parser.h
Normal file
182
42sh/includes/parser.h
Normal file
|
|
@ -0,0 +1,182 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parser.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/22 17:22:51 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/29 17:01:08 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef PARSER_H
|
||||||
|
# define PARSER_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Parse POSIX grammar
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum e_parstate
|
||||||
|
{
|
||||||
|
ERROR = 0,
|
||||||
|
UNDEFINED,
|
||||||
|
SUCCESS,
|
||||||
|
};
|
||||||
|
|
||||||
|
# define MATCH_STACK(x, y) (x == y || y == ALL)
|
||||||
|
|
||||||
|
struct s_parser
|
||||||
|
{
|
||||||
|
t_parstate state;
|
||||||
|
t_list *stack;
|
||||||
|
t_sym *new_sym;
|
||||||
|
t_list *heredoc_queue;
|
||||||
|
int cache;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_aggrematch
|
||||||
|
{
|
||||||
|
t_sym top;
|
||||||
|
t_sym under;
|
||||||
|
t_sym new_sym;
|
||||||
|
int erase_sym;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_prodmatch
|
||||||
|
{
|
||||||
|
t_type token;
|
||||||
|
t_sym stack;
|
||||||
|
t_sym new_sym;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_stackmatch
|
||||||
|
{
|
||||||
|
t_sym top;
|
||||||
|
t_sym under;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_errormatch
|
||||||
|
{
|
||||||
|
t_type token;
|
||||||
|
char *error;
|
||||||
|
};
|
||||||
|
|
||||||
|
int do_parser_routine(t_list **token, t_btree **ast);
|
||||||
|
void parser_init(t_parser *parser);
|
||||||
|
void parser_destroy(t_parser *parser);
|
||||||
|
int stack_init(t_parser *parser);
|
||||||
|
int redir_init(t_type type, t_redir *redir);
|
||||||
|
int ft_parse(t_btree **ast, t_list **token, t_parser *parser);
|
||||||
|
|
||||||
|
int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst);
|
||||||
|
int eval_sym(t_list **stack, t_sym new_sym);
|
||||||
|
int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state);
|
||||||
|
|
||||||
|
int push_stack(t_list **stack, t_sym new_sym);
|
||||||
|
int pop_stack(t_list **stack, t_sym erase_sym);
|
||||||
|
|
||||||
|
int pop_heredoc(t_list **lst);
|
||||||
|
|
||||||
|
int error_syntax(t_list **token);
|
||||||
|
int error_eof(void);
|
||||||
|
|
||||||
|
int ft_read_stack(t_sym *stack);
|
||||||
|
char *read_state(t_sym current);
|
||||||
|
|
||||||
|
struct s_treematch
|
||||||
|
{
|
||||||
|
t_type type;
|
||||||
|
int (*add)(t_btree **ast, t_list **lst);
|
||||||
|
};
|
||||||
|
|
||||||
|
int build_tree(t_btree **ast, t_list **lst, t_parser *parser);
|
||||||
|
|
||||||
|
int add_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_cmd(t_btree **ast, t_list **lst);
|
||||||
|
|
||||||
|
int add_file(t_btree **ast, t_list **lst);
|
||||||
|
int add_loop_cmd(t_btree **ast, t_list **lst);
|
||||||
|
int add_loop_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_condition_cmd(t_btree **ast, t_list **lst);
|
||||||
|
int add_condition_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_branch(t_btree **ast, t_list **lst);
|
||||||
|
int add_redir_word(t_btree **ast, t_list **lst);
|
||||||
|
int add_redir_type(t_btree **ast, t_list **lst);
|
||||||
|
int redir_init(t_type type, t_redir *redir);
|
||||||
|
int add_case_cmd(t_btree **ast, t_list **lst);
|
||||||
|
int add_case_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_pattern(t_btree **ast, t_list **lst);
|
||||||
|
int add_subshell_cmd(t_btree **ast, t_list **lst);
|
||||||
|
int add_subshell_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_func_cmd(t_btree **ast, t_list **lst);
|
||||||
|
int add_one_func(t_btree **ast, t_list **lst);
|
||||||
|
int add_pipe(t_btree **ast, t_list **lst);
|
||||||
|
int add_null(t_btree **ast, t_list **lst);
|
||||||
|
int add_ionumber(t_btree **ast, t_list **lst);
|
||||||
|
int add_bang(t_btree **ast, t_list **lst);
|
||||||
|
int add_bang_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_if(t_btree **ast, t_list **lst);
|
||||||
|
|
||||||
|
int isloop(t_btree **ast, t_list **lst);
|
||||||
|
int iscase(t_btree **ast, t_list **lst);
|
||||||
|
int iscase_pattern(t_btree **ast, t_list **lst);
|
||||||
|
int iscase_branch(t_btree **ast, t_list **lst);
|
||||||
|
int iscondition(t_btree **ast, t_list **lst);
|
||||||
|
int iscondition_branch(t_btree **ast, t_list **lst);
|
||||||
|
int issubshell(t_btree **ast, t_list **lst);
|
||||||
|
int isfunc(t_btree **ast, t_list **lst);
|
||||||
|
int isfunc_name(t_btree **ast, t_list **lst);
|
||||||
|
int isdir(t_btree **ast);
|
||||||
|
int iscondition(t_btree **ast, t_list **list);
|
||||||
|
int isdir_sep(t_btree **ast, t_list **list);
|
||||||
|
int isdir_word(t_btree **ast, t_list **list);
|
||||||
|
int isnull(t_btree **ast, t_list **list);
|
||||||
|
int isionumber(t_btree **ast, t_list **lst);
|
||||||
|
int isbang(t_btree **ast, t_list **lst);
|
||||||
|
int isbang_sep(t_btree **ast, t_list **lst);
|
||||||
|
|
||||||
|
int join_ast(t_btree **ast, t_btree **new_node);
|
||||||
|
int gen_node(t_btree **ast);
|
||||||
|
int superflous_token(t_btree **ast, t_list **list);
|
||||||
|
void sym_free(void *data, size_t size);
|
||||||
|
void tree_func_free(void *data, size_t content_size);
|
||||||
|
|
||||||
|
char *read_state(t_sym current);
|
||||||
|
|
||||||
|
struct s_distrostree
|
||||||
|
{
|
||||||
|
int (*test)(t_btree **ast, t_list **lst);
|
||||||
|
int (*add)(t_btree **ast, t_list **lst);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_redir
|
||||||
|
{
|
||||||
|
t_type type;
|
||||||
|
int n;
|
||||||
|
char *word;
|
||||||
|
char *heredoc_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_cmd
|
||||||
|
{
|
||||||
|
t_list *redir;
|
||||||
|
t_ld *token;
|
||||||
|
};
|
||||||
|
|
||||||
|
union u_astdata
|
||||||
|
{
|
||||||
|
t_cmd cmd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_astnode
|
||||||
|
{
|
||||||
|
int pattern;
|
||||||
|
int nest;
|
||||||
|
int full;
|
||||||
|
int cache;
|
||||||
|
t_type type;
|
||||||
|
t_astdata data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
235
42sh/includes/types.h
Normal file
235
42sh/includes/types.h
Normal file
|
|
@ -0,0 +1,235 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* types.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/29 16:40:25 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef TYPES_H
|
||||||
|
# define TYPES_H
|
||||||
|
|
||||||
|
# include <sys/types.h>
|
||||||
|
|
||||||
|
# define SH_INTERACTIVE (1 << 0)
|
||||||
|
# define SH_OPTS_JOBC (1 << 1)
|
||||||
|
# define SH_OPTS_LC (1 << 2)
|
||||||
|
# define SH_MODE_INPUT (1 << 3)
|
||||||
|
# define SH_MODE_EXEC (1 << 4)
|
||||||
|
|
||||||
|
# define SH_MODE_MASK (SH_MODE_INPUT | SH_MODE_EXEC)
|
||||||
|
# define SH_HAS_JOBC(b) (b & SH_OPTS_JOBC)
|
||||||
|
# define SH_IS_INTERACTIVE(b) (b & SH_INTERACTIVE)
|
||||||
|
# define SH_NO_INTERACTIVE(b) !(b & SH_INTERACTIVE)
|
||||||
|
|
||||||
|
# define SH_MSG_NOJOBC "no job-control"
|
||||||
|
|
||||||
|
typedef long long t_type;
|
||||||
|
typedef long long t_flag;
|
||||||
|
|
||||||
|
typedef struct s_data t_data;
|
||||||
|
typedef struct s_line t_line;
|
||||||
|
typedef struct s_comp t_comp;
|
||||||
|
typedef struct s_exec t_exec;
|
||||||
|
typedef struct s_jobc t_jobc;
|
||||||
|
typedef struct s_lexer t_lexer;
|
||||||
|
typedef struct s_parser t_parser;
|
||||||
|
typedef enum e_mode t_mode;
|
||||||
|
typedef struct s_data_template t_btexport;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Lexer types
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum e_lexstate t_lexstate;
|
||||||
|
typedef struct s_token t_token;
|
||||||
|
typedef struct s_rvwords t_rvwords;
|
||||||
|
typedef struct s_ld t_ld;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Execution types
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef int t_condition;
|
||||||
|
typedef struct s_job t_job;
|
||||||
|
typedef struct s_process t_process;
|
||||||
|
typedef int (t_execf)(const char *path,
|
||||||
|
char *const argv[],
|
||||||
|
char *const envp[]);
|
||||||
|
typedef enum e_process_type t_process_type;
|
||||||
|
typedef enum e_process_state t_process_state;
|
||||||
|
typedef union u_process_data t_process_data;
|
||||||
|
typedef struct s_process_map t_process_map;
|
||||||
|
typedef struct s_data_cond t_data_while;
|
||||||
|
typedef struct s_data_cond t_data_if;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Parser types
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct s_astnode t_astnode;
|
||||||
|
typedef struct s_redir t_redir;
|
||||||
|
typedef struct s_cmd t_cmd;
|
||||||
|
typedef union u_astdata t_astdata;
|
||||||
|
typedef union u_word t_word;
|
||||||
|
typedef int t_sym;
|
||||||
|
typedef enum e_parstate t_parstate;
|
||||||
|
typedef struct s_aggrematch t_aggrematch;
|
||||||
|
typedef struct s_prodmatch t_prodmatch;
|
||||||
|
typedef struct s_stackmatch t_stackmatch;
|
||||||
|
typedef struct s_errormatch t_errormatch;
|
||||||
|
typedef struct s_treematch t_treematch;
|
||||||
|
typedef struct s_distrostree t_distrostree;
|
||||||
|
|
||||||
|
enum e_sym
|
||||||
|
{
|
||||||
|
LINEBREAK = 1,
|
||||||
|
TK_COMMAND,
|
||||||
|
TK_LESS,
|
||||||
|
TK_GREAT,
|
||||||
|
TK_DLESS,
|
||||||
|
TK_DGREAT,
|
||||||
|
TK_LESSAND,
|
||||||
|
TK_GREATAND,
|
||||||
|
TK_SEMI,
|
||||||
|
TK_PIPE,
|
||||||
|
TK_AND_IF,
|
||||||
|
TK_OR_IF,
|
||||||
|
TK_AMP,
|
||||||
|
TK_PAREN_OPEN,
|
||||||
|
TK_PAREN_CLOSE,
|
||||||
|
TK_BQUOTE,
|
||||||
|
TK_NEWLINE,
|
||||||
|
TK_WHILE,
|
||||||
|
TK_DO,
|
||||||
|
TK_DONE,
|
||||||
|
TK_IF,
|
||||||
|
TK_THEN,
|
||||||
|
TK_FI,
|
||||||
|
TK_ELIF,
|
||||||
|
TK_ELSE,
|
||||||
|
TK_UNTIL,
|
||||||
|
TK_WORD,
|
||||||
|
TK_ASSIGNMENT_WORD = 50,
|
||||||
|
TK_BANG,
|
||||||
|
TK_NAME,
|
||||||
|
TK_FOR,
|
||||||
|
TK_IO_NUMBER,
|
||||||
|
TK_DLESSDASH,
|
||||||
|
TK_LESSGREAT,
|
||||||
|
TK_CASE,
|
||||||
|
TK_IN,
|
||||||
|
TK_ESAC,
|
||||||
|
TK_CLOBBER,
|
||||||
|
TK_LBRACE,
|
||||||
|
TK_RBRACE,
|
||||||
|
TK_DSEMI,
|
||||||
|
PROGRAM = 100,
|
||||||
|
COMPLETE_COMMAND,
|
||||||
|
COMPLETE_COMMANDS,
|
||||||
|
LIST,
|
||||||
|
AND_OR,
|
||||||
|
PIPELINE,
|
||||||
|
PIPE_SEQUENCE,
|
||||||
|
COMMAND,
|
||||||
|
COMPOUND_COMMAND,
|
||||||
|
SUBSHELL,
|
||||||
|
COMPOUND_LIST,
|
||||||
|
TERM,
|
||||||
|
FOR_CLAUSE,
|
||||||
|
NAME,
|
||||||
|
IN,
|
||||||
|
WORDLIST,
|
||||||
|
CASE_CLAUSE,
|
||||||
|
CASE_LIST,
|
||||||
|
CASE_LIST_NS,
|
||||||
|
CASE_ITEM,
|
||||||
|
CASE_ITEM_NS,
|
||||||
|
PATTERN,
|
||||||
|
IF_CLAUSE,
|
||||||
|
BRACE_CLAUSE,
|
||||||
|
ELSE_PART,
|
||||||
|
WHILE_CLAUSE,
|
||||||
|
UNTIL_CLAUSE,
|
||||||
|
FUNCTION_DEFINITION,
|
||||||
|
FUNCTION_BODY,
|
||||||
|
FNAME,
|
||||||
|
BRACE_GROUP,
|
||||||
|
DO_GROUP,
|
||||||
|
SIMPLE_COMMAND,
|
||||||
|
CMD_NAME,
|
||||||
|
CMD_WORD,
|
||||||
|
CMD_PREFIX,
|
||||||
|
CMD_SUFFIX,
|
||||||
|
REDIRECT_LIST,
|
||||||
|
IO_REDIRECT,
|
||||||
|
IO_FILE,
|
||||||
|
FILENAME,
|
||||||
|
IO_HERE,
|
||||||
|
HERE_END,
|
||||||
|
NEWLINE_LIST,
|
||||||
|
SEPARATOR_OP,
|
||||||
|
SEPARATOR,
|
||||||
|
SEQUENTIAL_SEP,
|
||||||
|
BRACE,
|
||||||
|
LOOP,
|
||||||
|
FUNC,
|
||||||
|
PIPE_SEMI_SEQUENCE,
|
||||||
|
PIPE_CLOSE_SEQUENCE,
|
||||||
|
CMD_SUPERIOR,
|
||||||
|
SEQUENCE,
|
||||||
|
END_COMMAND,
|
||||||
|
CONDITION,
|
||||||
|
COMPLETE_CONDITION,
|
||||||
|
FOR_WORDLIST,
|
||||||
|
PATTERN_CASE,
|
||||||
|
FUNC_NAME,
|
||||||
|
OPEN_FUNC,
|
||||||
|
CLOSE_FUNC,
|
||||||
|
CLOSE_LIST,
|
||||||
|
OTHER,
|
||||||
|
REDIR,
|
||||||
|
CMD,
|
||||||
|
AND_OR_MAJOR,
|
||||||
|
AND_OR_MINOR,
|
||||||
|
HEREDOCDATA,
|
||||||
|
HEREDOC_DELIM,
|
||||||
|
ALL = 200,
|
||||||
|
TERMINUS = 300,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
** LIST D:
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ft_ld_new(t_ld **alst, void *content);
|
||||||
|
t_ld *ft_ld_front(t_ld *ld);
|
||||||
|
void ft_ld_pushfront(t_ld **alst, void *content);
|
||||||
|
void ft_ld_pushback(t_ld **alst, void *content);
|
||||||
|
size_t ft_ld_size(t_ld *ld);
|
||||||
|
void ft_ld_del(t_ld **ld, void (*del)());
|
||||||
|
void ft_ld_clear(t_ld **ld, void (*del)());
|
||||||
|
void ft_ld_reverse(t_ld **lst);
|
||||||
|
t_ld *ft_ld_back(t_ld *ld);
|
||||||
|
t_ld *ft_ld_swap(t_ld *l_cur);
|
||||||
|
char **ft_ld_to_tab(t_ld *ld);
|
||||||
|
t_ld *ft_ld_order(t_ld *ld, int (*f)());
|
||||||
|
t_ld *ft_ld_copy(t_ld *src, void *(*f)(void *elem));
|
||||||
|
|
||||||
|
/*
|
||||||
|
** str:
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *ft_strjoinf(char *str, char *str2, int mode);
|
||||||
|
char *ft_strsubf(char *s, unsigned int start,
|
||||||
|
size_t len, short int mode);
|
||||||
|
void ft_tabdel(char ***mytab);
|
||||||
|
int ft_tablen(char **mytab);
|
||||||
|
|
||||||
|
void *ft_memrealloc(void *ptr, size_t old_s, size_t new_s);
|
||||||
|
|
||||||
|
#endif
|
||||||
1
42sh/libft/.gitignore
vendored
Normal file
1
42sh/libft/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
libft.a
|
||||||
246
42sh/libft/Makefile
Normal file
246
42sh/libft/Makefile
Normal file
|
|
@ -0,0 +1,246 @@
|
||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: jhalford <jack@crans.org> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2017/02/07 16:09:36 by jhalford #+# #+# #
|
||||||
|
# Updated: 2017/03/29 11:08:06 by gwojda ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = libft.a
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
AR = ar -rc
|
||||||
|
MKDIR = mkdir -p
|
||||||
|
RM = /bin/rm -rf
|
||||||
|
|
||||||
|
W_FLAGS = -Wall -Wextra -Werror -g
|
||||||
|
D_FLAGS = -g
|
||||||
|
FLAGS = $(W_FLAGS) $(D_FLAGS)
|
||||||
|
|
||||||
|
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||||
|
|
||||||
|
SRC_DIR = src/
|
||||||
|
INC_DIR = includes/
|
||||||
|
OBJ_DIR = objs/
|
||||||
|
|
||||||
|
SRC_BASE = \
|
||||||
|
btree/btree_apply_by_level.c\
|
||||||
|
btree/btree_apply_infix.c\
|
||||||
|
btree/btree_apply_prefix.c\
|
||||||
|
btree/btree_apply_suffix.c\
|
||||||
|
btree/btree_create_node.c\
|
||||||
|
btree/btree_del.c\
|
||||||
|
btree/btree_delone.c\
|
||||||
|
btree/btree_insert_data.c\
|
||||||
|
btree/btree_level_count.c\
|
||||||
|
btree/btree_map.c\
|
||||||
|
btree/btree_print.c\
|
||||||
|
btree/btree_search_item.c\
|
||||||
|
char/ft_isalnum.c\
|
||||||
|
char/ft_isalpha.c\
|
||||||
|
char/ft_isascii.c\
|
||||||
|
char/ft_isdigit.c\
|
||||||
|
char/ft_isprint.c\
|
||||||
|
char/ft_tolower.c\
|
||||||
|
char/ft_toupper.c\
|
||||||
|
cliopts/cliopts_get.c\
|
||||||
|
cliopts/cliopts_getmap.c\
|
||||||
|
color/ft_color_mk.c\
|
||||||
|
color/ft_color_mkif.c\
|
||||||
|
color/ft_color_reset.c\
|
||||||
|
color/ft_color_set.c\
|
||||||
|
dlst/ft_dlstadd_after.c\
|
||||||
|
dlst/ft_dlstadd_before.c\
|
||||||
|
dlst/ft_dlstdel.c\
|
||||||
|
dlst/ft_dlstdelone.c\
|
||||||
|
dlst/ft_dlstlast.c\
|
||||||
|
dlst/ft_dlstnew.c\
|
||||||
|
dlst/ft_dlstrtostr.c\
|
||||||
|
dlst/ft_dlstsize.c\
|
||||||
|
error/error.c\
|
||||||
|
ft_printf/ft_conversion.c\
|
||||||
|
ft_printf/ft_fmt_simplify.c\
|
||||||
|
ft_printf/ft_fmt_validate_conv.c\
|
||||||
|
ft_printf/ft_fmt_validate_flags.c\
|
||||||
|
ft_printf/ft_fmt_validate_mod.c\
|
||||||
|
ft_printf/ft_printf.c\
|
||||||
|
ft_printf/ft_printf_color.c\
|
||||||
|
ft_printf/ft_printf_parse.c\
|
||||||
|
ft_printf/ft_transform.c\
|
||||||
|
ft_printf/ft_vprintf.c\
|
||||||
|
ft_printf/lib_fmt.c\
|
||||||
|
ft_printf/lib_fmt_error.c\
|
||||||
|
ft_printf/lib_pad.c\
|
||||||
|
ft_printf/lib_pad_sharp.c\
|
||||||
|
get_next_line/get_next_line.c\
|
||||||
|
lst/ft_id.c\
|
||||||
|
lst/ft_lst_at.c\
|
||||||
|
lst/ft_lst_bfree.c\
|
||||||
|
lst/ft_lst_cfree.c\
|
||||||
|
lst/ft_lst_delif.c\
|
||||||
|
lst/ft_lst_delsub.c\
|
||||||
|
lst/ft_lst_filter.c\
|
||||||
|
lst/ft_lst_find.c\
|
||||||
|
lst/ft_lst_merge.c\
|
||||||
|
lst/ft_lst_order_delsub.c\
|
||||||
|
lst/ft_lst_print.c\
|
||||||
|
lst/ft_lst_print2.c\
|
||||||
|
lst/ft_lst_removeif.c\
|
||||||
|
lst/ft_lst_reverse.c\
|
||||||
|
lst/ft_lst_size.c\
|
||||||
|
lst/ft_lst_sorted_insert.c\
|
||||||
|
lst/ft_lst_sorted_merge.c\
|
||||||
|
lst/ft_lstadd.c\
|
||||||
|
lst/ft_lstdel.c\
|
||||||
|
lst/ft_lstdelone.c\
|
||||||
|
lst/ft_lsteadd.c\
|
||||||
|
lst/ft_lstiter.c\
|
||||||
|
lst/ft_lstlast.c\
|
||||||
|
lst/ft_lstmap.c\
|
||||||
|
lst/ft_lstnadd.c\
|
||||||
|
lst/ft_lstnew.c\
|
||||||
|
lst/ft_lstnew_range.c\
|
||||||
|
lst/ft_lstsort.c\
|
||||||
|
lst/pop.c\
|
||||||
|
lst/push.c\
|
||||||
|
lst/top.c\
|
||||||
|
math/ft_addrcmp.c\
|
||||||
|
math/ft_ilen.c\
|
||||||
|
math/ft_ilen_base.c\
|
||||||
|
math/ft_itoa.c\
|
||||||
|
math/ft_itoa_base.c\
|
||||||
|
math/ft_lllen.c\
|
||||||
|
math/ft_lllen_base.c\
|
||||||
|
math/ft_lltoa_base.c\
|
||||||
|
math/ft_uilen.c\
|
||||||
|
math/ft_uitoa_base.c\
|
||||||
|
math/ft_ulltoa_base.c\
|
||||||
|
math/id.c\
|
||||||
|
mem/ft_bzero.c\
|
||||||
|
mem/ft_malloc.c\
|
||||||
|
mem/ft_memalloc.c\
|
||||||
|
mem/ft_memccpy.c\
|
||||||
|
mem/ft_memchr.c\
|
||||||
|
mem/ft_memcmp.c\
|
||||||
|
mem/ft_memcpy.c\
|
||||||
|
mem/ft_memdel.c\
|
||||||
|
mem/ft_memmove.c\
|
||||||
|
mem/ft_memset.c\
|
||||||
|
mem/ft_realloc.c\
|
||||||
|
path/ft_path_notdir.c\
|
||||||
|
printing/ft_putchar.c\
|
||||||
|
printing/ft_putendl.c\
|
||||||
|
printing/ft_putnbr.c\
|
||||||
|
printing/ft_putstr.c\
|
||||||
|
sstr/ft_sstradd.c\
|
||||||
|
sstr/ft_sstrcat.c\
|
||||||
|
sstr/ft_sstrdel.c\
|
||||||
|
sstr/ft_sstrdup.c\
|
||||||
|
sstr/ft_sstrfree.c\
|
||||||
|
sstr/ft_sstrmerge.c\
|
||||||
|
sstr/ft_sstrprint.c\
|
||||||
|
sstr/ft_sstrprint_fd.c\
|
||||||
|
sstr/ft_sstrsort.c\
|
||||||
|
sstr/ft_sstrstr.c\
|
||||||
|
str/ft_atoi.c\
|
||||||
|
str/ft_convert_base.c\
|
||||||
|
str/ft_putaddr_fd.c\
|
||||||
|
str/ft_split_whitespaces.c\
|
||||||
|
str/ft_str3join.c\
|
||||||
|
str/ft_strappend.c\
|
||||||
|
str/ft_strbetween.c\
|
||||||
|
str/ft_strcat.c\
|
||||||
|
str/ft_strcatf.c\
|
||||||
|
str/ft_strchr.c\
|
||||||
|
str/ft_strchrcpy.c\
|
||||||
|
str/ft_strclr.c\
|
||||||
|
str/ft_strcmp.c\
|
||||||
|
str/ft_strcpy.c\
|
||||||
|
str/ft_strcspn.c\
|
||||||
|
str/ft_strcut.c\
|
||||||
|
str/ft_strdel.c\
|
||||||
|
str/ft_strdup.c\
|
||||||
|
str/ft_strdupchr.c\
|
||||||
|
str/ft_strduptr.c\
|
||||||
|
str/ft_strequ.c\
|
||||||
|
str/ft_strinsert.c\
|
||||||
|
str/ft_stris.c\
|
||||||
|
str/ft_striter.c\
|
||||||
|
str/ft_striteri.c\
|
||||||
|
str/ft_strjoin.c\
|
||||||
|
str/ft_strlcat.c\
|
||||||
|
str/ft_strlen.c\
|
||||||
|
str/ft_strlenchr.c\
|
||||||
|
str/ft_strmap.c\
|
||||||
|
str/ft_strmapi.c\
|
||||||
|
str/ft_strncat.c\
|
||||||
|
str/ft_strncmp.c\
|
||||||
|
str/ft_strncpy.c\
|
||||||
|
str/ft_strnequ.c\
|
||||||
|
str/ft_strnew.c\
|
||||||
|
str/ft_strnstr.c\
|
||||||
|
str/ft_strrchr.c\
|
||||||
|
str/ft_strreplace.c\
|
||||||
|
str/ft_strrev.c\
|
||||||
|
str/ft_strsplit.c\
|
||||||
|
str/ft_strstr.c\
|
||||||
|
str/ft_strsub.c\
|
||||||
|
str/ft_strtok.c\
|
||||||
|
str/ft_strtrim.c\
|
||||||
|
sys/create_directory.c\
|
||||||
|
sys/dup2_close.c\
|
||||||
|
sys/fd_replace.c\
|
||||||
|
sys/ft_getenv.c\
|
||||||
|
sys/ft_xattr_count.c\
|
||||||
|
sys/ft_xattr_print.c\
|
||||||
|
sys/is_directory.c\
|
||||||
|
sys/try_access.c\
|
||||||
|
time/ft_mytime_free.c\
|
||||||
|
time/ft_mytime_get.c\
|
||||||
|
time/ft_time_isrecent.c
|
||||||
|
|
||||||
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
|
NB = $(words $(SRC_BASE))
|
||||||
|
INDEX = 0
|
||||||
|
|
||||||
|
all:
|
||||||
|
@make -j $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ_DIR) $(OBJS)
|
||||||
|
@$(AR) $(NAME) $(OBJS)
|
||||||
|
@ranlib $(NAME)
|
||||||
|
@# @strip -x $(NAME)
|
||||||
|
@printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n"
|
||||||
|
|
||||||
|
$(OBJ_DIR)%.o: $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||||
|
@$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB)))))
|
||||||
|
@$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB)))))
|
||||||
|
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||||
|
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||||
|
@printf "\r\033[38;5;11m⌛ MAKE %10.10s : %2d%% \033[48;5;%dm%*s\033[0m%*s\033[48;5;255m \033[0m \033[38;5;11m %*.*s\033[0m\033[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) $(DELTA) "$@"
|
||||||
|
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||||
|
-I $(INC_DIR)
|
||||||
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
||||||
|
$(OBJ_DIR):
|
||||||
|
@$(MKDIR) $(OBJ_DIR)
|
||||||
|
@$(MKDIR) $(dir $(OBJS))
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@$(RM) $(OBJ_DIR)
|
||||||
|
@printf "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K\n"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@$(RM) $(NAME)
|
||||||
|
@printf "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K\n"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
22
42sh/libft/README.md
Normal file
22
42sh/libft/README.md
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# libft
|
||||||
|
|
||||||
|
## libc
|
||||||
|
|
||||||
|
malloc interface functions, string manipulation
|
||||||
|
|
||||||
|
## data structures
|
||||||
|
|
||||||
|
- string anipulation (`char *`)
|
||||||
|
- string array manipulation (`char **`)
|
||||||
|
- linked list (`t_list`)
|
||||||
|
- double linked list (`t_dlist`)
|
||||||
|
- binary trees (`t_btree`)
|
||||||
|
- time struct (`t_mytime`)
|
||||||
|
|
||||||
|
## ft_printf
|
||||||
|
|
||||||
|
printf rewrite
|
||||||
|
|
||||||
|
## get_next_line
|
||||||
|
|
||||||
|
read one line from a file descriptor, supports calls between multiple file descriptors.
|
||||||
55
42sh/libft/includes/btree.h
Normal file
55
42sh/libft/includes/btree.h
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/14 17:40:20 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);
|
||||||
|
t_btree *btree_map(t_btree *root, void *(*f)(void *));
|
||||||
|
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
|
||||||
43
42sh/libft/includes/cliopts.h
Normal file
43
42sh/libft/includes/cliopts.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cliopts.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/27 19:46:01 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CLIOPTS_H
|
||||||
|
# define CLIOPTS_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include "error.h"
|
||||||
|
|
||||||
|
typedef struct s_cliopts t_cliopts;
|
||||||
|
typedef struct s_data_template t_data_template;
|
||||||
|
typedef long long t_flag;
|
||||||
|
|
||||||
|
struct s_cliopts
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
char *str;
|
||||||
|
t_flag flag_on;
|
||||||
|
t_flag flag_off;
|
||||||
|
int (*get)();
|
||||||
|
int arg_required:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_data_template
|
||||||
|
{
|
||||||
|
t_flag flag;
|
||||||
|
char **av_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
int cliopts_get(char **av, t_cliopts opt_map[], void *data);
|
||||||
|
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg);
|
||||||
|
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg);
|
||||||
|
|
||||||
|
#endif
|
||||||
56
42sh/libft/includes/color.h
Normal file
56
42sh/libft/includes/color.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* color.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 13:36:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/02/18 20:01:33 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 "\e[0m"
|
||||||
|
# define ON_BOLD "\e[1m"
|
||||||
|
|
||||||
|
# define ON_UNDERLINED "\e[4m"
|
||||||
|
# define ON_INVERTED "\e[7m"
|
||||||
|
|
||||||
|
# define FG_BLACK "\e[30m"
|
||||||
|
# define FG_RED "\e[31m"
|
||||||
|
# define FG_GREEN "\e[32m"
|
||||||
|
# define FG_YELLOW "\e[33m"
|
||||||
|
# define FG_BLUE "\e[34m"
|
||||||
|
# define FG_MAGENTA "\e[35m"
|
||||||
|
# define FG_CYAN "\e[36m"
|
||||||
|
|
||||||
|
# define BG_BLACK "\e[40m"
|
||||||
|
# define BG_RED "\e[41m"
|
||||||
|
# define BG_GREEN "\e[42m"
|
||||||
|
# define BG_YELLOW "\e[43m"
|
||||||
|
# define BG_BLUE "\e[44m"
|
||||||
|
# define BG_MAGENTA "\e[45m"
|
||||||
|
# define BG_CYAN "\e[46m"
|
||||||
|
# define BG_DEFAULT "\e[49m"
|
||||||
|
|
||||||
|
# define FBG_DEFAULT FG_DEFAULT BG_DEFAULT
|
||||||
|
|
||||||
|
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
|
||||||
35
42sh/libft/includes/dlst.h
Normal file
35
42sh/libft/includes/dlst.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* dlst.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 17:25:50 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
|
||||||
50
42sh/libft/includes/error.h
Normal file
50
42sh/libft/includes/error.h
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* error.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 01:53:21 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef ERROR_H
|
||||||
|
# define ERROR_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||||
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
|
# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
||||||
|
|
||||||
|
# define ERR_PROTO(u, m) "{red}%s: %s{eoc}\n", u, m
|
||||||
|
# define ERR_MSG(u, m) ft_dprintf(2, ERR_PROTO(u, m))
|
||||||
|
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
|
||||||
|
# define ERRMSG_MAX_SIZE 150
|
||||||
|
|
||||||
|
enum e_errors
|
||||||
|
{
|
||||||
|
E_NOERR,
|
||||||
|
E_CO_INV,
|
||||||
|
E_CO_INVL,
|
||||||
|
E_CO_MULT,
|
||||||
|
E_CO_MISS,
|
||||||
|
E_CO_MISSL,
|
||||||
|
E_SYS_NOFILE,
|
||||||
|
E_SYS_ISDIR,
|
||||||
|
E_SYS_NOPERM,
|
||||||
|
E_MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern char g_error_msg[E_MAX][ERRMSG_MAX_SIZE];
|
||||||
|
extern char *g_errmsg;
|
||||||
|
extern int g_errnum;
|
||||||
|
extern char **g_argv;
|
||||||
|
|
||||||
|
int error_set(int n, ...);
|
||||||
|
int ft_perror(char *utility);
|
||||||
|
|
||||||
|
#endif
|
||||||
80
42sh/libft/includes/ft_printf.h
Normal file
80
42sh/libft/includes/ft_printf.h
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ftprintf.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 09:23:06 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_PRINTF_H
|
||||||
|
# define FT_PRINTF_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
# 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(char **final, char **str, va_list ap);
|
||||||
|
t_fmt *ft_printf_parse(char **format, va_list ap);
|
||||||
|
|
||||||
|
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
|
||||||
22
42sh/libft/includes/ft_types.h
Normal file
22
42sh/libft/includes/ft_types.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_types.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/25 01:56:58 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 02:02:06 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_TYPES_H
|
||||||
|
# define FT_TYPES_H
|
||||||
|
|
||||||
|
typedef struct s_stos t_stos;
|
||||||
|
typedef struct s_stof t_stof;
|
||||||
|
typedef struct s_itof t_itof;
|
||||||
|
typedef long long int t_flag;
|
||||||
|
typedef long long int t_type;
|
||||||
|
|
||||||
|
#endif
|
||||||
31
42sh/libft/includes/get_next_line.h
Normal file
31
42sh/libft/includes/get_next_line.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/05 12:21:36 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 13:07:58 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GET_NEXT_LINE_H
|
||||||
|
# define GET_NEXT_LINE_H
|
||||||
|
# define BUFF_SIZE 32
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/uio.h>
|
||||||
|
|
||||||
|
typedef struct s_save t_save;
|
||||||
|
|
||||||
|
struct s_save
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char *str;
|
||||||
|
};
|
||||||
|
|
||||||
|
int get_next_line(int const fd, char **line);
|
||||||
|
|
||||||
|
#endif
|
||||||
90
42sh/libft/includes/libft.h
Normal file
90
42sh/libft/includes/libft.h
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/26 21:12:20 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
|
||||||
|
# include <string.h>
|
||||||
|
# include <errno.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <time.h>
|
||||||
|
|
||||||
|
# include "ft_types.h"
|
||||||
|
# include "error.h"
|
||||||
|
# include "color.h"
|
||||||
|
# include "cliopts.h"
|
||||||
|
|
||||||
|
# include "lst.h"
|
||||||
|
# include "dlst.h"
|
||||||
|
# include "btree.h"
|
||||||
|
|
||||||
|
# include "str.h"
|
||||||
|
# include "sstr.h"
|
||||||
|
# include "math.h"
|
||||||
|
# include "mytime.h"
|
||||||
|
# include "get_next_line.h"
|
||||||
|
# include "sys.h"
|
||||||
|
|
||||||
|
struct s_stos
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
char *val;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_stof
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
int (*f)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_itof
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
int (*f)();
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_printf(const char *format, ...);
|
||||||
|
int ft_dprintf(int fd, const char *format, ...);
|
||||||
|
int ft_vdprintf(int fd, const char *format, va_list ap);
|
||||||
|
int ft_asprintf(char **ret, const char *format, ...);
|
||||||
|
int ft_vasprintf(char **ret, const char *format, va_list ap);
|
||||||
|
|
||||||
|
void *ft_malloc(size_t size);
|
||||||
|
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);
|
||||||
|
void *ft_memalloc(size_t size);
|
||||||
|
void ft_memdel(void **ap);
|
||||||
|
|
||||||
|
int ft_putchar(int c);
|
||||||
|
void ft_putstr(char const *s);
|
||||||
|
void ft_putendl(char const *s);
|
||||||
|
void ft_putnbr(long n);
|
||||||
|
void ft_putnbr_hex(long n);
|
||||||
|
|
||||||
|
int ft_error_message(char *message);
|
||||||
|
|
||||||
|
int ft_putchar_fd(int 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(long n, int fd);
|
||||||
|
void ft_putnbr_hex_fd(long n, int fd);
|
||||||
|
|
||||||
|
void *ft_realloc(void *data, int size);
|
||||||
|
|
||||||
|
#endif
|
||||||
84
42sh/libft/includes/lst.h
Normal file
84
42sh/libft/includes/lst.h
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lst.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/24 20:09:05 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;
|
||||||
|
|
||||||
|
int pop(t_list **lst);
|
||||||
|
t_list *push(t_list **stack, int elem);
|
||||||
|
int top(t_list *top);
|
||||||
|
|
||||||
|
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);
|
||||||
|
int ft_lstiter(t_list *lst, int (*f)());
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *));
|
||||||
|
|
||||||
|
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
|
||||||
38
42sh/libft/includes/math.h
Normal file
38
42sh/libft/includes/math.h
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* math.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MATH_H
|
||||||
|
# define MATH_H
|
||||||
|
|
||||||
|
# define FT_WS(x) (x == ' ' || x == '\t' || x == '\n')
|
||||||
|
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
|
||||||
|
# define FT_NEG(x) ((x) < 0)
|
||||||
|
# define FT_POS(x) ((x) > 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))
|
||||||
|
|
||||||
|
char *ft_itoa(int n);
|
||||||
|
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);
|
||||||
|
void *id(void *data);
|
||||||
|
|
||||||
|
#endif
|
||||||
34
42sh/libft/includes/mytime.h
Normal file
34
42sh/libft/includes/mytime.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mytime.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 11:43:12 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/02/18 13:11:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MYTIME_H
|
||||||
|
# define MYTIME_H
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
struct s_mytime
|
||||||
|
{
|
||||||
|
char *year;
|
||||||
|
char *month;
|
||||||
|
char *day;
|
||||||
|
char *hour;
|
||||||
|
char *min;
|
||||||
|
char *sec;
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
27
42sh/libft/includes/sstr.h
Normal file
27
42sh/libft/includes/sstr.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sstr.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/24 17:46:36 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef SSTR_H
|
||||||
|
# define SSTR_H
|
||||||
|
|
||||||
|
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);
|
||||||
|
char **ft_sstrmerge(char **s1, char **s2);
|
||||||
|
void ft_sstrdel(char **sstr, int index);
|
||||||
|
void ft_sstrfree(char **sstr);
|
||||||
|
char *ft_sstrcat(char **sstr, char sep);
|
||||||
|
char *ft_sstrstr(char **sstr, char *find);
|
||||||
|
|
||||||
|
#endif
|
||||||
75
42sh/libft/includes/str.h
Normal file
75
42sh/libft/includes/str.h
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* str.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/18 13:05:53 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 11:36:58 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef STR_H
|
||||||
|
# define STR_H
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *s);
|
||||||
|
size_t ft_strlenchr(const char *s, char c);
|
||||||
|
char *ft_strdup(const char *s1);
|
||||||
|
char *ft_strdupchr(const char *str, char c);
|
||||||
|
char *ft_strduptr(char *str, int (*is)(int c));
|
||||||
|
char *ft_strcpy(char *dst, const char *src);
|
||||||
|
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||||
|
char *ft_strchrcpy(char *dst, const char *str, char c);
|
||||||
|
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);
|
||||||
|
|
||||||
|
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_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_strtok(char *s, const char *delim);
|
||||||
|
size_t ft_strcspn(char *s, const char *delim);
|
||||||
|
|
||||||
|
char *ft_path_notdir(char *path);
|
||||||
|
int ft_stris(char *str, int (*f)());
|
||||||
|
|
||||||
|
#endif
|
||||||
44
42sh/libft/includes/sys.h
Normal file
44
42sh/libft/includes/sys.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sys.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/27 00:05:25 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef SYS_H
|
||||||
|
# define SYS_H
|
||||||
|
|
||||||
|
# define FT_XATTR_SIZE 10000
|
||||||
|
# define STDIN STDIN_FILENO
|
||||||
|
# define STDOUT STDOUT_FILENO
|
||||||
|
# define STDERR STDERR_FILENO
|
||||||
|
# define STDBUG 3
|
||||||
|
|
||||||
|
# define PIPE_READ 0
|
||||||
|
# define PIPE_WRITE 1
|
||||||
|
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/xattr.h>
|
||||||
|
# include <sys/acl.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
|
||||||
|
int ft_xattr_print(char *path);
|
||||||
|
int ft_xattr_count(char *path);
|
||||||
|
|
||||||
|
char *ft_getenv(char **env, char *key);
|
||||||
|
|
||||||
|
int try_access(char *file, int exists, t_flag a_flag);
|
||||||
|
int is_directory(const char *path);
|
||||||
|
char *create_directory(const char *path, const char *old_pathnames);
|
||||||
|
|
||||||
|
int dup2_close(int fd1, int fd2);
|
||||||
|
int fd_replace(int fd1, int fd2);
|
||||||
|
int fd_minor(int fd, int minor);
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
42sh/libft/pdf/ft_printf.pdf
Normal file
BIN
42sh/libft/pdf/ft_printf.pdf
Normal file
Binary file not shown.
BIN
42sh/libft/pdf/get_next_line.fr.pdf
Normal file
BIN
42sh/libft/pdf/get_next_line.fr.pdf
Normal file
Binary file not shown.
BIN
42sh/libft/pdf/libft.fr.pdf
Normal file
BIN
42sh/libft/pdf/libft.fr.pdf
Normal file
Binary file not shown.
46
42sh/libft/src/btree/btree_apply_by_level.c
Normal file
46
42sh/libft/src/btree/btree_apply_by_level.c
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_apply_by_level.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/14 17:25:46 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
int g_level = 0;
|
||||||
|
|
||||||
|
static void btree_apply_to_level(
|
||||||
|
t_btree *root,
|
||||||
|
int level,
|
||||||
|
int is_first_elem,
|
||||||
|
void (*applyf)(void *item, int current_level, int is_first_elem))
|
||||||
|
{
|
||||||
|
if (level == g_level)
|
||||||
|
{
|
||||||
|
(*applyf)(root->item, level, is_first_elem);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_to_level(root->left, level + 1, is_first_elem, applyf);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_to_level(root->right, level + 1, 0, applyf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void btree_apply_by_level(
|
||||||
|
t_btree *root,
|
||||||
|
void (*applyf)(void *item, int current_level, int is_first_elem))
|
||||||
|
{
|
||||||
|
int height;
|
||||||
|
|
||||||
|
height = btree_level_count(root);
|
||||||
|
while (g_level < height)
|
||||||
|
{
|
||||||
|
btree_apply_to_level(root, 0, 1, applyf);
|
||||||
|
g_level++;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
42sh/libft/src/btree/btree_apply_infix.c
Normal file
23
42sh/libft/src/btree/btree_apply_infix.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/06 18:22:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_apply_infix(t_btree *root, void (*applyf)(void *))
|
||||||
|
{
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_infix(root->left, applyf);
|
||||||
|
(*applyf)(root->item);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_infix(root->right, applyf);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
22
42sh/libft/src/btree/btree_apply_prefix.c
Normal file
22
42sh/libft/src/btree/btree_apply_prefix.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/18 21:06:44 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_apply_prefix(t_btree *root, void (*applyf)(void *))
|
||||||
|
{
|
||||||
|
(*applyf)(root->item);
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_prefix(root->left, applyf);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_prefix(root->right, applyf);
|
||||||
|
}
|
||||||
23
42sh/libft/src/btree/btree_apply_suffix.c
Normal file
23
42sh/libft/src/btree/btree_apply_suffix.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_apply_suffix.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/05 11:43:08 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/05 11:43:13 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_apply_suffix(t_btree *root, void (*applyf)(void *))
|
||||||
|
{
|
||||||
|
if (root->left)
|
||||||
|
btree_apply_suffix(root->left, applyf);
|
||||||
|
if (root->right)
|
||||||
|
btree_apply_suffix(root->right, applyf);
|
||||||
|
(*applyf)(root->item);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
35
42sh/libft/src/btree/btree_create_node.c
Normal file
35
42sh/libft/src/btree/btree_create_node.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
t_btree *btree_create_node(void const *item, size_t content_size)
|
||||||
|
{
|
||||||
|
t_btree *new;
|
||||||
|
|
||||||
|
if (!(new = (t_btree *)ft_malloc(sizeof(t_btree))))
|
||||||
|
return (NULL);
|
||||||
|
new->left = 0;
|
||||||
|
new->right = 0;
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
new->content_size = 0;
|
||||||
|
new->item = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new->content_size = content_size;
|
||||||
|
new->item = ft_memalloc(content_size + 1);
|
||||||
|
ft_memcpy(new->item, item, content_size);
|
||||||
|
}
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
23
42sh/libft/src/btree/btree_del.c
Normal file
23
42sh/libft/src/btree/btree_del.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_del.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 19:43:51 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_del(t_btree **root, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (root && *root && del)
|
||||||
|
{
|
||||||
|
btree_del(&(*root)->left, del);
|
||||||
|
btree_del(&(*root)->right, del);
|
||||||
|
btree_delone(root, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
42sh/libft/src/btree/btree_delone.c
Normal file
24
42sh/libft/src/btree/btree_delone.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_delone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/05 11:45:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 12:48:55 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_delone(t_btree **root, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (root && *root)
|
||||||
|
{
|
||||||
|
if (del)
|
||||||
|
(*del)((*root)->item, (*root)->content_size);
|
||||||
|
free(*root);
|
||||||
|
*root = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
42sh/libft/src/btree/btree_insert_data.c
Normal file
43
42sh/libft/src/btree/btree_insert_data.c
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/14 16:12:47 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void btree_insert_data(
|
||||||
|
t_btree **root,
|
||||||
|
void *item,
|
||||||
|
size_t content_size,
|
||||||
|
int (*cmpf)(void *, void *))
|
||||||
|
{
|
||||||
|
t_btree *node;
|
||||||
|
|
||||||
|
if (!*root)
|
||||||
|
{
|
||||||
|
*root = btree_create_node(item, content_size);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
node = *root;
|
||||||
|
if ((*cmpf)(item, node->item) < 0)
|
||||||
|
{
|
||||||
|
if (node->left)
|
||||||
|
btree_insert_data(&node->left, item, content_size, cmpf);
|
||||||
|
else
|
||||||
|
node->left = btree_create_node(item, content_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (node->right)
|
||||||
|
btree_insert_data(&node->right, item, content_size, cmpf);
|
||||||
|
else
|
||||||
|
node->right = btree_create_node(item, content_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
42sh/libft/src/btree/btree_level_count.c
Normal file
21
42sh/libft/src/btree/btree_level_count.c
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/25 17:46:00 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
int btree_level_count(t_btree *root)
|
||||||
|
{
|
||||||
|
return (root
|
||||||
|
? 1 + FT_MAX(btree_level_count(root->left),
|
||||||
|
btree_level_count(root->right))
|
||||||
|
: 0);
|
||||||
|
}
|
||||||
27
42sh/libft/src/btree/btree_map.c
Normal file
27
42sh/libft/src/btree/btree_map.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_map.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/24 15:49:42 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
t_btree *btree_map(t_btree *root, void *(*f)(void *))
|
||||||
|
{
|
||||||
|
t_btree *new;
|
||||||
|
|
||||||
|
if (!root)
|
||||||
|
return (NULL);
|
||||||
|
if (!(new = (t_btree *)ft_malloc(sizeof(*new))))
|
||||||
|
return (NULL);
|
||||||
|
new->item = (*f)(root->item);
|
||||||
|
new->left = btree_map(root->left, f);
|
||||||
|
new->right = btree_map(root->right, f);
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
82
42sh/libft/src/btree/btree_print.c
Normal file
82
42sh/libft/src/btree/btree_print.c
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 21:06:28 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
static int print_t2(t_printdata data, char s[20][255], char b[20])
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
width = 5;
|
||||||
|
i = -1;
|
||||||
|
while (++i < width)
|
||||||
|
s[2 * data.depth][data.offset + data.left + i] = b[i];
|
||||||
|
i = -1;
|
||||||
|
if (data.depth && data.is_left)
|
||||||
|
{
|
||||||
|
while (++i < width + data.right)
|
||||||
|
s[2 * data.depth - 1]
|
||||||
|
[data.offset + data.left + width / 2 + i] = '-';
|
||||||
|
s[2 * data.depth - 1][data.offset + data.left + width / 2] = '+';
|
||||||
|
s[2 * data.depth - 1]
|
||||||
|
[data.offset + data.left + data.right + 3 * width / 2] = '+';
|
||||||
|
}
|
||||||
|
else if (data.depth && !data.is_left)
|
||||||
|
{
|
||||||
|
while (++i < width + data.left)
|
||||||
|
s[2 * data.depth - 1][data.offset - width / 2 + i] = '-';
|
||||||
|
s[2 * data.depth - 1][data.offset + data.left + width / 2] = '+';
|
||||||
|
s[2 * data.depth - 1][data.offset - width / 2 - 1] = '+';
|
||||||
|
}
|
||||||
|
return (data.left + width + data.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int print_t(t_btree *tree,
|
||||||
|
t_printdata data, char s[20][255], char *(*printer)(void *))
|
||||||
|
{
|
||||||
|
char b[20];
|
||||||
|
int width;
|
||||||
|
|
||||||
|
width = 5;
|
||||||
|
if (!tree)
|
||||||
|
return (0);
|
||||||
|
sprintf(b, "%5s", printer(tree->item));
|
||||||
|
data.left = print_t(tree->left, (t_printdata){
|
||||||
|
1, data.offset, data.depth + 1, data.left, data.right}, s, printer);
|
||||||
|
data.right = print_t(tree->right, (t_printdata){
|
||||||
|
0, data.offset + data.left + width, data.depth + 1,
|
||||||
|
data.left, data.right}, s, printer);
|
||||||
|
return (print_t2(data, s, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
void btree_print(int fd, t_btree *tree, char *(*printer)(void *))
|
||||||
|
{
|
||||||
|
char s[20][255];
|
||||||
|
char empty[255];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (++i < 20)
|
||||||
|
sprintf(s[i], "%80s", " ");
|
||||||
|
sprintf(empty, "%80s", " ");
|
||||||
|
print_t(tree, (t_printdata){0, 0, 0, 0, 0}, s, printer);
|
||||||
|
i = -1;
|
||||||
|
while (++i < 20)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(s[i], empty) == 0)
|
||||||
|
break ;
|
||||||
|
if (i == 0 && ft_strcmp(s[1], empty) == 0)
|
||||||
|
break ;
|
||||||
|
ft_dprintf(fd, "%s\n", s[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
42sh/libft/src/btree/btree_search_item.c
Normal file
30
42sh/libft/src/btree/btree_search_item.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* btree_create_node.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/23 19:04:56 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "btree.h"
|
||||||
|
|
||||||
|
void *btree_search_item(t_btree *root,
|
||||||
|
void *data_ref, int (*cmpf)(void *, void *))
|
||||||
|
{
|
||||||
|
void *out;
|
||||||
|
|
||||||
|
out = NULL;
|
||||||
|
if (root)
|
||||||
|
{
|
||||||
|
out = btree_search_item(root->left, data_ref, cmpf);
|
||||||
|
if (!out && ((*cmpf)(root->item, data_ref) == 0))
|
||||||
|
out = root->item;
|
||||||
|
if (!out)
|
||||||
|
out = btree_search_item(root->right, data_ref, cmpf);
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
22
42sh/libft/src/char/ft_isalnum.c
Normal file
22
42sh/libft/src/char/ft_isalnum.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:31:33 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalnum(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 'a' && c <= 'z')
|
||||||
|
|| (c >= 'A' && c <= 'Z')
|
||||||
|
|| (c >= '0' && c <= '9'))
|
||||||
|
return (c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
42sh/libft/src/char/ft_isalpha.c
Normal file
20
42sh/libft/src/char/ft_isalpha.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 11:59:16 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalpha(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||||
|
return (c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
42sh/libft/src/char/ft_isascii.c
Normal file
20
42sh/libft/src/char/ft_isascii.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:28 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:35:42 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isascii(int c)
|
||||||
|
{
|
||||||
|
if (c >= 0 && c <= 127)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
23
42sh/libft/src/char/ft_isdigit.c
Normal file
23
42sh/libft/src/char/ft_isdigit.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:33 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 14:56:34 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isdigit(int c)
|
||||||
|
{
|
||||||
|
unsigned char a;
|
||||||
|
|
||||||
|
a = (unsigned char)c;
|
||||||
|
if (a >= '0' && a <= '9')
|
||||||
|
return (a);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
42sh/libft/src/char/ft_isprint.c
Normal file
20
42sh/libft/src/char/ft_isprint.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isprint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:56:38 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:32:40 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isprint(int c)
|
||||||
|
{
|
||||||
|
if (c >= 32 && c <= 126)
|
||||||
|
return (c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
42sh/libft/src/char/ft_tolower.c
Normal file
20
42sh/libft/src/char/ft_tolower.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tolower.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:58:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:24:09 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_tolower(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'A' && c <= 'Z')
|
||||||
|
return (c + 32);
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
20
42sh/libft/src/char/ft_toupper.c
Normal file
20
42sh/libft/src/char/ft_toupper.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_toupper.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/03 14:53:58 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/03 15:24:40 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_toupper(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'a' && c <= 'z')
|
||||||
|
return (c - 32);
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
110
42sh/libft/src/cliopts/cliopts_get.c
Normal file
110
42sh/libft/src/cliopts/cliopts_get.c
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cliopts_get.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 15:00:35 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** void *data must be a structure starting with `int flag`
|
||||||
|
** to do polymorphism with t_data_template !
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cliopts.h"
|
||||||
|
|
||||||
|
static char *check_required(char ***av, char *arg)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
if (!av || !*av)
|
||||||
|
return (NULL);
|
||||||
|
if (!arg || !*arg || !*(arg + 1))
|
||||||
|
return (*++(*av));
|
||||||
|
ret = arg + 1;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cliopts_parse_short(
|
||||||
|
char ***av, t_cliopts opt_map[], void *data)
|
||||||
|
{
|
||||||
|
t_cliopts *map;
|
||||||
|
char *arg;
|
||||||
|
int i;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
arg = **av + 1;
|
||||||
|
i = -1;
|
||||||
|
while (arg[++i] && !(tmp = NULL))
|
||||||
|
{
|
||||||
|
if (!(map = cliopts_getmap_short(opt_map, arg[i])))
|
||||||
|
return (ERR_SET(E_CO_INV, arg[i]));
|
||||||
|
((t_data_template*)data)->flag |= map->flag_on;
|
||||||
|
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||||
|
if (map->get)
|
||||||
|
{
|
||||||
|
if (map->arg_required && !(tmp = check_required(av, arg + i)))
|
||||||
|
return (ERR_SET(E_CO_MISS, *arg));
|
||||||
|
tmp = tmp ? tmp : **av;
|
||||||
|
if ((map->get)(tmp, data))
|
||||||
|
return (ERR_SET(E_CO_MISS, *arg));
|
||||||
|
if (map->arg_required)
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (++(*av) ? 0 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cliopts_parse_long(
|
||||||
|
char ***av, t_cliopts opt_map[], void *data)
|
||||||
|
{
|
||||||
|
t_cliopts *map;
|
||||||
|
char *arg;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
arg = **av + 2;
|
||||||
|
tmp = NULL;
|
||||||
|
if (!(map = cliopts_getmap_long(opt_map, arg)))
|
||||||
|
return (ERR_SET(E_CO_INVL, arg));
|
||||||
|
((t_data_template*)data)->flag |= map->flag_on;
|
||||||
|
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||||
|
if (map->get)
|
||||||
|
{
|
||||||
|
if (map->arg_required && !(tmp = check_required(av, NULL)))
|
||||||
|
return (ERR_SET(E_CO_MISS, *arg));
|
||||||
|
if ((map->get)(tmp, data))
|
||||||
|
return (ERR_SET(E_CO_MISSL, arg));
|
||||||
|
}
|
||||||
|
++(*av);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cliopts_get(char **av, t_cliopts opt_map[], void *data)
|
||||||
|
{
|
||||||
|
if (!av)
|
||||||
|
return (1);
|
||||||
|
av++;
|
||||||
|
while (av && *av)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(*av, "-") == 0 || (ft_strcmp(*av, "--") == 0 && av++))
|
||||||
|
break ;
|
||||||
|
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
||||||
|
{
|
||||||
|
if (cliopts_parse_long(&av, opt_map, data))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else if ((*av)[0] == '-')
|
||||||
|
{
|
||||||
|
if (cliopts_parse_short(&av, opt_map, data))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
((t_data_template*)data)->av_data = av;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
35
42sh/libft/src/cliopts/cliopts_getmap.c
Normal file
35
42sh/libft/src/cliopts/cliopts_getmap.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cliopts_getmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/25 14:59:03 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 15:01:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cliopts.h"
|
||||||
|
|
||||||
|
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (opt_map[++i].c)
|
||||||
|
if (!ft_strcmp(opt_map[i].str, arg))
|
||||||
|
return (&opt_map[i]);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (opt_map[++i].c)
|
||||||
|
if (opt_map[i].c == arg)
|
||||||
|
return (&opt_map[i]);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
19
42sh/libft/src/color/ft_color_mk.c
Normal file
19
42sh/libft/src/color/ft_color_mk.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_mk.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/12 11:54:49 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_mk(t_color *color, char fg[7], char bg[7])
|
||||||
|
{
|
||||||
|
ft_strcpy(color->fg, fg);
|
||||||
|
ft_strcpy(color->bg, bg);
|
||||||
|
}
|
||||||
19
42sh/libft/src/color/ft_color_mkif.c
Normal file
19
42sh/libft/src/color/ft_color_mkif.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_mk.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/03 12:17:14 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7])
|
||||||
|
{
|
||||||
|
if (cond)
|
||||||
|
ft_color_mk(color, fg, bg);
|
||||||
|
}
|
||||||
19
42sh/libft/src/color/ft_color_reset.c
Normal file
19
42sh/libft/src/color/ft_color_reset.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_reset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 13:48:05 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/25 14:06:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_reset(void)
|
||||||
|
{
|
||||||
|
ft_putstr(FG_DEFAULT);
|
||||||
|
ft_putstr(BG_DEFAULT);
|
||||||
|
}
|
||||||
22
42sh/libft/src/color/ft_color_set.c
Normal file
22
42sh/libft/src/color/ft_color_set.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_color_set.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/25 13:53:46 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/12 11:55:03 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_color_set(t_color color)
|
||||||
|
{
|
||||||
|
char out[20];
|
||||||
|
|
||||||
|
ft_strcpy(out, color.fg);
|
||||||
|
ft_strcat(out, color.bg);
|
||||||
|
ft_putstr(out);
|
||||||
|
}
|
||||||
30
42sh/libft/src/dlst/ft_dlstadd_after.c
Normal file
30
42sh/libft/src/dlst/ft_dlstadd_after.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_add_after.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:36 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_dlstadd_after(t_dlist **alst, t_dlist *new)
|
||||||
|
{
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
new->prev = (*alst);
|
||||||
|
if (*alst)
|
||||||
|
new->next = (*alst)->next;
|
||||||
|
else
|
||||||
|
new->next = NULL;
|
||||||
|
if (new->next)
|
||||||
|
new->next->prev = new;
|
||||||
|
if (new->prev)
|
||||||
|
new->prev->next = new;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
42sh/libft/src/dlst/ft_dlstadd_before.c
Normal file
28
42sh/libft/src/dlst/ft_dlstadd_before.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_add_before.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:09 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_dlstadd_before(t_dlist **alst, t_dlist *new)
|
||||||
|
{
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
new->next = (*alst);
|
||||||
|
if (*alst)
|
||||||
|
new->prev = (*alst)->prev;
|
||||||
|
if (new->next)
|
||||||
|
new->next->prev = new;
|
||||||
|
if (new->prev)
|
||||||
|
new->prev->next = new;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
42sh/libft/src/dlst/ft_dlstdel.c
Normal file
41
42sh/libft/src/dlst/ft_dlstdel.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlstdel.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/07 17:29:54 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static void ft_dlstdelback(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (alst && *alst && del)
|
||||||
|
{
|
||||||
|
ft_dlstdelback(&(*alst)->prev, del);
|
||||||
|
ft_dlstdelone(alst, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_dlstdelfront(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (alst && *alst && del)
|
||||||
|
{
|
||||||
|
ft_dlstdelfront(&(*alst)->next, del);
|
||||||
|
ft_dlstdelone(alst, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
if (alst && *alst && del)
|
||||||
|
{
|
||||||
|
ft_dlstdelback(&(*alst)->prev, del);
|
||||||
|
ft_dlstdelfront(&(*alst)->next, del);
|
||||||
|
ft_dlstdelone(alst, del);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
42sh/libft/src/dlst/ft_dlstdelone.c
Normal file
34
42sh/libft/src/dlst/ft_dlstdelone.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_delone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:13 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/14 17:52:58 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_dlist *tmp;
|
||||||
|
|
||||||
|
tmp = *alst;
|
||||||
|
if (tmp)
|
||||||
|
{
|
||||||
|
if (del)
|
||||||
|
(*del)(tmp->content, tmp->content_size);
|
||||||
|
if (tmp->next)
|
||||||
|
tmp->next->prev = tmp->prev;
|
||||||
|
if (tmp->prev)
|
||||||
|
tmp->prev->next = tmp->next;
|
||||||
|
if (tmp->prev)
|
||||||
|
*alst = tmp->prev;
|
||||||
|
else
|
||||||
|
*alst = tmp->next;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
42sh/libft/src/dlst/ft_dlstlast.c
Normal file
20
42sh/libft/src/dlst/ft_dlstlast.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_last.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:15 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_dlist *ft_dlstlast(t_dlist *list)
|
||||||
|
{
|
||||||
|
while (list && list->next)
|
||||||
|
list = list->next;
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
39
42sh/libft/src/dlst/ft_dlstnew.c
Normal file
39
42sh/libft/src/dlst/ft_dlstnew.c
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_new.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_dlist *ft_dlstnew(void const *content, size_t content_size)
|
||||||
|
{
|
||||||
|
t_dlist *new;
|
||||||
|
|
||||||
|
if (!content)
|
||||||
|
{
|
||||||
|
new = ft_malloc(sizeof(*new));
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
new->content_size = 0;
|
||||||
|
new->content = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new = (t_dlist *)ft_malloc(sizeof(*new));
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
new->content_size = content_size;
|
||||||
|
new->content = ft_memalloc(content_size + 1);
|
||||||
|
ft_memcpy(new->content, content, content_size);
|
||||||
|
}
|
||||||
|
new->next = NULL;
|
||||||
|
new->prev = NULL;
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
30
42sh/libft/src/dlst/ft_dlstrtostr.c
Normal file
30
42sh/libft/src/dlst/ft_dlstrtostr.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlstrtostr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:29 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/14 16:13:24 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_dlsttostr(t_dlist *list)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return (NULL);
|
||||||
|
while (list->prev)
|
||||||
|
list = list->prev;
|
||||||
|
str = (char *)ft_strnew(sizeof(char) * (ft_dlstsize(list) + 2));
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
ft_strcat(str, (char *)list->content);
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
36
42sh/libft/src/dlst/ft_dlstsize.c
Normal file
36
42sh/libft/src/dlst/ft_dlstsize.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_dlst_size.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:27:23 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 13:27:23 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_dlstsize(t_dlist *list)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
t_dlist *tmp;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
if (list)
|
||||||
|
size++;
|
||||||
|
tmp = list;
|
||||||
|
while (tmp->next)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
tmp = list;
|
||||||
|
while (tmp->prev)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
tmp = tmp->prev;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
48
42sh/libft/src/error/error.c
Normal file
48
42sh/libft/src/error/error.c
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/25 01:53:25 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] =
|
||||||
|
{
|
||||||
|
"unknown error 0",
|
||||||
|
"invalid option -%c",
|
||||||
|
"invalid option --%s",
|
||||||
|
"option '%c' awaits argument(s): please don't combine",
|
||||||
|
"option '%c': missing argument",
|
||||||
|
"option '%s': missing argument",
|
||||||
|
"%s: no such file or directory",
|
||||||
|
"%s: Is a directory",
|
||||||
|
"%s: Permission denied",
|
||||||
|
};
|
||||||
|
|
||||||
|
int g_errnum = 0;
|
||||||
|
char *g_errmsg = NULL;
|
||||||
|
char **g_argv;
|
||||||
|
|
||||||
|
int error_set(int n, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
g_errnum = n;
|
||||||
|
va_start(ap, n);
|
||||||
|
ft_strdel(&g_errmsg);
|
||||||
|
ft_vasprintf(&g_errmsg, g_error_msglist[n], ap);
|
||||||
|
return (g_errnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_perror(char *utility)
|
||||||
|
{
|
||||||
|
utility = utility ? utility : g_argv[0];
|
||||||
|
ERR_MSG(utility, g_errmsg);
|
||||||
|
return (g_errnum);
|
||||||
|
}
|
||||||
69
42sh/libft/src/ft_printf/ft_conversion.c
Normal file
69
42sh/libft/src/ft_printf/ft_conversion.c
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_conversion.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
static char base10[] = "0123456789";
|
||||||
|
long long arg;
|
||||||
|
|
||||||
|
arg = va_arg(ap, int);
|
||||||
|
(void)fmt;
|
||||||
|
return (ft_lltoa_base(arg, base10, fmt->flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_unsigned_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
unsigned int uiarg;
|
||||||
|
unsigned long long ullarg;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
if (!*fmt->modifier
|
||||||
|
|| ft_strequ(fmt->modifier, "hh")
|
||||||
|
|| ft_strequ(fmt->modifier, "h")
|
||||||
|
|| ft_strequ(fmt->modifier, "z"))
|
||||||
|
{
|
||||||
|
uiarg = va_arg(ap, int);
|
||||||
|
return (ft_uitoa_base(uiarg, g_convs[i].base));
|
||||||
|
}
|
||||||
|
ullarg = va_arg(ap, long long);
|
||||||
|
return (ft_ulltoa_base(ullarg, g_convs[i].base));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_char_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
(void)fmt;
|
||||||
|
ret = (char *)ft_malloc(sizeof(char) + 1);
|
||||||
|
ret[0] = (char)va_arg(ap, int);
|
||||||
|
ret[1] = '\0';
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_str_conversion(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
(void)fmt;
|
||||||
|
ret = va_arg(ap, char *);
|
||||||
|
if (ret == NULL)
|
||||||
|
return (ft_strdup("NULL"));
|
||||||
|
ret = ft_strdup(ret);
|
||||||
|
if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
|
||||||
|
ret[fmt->precision] = '\0';
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
31
42sh/libft/src/ft_printf/ft_fmt_simplify.c
Normal file
31
42sh/libft/src/ft_printf/ft_fmt_simplify.c
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt_validate.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:53:54 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_simplify(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char hashtag;
|
||||||
|
|
||||||
|
hashtag = '#';
|
||||||
|
if (fmt->conversion == 'p')
|
||||||
|
{
|
||||||
|
fmt->conversion = 'x';
|
||||||
|
if (!ft_strchr(fmt->flags, '#'))
|
||||||
|
ft_strncat(fmt->flags, &hashtag, 1);
|
||||||
|
}
|
||||||
|
if (ft_strchr("DOUCS", fmt->conversion))
|
||||||
|
{
|
||||||
|
fmt->conversion += 32;
|
||||||
|
ft_strcpy(fmt->modifier, "l");
|
||||||
|
}
|
||||||
|
}
|
||||||
24
42sh/libft/src/ft_printf/ft_fmt_validate_conv.c
Normal file
24
42sh/libft/src/ft_printf/ft_fmt_validate_conv.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:55:36 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:55:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_fmt_validate_conv(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion))
|
||||||
|
{
|
||||||
|
if (fmt->conversion != '%')
|
||||||
|
ft_fmt_error_conv(fmt->conversion);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
60
42sh/libft/src/ft_printf/ft_fmt_validate_flags.c
Normal file
60
42sh/libft/src/ft_printf/ft_fmt_validate_flags.c
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_flags.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/05 15:19:35 by wescande ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
static void ft_fmt_validate_flag_flag(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char *flag_ptr;
|
||||||
|
|
||||||
|
if (ft_strchr(fmt->flags, '+') && (flag_ptr = ft_strchr(fmt->flags, ' ')))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_flag(' ', '+');
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
if (ft_strchr(fmt->flags, '-') && (flag_ptr = ft_strchr(fmt->flags, '0')))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_flag('0', '-');
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
if (fmt->precision && (flag_ptr = ft_strchr(fmt->flags, '0')))
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_fmt_validate_flag_conv(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char *flag_ptr;
|
||||||
|
char flag;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
flag_ptr = fmt->flags;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
while (*flag_ptr)
|
||||||
|
{
|
||||||
|
flag = *flag_ptr;
|
||||||
|
if (!ft_strchr(g_convs[i].allowed_flags, flag))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_conv(flag, fmt->conversion);
|
||||||
|
if (flag == '#')
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
flag_ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_validate_flags(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
ft_fmt_validate_flag_conv(fmt);
|
||||||
|
ft_fmt_validate_flag_flag(fmt);
|
||||||
|
}
|
||||||
20
42sh/libft/src/ft_printf/ft_fmt_validate_mod.c
Normal file
20
42sh/libft/src/ft_printf/ft_fmt_validate_mod.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:53:42 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:53:52 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_validate_mod(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (fmt->conversion == 's' || fmt->conversion == 'c')
|
||||||
|
if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l"))
|
||||||
|
ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion);
|
||||||
|
}
|
||||||
37
42sh/libft/src/ft_printf/ft_printf.c
Normal file
37
42sh/libft/src/ft_printf/ft_printf.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:28:56 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_printf(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
return (ft_vdprintf(1, format, ap));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_dprintf(int fd, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
return (ft_vdprintf(fd, format, ap));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_asprintf(char **ret, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
return (ft_vasprintf(ret, format, ap));
|
||||||
|
}
|
||||||
53
42sh/libft/src/ft_printf/ft_printf_color.c
Normal file
53
42sh/libft/src/ft_printf/ft_printf_color.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf_color.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_stos g_colors[] =
|
||||||
|
{
|
||||||
|
{"{red}", FG_RED},
|
||||||
|
{"{gre}", FG_GREEN},
|
||||||
|
{"{yel}", FG_YELLOW},
|
||||||
|
{"{blu}", FG_BLUE},
|
||||||
|
{"{mag}", FG_MAGENTA},
|
||||||
|
{"{cya}", FG_CYAN},
|
||||||
|
{"{bla}", FG_BLACK},
|
||||||
|
{"{eoc}", FG_DEFAULT},
|
||||||
|
{"{bol}", ON_BOLD},
|
||||||
|
{"{und}", ON_UNDERLINED},
|
||||||
|
{"{inv}", ON_INVERTED},
|
||||||
|
{NULL, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
void ft_printf_color(char **final, char **str, va_list ap)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (ft_strncmp(*str, "{ran}", 5) == 0)
|
||||||
|
{
|
||||||
|
i = va_arg(ap, int) % 6;
|
||||||
|
*final = ft_strjoin(*final, g_colors[i].val);
|
||||||
|
*str += 5;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
while (g_colors[i].key)
|
||||||
|
{
|
||||||
|
if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
|
||||||
|
{
|
||||||
|
*final = ft_strjoin(*final, g_colors[i].val);
|
||||||
|
*str += 5;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
123
42sh/libft/src/ft_printf/ft_printf_parse.c
Normal file
123
42sh/libft/src/ft_printf/ft_printf_parse.c
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_parse.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
static void ft_printf_parse_flags(t_fmt *fmt, char **format)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = *format;
|
||||||
|
while (str[i])
|
||||||
|
{
|
||||||
|
if (ft_strchr(ALL_FLAGS, (int)str[i]))
|
||||||
|
{
|
||||||
|
if (!ft_strchr(fmt->flags, (int)str[i]))
|
||||||
|
ft_strncat(fmt->flags, str + i, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
*format += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buf[10];
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = *format;
|
||||||
|
if (str[i] == '*')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
fmt->width = va_arg(ap, int);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_strcpy(buf, "0");
|
||||||
|
while (ft_isdigit((int)(str[i])))
|
||||||
|
ft_strncat(buf, str + i++, 1);
|
||||||
|
fmt->width = ft_atoi(buf);
|
||||||
|
}
|
||||||
|
*format += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buf[10];
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = *format;
|
||||||
|
if (str[i] == '.')
|
||||||
|
{
|
||||||
|
if (str[++i] == '*')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
fmt->precision = va_arg(ap, int);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_strcpy(buf, "0");
|
||||||
|
while (ft_isdigit(str[i]))
|
||||||
|
ft_strncat(buf, str + i++, 1);
|
||||||
|
fmt->precision = ft_atoi(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*format += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_printf_parse_modifiers(t_fmt *fmt, char **format)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = *format;
|
||||||
|
if (str[0] == 'h' && str[1] == 'h')
|
||||||
|
ft_strcpy(fmt->modifier, "hh");
|
||||||
|
else if (str[0] == 'h' && str[1] != 'h')
|
||||||
|
ft_strcpy(fmt->modifier, "h");
|
||||||
|
else if (str[0] == 'l' && str[1] == 'l')
|
||||||
|
ft_strcpy(fmt->modifier, "ll");
|
||||||
|
else if (str[0] == 'l' && str[1] != 'l')
|
||||||
|
ft_strcpy(fmt->modifier, "l");
|
||||||
|
else if (str[0] == 'j')
|
||||||
|
ft_strcpy(fmt->modifier, "j");
|
||||||
|
else if (str[0] == 'z')
|
||||||
|
ft_strcpy(fmt->modifier, "z");
|
||||||
|
else
|
||||||
|
ft_strcpy(fmt->modifier, "");
|
||||||
|
*format += ft_strlen(fmt->modifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_fmt *ft_printf_parse(char **format, va_list ap)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
|
||||||
|
fmt = ft_fmt_init();
|
||||||
|
ft_printf_parse_flags(fmt, format);
|
||||||
|
ft_printf_parse_width(fmt, format, ap);
|
||||||
|
ft_printf_parse_precision(fmt, format, ap);
|
||||||
|
ft_printf_parse_modifiers(fmt, format);
|
||||||
|
fmt->conversion = **format;
|
||||||
|
(*format)++;
|
||||||
|
ft_fmt_validate_mod(fmt);
|
||||||
|
ft_fmt_validate_flags(fmt);
|
||||||
|
ft_fmt_simplify(fmt);
|
||||||
|
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
|
||||||
|
return (fmt);
|
||||||
|
}
|
||||||
34
42sh/libft/src/ft_printf/ft_transform.c
Normal file
34
42sh/libft/src/ft_printf/ft_transform.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_transform.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 10:26:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
char *ft_transform(t_fmt *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
fmt->conv = g_convs[i];
|
||||||
|
ret = (*fmt->conv.converter)(fmt, ap);
|
||||||
|
if (fmt->width > (int)ft_strlen(ret))
|
||||||
|
ret = ft_realloc(ret, fmt->width + 5);
|
||||||
|
else
|
||||||
|
ret = ft_realloc(ret, ft_strlen(ret) + 3);
|
||||||
|
if (ft_strchr(fmt->flags, '-'))
|
||||||
|
ft_pad_right(ret, fmt);
|
||||||
|
else
|
||||||
|
ft_pad_left(ret, fmt);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
85
42sh/libft/src/ft_printf/ft_vprintf.c
Normal file
85
42sh/libft/src/ft_printf/ft_vprintf.c
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_vprintf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/22 17:22:30 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_conv g_convs[] =
|
||||||
|
{
|
||||||
|
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
||||||
|
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
||||||
|
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
|
||||||
|
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
|
||||||
|
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
||||||
|
{'s', "-", "", &ft_str_conversion, NULL},
|
||||||
|
{'c', "-", "", &ft_char_conversion, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
int ft_vdprintf(int fd, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
char size;
|
||||||
|
|
||||||
|
ret = NULL;
|
||||||
|
size = ft_vasprintf(&ret, format, ap);
|
||||||
|
if (size != -1)
|
||||||
|
ft_putstr_fd(ret, fd);
|
||||||
|
ft_strdel(&ret);
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_vasprintf(char **ret, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
char *tmp;
|
||||||
|
char *final;
|
||||||
|
|
||||||
|
str = (char *)format;
|
||||||
|
final = ft_strnew(1);
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
tmp = final;
|
||||||
|
if (*str == '{')
|
||||||
|
ft_printf_color(&final, &str, ap);
|
||||||
|
else if (*str == '%')
|
||||||
|
{
|
||||||
|
if (ft_fmtcalc(&final, &str, ap))
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
else if (!(final = ft_strjoin(final, (char[]){*str++, 0})))
|
||||||
|
return (-1);
|
||||||
|
ft_strdel(&tmp);
|
||||||
|
}
|
||||||
|
*ret = final;
|
||||||
|
return (ft_strlen(final));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_fmtcalc(char **final, char **str, va_list ap)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
char *transform;
|
||||||
|
|
||||||
|
*str += 1;
|
||||||
|
if (!(fmt = ft_printf_parse(str, ap)))
|
||||||
|
return (1);
|
||||||
|
if (!fmt->valid)
|
||||||
|
ft_strncat(*final, &fmt->conversion, 1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transform = ft_transform(fmt, ap);
|
||||||
|
*final = ft_strjoin(*final, transform);
|
||||||
|
ft_strdel(&transform);
|
||||||
|
}
|
||||||
|
free(fmt);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
49
42sh/libft/src/ft_printf/lib_fmt.c
Normal file
49
42sh/libft/src/ft_printf/lib_fmt.c
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
t_fmt *ft_fmt_init(void)
|
||||||
|
{
|
||||||
|
t_fmt *fmt;
|
||||||
|
|
||||||
|
fmt = (t_fmt *)ft_malloc(sizeof(t_fmt) + 1);
|
||||||
|
ft_bzero(fmt->flags, 6);
|
||||||
|
ft_bzero(fmt->modifier, 3);
|
||||||
|
fmt->conversion = '\0';
|
||||||
|
fmt->width = 0;
|
||||||
|
fmt->precision = 0;
|
||||||
|
fmt->valid = 0;
|
||||||
|
return (fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_print(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
ft_putendl("\n---");
|
||||||
|
ft_putstr("valid: ");
|
||||||
|
ft_putnbr(fmt->valid);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("conv.: ");
|
||||||
|
ft_putchar(fmt->conversion);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("flags: ");
|
||||||
|
ft_putendl(fmt->flags);
|
||||||
|
ft_putstr("width: ");
|
||||||
|
ft_putnbr(fmt->width);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("prec.: ");
|
||||||
|
ft_putnbr(fmt->precision);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("modifier: ");
|
||||||
|
ft_putendl(fmt->modifier);
|
||||||
|
ft_putendl("---");
|
||||||
|
}
|
||||||
47
42sh/libft/src/ft_printf/lib_fmt_error.c
Normal file
47
42sh/libft/src/ft_printf/lib_fmt_error.c
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt_error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:38 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 17:22:41 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_error_conv(char conv)
|
||||||
|
{
|
||||||
|
ft_putstr("Warning: invalid or unsupported conversion specifier '");
|
||||||
|
ft_putchar(conv);
|
||||||
|
ft_putendl("'");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_error_mod_conv(char *mod, char conv)
|
||||||
|
{
|
||||||
|
ft_putstr("warning: length modifier '");
|
||||||
|
ft_putstr(mod);
|
||||||
|
ft_putstr("' results in undefined behaviour or no effect with '");
|
||||||
|
ft_putchar(conv);
|
||||||
|
ft_putendl("' conversion specifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_error_flag_conv(char flag, char conv)
|
||||||
|
{
|
||||||
|
ft_putstr("warning: flag '");
|
||||||
|
ft_putchar(flag);
|
||||||
|
ft_putstr("' results in undefined behaviour with '");
|
||||||
|
ft_putchar(conv);
|
||||||
|
ft_putendl("' conversion specifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_error_flag_flag(char flag1, char flag2)
|
||||||
|
{
|
||||||
|
ft_putstr("warning: flag '");
|
||||||
|
ft_putchar(flag1);
|
||||||
|
ft_putstr("' is ignored when flag '");
|
||||||
|
ft_putchar(flag2);
|
||||||
|
ft_putendl("' is present");
|
||||||
|
}
|
||||||
42
42sh/libft/src/ft_printf/lib_pad.c
Normal file
42
42sh/libft/src/ft_printf/lib_pad.c
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_pad.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/02/18 13:14:30 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_pad_right(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (ft_strchr(fmt->flags, '#'))
|
||||||
|
(fmt->conv.sharp_func)(str, fmt);
|
||||||
|
while ((int)ft_strlen(str) < fmt->width)
|
||||||
|
ft_strcat(str, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_pad_left(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char sign;
|
||||||
|
|
||||||
|
sign = 0;
|
||||||
|
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
|
||||||
|
{
|
||||||
|
sign = str[0];
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
if (ft_strchr(fmt->flags, '0'))
|
||||||
|
while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0))
|
||||||
|
ft_strcatf(str, "0");
|
||||||
|
if (sign)
|
||||||
|
str--;
|
||||||
|
if (ft_strchr(fmt->flags, '#'))
|
||||||
|
(fmt->conv.sharp_func)(str, fmt);
|
||||||
|
while ((int)ft_strlen(str) < fmt->width)
|
||||||
|
ft_strcatf(str, " ");
|
||||||
|
}
|
||||||
44
42sh/libft/src/ft_printf/lib_pad_sharp.c
Normal file
44
42sh/libft/src/ft_printf/lib_pad_sharp.c
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_pad_sharp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
|
(void)fmt;
|
||||||
|
ft_bzero(buf, 100);
|
||||||
|
if (str[0] != '0')
|
||||||
|
ft_strcatf(buf, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char start[3];
|
||||||
|
|
||||||
|
start[0] = '0';
|
||||||
|
start[1] = fmt->conversion;
|
||||||
|
start[2] = 0;
|
||||||
|
if (str[0] == '0')
|
||||||
|
{
|
||||||
|
if (str[1] == '0')
|
||||||
|
str[1] = fmt->conversion;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str[0] = fmt->conversion;
|
||||||
|
ft_strcatf(str, "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_strcatf(str, start);
|
||||||
|
}
|
||||||
89
42sh/libft/src/get_next_line/get_next_line.c
Normal file
89
42sh/libft/src/get_next_line/get_next_line.c
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "get_next_line.h"
|
||||||
|
|
||||||
|
static int ft_fdcmp(t_save *a, int *b)
|
||||||
|
{
|
||||||
|
return (a->fd - *b);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_gnlfree(void *a, size_t size)
|
||||||
|
{
|
||||||
|
(void)size;
|
||||||
|
ft_strdel(&((t_save*)a)->str);
|
||||||
|
free(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static t_list *ft_newfd(t_list **head, int fd)
|
||||||
|
{
|
||||||
|
t_save new;
|
||||||
|
|
||||||
|
new.fd = fd;
|
||||||
|
new.str = ft_memalloc((BUFF_SIZE > 0 ? BUFF_SIZE : 0) + 1);
|
||||||
|
ft_lstadd(head, ft_lstnew(&new, sizeof(t_save)));
|
||||||
|
return (*head);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_loop_read(int fd, char **line, char *save)
|
||||||
|
{
|
||||||
|
char buf[BUFF_SIZE + 1];
|
||||||
|
char *pos;
|
||||||
|
char *tmp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
|
||||||
|
{
|
||||||
|
buf[ret] = 0;
|
||||||
|
tmp = *line;
|
||||||
|
if ((pos = ft_strchr(buf, '\n')))
|
||||||
|
{
|
||||||
|
ft_strcpy(save, pos + 1);
|
||||||
|
*pos = 0;
|
||||||
|
}
|
||||||
|
if (!(*line = ft_strjoin(*line, buf)))
|
||||||
|
return (-1);
|
||||||
|
ft_strdel(&tmp);
|
||||||
|
if (pos)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (ret < 0)
|
||||||
|
return (-1);
|
||||||
|
return (**line ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_next_line(int const fd, char **line)
|
||||||
|
{
|
||||||
|
static t_list *head;
|
||||||
|
t_list *tmp;
|
||||||
|
char *pos;
|
||||||
|
char *save;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (fd < 0 || !line)
|
||||||
|
return (-1);
|
||||||
|
if (!(tmp = ft_lst_find(head, (void *)&fd, &ft_fdcmp)))
|
||||||
|
tmp = ft_newfd(&head, fd);
|
||||||
|
save = ((t_save*)tmp->content)->str;
|
||||||
|
if (!(*line = ft_strdup(save)))
|
||||||
|
return (-1);
|
||||||
|
ft_bzero(save, BUFF_SIZE + 1);
|
||||||
|
if ((pos = ft_strchr(*line, '\n')))
|
||||||
|
{
|
||||||
|
ft_strcpy(save, pos + 1);
|
||||||
|
*pos = 0;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (!(ret = ft_loop_read(fd, line, save)))
|
||||||
|
ft_lst_delif(&head, (int *)&fd, ft_fdcmp, &ft_gnlfree);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
18
42sh/libft/src/lst/ft_id.c
Normal file
18
42sh/libft/src/lst/ft_id.c
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_id.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:08:55 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/07 22:43:40 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_id(t_list *a)
|
||||||
|
{
|
||||||
|
return (a);
|
||||||
|
}
|
||||||
28
42sh/libft/src/lst/ft_lst_at.c
Normal file
28
42sh/libft/src/lst/ft_lst_at.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_at.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:18:48 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/12 14:58:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "lst.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_at(t_list *list, unsigned int nbr)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (i < nbr && list)
|
||||||
|
{
|
||||||
|
list = list->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (list);
|
||||||
|
}
|
||||||
26
42sh/libft/src/lst/ft_lst_bfree.c
Normal file
26
42sh/libft/src/lst/ft_lst_bfree.c
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_bfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/07 16:55:04 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/07 18:07:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_bfree(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
t_list *lst;
|
||||||
|
|
||||||
|
lst = ptr;
|
||||||
|
(void)size;
|
||||||
|
if (lst)
|
||||||
|
{
|
||||||
|
ft_strdel((char **)&lst->content);
|
||||||
|
free(lst);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
42sh/libft/src/lst/ft_lst_cfree.c
Normal file
20
42sh/libft/src/lst/ft_lst_cfree.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_cfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/07 16:55:43 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_cfree(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
(void)size;
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
36
42sh/libft/src/lst/ft_lst_delif.c
Normal file
36
42sh/libft/src/lst/ft_lst_delif.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_delif.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/27 17:45:01 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_delif(
|
||||||
|
t_list **alst,
|
||||||
|
void *data_ref,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
|
{
|
||||||
|
tmp = (*indirect);
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
42sh/libft/src/lst/ft_lst_delsub.c
Normal file
36
42sh/libft/src/lst/ft_lst_delsub.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_delsub.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/01/12 14:33:28 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_delsub(
|
||||||
|
t_list **alst,
|
||||||
|
t_list *sub,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, sub->content) == 0)
|
||||||
|
{
|
||||||
|
tmp = *indirect;
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
sub = sub->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
}
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
42sh/libft/src/lst/ft_lst_filter.c
Normal file
35
42sh/libft/src/lst/ft_lst_filter.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_filter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/02 17:47:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_filter(
|
||||||
|
t_list *lst,
|
||||||
|
void const *data_ref,
|
||||||
|
t_list *(*f)(t_list *elem, void const *))
|
||||||
|
{
|
||||||
|
t_list *out;
|
||||||
|
t_list *elem;
|
||||||
|
|
||||||
|
out = NULL;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
if (f)
|
||||||
|
elem = (*f)(lst, data_ref);
|
||||||
|
else
|
||||||
|
elem = lst;
|
||||||
|
elem = ft_lstnew(elem->content, elem->content_size);
|
||||||
|
ft_lsteadd(&out, elem);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
27
42sh/libft/src/lst/ft_lst_find.c
Normal file
27
42sh/libft/src/lst/ft_lst_find.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_find.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:20 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/01/10 11:07:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)())
|
||||||
|
{
|
||||||
|
t_list *list_ptr;
|
||||||
|
|
||||||
|
list_ptr = begin_list;
|
||||||
|
while (list_ptr)
|
||||||
|
{
|
||||||
|
if ((cmp)(list_ptr->content, data_ref) == 0)
|
||||||
|
return (list_ptr);
|
||||||
|
list_ptr = list_ptr->next;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
28
42sh/libft/src/lst/ft_lst_merge.c
Normal file
28
42sh/libft/src/lst/ft_lst_merge.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_merge.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:50:32 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/04 11:09:24 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2)
|
||||||
|
{
|
||||||
|
t_list *list_ptr;
|
||||||
|
|
||||||
|
if (*begin_list1)
|
||||||
|
{
|
||||||
|
list_ptr = *begin_list1;
|
||||||
|
while (list_ptr->next)
|
||||||
|
list_ptr = list_ptr->next;
|
||||||
|
list_ptr->next = begin_list2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*begin_list1 = begin_list2;
|
||||||
|
}
|
||||||
41
42sh/libft/src/lst/ft_lst_order_delsub.c
Normal file
41
42sh/libft/src/lst/ft_lst_order_delsub.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_order_delsub.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/04 12:01:47 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_order_delsub(
|
||||||
|
t_list **alst,
|
||||||
|
t_list *sub,
|
||||||
|
int (*cmp)(),
|
||||||
|
void (*del)(void *, size_t))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
|
indirect = alst;
|
||||||
|
while (*indirect)
|
||||||
|
{
|
||||||
|
if ((*cmp)((*indirect)->content, sub->content) > 0)
|
||||||
|
{
|
||||||
|
sub = sub->next;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
if ((*cmp)((*indirect)->content, sub->content) == 0)
|
||||||
|
{
|
||||||
|
tmp = *indirect;
|
||||||
|
(*indirect) = (*indirect)->next;
|
||||||
|
ft_lstdelone(&tmp, del);
|
||||||
|
sub = sub->next;
|
||||||
|
}
|
||||||
|
indirect = &(*indirect)->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
42sh/libft/src/lst/ft_lst_print.c
Normal file
25
42sh/libft/src/lst/ft_lst_print.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lst_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/26 21:25:21 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_print(t_list *list, void (*printer)())
|
||||||
|
{
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
ft_putstr("[");
|
||||||
|
(*printer)(list->content);
|
||||||
|
ft_putstr("]->");
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
ft_putendl("X\n");
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue