diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_exit.c | 1 | ||||
-rw-r--r-- | src/ft_get_music.c | 11 | ||||
-rw-r--r-- | src/ft_init_map.c | 5 | ||||
-rw-r--r-- | src/ft_music.c | 22 | ||||
-rw-r--r-- | src/ft_treat_args.c | 2 | ||||
-rw-r--r-- | src/ft_warp_level.c | 11 |
6 files changed, 31 insertions, 21 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c index 973abca..be4d46e 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -34,6 +34,7 @@ static void ft_memdel((void**)&clist->mlist.music_cmd); ft_memdel((void**)&clist->mlist.mapl); ft_free_words(clist->mlist.map); + ft_free_words(clist->mlist.mcmd_words); if (!clist->wlist.inited) ft_memdel((void**)&clist->wlist.winptr); } diff --git a/src/ft_get_music.c b/src/ft_get_music.c index cdd7039..2383e0a 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -15,7 +15,7 @@ #include <stdlib.h> #include <stdint.h> -static void +static int8_t ft_set_music_cmd(t_map *mlist) { uint8_t len; @@ -24,9 +24,13 @@ static void len += ft_strlen(FT_MUS_CMD) - 2; ft_memdel((void**)&mlist->music_cmd); if (!(mlist->music_cmd = (char *)malloc((len + 1) * sizeof(char)))) - return ; + return (-1); ft_sprintf(mlist->music_cmd, FT_MUS_CMD, mlist->music_path); + ft_free_words(mlist->mcmd_words); + if (!(mlist->mcmd_words = ft_split(mlist->music_cmd, ' '))) + return (-1); + return (0); } int8_t @@ -54,6 +58,5 @@ int8_t return (-1); } clist->mlist.ismusic = 1; - ft_set_music_cmd(&clist->mlist); - return (0); + return ((ft_set_music_cmd(&clist->mlist) == 0) ? (0) : (-1)); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 4fa127c..1c12189 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -30,7 +30,9 @@ static int8_t !(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) || !(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) || !(mlist->map = (char**)ft_calloc(2, sizeof(char*))) || - !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char)))) + !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->mcmd_words = (char**)ft_calloc(2, sizeof(char*))) || + !(mlist->mcmd_words[0] = (char*)ft_calloc(1, sizeof(char)))) return (-1); return (0); } @@ -41,6 +43,7 @@ int8_t if (ft_init_map_callocs(mlist) < 0) return (-1); mlist->map[1] = 0; + mlist->mcmd_words[1] = 0; mlist->map_w = 0; mlist->map_h = 0; mlist->mapl_len = 0; diff --git a/src/ft_music.c b/src/ft_music.c index 4d25a3a..f1801f9 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -11,19 +11,21 @@ /* ************************************************************************** */ #include <libft.h> -#include <cub3d.h> +#include <stddef.h> #include <stdlib.h> - #include <unistd.h> void - ft_music_fork(char *music_cmd) + ft_music_fork(char **mcmd_words) { - while (1) - { - ft_printf("%s\n", music_cmd); - sleep(1); - } - /* execve here */ - /* system(cl->mlist.music_cmd); */ + /* execve(2) here */ + + char *arg[4]; + + arg[0] = "/bin/sh"; + arg[1] = "-c"; + arg[2] = "aplay ./media/sound/DEVANT-LES-KAISSONS.wav"; + arg[3] = NULL; + (void)mcmd_words; + execve("/bin/sh", &arg[0], NULL); } diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index accf3aa..c4ffc98 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -42,7 +42,7 @@ uint8_t clist->isoldmus = 1; clist->mpid = fork(); if (clist->mpid == 0) - ft_music_fork(clist->mlist.music_cmd); + ft_music_fork(clist->mlist.mcmd_words); } ft_hooks_and_loops(&clist->wlist, clist); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index febff7e..9bd8d92 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -35,6 +35,7 @@ static void ft_memdel((void**)&ml->music_cmd); ft_memdel((void**)&ml->mapl); ft_free_words(ml->map); + ft_free_words(ml->mcmd_words); } static void @@ -75,11 +76,11 @@ static void else if (isoldmus && cl->mlist.ismusic && ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) { - kill(cl->mpid, SIGTERM); - wait(&cl->mpid); - cl->mpid = fork(); - if (cl->mpid == 0) - ft_music_fork(cl->mlist.music_cmd); + /* kill(cl->mpid, SIGTERM); */ + /* wait(&cl->mpid); */ + /* cl->mpid = fork(); */ + /* if (cl->mpid == 0) */ + /* ft_music_fork(cl->mlist.mcmd_words); */ } else if (isoldmus && cl->mlist.ismusic && !ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) |