Fix comments and noninitialized res in categorize
authorLukas Jiriste <ljiriste@student.42prague.com>
Sat, 31 Aug 2024 16:58:10 +0000 (18:58 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sat, 31 Aug 2024 16:58:10 +0000 (18:58 +0200)
src/token_categorize.c
src/tokenization.c

index 6579637e80ef3822dab1a69c883d14ef9a76c164..39c68b72b5e8c55a73ff6fb9e75cc8d9350d9dee 100644 (file)
@@ -1,12 +1,12 @@
 /* ************************************************************************** */
 /*                                                                            */
 /*                                                        :::      ::::::::   */
-/*   categorization_step.c                              :+:      :+:    :+:   */
+/*   token_categorize.c                                 :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
 /*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/21 16:34:43 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/31 15:53:33 by lnikolov         ###   ########.fr       */
+/*   Updated: 2024/08/31 18:56:37 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -63,6 +63,7 @@ int   categorization_step(char *line, size_t *i,
 {
        int     res;
 
+       res = 0;
        if (is_operator_start(current_token->vec, current_token->size)
                && can_expand_operator(current_token, line[*i]))
                res = (ft_vec_append(current_token, line + (*i)++) != success);
@@ -81,8 +82,6 @@ int   categorization_step(char *line, size_t *i,
                                != success;
                ++*i;
        }
-       else if (current_token->size > 0)
-               res = ft_vec_append(current_token, line + (*i)++) != success;
        else
                res = ft_vec_append(current_token, line + (*i)++) != success;
        return (res);
index d0ffe6e44029d08fba85055ce5246f2a60b54db0..a4e945aad742352d62ece00767b7c5d3bfea2532 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/31 15:08:00 by lnikolov          #+#    #+#             */
-/*   Updated: 2024/08/31 15:42:59 by lnikolov         ###   ########.fr       */
+/*   Updated: 2024/08/31 18:56:53 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -68,7 +68,7 @@ int   tokenize(char *line, t_vec *tokens)
        i = 0;
        while (line[i] && res == 0)
        {
-               if (line[i] == '#')
+               if (line[i] == '#' && (i == 0 || ft_isspace(line[i - 1])))
                        break ;
                res = categorization_step(line, &i, &current_token, tokens);
        }