190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/*
2f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber *
4f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Use of this source code is governed by a BSD-style license
5f71323e297a928af368937089d3ed71239786f86Andreas Huber *  that can be found in the LICENSE file in the root of the source
6f71323e297a928af368937089d3ed71239786f86Andreas Huber *  tree. An additional intellectual property rights grant can be found
7f71323e297a928af368937089d3ed71239786f86Andreas Huber *  in the file PATENTS.  All contributing project authors may
8f71323e297a928af368937089d3ed71239786f86Andreas Huber *  be found in the AUTHORS file in the root of the source tree.
990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber */
1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
12b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifndef ARGS_H_
13b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#define ARGS_H_
1490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <stdio.h>
1590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
16b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifdef __cplusplus
17b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanianextern "C" {
18b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#endif
19b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
20ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangstruct arg {
21ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  char                 **argv;
22ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const char            *name;
23ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const char            *val;
24ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  unsigned int           argv_step;
25ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const struct arg_def  *def;
2690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber};
2790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
28ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangstruct arg_enum_list {
29ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const char *name;
30ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  int         val;
3179f15823c34ae1e423108295e416213200bb280fAndreas Huber};
3279f15823c34ae1e423108295e416213200bb280fAndreas Huber#define ARG_ENUM_LIST_END {0}
3379f15823c34ae1e423108295e416213200bb280fAndreas Huber
34ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangtypedef struct arg_def {
35ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const char *short_name;
36ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const char *long_name;
37ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  int         has_val;
38ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const char *desc;
39ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang  const struct arg_enum_list *enums;
4090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} arg_def_t;
4179f15823c34ae1e423108295e416213200bb280fAndreas Huber#define ARG_DEF(s,l,v,d) {s,l,v,d, NULL}
4279f15823c34ae1e423108295e416213200bb280fAndreas Huber#define ARG_DEF_ENUM(s,l,v,d,e) {s,l,v,d,e}
4390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define ARG_DEF_LIST_END {0}
4490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberstruct arg arg_init(char **argv);
4690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberint arg_match(struct arg *arg_, const struct arg_def *def, char **argv);
4790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberconst char *arg_next(struct arg *arg);
4890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubervoid arg_show_usage(FILE *fp, const struct arg_def *const *defs);
4990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberchar **argv_dup(int argc, const char **argv);
5090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberunsigned int arg_parse_uint(const struct arg *arg);
5290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberint arg_parse_int(const struct arg *arg);
5390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberstruct vpx_rational arg_parse_rational(const struct arg *arg);
5479f15823c34ae1e423108295e416213200bb280fAndreas Huberint arg_parse_enum_or_int(const struct arg *arg);
55b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifdef __cplusplus
56b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian}  // extern "C"
5790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
58b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
59b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#endif  // ARGS_H_
60