1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
char *parse_star(char *str)
{
char **tabl;
char **retab;
char *str2;
int i;
int e;
e = 0;
i = 0;
str = space(str);
tabl = str_to_wordtab(str, " ");
retab = xmalloc(sizeof(*retab) * strlen(str));
while (tabl[i] != NULL)
{
retab[e] = star(tabl[i]);
e++;
i++;
}
retab[e] = NULL;
str2 = tab_to_str(' ', retab);
return (str2);
}
-------------------------------------------------------------
static void exec_wait(t_info *info)
{
int statut;
int i;
i = 0;
if (info->nb_wait > 0)
while (i++ < info->nb_wait)
wait(&statut);
info->nb_wait = 0;
}
int execute(t_mysh *mysh)
{
t_pipe *lpipe;
t_cmd *lcmd;
t_cmp cmp;
cmp.i = 0;
lcmd = mysh->icmd->begin;
while (cmp.i < mysh->icmd->len_list)
{
cmp.j = 0;
mysh->info->flag = FALSE;
lpipe = lcmd->begin_pipe;
mysh->info->std = lcmd->len_list_pipe;
while ((cmp.j < lcmd->len_list_pipe) || (mysh->info->std > 0))
{
check_cmd(epur_str(lpipe->table_pipe), mysh);
mysh->info->flag = TRUE;
lpipe = lpipe->next;
mysh->info->std--;
cmp.j++;
}
exec_wait(mysh->info);
lcmd = lcmd->next;
cmp.i++;
}
return (TRUE);
}
-------------------------------------------------------------------
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
# define MSG_ERROR_EXECVE "2: execve c'est mal terminer!\n"
int xexecve(char *bin_path, char **bin_cmd)
{
extern char **environ;
int fd;
fd = 0;
fd = execve(bin_path, bin_cmd, environ);
if (fd == (-1))
{
printf("errno => %i\n", errno);
write(2, MSG_ERROR_EXECVE, strlen(MSG_ERROR_EXECVE));
exit(0);
}
return (fd);
} |
Partager