options: support string list separators other than ','

Allow specifying a custom separator character for options of string
list type, and use that to define OPT_PATHLIST which takes a list of
strings separated by ':' (or ';' on Windows).
This commit is contained in:
Uoti Urpala 2011-04-19 04:11:52 +03:00
parent acc187cd20
commit 2db33ab48c
2 changed files with 15 additions and 5 deletions

View File

@ -535,7 +535,6 @@ const m_option_type_t m_option_type_string = {
//////////// String list
#define LIST_SEPARATOR ','
#undef VAL
#define VAL(x) (*(char***)(x))
@ -683,9 +682,9 @@ static int parse_str_list(const m_option_t* opt,const char *name, const char *pa
if (param == NULL || strlen(param) == 0)
return M_OPT_MISSING_PARAM;
char separator = opt->priv ? *(char *)opt->priv : OPTION_LIST_SEPARATOR;
while(ptr[0] != '\0') {
ptr = get_nextsep(ptr, LIST_SEPARATOR, 0);
ptr = get_nextsep(ptr, separator, 0);
if(!ptr) {
n++;
break;
@ -707,7 +706,7 @@ static int parse_str_list(const m_option_t* opt,const char *name, const char *pa
while(1) {
last_ptr = ptr;
ptr = get_nextsep(ptr, LIST_SEPARATOR, 1);
ptr = get_nextsep(ptr, separator, 1);
if(!ptr) {
res[n] = strdup(last_ptr);
n++;
@ -1857,7 +1856,7 @@ static int parse_obj_settings_list(const m_option_t* opt,const char *name,
while(ptr[0] != '\0') {
last_ptr = ptr;
ptr = get_nextsep(ptr, LIST_SEPARATOR, 1);
ptr = get_nextsep(ptr, OPTION_LIST_SEPARATOR, 1);
if(!ptr) {
r = parse_obj_settings(name,last_ptr,opt->priv,dst ? &res : NULL,n);

View File

@ -22,6 +22,8 @@
#include <string.h>
#include <stddef.h>
#include "config.h"
/// \defgroup Options
/// m_option allows to parse, print and copy data of various types.
/// It is the base of the \ref OptionsStruct, \ref Config and
@ -536,11 +538,20 @@ m_option_free(const m_option_t* opt,void* dst) {
*/
int parse_timestring(const char *str, double *time, char endchar);
#define OPTION_LIST_SEPARATOR ','
#if HAVE_DOS_PATHS
#define OPTION_PATH_SEPARATOR ';'
#else
#define OPTION_PATH_SEPARATOR ':'
#endif
#define OPT_FLAG_ON(optname, varname, flags) {optname, NULL, &m_option_type_flag, flags, 0, 1, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_FLAG_OFF(optname, varname, flags) {optname, NULL, &m_option_type_flag, flags, 1, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_MAKE_FLAGS(optname, varname, flags) OPT_FLAG_ON(optname, varname, flags), OPT_FLAG_OFF("no" optname, varname, flags)
#define OPT_FLAG_CONSTANTS(optname, varname, flags, offvalue, value) {optname, NULL, &m_option_type_flag, flags, offvalue, value, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_STRINGLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_PATHLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, (void *)&(const char){OPTION_PATH_SEPARATOR}, 1, offsetof(struct MPOpts, varname)}
#define OPT_INT(optname, varname, flags) {optname, NULL, &m_option_type_int, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_INTRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_int, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_INTPAIR(optname, varname, flags) {optname, NULL, &m_option_type_intpair, (flags), 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}