Skip to content

Commit 210b00f

Browse files
committed
add -l option to examples
1 parent 3e366a5 commit 210b00f

16 files changed

+93
-38
lines changed

examples/unix/c11/z_get.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
4242
const char *value = NULL;
4343

4444
int opt;
45-
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
45+
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
4646
switch (opt) {
4747
case 'k':
4848
keyexpr = optarg;
@@ -53,11 +53,15 @@ int main(int argc, char **argv) {
5353
case 'm':
5454
mode = optarg;
5555
break;
56+
case 'l':
57+
locator = optarg;
58+
mode = "peer";
59+
break;
5660
case 'v':
5761
value = optarg;
5862
break;
5963
case '?':
60-
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
64+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
6165
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
6266
} else {
6367
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_info.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ int main(int argc, char **argv) {
3232
char *locator = NULL;
3333

3434
int opt;
35-
while ((opt = getopt(argc, argv, "e:m:")) != -1) {
35+
while ((opt = getopt(argc, argv, "e:m:l:")) != -1) {
3636
switch (opt) {
3737
case 'e':
3838
locator = optarg;
3939
break;
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_pub.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,14 @@ int main(int argc, char **argv) {
4646
mode = optarg;
4747
break;
4848
case 'l':
49-
opt = atoi(optarg);
50-
value = z_malloc(opt + 1);
51-
memset(value, 'A', opt);
52-
value[opt] = 0;
53-
for (int i = opt - 1; opt > 0; i--, opt /= 10) {
54-
value[i] = '0' + (opt % 10);
55-
}
49+
locator = optarg;
50+
mode = "peer";
5651
break;
5752
case 'n':
5853
n = atoi(optarg);
5954
break;
6055
case '?':
61-
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
56+
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
6257
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
6358
} else {
6459
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_pub_st.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
2626
char *locator = NULL;
2727

2828
int opt;
29-
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
29+
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
3030
switch (opt) {
3131
case 'k':
3232
keyexpr = optarg;
@@ -40,8 +40,12 @@ int main(int argc, char **argv) {
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_put.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
2626
char *locator = NULL;
2727

2828
int opt;
29-
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
29+
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
3030
switch (opt) {
3131
case 'k':
3232
keyexpr = optarg;
@@ -40,8 +40,12 @@ int main(int argc, char **argv) {
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_queryable.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, char **argv) {
4141
char *locator = NULL;
4242

4343
int opt;
44-
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
44+
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
4545
switch (opt) {
4646
case 'k':
4747
keyexpr = optarg;
@@ -52,11 +52,15 @@ int main(int argc, char **argv) {
5252
case 'm':
5353
mode = optarg;
5454
break;
55+
case 'l':
56+
locator = optarg;
57+
mode = "peer";
58+
break;
5559
case 'v':
5660
value = optarg;
5761
break;
5862
case '?':
59-
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
63+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
6064
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
6165
} else {
6266
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_sub.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char **argv) {
3333
char *locator = NULL;
3434

3535
int opt;
36-
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
36+
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
3737
switch (opt) {
3838
case 'k':
3939
keyexpr = optarg;
@@ -44,8 +44,12 @@ int main(int argc, char **argv) {
4444
case 'm':
4545
mode = optarg;
4646
break;
47+
case 'l':
48+
locator = optarg;
49+
mode = "peer";
50+
break;
4751
case '?':
48-
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
52+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4953
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
5054
} else {
5155
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c11/z_sub_st.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char **argv) {
3333
char *locator = NULL;
3434

3535
int opt;
36-
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
36+
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
3737
switch (opt) {
3838
case 'k':
3939
keyexpr = optarg;
@@ -44,8 +44,12 @@ int main(int argc, char **argv) {
4444
case 'm':
4545
mode = optarg;
4646
break;
47+
case 'l':
48+
locator = optarg;
49+
mode = "peer";
50+
break;
4751
case '?':
48-
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
52+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4953
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
5054
} else {
5155
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_get.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
4242
const char *value = NULL;
4343

4444
int opt;
45-
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
45+
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
4646
switch (opt) {
4747
case 'k':
4848
keyexpr = optarg;
@@ -53,11 +53,15 @@ int main(int argc, char **argv) {
5353
case 'm':
5454
mode = optarg;
5555
break;
56+
case 'l':
57+
locator = optarg;
58+
mode = "peer";
59+
break;
5660
case 'v':
5761
value = optarg;
5862
break;
5963
case '?':
60-
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
64+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
6165
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
6266
} else {
6367
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_info.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ int main(int argc, char **argv) {
3232
char *locator = NULL;
3333

3434
int opt;
35-
while ((opt = getopt(argc, argv, "e:m:")) != -1) {
35+
while ((opt = getopt(argc, argv, "e:m:l:")) != -1) {
3636
switch (opt) {
3737
case 'e':
3838
locator = optarg;
3939
break;
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_pub.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
2626
char *locator = NULL;
2727

2828
int opt;
29-
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
29+
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
3030
switch (opt) {
3131
case 'k':
3232
keyexpr = optarg;
@@ -40,8 +40,12 @@ int main(int argc, char **argv) {
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_pub_st.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
2626
char *locator = NULL;
2727

2828
int opt;
29-
while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
29+
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
3030
switch (opt) {
3131
case 'k':
3232
keyexpr = optarg;
@@ -40,8 +40,12 @@ int main(int argc, char **argv) {
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_put.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
2626
char *locator = NULL;
2727

2828
int opt;
29-
while ((opt = getopt(argc, argv, "k:v:e:")) != -1) {
29+
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
3030
switch (opt) {
3131
case 'k':
3232
keyexpr = optarg;
@@ -40,8 +40,12 @@ int main(int argc, char **argv) {
4040
case 'm':
4141
mode = optarg;
4242
break;
43+
case 'l':
44+
locator = optarg;
45+
mode = "peer";
46+
break;
4347
case '?':
44-
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
48+
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4549
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
4650
} else {
4751
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_queryable.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main(int argc, char **argv) {
3737
char *locator = NULL;
3838

3939
int opt;
40-
while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) {
40+
while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) {
4141
switch (opt) {
4242
case 'k':
4343
keyexpr = optarg;
@@ -51,8 +51,12 @@ int main(int argc, char **argv) {
5151
case 'e':
5252
locator = optarg;
5353
break;
54+
case 'l':
55+
locator = optarg;
56+
mode = "peer";
57+
break;
5458
case '?':
55-
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') {
59+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
5660
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
5761
} else {
5862
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_sub.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char **argv) {
3333
char *locator = NULL;
3434

3535
int opt;
36-
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
36+
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
3737
switch (opt) {
3838
case 'k':
3939
keyexpr = optarg;
@@ -44,8 +44,12 @@ int main(int argc, char **argv) {
4444
case 'm':
4545
mode = optarg;
4646
break;
47+
case 'l':
48+
locator = optarg;
49+
mode = "peer";
50+
break;
4751
case '?':
48-
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
52+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4953
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
5054
} else {
5155
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

examples/unix/c99/z_sub_st.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char **argv) {
3333
char *locator = NULL;
3434

3535
int opt;
36-
while ((opt = getopt(argc, argv, "k:e:m:")) != -1) {
36+
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
3737
switch (opt) {
3838
case 'k':
3939
keyexpr = optarg;
@@ -44,8 +44,12 @@ int main(int argc, char **argv) {
4444
case 'm':
4545
mode = optarg;
4646
break;
47+
case 'l':
48+
locator = optarg;
49+
mode = "peer";
50+
break;
4751
case '?':
48-
if (optopt == 'k' || optopt == 'e' || optopt == 'm') {
52+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
4953
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
5054
} else {
5155
fprintf(stderr, "Unknown option `-%c'.\n", optopt);

0 commit comments

Comments
 (0)