tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
read_map.c File Reference

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 07:22:24 by tgrekov #+# #+# */
/* Updated: 2024/06/24 08:55:47 by tgrekov ### ########.fr */
/* */
/* ************************************************************************** */

Definition in file read_map.c.

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <libft.h>
#include <ft_printf.h>
#include <get_next_line_bonus.h>
#include "utils/utils.h"
#include "fdf/map.h"
Include dependency graph for read_map.c:

Go to the source code of this file.

Functions

static void lst_arr_free (void *arr)
 Wrapper around arr_free for use with ft_lstclear.
 
static char * prep_row (char *row, t_list **lst)
 Remove trailing newline from row or print appropriate error message.
 
static void split_rows (int fd, t_list **lst)
 Read rows from fd and place them into lst nodes, split on spaces.
 
static int fill_points (t_map *map, t_list *lst)
 Allocate map points and set height values from lst.
 
t_map read_map (int fd)
 Initialize map from an fdf map file pointed to by fd.
 

Function Documentation

◆ fill_points()

static int fill_points ( t_map map,
t_list lst 
)
static

Allocate map points and set height values from lst.

Parameters
[in,out]map
[in]lst
Return values
int0 on success, positive number greater than zero otherwise

Definition at line 112 of file read_map.c.

References arr_free(), arr_len(), s_list::content, err(), ft_atoi(), ft_printf(), s_point::height, s_list::next, s_map::point, and s_map::width.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lst_arr_free()

static void lst_arr_free ( void *  arr)
static

Wrapper around arr_free for use with ft_lstclear.

Parameters
arr

Definition at line 35 of file read_map.c.

References arr_free().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prep_row()

static char * prep_row ( char *  row,
t_list **  lst 
)
static

Remove trailing newline from row or print appropriate error message.

Parameters
[in]row
[in]lstLinked list where each node contains an array of strings with height,color for that index of the row
Return values
char*

Definition at line 48 of file read_map.c.

References ft_printf(), and ft_strlen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_map()

t_map read_map ( int  fd)

Initialize map from an fdf map file pointed to by fd.

Parameters
[in]fd
Return values
t_map

Definition at line 147 of file read_map.c.

References arr_len(), s_list::content, err(), fill_points(), ft_calloc(), ft_lstclear(), ft_lstsize(), s_map::height, lst_arr_free(), s_map::point, split_rows(), and s_map::width.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ split_rows()

static void split_rows ( int  fd,
t_list **  lst 
)
static

Read rows from fd and place them into lst nodes, split on spaces.

Parameters
[in]fdMap file fd
[out]lstLinked list where each node contains an array of strings with height,color for that index of the row

Definition at line 76 of file read_map.c.

References ft_lstadd_back(), ft_lstclear(), ft_lstnew(), ft_split(), get_next_line(), lst_arr_free(), and prep_row().

Here is the call graph for this function:
Here is the caller graph for this function: