Imported cueconvert fixes and improvements from Debian's patch.
This commit is contained in:
@@ -5,10 +5,10 @@
|
|||||||
* For license terms, see the file COPYING in this distribution.
|
* For license terms, see the file COPYING in this distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <getopt.h> /* getopt_long() */
|
||||||
#include <stdlib.h>
|
#include <stdio.h> /* fprintf(), printf(), snprintf(), stderr */
|
||||||
#include <string.h>
|
#include <stdlib.h> /* exit() */
|
||||||
#include <getopt.h>
|
#include <string.h> /* strcasecmp() */
|
||||||
#include "cuefile.h"
|
#include "cuefile.h"
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
@@ -22,15 +22,12 @@ char *progname;
|
|||||||
void usage (int status)
|
void usage (int status)
|
||||||
{
|
{
|
||||||
if (0 == status) {
|
if (0 == status) {
|
||||||
fprintf(stdout, "%s: usage: cueconvert [option...] [infile [outfile]]\n", progname);
|
printf("%s: usage: cueconvert [option...] [infile [outfile]]\n", progname);
|
||||||
fputs("\
|
printf("OPTIONS\n"
|
||||||
\n\
|
"-h, --help print usage\n"
|
||||||
OPTIONS\n\
|
"-i, --input-format cue|toc set format of input file\n"
|
||||||
-h, --help print usage\n\
|
"-o, --output-format cue|toc set format of output file\n"
|
||||||
-i, --input-format cue|toc set format of input file\n\
|
"-V, --version print version information\n");
|
||||||
-o, --output-format cue|toc set format of output file\n\
|
|
||||||
-V, --version print version information\n\
|
|
||||||
", stdout);
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "run `%s --help' for usage\n", progname);
|
fprintf(stderr, "run `%s --help' for usage\n", progname);
|
||||||
}
|
}
|
||||||
@@ -50,7 +47,8 @@ int convert (char *iname, int iformat, char *oname, int oformat)
|
|||||||
Cd *cd = NULL;
|
Cd *cd = NULL;
|
||||||
|
|
||||||
if (NULL == (cd = cf_parse(iname, &iformat))) {
|
if (NULL == (cd = cf_parse(iname, &iformat))) {
|
||||||
fprintf(stderr, "input file error\n");
|
fprintf(stderr, "%s: error: unable to parse input file "
|
||||||
|
"`%s'\n", progname, iname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +74,8 @@ int main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int iformat = UNKNOWN;
|
int iformat = UNKNOWN;
|
||||||
int oformat = UNKNOWN;
|
int oformat = UNKNOWN;
|
||||||
|
int ret = 0; /* return value of convert() */
|
||||||
|
|
||||||
/* option variables */
|
/* option variables */
|
||||||
int c;
|
int c;
|
||||||
/* getopt_long() variables */
|
/* getopt_long() variables */
|
||||||
@@ -90,7 +90,7 @@ int main (int argc, char **argv)
|
|||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
progname = *argv;
|
progname = argv[0];
|
||||||
|
|
||||||
while (-1 != (c = getopt_long(argc, argv, "hi:o:V", longopts, NULL))) {
|
while (-1 != (c = getopt_long(argc, argv, "hi:o:V", longopts, NULL))) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -103,7 +103,8 @@ int main (int argc, char **argv)
|
|||||||
} else if (0 == strcmp("toc", optarg)) {
|
} else if (0 == strcmp("toc", optarg)) {
|
||||||
iformat = TOC;
|
iformat = TOC;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
|
fprintf(stderr, "%s: error: unknown input file "
|
||||||
|
"format `%s'\n", progname, optarg);
|
||||||
usage(1);
|
usage(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -113,7 +114,8 @@ int main (int argc, char **argv)
|
|||||||
} else if (0 == strcmp("toc", optarg)) {
|
} else if (0 == strcmp("toc", optarg)) {
|
||||||
oformat = TOC;
|
oformat = TOC;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
|
fprintf(stderr, "%s: error: unknown input file "
|
||||||
|
"format `%s'\n", progname, optarg);
|
||||||
usage(1);
|
usage(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -126,15 +128,19 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* What we do depends on the number of operands. */
|
||||||
if (optind == argc) {
|
if (optind == argc) {
|
||||||
convert("-", iformat, "-", oformat);
|
/* No operands: report breakpoints of stdin. */
|
||||||
|
ret = convert("-", iformat, "-", oformat);
|
||||||
} else if (optind == argc - 1) {
|
} else if (optind == argc - 1) {
|
||||||
convert(argv[optind], iformat, "-", oformat);
|
/* One operand: convert operand file to stdout. */
|
||||||
|
ret = convert(argv[optind], iformat, "-", oformat);
|
||||||
} else if (optind == argc - 2) {
|
} else if (optind == argc - 2) {
|
||||||
convert(argv[optind], iformat, argv[optind + 1], oformat);
|
/* Two operands: convert input file to output file. */
|
||||||
|
ret = convert(argv[optind], iformat, argv[optind + 1], oformat);
|
||||||
} else {
|
} else {
|
||||||
usage(1);
|
usage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user