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:
Khaïs COLIN 2025-02-13 15:17:30 +01:00
parent 871571e258
commit a083800506
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
9 changed files with 262 additions and 0 deletions

View 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);
}