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,15 +8,15 @@ cuebreakpoints \- print the breakpoints from a cue or toc file
. .
.SH SYNOPSIS .SH SYNOPSIS
.B cuebreakpoints .B cuebreakpoints
[\-h] [\-i cue|toc] [file...] [option...] [file...]
. .
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-h .B \-h, \--help
print usage information print usage information
. .
.TP .TP
.B \-i cue|toc .B \-i, \--input-format cue|toc
set format of file(s) set format of file(s)
. .
.SH NOTES .SH NOTES

View File

@@ -8,19 +8,19 @@ cueconvert \- convert between the cue and toc formats
. .
.SH SYNOPSIS .SH SYNOPSIS
.B cueconvert .B cueconvert
[\-h] [\-i cue|toc] [\-o cue|toc] [infile [outfile]] [option...] [infile [outfile]]
. .
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-h .B \-h, \--help
print usage information print usage information
. .
.TP .TP
.B \-i cue|toc .B \-i, \--input-format cue|toc
set format of input file set format of input file
. .
.TP .TP
.B \-o cue|toc .B \-o, \--output-format cue|toc
set format of output file set format of output file
. .
.SH NOTES .SH NOTES

View File

@@ -8,27 +8,27 @@ cueprint \- print disc and track infomation for a cue or toc file
. .
.SH SYNOPSIS .SH SYNOPSIS
.B cueprint .B cueprint
[\-h] [\-i cue|toc] [-n <tracknumber>] [\-d <template>] [\-t <template>] [file...] [option...] [file...]
. .
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-h .B \-h, \--help
print usage information print usage information
. .
.TP .TP
.B \-i cue|toc .B \-i, \--input-format cue|toc
set format of file(s) set format of file(s)
. .
.TP .TP
.B \-n <tracknumber> .B \-n, \--track-number <number>
only print track information for track tracknumber. The default is to print information for all tracks. only print track information for single track. The default is to print information for all tracks.
. .
.TP .TP
.B \-d <template> .B \-d, \--disc-template <template>
set disc template (see TEMPLATE EXPANSION) set disc template (see TEMPLATE EXPANSION)
. .
.TP .TP
.B \-t <template> .B \-t, \--track-template <template>
set track template (see TEMPLATE EXPANSION) set track template (see TEMPLATE EXPANSION)
. .
.SH TEMPLATE EXPANSION .SH TEMPLATE EXPANSION

View File

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

View File

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

View File

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