Add help information and fix quit functionality.
This commit is contained in:
parent
3e3ef767a4
commit
fc94e08e31
15
demo/main.c
15
demo/main.c
@ -20,6 +20,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
void print_help() {
|
||||||
|
puts("Use `/' at the beginning to indicate a command (like in IRC).");
|
||||||
|
puts(" stats -- Give network statistics of the local node.");
|
||||||
|
puts(" num_nodes -- Get total number of nodes.");
|
||||||
|
puts(" exit | quit -- Close the program.");
|
||||||
|
puts(" help -- Show this help information.");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if(argc != 2 && argc != 4)
|
if(argc != 2 && argc != 4)
|
||||||
{
|
{
|
||||||
@ -45,16 +53,19 @@ int main(int argc, char *argv[]) {
|
|||||||
if(connect_address)
|
if(connect_address)
|
||||||
NeoComm_connect(connect_address, connect_port);
|
NeoComm_connect(connect_address, connect_port);
|
||||||
|
|
||||||
while(1) {
|
int run = 1;
|
||||||
|
while(run) {
|
||||||
char in[128];
|
char in[128];
|
||||||
printf("> ");
|
printf("> ");
|
||||||
scanf("%s", in);
|
scanf("%s", in);
|
||||||
if(strcmp(in, "/exit") == 0 || strcmp(in, "/quit") == 0)
|
if(strcmp(in, "/exit") == 0 || strcmp(in, "/quit") == 0)
|
||||||
break;
|
run = 0;
|
||||||
else if(strcmp(in, "/stats") == 0)
|
else if(strcmp(in, "/stats") == 0)
|
||||||
printf("%s", NeoComm_get_node_stats());
|
printf("%s", NeoComm_get_node_stats());
|
||||||
else if(strcmp(in, "/num_nodes") == 0)
|
else if(strcmp(in, "/num_nodes") == 0)
|
||||||
printf("%u", NeoComm_count_connected_nodes());
|
printf("%u", NeoComm_count_connected_nodes());
|
||||||
|
else if(strcmp(in, "/help") == 0)
|
||||||
|
print_help();
|
||||||
}
|
}
|
||||||
|
|
||||||
NeoComm_deinit();
|
NeoComm_deinit();
|
||||||
|
Loading…
Reference in New Issue
Block a user