1*77c1e3ccSAndroid Build Coastguard Worker /* 2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2020, Alliance for Open Media. All rights reserved. 3*77c1e3ccSAndroid Build Coastguard Worker * 4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and 5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can 7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the 9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10*77c1e3ccSAndroid Build Coastguard Worker */ 11*77c1e3ccSAndroid Build Coastguard Worker 12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_COMMON_ARGS_HELPER_H_ 13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_COMMON_ARGS_HELPER_H_ 14*77c1e3ccSAndroid Build Coastguard Worker 15*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_encoder.h" 16*77c1e3ccSAndroid Build Coastguard Worker 17*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus 18*77c1e3ccSAndroid Build Coastguard Worker extern "C" { 19*77c1e3ccSAndroid Build Coastguard Worker #endif 20*77c1e3ccSAndroid Build Coastguard Worker 21*77c1e3ccSAndroid Build Coastguard Worker // Maximum length of the error messages for the helper functions. 22*77c1e3ccSAndroid Build Coastguard Worker #define ARG_ERR_MSG_MAX_LEN 200 23*77c1e3ccSAndroid Build Coastguard Worker 24*77c1e3ccSAndroid Build Coastguard Worker struct arg { 25*77c1e3ccSAndroid Build Coastguard Worker char **argv; 26*77c1e3ccSAndroid Build Coastguard Worker const char *name; 27*77c1e3ccSAndroid Build Coastguard Worker const char *val; 28*77c1e3ccSAndroid Build Coastguard Worker unsigned int argv_step; 29*77c1e3ccSAndroid Build Coastguard Worker const struct arg_def *def; 30*77c1e3ccSAndroid Build Coastguard Worker }; 31*77c1e3ccSAndroid Build Coastguard Worker 32*77c1e3ccSAndroid Build Coastguard Worker struct arg_enum_list { 33*77c1e3ccSAndroid Build Coastguard Worker const char *name; 34*77c1e3ccSAndroid Build Coastguard Worker int val; 35*77c1e3ccSAndroid Build Coastguard Worker }; 36*77c1e3ccSAndroid Build Coastguard Worker #define ARG_ENUM_LIST_END \ 37*77c1e3ccSAndroid Build Coastguard Worker { 0 } 38*77c1e3ccSAndroid Build Coastguard Worker 39*77c1e3ccSAndroid Build Coastguard Worker typedef struct arg_def { 40*77c1e3ccSAndroid Build Coastguard Worker const char *short_name; 41*77c1e3ccSAndroid Build Coastguard Worker const char *long_name; 42*77c1e3ccSAndroid Build Coastguard Worker int has_val; // 0: The argument must not have a value. 43*77c1e3ccSAndroid Build Coastguard Worker // 1: The argument must have a value. 44*77c1e3ccSAndroid Build Coastguard Worker // -1: The argument may or may not have a value. 45*77c1e3ccSAndroid Build Coastguard Worker const char *desc; 46*77c1e3ccSAndroid Build Coastguard Worker const struct arg_enum_list *enums; 47*77c1e3ccSAndroid Build Coastguard Worker } arg_def_t; 48*77c1e3ccSAndroid Build Coastguard Worker #define ARG_DEF(s, l, v, d) \ 49*77c1e3ccSAndroid Build Coastguard Worker { s, l, v, d, NULL } 50*77c1e3ccSAndroid Build Coastguard Worker #define ARG_DEF_ENUM(s, l, v, d, e) \ 51*77c1e3ccSAndroid Build Coastguard Worker { s, l, v, d, e } 52*77c1e3ccSAndroid Build Coastguard Worker #define ARG_DEF_LIST_END \ 53*77c1e3ccSAndroid Build Coastguard Worker { 0 } 54*77c1e3ccSAndroid Build Coastguard Worker 55*77c1e3ccSAndroid Build Coastguard Worker struct arg arg_init(char **argv); 56*77c1e3ccSAndroid Build Coastguard Worker 57*77c1e3ccSAndroid Build Coastguard Worker /* 58*77c1e3ccSAndroid Build Coastguard Worker * The helper functions below all take an optional parameter err_msg for 59*77c1e3ccSAndroid Build Coastguard Worker * error reporting. When err_msg is not NULL (must point to a buffer 60*77c1e3ccSAndroid Build Coastguard Worker * which is at least ARG_ERR_MSG_MAX_LEN bytes long), a related error message is 61*77c1e3ccSAndroid Build Coastguard Worker * stored in it if an error occurs. It will be set to an empty string if no 62*77c1e3ccSAndroid Build Coastguard Worker * error occurs. 63*77c1e3ccSAndroid Build Coastguard Worker */ 64*77c1e3ccSAndroid Build Coastguard Worker int arg_match_helper(struct arg *arg_, const struct arg_def *def, char **argv, 65*77c1e3ccSAndroid Build Coastguard Worker char *err_msg); 66*77c1e3ccSAndroid Build Coastguard Worker unsigned int arg_parse_uint_helper(const struct arg *arg, char *err_msg); 67*77c1e3ccSAndroid Build Coastguard Worker int arg_parse_int_helper(const struct arg *arg, char *err_msg); 68*77c1e3ccSAndroid Build Coastguard Worker struct aom_rational arg_parse_rational_helper(const struct arg *arg, 69*77c1e3ccSAndroid Build Coastguard Worker char *err_msg); 70*77c1e3ccSAndroid Build Coastguard Worker int arg_parse_enum_helper(const struct arg *arg, char *err_msg); 71*77c1e3ccSAndroid Build Coastguard Worker int arg_parse_enum_or_int_helper(const struct arg *arg, char *err_msg); 72*77c1e3ccSAndroid Build Coastguard Worker int arg_parse_list_helper(const struct arg *arg, int *list, int n, 73*77c1e3ccSAndroid Build Coastguard Worker char *err_msg); 74*77c1e3ccSAndroid Build Coastguard Worker 75*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus 76*77c1e3ccSAndroid Build Coastguard Worker } // extern "C" 77*77c1e3ccSAndroid Build Coastguard Worker #endif 78*77c1e3ccSAndroid Build Coastguard Worker 79*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_COMMON_ARGS_HELPER_H_ 80