tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* main.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/05/20 07:21:24 by tgrekov #+# #+# */
9/* Updated: 2024/06/24 09:54:05 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <fcntl.h>
21#include <stdio.h>
22#include <libft.h>
23#include <ft_printf.h>
24#include "fdf/map.h"
25#include "utils/utils.h"
26
27t_map read_map(int fd);
28int fdf(t_map map);
29
36static int open_map(char *filename)
37{
38 int len;
39 int fd;
40
41 if (filename)
42 len = ft_strlen(filename);
43 if (!filename || len < 4 || ft_strncmp(".fdf", filename + len - 4, 4))
44 {
45 ft_printf("%>Expected an FDF map file ending in .fdf\n", 2);
46 return (-1);
47 }
48 fd = open(filename, O_RDONLY);
49 if (fd == -1)
50 perror("open()");
51 return (fd);
52}
53
59int main(int argc, char **argv)
60{
61 t_map map;
62 int fd;
63 int status;
64
65 (void) argc;
66 fd = open_map(argv[1]);
67 if (fd == -1)
68 return (1);
69 map = read_map(fd);
70 if (close(fd) == -1)
71 {
72 perror("close()");
73 if (map.point)
74 arr_free((void **) map.point);
75 return (1);
76 }
77 if (!map.point)
78 return (1);
79 status = fdf(map);
80 arr_free((void **) map.point);
81 return (status);
82}
void ** arr_free(void **arr)
Free each element in a null-terminated array, and then the array itself.
Definition arr_free.c:30
int ft_printf(const char *format,...)
Prints and formats a variable set of arguments.
Definition ft_printf.c:252
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28
int ft_strncmp(const char *s1, const char *s2, size_t n)
Compare up to n characters of string s1 with string s2.
Definition ft_strncmp.c:33
static int open_map(char *filename)
Validate filename and open fdf map file.
Definition main.c:36
int main(int argc, char **argv)
Definition main.c:59
int fdf(t_map map)
Initialize mlx, run map projection and scaling, execute mlx, and cleanup.
Definition fdf_mlx.c:131
t_map read_map(int fd)
Initialize map from an fdf map file pointed to by fd.
Definition read_map.c:147
Map data.
Definition map.h:54
t_point ** point
2d array of points in [y][x] order
Definition map.h:57