RM := rm -f
+EXT_LIBS := readline
+LINKS := $(addprefix -l, $(EXT_LIBS))
+
SUBPROJECTS := Libft
INCDIR := inc
debug : $(NAME)
$(NAME) : $(OBJECTS) Libft/libft.a
- $(CC) $(CFLAGS) -o $@ $^
+ $(CC) $(CFLAGS) -o $@ $^ $(LINKS)
Libft/libft.a : | Libft/Makefile
ifneq (,$(findstring debug, $(MAKECMDGOALS)))
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 13:11:47 by ljiriste #+# #+# */
-/* Updated: 2024/04/26 13:12:09 by ljiriste ### ########.fr */
+/* Updated: 2024/04/26 14:13:15 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+#include <stdlib.h>
+#include <unistd.h> // getcwd
+#include <stdio.h> // readline
+#include <readline/readline.h> // readline
+#include <readline/history.h> // readline
+
+// A string is "almost_empty" if it:
+// is a NULL pointer
+// is an empty string
+// only contains whitespace
+int almost_empty(const char *str)
+{
+ if (!str)
+ return (1);
+ while (*str)
+ {
+ if (!ft_isspace(*str))
+ return (0);
+ ++str;
+ }
+ return (1);
+}
+
+char *rl_get_line(void)
+{
+ char *cwd;
+ char *prompt;
+ char *line;
+
+ cwd = getcwd(NULL, 0);
+ prompt = ft_strjoin(cwd, "$ ");
+ free(cwd);
+ line = readline(prompt);
+ free(prompt);
+ if (!almost_empty(line))
+ add_history(line);
+ return (line);
+}
+
+void handle_input(__attribute__((unused)) const char *input)
+{
+ return ;
+}
+
int main(void)
{
- return (0);
+ char *line;
+
+ while (1)
+ {
+ line = rl_get_line();
+ if (!line || !ft_strcmp(line, "exit"))
+ {
+ rl_clear_history();
+ ft_printf("exit\n");
+ return (0);
+ }
+ handle_input(line);
+ free(line);
+ }
}