From 836b0ce44a9ff7e067c93eb74f59bb909507a446 Mon Sep 17 00:00:00 2001 From: Lilia-42 Date: Sat, 31 Aug 2024 11:26:21 +0200 Subject: [PATCH] Make lines in most files comply with the 42 Norm --- src/builtins/echo.c | 10 +++++----- src/builtins/exit.c | 7 ++++--- src/builtins/export.c | 7 ++++--- src/builtins/unset.c | 6 +++--- src/execution.c | 2 +- src/tokenization.c | 44 ++++++++++++++++++++++--------------------- src/vars.c | 16 ++++++++-------- src/wildcards.c | 30 +++++++++++++++++++---------- 8 files changed, 68 insertions(+), 54 deletions(-) diff --git a/src/builtins/echo.c b/src/builtins/echo.c index 1a21600..5a8d347 100644 --- a/src/builtins/echo.c +++ b/src/builtins/echo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* echo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ +/* By: lnikolov +#+ +:+ +#+ */ +/* By: lnikolov +#+ +:+ +#+ */ +/* By: lnikolov +#+ +:+ +#+ */ +/* By: lnikolov +#+ +:+ +#+ */ +/* By: lnikolov ", size) - || !ft_strncmp(str, "<<", size) - || !ft_strncmp(str, ">>", size) - || !ft_strncmp(str, "|", size) - || !ft_strncmp(str, "(", size) - || !ft_strncmp(str, ")", size)); + || !ft_strncmp(str, "||", size) + || !ft_strncmp(str, "<", size) + || !ft_strncmp(str, ">", size) + || !ft_strncmp(str, "<<", size) + || !ft_strncmp(str, ">>", size) + || !ft_strncmp(str, "|", size) + || !ft_strncmp(str, "(", size) + || !ft_strncmp(str, ")", size)); } static int is_operator(t_vec *current_token) @@ -134,9 +134,9 @@ const char *get_token_type(const char *str, char next) char *continue_input(char *line, size_t *i) { - free(line); - *i = 0; - return (readline("> ")); + free(line); + *i = 0; + return (readline("> ")); } #else //NOLEAKS @@ -188,9 +188,9 @@ int finish_token(t_vec *tokens, t_vec *current_token, char next) int is_redirection_operator(const t_token *token) { return (token->type == g_tokens[LESS] - || token->type == g_tokens[DLESS] - || token->type == g_tokens[GREAT] - || token->type == g_tokens[DGREAT]); + || token->type == g_tokens[DLESS] + || token->type == g_tokens[GREAT] + || token->type == g_tokens[DGREAT]); } void filter_assignment_word(t_vec *tokens) @@ -210,9 +210,9 @@ void filter_assignment_word(t_vec *tokens) } prev_token = ft_vec_caccess(tokens, i - 1); if (prev_token->type == g_tokens[ASSIGNMENT_WORD] - || prev_token->type == g_tokens[AND_IF] - || prev_token->type == g_tokens[OR_IF] - || prev_token->type == g_tokens[LPARA]) + || prev_token->type == g_tokens[AND_IF] + || prev_token->type == g_tokens[OR_IF] + || prev_token->type == g_tokens[LPARA]) { ++i; continue ; @@ -242,7 +242,8 @@ int tokenize(char **line, t_vec *tokens) i = 0; while (line[0][i] && res == 0) { - if (is_operator_start(current_token.vec, current_token.size) && can_expand_operator(¤t_token, line[0][i])) + if (is_operator_start(current_token.vec, current_token.size) + && can_expand_operator(¤t_token, line[0][i])) res = (ft_vec_append(¤t_token, line[0] + (i++)) != success); else if (is_operator(¤t_token)) res = finish_token(tokens, ¤t_token, '\0'); @@ -255,7 +256,8 @@ int tokenize(char **line, t_vec *tokens) if (current_token.size > 0) res = finish_token(tokens, ¤t_token, line[0][i]); if (!ft_isspace(line[0][i])) - res = res || ft_vec_append(¤t_token, line[0] + i) != success; + res = res || ft_vec_append(¤t_token, line[0] + i) + != success; ++i; } else if (current_token.size > 0) diff --git a/src/vars.c b/src/vars.c index d9b445b..089d31c 100644 --- a/src/vars.c +++ b/src/vars.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* vars.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ +/* By: lnikolov +#+ +:+ +#+ */ +/* By: lnikolov current_expand_char + 1) == '/' && info->current_entry_char == info->entry)) + if (!(*(info->current_expand_char + 1) == '/' && info->current_entry_char + == info->entry)) { ++info->current_expand_char; if (add_conformant(expanded, info, '\0')) @@ -84,7 +85,8 @@ int add_conformant(t_vec *expanded, t_wildcard_info *info, char quote) ++info->current_expand_char; return (expand_further(expanded, *info)); } - if (*info->current_expand_char == '/' && info->current_entry_char == info->entry) + if (*info->current_expand_char == '/' && info->current_entry_char + == info->entry) { ++info->current_expand_char; return (add_conformant(expanded, info, quote)); @@ -100,14 +102,18 @@ int add_conformant(t_vec *expanded, t_wildcard_info *info, char quote) ++info->current_expand_char; return (add_conformant(expanded, info, quote)); } - if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry) && !quote) - || (*info->current_expand_char == *info->current_entry_char && (*info->current_expand_char != '*' || quote))) + if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0' + && (*info->current_entry_char != '.' + || info->current_entry_char != info->entry) && !quote) + || (*info->current_expand_char == *info->current_entry_char + && (*info->current_expand_char != '*' || quote))) { ++info->current_expand_char; ++info->current_entry_char; return (add_conformant(expanded, info, quote)); } - if (*info->current_expand_char == '*' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry) && !quote) + if (*info->current_expand_char == '*' && (*info->current_entry_char != '.' + || info->current_entry_char != info->entry) && !quote) return (branch_at_star(expanded, info)); return (0); } @@ -225,7 +231,9 @@ char *get_start_path(const char *str, const t_execution_env *env) unquote_field(unquoted_str); if (unquoted_str[0] == '/') res = ft_strdup("/"); - else if (unquoted_str[0] == '~' && (ft_isalpha(unquoted_str[1]) || unquoted_str[1] == '/' || unquoted_str[1] == '~' || unquoted_str[1] == '+' || unquoted_str[1] == '-')) + else if (unquoted_str[0] == '~' && (ft_isalpha(unquoted_str[1]) + || unquoted_str[1] == '/' || unquoted_str[1] == '~' + || unquoted_str[1] == '+' || unquoted_str[1] == '-')) { if (unquoted_str[1] == '/' || unquoted_str[1] == '\0') res = ft_strjoin(get_env_var_value(env, "HOME"), "/"); @@ -247,8 +255,9 @@ int expand_word(char **str, const t_execution_env *env) t_vec matched; t_wildcard_info info; int res; - char last_char = str[0][ft_strlen(*str) - 1]; + char last_char; + last_char = str[0][ft_strlen(*str) - 1]; if (last_char == '\n') str[0][ft_strlen(*str) - 1] = '\0'; if (ft_vec_init(&matched, sizeof(char *)) != success) @@ -284,7 +293,8 @@ int should_be_expanded(const char *word) i = 0; while (word[i]) { - if ((word[i] == '*' || (word[i] == '?' && !(i && word[i - 1] == '$'))) && quote_char == '\0') + if ((word[i] == '*' || (word[i] == '?' && !(i && word[i - 1] == '$'))) + && quote_char == '\0') return (1); if (word[i] == '"') { -- 2.30.2