Skip to content

Commit

Permalink
add -l option to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Sep 13, 2023
1 parent 3e366a5 commit 210b00f
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 38 deletions.
8 changes: 6 additions & 2 deletions examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, char **argv) {
const char *value = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -53,11 +53,15 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case 'v':
value = optarg;
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c11/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "e:m:")) != -1) {
while ((opt = getopt(argc, argv, "e:m:l:")) != -1) {
switch (opt) {
case 'e':
locator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'e' || optopt == 'm') {
if (optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
11 changes: 3 additions & 8 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ int main(int argc, char **argv) {
mode = optarg;
break;
case 'l':
opt = atoi(optarg);
value = z_malloc(opt + 1);
memset(value, 'A', opt);
value[opt] = 0;
for (int i = opt - 1; opt > 0; i--, opt /= 10) {
value[i] = '0' + (opt % 10);
}
locator = optarg;
mode = "peer";
break;
case 'n':
n = atoi(optarg);
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c11/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -40,8 +40,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -40,8 +40,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c11/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -52,11 +52,15 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case 'v':
value = optarg;
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -44,8 +44,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c11/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -44,8 +44,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, char **argv) {
const char *value = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -53,11 +53,15 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case 'v':
value = optarg;
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "e:m:")) != -1) {
while ((opt = getopt(argc, argv, "e:m:l:")) != -1) {
switch (opt) {
case 'e':
locator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'e' || optopt == 'm') {
if (optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -40,8 +40,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -40,8 +40,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:v:e:")) != -1) {
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -40,8 +40,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -51,8 +51,12 @@ int main(int argc, char **argv) {
case 'e':
locator = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -44,8 +44,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
8 changes: 6 additions & 2 deletions examples/unix/c99/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv) {
char *locator = NULL;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -44,8 +44,12 @@ int main(int argc, char **argv) {
case 'm':
mode = optarg;
break;
case 'l':
locator = optarg;
mode = "peer";
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down

0 comments on commit 210b00f

Please sign in to comment.