summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-06-12 14:37:37 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-06-12 14:37:37 +0200
commit9821f4fcc5da36d24bc41186dccb12ed9f361662 (patch)
treedb55e66ea25b232c35ed2584c4d7cc3f2dd41037
parent1f53cc0acfc0552172f2b142910f10def4ff0e61 (diff)
downloadbiruda-9821f4fcc5da36d24bc41186dccb12ed9f361662.tar.gz
biruda-9821f4fcc5da36d24bc41186dccb12ed9f361662.tar.bz2
show workers when completing, eliminating duplicates
-rw-r--r--src/cli.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/cli.c b/src/cli.c
index aa2d169..63def10 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -91,7 +91,15 @@ static void get_workers( )
free( data );
return;
}
- worker_names[nof_worker_names++] = strdup( p + 1 );
+ bool duplicate = false;
+ for( int j = 0; j < nof_worker_names; j++ ) {
+ if( strcmp( worker_names[j], p + 1 ) == 0 ) {
+ duplicate = true;
+ }
+ }
+ if( !duplicate ) {
+ worker_names[nof_worker_names++] = strdup( p + 1 );
+ }
*pp = s;
line = strtok( NULL, "\n" );
}
@@ -103,7 +111,12 @@ static void get_workers( )
static void print_workers( )
{
- puts( "available workers..." );
+ printf( "available workers: " );
+ for( int i = 0; i < nof_worker_names; i++ ) {
+ if( i != 0 ) printf( " " );
+ printf( worker_names[i] );
+ }
+ puts( "" );
}
static void completion_func( const char *buf, linenoiseCompletions *lc )
@@ -126,6 +139,7 @@ static void completion_func( const char *buf, linenoiseCompletions *lc )
case STOP_WORKER:
case MESSAGES_WORKER:
get_workers( );
+ print_workers( );
for( int i = 0; i < nof_worker_names; i++ ) {
linenoiseAddCompletion( lc, worker_names[i] );
}