sh.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef SH_H
  2. # define SH_H
  3. # include "../libft/libft.h"
  4. # include "struct.h"
  5. # include "term.h"
  6. # include <stdlib.h>
  7. # include <unistd.h>
  8. # include <sys/types.h>
  9. # include <sys/wait.h>
  10. # include <dirent.h>
  11. # include <signal.h>
  12. # define PROMPT "21sh}-> "
  13. # define STDIN 0
  14. # define STDOUT 1
  15. # define STDERR 2
  16. /*
  17. ** main.c
  18. */
  19. void shell_script(t_e *e, char *script_name);
  20. void comma_split(t_e *e, char *cmd);
  21. /*
  22. ** detect_cotes.c
  23. */
  24. void init_detect_blocks(t_e *e, char *line);
  25. void detect_blocks(t_e *e, char *line, int pos, int b_pos);
  26. int coted_block(t_e *e, char *line, int pos, t_block *blk);
  27. int non_coted_block(t_e *e, char *line, int pos, t_block *blk);
  28. /*
  29. ** pipe_parsing.c
  30. */
  31. void pipe_init(t_e *e, char *all_cmd);
  32. void pipe_init_2(t_e *e, t_pipe *p, char *all_cmd);
  33. void pipe_parsing(t_pipe *p, t_e *e);
  34. void count_pipe_nbr(t_e *e, t_pipe *p, char *str);
  35. /*
  36. ** pipe_redir_parsing.c
  37. */
  38. void fill_pipe_redir_data(t_e *e, t_pipe *p, t_pipe_redir **t);
  39. void pipe_creation(t_pipe_redir **t, t_pipe *p, char *cmd);
  40. void display_data(t_pipe_redir **t);
  41. int parse_double_redir(t_e *e, char *str, t_pipe *p, t_pipe_redir **t);
  42. int parse_redirection(t_e *e, t_pipe *p, char *str, t_pipe_redir **t);
  43. /*
  44. ** parse_redirections.c
  45. */
  46. int check_chev_is_on_non_coted_block(t_e *e, char *str, char c);
  47. int check_before_after_chevron(char *str, int chev);
  48. void parse_and(char *str, t_pipe_redir *t, int file_pos);
  49. /*
  50. ** pipe_exec.c
  51. */
  52. void launch_pipes(t_e *e, t_pipe *p, t_pipe_redir **t);
  53. void handle_multi_piping(t_e *e, t_pipe *p, t_pipe_redir *t);
  54. void inside_pipe(t_e *e, t_pipe *p, t_pipe_redir *t);
  55. void remove_cotes(char **cmd);
  56. /*
  57. ** redirect.c
  58. */
  59. void open_left_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
  60. void open_right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
  61. void close_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
  62. /*
  63. ** heredoc.c
  64. */
  65. void prompt_redirection(t_e *e, t_pipe *p, t_pipe_redir *t);
  66. char *prompt_heredoc(t_e *e, char *txt, char *eof, int i);
  67. int here_edition(t_e *h, int heredoc);
  68. /*
  69. ** herething.c
  70. */
  71. int herething(t_e *e);
  72. void exec_herething(t_e *e, int pos, char *fc);
  73. char *prompt_herething(t_e *e, int pos, char *fc);
  74. /*
  75. ** cmd_splitting.c
  76. */
  77. char **cmd_splitting(t_e *e, char *cmd, char c);
  78. int is_on_coted_block(t_e *e, int pos);
  79. char **fill_tabe(char **tabe, char *cmd, int nbr, int *poss);
  80. /*
  81. ** exec.c
  82. */
  83. int manage_cmd_1(t_e *e, char **cmdt);
  84. void manage_cmd_2(t_e *e, char **cmdt);
  85. void execute(t_e *e, char **cmdt);
  86. void exec_if_perm_ok(t_e *e, char *path, char **cmd);
  87. char **change_tilde_to_home(t_e *e, char **cmd);
  88. /*
  89. ** env.c
  90. */
  91. char *get_tenv(t_e *e, char *var);
  92. void ft_setenv(t_e *e, char *namevalue);
  93. void ft_unsetenv(t_e *e, char *name);
  94. int isenv(char *str);
  95. /*
  96. ** tabenv.c
  97. */
  98. void add_env(t_e *e, char *nenv);
  99. void del_env(t_e *e, char *old_env);
  100. /*
  101. ** cd.c
  102. */
  103. void cd(t_e *e, char **paths);
  104. void apply_cd(t_e *e, char *path, char *pwd);
  105. char *get_pwd();
  106. /*
  107. ** tools.c
  108. */
  109. void sighandler();
  110. void error_message(char *one, char *two, char *three);
  111. int check_cmd_presence(char *cmd);
  112. #endif