mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Autocomplete fix
@ 2011-08-25 23:40 Carlo Caione
  2011-08-26  7:47 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Carlo Caione @ 2011-08-25 23:40 UTC (permalink / raw)
  To: barebox

Autocomplete fixed: now working also to autocomplete file names as first 
argument.

i.e.:

# ./en<TAB> completes to # ./env/

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
  common/complete.c |   13 +++++++++----
  1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 46ba871..543e649 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -71,6 +71,7 @@ static int command_complete(struct string_list *sl, 
char *instr)
  {
  	struct command *cmdtp;
  	char cmd[128];
+	int found = 0;

  	for_each_command(cmdtp) {
  		if (!strncmp(instr, cmdtp->name, strlen(instr))) {
@@ -78,10 +79,11 @@ static int command_complete(struct string_list *sl, 
char *instr)
  			cmd[strlen(cmdtp->name)] = ' ';
  			cmd[strlen(cmdtp->name) + 1] = 0;
  			string_list_add(sl, cmd);
+			found = 1;
  		}
  	}

-	return 0;
+	return(found);
  }

  static int tab_pressed = 0;
@@ -116,13 +118,16 @@ int complete(char *instr, char **outstr)

  	instr = t;

-	/* get the completion possibilities */
  	if ((t = strrchr(t, ' '))) {
  		t++;
  		file_complete(&sl, t);
  		instr = t;
-	} else
-		command_complete(&sl, instr);
+	} else {
+		if(!command_complete(&sl, instr)){	
+			file_complete(&sl, instr);
+		}
+	}
+		

  	pos = strlen(instr);

-- 
1.7.6.1

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Autocomplete fix
  2011-08-25 23:40 [PATCH] Autocomplete fix Carlo Caione
@ 2011-08-26  7:47 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2011-08-26  7:47 UTC (permalink / raw)
  To: Carlo Caione; +Cc: barebox

Hello Carlo,

You have trailing whitespaces in your patch, also your mailer wraps
lines. Please fix this before resending.

On Thu, Aug 25, 2011 at 04:40:36PM -0700, Carlo Caione wrote:
> Autocomplete fixed: now working also to autocomplete file names as
> first argument.
> 
> i.e.:
> 
> # ./en<TAB> completes to # ./env/
> 
> Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
> ---
>  common/complete.c |   13 +++++++++----
>  1 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/common/complete.c b/common/complete.c
> index 46ba871..543e649 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -71,6 +71,7 @@ static int command_complete(struct string_list
> *sl, char *instr)
>  {
>  	struct command *cmdtp;
>  	char cmd[128];
> +	int found = 0;
> 
>  	for_each_command(cmdtp) {
>  		if (!strncmp(instr, cmdtp->name, strlen(instr))) {
> @@ -78,10 +79,11 @@ static int command_complete(struct string_list
> *sl, char *instr)
>  			cmd[strlen(cmdtp->name)] = ' ';
>  			cmd[strlen(cmdtp->name) + 1] = 0;
>  			string_list_add(sl, cmd);
> +			found = 1;
>  		}
>  	}
> 
> -	return 0;
> +	return(found);

No () with return please.

>  }
> 
>  static int tab_pressed = 0;
> @@ -116,13 +118,16 @@ int complete(char *instr, char **outstr)
> 
>  	instr = t;
> 
> -	/* get the completion possibilities */
>  	if ((t = strrchr(t, ' '))) {
>  		t++;
>  		file_complete(&sl, t);
>  		instr = t;
> -	} else
> -		command_complete(&sl, instr);
> +	} else {
> +		if(!command_complete(&sl, instr)){	
> +			file_complete(&sl, instr);
> +		}

This will only show the file completion when no suitable command is
found which is a bit strange behaviour. Normally I would expect to
see all possibilities. This can easily be archieved by calling both
command_complete() and file_complete() unconditionally.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-26  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-25 23:40 [PATCH] Autocomplete fix Carlo Caione
2011-08-26  7:47 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox