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 all commits
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
19 changes: 13 additions & 6 deletions examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,30 @@ void reply_handler(z_owned_reply_t *reply, void *ctx) {
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/**";
const char *mode = "client";
const char *locator = NULL;
const char *clocator = NULL;
const char *llocator = NULL;
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;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = optarg;
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 All @@ -70,8 +74,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
19 changes: 13 additions & 6 deletions examples/unix/c11/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ void print_zid(const z_id_t *id, void *ctx) {

int main(int argc, char **argv) {
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = 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;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = optarg;
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 All @@ -54,8 +58,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
22 changes: 10 additions & 12 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ int main(int argc, char **argv) {
char *const default_value = "Pub from Pico!";
char *value = default_value;
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = NULL;
int n = 10;

int opt;
Expand All @@ -40,25 +41,19 @@ int main(int argc, char **argv) {
value = optarg;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
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);
}
llocator = optarg;
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 All @@ -71,8 +66,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
19 changes: 13 additions & 6 deletions examples/unix/c11/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-pub";
const char *value = "Pub from Pico!";
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = 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 @@ -35,13 +36,16 @@ int main(int argc, char **argv) {
value = optarg;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = 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 All @@ -54,8 +58,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
19 changes: 13 additions & 6 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-put";
const char *value = "Pub from Pico!";
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = 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 @@ -35,13 +36,16 @@ int main(int argc, char **argv) {
value = optarg;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = 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 All @@ -54,8 +58,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
19 changes: 13 additions & 6 deletions examples/unix/c11/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,29 @@ void query_handler(const z_query_t *query, void *ctx) {

int main(int argc, char **argv) {
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = 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;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = optarg;
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 All @@ -69,8 +73,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
19 changes: 13 additions & 6 deletions examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ void data_handler(const z_sample_t *sample, void *ctx) {
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/**";
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = 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;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = optarg;
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 All @@ -58,8 +62,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
19 changes: 13 additions & 6 deletions examples/unix/c11/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ void data_handler(const z_sample_t *sample, void *ctx) {
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/**";
const char *mode = "client";
char *locator = NULL;
char *clocator = NULL;
char *llocator = 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;
break;
case 'e':
locator = optarg;
clocator = optarg;
break;
case 'm':
mode = optarg;
break;
case 'l':
llocator = optarg;
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 All @@ -58,8 +62,11 @@ int main(int argc, char **argv) {

z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (locator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator));
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
Loading
Loading