1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #ifndef AOM_COMMON_ARGS_H_ 13 #define AOM_COMMON_ARGS_H_ 14 #include <stdio.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 struct arg { 21 char **argv; 22 const char *name; 23 const char *val; 24 unsigned int argv_step; 25 const struct arg_def *def; 26 }; 27 28 struct arg_enum_list { 29 const char *name; 30 int val; 31 }; 32 #define ARG_ENUM_LIST_END \ 33 { 0 } 34 35 typedef struct arg_def { 36 const char *short_name; 37 const char *long_name; 38 int has_val; 39 const char *desc; 40 const struct arg_enum_list *enums; 41 } arg_def_t; 42 #define ARG_DEF(s, l, v, d) \ 43 { s, l, v, d, NULL } 44 #define ARG_DEF_ENUM(s, l, v, d, e) \ 45 { s, l, v, d, e } 46 #define ARG_DEF_LIST_END \ 47 { 0 } 48 49 struct arg arg_init(char **argv); 50 int arg_match(struct arg *arg_, const struct arg_def *def, char **argv); 51 char *ignore_front_spaces(const char *str); 52 void ignore_end_spaces(char *str); 53 int arg_cfg(int *argc, char ***argv, const char *file); 54 const char *arg_next(struct arg *arg); 55 void arg_show_usage(FILE *fp, const struct arg_def *const *defs); 56 char **argv_dup(int argc, const char **argv); 57 58 unsigned int arg_parse_uint(const struct arg *arg); 59 int arg_parse_int(const struct arg *arg); 60 struct aom_rational arg_parse_rational(const struct arg *arg); 61 int arg_parse_enum(const struct arg *arg); 62 int arg_parse_enum_or_int(const struct arg *arg); 63 int arg_parse_list(const struct arg *arg, int *list, int n); 64 #ifdef __cplusplus 65 } // extern "C" 66 #endif 67 68 #endif // AOM_COMMON_ARGS_H_ 69