John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 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. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_COMMON_ARGS_H_ |
| 13 | #define AOM_COMMON_ARGS_H_ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 16 | #include "aom/aom_codec.h" |
| 17 | #include "aom/aom_encoder.h" |
| 18 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 23 | struct arg { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 24 | char **argv; |
| 25 | const char *name; |
| 26 | const char *val; |
| 27 | unsigned int argv_step; |
| 28 | const struct arg_def *def; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 29 | }; |
| 30 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 31 | struct arg_enum_list { |
| 32 | const char *name; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 33 | int val; |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 34 | }; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 35 | #define ARG_ENUM_LIST_END \ |
| 36 | { 0 } |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 37 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 38 | typedef struct arg_def { |
| 39 | const char *short_name; |
| 40 | const char *long_name; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 41 | int has_val; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 42 | const char *desc; |
| 43 | const struct arg_enum_list *enums; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 44 | } arg_def_t; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 45 | #define ARG_DEF(s, l, v, d) \ |
| 46 | { s, l, v, d, NULL } |
| 47 | #define ARG_DEF_ENUM(s, l, v, d, e) \ |
| 48 | { s, l, v, d, e } |
| 49 | #define ARG_DEF_LIST_END \ |
| 50 | { 0 } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 51 | |
| 52 | struct arg arg_init(char **argv); |
| 53 | int arg_match(struct arg *arg_, const struct arg_def *def, char **argv); |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 54 | char *ignore_front_spaces(const char *str); |
| 55 | void ignore_end_spaces(char *str); |
Yaowu Xu | 4d5dbb1 | 2019-11-08 11:13:32 -0800 | [diff] [blame] | 56 | int parse_cfg(const char *file, cfg_options_t *config); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 57 | const char *arg_next(struct arg *arg); |
| 58 | void arg_show_usage(FILE *fp, const struct arg_def *const *defs); |
| 59 | char **argv_dup(int argc, const char **argv); |
| 60 | |
| 61 | unsigned int arg_parse_uint(const struct arg *arg); |
| 62 | int arg_parse_int(const struct arg *arg); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | struct aom_rational arg_parse_rational(const struct arg *arg); |
James Zern | 4e5a778 | 2014-10-11 11:27:23 +0200 | [diff] [blame] | 64 | int arg_parse_enum(const struct arg *arg); |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 65 | int arg_parse_enum_or_int(const struct arg *arg); |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 66 | int arg_parse_list(const struct arg *arg, int *list, int n); |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 67 | #ifdef __cplusplus |
| 68 | } // extern "C" |
| 69 | #endif |
| 70 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 71 | #endif // AOM_COMMON_ARGS_H_ |