t_element *element, t_vec3 direction, double distance);
void change_radius(t_element *element, double change);
void change_height(t_element *element, double change);
+void print_help(int argc, char **argv);
#endif // MINIRT_H
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* parsing.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/11/28 12:34:20 by ljiriste #+# #+# */
+/* Updated: 2025/01/13 19:54:25 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "miniRT.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+void print_msg(char *msg)
+{
+ printf("%s\n", msg);
+ printf("Usage: miniRT [options] [file.rt]\n");
+ printf("Options:\n");
+ printf("\t-w [int] (width) - set the width of the window\n");
+ printf("\t-h [int] (height) - set the height of the window\n");
+}
+
+/*
+Function that check propriete file ending (.rt) and also
+checks if this file exists.
+- use fopen to open file and check if error occurs during
+opening --> file can be open
+*/
+int check_file(char *filename)
+{
+ int i;
+ int fd;
+
+ fd = -1;
+ i = 0;
+ while (filename[i])
+ i++;
+ if ((ft_strlen(filename) < 4) || (filename[i - 1] != 't'
+ || filename[i - 2] != 'r' || filename[i - 3] != '.'))
+ {
+ printf("Wrong file ending! Please, provide .rt file\n");
+ return (1);
+ }
+ else
+ {
+ fd = open(filename, 0);
+ }
+ if (fd == -1)
+ {
+ printf("Error in opening file.\n");
+ return (1);
+ }
+ close(fd);
+ return (0);
+}
+
+/*
+checks for errors in arguments and provide error message
+*/
+void print_help(int argc, char **argv)
+{
+ if (argc < 2 || argc % 2 == 0)
+ {
+ print_msg("Wrong number of arguments");
+ return ;
+ }
+ else if (ft_strcmp(argv[argc - 2], "-f"))
+ {
+ print_msg("Provide -f flag for filename\n");
+ return ;
+ }
+ else
+ check_file(argv[argc - 1]);
+ return ;
+}