Skip to content

Commit

Permalink
feat : add_dict 인자 3개로 수정, erase_dict const 사용->널가드로 변경 #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Giromi committed Sep 14, 2022
1 parent ed04d4d commit ccea116
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
16 changes: 9 additions & 7 deletions dict_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: minsuki2 <minsuki2@student.42seoul.kr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/13 22:51:24 by minsuki2 #+# #+# */
/* Updated: 2022/09/14 22:32:29 by minsuki2 ### ########.fr */
/* Updated: 2022/09/14 22:52:33 by minsuki2 ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -36,22 +36,24 @@ t_dict *find_dict(t_dict *cur, const char *name)
return (NULL);
}

/* Please never NULL */
void erase_dict(char *name)
{
int idx = chr_to_idx(*name);
t_dict *const head_node = &g_dict[idx];
t_dict *const last_node = head_node->prev;
t_dict *find_node;
int idx;
t_dict *last_node;
t_dict *find_node;

if (!name)
return ;
idx = chr_to_idx(*name);
find_node = find_dict(&g_dict[idx], name);
if (!find_node)
return ;
find_node->prev->next = find_node->next;
if (find_node->next)
find_node->next->prev = find_node->prev;
last_node = g_dict[idx].prev;
if (find_node == last_node)
head_node->prev = find_node->prev;
g_dict[idx].prev = find_node->prev;
my_multi_free(find_node->name, find_node->value, find_node, NULL);
}

Expand Down
4 changes: 3 additions & 1 deletion envp_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jaesjeon <jaesjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/09 15:25:42 by minsuki2 #+# #+# */
/* Updated: 2022/09/14 22:28:39 by minsuki2 ### ########.fr */
/* Updated: 2022/09/14 22:35:44 by minsuki2 ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -92,6 +92,8 @@ void dict_lstadd_order(t_dict *head, t_dict *new)
val = comapre_order_dict(cur->next, new);
if (val > 0)
dict_lstadd_next(cur, new);
else if (val == 0)
return ;
cur = cur->next;
}
}
Expand Down
21 changes: 8 additions & 13 deletions minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jaesjeon <jaesjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/25 11:00:34 by jaesjeon #+# #+# */
/* Updated: 2022/09/14 22:30:56 by minsuki2 ### ########.fr */
/* Updated: 2022/09/14 22:47:00 by minsuki2 ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,19 +44,14 @@ int main(int argc, char *argv[], char *envp[])
terminal_off_control_chars();
set_exit_status(0);
envp_to_dict(envp);

put_dict(ft_strdup("a"), ft_strdup("123"));
print_dictionary_lst();
printf("------------------------------------------------------------\n");
printf("------------------------------------------------------------\n");
// add_dict(NULL, NULL, "a=34");
put_dict(ft_strdup("a"), ft_strdup("341"));
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
print_dictionary_lst();
// printf("\nreal_total = %d\n", print_strs(envp));
// printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
// strs = dict_to_envp();
// printf("\nmy_total = %d\n", print_strs(strs));
// char_dimen2_free(strs);
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
strs = dict_to_envp();
printf("\nmy_total = %d\n", print_strs(strs));
char_dimen2_free(strs);
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");

while (true)
{
full_line = liner(&oflag);
Expand Down

0 comments on commit ccea116

Please sign in to comment.