Imported cuebreakpoints fixes and improvements from Debian's patch.

This commit is contained in:
Svend Sorensen
2006-03-01 00:33:38 +00:00
parent 5757bdc0e4
commit 65c192e582

View File

@@ -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"
#include "time.h" #include "time.h"
@@ -21,7 +21,7 @@
char *progname; char *progname;
/* /*
* pregap correction modes * pregap correction modes:
* APPEND - append pregap to previous track (except for first track) * APPEND - append pregap to previous track (except for first track)
* PREPEND - prefix pregap to current track * PREPEND - prefix pregap to current track
* SPLIT - print breakpoints for beginning and end of pregap * SPLIT - print breakpoints for beginning and end of pregap
@@ -31,17 +31,14 @@ enum GapMode {APPEND, PREPEND, SPLIT};
void usage (int status) void usage (int status)
{ {
if (0 == status) { if (0 == status) {
fprintf(stdout, "%s: usage: cuebreakpoints [option...] [file...]\n", progname); printf("%s: usage: cuebreakpoints [option...] [file...]\n", progname);
fputs("\ printf("OPTIONS\n"
\n\ "-h, --help print usage\n"
OPTIONS\n\ "-i, --input-format cue|toc set format of file(s)\n"
-h, --help print usage\n\ "--append-gaps append pregaps to previous track (default)\n"
-i, --input-format cue|toc set format of file(s)\n\ "--prepend-gaps prefix pregaps to track\n"
--append-gaps append pregaps to previous track (default)\n\ "--split-gaps split at beginning and end of pregaps\n"
--prepend-gaps prefix pregaps to track\n\ "-V, --version print version information\n");
--split-gaps split at beginning and end of pregaps\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);
} }
@@ -91,7 +88,10 @@ void print_breaks (Cd *cd, int gaps)
if (gaps == PREPEND || gaps == SPLIT) { if (gaps == PREPEND || gaps == SPLIT) {
print_breakpoint(b); print_breakpoint(b);
/* there is no previous track to append the first tracks pregap to */ /*
* There is no previous track to append the first track's
* pregap to.
*/
} else if (gaps == APPEND && 1 < i) { } else if (gaps == APPEND && 1 < i) {
print_breakpoint(b + pg); print_breakpoint(b + pg);
} }
@@ -108,7 +108,8 @@ int breaks (char *name, int format, int gaps)
Cd *cd = NULL; Cd *cd = NULL;
if (NULL == (cd = cf_parse(name, &format))) { if (NULL == (cd = cf_parse(name, &format))) {
fprintf(stderr, "%s: input file error\n", name); fprintf(stderr, "%s: error: unable to parse input file "
"`%s'\n", progname, name);
return -1; return -1;
} }
@@ -121,6 +122,7 @@ int main (int argc, char **argv)
{ {
int format = UNKNOWN; int format = UNKNOWN;
int gaps = APPEND; int gaps = APPEND;
int ret = 0; /* return value of breaks() */
/* option variables */ /* option variables */
int c; int c;
@@ -138,7 +140,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:V", longopts, NULL))) { while (-1 != (c = getopt_long(argc, argv, "hi:V", longopts, NULL))) {
switch (c) { switch (c) {
@@ -151,7 +153,8 @@ int main (int argc, char **argv)
} else if (0 == strcmp("toc", optarg)) { } else if (0 == strcmp("toc", optarg)) {
format = TOC; format = 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;
@@ -173,13 +176,20 @@ int main (int argc, char **argv)
} }
} }
/* What we do depends on the number of operands. */
if (optind == argc) { if (optind == argc) {
breaks("-", format, gaps); /* No operands: report breakpoints of stdin. */
ret = breaks("-", format, gaps);
} else { } else {
/* Report track breakpoints for each operand. */
for (; optind < argc; optind++) { for (; optind < argc; optind++) {
breaks(argv[optind], format, gaps); ret = breaks(argv[optind], format, gaps);
/* Exit if breaks returns an error. */
if (!ret) {
break;
}
} }
} }
return 0; return ret;
} }