--- uuid_cli.c 2004/01/06 20:29:51 1.2
+++ uuid_cli.c 2004/01/08 21:31:47 1.3
@@ -52,9 +52,18 @@
/* usage handler */
static void
-usage(void)
+usage(const char *str, ...)
{
+ va_list ap;
+
+ va_start(ap, str);
+ if (str != NULL) {
+ fprintf(stderr, "uuid:ERROR: ");
+ vfprintf(stderr, str, ap);
+ fprintf(stderr, "\n");
+ }
fprintf(stderr, "usage: uuid [-1] [-n count] [-a] [-d] [-o filename] [UUID]\n");
+ va_end(ap);
exit(1);
}
@@ -73,6 +82,7 @@
int decode;
char *cp;
void *vp;
+ unsigned int version;
/* command line parsing */
count = -1; /* no count yet */
@@ -80,17 +90,18 @@
iterate = 0; /* not one at a time */
ascii = 0; /* default is binary output */
decode = 0; /* default is to encode */
- while ((ch = getopt(argc, argv, "1n:ado:")) != -1) {
+ version = UUID_VERSION1;
+ while ((ch = getopt(argc, argv, "1n:ado:v:")) != -1) {
switch (ch) {
case '1':
iterate = 1;
break;
case 'n':
if (count > 0)
- usage();
+ usage("option 'n' specified multiple times");
count = strtol(optarg, &p, 10);
- if (*p != 0 || count < 1)
- usage();
+ if (*p != '\0' || count < 1)
+ usage("invalid argument to option 'n'");
break;
case 'a':
ascii = 1;
@@ -104,8 +115,21 @@
if ((fp = fopen(optarg, "w")) == NULL)
error(1, "fopen: %s", strerror(errno));
break;
+ case 'v':
+ i = strtol(optarg, &p, 10);
+ if (*p != '\0')
+ usage("invalid argument to option 'v'");
+ switch (i) {
+ case 1: version = UUID_VERSION1; break;;
+ case 3: version = UUID_VERSION3; break;;
+ case 4: version = UUID_VERSION4; break;;
+ default:
+ usage("invalid version on option 'v'");
+ break;
+ }
+ break;
default:
- usage();
+ usage("invalid option '%c'", ch);
}
}
argv += optind;
@@ -116,13 +140,13 @@
if (decode) {
/* decoding */
if (argc != 1)
- usage();
+ usage("invalid number of arguments");
/* FIXME */
}
else {
/* encoding */
- if (argc < 0 || argc > 1)
- usage();
+ if (argc < 0 || ((version == UUID_VERSION3 && argc > 2) || argc > 1))
+ usage("invalid number of arguments");
if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
error(1, "uuid_create: %s", uuid_error(rc));
if (argc == 1) {
@@ -135,7 +159,11 @@
if ((rc = uuid_null(uuid)) != UUID_RC_OK)
error(1, "uuid_null: %s", uuid_error(rc));
}
- if ((rc = uuid_generate(uuid)) != UUID_RC_OK)
+ if (version == UUID_VERSION3)
+ rc = uuid_generate(uuid, version, argv[0]);
+ else
+ rc = uuid_generate(uuid, version);
+ if (rc != UUID_RC_OK)
error(1, "uuid_generate: %s", uuid_error(rc));
if (ascii) {
cp = NULL;
|