mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
57 lines
1.8 KiB
C
57 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* 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);
|
|
}
|