Make lines in most files comply with the 42 Norm
authorLilia-42 <nikolovalilianenkova@gmail.com>
Sat, 31 Aug 2024 09:26:21 +0000 (11:26 +0200)
committerLilia-42 <nikolovalilianenkova@gmail.com>
Sat, 31 Aug 2024 09:32:42 +0000 (11:32 +0200)
src/builtins/echo.c
src/builtins/exit.c
src/builtins/export.c
src/builtins/unset.c
src/execution.c
src/tokenization.c
src/vars.c
src/wildcards.c

index 1a21600522d51888289d3f0c20dfb940b6dde3f6..5a8d347cd3ea3a024eb21a14c9f3ac8432882074 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   echo.c                                             :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/26 11:43:48 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/26 11:45:17 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:05:49 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -24,9 +24,9 @@ int   ft_check_n(char *str)
 
 int    echo(int argc, char **argv)
 {
-       int i;
-       int flag;
-       int t;
+       int     i;
+       int     flag;
+       int     t;
 
        i = 1;
        flag = 0;
index 149397bc89bd57288ef5ccefd97026e48650deff..8eda4f256883552edcaafda35081963d379a372b 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   exit.c                                             :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/27 14:49:17 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/27 17:00:31 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:06:52 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -42,7 +42,8 @@ int   execute_exit(int argc, char **argv, t_execution_env *env)
        }
        if (!is_numeric(argv[1]))
        {
-               ft_dprintf(STDERR_FILENO, "exit: %s: numeric argument required\n", argv[1]);
+               ft_dprintf(STDERR_FILENO,
+                       "exit: %s: numeric argument required\n", argv[1]);
                return (2);
        }
        return (ft_atoi(argv[1]));
index c919a3e308bb81777cda69147218c893e6ea0a12..14a866336438d45de0cd8801d81599fa1ae6b7d1 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   export.c                                           :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/23 09:40:38 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/30 09:16:28 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:08:30 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -24,7 +24,8 @@ static int    export_single(const char *var, t_execution_env *env)
 
        if (!has_valid_name(var))
        {
-               ft_dprintf(STDERR_FILENO, "export: '%s': not a valid identifier\n", var);
+               ft_dprintf(STDERR_FILENO,
+                       "export: '%s': not a valid identifier\n", var);
                return (1);
        }
        name = get_var_name(var);
index d8b6395f86fc99ccf8e95e3feffa7dc427e5aed6..ecc41aebaddf557454b5e5782efdbfa7e7df89f9 100644 (file)
@@ -3,17 +3,17 @@
 /*                                                        :::      ::::::::   */
 /*   unset.c                                            :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/26 08:18:30 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/26 11:47:56 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:10:24 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "builtins.h"
 #include "minishell_structs.h"
 
-void           unset_single(const char *name, t_execution_env *env)
+void   unset_single(const char *name, t_execution_env *env)
 {
        ssize_t index;
 
index ed263a277b35e5b8e37442233ae99774ea1421fa..e367194f1fc6423ffdc7fc0f15f13d0b717ff931 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/07/21 08:57:54 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/30 17:31:53 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/31 11:30:11 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
index 5f5114a879ab7ed64b616ac0b9aaca78b6608c38..cc8791d84d1c88834d4255ba730aa51224bc363c 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   tokenization.c                                     :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/21 16:34:43 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/28 10:32:02 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:28:42 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -26,14 +26,14 @@ static int  is_operator_start(char *str, size_t size)
        if (!str)
                return (1);
        return (!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)
+               || !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(&current_token, line[0][i]))
+               if (is_operator_start(current_token.vec, current_token.size)
+                       && can_expand_operator(&current_token, line[0][i]))
                        res = (ft_vec_append(&current_token, line[0] + (i++)) != success);
                else if (is_operator(&current_token))
                        res = finish_token(tokens, &current_token, '\0');
@@ -255,7 +256,8 @@ int tokenize(char **line, t_vec *tokens)
                        if (current_token.size > 0)
                                res = finish_token(tokens, &current_token, line[0][i]);
                        if (!ft_isspace(line[0][i]))
-                               res = res || ft_vec_append(&current_token, line[0] + i) != success;
+                               res = res || ft_vec_append(&current_token, line[0] + i)
+                                       != success;
                        ++i;
                }
                else if (current_token.size > 0)
index d9b445b1e8e63246791cf611f614f1555df0c0f0..089d31c6f4035a63403d9356e342e776d3c70928 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   vars.c                                             :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/02 13:21:32 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/30 09:14:10 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:30:49 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -156,9 +156,9 @@ int set_env_var_value(t_execution_env *env, const char *name, const char *value)
 
 ssize_t        get_var_index(const t_vec *vars, const char *var_name)
 {
-       size_t          len;
-       ssize_t         i;
-       const char      *const *line;
+       size_t                          len;
+       ssize_t                         i;
+       const char *const       *line;
 
        len = ft_strlen(var_name);
        i = 0;
@@ -176,9 +176,9 @@ ssize_t     get_var_index(const t_vec *vars, const char *var_name)
 
 const char     *get_var_value(const t_vec *vars, const char *var_name)
 {
-       size_t          len;
-       ssize_t         i;
-       const char      *const *line;
+       size_t                          len;
+       ssize_t                         i;
+       const char *const       *line;
 
        len = ft_strlen(var_name);
        i = get_var_index(vars, var_name);
index dabdf859e55fece1ed1460178faaf57883d975b1..89adcfbef0257e247415a8ebbde6f528fc19d7a2 100644 (file)
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   wildcards.c                                        :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/08 10:50:26 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/29 17:09:47 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/30 14:39:10 by lnikolov         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -40,7 +40,8 @@ int   branch_at_star(t_vec *expanded, t_wildcard_info *info)
        if (g_last_signal != 0)
                return (2);
        info_dup = *info;
-       if (!(*(info->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] == '"')
                {