mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
quote marking: no quotes lead to marker filled with spaces
This commit is contained in:
parent
4b403c4bf3
commit
2c5d5abdc4
3 changed files with 39 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */
|
||||
/* Updated: 2025/02/20 14:02:11 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/06 15:03:56 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,18 +18,28 @@
|
|||
** allocate a new worddesc with given flags and the given word as word.
|
||||
**
|
||||
** return null in case of error, or if word is null
|
||||
**
|
||||
** mark_string is initialized as a string of the same length as word, but filled
|
||||
** with spaces
|
||||
**
|
||||
** In case of allocation error, word is freed, as well as any memory allocated
|
||||
** in this function
|
||||
*/
|
||||
t_worddesc *worddesc_create(char *word, char flags)
|
||||
{
|
||||
t_worddesc *retvalue;
|
||||
t_worddesc *retvalue;
|
||||
|
||||
if (word == NULL)
|
||||
return (NULL);
|
||||
return (NULL);
|
||||
retvalue = ft_calloc(1, sizeof(t_worddesc));
|
||||
if (retvalue == NULL)
|
||||
return (NULL);
|
||||
return (free(word), NULL);
|
||||
retvalue->word = word;
|
||||
retvalue->flags = flags;
|
||||
retvalue->marker = ft_calloc(ft_strlen(word) + 1, sizeof(char));
|
||||
if (retvalue->marker == NULL)
|
||||
return (free(word), free(retvalue), NULL);
|
||||
ft_memset(retvalue->marker, ' ', ft_strlen(word));
|
||||
return (retvalue);
|
||||
}
|
||||
|
||||
|
|
@ -41,5 +51,6 @@ void worddesc_destroy(t_worddesc *worddesc)
|
|||
if (worddesc == NULL)
|
||||
return ;
|
||||
free(worddesc->word);
|
||||
free(worddesc->marker);
|
||||
free(worddesc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 15:47:58 by khais #+# #+# */
|
||||
/* Updated: 2025/02/20 14:02:21 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/06 17:20:50 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,6 +41,18 @@ typedef struct s_worddesc
|
|||
** See above for flag definitions
|
||||
*/
|
||||
char flags;
|
||||
/*
|
||||
** a character mask for word to designate the status
|
||||
** of its characters and wether or not they are subject to modifications
|
||||
**
|
||||
** Possible flags are ''', '"', '$', ' '
|
||||
**
|
||||
** ' ' the default, no flag, no meaning
|
||||
** ''' corresponding character is single-quoted
|
||||
** '"' corresponding character is double-quoted
|
||||
** '$' corresponding character is a result of $var expansion
|
||||
*/
|
||||
char *marker;
|
||||
} t_worddesc;
|
||||
|
||||
t_worddesc *worddesc_create(char *word, char flags);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 15:17:56 by khais #+# #+# */
|
||||
/* Updated: 2025/02/24 14:49:09 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/06 15:05:58 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,6 +24,7 @@ static void test_wordsplit_singleword(void)
|
|||
|
||||
words = minishell_wordsplit("echo");
|
||||
assert_strequal("echo", wordlist_get(words, 0)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 0)->marker);
|
||||
assert(NULL == wordlist_get(words, 1));
|
||||
wordlist_destroy(words);
|
||||
}
|
||||
|
|
@ -34,6 +35,7 @@ static void test_wordsplit_singleword_with_blanks(void)
|
|||
|
||||
words = minishell_wordsplit("\t \t echo \t\t ");
|
||||
assert_strequal("echo", wordlist_get(words, 0)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 0)->marker);
|
||||
assert(NULL == wordlist_get(words, 1));
|
||||
wordlist_destroy(words);
|
||||
}
|
||||
|
|
@ -44,15 +46,23 @@ static void test_wordsplit_multiword(void)
|
|||
|
||||
words = minishell_wordsplit("\t echo\tThe file is named $MYFILE \t");
|
||||
assert_strequal("echo", wordlist_get(words, 0)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 0)->marker);
|
||||
assert_strequal("The", wordlist_get(words, 1)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 1)->marker);
|
||||
assert_strequal("file", wordlist_get(words, 2)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 2)->marker);
|
||||
assert_strequal("is", wordlist_get(words, 3)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 3)->marker);
|
||||
assert_strequal("named", wordlist_get(words, 4)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 4)->marker);
|
||||
assert_strequal("$MYFILE", wordlist_get(words, 5)->word);
|
||||
assert_strequal(" ", wordlist_get(words, 5)->marker);
|
||||
assert(NULL == wordlist_get(words, 6));
|
||||
wordlist_destroy(words);
|
||||
}
|
||||
|
||||
// kco work marker
|
||||
|
||||
static void test_wordsplit_multiword_with_single_quotes(void)
|
||||
{
|
||||
t_wordlist *words;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue