blob: c3427bcfa39acfeae40de3d11643c903aa9b9055 [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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 Koleszar0ea50ce2010-05-18 11:58:33 -040010 */
11
James Zern0f512782013-12-15 18:40:23 -080012#ifndef ARGS_H_
13#define ARGS_H_
John Koleszar0ea50ce2010-05-18 11:58:33 -040014#include <stdio.h>
15
James Zern25cfd8e2014-01-18 12:16:11 -080016#ifdef __cplusplus
17extern "C" {
18#endif
19
John Koleszarc6b90392012-07-13 15:21:29 -070020struct arg {
clang-format6c4d83e2016-08-08 19:03:30 -070021 char **argv;
22 const char *name;
23 const char *val;
24 unsigned int argv_step;
25 const struct arg_def *def;
John Koleszar0ea50ce2010-05-18 11:58:33 -040026};
27
John Koleszarc6b90392012-07-13 15:21:29 -070028struct arg_enum_list {
29 const char *name;
clang-format6c4d83e2016-08-08 19:03:30 -070030 int val;
John Koleszarb0da9b32010-12-17 09:43:39 -050031};
clang-format6c4d83e2016-08-08 19:03:30 -070032#define ARG_ENUM_LIST_END \
33 { 0 }
John Koleszarb0da9b32010-12-17 09:43:39 -050034
John Koleszarc6b90392012-07-13 15:21:29 -070035typedef struct arg_def {
36 const char *short_name;
37 const char *long_name;
clang-format6c4d83e2016-08-08 19:03:30 -070038 int has_val;
John Koleszarc6b90392012-07-13 15:21:29 -070039 const char *desc;
40 const struct arg_enum_list *enums;
John Koleszar0ea50ce2010-05-18 11:58:33 -040041} arg_def_t;
clang-format6c4d83e2016-08-08 19:03:30 -070042#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 Koleszar0ea50ce2010-05-18 11:58:33 -040048
49struct arg arg_init(char **argv);
50int arg_match(struct arg *arg_, const struct arg_def *def, char **argv);
51const char *arg_next(struct arg *arg);
52void arg_show_usage(FILE *fp, const struct arg_def *const *defs);
53char **argv_dup(int argc, const char **argv);
54
55unsigned int arg_parse_uint(const struct arg *arg);
56int arg_parse_int(const struct arg *arg);
Yaowu Xuf883b422016-08-30 14:01:10 -070057struct aom_rational arg_parse_rational(const struct arg *arg);
James Zern4e5a7782014-10-11 11:27:23 +020058int arg_parse_enum(const struct arg *arg);
John Koleszarb0da9b32010-12-17 09:43:39 -050059int arg_parse_enum_or_int(const struct arg *arg);
Dominic Symes26ad0b22017-10-01 16:35:13 +020060int arg_parse_list(const struct arg *arg, int *list, int n);
James Zern25cfd8e2014-01-18 12:16:11 -080061#ifdef __cplusplus
62} // extern "C"
63#endif
64
James Zern0f512782013-12-15 18:40:23 -080065#endif // ARGS_H_