changeset 14286:da530c6064a0

Use subopt helper to parse arguments
author reimar
date Fri, 31 Dec 2004 14:58:49 +0000
parents 6c3241503d9b
children 25142a687b00
files libvo/vo_gl.c
diffstat 1 files changed, 19 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_gl.c	Fri Dec 31 14:57:12 2004 +0000
+++ b/libvo/vo_gl.c	Fri Dec 31 14:58:49 2004 +0000
@@ -6,6 +6,7 @@
 
 #include "mp_msg.h"
 #include "config.h"
+#include "subopt-helper.h"
 #include "video_out.h"
 #include "video_out_internal.h"
 #include "font_load.h"
@@ -470,63 +471,31 @@
   vo_x11_uninit();
 }
 
+static int int_non_neg(int *sh)
+{
+  if ( *sh < 0 )
+    return 0;
+  return 1;
+}
+
+static opt_t subopts[] = {
+  {"manyfmts",     OPT_ARG_BOOL, &many_fmts,    NULL},
+  {"osd",          OPT_ARG_BOOL, &use_osd,      NULL},
+  {"scaled-osd",   OPT_ARG_BOOL, &scaled_osd,   NULL},
+  {"aspect",       OPT_ARG_BOOL, &use_aspect,   NULL},
+  {"slice-height", OPT_ARG_INT,  &slice_height, (opt_test_f)int_non_neg},
+  {NULL}
+};
+
 static uint32_t preinit(const char *arg)
 {
-    int parse_err = 0;
-    unsigned int parse_pos = 0;
+    // set defaults
     many_fmts = 0;
     use_osd = 1;
     scaled_osd = 0;
     use_aspect = 1;
     slice_height = 4;
-    if(arg) 
-    {
-        while (arg[parse_pos] && !parse_err) {
-            if (strncmp (&arg[parse_pos], "manyfmts", 8) == 0) {
-                parse_pos += 8;
-                many_fmts = 1;
-            } else if (strncmp (&arg[parse_pos], "nomanyfmts", 10) == 0) {
-                parse_pos += 10;
-                many_fmts = 0;
-            } else if (strncmp (&arg[parse_pos], "osd", 3) == 0) {
-                parse_pos += 3;
-                use_osd = 1;
-            } else if (strncmp (&arg[parse_pos], "noosd", 5) == 0) {
-                parse_pos += 5;
-                use_osd = 0;
-            } else if (strncmp (&arg[parse_pos], "scaled-osd", 10) == 0) {
-                parse_pos += 10;
-                scaled_osd = 1;
-            } else if (strncmp (&arg[parse_pos], "noscaled-osd", 12) == 0) {
-                parse_pos += 12;
-                scaled_osd = 0;
-            } else if (strncmp (&arg[parse_pos], "aspect", 6) == 0) {
-                parse_pos += 6;
-                use_aspect = 1;
-            } else if (strncmp (&arg[parse_pos], "noaspect", 8) == 0) {
-                parse_pos += 8;
-                use_aspect = 0;
-            } else if (strncmp (&arg[parse_pos], "slice-height=", 13) == 0) {
-                int val;
-                char *end;
-                parse_pos += 13;
-                val = strtol(&arg[parse_pos], &end, 0);
-                if (val < 0) parse_err = 1;
-                else {
-                  slice_height = val;
-                  parse_pos = end - arg;
-                }
-            }
-            if (arg[parse_pos] == ':') parse_pos++;
-            else if (arg[parse_pos]) parse_err = 1;
-        }
-    }
-    if (parse_err) {
-      unsigned int i;
-      mp_msg(MSGT_VO, MSGL_FATAL, "Could not parse arguments:\n%s\n", arg);
-      for (i = 0; i < parse_pos; i++)
-        mp_msg(MSGT_VO, MSGL_FATAL, " ");
-      mp_msg(MSGT_VO, MSGL_FATAL, "^\n");
+    if (subopt_parse(arg, subopts) != 0) {
       mp_msg(MSGT_VO, MSGL_FATAL,
               "\n-vo gl command line help:\n"
               "Example: mplayer -vo gl:slice-height=4\n"