1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
2023-08-03 23:16:27 +02:00

80 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/29 17:38:13 by tomoron #+# #+# */
/* Updated: 2023/07/30 22:09:51 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
char *ft_read_file(char *filename)
{
char c;
int file;
int len;
char *res;
int i;
i = 0;
file = open(filename, O_RDONLY);
len = 0;
if (file == -1)
return (0);
while (read(file, &c, 1))
len++;
close(file);
res = malloc((len + 1) * sizeof(char));
file = open(filename, O_RDONLY);
if (file == -1 || !res)
return (0);
while (read(file, &c, 1))
res[i++] = c;
res[i] = 0;
close(file);
return (res);
}
int ft_count_parts(char *file)
{
int res;
int sem_found;
res = 0;
while (*file == '\n')
file++;
while (*file)
{
sem_found = 0;
while (*file != '\n' && *file)
{
file++;
if (!sem_found && *file == ':')
{
sem_found = 1;
res++;
}
}
res++;
while (*file == '\n')
file++;
}
return (res + 1);
}
int ft_error(char **res, char *file, int i)
{
while (i >= 0)
{
free(res[i]);
i--;
}
free(res);
free(file);
return (0);
}