2 * Various utilities for command line tools
3 * Copyright (c) 2000-2003 Fabrice Bellard
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #define HAVE_AV_CONFIG_H
25 void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
31 for(po = options; po->name != NULL; po++) {
33 if ((po->flags & mask) == value) {
38 pstrcpy(buf, sizeof(buf), po->name);
39 if (po->flags & HAS_ARG) {
40 pstrcat(buf, sizeof(buf), " ");
41 pstrcat(buf, sizeof(buf), po->argname);
43 printf("-%-17s %s\n", buf, po->help);
48 static const OptionDef* find_option(const OptionDef *po, const char *name){
49 while (po->name != NULL) {
50 if (!strcmp(name, po->name))
57 void parse_options(int argc, char **argv, const OptionDef *options)
59 const char *opt, *arg;
65 while (optindex < argc) {
66 opt = argv[optindex++];
68 if (opt[0] == '-' && opt[1] != '\0') {
69 po= find_option(options, opt + 1);
71 po= find_option(options, "default");
74 fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
78 if (po->flags & HAS_ARG) {
79 arg = argv[optindex++];
81 fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
85 if (po->flags & OPT_STRING) {
89 } else if (po->flags & OPT_BOOL) {
91 } else if (po->flags & OPT_INT) {
92 *po->u.int_arg = atoi(arg);
93 } else if (po->flags & OPT_FLOAT) {
94 *po->u.float_arg = atof(arg);
95 } else if (po->flags & OPT_FUNC2) {
96 if(po->u.func2_arg(opt+1, arg)<0)
107 void print_error(const char *filename, int err)
110 case AVERROR_NUMEXPECTED:
111 fprintf(stderr, "%s: Incorrect image filename syntax.\n"
112 "Use '%%d' to specify the image number:\n"
113 " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
114 " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
117 case AVERROR_INVALIDDATA:
118 fprintf(stderr, "%s: Error while parsing header\n", filename);
121 fprintf(stderr, "%s: Unknown format\n", filename);
124 fprintf(stderr, "%s: I/O error occured\n"
125 "Usually that means that input file is truncated and/or corrupted.\n",
129 fprintf(stderr, "%s: memory allocation error occured\n", filename);
132 fprintf(stderr, "%s: Error while opening file\n", filename);