/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_select :+: :+: */
/* +:+ */
/* Author: Noah Loomans +#+ */
/* <nloomans@student.codam.nl> +#+ */
/* #+# #+# */
/* License: GPLv3 ######## odam.nl */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <ft_printf.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "error.h"
#include "state.h"
struct s_state_option *unpack_option(struct s_list2_conn *conn)
{
if (conn == NULL)
return (NULL);
return (struct s_state_option *)(
(char *)conn - offsetof(struct s_state_option, conn));
}
t_error state_make_options(
t_list2_meta *dest, int argc, char **argv)
{
int i;
t_list2_conn *prev;
struct s_state_option *new_option;
if (argc <= 1)
return (errorf("no options to select"));
i = 1;
prev = NULL;
while (i < argc)
{
new_option = ft_memalloc(sizeof(*new_option));
if (new_option == NULL)
return (errorf("failed to allocate option"));
new_option->name = argv[i];
new_option->selected = false;
list2_insert(dest, prev, &new_option->conn);
prev = &new_option->conn;
i++;
}
return (ERROR_NULL);
}