[ADD] parse_command()

This commit is contained in:
mcolonna 2024-04-24 14:49:32 +02:00
parent 24d8b38510
commit af6488534b
10 changed files with 225 additions and 13 deletions

View file

@ -5,13 +5,13 @@ INCLUDES = ./ include/
CODE = \
mem mem_utils str1 str2 str3 str_stream str_char1 \
str_char2 str_stream_more str_streamstr print \
list1 list2 error data read_line read_line_utils
list1 list2 list3 error data read_line read_line_utils
PRINTF_CODE = \
conversions1 conversions2 do_conversion ft_itoa tf_printf \
ft_strjoin stream1 stream2 utils1 utils2
PRINTF_SRCS = tf_printf/src/
PRINTF_INCLUDES = ./ tf_printf/include/
WHAT = LIBTF v9
WHAT = LIBTF v11
USED = malloc() free() write()
# It works and I probably won't change it for the rest of my life

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/18 11:07:59 by mcolonna #+# #+# */
/* Updated: 2024/03/11 12:12:03 by mcolonna ### ########.fr */
/* Updated: 2024/04/25 16:06:24 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -381,6 +381,22 @@ void list_rotate(t_list *list);
*/
void list_revrotate(t_list *list);
/**
* Convert the t_list to a void** ended by NULL.
*/
void **list_convert(
t_err *err, t_memclass mc, const t_list *list);
/**
* Let '<type>' be the type of the value of all elements of the list:
* convert the t_list to a <type>* list ended by a <type> filled with nul bytes.
* For example:
* If 'list' is {3, 4, 7, 2, 1} wth each element being an int, this function
* will return (int*){3, 4, 7, 2, 1, 0}.
*/
void *list_convert_type(t_err *err,
t_memclass mc, const t_list *list, int size);
///// DATA /////
/**

53
libtf/src/list3.c Normal file
View file

@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 12:05:28 by mcolonna #+# #+# */
/* Updated: 2024/04/25 16:19:00 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libtf.h"
void **list_convert(t_err *err, t_memclass mc, const t_list *list)
{
const int size = list_getsize(list);
int i;
void **r;
r = mem_alloc(err, mc, (size + 1) * sizeof(void *));
i = -1;
while (++i < size)
r[i] = list_get(err, list, i);
r[i] = NULL;
return (r);
}
static void fill_with_0(char *dest, int size)
{
int i;
i = -1;
while (++i < size)
dest[i] = '\0';
}
void *list_convert_type(t_err *err,
t_memclass mc, const t_list *list, int size)
{
const t_memclass mc_in = mem_subclass(err, mc);
char **const list2 = (char **)list_convert(err, mc_in, list);
const int listsize = list_getsize(list);
char *r;
int i;
r = mem_alloc(err, mc, (listsize + 1) * size);
i = -1;
while (++i < listsize)
data_cpy(r + i * size, list2[i], size);
fill_with_0(r + i * size, size);
return (r);
}