From 210b00f09d1c04e9d670be404adb18a625fb042f Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Wed, 13 Sep 2023 15:27:11 +0200 Subject: [PATCH] add -l option to examples --- examples/unix/c11/z_get.c | 8 ++++++-- examples/unix/c11/z_info.c | 8 ++++++-- examples/unix/c11/z_pub.c | 11 +++-------- examples/unix/c11/z_pub_st.c | 8 ++++++-- examples/unix/c11/z_put.c | 8 ++++++-- examples/unix/c11/z_queryable.c | 8 ++++++-- examples/unix/c11/z_sub.c | 8 ++++++-- examples/unix/c11/z_sub_st.c | 8 ++++++-- examples/unix/c99/z_get.c | 8 ++++++-- examples/unix/c99/z_info.c | 8 ++++++-- examples/unix/c99/z_pub.c | 8 ++++++-- examples/unix/c99/z_pub_st.c | 8 ++++++-- examples/unix/c99/z_put.c | 8 ++++++-- examples/unix/c99/z_queryable.c | 8 ++++++-- examples/unix/c99/z_sub.c | 8 ++++++-- examples/unix/c99/z_sub_st.c | 8 ++++++-- 16 files changed, 93 insertions(+), 38 deletions(-) diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index c1971702e..400cd39b4 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -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; @@ -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); diff --git a/examples/unix/c11/z_info.c b/examples/unix/c11/z_info.c index 68091cde8..5697d5c4f 100644 --- a/examples/unix/c11/z_info.c +++ b/examples/unix/c11/z_info.c @@ -32,7 +32,7 @@ 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; @@ -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 == '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); diff --git a/examples/unix/c11/z_pub.c b/examples/unix/c11/z_pub.c index e7b7e64bc..cc4252b24 100644 --- a/examples/unix/c11/z_pub.c +++ b/examples/unix/c11/z_pub.c @@ -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); diff --git a/examples/unix/c11/z_pub_st.c b/examples/unix/c11/z_pub_st.c index 1e27ade12..c8440b2e9 100644 --- a/examples/unix/c11/z_pub_st.c +++ b/examples/unix/c11/z_pub_st.c @@ -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; @@ -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); diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index 2a403af44..c4aca1cc9 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -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; @@ -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); diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index e6f9d8e48..392778381 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -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; @@ -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); diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index 7cc329416..d004ead95 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -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; @@ -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); diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index 7a8b96143..103c68a06 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index f20104028..b7097b445 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_info.c b/examples/unix/c99/z_info.c index a06f13ee3..0497ea6f8 100644 --- a/examples/unix/c99/z_info.c +++ b/examples/unix/c99/z_info.c @@ -32,7 +32,7 @@ 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; @@ -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 == '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); diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index a5839f36f..bd83501f5 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index 1261fcd50..36ec2457f 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index 45ebe29b4..461fa7a32 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index e920b1035..9a76be6d7 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index db294ee00..a04d9e03c 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -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; @@ -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); diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index 4a87cce3b..e3f7f6dec 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -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; @@ -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);