From 53a5dc3296b363cdb3375dfa7ef3ff582d3cbd1b Mon Sep 17 00:00:00 2001
From: Rudy Bousset <rbousset@z2r5p6.le-101.fr>
Date: Tue, 29 Oct 2019 13:54:42 +0100
Subject: commit, lotta stuff

---
 src/ft_echo.c        | 23 +++++++++--------------
 src/ft_process_arg.c | 13 +++++++++++++
 src/ft_pwd.c         |  2 +-
 src/main.c           |  2 +-
 4 files changed, 24 insertions(+), 16 deletions(-)

(limited to 'src')

diff --git a/src/ft_echo.c b/src/ft_echo.c
index 66d803f..08fac36 100644
--- a/src/ft_echo.c
+++ b/src/ft_echo.c
@@ -12,21 +12,16 @@ ft_echo(char **com, uint8_t n)
 	fd = 1;
 	if (!com[1])
 		ft_putendl_fd("", fd);
-	else if (ft_strncmp(com[1], "-n", ft_strlen(com[1])))
+	else if (!ft_strncmp(com[1], "-n", ft_strlen(com[1])))
+		i = 2;
+	while (i < n)
 	{
-		while (i < n)
-		{
-			ft_putendl_fd(com[i], fd);
-			i++;
-		}
-	}
-	else
-	{
-		while (i < n)
-		{
-			ft_putstr_fd(com[i], fd);
-			i++;
-		}
+		ft_putstr_fd(com[i], fd);
+		if (i != n - 1)
+			ft_putchar_fd(' ', fd);
+		i++;
 	}
+	if (ft_strncmp(com[1], "-n", ft_strlen(com[1])))
+		ft_putchar_fd('\n', fd);
 	return (0);
 }
diff --git a/src/ft_process_arg.c b/src/ft_process_arg.c
index d82f9da..e1b6f8f 100644
--- a/src/ft_process_arg.c
+++ b/src/ft_process_arg.c
@@ -2,12 +2,23 @@
 #include <minishell.h>
 #include <inttypes.h>
 
+int
+ft_not_found(const char *com)
+{
+	ft_putstr("joe-sh: ");
+	ft_putstr(com);
+	ft_putendl(": command not found");
+	return (127);
+}
+
 int
 ft_process_arg(const char *arg)
 {
 	char **com;
 	uint8_t i;
 
+	if (arg[0] == '\0')
+		return (0);
 	i = 0;
 	com = ft_split(arg, ' ');
 	while (com[i])
@@ -18,5 +29,7 @@ ft_process_arg(const char *arg)
 		ft_echo(com, i);
 	else if (!ft_strncmp(com[0], "pwd", ft_strlen(com[0])))
 		ft_pwd();
+	else
+		ft_not_found(com[0]);
 	return (0);
 }
diff --git a/src/ft_pwd.c b/src/ft_pwd.c
index 24394fe..bd67873 100644
--- a/src/ft_pwd.c
+++ b/src/ft_pwd.c
@@ -8,6 +8,6 @@ ft_pwd(void)
 	char *buff;
 
 	buff = NULL;
-	ft_putstr(getcwd(buff, 1000));
+	ft_putendl(getcwd(buff, 1000));
 	return (0);
 }
diff --git a/src/main.c b/src/main.c
index 5db5fb7..9df9d88 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,7 @@ int
 	arg = NULL;
 	while (1)
 	{
+		write(1, "joe-sh~> ", 9);
 		if (arg)
 		{
 			free(arg);
@@ -36,7 +37,6 @@ int
 		}
 		if (!(arg = (char*)ft_calloc(129, sizeof(char))))
 			return (1);
-		write(1, "joe-shell~> ", 12);
 		i = 0;
 		while (read(1, &c, 1) > 0)
 		{
-- 
cgit v1.2.3