mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
quote marking: single-quotes are marked
This commit is contained in:
parent
e99c7e5986
commit
c1f337af01
3 changed files with 23 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 14:00:45 by khais #+# #+# */
|
/* Created: 2025/02/20 14:00:45 by khais #+# #+# */
|
||||||
/* Updated: 2025/02/21 12:39:17 by khais ### ########.fr */
|
/* Updated: 2025/03/06 15:18:41 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,6 +21,7 @@ typedef struct s_token_build
|
||||||
{
|
{
|
||||||
t_wordlist *wordlist;
|
t_wordlist *wordlist;
|
||||||
t_buffer *cur_token;
|
t_buffer *cur_token;
|
||||||
|
t_buffer *cur_marker;
|
||||||
char cur_flags;
|
char cur_flags;
|
||||||
bool currently_in_word;
|
bool currently_in_word;
|
||||||
bool currently_in_operator;
|
bool currently_in_operator;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 14:02:29 by khais #+# #+# */
|
/* Created: 2025/02/20 14:02:29 by khais #+# #+# */
|
||||||
/* Updated: 2025/02/21 12:38:27 by khais ### ########.fr */
|
/* Updated: 2025/03/06 16:51:58 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,10 +18,13 @@ void delimit(t_token_build *builder)
|
||||||
if (builder->cur_token == NULL)
|
if (builder->cur_token == NULL)
|
||||||
return ;
|
return ;
|
||||||
builder->wordlist = wordlist_push(builder->wordlist,
|
builder->wordlist = wordlist_push(builder->wordlist,
|
||||||
worddesc_create(builder->cur_token->buffer, builder->cur_flags));
|
worddesc_create(builder->cur_token->buffer,
|
||||||
|
builder->cur_flags, builder->cur_marker->buffer));
|
||||||
free(builder->cur_token);
|
free(builder->cur_token);
|
||||||
|
free(builder->cur_marker);
|
||||||
builder->cur_flags = 0;
|
builder->cur_flags = 0;
|
||||||
builder->cur_token = NULL;
|
builder->cur_token = NULL;
|
||||||
|
builder->cur_marker = NULL;
|
||||||
builder->currently_in_word = false;
|
builder->currently_in_word = false;
|
||||||
builder->currently_in_operator = false;
|
builder->currently_in_operator = false;
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +33,12 @@ void push_char(t_token_build *builder, char c)
|
||||||
{
|
{
|
||||||
if (builder->cur_token == NULL)
|
if (builder->cur_token == NULL)
|
||||||
builder->cur_token = ft_buffer_new();
|
builder->cur_token = ft_buffer_new();
|
||||||
|
if (builder->cur_marker == NULL)
|
||||||
|
builder->cur_marker = ft_buffer_new();
|
||||||
|
if (builder->quote == '\0' || c == builder->quote)
|
||||||
|
ft_buffer_pushchar(builder->cur_marker, ' ');
|
||||||
|
else
|
||||||
|
ft_buffer_pushchar(builder->cur_marker, builder->quote);
|
||||||
ft_buffer_pushchar(builder->cur_token, c);
|
ft_buffer_pushchar(builder->cur_token, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,15 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/13 15:17:56 by khais #+# #+# */
|
/* Created: 2025/02/13 15:17:56 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/06 15:05:58 by khais ### ########.fr */
|
/* Updated: 2025/03/06 15:17:10 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "testutil.h"
|
#include "testutil.h"
|
||||||
#include "../src/parser/wordsplit/wordsplit.h"
|
#include "../src/parser/wordsplit/wordsplit.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "libft.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -61,19 +63,24 @@ static void test_wordsplit_multiword(void)
|
||||||
wordlist_destroy(words);
|
wordlist_destroy(words);
|
||||||
}
|
}
|
||||||
|
|
||||||
// kco work marker
|
|
||||||
|
|
||||||
static void test_wordsplit_multiword_with_single_quotes(void)
|
static void test_wordsplit_multiword_with_single_quotes(void)
|
||||||
{
|
{
|
||||||
t_wordlist *words;
|
t_wordlist *words;
|
||||||
|
|
||||||
words = minishell_wordsplit("\t echo\t' \t The file is named $MYFILE ' \t");
|
words = minishell_wordsplit("\t echo\t' \t The file is named $MYFILE ' \t");
|
||||||
assert_strequal("echo", wordlist_get(words, 0)->word);
|
assert_strequal("echo", wordlist_get(words, 0)->word);
|
||||||
|
assert_strequal(" ", wordlist_get(words, 0)->marker);
|
||||||
assert_strequal("' \t The file is named $MYFILE '", wordlist_get(words, 1)->word);
|
assert_strequal("' \t The file is named $MYFILE '", wordlist_get(words, 1)->word);
|
||||||
|
// This marker is one char shorter because the tab character above is
|
||||||
|
// represented here with two chars
|
||||||
|
ft_dprintf(STDERR_FILENO, "the marker below is shorter than the string above because the string above contains a tab, it is normal\n");
|
||||||
|
assert_strequal(" '''''''''''''''''''''''''''''''''' ", wordlist_get(words, 1)->marker);
|
||||||
assert(NULL == wordlist_get(words, 2));
|
assert(NULL == wordlist_get(words, 2));
|
||||||
wordlist_destroy(words);
|
wordlist_destroy(words);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// kco work marker
|
||||||
|
|
||||||
static void test_wordsplit_multiword_with_double_quotes(void)
|
static void test_wordsplit_multiword_with_double_quotes(void)
|
||||||
{
|
{
|
||||||
t_wordlist *words;
|
t_wordlist *words;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue