sh.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 launch_double_redirections(t_e *e, t_pipe *p, t_pipe_redir **t);
  56. void remove_cotes(char **cmd);
  57. /*
  58. ** redirect.c
  59. */
  60. void open_left_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
  61. void open_right_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
  62. void close_redirections(t_e *e, t_pipe *p, t_pipe_redir *t);
  63. /*
  64. ** heredoc.c
  65. */
  66. void prompt_redirection(t_e *e, t_pipe *p, t_pipe_redir *t, t_pipe_redir *t2);
  67. char *prompt_heredoc(t_e *e, char *txt, char *eof, int i);
  68. int here_edition(t_e *h, int heredoc);
  69. /*
  70. ** herething.c
  71. */
  72. int herething(t_e *e);
  73. void exec_herething(t_e *e, int pos, char *fc);
  74. char *prompt_herething(t_e *e, int pos, char *fc);
  75. /*
  76. ** cmd_splitting.c
  77. */
  78. char **cmd_splitting(t_e *e, char *cmd, char c);
  79. int is_on_coted_block(t_e *e, int pos);
  80. char **fill_tabe(char **tabe, char *cmd, int nbr, int *poss);
  81. /*
  82. ** exec.c
  83. */
  84. int manage_cmd_1(t_e *e, char **cmdt);
  85. void manage_cmd_2(t_e *e, char **cmdt);
  86. void execute(t_e *e, char **cmdt);
  87. void exec_if_perm_ok(t_e *e, char *path, char **cmd);
  88. char **change_tilde_to_home(t_e *e, char **cmd);
  89. /*
  90. ** env.c
  91. */
  92. char *get_tenv(t_e *e, char *var);
  93. void ft_setenv(t_e *e, char *namevalue);
  94. void ft_unsetenv(t_e *e, char *name);
  95. int isenv(char *str);
  96. /*
  97. ** tabenv.c
  98. */
  99. void add_env(t_e *e, char *nenv);
  100. void del_env(t_e *e, char *old_env);
  101. /*
  102. ** cd.c
  103. */
  104. void cd(t_e *e, char **paths);
  105. void apply_cd(t_e *e, char *path, char *pwd);
  106. char *get_pwd();
  107. /*
  108. ** tools.c
  109. */
  110. void sighandler();
  111. void error_message(char *one, char *two, char *three);
  112. int check_cmd_presence(char *cmd);
  113. #endif