00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define HAVE_AV_CONFIG_H
00020 #include "avformat.h"
00021 #include "common.h"
00022
00023 #include "cmdutils.h"
00024
00025 void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
00026 {
00027 const OptionDef *po;
00028 int first;
00029
00030 first = 1;
00031 for(po = options; po->name != NULL; po++) {
00032 char buf[64];
00033 if ((po->flags & mask) == value) {
00034 if (first) {
00035 printf("%s", msg);
00036 first = 0;
00037 }
00038 pstrcpy(buf, sizeof(buf), po->name);
00039 if (po->flags & HAS_ARG) {
00040 pstrcat(buf, sizeof(buf), " ");
00041 pstrcat(buf, sizeof(buf), po->argname);
00042 }
00043 printf("-%-17s %s\n", buf, po->help);
00044 }
00045 }
00046 }
00047
00048 void parse_options(int argc, char **argv, const OptionDef *options)
00049 {
00050 const char *opt, *arg;
00051 int optindex;
00052 const OptionDef *po;
00053
00054
00055 optindex = 1;
00056 while (optindex < argc) {
00057 opt = argv[optindex++];
00058
00059 if (opt[0] == '-' && opt[1] != '\0') {
00060 po = options;
00061 while (po->name != NULL) {
00062 if (!strcmp(opt + 1, po->name))
00063 break;
00064 po++;
00065 }
00066 if (!po->name) {
00067 fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
00068 exit(1);
00069 }
00070 arg = NULL;
00071 if (po->flags & HAS_ARG) {
00072 arg = argv[optindex++];
00073 if (!arg) {
00074 fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
00075 exit(1);
00076 }
00077 }
00078 if (po->flags & OPT_STRING) {
00079 char *str;
00080 str = av_strdup(arg);
00081 *po->u.str_arg = str;
00082 } else if (po->flags & OPT_BOOL) {
00083 *po->u.int_arg = 1;
00084 } else if (po->flags & OPT_INT) {
00085 *po->u.int_arg = atoi(arg);
00086 } else if (po->flags & OPT_FLOAT) {
00087 *po->u.float_arg = atof(arg);
00088 } else {
00089 po->u.func_arg(arg);
00090 }
00091 } else {
00092 parse_arg_file(opt);
00093 }
00094 }
00095 }
00096
00097 void print_error(const char *filename, int err)
00098 {
00099 switch(err) {
00100 case AVERROR_NUMEXPECTED:
00101 fprintf(stderr, "%s: Incorrect image filename syntax.\n"
00102 "Use '%%d' to specify the image number:\n"
00103 " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
00104 " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
00105 filename);
00106 break;
00107 case AVERROR_INVALIDDATA:
00108 fprintf(stderr, "%s: Error while parsing header\n", filename);
00109 break;
00110 case AVERROR_NOFMT:
00111 fprintf(stderr, "%s: Unknown format\n", filename);
00112 break;
00113 case AVERROR_IO:
00114 fprintf(stderr, "%s: I/O error occured\n"
00115 "Usually that means that input file is truncated and/or corrupted.\n",
00116 filename);
00117 break;
00118 case AVERROR_NOMEM:
00119 fprintf(stderr, "%s: memory allocation error occured\n", filename);
00120 break;
00121 default:
00122 fprintf(stderr, "%s: Error while opening file\n", filename);
00123 break;
00124 }
00125 }