1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-14 08:18:45 +02:00

」 feat: echo done(hopefully)

This commit is contained in:
2024-06-29 20:05:18 +02:00
parent 26b8603933
commit 817ed058dd
6 changed files with 80 additions and 7 deletions

60
src/builtins/ft_echo.c Normal file
View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 19:19:57 by adjoly #+# #+# */
/* Updated: 2024/06/29 20:04:36 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdbool.h>
//#include <stdlib.h>
#include "libft.h"
#include <stdio.h>
size_t __nl_option(char **args)
{
char **tmp;
char *tmp_arg;
size_t i;
tmp = args;
i = 0;
while ((*tmp)[0] == '-' && (*tmp)[1] == 'n')
{
tmp_arg = (*tmp);
tmp_arg++;
while (*tmp_arg == 'n')
tmp_arg++;
if (*tmp_arg)
break ;
i++;
tmp++;
}
return (i);
}
void ft_echo(char **args)
{
char **tmp;
bool new_line;
tmp = args;
if (__nl_option(args) > 0)
new_line = false;
else
new_line = true;
tmp += __nl_option(args);
while (*tmp)
{
ft_putstr_fd(*tmp, STDOUT_FILENO);
tmp++;
if (*tmp != NULL)
ft_putchar_fd(' ', STDOUT_FILENO);
}
if (new_line == true)
ft_putchar_fd('\n', STDOUT_FILENO);
}