-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.cpp
99 lines (83 loc) · 2.56 KB
/
cli.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/********************************************************************\
* cli.cpp -- UNIX command line interface *
* *
* Copyright (C) 2009 Kenneth Laskoski *
* *
\********************************************************************/
/** @file cli.cpp
@brief UNIX command line interface
@author Copyright (C) 2009 Kenneth Laskoski
Use, modification, and distribution are subject
to the Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
*/
#include "kashmir/uuid_gen.h"
#include "kashmir/system/ccmd5.h"
#include "kashmir/system/ccsha1.h"
#include "kashmir/system/devrand.h"
#include <iostream>
#include <fstream>
#include <unistd.h>
namespace
{
int n = 1;
int v = 4;
std::ostream* outp = &std::cout;
std::ofstream ofile;
void parse_cmd_line(int argc, char *argv[])
{
int ch;
char *p;
while ((ch = getopt(argc, argv, "n:o:v:")) != -1) {
switch (ch) {
case 'n':
n = strtoul(optarg, &p, 10);
if (*p != '\0' || n < 1)
std::cerr << "invalid argument for option 'n'\n";
break;
case 'o':
ofile.open(optarg);
outp = &ofile;
break;
case 'v':
v = strtoul(optarg, &p, 10);
if (*p == '\0' && (3 <= v && v <= 5))
break;
std::cerr << "invalid argument for option 'v'\n";
// fall through
default:
exit(1);
}
argv += optind;
argc -= optind;
}
}
}
int main(int argc, char *argv[])
{
using kashmir::system::ccmd5;
using kashmir::system::ccsha1;
using kashmir::system::DevRand;
parse_cmd_line(argc, argv);
std::ostream& out = *outp;
kashmir::uuid_t uuid;
if (v == 3)
{
ccmd5 md5engine;
out << kashmir::uuid::generate(md5engine, uuid, "") << '\n';
return 0;
}
if (v == 5)
{
ccsha1 sha1engine;
out << kashmir::uuid::generate(sha1engine, uuid, "") << '\n';
return 0;
}
DevRand devrand;
for (int i = 0; i < n; i++)
{
devrand >> uuid;
out << uuid << '\n';
}
return 0;
}