tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

args_helper.h (2558B)


      1 /*
      2 * Copyright (c) 2020, Alliance for Open Media. All rights reserved.
      3 *
      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.
     10 */
     11 
     12 #ifndef AOM_COMMON_ARGS_HELPER_H_
     13 #define AOM_COMMON_ARGS_HELPER_H_
     14 
     15 #include "aom/aom_encoder.h"
     16 
     17 #ifdef __cplusplus
     18 extern "C" {
     19 #endif
     20 
     21 // Maximum length of the error messages for the helper functions.
     22 #define ARG_ERR_MSG_MAX_LEN 200
     23 
     24 struct arg {
     25  char **argv;
     26  const char *name;
     27  const char *val;
     28  unsigned int argv_step;
     29  const struct arg_def *def;
     30 };
     31 
     32 struct arg_enum_list {
     33  const char *name;
     34  int val;
     35 };
     36 #define ARG_ENUM_LIST_END { 0 }
     37 
     38 typedef struct arg_def {
     39  const char *short_name;
     40  const char *long_name;
     41  int has_val;  //  0: The argument must not have a value.
     42                //  1: The argument must have a value.
     43                // -1: The argument may or may not have a value.
     44  const char *desc;
     45  const struct arg_enum_list *enums;
     46 } arg_def_t;
     47 #define ARG_DEF(s, l, v, d) { s, l, v, d, NULL }
     48 #define ARG_DEF_ENUM(s, l, v, d, e) { s, l, v, d, e }
     49 #define ARG_DEF_LIST_END { 0 }
     50 
     51 /*
     52 * The helper functions below all take an optional parameter err_msg for
     53 * error reporting. When err_msg is not NULL (must point to a buffer
     54 * which is at least ARG_ERR_MSG_MAX_LEN bytes long), a related error message is
     55 * stored in it if an error occurs. It will be set to an empty string if no
     56 * error occurs.
     57 */
     58 int arg_match_helper(struct arg *arg_, const struct arg_def *def, char **argv,
     59                     char *err_msg);
     60 
     61 // Note: arg_match_helper() must be called before invoking these functions.
     62 unsigned int arg_parse_uint_helper(const struct arg *arg, char *err_msg);
     63 int arg_parse_int_helper(const struct arg *arg, char *err_msg);
     64 struct aom_rational arg_parse_rational_helper(const struct arg *arg,
     65                                              char *err_msg);
     66 int arg_parse_enum_helper(const struct arg *arg, char *err_msg);
     67 int arg_parse_enum_or_int_helper(const struct arg *arg, char *err_msg);
     68 int arg_parse_list_helper(const struct arg *arg, int *list, int n,
     69                          char *err_msg);
     70 
     71 #ifdef __cplusplus
     72 }  // extern "C"
     73 #endif
     74 
     75 #endif  // AOM_COMMON_ARGS_HELPER_H_