/*
- * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
+ * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
- * Use of this source code is governed by a BSD-style license
+ * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
+ * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
char *long_val = def->has_val ? "=<arg>" : "";
if (def->short_name && def->long_name)
- snprintf(option_text, 37, "-%s%s, --%s%s",
- def->short_name, short_val,
+ {
+ char *comma = def->has_val ? "," : ", ";
+
+ snprintf(option_text, 37, "-%s%s%s --%s%6s",
+ def->short_name, short_val, comma,
def->long_name, long_val);
+ }
else if (def->short_name)
snprintf(option_text, 37, "-%s%s",
def->short_name, short_val);
def->long_name, long_val);
fprintf(fp, " %-37s\t%s\n", option_text, def->desc);
+
+ if(def->enums)
+ {
+ const struct arg_enum_list *listptr;
+
+ fprintf(fp, " %-37s\t ", "");
+
+ for(listptr = def->enums; listptr->name; listptr++)
+ fprintf(fp, "%s%s", listptr->name,
+ listptr[1].name ? ", " : "\n");
+ }
}
}
return rat;
}
+
+
+int arg_parse_enum(const struct arg *arg)
+{
+ const struct arg_enum_list *listptr;
+ long int rawval;
+ char *endptr;
+
+ /* First see if the value can be parsed as a raw value */
+ rawval = strtol(arg->val, &endptr, 10);
+ if (arg->val[0] != '\0' && endptr[0] == '\0')
+ {
+ /* Got a raw value, make sure it's valid */
+ for(listptr = arg->def->enums; listptr->name; listptr++)
+ if(listptr->val == rawval)
+ return rawval;
+ }
+
+ /* Next see if it can be parsed as a string */
+ for(listptr = arg->def->enums; listptr->name; listptr++)
+ if(!strcmp(arg->val, listptr->name))
+ return listptr->val;
+
+ die("Option %s: Invalid value '%s'\n", arg->name, arg->val);
+ return 0;
+}
+
+
+int arg_parse_enum_or_int(const struct arg *arg)
+{
+ if(arg->def->enums)
+ return arg_parse_enum(arg);
+ return arg_parse_int(arg);
+}