aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2007-01-28 23:40:59 +1000
committerGravatar axel <axel@liljencrantz.se>2007-01-28 23:40:59 +1000
commit37a95a3096e2472c0607420a8208d1cac1730369 (patch)
tree2072bc3719d9a6042332f46dcdb6f511d96b34b9
parentbbd229b206ed921cab13e6bf637453d2613b1989 (diff)
Make parsing of --authorative switch for complete builtin more logical. Fix bug with previous approach causing some completions to be ignored.
darcs-hash:20070128134059-ac50b-de53eb223939fbdf0d247dfbe343c62fc31cce11.gz
-rw-r--r--builtin_complete.c100
-rw-r--r--complete.c108
-rw-r--r--complete.h10
-rw-r--r--doc_src/complete.txt1
4 files changed, 111 insertions, 108 deletions
diff --git a/builtin_complete.c b/builtin_complete.c
index 51775115..9912e2f1 100644
--- a/builtin_complete.c
+++ b/builtin_complete.c
@@ -48,7 +48,6 @@ static void builtin_complete_add2( const wchar_t *cmd,
array_list_t *gnu_opt,
array_list_t *old_opt,
int result_mode,
- int authorative,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc )
@@ -64,7 +63,6 @@ static void builtin_complete_add2( const wchar_t *cmd,
0,
0,
result_mode,
- authorative,
condition,
comp,
desc );
@@ -78,7 +76,6 @@ static void builtin_complete_add2( const wchar_t *cmd,
(wchar_t *)al_get(gnu_opt, i ),
0,
result_mode,
- authorative,
condition,
comp,
desc );
@@ -92,7 +89,6 @@ static void builtin_complete_add2( const wchar_t *cmd,
(wchar_t *)al_get(old_opt, i ),
1,
result_mode,
- authorative,
condition,
comp,
desc );
@@ -106,7 +102,6 @@ static void builtin_complete_add2( const wchar_t *cmd,
0,
0,
result_mode,
- authorative,
condition,
comp,
desc );
@@ -128,72 +123,47 @@ static void builtin_complete_add( array_list_t *cmd,
const wchar_t *desc )
{
int i;
- int has_content =( wcslen( short_opt ) ||
- al_get_count( gnu_opt ) ||
- al_get_count( old_opt ) ||
- comp );
for( i=0; i<al_get_count( cmd ); i++ )
{
- if( has_content )
- {
-
- builtin_complete_add2( al_get( cmd, i ),
- COMMAND,
- short_opt,
- gnu_opt,
- old_opt,
- result_mode,
- authorative,
- condition,
- comp,
- desc );
- }
- else
+ builtin_complete_add2( al_get( cmd, i ),
+ COMMAND,
+ short_opt,
+ gnu_opt,
+ old_opt,
+ result_mode,
+ condition,
+ comp,
+ desc );
+
+ if( authorative != -1 )
{
- complete_add( al_get( cmd, i ),
- COMMAND,
- 0,
- 0,
- 0,
- 0,
- authorative,
- 0,
- 0,
- 0 );
+ complete_set_authorative( al_get( cmd, i ),
+ COMMAND,
+ authorative );
}
}
for( i=0; i<al_get_count( path ); i++ )
{
- if( has_content )
- {
-
- builtin_complete_add2( al_get( path, i ),
- PATH,
- short_opt,
- gnu_opt,
- old_opt,
- result_mode,
- authorative,
- condition,
- comp,
- desc );
- }
- else
+ builtin_complete_add2( al_get( path, i ),
+ PATH,
+ short_opt,
+ gnu_opt,
+ old_opt,
+ result_mode,
+ condition,
+ comp,
+ desc );
+
+ if( authorative != -1 )
{
- complete_add( al_get( cmd, i ),
- PATH,
- 0,
- 0,
- 0,
- 0,
- authorative,
- 0,
- 0,
- 0 );
+ complete_set_authorative( al_get( path, i ),
+ PATH,
+ authorative );
}
+
}
}
@@ -316,7 +286,7 @@ static int builtin_complete( wchar_t **argv )
int argc=0;
int result_mode=SHARED;
int remove = 0;
- int authorative = 1;
+ int authorative = -1;
string_buffer_t short_opt;
array_list_t gnu_opt, old_opt;
@@ -398,6 +368,10 @@ static int builtin_complete( wchar_t **argv )
}
,
{
+ L"authorative", no_argument, 0, 'A'
+ }
+ ,
+ {
L"condition", required_argument, 0, 'n'
}
,
@@ -419,7 +393,7 @@ static int builtin_complete( wchar_t **argv )
int opt = wgetopt_long( argc,
argv,
- L"a:c:p:s:l:o:d:frxeun:C::h",
+ L"a:c:p:s:l:o:d:frxeuAn:C::h",
long_options,
&opt_index );
if( opt == -1 )
@@ -479,6 +453,10 @@ static int builtin_complete( wchar_t **argv )
authorative=0;
break;
+ case 'A':
+ authorative=1;
+ break;
+
case 's':
sb_append( &short_opt, woptarg );
break;
diff --git a/complete.c b/complete.c
index 899cf7c4..5557bb0d 100644
--- a/complete.c
+++ b/complete.c
@@ -390,21 +390,13 @@ static complete_entry_t *complete_find_exact_entry( const wchar_t *cmd,
return 0;
}
-void complete_add( const wchar_t *cmd,
- int cmd_type,
- wchar_t short_opt,
- const wchar_t *long_opt,
- int old_mode,
- int result_mode,
- int authorative,
- const wchar_t *condition,
- const wchar_t *comp,
- const wchar_t *desc )
+/**
+ Locate the specified entry. Create it if it doesn't exist.
+*/
+static complete_entry_t *complete_get_exact_entry( const wchar_t *cmd,
+ int cmd_type )
{
complete_entry_t *c;
- complete_entry_opt_t *opt;
-
- CHECK( cmd, );
complete_init();
@@ -427,46 +419,72 @@ void complete_add( const wchar_t *cmd,
c->short_opt_str = wcsdup(L"");
}
+ return c;
+}
+
+
+void complete_set_authorative( const wchar_t *cmd,
+ int cmd_type,
+ int authorative )
+{
+ complete_entry_t *c;
+
+ CHECK( cmd, );
+ c = complete_get_exact_entry( cmd, cmd_type );
c->authorative = authorative;
+}
- if( short_opt != L'\0' || long_opt )
- {
-
- opt = halloc( 0, sizeof( complete_entry_opt_t ) );
+
+void complete_add( const wchar_t *cmd,
+ int cmd_type,
+ wchar_t short_opt,
+ const wchar_t *long_opt,
+ int old_mode,
+ int result_mode,
+ const wchar_t *condition,
+ const wchar_t *comp,
+ const wchar_t *desc )
+{
+ complete_entry_t *c;
+ complete_entry_opt_t *opt;
+
+ CHECK( cmd, );
+
+ c = complete_get_exact_entry( cmd, cmd_type );
+
+ opt = halloc( 0, sizeof( complete_entry_opt_t ) );
- opt->next = c->first_option;
- c->first_option = opt;
- if( short_opt != L'\0' )
+ opt->next = c->first_option;
+ c->first_option = opt;
+ if( short_opt != L'\0' )
+ {
+ int len = 1 + ((result_mode & NO_COMMON) != 0);
+ c->short_opt_str =
+ realloc( c->short_opt_str,
+ sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) );
+ wcsncat( c->short_opt_str,
+ &short_opt, 1 );
+ if( len == 2 )
{
- int len = 1 + ((result_mode & NO_COMMON) != 0);
- c->short_opt_str =
- realloc( c->short_opt_str,
- sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) );
- wcsncat( c->short_opt_str,
- &short_opt, 1 );
- if( len == 2 )
- {
- wcscat( c->short_opt_str, L":" );
- }
+ wcscat( c->short_opt_str, L":" );
}
+ }
- opt->short_opt = short_opt;
- opt->result_mode = result_mode;
- opt->old_mode=old_mode;
+ opt->short_opt = short_opt;
+ opt->result_mode = result_mode;
+ opt->old_mode=old_mode;
- opt->comp = comp?halloc_wcsdup(opt, comp):L"";
- opt->condition = condition?halloc_wcsdup(opt, condition):L"";
- opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ;
+ opt->comp = comp?halloc_wcsdup(opt, comp):L"";
+ opt->condition = condition?halloc_wcsdup(opt, condition):L"";
+ opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ;
- if( desc && wcslen( desc ) )
- {
- opt->desc = halloc_wcsdup( opt, desc );
- }
- else
- {
- opt->desc = L"";
- }
-
+ if( desc && wcslen( desc ) )
+ {
+ opt->desc = halloc_wcsdup( opt, desc );
+ }
+ else
+ {
+ opt->desc = L"";
}
}
diff --git a/complete.h b/complete.h
index 9461cfc7..e04d0e5f 100644
--- a/complete.h
+++ b/complete.h
@@ -105,7 +105,6 @@
file completion is not performed.
\param comp A space separated list of completions which may contain subshells.
\param desc A description of the completion.
- \param authorative Whether there list of completions for this command is complete. If true, any options not matching one of the provided options will be flagged as an error by syntax highlighting.
\param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used.
*/
@@ -115,10 +114,17 @@ void complete_add( const wchar_t *cmd,
const wchar_t *long_opt,
int long_mode,
int result_mode,
- int authorative,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc );
+/**
+ Sets whether the completion list for this command is complete. If
+ true, any options not matching one of the provided options will be
+ flagged as an error by syntax highlighting.
+*/
+void complete_set_authorative( const wchar_t *cmd,
+ int cmd_type,
+ int authorative );
/**
Remove a previously defined completion
diff --git a/doc_src/complete.txt b/doc_src/complete.txt
index ab1b326b..20a0ad34 100644
--- a/doc_src/complete.txt
+++ b/doc_src/complete.txt
@@ -22,6 +22,7 @@ the fish manual.
- <tt>-p</tt> or <tt>--path</tt> implies that the string COMMAND is the full path of the command
- <tt>-r</tt> or <tt>--require-parameter</tt> specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option
- <tt>-u</tt> or <tt>--unauthorative</tt> implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors
+- <tt>-A</tt> or <tt>--authorative</tt> implies that there may be no more options than the ones specified, and that fish should assume that options not listed are spelling errors
- <tt>-x</tt> or <tt>--exclusive</tt> implies both <tt>-r</tt> and <tt>-f</tt>
Command specific tab-completions in \c fish are based on the notion