summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-22 22:41:51 +0200
committerwm4 <wm4@nowhere>2013-07-22 22:42:55 +0200
commit1df2ad7e034c1c42a8ae86e8b3077c2342ad40bd (patch)
tree10d9cbb9d44eee289ee8925119c6ad4ea965c676
parent14f1a25a8e89c8b50ba2d0dd121a8becb591f3df (diff)
downloadmpv-1df2ad7e034c1c42a8ae86e8b3077c2342ad40bd.tar.bz2
mpv-1df2ad7e034c1c42a8ae86e8b3077c2342ad40bd.tar.xz
Remove subopt-helper
Finally not used by anything anymore. Farewell.
-rw-r--r--Makefile1
-rw-r--r--audio/out/ao_alsa.c2
-rw-r--r--core/subopt-helper.c338
-rw-r--r--core/subopt-helper.h64
-rw-r--r--video/out/vo_corevideo.m2
-rw-r--r--video/out/vo_lavc.c1
-rw-r--r--video/out/vo_xv.c2
-rw-r--r--video/out/wayland_common.c2
8 files changed, 3 insertions, 409 deletions
diff --git a/Makefile b/Makefile
index 0bed4dada5..92ef2c7cf5 100644
--- a/Makefile
+++ b/Makefile
@@ -182,7 +182,6 @@ SOURCES = talloc.c \
core/playlist.c \
core/playlist_parser.c \
core/screenshot.c \
- core/subopt-helper.c \
core/version.c \
core/input/input.c \
core/timeline/tl_edl.c \
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index 7428c29a29..8c70ff39c0 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -37,7 +37,7 @@
#include "config.h"
#include "core/options.h"
-#include "core/subopt-helper.h"
+#include "core/m_option.h"
#include "audio/mixer.h"
#include "core/mp_msg.h"
diff --git a/core/subopt-helper.c b/core/subopt-helper.c
deleted file mode 100644
index 9216abeeae..0000000000
--- a/core/subopt-helper.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-/**
- * \file subopt-helper.c
- *
- * \brief Compensates the suboption parsing code duplication a bit.
- *
- * The routines defined below are there to help you with the
- * suboption parsing. Meaning extracting the options and their
- * values for you and also outputting generic help message if
- * a parse error is encountered.
- *
- * Most stuff happens in the subopt_parse function: if you call it
- * it parses for the passed opts in the passed string. It calls some
- * extra functions for explicit argument parsing ( where the option
- * itself isn't the argument but a value given after the argument
- * delimiter ('='). It also calls your test function if you supplied
- * one.
- *
- */
-
-#include "core/subopt-helper.h"
-#include "core/mp_msg.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <assert.h>
-
-#ifndef MPDEBUG
- #define NDEBUG
-#endif
-
-
-static char const * parse_int( char const * const str, int * const valp )
-{
- char * endp;
-
- assert( str && "parse_int(): str == NULL" );
-
- *valp = (int)strtol( str, &endp, 0 );
-
- /* nothing was converted */
- if ( str == endp ) { return NULL; }
-
- return endp;
-}
-
-static char const * parse_float( char const * const str, float * const valp )
-{
- char * endp;
-
- assert( str && "parse_float(): str == NULL" );
-
- *valp = strtod( str, &endp );
-
- /* nothing was converted */
- if ( str == endp ) { return NULL; }
-
- return endp;
-}
-
-#define QUOTE_CHAR '%'
-static char const * parse_str( char const * str, strarg_t * const valp )
-{
- char const * match = strchr( str, ':' );
-
- if (str[0] == QUOTE_CHAR) {
- int len = 0;
- str = &str[1];
- len = (int)strtol(str, (char **)&str, 0);
- if (!str || str[0] != QUOTE_CHAR || (len > strlen(str) - 1))
- return NULL;
- str = &str[1];
- match = &str[len];
- }
- else
- if (str[0] == '"') {
- str = &str[1];
- match = strchr(str, '"');
- if (!match)
- return NULL;
- valp->len = match - str;
- valp->str = str;
- return &match[1];
- }
- if ( !match )
- match = &str[strlen(str)];
-
- // empty string or too long
- if ((match == str) || (match - str > INT_MAX))
- return NULL;
-
- valp->len = match - str;
- valp->str = str;
-
- return match;
-}
-
-
-/**
- * \brief Try to parse all options in str and fail if it was not possible.
- *
- * \param str Pointer to the zero terminated string to be parsed.
- * \param opts Pointer to a options array. The array must be terminated
- * with an element having set name to NULL in its opt_t structure.
- *
- * \return The return value is zero if the string could be parsed
- * else a non-zero value is returned.
- *
- */
-int subopt_parse( char const * const str, const opt_t * opts )
-{
- int parse_err = 0, idx;
- unsigned int parse_pos = 0;
-
- if ( str )
- {
- while ( str[parse_pos] && !parse_err )
- {
- int next = 0;
-
- idx = 0; // reset index for the below loop
- while ( opts[idx].name )
- {
- int opt_len;
- int substr_len;
-
- // get length of the option we test against */
- opt_len = strlen( opts[idx].name );
-
- // get length of the current substring of str */
- {
- char * delim, * arg_delim;
-
- /* search nearest delimiter ( option or argument delimiter ) */
- delim = strchr( &str[parse_pos], ':' );
- arg_delim = strchr( &str[parse_pos], '=' );
-
- if ( ( delim && arg_delim && delim > arg_delim ) ||
- delim == NULL )
- {
- delim = strchr( &str[parse_pos], '=' );
- }
-
- substr_len = delim ? // is a delim present
- delim - &str[parse_pos] : // yes
- strlen( &str[parse_pos] ); // no, end of string
- }
-
- //printf( "substr_len=%d, opt_len=%d\n", substr_len, opt_len );
-
- /* Check if the length of the current option matches the *
- * length of the option we want to test again. */
- if ( substr_len == opt_len )
-{
- /* check if option was activated/deactivated */
- if( strncmp( &str[parse_pos], opts[idx].name, opt_len ) == 0 )
- {
- /* option was found */
- next = 1;
-
- assert( opts[idx].valp && "Need a pointer to store the arg!" );
-
- /* type specific code */
- if ( opts[idx].type == OPT_ARG_BOOL )
- {
- /* Handle OPT_ARG_BOOL separately so *
- * the others can share code. */
-
- /* set option to true */
- *((int *)(opts[idx].valp)) = 1;
-
- /* increment position */
- parse_pos += opt_len;
- }
- else
- {
- /* Type is not OPT_ARG_BOOL, means we have to parse *
- * for the arg delimiter character and eventually *
- * call a test function. */
- char const * last;
-
- /* increment position to check for arg */
- parse_pos += opt_len;
-
- if ( str[parse_pos] != '=' )
- {
- parse_err = 1; break;
- }
-
- /* '=' char was there, so let's move after it */
- ++parse_pos;
-
- switch ( opts[idx].type )
- {
- case OPT_ARG_INT:
- last = parse_int( &str[parse_pos],
- (int *)opts[idx].valp );
-
- break;
- case OPT_ARG_STR:
- last = parse_str( &str[parse_pos],
- (strarg_t *)opts[idx].valp );
- break;
- case OPT_ARG_MSTRZ:
- {
- char **valp = opts[idx].valp;
- strarg_t tmp;
- tmp.str = NULL;
- tmp.len = 0;
- last = parse_str( &str[parse_pos], &tmp );
- free(*valp);
- *valp = NULL;
- if (tmp.str && tmp.len > 0) {
- *valp = malloc(tmp.len + 1);
- memcpy(*valp, tmp.str, tmp.len);
- (*valp)[tmp.len] = 0;
- }
- break;
- }
- case OPT_ARG_FLOAT:
- last = parse_float( &str[parse_pos],
- (float *)opts[idx].valp );
- break;
- default:
- assert( 0 && "Arg type of suboption doesn't exist!" );
- last = NULL; // break parsing!
- }
-
- /* was the conversion succesful? */
- if ( !last )
- {
- parse_err = 1; break;
- }
-
- /* make test if supplied */
- if ( opts[idx].test && !opts[idx].test( opts[idx].valp ) )
- {
- parse_err = 1; break;
- }
-
- /* we succeded, set position */
- parse_pos = last - str;
- }
- }
- }
- else if (opts[idx].type == OPT_ARG_BOOL) {
- // check for no-<opt>
- for (char **p = (char *[]){"no-", "no", NULL}; *p; p++) {
- if (substr_len == opt_len + strlen(*p) &&
- !strncmp(str + parse_pos, *p, strlen(*p)) &&
- !strncmp(str + parse_pos + strlen(*p), opts[idx].name, opt_len)) {
- /* option was found but negated */
- next = 1;
-
- /* set arg to false */
- *((int *)(opts[idx].valp)) = 0;
-
- parse_pos += opt_len + strlen(*p);
- break;
- }
- }
- }
-
- ++idx; // test against next option
-
- /* break out of the loop, if this subopt is processed */
- if ( next ) { break; }
- }
-
- /* if we had a valid suboption the current pos should *
- * equal the delimiter char, which should be ':' for *
- * suboptions. */
- if ( !parse_err && str[parse_pos] == ':' ) { ++parse_pos; }
- else if ( str[parse_pos] ) { parse_err = 1; }
- }
- }
-
- /* if an error was encountered */
- if (parse_err)
- {
- unsigned int i;
- mp_msg( MSGT_VO, MSGL_FATAL, "Could not parse arguments at the position indicated below:\n%s\n", str );
- for ( i = 0; i < parse_pos; ++i )
- {
- mp_msg(MSGT_VO, MSGL_FATAL, " ");
- }
- mp_msg(MSGT_VO, MSGL_FATAL, "^\n");
-
- return -1;
- }
-
- /* we could parse everything */
- return 0;
-}
-
-
-/*** common test functions ***/
-
-/** \brief Test if i is not negative */
-int int_non_neg(void *iptr)
-{
- int *i = iptr;
- return *i >= 0;
-}
-/** \brief Test if i is positive. */
-int int_pos(void *iptr)
-{
- int *i = iptr;
- return *i > 0;
-}
-
-/*** little helpers */
-
-/** \brief compare the stings just as strcmp does */
-int strargcmp(strarg_t *arg, const char *str) {
- int res = strncmp(arg->str, str, arg->len);
- if (!res && arg->len != strlen(str))
- res = arg->len - strlen(str);
- return res;
-}
diff --git a/core/subopt-helper.h b/core/subopt-helper.h
deleted file mode 100644
index e234db4ed2..0000000000
--- a/core/subopt-helper.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef MPLAYER_SUBOPT_HELPER_H
-#define MPLAYER_SUBOPT_HELPER_H
-
-/**
- * \file subopt-helper.h
- *
- * \brief Datatype and functions declarations for usage
- * of the suboption parser.
- *
- */
-
-#define OPT_ARG_BOOL 0
-#define OPT_ARG_INT 1
-#define OPT_ARG_STR 2
-#define OPT_ARG_MSTRZ 3 ///< A malloced, zero terminated string, use free()!
-#define OPT_ARG_FLOAT 4
-
-typedef int (*opt_test_f)(void *);
-
-/** simple structure for defining the option name, type and storage location */
-typedef struct opt_s
-{
- const char * name; ///< string that identifies the option
- int type; ///< option type as defined in subopt-helper.h
- void * valp; ///< pointer to the mem where the value should be stored
- opt_test_f test; ///< argument test func ( optional )
-} opt_t;
-
-/** parses the string for the options specified in opt */
-int subopt_parse( char const * const str, const opt_t * opts );
-
-
-/*------------------ arg specific types and declaration -------------------*/
-typedef struct strarg_s
-{
- int len; ///< length of the string determined by the parser
- char const * str; ///< pointer to position inside the parse string
-} strarg_t;
-
-
-int int_non_neg(void *iptr);
-int int_pos(void *iptr);
-
-int strargcmp(strarg_t *arg, const char *str);
-
-#endif /* MPLAYER_SUBOPT_HELPER_H */
diff --git a/video/out/vo_corevideo.m b/video/out/vo_corevideo.m
index 3fabacf6d3..3a45c42921 100644
--- a/video/out/vo_corevideo.m
+++ b/video/out/vo_corevideo.m
@@ -27,7 +27,7 @@
#import "talloc.h"
#import "vo.h"
#import "sub/sub.h"
-#import "core/subopt-helper.h"
+#import "core/m_option.h"
#import "video/csputils.h"
#import "video/vfcap.h"
diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c
index ffc565f0bf..6c28169baa 100644
--- a/video/out/vo_lavc.c
+++ b/video/out/vo_lavc.c
@@ -28,7 +28,6 @@
#include "video/fmt-conversion.h"
#include "video/mp_image.h"
#include "video/vfcap.h"
-#include "core/subopt-helper.h"
#include "talloc.h"
#include "vo.h"
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index 180dfc1d85..6c91e7bcd4 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -53,7 +53,7 @@
#include "sub/sub.h"
#include "sub/draw_bmp.h"
#include "video/csputils.h"
-#include "core/subopt-helper.h"
+#include "core/m_option.h"
#include "osdep/timer.h"
static const vo_info_t info = {
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 9396c69c07..f6d8cdd9d2 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -45,8 +45,6 @@
#include "aspect.h"
#include "osdep/timer.h"
-#include "core/subopt-helper.h"
-
#include "core/input/input.h"
#include "core/input/keycodes.h"