args.h 1.87 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar's avatar
John Koleszar committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
John Koleszar's avatar
John Koleszar committed
10 11
 */

12 13
#ifndef ARGS_H_
#define ARGS_H_
John Koleszar's avatar
John Koleszar committed
14 15
#include <stdio.h>

16 17 18 19
#ifdef __cplusplus
extern "C" {
#endif

John Koleszar's avatar
John Koleszar committed
20
struct arg {
clang-format's avatar
clang-format committed
21 22 23 24 25
  char **argv;
  const char *name;
  const char *val;
  unsigned int argv_step;
  const struct arg_def *def;
John Koleszar's avatar
John Koleszar committed
26 27
};

John Koleszar's avatar
John Koleszar committed
28 29
struct arg_enum_list {
  const char *name;
clang-format's avatar
clang-format committed
30
  int val;
John Koleszar's avatar
John Koleszar committed
31
};
clang-format's avatar
clang-format committed
32 33
#define ARG_ENUM_LIST_END \
  { 0 }
John Koleszar's avatar
John Koleszar committed
34

John Koleszar's avatar
John Koleszar committed
35 36 37
typedef struct arg_def {
  const char *short_name;
  const char *long_name;
clang-format's avatar
clang-format committed
38
  int has_val;
John Koleszar's avatar
John Koleszar committed
39 40
  const char *desc;
  const struct arg_enum_list *enums;
John Koleszar's avatar
John Koleszar committed
41
} arg_def_t;
clang-format's avatar
clang-format committed
42 43 44 45 46 47
#define ARG_DEF(s, l, v, d) \
  { s, l, v, d, NULL }
#define ARG_DEF_ENUM(s, l, v, d, e) \
  { s, l, v, d, e }
#define ARG_DEF_LIST_END \
  { 0 }
John Koleszar's avatar
John Koleszar committed
48 49 50

struct arg arg_init(char **argv);
int arg_match(struct arg *arg_, const struct arg_def *def, char **argv);
51 52 53
char *ignore_front_spaces(const char *str);
void ignore_end_spaces(char *str);
int arg_cfg(int *argc, char ***argv, const char *file);
John Koleszar's avatar
John Koleszar committed
54 55 56 57 58 59
const char *arg_next(struct arg *arg);
void arg_show_usage(FILE *fp, const struct arg_def *const *defs);
char **argv_dup(int argc, const char **argv);

unsigned int arg_parse_uint(const struct arg *arg);
int arg_parse_int(const struct arg *arg);
60
struct aom_rational arg_parse_rational(const struct arg *arg);
61
int arg_parse_enum(const struct arg *arg);
John Koleszar's avatar
John Koleszar committed
62
int arg_parse_enum_or_int(const struct arg *arg);
63
int arg_parse_list(const struct arg *arg, int *list, int n);
64 65 66 67
#ifdef __cplusplus
}  // extern "C"
#endif

68
#endif  // ARGS_H_