Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add -l option to examples #248

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that, configuration should be updated accordingly. I.e.: in case of -e the config is:
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));

In case of -l the config should be:
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(locator));

This comment applies also to all the other examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that using Z_CONFIG_LISTEN_KEY would imply more changes. At least from a quick search it is not used anywhere in the code.

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
Loading