summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--src/ft_echo.c23
-rw-r--r--src/ft_process_arg.c13
-rw-r--r--src/ft_pwd.c2
-rw-r--r--src/main.c2
5 files changed, 25 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 3ac6d22..a24ca4b 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ INCS_DIR = -Iinc/ -Ilibft/
LIB_DIR = -Llibft/
LIB = -lft
-CC = gcc
+CC = clang
CFLAGS = -Wall -Wextra -Werror
DEBUG = -g3
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
@@ -3,11 +3,22 @@
#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)
{