changeset 16345:feb16d0117c8

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
author gpoirier
date Fri, 02 Sep 2005 08:29:30 +0000
parents b139ca30d52b
children 6ff303d2876b
files m_option.c m_option.h mplayer.c parser-mecmd.c parser-mpcmd.c
diffstat 5 files changed, 42 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/m_option.c	Fri Sep 02 00:05:21 2005 +0000
+++ b/m_option.c	Fri Sep 02 08:29:30 2005 +0000
@@ -1005,7 +1005,7 @@
     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 @@
     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 @@
     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 @@
 	     max);
     }
     printf("\n");
-    return M_OPT_EXIT;
+    return M_OPT_EXIT - 1;
   }
 
   for(nopts = 0 ; desc->fields[nopts].name ; nopts++)
@@ -1545,7 +1545,7 @@
       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 @@
 	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 ;
--- a/m_option.h	Fri Sep 02 00:05:21 2005 +0000
+++ b/m_option.h	Fri Sep 02 08:29:30 2005 +0000
@@ -217,6 +217,11 @@
 #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
--- a/mplayer.c	Fri Sep 02 00:05:21 2005 +0000
+++ b/mplayer.c	Fri Sep 02 08:29:30 2005 +0000
@@ -1048,6 +1048,8 @@
 
 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 @@
 
     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 @@
 	filename = play_tree_iter_get_file(playtree_iter,1);
       }
     }
+    }
 	
 #ifdef WIN32
 	if(proc_priority){
@@ -1205,12 +1208,12 @@
 
     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 @@
         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 @@
         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 @@
        (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)
 {
--- a/parser-mecmd.c	Fri Sep 02 00:05:21 2005 +0000
+++ b/parser-mecmd.c	Fri Sep 02 08:29:30 2005 +0000
@@ -51,6 +51,7 @@
   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 @@
 	  }
 	} 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 @@
 	    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 @@
       }
   }
 
+  if (opt_exit)
+    exit(0);
   if(nf == 0) {
     m_entry_list_free(lst);
     mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n");
--- a/parser-mpcmd.c	Fri Sep 02 00:05:21 2005 +0000
+++ b/parser-mpcmd.c	Fri Sep 02 08:29:30 2005 +0000
@@ -63,6 +63,7 @@
   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 @@
 	  }
 	}
 
+	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 @@
       }
   }
 
+  if (opt_exit)
+    goto err_out;
   --recursion_depth;
   if(last_parent != root)
     mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n");