X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=examples%2Fchat.c;h=f5f41c936126c98393e1e53c1792d8e7267b2357;hb=d5de0bca747e9ba43bc28fbef54aaf5cfc321f5b;hp=37e067345f1561c1ac3fda2cbb53147f7c6b1d4c;hpb=fc484c9dde648cad4c95af9763db674ab4be668f;p=meshlink diff --git a/examples/chat.c b/examples/chat.c index 37e06734..f5f41c93 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -89,9 +89,9 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { } else if(!strcasecmp(buf, "who")) { if(!arg) { nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes); - if(!nnodes) { + if(!nnodes) fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno)); - } else { + else { printf("%zu known nodes:", nnodes); for(int i = 0; i < nnodes; i++) printf(" %s", nodes[i]->name); @@ -99,28 +99,26 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { } } else { meshlink_node_t *node = meshlink_get_node(mesh, arg); - if(!node) { + if(!node) fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); - } else { + else printf("Node %s found\n", arg); - } } } else if(!strcasecmp(buf, "quit")) { printf("Bye!\n"); fclose(stdin); } else if(!strcasecmp(buf, "help")) { printf( - ": Send a message to the given node.\n" - " Subsequent messages don't need the : prefix.\n" - "/invite Create an invitation for a new node.\n" - "/join Join an existing mesh using an invitation.\n" - "/kick Blacklist the given node.\n" - "/who [] List all nodes or show information about the given node.\n" - "/quit Exit this program.\n" - ); - } else { + ": Send a message to the given node.\n" + " Subsequent messages don't need the : prefix.\n" + "/invite Create an invitation for a new node.\n" + "/join Join an existing mesh using an invitation.\n" + "/kick Blacklist the given node.\n" + "/who [] List all nodes or show information about the given node.\n" + "/quit Exit this program.\n" + ); + } else fprintf(stderr, "Unknown command '/%s'\n", buf); - } } static void parse_input(meshlink_handle_t *mesh, char *buf) { @@ -211,7 +209,7 @@ int main(int argc, char *argv[]) { printf("Chat started.\nType /help for a list of commands.\n"); - while(fgets(buf, sizeof buf, stdin)) + while(fgets(buf, sizeof(buf), stdin)) parse_input(mesh, buf); printf("Chat stopping.\n");