1 /* 2 * Copyright (c) 2020, 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_HELPER_H_ 13 #define AOM_COMMON_ARGS_HELPER_H_ 14 15 #include "aom/aom_encoder.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 // Maximum length of the error messages for the helper functions. 22 #define ARG_ERR_MSG_MAX_LEN 200 23 24 struct arg { 25 char **argv; 26 const char *name; 27 const char *val; 28 unsigned int argv_step; 29 const struct arg_def *def; 30 }; 31 32 struct arg_enum_list { 33 const char *name; 34 int val; 35 }; 36 #define ARG_ENUM_LIST_END \ 37 { 0 } 38 39 typedef struct arg_def { 40 const char *short_name; 41 const char *long_name; 42 int has_val; // 0: The argument must not have a value. 43 // 1: The argument must have a value. 44 // -1: The argument may or may not have a value. 45 const char *desc; 46 const struct arg_enum_list *enums; 47 } arg_def_t; 48 #define ARG_DEF(s, l, v, d) \ 49 { s, l, v, d, NULL } 50 #define ARG_DEF_ENUM(s, l, v, d, e) \ 51 { s, l, v, d, e } 52 #define ARG_DEF_LIST_END \ 53 { 0 } 54 55 struct arg arg_init(char **argv); 56 57 /* 58 * The helper functions below all take an optional parameter err_msg for 59 * error reporting. When err_msg is not NULL (must point to a buffer 60 * which is at least ARG_ERR_MSG_MAX_LEN bytes long), a related error message is 61 * stored in it if an error occurs. It will be set to an empty string if no 62 * error occurs. 63 */ 64 int arg_match_helper(struct arg *arg_, const struct arg_def *def, char **argv, 65 char *err_msg); 66 unsigned int arg_parse_uint_helper(const struct arg *arg, char *err_msg); 67 int arg_parse_int_helper(const struct arg *arg, char *err_msg); 68 struct aom_rational arg_parse_rational_helper(const struct arg *arg, 69 char *err_msg); 70 int arg_parse_enum_helper(const struct arg *arg, char *err_msg); 71 int arg_parse_enum_or_int_helper(const struct arg *arg, char *err_msg); 72 int arg_parse_list_helper(const struct arg *arg, int *list, int n, 73 char *err_msg); 74 75 #ifdef __cplusplus 76 } // extern "C" 77 #endif 78 79 #endif // AOM_COMMON_ARGS_HELPER_H_ 80