From 9821f4fcc5da36d24bc41186dccb12ed9f361662 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 12 Jun 2015 14:37:37 +0200 Subject: show workers when completing, eliminating duplicates --- src/cli.c | 18 ++++++++++++++++-- 1 file 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] ); } -- cgit v1.2.3-54-g00ecf