args_helper.h 2.5 KB

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