Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknamemohaji committed Apr 5, 2024
1 parent f32723a commit 3e6c210
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 43 deletions.
9 changes: 6 additions & 3 deletions codes/builtins/builtin_cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:33 by nicknamemoh #+# #+# */
/* Updated: 2024/04/04 15:46:54 by kyungjle ### ########.fr */
/* Created: 2024/03/27 06:04:33 by kyungjle #+# #+# */
/* Updated: 2024/04/05 12:45:42 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,6 +19,8 @@ int builtin_cd(char *args[], t_ld_map_env *env)
{
char *key_pwd;

if (!builtin_check_argument_count((const char **)args, 2))
return (EXIT_FAILURE);
if (args[1] != NULL)
{
if (args[1][0] == '/')
Expand All @@ -29,7 +31,8 @@ int builtin_cd(char *args[], t_ld_map_env *env)
return (EXIT_FAILURE);
}
}
else if (ft_strchr(args[1], '/') != NULL && ld_chdir(args[1]) != TRUE)
else if ((ft_strchr(args[1], '/') != NULL && ld_chdir(args[1]) != TRUE)
|| (ft_strchr(args[1], '/') == NULL && !chdir(args[1])))
return (EXIT_FAILURE);
key_pwd = ft_strdup("PWD");
if (key_pwd == NULL)
Expand Down
6 changes: 3 additions & 3 deletions codes/builtins/builtin_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtin_echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nicknamemohaji <nicknamemohaji@student. +#+ +:+ +#+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:35 by nicknamemoh #+# #+# */
/* Updated: 2024/03/27 06:43:25 by nicknamemoh ### ########.fr */
/* Created: 2024/04/05 12:45:54 by kyungjle #+# #+# */
/* Updated: 2024/04/05 12:46:00 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
13 changes: 7 additions & 6 deletions codes/builtins/builtin_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
/* +:+ +:+ +:+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:39 by nicknamemoh #+# #+# */
/* Updated: 2024/04/04 17:47:08 by kyungjle ### ########.fr */
/* Created: 2024/03/27 06:04:39 by kyungjle #+# #+# */
/* Updated: 2024/04/05 13:00:50 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

#include "builtin.h"
#include "utils.h"

int builtin_env(char *args[], t_ld_map_env *env);
int builtin_env_print(t_ld_map_env *env);
int builtin_env(char *args[], t_ld_map_env *env);
static int builtin_env_print(t_ld_map_env *env);

int builtin_env(char *args[], t_ld_map_env *env)
{
(void)args;
return (builtin_env_print(env));
}

int builtin_env_print(t_ld_map_env *env)
static int builtin_env_print(t_ld_map_env *env)
{
t_ld_map_node *node;

node = env->contents;
while (node != NULL)
{
printf("%s=%s\n", node->key, node->value);
if (ldpre_env_validate_key(node->key) == TRUE)
printf("%s=%s\n", node->key, node->value);
node = node->next;
}
return (EXIT_SUCCESS);
Expand Down
14 changes: 7 additions & 7 deletions codes/builtins/builtin_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:41 by nicknamemoh #+# #+# */
/* Updated: 2024/04/05 12:21:17 by kyungjle ### ########.fr */
/* Updated: 2024/04/05 12:31:53 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,12 +15,12 @@

int builtin_exit(char *args[], t_ld_map_env *env);
static t_bool check_digit(const char *c);
static t_bool check_argumen_count(const char *args[]);
t_bool builtin_check_argument_count(const char *args[], int limit);

int builtin_exit(char *args[], t_ld_map_env *env)
{
printf("exit\n");
if (!check_argumen_count((const char **) args))
if (!builtin_check_argument_count((const char **) args, 2))
return (1);
if (args[1] != NULL)
{
Expand Down Expand Up @@ -50,7 +50,7 @@ static t_bool check_digit(const char *c)
return (TRUE);
}

static t_bool check_argumen_count(const char *args[])
t_bool builtin_check_argument_count(const char *args[], int limit)
{
int count;

Expand All @@ -60,11 +60,11 @@ static t_bool check_argumen_count(const char *args[])
count++;
args++;
}
if (count > 2)
if (count > limit)
{
printf("exit: too many arguments\n");
printf("too many arguments\n");
return (FALSE);
}
else
return (TRUE);
}
}
19 changes: 15 additions & 4 deletions codes/builtins/builtin_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:43 by nicknamemoh #+# #+# */
/* Updated: 2024/04/04 17:47:28 by kyungjle ### ########.fr */
/* Updated: 2024/04/05 14:05:37 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

#include "builtin.h"
#include "utils.h"

int builtin_export(char *args[], t_ld_map_env *env);
int builtin_export(char *args[], t_ld_map_env *env);
static int builtin_export_print(t_ld_map_env *env);

int builtin_export(char *args[], t_ld_map_env *env)
{
int i;
char *key;
char *value;

// TODO 정렬된 상태로 출력
if (args[1] == NULL)
return (builtin_env_print(env));
return (builtin_export_print(env));
i = 1;
while (args[i] != NULL)
{
Expand All @@ -44,3 +44,14 @@ int builtin_export(char *args[], t_ld_map_env *env)
}
return (EXIT_SUCCESS);
}

static int builtin_export_print(t_ld_map_env *env)
{
char **envp;

envp = ldpre_env_toenvp_f(env);
for (int i = 0; envp[i] != NULL; i++)
printf("%s\n", envp[i]);
free_ft_split(envp);
return (EXIT_SUCCESS);
}
6 changes: 3 additions & 3 deletions codes/includes/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtin.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nicknamemohaji <nicknamemohaji@student. +#+ +:+ +#+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:05:01 by nicknamemoh #+# #+# */
/* Updated: 2024/04/01 13:05:08 by nicknamemoh ### ########.fr */
/* Updated: 2024/04/05 12:59:12 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -34,6 +34,7 @@ int builtin_echo(char *args[], t_ld_map_env *env);
// builtin_exit.c

int builtin_exit(char *args[], t_ld_map_env *env);
t_bool builtin_check_argument_count(const char *args[], int limit);

// builtin_export.c

Expand All @@ -45,7 +46,6 @@ int builtin_unset(char *args[], t_ld_map_env *env);

// builtin_env.c

int builtin_env_print(t_ld_map_env *env);
int builtin_env(char *args[], t_ld_map_env *env);

#endif
7 changes: 5 additions & 2 deletions codes/includes/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dogwak <dogwak@student.42.fr> +#+ +:+ +#+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 19:54:44 by nicknamemoh #+# #+# */
/* Updated: 2024/04/05 11:40:42 by dogwak ### ########.fr */
/* Updated: 2024/04/05 13:00:27 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,16 +49,19 @@ void input_sighandler(int sig, siginfo_t *info, void *ucontext);
void ldexec_sigign_setup(struct sigaction oldacts[2]);

// ld_map_functions.c

t_ld_map_env *ldpre_env_fromenvp_f(char **envp);
void ld_map_node_attach(t_ld_map_env *map, t_ld_map_node *node);
char **ldpre_env_toenvp_f(t_ld_map_env *map);
void free_ld_map(t_ld_map_env *map);

// ld_map_functions2.c

char *ldpre_env_fetch(char *key, t_ld_map_env *map);
void ldpre_env_add(char *key, char *value, t_ld_map_env *map);
t_bool ldpre_env_remove(char *key, t_ld_map_env *map);
t_ld_map_node **ldpre_env_searchkey(char *key, t_ld_map_env *map);
t_bool ldpre_env_validate_key(char *key);

// ft_qsort.c
void ft_qsort(void **arr, int left, int right,
Expand Down
16 changes: 10 additions & 6 deletions codes/input/input_terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* input_terminal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nicknamemohaji <nicknamemohaji@student. +#+ +:+ +#+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/12 22:19:08 by kyungjle #+# #+# */
/* Updated: 2024/03/21 11:48:24 by nicknamemoh ### ########.fr */
/* Updated: 2024/04/05 13:57:49 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -25,11 +25,14 @@ void input_terminal_setup(struct termios *oldterm)
struct termios term;

if (tcgetattr(STDIN_FILENO, &term) != 0)
do_exit("input_terminal_setup.tcgetattr");
printf(TERM_COLOR_RED "WARN" TERM_COLOR_END
"input_terminal_setup.tcgetattr");
*oldterm = term;
term.c_lflag |= (ECHO | ECHOCTL);
term.c_lflag |= ECHO;
term.c_lflag &= ~ECHOCTL;
if (tcsetattr(STDIN_FILENO, TCSANOW, &term) != 0)
do_exit("input_terminal_setup.tcsetattr");
printf(TERM_COLOR_RED "WARN" TERM_COLOR_END
"input_terminal_setup.tcsetattr");
}

/*
Expand All @@ -39,5 +42,6 @@ void input_terminal_restore(struct termios *oldterm)
void input_terminal_restore(struct termios *oldterm)
{
if (tcsetattr(STDIN_FILENO, TCSANOW, oldterm) != 0)
do_exit("input_terminal_restore.tcsetattr");
printf(TERM_COLOR_RED "WARN" TERM_COLOR_END
"input_terminal_restore.tcsetattr");
}
7 changes: 4 additions & 3 deletions codes/loader/ldpre_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 11:20:45 by kyungjle #+# #+# */
/* Updated: 2024/04/05 12:20:01 by kyungjle ### ########.fr */
/* Updated: 2024/04/05 12:54:20 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -234,13 +234,14 @@ int ldpre_ast(t_ast_node *ast, t_ld_map_env *env,
return (-2);
return (ldpre_ast(ast->left, env, exec, heredoc));
}
return -1;
return 0;
}
break;

case EXP_PRE_RREAD: // FALLTHROUGH
case EXP_PRE_RHEREDOC:
{
// TODO read 실패한 경우 처리
// TODO command가 없는 경우
if ((ast->right)->node_type == NODE_FILE)
{
Expand All @@ -261,7 +262,7 @@ int ldpre_ast(t_ast_node *ast, t_ld_map_env *env,
ldpre_ast(ast->left, env, exec, heredoc);
return (ldpre_ast(ast->right, env, exec, heredoc));
}
return -1;
return 0;
}
break;

Expand Down
2 changes: 1 addition & 1 deletion codes/loader/ldpre_ast_redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 18:41:08 by kyungjle #+# #+# */
/* Updated: 2024/04/05 12:19:56 by kyungjle ### ########.fr */
/* Updated: 2024/04/05 12:44:40 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
10 changes: 5 additions & 5 deletions codes/utils/ld_map_functions2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ char *ldpre_env_fetch(char *key, t_ld_map_env *map);
void ldpre_env_add(char *key, char *value,
t_ld_map_env *map);
t_bool ldpre_env_remove(char *key, t_ld_map_env *map);
static t_bool validate_key_format(char *key);
t_bool ldpre_env_validate_key(char *key);

/*
t_ld_map_node **ldpre_env_searchkey(char *key, t_ld_map_env *map)
Expand Down Expand Up @@ -56,7 +56,7 @@ char *ldpre_env_fetch(char *key, t_ld_map_env *map)
{
t_ld_map_node **node;

if (!validate_key_format(key))
if (!ldpre_env_validate_key(key))
{
printf("syntax error: [%s]\n", key);
return (NULL);
Expand All @@ -74,7 +74,7 @@ void ldpre_env_add(char *key, char *value, t_ld_map_env *map)
char *key_copy;
char *value_copy;

if (!validate_key_format(key))
if (!ldpre_env_validate_key(key))
{
printf("syntax error: [%s]\n", key);
return ;
Expand Down Expand Up @@ -115,11 +115,11 @@ t_bool ldpre_env_remove(char *key, t_ld_map_env *map)
}

/*
static t_bool validate_key_format(char *key)
t_bool ldpre_env_validate_key(char *key)
:param key: key string to validate
:return: TRUE if key matches requirements
*/
static t_bool validate_key_format(char *key)
t_bool ldpre_env_validate_key(char *key)
{
if (!(ft_isalpha(*key) || *key == '_'))
return (FALSE);
Expand Down

0 comments on commit 3e6c210

Please sign in to comment.