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 | 0f51278 | 2013-12-15 18:40:23 -0800 | [diff] [blame] | 12 | #ifndef ARGS_H_ |
| 13 | #define ARGS_H_ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 20 | struct arg { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 21 | char **argv; |
| 22 | const char *name; |
| 23 | const char *val; |
| 24 | unsigned int argv_step; |
| 25 | const struct arg_def *def; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 26 | }; |
| 27 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 28 | struct arg_enum_list { |
| 29 | const char *name; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 30 | int val; |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 31 | }; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 32 | #define ARG_ENUM_LIST_END \ |
| 33 | { 0 } |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 34 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 35 | typedef struct arg_def { |
| 36 | const char *short_name; |
| 37 | const char *long_name; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 38 | int has_val; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 39 | const char *desc; |
| 40 | const struct arg_enum_list *enums; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 41 | } arg_def_t; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 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 } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 48 | |
| 49 | struct arg arg_init(char **argv); |
| 50 | int arg_match(struct arg *arg_, const struct arg_def *def, char **argv); |
| 51 | const char *arg_next(struct arg *arg); |
| 52 | void arg_show_usage(FILE *fp, const struct arg_def *const *defs); |
| 53 | char **argv_dup(int argc, const char **argv); |
| 54 | |
| 55 | unsigned int arg_parse_uint(const struct arg *arg); |
| 56 | int arg_parse_int(const struct arg *arg); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 57 | struct aom_rational arg_parse_rational(const struct arg *arg); |
James Zern | 4e5a778 | 2014-10-11 11:27:23 +0200 | [diff] [blame] | 58 | int arg_parse_enum(const struct arg *arg); |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 59 | int arg_parse_enum_or_int(const struct arg *arg); |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 60 | int arg_parse_list(const struct arg *arg, int *list, int n); |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 61 | #ifdef __cplusplus |
| 62 | } // extern "C" |
| 63 | #endif |
| 64 | |
James Zern | 0f51278 | 2013-12-15 18:40:23 -0800 | [diff] [blame] | 65 | #endif // ARGS_H_ |