blob: 286f7dd1acd08e8267739027716723944dc7e748 [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 Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_COMMON_ARGS_H_
13#define AOM_COMMON_ARGS_H_
John Koleszar0ea50ce2010-05-18 11:58:33 -040014#include <stdio.h>
15
Ryan44276df2019-10-29 17:11:45 -070016#include "aom/aom_codec.h"
17#include "aom/aom_encoder.h"
18
James Zern25cfd8e2014-01-18 12:16:11 -080019#ifdef __cplusplus
20extern "C" {
21#endif
22
John Koleszarc6b90392012-07-13 15:21:29 -070023struct arg {
clang-format6c4d83e2016-08-08 19:03:30 -070024 char **argv;
25 const char *name;
26 const char *val;
27 unsigned int argv_step;
28 const struct arg_def *def;
John Koleszar0ea50ce2010-05-18 11:58:33 -040029};
30
John Koleszarc6b90392012-07-13 15:21:29 -070031struct arg_enum_list {
32 const char *name;
clang-format6c4d83e2016-08-08 19:03:30 -070033 int val;
John Koleszarb0da9b32010-12-17 09:43:39 -050034};
clang-format6c4d83e2016-08-08 19:03:30 -070035#define ARG_ENUM_LIST_END \
36 { 0 }
John Koleszarb0da9b32010-12-17 09:43:39 -050037
John Koleszarc6b90392012-07-13 15:21:29 -070038typedef struct arg_def {
39 const char *short_name;
40 const char *long_name;
clang-format6c4d83e2016-08-08 19:03:30 -070041 int has_val;
John Koleszarc6b90392012-07-13 15:21:29 -070042 const char *desc;
43 const struct arg_enum_list *enums;
John Koleszar0ea50ce2010-05-18 11:58:33 -040044} arg_def_t;
clang-format6c4d83e2016-08-08 19:03:30 -070045#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 Koleszar0ea50ce2010-05-18 11:58:33 -040051
52struct arg arg_init(char **argv);
53int arg_match(struct arg *arg_, const struct arg_def *def, char **argv);
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +010054char *ignore_front_spaces(const char *str);
55void ignore_end_spaces(char *str);
Yaowu Xu4d5dbb12019-11-08 11:13:32 -080056int parse_cfg(const char *file, cfg_options_t *config);
John Koleszar0ea50ce2010-05-18 11:58:33 -040057const char *arg_next(struct arg *arg);
58void arg_show_usage(FILE *fp, const struct arg_def *const *defs);
59char **argv_dup(int argc, const char **argv);
60
61unsigned int arg_parse_uint(const struct arg *arg);
62int arg_parse_int(const struct arg *arg);
Yaowu Xuf883b422016-08-30 14:01:10 -070063struct aom_rational arg_parse_rational(const struct arg *arg);
James Zern4e5a7782014-10-11 11:27:23 +020064int arg_parse_enum(const struct arg *arg);
John Koleszarb0da9b32010-12-17 09:43:39 -050065int arg_parse_enum_or_int(const struct arg *arg);
Dominic Symes26ad0b22017-10-01 16:35:13 +020066int arg_parse_list(const struct arg *arg, int *list, int n);
James Zern25cfd8e2014-01-18 12:16:11 -080067#ifdef __cplusplus
68} // extern "C"
69#endif
70
James Zerne1cbb132018-08-22 14:10:36 -070071#endif // AOM_COMMON_ARGS_H_