char *ft_read_arg(int argc, char **argv, int i) { int ret; int fd; char buf; char *str; if (argc == 2) { str = malloc(sizeof(char) * (ft_count_arg(argc, argv) + 1)); fd = open(argv[1], O_RDONLY); while ((ret = read(fd, &buf, 1))) { str[i] = buf; i++; } str[i] = '\0'; return (str); } else return (0); }
void ft_parse_input(t_shell **shell) { if (*(*shell)->input) { (*shell)->argv = ft_parse_get_args((*shell)->input); (*shell)->argc = ft_count_arg((*shell)->argv); if ((*shell)->argc != 0) { if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "env") == 0) ft_print_environ(*shell); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "setenv") == 0) ft_setenv(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "unsetenv") == 0) ft_unsetenv(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "exit") == 0) ft_exit(&(*shell)); else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "cd") == 0) ft_cd(&(*shell)); else ft_exec_bin(&(*shell)); } } }