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);