You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.6KB

  1. /*
  2. * Various utilities for command line tools
  3. * copyright (c) 2003 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef FFMPEG_CMDUTILS_H
  22. #define FFMPEG_CMDUTILS_H
  23. #include <inttypes.h>
  24. /**
  25. * Parses a string and returns its corresponding value as a double.
  26. * Exits from the application if the string cannot be correctly
  27. * parsed or the corresponding value is invalid.
  28. *
  29. * @param context the context of the value to be set (e.g. the
  30. * corresponding commandline option name)
  31. * @param numstr the string to be parsed
  32. * @param type the type (OPT_INT64 or OPT_FLOAT) as which the
  33. * string should be parsed
  34. * @param min the minimum valid accepted value
  35. * @param max the maximum valid accepted value
  36. */
  37. double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max);
  38. typedef struct {
  39. const char *name;
  40. int flags;
  41. #define HAS_ARG 0x0001
  42. #define OPT_BOOL 0x0002
  43. #define OPT_EXPERT 0x0004
  44. #define OPT_STRING 0x0008
  45. #define OPT_VIDEO 0x0010
  46. #define OPT_AUDIO 0x0020
  47. #define OPT_GRAB 0x0040
  48. #define OPT_INT 0x0080
  49. #define OPT_FLOAT 0x0100
  50. #define OPT_SUBTITLE 0x0200
  51. #define OPT_FUNC2 0x0400
  52. #define OPT_INT64 0x0800
  53. union {
  54. void (*func_arg)(const char *); //FIXME passing error code as int return would be nicer then exit() in the func
  55. int *int_arg;
  56. char **str_arg;
  57. float *float_arg;
  58. int (*func2_arg)(const char *, const char *);
  59. int64_t *int64_arg;
  60. } u;
  61. const char *help;
  62. const char *argname;
  63. } OptionDef;
  64. void show_help_options(const OptionDef *options, const char *msg, int mask, int value);
  65. /**
  66. * Parses the command line arguments.
  67. * @param options Array with the definitions required to interpret every
  68. * option of the form: -<option_name> [<argument>]
  69. * @param parse_arg_function Name of the function called to process every
  70. * argument without a leading option name flag. NULL if such arguments do
  71. * not have to be processed.
  72. */
  73. void parse_options(int argc, char **argv, const OptionDef *options,
  74. void (* parse_arg_function)(const char*));
  75. void print_error(const char *filename, int err);
  76. /**
  77. * Prints the program banner to stderr. The banner contents depend on the
  78. * current version of the repository and of the libav* libraries used by
  79. * the program.
  80. * @param program_name name of the program
  81. * @param program_birth_year year of birth of the program
  82. */
  83. void show_banner(const char *program_name, int program_birth_year);
  84. /**
  85. * Prints the version of the program to stdout. The version message
  86. * depends on the current versions of the repository and of the libav*
  87. * libraries.
  88. * @param program_name name of the program
  89. */
  90. void show_version(const char *program_name);
  91. /**
  92. * Prints the license of the program to stdout. The license depends on
  93. * the license of the libraries compiled into the program.
  94. */
  95. void show_license(void);
  96. #endif /* FFMPEG_CMDUTILS_H */