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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 void show_help_options(const OptionDef
*options
)
33 printf("Main options are:\n");
36 for(po
= options
; po
->name
!= NULL
; po
++) {
38 expert
= (po
->flags
& OPT_EXPERT
) != 0;
40 if (expert
&& first
) {
41 printf("\nAdvanced options are:\n");
44 strcpy(buf
, po
->name
);
45 if (po
->flags
& HAS_ARG
) {
47 strcat(buf
, po
->argname
);
49 printf("-%-17s %s\n", buf
, po
->help
);
55 void parse_options(int argc
, char **argv
, const OptionDef
*options
)
57 const char *opt
, *arg
;
63 while (optindex
< argc
) {
64 opt
= argv
[optindex
++];
66 if (opt
[0] == '-' && opt
[1] != '\0') {
68 while (po
->name
!= NULL
) {
69 if (!strcmp(opt
+ 1, po
->name
))
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
) {
100 void print_error(const char *filename
, int err
)
103 case AVERROR_NUMEXPECTED
:
104 fprintf(stderr
, "%s: Incorrect image filename syntax.\n"
105 "Use '%%d' to specify the image number:\n"
106 " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
107 " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
110 case AVERROR_INVALIDDATA
:
111 fprintf(stderr
, "%s: Error while parsing header\n", filename
);
114 fprintf(stderr
, "%s: Unknown format\n", filename
);
117 fprintf(stderr
, "%s: Error while opening file\n", filename
);