Commit e993649a authored by Yoni Fogel's avatar Yoni Fogel

Added -u option

Reordered options
Set default numkeys of 1024
Fixed usage()
Addresses #52


git-svn-id: file:///svn/tokudb@1058 c7de825b-a66e-492c-adef-691d508d4ae1
parent 36aaf769
...@@ -45,6 +45,7 @@ uint32_t seed = 1; ...@@ -45,6 +45,7 @@ uint32_t seed = 1;
bool set_seed = false; bool set_seed = false;
bool printableonly = false; bool printableonly = false;
bool leadingspace = true; bool leadingspace = true;
bool force_unique = true;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
...@@ -59,26 +60,15 @@ int main (int argc, char *argv[]) { ...@@ -59,26 +60,15 @@ int main (int argc, char *argv[]) {
strcpy(sort_delimiter, ""); strcpy(sort_delimiter, "");
while ((ch = getopt(argc, argv, "PfFhHTpVr:s:d:m:M:n:o:")) != EOF) { while ((ch = getopt(argc, argv, "PpTo:r:m:M:n:uVhHfFd:s:")) != EOF) {
switch (ch) { switch (ch) {
case ('P'): { case ('P'): {
printableonly = true; printableonly = true;
break; break;
} }
case ('h'): { case ('p'): {
header = false; g.plaintext = true;
break; leadingspace = true;
}
case ('H'): {
justheader = true;
break;
}
case ('f'): {
footer = false;
break;
}
case ('F'): {
justfooter = true;
break; break;
} }
case ('T'): { case ('T'): {
...@@ -88,11 +78,6 @@ int main (int argc, char *argv[]) { ...@@ -88,11 +78,6 @@ int main (int argc, char *argv[]) {
footer = false; footer = false;
break; break;
} }
case ('p'): {
g.plaintext = true;
leadingspace = true;
break;
}
case ('o'): { case ('o'): {
if (freopen(optarg, "w", stdout) == NULL) { if (freopen(optarg, "w", stdout) == NULL) {
ERROR(errno, "%s: reopen\n", optarg); ERROR(errno, "%s: reopen\n", optarg);
...@@ -100,37 +85,6 @@ int main (int argc, char *argv[]) { ...@@ -100,37 +85,6 @@ int main (int argc, char *argv[]) {
} }
break; break;
} }
case ('d'): {
int temp = get_delimiter(optarg);
if (temp == EOF) {
ERRORX("%s: (-d) Key (or value) delimiter must be one character.",
optarg);
goto error;
}
if (isxdigit(temp)) {
ERRORX("%c: (-d) Key (or value) delimiter cannot be a hex digit.",
temp);
goto error;
}
dbt_delimiter = (char)temp;
break;
}
case ('s'): {
int temp = get_delimiter(optarg);
if (temp == EOF) {
ERRORX("%s: (-s) Sorting (Between key/value pairs) delimiter must be one character.",
optarg);
goto error;
}
if (isxdigit(temp)) {
ERRORX("%c: (-s) Sorting (Between key/value pairs) delimiter cannot be a hex digit.",
temp);
goto error;
}
sort_delimiter[0] = (char)temp;
sort_delimiter[1] = '\0';
break;
}
case ('r'): { case ('r'): {
if (strtouint32(optarg, &seed, 0, UINT32_MAX, 10)) { if (strtouint32(optarg, &seed, 0, UINT32_MAX, 10)) {
ERRORX("%s: (-r) Random seed invalid.", optarg); ERRORX("%s: (-r) Random seed invalid.", optarg);
...@@ -163,6 +117,57 @@ int main (int argc, char *argv[]) { ...@@ -163,6 +117,57 @@ int main (int argc, char *argv[]) {
set_numkeys = true; set_numkeys = true;
break; break;
} }
case ('u'): {
force_unique = false;
break;
}
case ('h'): {
header = false;
break;
}
case ('H'): {
justheader = true;
break;
}
case ('f'): {
footer = false;
break;
}
case ('F'): {
justfooter = true;
break;
}
case ('d'): {
int temp = get_delimiter(optarg);
if (temp == EOF) {
ERRORX("%s: (-d) Key (or value) delimiter must be one character.",
optarg);
goto error;
}
if (isxdigit(temp)) {
ERRORX("%c: (-d) Key (or value) delimiter cannot be a hex digit.",
temp);
goto error;
}
dbt_delimiter = (char)temp;
break;
}
case ('s'): {
int temp = get_delimiter(optarg);
if (temp == EOF) {
ERRORX("%s: (-s) Sorting (Between key/value pairs) delimiter must be one character.",
optarg);
goto error;
}
if (isxdigit(temp)) {
ERRORX("%c: (-s) Sorting (Between key/value pairs) delimiter cannot be a hex digit.",
temp);
goto error;
}
sort_delimiter[0] = (char)temp;
sort_delimiter[1] = '\0';
break;
}
case ('V'): { case ('V'): {
printf("%s\n", db_version(NULL, NULL, NULL)); printf("%s\n", db_version(NULL, NULL, NULL));
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -209,8 +214,8 @@ int main (int argc, char *argv[]) { ...@@ -209,8 +214,8 @@ int main (int argc, char *argv[]) {
if (justfooter || justheader) outputkeys = false; if (justfooter || justheader) outputkeys = false;
else if (!set_numkeys) else if (!set_numkeys)
{ {
ERRORX("The -n option is required.\n"); ERRORX("Using default number of keys. (-n 1024).\n");
goto error; numkeys = 1024;
} }
if (outputkeys && !set_seed) { if (outputkeys && !set_seed) {
ERRORX("Using default seed. (-r 1).\n"); ERRORX("Using default seed. (-r 1).\n");
...@@ -252,10 +257,9 @@ int main (int argc, char *argv[]) { ...@@ -252,10 +257,9 @@ int main (int argc, char *argv[]) {
int usage() int usage()
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s [-PfFhHTpV] [-r random seed] [-s delimiter] \n" "usage: %s [-PpTuVhHfF] [-o output] [-r seed] [-m minsize] [-M limitsize]\n"
" [-d delimiter] [-m lengthmin] [-M lengthlimit] \n" " %*s[-n numpairs] [-d delimiter] [-s delimiter]\n",
" -n numkeys [-o output_file] \n", g.progname, strlen(g.progname) + 1, "");
g.progname);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -311,13 +315,15 @@ void generate_keys() ...@@ -311,13 +315,15 @@ void generate_keys()
outputbyte(ch); outputbyte(ch);
} }
totalsize += length; totalsize += length;
if (length == 0 && !usedemptykey) usedemptykey = true; if (force_unique) {
else { if (length == 0 && !usedemptykey) usedemptykey = true;
/* Append identifier to ensure uniqueness. */ else {
sprintf(identifier, "x%llx", numgenerated); /* Append identifier to ensure uniqueness. */
outputstring(identifier); sprintf(identifier, "x%llx", numgenerated);
totalsize += strlen(identifier); outputstring(identifier);
} totalsize += strlen(identifier);
}
}
} }
printf("%c", dbt_delimiter); printf("%c", dbt_delimiter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment