maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
echo.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* echo.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/06/03 16:31:33 by dmdemirk #+# #+# */
9/* Updated: 2024/11/08 15:15:40 by dmdemirk ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14#include "shell.h"
15#include "exit_status.h"
16#include "execute.h"
17
18/*
19Functionality:
20- Print the argument
21 */
22
24{
25 int newline;
26 int i;
27 char **args;
28
29 newline = 1;
30 i = 1;
31 args = data->args;
32 if (!data || !data->args || !data->args[0])
33 return (EXIT_FAILURE);
34 handle_std_io(&data->std_out, STDOUT_FILENO);
35 if (args[1] && ft_strcmp(args[1], "-n") == 0)
36 {
37 newline = 0;
38 i = 2;
39 }
40 while (args[i])
41 {
42 ft_putstr_fd(args[i], STDOUT_FILENO);
43 if (args[i + 1])
44 ft_putstr_fd(" ", STDOUT_FILENO);
45 i++;
46 }
47 if (newline)
48 ft_putchar_fd('\n', STDOUT_FILENO);
49 return (EXIT_SUCCESS);
50}
int builtin_echo(t_ms_data *data)
Definition echo.c:23
void handle_std_io(int *std_io, int std_fileno)
Definition utils_0.c:50
#define EXIT_SUCCESS
Definition exit_status.h:16
#define EXIT_FAILURE
Definition exit_status.h:17
int ft_strcmp(const char *s1, const char *s2)
Definition ft_strcmp.c:24
void ft_putchar_fd(char c, int fd)
void ft_putstr_fd(char *s, int fd)
int std_out
Definition shell.h:27
char ** args
Definition shell.h:23