gysiang / minishell

0 stars 1 forks source link

Double Quotes + Single Quotes_1 #287

Closed axellee1994 closed 2 days ago

axellee1994 commented 3 days ago

Selvam Testcases:

echo "double"'single''"123"'"'456'" doublesingle"123"'456'

Ours: minishell$ echo "double"'single''"123"'"'456'" double single "123" '456'

Execute a simple command Then execute echo $? or $?$? 0+00

Ours return: axlee@axlee:~/Desktop/42_minishell$ ./minishell minishell$ echo $?+$?$? 0+ 0 0

Both issues stems in the minishell_echo where the space is being printed out. Need to write a command which keeps tracks of the space in the command line. If there is a space, print the space out. Else, do not print it.

gysiang commented 3 days ago

@axellee1994 I'll try to work on this tonight. The multiple heredoc feature i don't understand how to make it work.

axellee1994 commented 3 days ago

@gysiang I am still working on it. The closest I can get is to remove the space after the first token but it messes up echo hello world, echo hi bye etc.

Seems like a big issue to overhaul the entire parser and tokenization.

axellee1994 commented 3 days ago

@gysiang

The closest I gotten to was this:

static void print_tokens(t_token *current, t_shell *minishell, int newline)
{
    int first;

    first = 1;
    while (current != NULL)
    {
        if (current->type == T_IDENTIFIER)
            printf("%s\n", current->token);
        else if (current->type == T_FILE || check_redirection_type(current))
        {
            current = current->next->next;
            continue ;
        }
        else
            break ;
        current = current->next;
    }
    if (minishell->flag)
    {
        print_input_fd(minishell);
        safe_close(&minishell->input_fd);
    }
    if (newline)
        printf("\n");
}
axellee1994 commented 3 days ago

@gysiang

Can you try this https://github.com/axellee1994/minishell/tree/echo_double

It can process the echo $?+$?? and the other commands listed in here but there is a leading white space at the front which I am having trouble removing.

image

gysiang commented 3 days ago
void minishell_echo(t_token *curr, t_shell *minishell)
{
    t_token *current;
    int newline = 1;

    current = curr->next;
    while (current && ft_strcmp(current->token, "-n") == 0)
    {
        newline = 0;
        current = current->next;
    }
    if (current && current->type == T_IDENTIFIER && current->next)
    {
        current = current->next;
    }
    print_tokens(current);
    if (minishell->flag)
    {
        print_input_fd(minishell);
        safe_close(&minishell->input_fd);
    }
    if (newline)
        ft_putchar_fd('\n', STDOUT_FILENO);
}

@axellee1994 the issue is you created a new type which is T_WHITESPACE, but the token created is still T_IDENTIFIER, skipping one token will be enough to remove the front white space. the print input_fd need to be infront of if newline to mimic the herestring process.

axellee1994 commented 3 days ago

Swapping it to white space will break the code and revert back to the original again

gysiang commented 3 days ago

@axellee1994 ok if thats the case try pasting my code and test

minishell$ echo $?+$?$? 0+00

axellee1994 commented 3 days ago

@gysiang

Okay, my bad on this. I read the code wrongly on my side. It solves the test case, but breaks our passing rate of the minishell tester from 143 down to 75.

Changing the process line breaks 10 cases. Changing the builtin_echo breaks around 60 +. Will need to think how to combine both the echos together that will solve the issue and not break our testcases

gysiang commented 3 days ago

@axellee1994 can you test out my echo branch? the tester shows 134/146 but when i tried out the command, it worked normally. echo $?+$?$? is resolved but echo "hello world will automatically print out " in the next line.

axellee1994 commented 3 days ago

Can, I'll pull your echo branch jn and test