2828#include <errno.h>
2929#include <unistd.h>
3030#include <locale.h>
31+ #include <sys/wait.h>
3132#ifdef _WIN32
3233#include <windows.h>
3334#endif
@@ -40,6 +41,7 @@ static int opt_lua = 0;
4041static int opt_debug = 0 ;
4142static int opt_width = WIDTH ;
4243static char * opt_autoload = NULL ;
44+ static const char * mmedia_bin = NULL ;
4345static int opt_autosave = 1 ;
4446static int opt_mmedia = 0 ;
4547static int need_restart = 0 ;
@@ -217,6 +219,23 @@ static char *media_fn[] = {
217219 "instead.get_music"
218220};
219221
222+ static void mmedia_run (const char * f )
223+ {
224+ pid_t pid ;
225+ int status ;
226+ if (!mmedia_bin || !mmedia_bin [0 ])
227+ return ;
228+ pid = fork ();
229+ if (pid == -1 )
230+ return ;
231+ else if (pid > 0 ) {
232+ waitpid (pid , & status , 0 );
233+ } else {
234+ execl (mmedia_bin , mmedia_bin , f , NULL );
235+ exit (1 );
236+ }
237+ }
238+
220239static void mmedia (int t )
221240{
222241 char * mm ;
@@ -235,6 +254,7 @@ static void mmedia(int t)
235254 media [t ] = mm ;
236255 if (mm && * mm ) { /* changed */
237256 printf ("@ %s\n" , mm );
257+ mmedia_run (mm );
238258 }
239259 }
240260}
@@ -264,8 +284,9 @@ int main(int argc, const char **argv)
264284 opt_autosave = 1 ;
265285 } else if (!strcmp (argv [i ], "-x" )) {
266286 opt_lua = 1 ;
267- } else if (!strcmp (argv [i ], "-m" )) {
287+ } else if (!strncmp (argv [i ], "-m" , 2 )) {
268288 opt_mmedia = 1 ;
289+ mmedia_bin = argv [i ] + 2 ;
269290 } else if (!strncmp (argv [i ], "-d" , 2 )) {
270291 opt_debug = 1 ;
271292 reopen_stderr (argv [i ] + 2 );
0 commit comments