1/*
2 * gen_uuid.c --- generate a DCE-compatible uuid
3 *
4 * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
5 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
10 */
11
12#include <stdio.h>
13#ifdef HAVE_STDLIB_H
14#include <stdlib.h>
15#endif
16#ifdef HAVE_GETOPT_H
17#include <getopt.h>
18#else
19extern int getopt(int argc, char * const argv[], const char *optstring);
20extern char *optarg;
21extern int optind;
22#endif
23#include "uuid/uuid.h"
24#include "nls-enable.h"
25
26#define DO_TYPE_TIME	1
27#define DO_TYPE_RANDOM	2
28
29static void usage(const char *progname)
30{
31	fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
32	exit(1);
33}
34
35int
36main (int argc, char *argv[])
37{
38	int    c;
39	int    do_type = 0;
40	char   str[37];
41	uuid_t uu;
42
43#ifdef ENABLE_NLS
44	setlocale(LC_MESSAGES, "");
45	setlocale(LC_CTYPE, "");
46	bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
47	textdomain(NLS_CAT_NAME);
48#endif
49
50	while ((c = getopt (argc, argv, "tr")) != EOF)
51		switch (c) {
52		case 't':
53			do_type = DO_TYPE_TIME;
54			break;
55		case 'r':
56			do_type = DO_TYPE_RANDOM;
57			break;
58		default:
59			usage(argv[0]);
60		}
61
62	switch (do_type) {
63	case DO_TYPE_TIME:
64		uuid_generate_time(uu);
65		break;
66	case DO_TYPE_RANDOM:
67		uuid_generate_random(uu);
68		break;
69	default:
70		uuid_generate(uu);
71		break;
72	}
73
74	uuid_unparse(uu, str);
75
76	printf("%s\n", str);
77
78	return 0;
79}
80