-
Notifications
You must be signed in to change notification settings - Fork 0
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
builtinコマンド exit
を追加
#72
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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,23 @@ | ||
#include "builtin.h" | ||
|
||
int builtin_exit(int argc, char **argv, int last_exit_status) | ||
{ | ||
int num; | ||
|
||
ft_putendl_fd("exit", STDERR_FILENO); | ||
if (argc == 1) | ||
exit(last_exit_status); | ||
if (argc == 2) | ||
{ | ||
if (!atoi_strict(argv[1], &num)) | ||
{ | ||
ft_putendl_fd("minishell: exit: ", STDERR_FILENO); | ||
ft_putendl_fd(argv[1], STDERR_FILENO); | ||
ft_putendl_fd(": numeric argument required", STDERR_FILENO); | ||
return (EXIT_FAILURE); | ||
} | ||
exit((unsigned char)num); //todo: free? | ||
} | ||
ft_putendl_fd("minishell: exit: too many arguments", STDERR_FILENO); | ||
return (EXIT_FAILURE); | ||
} |
This file contains 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 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,4 @@ | ||
int ft_isdigit(int c) | ||
{ | ||
return ('0' <= c && c <= '9'); | ||
} |
This file contains 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 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,3 @@ | ||
exit 0 | ||
exit 1 | ||
exit -1 |
This file contains 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,29 @@ | ||
#include "utils.h" | ||
|
||
bool atoi_strict(const char *str, int *num) | ||
{ | ||
long long converted; | ||
int sign; | ||
|
||
converted = 0; | ||
sign = 1; | ||
while (('\t' <= *str && *str <= '\r') || *str == ' ') | ||
str++; | ||
if ((*str == '+' || *str == '-') && *str++ == '-') | ||
sign = -1; | ||
if (*str == '\0') | ||
return (false); | ||
while (ft_isdigit(*str)) | ||
{ | ||
if ((converted * 10 + *str - '0') / 10 != converted) | ||
return (false); | ||
converted = converted * 10 + *str - '0'; | ||
str++; | ||
} | ||
if (*str == '\0') | ||
{ | ||
*num = (int)(sign * converted); | ||
return (true); | ||
} | ||
return (false); | ||
} |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit
をパイプで繋いだ時に、コマンドの成功・失敗の判定じゃなくてプログラム自体をexit
してる気がします。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このパターンがかなり謎いですね。。
exit
が失敗して||
で繋いでもecho hello
が実行されないという。。。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このケースはパイプ(?)・OR IFの影響じゃなくて、
exit aaa
がシンプルに成功して、exitしてるだけかと思います。ちなみにだるかったので対応してないです。(fukadaさんのテストケース見ると、exit -- 42
が成功するとかよく分からんテストケースがありますww)このパターン謎いっすね。考えられるものとしては、
exitがきたあとは何も読まないとかですかね... PRの方にも書いたんですけど、とりあえず
exit 0`とかで終了できるようにしたかっただけなので、ここら辺あんまりまだ対応する気が起きないです。Issueにでも上げておきます。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#73 ここに記載しておきましたー