Skip to content

Commit

Permalink
[FIX] echo function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Mendy committed May 10, 2023
1 parent bc77101 commit 9cd12e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/command/display_error_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int display_error_command(char *cmd)
return 84;
break;
default:
fprintf(stderr,"%s: %s\n", cmd, strerror(errno));
fprintf(stderr,"%s: %s.\n", cmd, strerror(errno));
break;
}
return 0;
Expand Down
34 changes: 30 additions & 4 deletions src/command/echo_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,42 @@ static int echo_command_ter(char **command, int tab_len, int i)
return OK;
}

static int echo_command_sub(char **command, int tab_len, int flag, int i)
static int oifozehguzeihfgzo(int multiple, int i, int i_begin, char **command)
{
int len_str = 0;
if (command == NULL)
int tab_len = my_tablen(command);

if ((len_str = my_strlen(command[i])) == KO)
return KO;
for (; command[i] != NULL; i ++){
if ((len_str = my_strlen(command[i])) == KO)
if (multiple == 1 && i == i_begin) {
if (write(1, &(command[i][1]), len_str - 1) == KO)
return KO;
}
if (multiple == 1 && i == tab_len - 1) {
if (write(1, command[i], len_str - 1) == KO)
return KO;
}
if (!((multiple == 1 && i == tab_len - 1) ||
(multiple == 1 && i == i_begin))) {
if (write(1, command[i], len_str) == KO)
return KO;
}
return 0;
}

static int echo_command_sub(char **command, int tab_len, int flag, int i)
{
int multiple = 0;
int i_begin = i;

if (command == NULL)
return KO;
return
if (tab_len - i != 1)
multiple = 1;
for (; command[i] != NULL; i ++) {
if (oifozehguzeihfgzo(multiple, i, i_begin, command) == KO)
return KO;
if (echo_command_ter(command, tab_len, i) != OK)
return KO;
}
Expand Down

0 comments on commit 9cd12e6

Please sign in to comment.