Skip to content

Commit

Permalink
Revert "fix:export DIMA=DEM"
Browse files Browse the repository at this point in the history
This reverts commit e0aa44b.
  • Loading branch information
dimadem committed Aug 29, 2024
1 parent 83ba94b commit 837a167
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/builtins/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void print_env_stack(t_env *envp)
curr_node = envp;
while (curr_node)
{
ft_printf("%s=%s\n", curr_node->key, curr_node->value);
printf("%s=%s\n", curr_node->key, curr_node->value);
curr_node = curr_node->next;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int builtin_exit(t_ms_data *data)
{
const char *message;

ft_printf("\nbuiltin_exit\n");
printf("\nbuiltin_exit\n");
message = "exit\n";
write(STDOUT_FILENO, message, ft_strlen(message));
exit(data->exit_status);
Expand Down
14 changes: 13 additions & 1 deletion src/builtins/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ int builtin_export(t_ms_data *data)
{
curr_node = data->envp;
while (curr_node)
{
printf("declare -x %s=%s\n", curr_node->key, curr_node->value);
curr_node = curr_node->next;
}
else
Expand All @@ -45,17 +47,27 @@ int builtin_export(t_ms_data *data)

void add_env(char *key, t_ms_data *data)
{
int i;
int i;
char* key;

i = 0;
key = NULL;
while (data->args[++i])
{
if (ft_strchr(data->args[i], '='))
{
printf("we are here boom\n");
char* res;
res = data->args[i];
printf("curr arg -> %s\n", ft_strchr(res, '$') + 1);
set_env(&data->envp, data->args[i], \
ft_strchr(data->args[i], '=') + 1);
}
else
{
key = ft_strcdup(data->args[i], '=');
if (!key)
continue ;
if (get_env(data->envp, key))
set_env(&data->envp, key, "");
else
Expand Down
51 changes: 50 additions & 1 deletion src/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,53 @@ t_ast *manage_pipe(t_token **tokens, t_ms_data *data)
*tokens = next_token;
}
return (manage_redirs(&tmp, data));
}
}

//void print_spaces(int count) {
// for (int i = 0; i < count; i++) {
// printf(" ");
// }
//}
//
//void print_ast_node(t_ast *node, int depth) {
// if (node == NULL) {
// return;
// }
// print_spaces(depth);
// switch (node->type) {
// case PHRASE:
// printf("COMMAND: ");
// for (int i = 0; node->args && node->args[i]; i++) {
// printf("%s ", node->args[i]);
// }
// printf("\n");
// break;
// case REDIR_IN:
// printf("REDIRECTION IN: %s\n", node->args[0]);
// break;
// case REDIR_OUT:
// printf("REDIRECTION OUT: %s\n", node->args[0]);
// break;
// case REDIR_APPEND:
// printf("REDIRECTION APPEND: %s\n", node->args[0]);
// break;
// case REDIR_HEREDOC:
// printf("REDIRECTION HEREDOC: %s\n", node->args[0]);
// break;
// case PIPE:
// printf("PIPE\n");
// break;
// default:
// printf("UNKNOWN NODE TYPE\n");
// break;
// }
// if (node->left) {
// print_ast_node(node->left, depth + 1);
// }
// if (node->right) {
// print_ast_node(node->right, depth + 1);
// }
//}
//void visualize_ast(t_ast *root) {
// print_ast_node(root, 0);
//}

0 comments on commit 837a167

Please sign in to comment.