X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=inline;f=examples%2Fchannels.c;h=a869f513e9bed1e46c86f192c09dff6b9bef10ff;hb=185a8731839551fc9df7059ac374be5f5e35c086;hp=1fceb0b4594ce7948d873cf0a942380a3bee70de;hpb=bb6e35501cb2c39e52022416592c5869a2f0bf40;p=meshlink diff --git a/examples/channels.c b/examples/channels.c index 1fceb0b4..a869f513 100644 --- a/examples/channels.c +++ b/examples/channels.c @@ -123,9 +123,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); @@ -133,28 +133,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) { @@ -263,7 +261,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");