mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
word splitting: a single word is not split
Sorry this commit is a bit big, lots of groudwork is being established here
This commit is contained in:
parent
871571e258
commit
a083800506
9 changed files with 262 additions and 0 deletions
57
src/parser/wordlist/wordlist.c
Normal file
57
src/parser/wordlist/wordlist.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* wordlist.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 17:07:01 by khais #+# #+# */
|
||||
/* Updated: 2025/02/14 13:29:16 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "wordlist.h"
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
** create a new wordlist element, with next set to null and word set to the
|
||||
** passed worddesc.
|
||||
**
|
||||
** in case of error, return null
|
||||
*/
|
||||
t_wordlist *wordlist_create(t_worddesc *word)
|
||||
{
|
||||
t_wordlist *retvalue;
|
||||
|
||||
retvalue = ft_calloc(1, sizeof(t_wordlist));
|
||||
if (retvalue == NULL)
|
||||
return (NULL);
|
||||
retvalue->next = NULL;
|
||||
retvalue->word = word;
|
||||
return (retvalue);
|
||||
}
|
||||
|
||||
/*
|
||||
** free all memory associated with this wordlist.
|
||||
*/
|
||||
void wordlist_destroy(t_wordlist *wordlist)
|
||||
{
|
||||
free(wordlist);
|
||||
}
|
||||
|
||||
/*
|
||||
** get the worddesc at position idx in the given wordlist.
|
||||
**
|
||||
** return null if out of range or wordlist is null
|
||||
*/
|
||||
t_worddesc *wordlist_get(t_wordlist *wordlist, int idx)
|
||||
{
|
||||
if (wordlist == NULL || idx < 0)
|
||||
return (NULL);
|
||||
while (idx > 0 && wordlist != NULL)
|
||||
wordlist = wordlist->next;
|
||||
if (wordlist == NULL)
|
||||
return (NULL);
|
||||
return (wordlist->word);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue