Remove interpreting unclosed quotes and \
authorLukas Jiriste <ljiriste@student.42prague.com>
Mon, 22 Jul 2024 20:43:19 +0000 (22:43 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Mon, 22 Jul 2024 20:43:19 +0000 (22:43 +0200)
As per the subject those should not be handled. Hence it is removed from
the tokenizer.

src/tokenization.c

index b8c350487f3fe74e7fc848a31bebae43a904787f..75dade69a9848b9fcf501273f773caff304856bf 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/21 16:34:43 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/06/23 18:54:02 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/07/22 22:42:16 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -110,8 +110,6 @@ static int  is_assignment_word(const char *str)
                else if (str[i] == '\'')
                        while (str[i] && str[i] != '\'')
                                ++i;
-               else if (str[i] == '\\')
-                       ++i;
                else if (str[i] == '=')
                {
                        j = 0;
@@ -185,29 +183,20 @@ char      *continue_input(char *line, size_t *i)
 
 #endif //NOLEAKS
 
-void   handle_quote(t_vec *current_token, char **line, char quote_char, size_t *i)
+int    handle_quote(t_vec *current_token, char **line, char quote_char, size_t *i)
 {
-       ft_vec_append(current_token, line[0] + (*i)++);
-       if (quote_char == '\\')
-       {
-               if (line[0][*i] == '\n')
-               {
-                       ft_vec_erase(current_token, current_token->size - 1, NULL);
-                       *line = continue_input(*line, i);
-               }
-               else
-                       ft_vec_append(current_token, line[0] + (*i)++);
-               return ;
-       }
+       if (ft_vec_append(current_token, line[0] + (*i)++) != success)
+               return (1);
        while (line[0][*i] != quote_char)
        {
                if (!line[0][*i])
-                       *line = continue_input(*line, i);
+                       return (1);
                else
-                       ft_vec_append(current_token, line[0] + (*i)++);
+                       if (ft_vec_append(current_token, line[0] + (*i)++) != success)
+                               return (1);
        }
        ft_vec_append(current_token, line[0] + (*i)++);
-       return ;
+       return (0);
 }
 
 //     This function turns the input char string into a string of tokens
@@ -236,12 +225,16 @@ int       tokenize(char **line, t_vec *tokens)
                        ft_vec_append(tokens, &token);
                        ft_vec_init(&current_token, sizeof(char));
                }
-               else if (line[0][i] == '\'')
-                       handle_quote(&current_token, line, '\'', &i);
-               else if (line[0][i] == '"')
-                       handle_quote(&current_token, line, '"', &i);
-               else if (line[0][i] == '\\')
-                       handle_quote(&current_token, line, '\\', &i);
+               else if (line[0][i] == '\'' && handle_quote(&current_token, line, '\'', &i))
+               {
+                       ft_vec_free(tokens, free_token);
+                       return (1);
+               }
+               else if (line[0][i] == '"' && handle_quote(&current_token, line, '"', &i))
+               {
+                       ft_vec_free(tokens, free_token);
+                       return (1);
+               }
                else if (is_operator_start(line[0] + i, 1) || ft_isspace(line[0][i]))
                {
                        if (current_token.size > 0)