--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/10/11 18:10:37 by ljiriste #+# #+# */
+/* Updated: 2023/10/11 18:15:50 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef MAIN_H
+# define MAIN_H
+
+char *ft_strdup(const char *str);
+int ft_printf(const char *format, ...);
+void ft_putstr_fd(const char *str, int fd);
+int ft_strlen(const char *str);
+
+#endif
-#define TEST_DIR "./test_files/"
-#define RESULT_DIR "./results/"
-#define SEPARATOR "---------------------\n"
+#ifndef TEST_DIR
+# define TEST_DIR "./test_files/"
+#endif
+
+#ifndef RESULT_DIR
+# define RESULT_DIR "./results/"
+#endif
+
+#ifndef SEPARATOR
+# define SEPARATOR "---------------------\n"
+#endif
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "main.h"
+#include "get_next_line.h"
int my_open(const char *fname)
{
char *path;
path = ft_strdup(TEST_DIR);
- ft_strncat_alloc(&path, fname);
+ ft_strncat_alloc(&path, fname, ft_strlen(fname));
fd = open(path, O_RDONLY);
return (fd);
}
+char last_char(const char *str)
+{
+ if (*str == '\0')
+ return ('\0');
+ while (*str != '\0')
+ ++str;
+ return (*(str - 1));
+}
+
int create_res_file(const char *fname)
{
int fd;
char *path;
path = ft_strdup(RESULT_DIR);
- ft_strncat_alloc(&path, fname);
+ ft_strncat_alloc(&path, fname, ft_strlen(fname));
fd = open(path, O_WRONLY | O_CREAT);
return (fd);
}
line = get_next_line(testfd);
while (line)
{
- ft_pustr_fd(resfd, line);
- ft_putstr_fd(resfd, SEPARATOR);
+ ft_putstr_fd(line, resfd);
free(line);
line = get_next_line(testfd);
+ if (last_char(line) == '\n')
+ ft_putstr_fd(SEPARATOR, resfd);
}
return ;
}
i = 1;
while (i < argc)
{
- test = my_open(argv[i]);
- result = create_res_file(argv[i]);
+ testfd = my_open(argv[i]);
+ resfd = create_res_file(argv[i]);
test_gnl(testfd, resfd);
close(testfd);
close(resfd);