From: Lilia-42 Date: Sat, 31 Aug 2024 11:34:06 +0000 (+0200) Subject: Make lines comply with the 42 Norm X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=4ded217aa50f900fee9406132b910c2ea8cddb72;p=42%2Fminishell.git Make lines comply with the 42 Norm --- diff --git a/src/execution.c b/src/execution.c index e367194..6e184ab 100644 --- a/src/execution.c +++ b/src/execution.c @@ -6,7 +6,7 @@ /* By: lnikolov children, simple_command->children.size - 1); + subnode = ft_vec_access(&simple_command->children, + simple_command->children.size - 1); if (is_token_type(subnode, "cmd_suffix")) if (save_redirections_psfix(redirections, subnode, env)) return (1); @@ -353,7 +371,8 @@ int save_redirections(t_vec *redirections, t_parse_tree_node *simple_command, t_ static const char space = ' '; -int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int enquote_result) +int add_word(t_vec *exp_str, const char *word, + const t_execution_env *env, int enquote_result) { size_t i; char *var; @@ -371,7 +390,8 @@ int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int e quote = '\'' * !quote; else if (word[i] == '"' && quote != '\'') quote = '"' * !quote; - if (word[i] == '$' && quote != '\'' && (ft_isalnum(word[i + 1]) || word[i + 1] == '_' || word[i + 1] == '?')) + if (word[i] == '$' && quote != '\'' && (ft_isalnum(word[i + 1]) + || word[i + 1] == '_' || word[i + 1] == '?')) { ++i; if (word[i] == '?') @@ -388,14 +408,15 @@ int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int e const_val = get_env_var_value(env, var); free(var); if (!const_val) - continue; + continue ; value = ft_strdup(const_val); } if (!value) return (1); if (enquote_result) error = error || ft_vec_append(exp_str, "'") != success; - error = error || ft_vec_append_range(exp_str, value, ft_strlen(value)) != success; + error = error || ft_vec_append_range(exp_str, + value, ft_strlen(value)) != success; if (enquote_result) error = error || ft_vec_append(exp_str, "'") != success; free(value); @@ -411,7 +432,8 @@ int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int e return (0); } -int expand_cmd(t_vec *exp_str, const t_parse_tree_node *node, const t_execution_env *env) +int expand_cmd(t_vec *exp_str, + const t_parse_tree_node *node, const t_execution_env *env) { size_t i; const t_parse_tree_node *subnode; @@ -553,14 +575,14 @@ char **expand(t_parse_tree_node *simple_command, const t_execution_env *env) while (i < simple_command->children.size) { subnode = ft_vec_access(&simple_command->children, i); - if (is_token_type(subnode, "cmd_name") + if ((is_token_type(subnode, "cmd_name") || is_token_type(subnode, "cmd_word") || is_token_type(subnode, "cmd_suffix")) - if (expand_cmd(&expanded_str, subnode, env)) - { - ft_vec_free(&expanded_str, NULL); - return (NULL); - } + && expand_cmd(&expanded_str, subnode, env)) + { + ft_vec_free(&expanded_str, NULL); + return (NULL); + } ++i; } if (ft_vec_append(&expanded_str, &null_char) != success) @@ -587,7 +609,8 @@ int assignments_to_env(const t_vec *assignments, t_execution_env *env) var_name = get_var_name(var_line); if (!var_name) return (1); - if (set_env_var_value(env, var_name, var_line + ft_strlen(var_name) + 1)) + if (set_env_var_value(env, var_name, + var_line + ft_strlen(var_name) + 1)) { free(var_name); return (1); @@ -722,10 +745,11 @@ void close_redirections(const t_vec *redirections) return ; } -int add_exported(__attribute__((unused)) t_vec *assignments, __attribute__((unused)) const t_execution_env *env) +int add_exported(__attribute__((unused)) + t_vec *assignments, __attribute__((unused)) const t_execution_env *env) { - size_t i; - char *var; + size_t i; + char *var; const t_vec *exported; exported = &env->vars->exported; @@ -733,7 +757,7 @@ int add_exported(__attribute__((unused)) t_vec *assignments, __attribute__((unus while (i < exported->size) { var = ft_strdup(*(char *const *)ft_vec_caccess(exported, i)); - if (ft_vec_append(assignments, &var) != success) // Should exported be overwritten? + if (ft_vec_append(assignments, &var) != success) return (1); ++i; } @@ -804,7 +828,9 @@ int restore_std_filenos(int fds[3]) return (0); } -int ex_builtin(char **fields, __attribute__((unused)) t_vec *assignments, __attribute__((unused)) const t_vec *redirections, t_execution_env *env) +int ex_builtin(char **fields, __attribute__((unused)) + t_vec *assignments, __attribute__((unused)) const t_vec *redirections, + t_execution_env *env) { int fds[3]; @@ -824,7 +850,8 @@ int ex_builtin(char **fields, __attribute__((unused)) t_vec *assignments, __attr else if (!ft_strcmp(fields[0], "unset")) env->last_builtin_ret_val = unset(count_fields(fields), fields, env); else if (!ft_strcmp(fields[0], "exit")) - env->last_builtin_ret_val = execute_exit(count_fields(fields), fields, env); + env->last_builtin_ret_val = execute_exit(count_fields(fields), + fields, env); else return (1); env->last_was_builtin = 1; @@ -849,7 +876,8 @@ void close_fds(t_vec *fds_to_close) return ; } -int ex_fields(char **fields, t_vec *assignments, const t_vec *redirections, t_execution_env *env) +int ex_fields(char **fields, t_vec *assignments, + const t_vec *redirections, t_execution_env *env) { pid_t pid; char *path; @@ -933,8 +961,8 @@ int ex_simple_command(t_parse_tree_node *simple_command, t_execution_env *env) t_ft_stat v_strcopy(void *v_dest, const void *v_src) { - char **dest; - const char *const *src; + char **dest; + const char *const *src; dest = v_dest; src = v_src; @@ -1047,7 +1075,8 @@ void wait_for_return(t_execution_env *env) { if (env->child_pids.size == 0) return ; - last_pid = *(pid_t *)ft_vec_access(&env->child_pids, env->child_pids.size - 1); + last_pid = *(pid_t *)ft_vec_access(&env->child_pids, + env->child_pids.size - 1); waitpid(last_pid, &status, 0); if (g_last_signal != 0) killall(&env->child_pids, g_last_signal); diff --git a/src/main.c b/src/main.c index 9902951..1516de7 100644 --- a/src/main.c +++ b/src/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ +/* By: lnikolov 1)