Added long options to all tools.

Tools exit if format is not "cue" or "toc".
This commit is contained in:
Svend Sorensen
2005-02-08 08:23:25 +00:00
parent 45012c8e5e
commit 4aa5950850
6 changed files with 73 additions and 42 deletions

View File

@@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include "cuefile.h"
#include "time.h"
@@ -17,16 +17,15 @@ char *progname;
void usage (int status)
{
if (0 == status) {
fprintf(stdout, "%s: usage: cuebreakpoints [-h] [-i cue|toc] [file...]\n", progname);
fprintf(stdout, "%s: usage: cuebreakpoints [option...] [file...]\n", progname);
fputs("\
\n\
OPTIONS\n\
-h print usage\n\
-i cue|toc set format of file(s)\n\
-h, --help print usage\n\
-i, --input-format cue|toc set format of file(s)\n\
", stdout);
} else {
fprintf(stderr, "%s: syntax error\n", progname);
fprintf(stderr, "run `%s -h' for usage\n", progname);
fprintf(stderr, "run `%s --help' for usage\n", progname);
}
exit (status);
@@ -75,13 +74,19 @@ int main (int argc, char **argv)
/* option variables */
char c;
/* getopt() variables */
/* getopt_long() variables */
extern char *optarg;
extern int optind;
static struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
{"input-format", required_argument, NULL, 'i'},
{NULL, 0, NULL, 0}
};
progname = *argv;
while (-1 != (c = getopt(argc, argv, "hi:"))) {
while (-1 != (c = getopt_long(argc, argv, "hi:", longopts, NULL))) {
switch (c) {
case 'h':
usage(0);
@@ -91,6 +96,9 @@ int main (int argc, char **argv)
format = CUE;
else if (0 == strcmp("toc", optarg))
format = TOC;
else
fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
usage(1);
break;
default:
usage(1);

View File

@@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include "cuefile.h"
char *progname;
@@ -16,17 +16,16 @@ char *progname;
void usage (int status)
{
if (0 == status) {
fprintf(stdout, "%s: usage: cueconvert [-h] [-i cue|toc] [-o cue|toc] [infile [outfile]]\n", progname);
fprintf(stdout, "%s: usage: cueconvert [option...] [infile [outfile]]\n", progname);
fputs("\
\n\
OPTIONS\n\
-h print usage\n\
-i cue|toc set format of input file\n\
-o cue|toc set format of output file\n\
-h, --help print usage\n\
-i, --input-format cue|toc set format of input file\n\
-o, --output-format cue|toc set format of output file\n\
", stdout);
} else {
fprintf(stderr, "%s: syntax error\n", progname);
fprintf(stderr, "run `%s -h' for usage\n", progname);
fprintf(stderr, "run `%s --help' for usage\n", progname);
}
exit (status);
@@ -65,13 +64,20 @@ int main (int argc, char **argv)
int oformat = UNKNOWN;
/* option variables */
char c;
/* getopt() variables */
/* getopt_long() variables */
extern char *optarg;
extern int optind;
static struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
{"input-format", required_argument, NULL, 'i'},
{"output-format", required_argument, NULL, 'o'},
{NULL, 0, NULL, 0}
};
progname = *argv;
while (-1 != (c = getopt(argc, argv, "hi:o:"))) {
while (-1 != (c = getopt_long(argc, argv, "hi:o:", longopts, NULL))) {
switch (c) {
case 'h':
usage(0);
@@ -81,12 +87,18 @@ int main (int argc, char **argv)
iformat = CUE;
else if (0 == strcmp("toc", optarg))
iformat = TOC;
else
fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
usage(1);
break;
case 'o':
if (0 == strcmp("cue", optarg))
oformat = CUE;
else if (0 == strcmp("toc", optarg))
oformat = TOC;
else
fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
usage(1);
break;
default:
usage(1);

View File

@@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h> /* exit() */
#include <string.h> /* strcmp() */
#include <unistd.h> /* getopt() */
#include <getopt.h>
#include <ctype.h> /* isdigit() */
#include "cuefile.h"
@@ -58,15 +58,15 @@ char *progname;
void usage (int status)
{
if (0 == status) {
fprintf(stdout, "%s: usage: cueprint [-h] [-i cue|toc] [-n <tracknumer>] [-d <template>] [-t <template>] [file...]\n", progname);
fprintf(stdout, "%s: usage: cueprint [option...] [file...]\n", progname);
fputs("\
\n\
OPTIONS\n\
-h print usage\n\
-i cue|toc set format of file(s)\n\
-n <tracknumber> only print track information for track tracknumer\n\
-d <template> set disc template (see TEMPLATE EXPANSION)\n\
-t <template> set track template (see TEMPLATE EXPANSION)\n\
-h, --help print usage\n\
-i, --input-format cue|toc set format of file(s)\n\
-n, --track-number <number> only print track information for single track\n\
-d, --disc-template <template> set disc template (see TEMPLATE EXPANSION)\n\
-t, --track-template <template> set track template (see TEMPLATE EXPANSION)\n\
\n\
Template Expansion\n\
Disc:\n\
@@ -97,8 +97,7 @@ Any other %<character> is expanded to that character. For example, to get a\n\
fprintf(stdout, "default disc template is:\n%s\n", D_TEMPLATE);
fprintf(stdout, "default track template is:\n%s\n", T_TEMPLATE);
} else {
fprintf(stderr, "%s: syntax error\n", progname);
fprintf(stderr, "run `%s -h' for usage\n", progname);
fprintf(stderr, "run `%s --help' for usage\n", progname);
}
exit (status);
@@ -424,14 +423,23 @@ int main (int argc, char **argv)
int trackno = -1; /* track number (-1 = unspecified, 0 = disc info) */
char *d_template = NULL; /* disc template */
char *t_template = NULL; /* track template */
/* getopt () variables */
/* getopt_long() variables */
char c;
extern char *optarg;
extern int optind;
static struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
{"input-format", required_argument, NULL, 'i'},
{"track-number", required_argument, NULL, 'n'},
{"disc-template", required_argument, NULL, 'd'},
{"track-template", required_argument, NULL, 't'},
{NULL, 0, NULL, 0}
};
progname = *argv;
while (-1 != (c = getopt(argc, argv, "hi:n:d:t:"))) {
while (-1 != (c = getopt_long(argc, argv, "hi:n:d:t:", longopts, NULL))) {
switch (c) {
case 'h':
usage(0);
@@ -441,6 +449,9 @@ int main (int argc, char **argv)
format = CUE;
else if (0 == strcmp("toc", optarg))
format = TOC;
else
fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
usage(1);
break;
case 'n':
trackno = atoi(optarg);