From 43844d090c5580b71228c7a13efa7ce13b37cab8 Mon Sep 17 00:00:00 2001 From: gpoirier Date: Fri, 2 Sep 2005 08:29:30 +0000 Subject: allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net " This one makes mplayer -vo help -ao help -ac help -vc help -pphelp -af help -vfm help -vf help -afm help -fstype help produce the desired output. From the thread: Date: Jul 16, 2005 8:25 PM Subject: [MPlayer-dev-eng] [PATCH] allow multiple help clauses on the command line git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@16346 b3059339-0415-0410-9bf9-f77b7e298cf2 --- m_option.c | 12 ++++++------ m_option.h | 5 +++++ mplayer.c | 28 +++++++++++++++++----------- parser-mecmd.c | 9 +++++++-- parser-mpcmd.c | 9 +++++++-- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/m_option.c b/m_option.c index 2980c0adbb..13551cd26c 100644 --- a/m_option.c +++ b/m_option.c @@ -1005,7 +1005,7 @@ static int parse_imgfmt(m_option_t* opt,char *name, char *param, void* dst, int for(i = 0 ; mp_imgfmt_list[i].name ; i++) mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s",mp_imgfmt_list[i].name); mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - return M_OPT_EXIT; + return M_OPT_EXIT - 1; } if (sscanf(param, "0x%x", &fmt) != 1) @@ -1093,7 +1093,7 @@ static int parse_afmt(m_option_t* opt,char *name, char *param, void* dst, int sr for(i = 0 ; mp_afmt_list[i].name ; i++) mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s",mp_afmt_list[i].name); mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - return M_OPT_EXIT; + return M_OPT_EXIT - 1; } if (sscanf(param, "0x%x", &fmt) != 1) @@ -1212,7 +1212,7 @@ static int get_obj_params(char* opt_name, char* name,char* params, char min[50],max[50]; if(!desc->fields) { printf("%s doesn't have any options.\n\n",name); - return M_OPT_EXIT; + return M_OPT_EXIT - 1; } printf("\n Name Type Min Max\n\n"); for(n = 0 ; desc->fields[n].name ; n++) { @@ -1233,7 +1233,7 @@ static int get_obj_params(char* opt_name, char* name,char* params, max); } printf("\n"); - return M_OPT_EXIT; + return M_OPT_EXIT - 1; } for(nopts = 0 ; desc->fields[nopts].name ; nopts++) @@ -1545,7 +1545,7 @@ static int parse_obj_settings_list(m_option_t* opt,char *name, mp_msg(MSGT_VFILTER,MSGL_INFO," %-15s: %s\n", M_ST_MB(char*,ol->list[n],ol->name_off), M_ST_MB(char*,ol->list[n],ol->info_off)); - return M_OPT_EXIT; + return M_OPT_EXIT - 1; } ptr = str = strdup(param); @@ -1688,7 +1688,7 @@ static int parse_obj_presets(m_option_t* opt,char *name, pre += s) mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s",pre_name); mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n"); - return M_OPT_EXIT; + return M_OPT_EXIT - 1; } for(pre_name = M_ST_MB(char*,pre,obj_p->name_off) ; pre_name ; diff --git a/m_option.h b/m_option.h index 8d2427c9a8..5ab2597549 100644 --- a/m_option.h +++ b/m_option.h @@ -217,6 +217,11 @@ struct m_option { #define M_OPT_OUT_OF_RANGE -4 #define M_OPT_PARSER_ERR -5 #define M_OPT_EXIT -6 +// M_OPT_EXIT must be the lowest number on this list. +// To indicate that mplayer should exit without playing anything, +// a parsing function needs to return M_OPT_EXIT less the number +// of additional command line parameters it consumed. +// Generally it will return either M_OPT_EXIT or M_OPT_EXIT - 1. // FIXME: backward compatibility #define ERR_NOT_AN_OPTION M_OPT_UNKNOWN diff --git a/mplayer.c b/mplayer.c index 45da221613..2257c09687 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1048,6 +1048,8 @@ int osd_show_status = 0; int rtc_fd=-1; +int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything + //float a_frame=0; // Audio int i; @@ -1150,8 +1152,8 @@ int gui_no_filename=0; playtree = m_config_parse_mp_command_line(mconfig, argc, argv); if(playtree == NULL) - exit_player(NULL); - + opt_exit = 1; + else { playtree = play_tree_cleanup(playtree); if(playtree) { playtree_iter = play_tree_iter_new(playtree,mconfig); @@ -1163,6 +1165,7 @@ int gui_no_filename=0; filename = play_tree_iter_get_file(playtree_iter,1); } } + } #ifdef WIN32 if(proc_priority){ @@ -1205,12 +1208,12 @@ int gui_no_filename=0; if(video_driver_list && strcmp(video_driver_list[0],"help")==0){ list_video_out(); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){ list_audio_out(); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } // check codec.conf @@ -1241,7 +1244,7 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){ mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_CODECS\n"); list_codecs(1); mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } if(video_codec_list && strcmp(video_codec_list[0],"help")==0){ mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs); @@ -1249,28 +1252,28 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){ mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VIDEO_CODECS\n"); list_codecs(0); mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } if(video_fm_list && strcmp(video_fm_list[0],"help")==0){ vfm_help(); mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){ afm_help(); mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){ af_help(); printf("\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } #ifdef HAVE_X11 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){ fstype_help(); mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } #endif if((demuxer_name && strcmp(demuxer_name,"help")==0) || @@ -1278,9 +1281,12 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){ (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){ demuxer_help(); mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); - exit_player_with_rc(NULL, 0); + opt_exit = 1; } + if(opt_exit) + exit_player(NULL); + #ifdef USE_EDL if (edl_check_mode() == EDL_ERROR && edl_filename) { diff --git a/parser-mecmd.c b/parser-mecmd.c index b25d440420..b77f8c421e 100644 --- a/parser-mecmd.c +++ b/parser-mecmd.c @@ -51,6 +51,7 @@ m_config_parse_me_command_line(m_config_t *config, int argc, char **argv) int tmp; char *opt; int no_more_opts = 0; + int opt_exit = 0; m_entry_t *lst = NULL, *entry = NULL; #ifdef MP_DEBUG @@ -98,6 +99,10 @@ m_config_parse_me_command_line(m_config_t *config, int argc, char **argv) } } else { tmp = m_config_check_option(config, opt, argv[i + 1]); + if (tmp <= M_OPT_EXIT) { + opt_exit = 1; + tmp = M_OPT_EXIT - tmp; + } if(tmp >= 0) { entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*)); entry->opts[2*no] = strdup(opt); @@ -106,8 +111,6 @@ m_config_parse_me_command_line(m_config_t *config, int argc, char **argv) no++; } else { // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp); - if(tmp == M_OPT_EXIT) - exit(0); goto err_out; } } @@ -124,6 +127,8 @@ m_config_parse_me_command_line(m_config_t *config, int argc, char **argv) } } + if (opt_exit) + exit(0); if(nf == 0) { m_entry_list_free(lst); mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n"); diff --git a/parser-mpcmd.c b/parser-mpcmd.c index 137f72cbca..67b579b644 100644 --- a/parser-mpcmd.c +++ b/parser-mpcmd.c @@ -63,6 +63,7 @@ m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) char *opt,*splitpos=NULL; char entbuf[10]; int no_more_opts = 0; + int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything play_tree_t *last_parent, *last_entry = NULL, *root; #ifdef MACOSX_FINDER_SUPPORT extern play_tree_t *macosx_finder_args(m_config_t *, int , char **); @@ -196,9 +197,11 @@ m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) } } + if (tmp <= M_OPT_EXIT) { + opt_exit = 1; + tmp = M_OPT_EXIT - tmp; + } else if (tmp < 0) { - if (tmp == M_OPT_EXIT) - exit(0); goto err_out; } i += tmp; @@ -252,6 +255,8 @@ m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) } } + if (opt_exit) + goto err_out; --recursion_depth; if(last_parent != root) mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); -- cgit v1.2.3