Minishell 1.0
42 School Minishell Project - A simple shell implementation
Yüklüyor...
Arıyor...
Eşleşme Yok
builtin_echo.c
Bu dosyanın dokümantasyonuna git.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* builtin_echo.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: hgenc <hgenc@student.42kocaeli.com.tr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2026/01/17 18:42:00 by hgenc #+# #+# */
9/* Updated: 2026/01/18 17:23:00 by hgenc ### ########.fr */
10/* */
11/* ************************************************************************** */
12
14#include <unistd.h>
15
16/*
17** -n opsiyonunu kontrol eder
18** Birden fazla -n olabilir: echo -n -n -n hello
19** -nnn gibi kombinasyonlar da geçerli
20** @return: İlk argüman indeksi (opsiyonlardan sonra)
21*/
22static int check_n_option(char **args, int *no_newline)
23{
24 int i;
25 int j;
26
27 i = 1;
28 *no_newline = 0;
29 while (args[i] && args[i][0] == '-')
30 {
31 j = 1;
32 if (!args[i][j])
33 break ;
34 while (args[i][j] == 'n')
35 j++;
36 if (args[i][j] != '\0')
37 break ;
38 *no_newline = 1;
39 i++;
40 }
41 return (i);
42}
43
44/*
45** echo builtin - metni yazdırır
46** -n opsiyonu: newline yazdırmaz
47** Argümanlar arası boşluk ile ayrılır
48** @return: Her zaman 0 (başarılı)
49*/
51{
52 int i;
53 int no_newline;
54
55 i = check_n_option(cmd->args, &no_newline);
56 while (cmd->args[i])
57 {
58 ft_putstr_fd(cmd->args[i], STDOUT_FILENO);
59 if (cmd->args[i + 1])
60 ft_putchar_fd(' ', STDOUT_FILENO);
61 i++;
62 }
63 if (!no_newline)
64 ft_putchar_fd('\n', STDOUT_FILENO);
65 return (0);
66}
int builtin_echo(t_cmd *cmd)
static int check_n_option(char **args, int *no_newline)
Minishell ana header dosyası
struct s_cmd t_cmd
char ** args
Definition minishell.h:129