-
Notifications
You must be signed in to change notification settings - Fork 1
191 invoke cmd handle built in command #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7edf6ec
fix print_cmd_not_found func
dayano74 8efcd96
update built-in exit
dayano74 fffe15b
fix builit-in exit
dayano74 36cb46d
fix execute builitin
dayano74 fa18d11
Merge branch 'main' into 191-invoke_cmd-handle-built-in-command
dayano74 277587c
fix norm exit.c
dayano74 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/21 21:39:18 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/28 13:56:33 by dayano ### ########.fr */ | ||
| /* Updated: 2025/05/04 17:48:44 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
|
|
@@ -16,6 +16,7 @@ | |
| # define PATH_PREFIX_LEN 5 | ||
| # define EQUAL_LEN 1 | ||
|
|
||
| # define INCORRECT_USAGE 2 | ||
| # define CMD_FAILED_EXIT_STATUS 126 | ||
| # define CMD_NOT_FOUND_EXIT_STATUS 127 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/20 21:21:13 by dayano #+# #+# */ | ||
| /* Updated: 2025/05/01 16:38:55 by dayano ### ########.fr */ | ||
| /* Updated: 2025/05/04 18:14:32 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| int invoke_commands(t_cmd *cmd_head, t_minish *minish); | ||
| int exec_unit_builtin(t_cmd *cmd, t_minish *minish); | ||
| int execute_builtin(t_cmd *cmd, t_minish *minish); | ||
|
|
||
| // wait_pipeline.c | ||
| int wait_pipeline(t_cmd *cmd_head); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* ft_strtol.c :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/03/07 20:43:11 by dayano #+# #+# */ | ||
| /* Updated: 2025/05/04 17:29:50 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #include "libft.h" | ||
| #include <ctype.h> | ||
| #include <errno.h> | ||
| #include <limits.h> | ||
|
|
||
| long ft_strtol(const char *nptr, char **endptr, int base) | ||
| { | ||
| return ((long)ft_strtoll(nptr, endptr, base)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* ************************************************************************** */ | ||
| /* */ | ||
| /* ::: :::::::: */ | ||
| /* ft_strtoll.c :+: :+: :+: */ | ||
| /* +:+ +:+ +:+ */ | ||
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/03/09 21:02:46 by dayano #+# #+# */ | ||
| /* Updated: 2025/05/04 17:30:03 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #include "libft.h" | ||
| #include <errno.h> | ||
| #include <limits.h> | ||
| #include <stddef.h> | ||
|
|
||
| static int parse_base_and_sign(const char **str, int base, int *sign) | ||
| { | ||
| *sign = 1; | ||
| if (**str == '-' || **str == '+') | ||
| { | ||
| if (**str == '-') | ||
| *sign = -1; | ||
| (*str)++; | ||
| } | ||
| if (base == 0) | ||
| { | ||
| if (**str == '0') | ||
| { | ||
| (*str)++; | ||
| if (**str == 'x' || **str == 'X') | ||
| { | ||
| (*str)++; | ||
| return (16); | ||
| } | ||
| return (8); | ||
| } | ||
| return (10); | ||
| } | ||
| if (base == 16 && **str == '0' && (*(*str + 1) == 'x' || *(*str | ||
| + 1) == 'X')) | ||
| *str += 2; | ||
| return (base); | ||
| } | ||
|
|
||
| static int convert_digit(char c, int base) | ||
| { | ||
| const char *digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
| const char *p; | ||
|
|
||
| p = ft_strchr(digits, ft_toupper(c)); | ||
| if (p && p - digits < base) | ||
| return (p - digits); | ||
| return (-1); | ||
| } | ||
|
|
||
| static void handle_overflow(const char **str, int base, | ||
| unsigned long long *result, int sign) | ||
| { | ||
| errno = ERANGE; | ||
| *result = (unsigned long long)LLONG_MAX + ((1 - sign) >> 1); | ||
| while (convert_digit(**str, base) >= 0) | ||
| (*str)++; | ||
| } | ||
|
|
||
| static long long process_digits(const char **str, int base, int sign, | ||
| char **endptr) | ||
| { | ||
| unsigned long long result; | ||
| unsigned long long cutoff; | ||
| int cutlim; | ||
| int digit; | ||
|
|
||
| result = 0; | ||
| cutoff = (unsigned long long)LLONG_MAX + ((1 - sign) >> 1); | ||
| cutlim = cutoff % base; | ||
| cutoff /= base; | ||
| while (1) | ||
| { | ||
| digit = convert_digit(**str, base); | ||
| if (digit < 0) | ||
| break ; | ||
| if (result > cutoff || (result == cutoff && digit > cutlim)) | ||
| { | ||
| handle_overflow(str, base, &result, sign); | ||
| break ; | ||
| } | ||
| result = result * base + digit; | ||
| (*str)++; | ||
| } | ||
| if (endptr) | ||
| *endptr = (char *)*str; | ||
| return ((long long)sign * (long long)result); | ||
| } | ||
|
|
||
| long long ft_strtoll(const char *nptr, char **endptr, int base) | ||
| { | ||
| const char *str; | ||
| int sign; | ||
| long long result; | ||
|
|
||
| if (base < 0 || base == 1 || base > 36) | ||
| { | ||
| errno = EINVAL; | ||
| if (endptr) | ||
| *endptr = (char *)nptr; | ||
| return (0); | ||
| } | ||
| while (ft_isspace(*nptr)) | ||
| nptr++; | ||
| str = nptr; | ||
| base = parse_base_and_sign(&str, base, &sign); | ||
| result = process_digits(&str, base, sign, endptr); | ||
| if (str == nptr) | ||
| { | ||
| if (endptr) | ||
| *endptr = (char *)nptr; | ||
| return (0); | ||
| } | ||
| return (result); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,31 @@ | |
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/13 21:20:48 by dayano #+# #+# */ | ||
| /* Updated: 2025/05/01 15:50:02 by dayano ### ########.fr */ | ||
| /* Updated: 2025/05/04 17:54:32 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #include "main.h" | ||
|
|
||
| int builtin_exit(int argc, char *argv[], t_minish *minish) | ||
| { | ||
| long status; | ||
| char *endptr; | ||
|
|
||
| (void)minish; | ||
| if (argc != 1) | ||
| if (argc > 2) | ||
| return (error_mes(argv[0], "too many arguments"), EXIT_FAILURE); | ||
| if (printf("exit\n") < 0) | ||
| return (perror("printf"), EXIT_FAILURE); | ||
| exit(EXIT_SUCCESS); | ||
| if(argc == 1) | ||
| exit(EXIT_SUCCESS); | ||
| errno = 0; | ||
| status = ft_strtol(argv[1], &endptr, 10); | ||
| if(errno != 0 || *endptr != '\0') | ||
| { | ||
| ft_putstr_fd("minishell: exit: ", STDERR_FILENO); | ||
| error_mes(argv[1], "numeric argument required"); | ||
| exit(INCORRECT_USAGE); | ||
| } | ||
| exit((unsigned int)status); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/21 13:14:15 by dayano #+# #+# */ | ||
| /* Updated: 2025/05/01 16:51:13 by dayano ### ########.fr */ | ||
| /* Updated: 2025/05/04 18:14:21 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
|
|
@@ -57,7 +57,7 @@ static pid_t _fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds, | |
| if ((cmd->next != NULL) && is_redirect(cmd->next)) | ||
| redirect(cmd->next); | ||
| if (is_builtin(cmd)) | ||
| exit(exec_unit_builtin(cmd, minish)); | ||
| exit(execute_builtin(cmd, minish)); | ||
cacapon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| execute_cmd(cmd, minish); | ||
| print_error(cmd->argv[0]); | ||
| exit(EXIT_FAILURE); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,18 @@ | |
| /* By: dayano <[email protected]> +#+ +:+ +#+ */ | ||
| /* +#+#+#+#+#+ +#+ */ | ||
| /* Created: 2025/04/21 21:37:20 by dayano #+# #+# */ | ||
| /* Updated: 2025/04/25 20:50:51 by dayano ### ########.fr */ | ||
| /* Updated: 2025/05/04 17:04:58 by dayano ### ########.fr */ | ||
| /* */ | ||
| /* ************************************************************************** */ | ||
|
|
||
| #include "main.h" | ||
|
|
||
| void print_cmd_not_found(t_cmd *cmd) | ||
| { | ||
| ft_putstr_fd("minish: ", STDERR_FILENO); | ||
cacapon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ft_putstr_fd(cmd->argv[0], STDERR_FILENO); | ||
| ft_putstr_fd(": command not found", STDERR_FILENO); | ||
| ft_putstr_fd(": command not found\n", STDERR_FILENO); | ||
| cmd->status = CMD_NOT_FOUND_EXIT_STATUS; | ||
| exit(CMD_NOT_FOUND_EXIT_STATUS); | ||
| } | ||
|
|
||
| void free_str_array(char **str) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.