From c57c491865a9b35cfcb5288f3812cf44f74aa4ba Mon Sep 17 00:00:00 2001 From: David Orozco Date: Sat, 18 Apr 2020 16:22:26 -0500 Subject: [PATCH] Custom status added --- builtins.h | 1 + exit.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/builtins.h b/builtins.h index 7004f22..00f7767 100644 --- a/builtins.h +++ b/builtins.h @@ -12,6 +12,7 @@ int check_builtin(general_t *info, char **arguments); /* exit.c */ void bin_exit(general_t *info, char **arguments); +int number_controller(general_t *info, char *number); /* env.c */ void bin_env(general_t *info, char **arguments); diff --git a/exit.c b/exit.c index a7503e1..90ef4ed 100644 --- a/exit.c +++ b/exit.c @@ -1,4 +1,5 @@ #include "builtins.h" +#include "general.h" /** * bin_exit - Implementation of the exit builtin @@ -10,7 +11,14 @@ **/ void bin_exit(general_t *info, char **arguments) { - int status_code; + int status_code, status; + + status = _TRUE; + if (arguments[1] != NULL) + status = number_controller(info, arguments[1]); + + if (status == _FALSE) + return; status_code = info->status_code; @@ -22,3 +30,25 @@ void bin_exit(general_t *info, char **arguments) exit(status_code); } +int number_controller(general_t *info, char *number) +{ + int _number; + + _number = _atoi(number); + + if (_number < 0 || contains_letter(number)) + { + info->status_code = 2; + info->error_code = _CODE_ILLEGAL_NUMBER; + error(info); + return (_FALSE); + } + + if (_number > 255) + info->status_code = 232; + + printf("%d\n", _number); + + return (_TRUE); +} +