Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Apply new indentation, brace, and whitespace style

  • Loading branch information...
commit 9992b8eb0e3366ff8a3948aa0b66a19c3c12c737 1 parent bab69f2
@ridiculousfish ridiculousfish authored
Showing with 17,869 additions and 16,957 deletions.
  1. +93 −58 autoload.cpp
  2. +21 −17 autoload.h
  3. +3,478 −3,405 builtin.cpp
  4. +8 −8 builtin.h
  5. +427 −427 builtin_commandline.cpp
  6. +469 −469 builtin_complete.cpp
  7. +225 −225 builtin_jobs.cpp
  8. +534 −529 builtin_set.cpp
  9. +648 −549 builtin_test.cpp
  10. +350 −350 builtin_ulimit.cpp
  11. +165 −78 color.cpp
  12. +59 −18 color.h
  13. +1,510 −1,437 common.cpp
  14. +154 −110 common.h
  15. +1,011 −970 complete.cpp
  16. +55 −50 complete.h
  17. +777 −747 env.cpp
  18. +26 −15 env.h
  19. +283 −283 env_universal.cpp
  20. +9 −9 env_universal.h
  21. +516 −510 env_universal_common.cpp
  22. +65 −65 env_universal_common.h
  23. +311 −306 event.cpp
  24. +33 −32 event.h
  25. +950 −923 exec.cpp
  26. +7 −7 exec.h
  27. +766 −742 expand.cpp
  28. +34 −33 expand.h
  29. +800 −796 fallback.cpp
  30. +66 −66 fallback.h
  31. +329 −329 fish.cpp
  32. +250 −241 fish_indent.cpp
  33. +939 −935 fish_pager.cpp
  34. +498 −413 fish_tests.cpp
  35. +553 −549 fishd.cpp
  36. +86 −71 function.cpp
  37. +47 −46 function.h
  38. +931 −882 highlight.cpp
  39. +5 −4 highlight.h
  40. +381 −253 history.cpp
Sorry, we could not display the entire diff because it was too big.
View
151 autoload.cpp
@@ -17,17 +17,24 @@ The classes responsible for autoloading functions and completions.
/* The time before we'll recheck an autoloaded file */
static const int kAutoloadStalenessInterval = 15;
-file_access_attempt_t access_file(const wcstring &path, int mode) {
+file_access_attempt_t access_file(const wcstring &path, int mode)
+{
//printf("Touch %ls\n", path.c_str());
file_access_attempt_t result = {0};
struct stat statbuf;
- if (wstat(path, &statbuf)) {
+ if (wstat(path, &statbuf))
+ {
result.error = errno;
- } else {
+ }
+ else
+ {
result.mod_time = statbuf.st_mtime;
- if (waccess(path, mode)) {
+ if (waccess(path, mode))
+ {
result.error = errno;
- } else {
+ }
+ else
+ {
result.accessible = true;
}
}
@@ -39,21 +46,23 @@ file_access_attempt_t access_file(const wcstring &path, int mode) {
}
autoload_t::autoload_t(const wcstring &env_var_name_var, const builtin_script_t * const scripts, size_t script_count) :
- lock(),
- env_var_name(env_var_name_var),
- builtin_scripts(scripts),
- builtin_script_count(script_count),
- last_path(),
- is_loading_set()
+ lock(),
+ env_var_name(env_var_name_var),
+ builtin_scripts(scripts),
+ builtin_script_count(script_count),
+ last_path(),
+ is_loading_set()
{
pthread_mutex_init(&lock, NULL);
}
-autoload_t::~autoload_t() {
+autoload_t::~autoload_t()
+{
pthread_mutex_destroy(&lock);
}
-void autoload_t::node_was_evicted(autoload_function_t *node) {
+void autoload_t::node_was_evicted(autoload_function_t *node)
+{
// This should only ever happen on the main thread
ASSERT_IS_MAIN_THREAD();
@@ -63,27 +72,27 @@ void autoload_t::node_was_evicted(autoload_function_t *node) {
delete node;
}
-int autoload_t::unload( const wcstring &cmd )
+int autoload_t::unload(const wcstring &cmd)
{
return this->evict_node(cmd);
}
-int autoload_t::load( const wcstring &cmd, bool reload )
+int autoload_t::load(const wcstring &cmd, bool reload)
{
- int res;
- CHECK_BLOCK( 0 );
+ int res;
+ CHECK_BLOCK(0);
ASSERT_IS_MAIN_THREAD();
- env_var_t path_var = env_get_string( env_var_name );
+ env_var_t path_var = env_get_string(env_var_name);
/*
Do we know where to look?
*/
- if( path_var.empty() )
+ if (path_var.empty())
return 0;
/* Check if the lookup path has changed. If so, drop all loaded files. path_var may only be inspected on the main thread. */
- if( path_var != this->last_path )
+ if (path_var != this->last_path)
{
this->last_path = path_var;
scoped_lock locker(lock);
@@ -93,10 +102,10 @@ int autoload_t::load( const wcstring &cmd, bool reload )
/** Warn and fail on infinite recursion. It's OK to do this because this function is only called on the main thread. */
if (this->is_loading(cmd))
{
- debug( 0,
- _( L"Could not autoload item '%ls', it is already being autoloaded. "
- L"This is a circular dependency in the autoloading scripts, please remove it."),
- cmd.c_str() );
+ debug(0,
+ _(L"Could not autoload item '%ls', it is already being autoloaded. "
+ L"This is a circular dependency in the autoloading scripts, please remove it."),
+ cmd.c_str());
return 1;
}
@@ -105,27 +114,27 @@ int autoload_t::load( const wcstring &cmd, bool reload )
/* Get the list of paths from which we will try to load */
std::vector<wcstring> path_list;
- tokenize_variable_array( path_var, path_list );
+ tokenize_variable_array(path_var, path_list);
- /* Try loading it */
- res = this->locate_file_and_maybe_load_it( cmd, true, reload, path_list );
+ /* Try loading it */
+ res = this->locate_file_and_maybe_load_it(cmd, true, reload, path_list);
/* Clean up */
bool erased = !! is_loading_set.erase(cmd);
assert(erased);
- return res;
+ return res;
}
-bool autoload_t::can_load( const wcstring &cmd, const env_vars_snapshot_t &vars )
+bool autoload_t::can_load(const wcstring &cmd, const env_vars_snapshot_t &vars)
{
const env_var_t path_var = vars.get(env_var_name);
if (path_var.missing_or_empty())
return false;
std::vector<wcstring> path_list;
- tokenize_variable_array( path_var, path_list );
- return this->locate_file_and_maybe_load_it( cmd, false, false, path_list );
+ tokenize_variable_array(path_var, path_list);
+ return this->locate_file_and_maybe_load_it(cmd, false, false, path_list);
}
static bool script_name_precedes_script_name(const builtin_script_t &script1, const builtin_script_t &script2)
@@ -133,20 +142,22 @@ static bool script_name_precedes_script_name(const builtin_script_t &script1, co
return wcscmp(script1.name, script2.name) < 0;
}
-void autoload_t::unload_all(void) {
+void autoload_t::unload_all(void)
+{
scoped_lock locker(lock);
this->evict_all_nodes();
}
/** Check whether the given command is loaded. */
-bool autoload_t::has_tried_loading( const wcstring &cmd )
+bool autoload_t::has_tried_loading(const wcstring &cmd)
{
scoped_lock locker(lock);
autoload_function_t * func = this->get_node(cmd);
return func != NULL;
}
-static bool is_stale(const autoload_function_t *func) {
+static bool is_stale(const autoload_function_t *func)
+{
/** Return whether this function is stale. Internalized functions can never be stale. */
return ! func->is_internalized && time(NULL) - func->access.last_checked > kAutoloadStalenessInterval;
}
@@ -155,11 +166,15 @@ autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcs
{
ASSERT_IS_LOCKED(lock);
autoload_function_t *func = this->get_node(cmd);
- if (! func) {
+ if (! func)
+ {
func = new autoload_function_t(cmd);
- if (allow_eviction) {
+ if (allow_eviction)
+ {
this->add_node(func);
- } else {
+ }
+ else
+ {
this->add_node_without_eviction(func);
}
}
@@ -178,11 +193,11 @@ autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcs
Result: if really_load is true, returns whether the function was loaded. Otherwise returns whether the function existed.
*/
-bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list )
+bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list)
{
/* Note that we are NOT locked in this function! */
- size_t i;
- bool reloaded = 0;
+ size_t i;
+ bool reloaded = 0;
/* Try using a cached function. If we really want the function to be loaded, require that it be really loaded. If we're not reloading, allow stale functions. */
{
@@ -196,22 +211,30 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
/* Determine if we can use this cached function */
bool use_cached;
- if (! func) {
+ if (! func)
+ {
/* Can't use a function that doesn't exist */
use_cached = false;
- } else if (really_load && ! func->is_placeholder && ! func->is_loaded) {
+ }
+ else if (really_load && ! func->is_placeholder && ! func->is_loaded)
+ {
/* Can't use an unloaded function */
use_cached = false;
- } else if ( ! allow_stale_functions && is_stale(func)) {
+ }
+ else if (! allow_stale_functions && is_stale(func))
+ {
/* Can't use a stale function */
use_cached = false;
- } else {
+ }
+ else
+ {
/* I guess we can use it */
use_cached = true;
}
/* If we can use this function, return whether we were able to access it */
- if (use_cached) {
+ if (use_cached)
+ {
return func->is_internalized || func->access.accessible;
}
}
@@ -235,7 +258,8 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
matching_builtin_script = found;
}
}
- if (matching_builtin_script) {
+ if (matching_builtin_script)
+ {
has_script_source = true;
script_source = str2wcstring(matching_builtin_script->def);
@@ -253,13 +277,14 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
if (! has_script_source)
{
/* Iterate over path searching for suitable completion files */
- for( i=0; i<path_list.size(); i++ )
+ for (i=0; i<path_list.size(); i++)
{
wcstring next = path_list.at(i);
wcstring path = next + L"/" + cmd + L".fish";
const file_access_attempt_t access = access_file(path, R_OK);
- if (access.accessible) {
+ if (access.accessible)
+ {
/* Found it! */
found_file = true;
@@ -269,7 +294,8 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
/* Generate the source if we need to load it */
bool need_to_load_function = really_load && (func == NULL || func->access.mod_time != access.mod_time || ! func->is_loaded);
- if (need_to_load_function) {
+ if (need_to_load_function)
+ {
/* Generate the script source */
wcstring esc = escape_string(path, 1);
@@ -277,7 +303,8 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
has_script_source = true;
/* Remove any loaded command because we are going to reload it. Note that this will deadlock if command_removed calls back into us. */
- if (func && func->is_loaded) {
+ if (func && func->is_loaded)
+ {
command_removed(cmd);
func->is_placeholder = false;
}
@@ -287,7 +314,8 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
}
/* Create the function if we haven't yet. This does not load it. Do not trigger eviction unless we are actually loading, because we don't want to evict off of the main thread. */
- if (! func) {
+ if (! func)
+ {
func = get_autoloaded_function_with_creation(cmd, really_load);
}
@@ -306,17 +334,21 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
Later we only research if the current time is at least five seconds later.
This way, the files won't be searched over and over again.
*/
- if( ! found_file && ! has_script_source )
+ if (! found_file && ! has_script_source)
{
scoped_lock locker(lock);
/* Generate a placeholder */
autoload_function_t *func = this->get_node(cmd);
- if (! func) {
+ if (! func)
+ {
func = new autoload_function_t(cmd);
func->is_placeholder = true;
- if (really_load) {
+ if (really_load)
+ {
this->add_node(func);
- } else {
+ }
+ else
+ {
this->add_node_without_eviction(func);
}
}
@@ -327,7 +359,7 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
/* If we have a script, either built-in or a file source, then run it */
if (really_load && has_script_source)
{
- if( exec_subshell( script_source) == -1 )
+ if (exec_subshell(script_source) == -1)
{
/*
Do nothing on failiure
@@ -336,9 +368,12 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
}
- if (really_load) {
+ if (really_load)
+ {
return reloaded;
- } else {
+ }
+ else
+ {
return found_file || has_script_source;
}
}
View
38 autoload.h
@@ -14,7 +14,8 @@
#include "lru.h"
/** A struct responsible for recording an attempt to access a file. */
-struct file_access_attempt_t {
+struct file_access_attempt_t
+{
time_t mod_time; /** The modification time of the file */
time_t last_checked; /** When we last checked the file */
bool accessible; /** Whether we believe we could access this file */
@@ -40,7 +41,8 @@ class env_vars_snapshot_t;
/**
A class that represents a path from which we can autoload, and the autoloaded contents.
*/
-class autoload_t : private lru_cache_t<autoload_function_t> {
+class autoload_t : private lru_cache_t<autoload_function_t>
+{
private:
/** Lock for thread safety */
@@ -58,34 +60,36 @@ class autoload_t : private lru_cache_t<autoload_function_t> {
/** The path from which we most recently autoloaded */
wcstring last_path;
- /**
- A table containing all the files that are currently being
- loaded. This is here to help prevent recursion.
- */
+ /**
+ A table containing all the files that are currently being
+ loaded. This is here to help prevent recursion.
+ */
std::set<wcstring> is_loading_set;
- bool is_loading(const wcstring &name) const {
+ bool is_loading(const wcstring &name) const
+ {
return is_loading_set.find(name) != is_loading_set.end();
}
- void remove_all_functions(void) {
+ void remove_all_functions(void)
+ {
this->evict_all_nodes();
}
- bool locate_file_and_maybe_load_it( const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list );
+ bool locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list);
virtual void node_was_evicted(autoload_function_t *node);
autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd, bool allow_eviction);
- protected:
+protected:
/** Overridable callback for when a command is removed */
virtual void command_removed(const wcstring &cmd) { }
- public:
+public:
/** Create an autoload_t for the given environment variable name */
- autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts, size_t script_count );
+ autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts, size_t script_count);
/** Destructor */
virtual ~autoload_t();
@@ -101,10 +105,10 @@ class autoload_t : private lru_cache_t<autoload_function_t> {
\param on_unload a callback function to run if a suitable file is found, which has not already been run. unload will also be called for old files which are unloaded.
\param reload wheter to recheck file timestamps on already loaded files
*/
- int load( const wcstring &cmd, bool reload );
+ int load(const wcstring &cmd, bool reload);
/** Check whether we have tried loading the given command. Does not do any I/O. */
- bool has_tried_loading( const wcstring &cmd );
+ bool has_tried_loading(const wcstring &cmd);
/**
Tell the autoloader that the specified file, in the specified path,
@@ -114,15 +118,15 @@ class autoload_t : private lru_cache_t<autoload_function_t> {
\param on_unload a callback function which will be called before (re)loading a file, may be used to unload the previous file.
\return non-zero if the file was removed, zero if the file had not yet been loaded
*/
- int unload( const wcstring &cmd );
+ int unload(const wcstring &cmd);
/**
Unloads all files.
*/
- void unload_all( );
+ void unload_all();
/** Check whether the given command could be loaded, but do not load it. */
- bool can_load( const wcstring &cmd, const env_vars_snapshot_t &vars );
+ bool can_load(const wcstring &cmd, const env_vars_snapshot_t &vars);
};
View
6,883 builtin.cpp
3,478 additions, 3,405 deletions not shown
View
16 builtin.h
@@ -15,9 +15,9 @@ class parser_t;
enum
{
- COMMAND_NOT_BUILTIN,
- BUILTIN_REGULAR,
- BUILTIN_FUNCTION
+ COMMAND_NOT_BUILTIN,
+ BUILTIN_REGULAR,
+ BUILTIN_FUNCTION
}
;
@@ -125,7 +125,7 @@ void builtin_destroy();
/**
Is there a builtin command with the given name?
*/
-int builtin_exists( const wcstring &cmd );
+int builtin_exists(const wcstring &cmd);
/**
Execute a builtin command
@@ -139,7 +139,7 @@ int builtin_exists( const wcstring &cmd );
\return the exit status of the builtin command
*/
-int builtin_run( parser_t &parser, const wchar_t * const *argv, const io_chain_t &io );
+int builtin_run(parser_t &parser, const wchar_t * const *argv, const io_chain_t &io);
/** Returns a list of all builtin names */
wcstring_list_t builtin_get_names(void);
@@ -150,7 +150,7 @@ void builtin_get_names(std::vector<completion_t> &list);
/**
Pushes a new set of input/output to the stack. The new stdin is supplied, a new set of output strings is created.
*/
-void builtin_push_io( parser_t &parser, int stdin_fd );
+void builtin_push_io(parser_t &parser, int stdin_fd);
/**
Pops a set of input/output from the stack. The output strings are destroued, but the input file is not closed.
@@ -161,7 +161,7 @@ void builtin_pop_io(parser_t &parser);
/**
Return a one-line description of the specified builtin.
*/
-wcstring builtin_get_desc( const wcstring &b );
+wcstring builtin_get_desc(const wcstring &b);
/**
@@ -177,6 +177,6 @@ const wchar_t *builtin_complete_get_temporary_buffer();
for the specified command.
*/
-wcstring builtin_help_get( parser_t &parser, const wchar_t *cmd );
+wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
#endif
View
854 builtin_commandline.cpp
@@ -34,23 +34,23 @@ Functions used for implementing the commandline builtin.
*/
enum
{
- STRING_MODE=1, /**< Operate on entire buffer */
- JOB_MODE, /**< Operate on job under cursor */
- PROCESS_MODE, /**< Operate on process under cursor */
- TOKEN_MODE /**< Operate on token under cursor */
+ STRING_MODE=1, /**< Operate on entire buffer */
+ JOB_MODE, /**< Operate on job under cursor */
+ PROCESS_MODE, /**< Operate on process under cursor */
+ TOKEN_MODE /**< Operate on token under cursor */
}
- ;
+;
/**
For text insertion, how should it be done
*/
enum
{
- REPLACE_MODE=1, /**< Replace current text */
- INSERT_MODE, /**< Insert at cursor position */
- APPEND_MODE /**< Insert at end of current token/command/buffer */
+ REPLACE_MODE=1, /**< Replace current text */
+ INSERT_MODE, /**< Insert at cursor position */
+ APPEND_MODE /**< Insert at end of current token/command/buffer */
}
- ;
+;
/**
Pointer to what the commandline builtin considers to be the current
@@ -68,7 +68,7 @@ static size_t current_cursor_pos = (size_t)(-1);
*/
static const wchar_t *get_buffer()
{
- return current_buffer;
+ return current_buffer;
}
/**
@@ -76,7 +76,7 @@ static const wchar_t *get_buffer()
*/
static size_t get_cursor_pos()
{
- return current_cursor_pos;
+ return current_cursor_pos;
}
@@ -88,46 +88,46 @@ static size_t get_cursor_pos()
\param insert the string to insert
\param append_mode can be one of REPLACE_MODE, INSERT_MODE or APPEND_MODE, affects the way the test update is performed
*/
-static void replace_part( const wchar_t *begin,
- const wchar_t *end,
- const wchar_t *insert,
- int append_mode )
+static void replace_part(const wchar_t *begin,
+ const wchar_t *end,
+ const wchar_t *insert,
+ int append_mode)
{
- const wchar_t *buff = get_buffer();
- size_t out_pos = get_cursor_pos();
+ const wchar_t *buff = get_buffer();
+ size_t out_pos = get_cursor_pos();
wcstring out;
out.append(buff, begin - buff);
- switch( append_mode)
- {
+ switch (append_mode)
+ {
case REPLACE_MODE:
{
- out.append(insert);
- out_pos = wcslen( insert ) + (begin-buff);
- break;
+ out.append(insert);
+ out_pos = wcslen(insert) + (begin-buff);
+ break;
}
case APPEND_MODE:
{
- out.append( begin, end-begin );
- out.append( insert );
- break;
+ out.append(begin, end-begin);
+ out.append(insert);
+ break;
}
case INSERT_MODE:
{
- long cursor = get_cursor_pos() -(begin-buff);
- out.append( begin, cursor );
- out.append( insert );
- out.append( begin+cursor, end-begin-cursor );
- out_pos += wcslen( insert );
- break;
+ long cursor = get_cursor_pos() -(begin-buff);
+ out.append(begin, cursor);
+ out.append(insert);
+ out.append(begin+cursor, end-begin-cursor);
+ out_pos += wcslen(insert);
+ break;
+ }
}
- }
- out.append( end );
- reader_set_buffer( out, out_pos );
+ out.append(end);
+ reader_set_buffer(out, out_pos);
}
/**
@@ -138,62 +138,62 @@ static void replace_part( const wchar_t *begin,
\param cut_at_cursor whether printing should stop at the surrent cursor position
\param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
*/
-static void write_part( const wchar_t *begin,
- const wchar_t *end,
- int cut_at_cursor,
- int tokenize )
+static void write_part(const wchar_t *begin,
+ const wchar_t *end,
+ int cut_at_cursor,
+ int tokenize)
{
- tokenizer tok;
- wcstring out;
- wchar_t *buff;
- size_t pos;
-
- pos = get_cursor_pos()-(begin-get_buffer());
+ tokenizer tok;
+ wcstring out;
+ wchar_t *buff;
+ size_t pos;
- if( tokenize )
- {
- buff = wcsndup( begin, end-begin );
-// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
- out.clear();
+ pos = get_cursor_pos()-(begin-get_buffer());
- for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
- tok_has_next( &tok );
- tok_next( &tok ) )
+ if (tokenize)
{
- if( (cut_at_cursor) &&
- (tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
- break;
+ buff = wcsndup(begin, end-begin);
+// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
+ out.clear();
- switch( tok_last_type( &tok ) )
- {
- case TOK_STRING:
+ for (tok_init(&tok, buff, TOK_ACCEPT_UNFINISHED);
+ tok_has_next(&tok);
+ tok_next(&tok))
{
- out.append(escape_string(tok_last( &tok ), UNESCAPE_INCOMPLETE));
- out.push_back(L'\n');
- break;
+ if ((cut_at_cursor) &&
+ (tok_get_pos(&tok)+wcslen(tok_last(&tok)) >= pos))
+ break;
+
+ switch (tok_last_type(&tok))
+ {
+ case TOK_STRING:
+ {
+ out.append(escape_string(tok_last(&tok), UNESCAPE_INCOMPLETE));
+ out.push_back(L'\n');
+ break;
+ }
+
+ }
}
- }
- }
-
stdout_buffer.append(out);
- free( buff );
- tok_destroy( &tok );
- }
- else
- {
- if( cut_at_cursor )
- {
- end = begin+pos;
+ free(buff);
+ tok_destroy(&tok);
}
+ else
+ {
+ if (cut_at_cursor)
+ {
+ end = begin+pos;
+ }
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
stdout_buffer.append(begin, end - begin);
stdout_buffer.append(L"\n");
- }
+ }
}
@@ -201,446 +201,446 @@ static void write_part( const wchar_t *begin,
The commandline builtin. It is used for specifying a new value for
the commandline.
*/
-static int builtin_commandline( parser_t &parser, wchar_t **argv )
+static int builtin_commandline(parser_t &parser, wchar_t **argv)
{
- int buffer_part=0;
- int cut_at_cursor=0;
-
- int argc = builtin_count_args( argv );
- int append_mode=0;
+ int buffer_part=0;
+ int cut_at_cursor=0;
- int function_mode = 0;
+ int argc = builtin_count_args(argv);
+ int append_mode=0;
- int tokenize = 0;
+ int function_mode = 0;
- int cursor_mode = 0;
- int line_mode = 0;
- int search_mode = 0;
- const wchar_t *begin, *end;
+ int tokenize = 0;
- current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
- if( current_buffer )
- {
- current_cursor_pos = wcslen( current_buffer );
- }
- else
- {
- current_buffer = reader_get_buffer();
- current_cursor_pos = reader_get_cursor_pos();
- }
+ int cursor_mode = 0;
+ int line_mode = 0;
+ int search_mode = 0;
+ const wchar_t *begin, *end;
- if( !get_buffer() )
- {
- if (is_interactive_session)
+ current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
+ if (current_buffer)
{
- /*
- Prompt change requested while we don't have
- a prompt, most probably while reading the
- init files. Just ignore it.
- */
- return 1;
+ current_cursor_pos = wcslen(current_buffer);
}
+ else
+ {
+ current_buffer = reader_get_buffer();
+ current_cursor_pos = reader_get_cursor_pos();
+ }
+
+ if (!get_buffer())
+ {
+ if (is_interactive_session)
+ {
+ /*
+ Prompt change requested while we don't have
+ a prompt, most probably while reading the
+ init files. Just ignore it.
+ */
+ return 1;
+ }
stderr_buffer.append(argv[0]);
stderr_buffer.append(L": Can not set commandline in non-interactive mode\n");
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ return 1;
+ }
- woptind=0;
+ woptind=0;
- while( 1 )
- {
- static const struct woption
- long_options[] =
- {
- {
- L"append", no_argument, 0, 'a'
- }
- ,
- {
- L"insert", no_argument, 0, 'i'
- }
- ,
- {
- L"replace", no_argument, 0, 'r'
- }
- ,
- {
- L"current-job", no_argument, 0, 'j'
- }
- ,
- {
- L"current-process", no_argument, 0, 'p'
- }
- ,
- {
- L"current-token", no_argument, 0, 't'
- }
- ,
- {
- L"current-buffer", no_argument, 0, 'b'
- }
- ,
- {
- L"cut-at-cursor", no_argument, 0, 'c'
- }
- ,
- {
- L"function", no_argument, 0, 'f'
- }
- ,
- {
- L"tokenize", no_argument, 0, 'o'
- }
- ,
- {
- L"help", no_argument, 0, 'h'
- }
- ,
+ while (1)
+ {
+ static const struct woption
+ long_options[] =
{
- L"input", required_argument, 0, 'I'
+ {
+ L"append", no_argument, 0, 'a'
+ }
+ ,
+ {
+ L"insert", no_argument, 0, 'i'
+ }
+ ,
+ {
+ L"replace", no_argument, 0, 'r'
+ }
+ ,
+ {
+ L"current-job", no_argument, 0, 'j'
+ }
+ ,
+ {
+ L"current-process", no_argument, 0, 'p'
+ }
+ ,
+ {
+ L"current-token", no_argument, 0, 't'
+ }
+ ,
+ {
+ L"current-buffer", no_argument, 0, 'b'
+ }
+ ,
+ {
+ L"cut-at-cursor", no_argument, 0, 'c'
+ }
+ ,
+ {
+ L"function", no_argument, 0, 'f'
+ }
+ ,
+ {
+ L"tokenize", no_argument, 0, 'o'
+ }
+ ,
+ {
+ L"help", no_argument, 0, 'h'
+ }
+ ,
+ {
+ L"input", required_argument, 0, 'I'
+ }
+ ,
+ {
+ L"cursor", no_argument, 0, 'C'
+ }
+ ,
+ {
+ L"line", no_argument, 0, 'L'
+ }
+ ,
+ {
+ L"search-mode", no_argument, 0, 'S'
+ }
+ ,
+ {
+ 0, 0, 0, 0
+ }
}
- ,
+ ;
+
+ int opt_index = 0;
+
+ int opt = wgetopt_long(argc,
+ argv,
+ L"abijpctwforhI:CLS",
+ long_options,
+ &opt_index);
+ if (opt == -1)
+ break;
+
+ switch (opt)
{
- L"cursor", no_argument, 0, 'C'
+ case 0:
+ if (long_options[opt_index].flag != 0)
+ break;
+ append_format(stderr_buffer,
+ BUILTIN_ERR_UNKNOWN,
+ argv[0],
+ long_options[opt_index].name);
+ builtin_print_help(parser, argv[0], stderr_buffer);
+
+ return 1;
+
+ case L'a':
+ append_mode = APPEND_MODE;
+ break;
+
+ case L'b':
+ buffer_part = STRING_MODE;
+ break;
+
+
+ case L'i':
+ append_mode = INSERT_MODE;
+ break;
+
+ case L'r':
+ append_mode = REPLACE_MODE;
+ break;
+
+ case 'c':
+ cut_at_cursor=1;
+ break;
+
+ case 't':
+ buffer_part = TOKEN_MODE;
+ break;
+
+ case 'j':
+ buffer_part = JOB_MODE;
+ break;
+
+ case 'p':
+ buffer_part = PROCESS_MODE;
+ break;
+
+ case 'f':
+ function_mode=1;
+ break;
+
+ case 'o':
+ tokenize=1;
+ break;
+
+ case 'I':
+ current_buffer = woptarg;
+ current_cursor_pos = wcslen(woptarg);
+ break;
+
+ case 'C':
+ cursor_mode = 1;
+ break;
+
+ case 'L':
+ line_mode = 1;
+ break;
+
+ case 'S':
+ search_mode = 1;
+ break;
+
+ case 'h':
+ builtin_print_help(parser, argv[0], stdout_buffer);
+ return 0;
+
+ case L'?':
+ builtin_unknown_option(parser, argv[0], argv[woptind-1]);
+ return 1;
}
- ,
+ }
+
+ if (function_mode)
+ {
+ int i;
+
+ /*
+ Check for invalid switch combinations
+ */
+ if (buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode)
{
- L"line", no_argument, 0, 'L'
+ append_format(stderr_buffer,
+ BUILTIN_ERR_COMBO,
+ argv[0]);
+
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ return 1;
}
- ,
+
+
+ if (argc == woptind)
{
- L"search-mode", no_argument, 0, 'S'
+ append_format(stderr_buffer,
+ BUILTIN_ERR_MISSING,
+ argv[0]);
+
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ return 1;
}
- ,
+ for (i=woptind; i<argc; i++)
{
- 0, 0, 0, 0
+ wint_t c = input_function_get_code(argv[i]);
+ if (c != -1)
+ {
+ /*
+ input_unreadch inserts the specified keypress or
+ readline function at the top of the stack of unused
+ keypresses
+ */
+ input_unreadch(c);
+ }
+ else
+ {
+ append_format(stderr_buffer,
+ _(L"%ls: Unknown input function '%ls'\n"),
+ argv[0],
+ argv[i]);
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ return 1;
+ }
}
- }
- ;
- int opt_index = 0;
-
- int opt = wgetopt_long( argc,
- argv,
- L"abijpctwforhI:CLS",
- long_options,
- &opt_index );
- if( opt == -1 )
- break;
+ return 0;
+ }
- switch( opt )
+ /*
+ Check for invalid switch combinations
+ */
+ if ((search_mode || line_mode || cursor_mode) && (argc-woptind > 1))
{
- case 0:
- if(long_options[opt_index].flag != 0)
- break;
- append_format( stderr_buffer,
- BUILTIN_ERR_UNKNOWN,
- argv[0],
- long_options[opt_index].name );
- builtin_print_help( parser, argv[0], stderr_buffer );
+ append_format(stderr_buffer,
+ argv[0],
+ L": Too many arguments\n",
+ NULL);
+ builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
+ }
- case L'a':
- append_mode = APPEND_MODE;
- break;
-
- case L'b':
- buffer_part = STRING_MODE;
- break;
-
-
- case L'i':
- append_mode = INSERT_MODE;
- break;
-
- case L'r':
- append_mode = REPLACE_MODE;
- break;
-
- case 'c':
- cut_at_cursor=1;
- break;
-
- case 't':
- buffer_part = TOKEN_MODE;
- break;
-
- case 'j':
- buffer_part = JOB_MODE;
- break;
-
- case 'p':
- buffer_part = PROCESS_MODE;
- break;
-
- case 'f':
- function_mode=1;
- break;
+ if ((buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode))
+ {
+ append_format(stderr_buffer,
+ BUILTIN_ERR_COMBO,
+ argv[0]);
- case 'o':
- tokenize=1;
- break;
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ return 1;
+ }
- case 'I':
- current_buffer = woptarg;
- current_cursor_pos = wcslen( woptarg );
- break;
- case 'C':
- cursor_mode = 1;
- break;
+ if ((tokenize || cut_at_cursor) && (argc-woptind))
+ {
+ append_format(stderr_buffer,
+ BUILTIN_ERR_COMBO2,
+ argv[0],
+ L"--cut-at-cursor and --tokenize can not be used when setting the commandline");
- case 'L':
- line_mode = 1;
- break;
- case 'S':
- search_mode = 1;
- break;
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ return 1;
+ }
- case 'h':
- builtin_print_help( parser, argv[0], stdout_buffer );
- return 0;
+ if (append_mode && !(argc-woptind))
+ {
+ append_format(stderr_buffer,
+ BUILTIN_ERR_COMBO2,
+ argv[0],
+ L"insertion mode switches can not be used when not in insertion mode");
- case L'?':
- builtin_unknown_option( parser, argv[0], argv[woptind-1] );
+ builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
}
- }
-
- if( function_mode )
- {
- int i;
/*
- Check for invalid switch combinations
+ Set default modes
*/
- if( buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode )
+ if (!append_mode)
{
- append_format(stderr_buffer,
- BUILTIN_ERR_COMBO,
- argv[0] );
-
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
+ append_mode = REPLACE_MODE;
}
-
- if( argc == woptind )
+ if (!buffer_part)
{
- append_format(stderr_buffer,
- BUILTIN_ERR_MISSING,
- argv[0] );
-
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
- for( i=woptind; i<argc; i++ )
- {
- wint_t c = input_function_get_code( argv[i] );
- if( c != -1 )
- {
- /*
- input_unreadch inserts the specified keypress or
- readline function at the top of the stack of unused
- keypresses
- */
- input_unreadch(c);
- }
- else
- {
- append_format(stderr_buffer,
- _(L"%ls: Unknown input function '%ls'\n"),
- argv[0],
- argv[i] );
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
+ buffer_part = STRING_MODE;
}
- return 0;
- }
-
- /*
- Check for invalid switch combinations
- */
- if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
- {
-
- append_format(stderr_buffer,
- argv[0],
- L": Too many arguments\n",
- NULL );
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
-
- if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
- {
- append_format(stderr_buffer,
- BUILTIN_ERR_COMBO,
- argv[0] );
-
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
-
-
- if( (tokenize || cut_at_cursor) && (argc-woptind) )
- {
- append_format(stderr_buffer,
- BUILTIN_ERR_COMBO2,
- argv[0],
- L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
-
-
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
-
- if( append_mode && !(argc-woptind) )
- {
- append_format(stderr_buffer,
- BUILTIN_ERR_COMBO2,
- argv[0],
- L"insertion mode switches can not be used when not in insertion mode" );
-
- builtin_print_help( parser, argv[0], stderr_buffer );
- return 1;
- }
-
- /*
- Set default modes
- */
- if( !append_mode )
- {
- append_mode = REPLACE_MODE;
- }
-
- if( !buffer_part )
- {
- buffer_part = STRING_MODE;
- }
-
- if( cursor_mode )
- {
- if( argc-woptind )
+ if (cursor_mode)
{
- wchar_t *endptr;
- long new_pos;
- errno = 0;
+ if (argc-woptind)
+ {
+ wchar_t *endptr;
+ long new_pos;
+ errno = 0;
+
+ new_pos = wcstol(argv[woptind], &endptr, 10);
+ if (*endptr || errno)
+ {
+ append_format(stderr_buffer,
+ BUILTIN_ERR_NOT_NUMBER,
+ argv[0],
+ argv[woptind]);
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ }
+
+ current_buffer = reader_get_buffer();
+ new_pos = maxi(0L, mini(new_pos, (long)wcslen(current_buffer)));
+ reader_set_buffer(current_buffer, (size_t)new_pos);
+ return 0;
+ }
+ else
+ {
+ append_format(stdout_buffer, L"%lu\n", (unsigned long)reader_get_cursor_pos());
+ return 0;
+ }
- new_pos = wcstol( argv[woptind], &endptr, 10 );
- if( *endptr || errno )
- {
- append_format(stderr_buffer,
- BUILTIN_ERR_NOT_NUMBER,
- argv[0],
- argv[woptind] );
- builtin_print_help( parser, argv[0], stderr_buffer );
- }
-
- current_buffer = reader_get_buffer();
- new_pos = maxi( 0L, mini( new_pos, (long)wcslen( current_buffer ) ) );
- reader_set_buffer( current_buffer, (size_t)new_pos );
- return 0;
}
- else
- {
- append_format(stdout_buffer, L"%lu\n", (unsigned long)reader_get_cursor_pos() );
- return 0;
- }
-
- }
- if( line_mode )
- {
- size_t pos = reader_get_cursor_pos();
- const wchar_t *buff = reader_get_buffer();
- append_format(stdout_buffer, L"%lu\n", (unsigned long)parse_util_lineno( buff, pos ) );
- return 0;
+ if (line_mode)
+ {
+ size_t pos = reader_get_cursor_pos();
+ const wchar_t *buff = reader_get_buffer();
+ append_format(stdout_buffer, L"%lu\n", (unsigned long)parse_util_lineno(buff, pos));
+ return 0;
- }
+ }
- if( search_mode )
- {
- return !reader_search_mode();
- }
+ if (search_mode)
+ {
+ return !reader_search_mode();
+ }
- switch( buffer_part )
- {
+ switch (buffer_part)
+ {
case STRING_MODE:
{
- begin = get_buffer();
- end = begin+wcslen(begin);
- break;
+ begin = get_buffer();
+ end = begin+wcslen(begin);
+ break;
}
case PROCESS_MODE:
{
- parse_util_process_extent( get_buffer(),
- get_cursor_pos(),
- &begin,
- &end );
- break;
+ parse_util_process_extent(get_buffer(),
+ get_cursor_pos(),
+ &begin,
+ &end);
+ break;
}
case JOB_MODE:
{
- parse_util_job_extent( get_buffer(),
- get_cursor_pos(),
- &begin,
- &end );
- break;
+ parse_util_job_extent(get_buffer(),
+ get_cursor_pos(),
+ &begin,
+ &end);
+ break;
}
case TOKEN_MODE:
{
- parse_util_token_extent( get_buffer(),
- get_cursor_pos(),
- &begin,
- &end,
- 0, 0 );
- break;
+ parse_util_token_extent(get_buffer(),
+ get_cursor_pos(),
+ &begin,
+ &end,
+ 0, 0);
+ break;
}
- }
+ }
- switch(argc-woptind)
- {
+ switch (argc-woptind)
+ {
case 0:
{
- write_part( begin, end, cut_at_cursor, tokenize );
- break;
+ write_part(begin, end, cut_at_cursor, tokenize);
+ break;
}
case 1:
{
- replace_part( begin, end, argv[woptind], append_mode );
- break;
+ replace_part(begin, end, argv[woptind], append_mode);
+ break;
}
default:
{
- wcstring sb = argv[woptind];
- int i;
+ wcstring sb = argv[woptind];
+ int i;
- for( i=woptind+1; i<argc; i++ )
- {
- sb.push_back(L'\n');
- sb.append(argv[i]);
- }
+ for (i=woptind+1; i<argc; i++)
+ {
+ sb.push_back(L'\n');
+ sb.append(argv[i]);
+ }
- replace_part( begin, end, sb.c_str(), append_mode );
+ replace_part(begin, end, sb.c_str(), append_mode);
- break;
+ break;
+ }
}
- }
- return 0;
+ return 0;
}
View
938 builtin_complete.cpp
@@ -42,201 +42,201 @@ static const wchar_t *temporary_buffer;
/**
Silly function
*/
-static void builtin_complete_add2( const wchar_t *cmd,
- int cmd_type,
- const wchar_t *short_opt,
- const wcstring_list_t &gnu_opt,
- const wcstring_list_t &old_opt,
- int result_mode,
- const wchar_t *condition,
- const wchar_t *comp,
- const wchar_t *desc,
- int flags )
+static void builtin_complete_add2(const wchar_t *cmd,
+ int cmd_type,
+ const wchar_t *short_opt,
+ const wcstring_list_t &gnu_opt,
+ const wcstring_list_t &old_opt,
+ int result_mode,
+ const wchar_t *condition,
+ const wchar_t *comp,
+ const wchar_t *desc,
+ int flags)
{
- size_t i;
- const wchar_t *s;
-
- for( s=short_opt; *s; s++ )
- {
- complete_add( cmd,
- cmd_type,
- *s,
- 0,
- 0,
- result_mode,
- condition,
- comp,
- desc,
- flags );
- }
-
- for( i=0; i<gnu_opt.size(); i++ )
- {
- complete_add( cmd,
- cmd_type,
- 0,
- gnu_opt.at(i).c_str(),
- 0,
- result_mode,
- condition,
- comp,
- desc,
- flags );
- }
-
- for( i=0; i<old_opt.size(); i++ )
- {
- complete_add( cmd,
- cmd_type,
- 0,
- old_opt.at(i).c_str(),
- 1,
- result_mode,
- condition,
- comp,
- desc,
- flags );
- }
-
- if( old_opt.size() == 0 && gnu_opt.size() == 0 && wcslen(short_opt) == 0 )
- {
- complete_add( cmd,
- cmd_type,
- 0,
- 0,
- 0,
- result_mode,
- condition,
- comp,
- desc,
- flags );
- }
+ size_t i;
+ const wchar_t *s;
+
+ for (s=short_opt; *s; s++)
+ {
+ complete_add(cmd,
+ cmd_type,
+ *s,
+ 0,
+ 0,
+ result_mode,
+ condition,
+ comp,
+ desc,
+ flags);
+ }
+
+ for (i=0; i<gnu_opt.size(); i++)
+ {
+ complete_add(cmd,
+ cmd_type,
+ 0,
+ gnu_opt.at(i).c_str(),
+ 0,
+ result_mode,
+ condition,
+ comp,
+ desc,
+ flags);
+ }
+
+ for (i=0; i<old_opt.size(); i++)
+ {
+ complete_add(cmd,
+ cmd_type,
+ 0,
+ old_opt.at(i).c_str(),
+ 1,
+ result_mode,
+ condition,
+ comp,
+ desc,
+ flags);
+ }
+
+ if (old_opt.size() == 0 && gnu_opt.size() == 0 && wcslen(short_opt) == 0)
+ {
+ complete_add(cmd,
+ cmd_type,
+ 0,
+ 0,
+ 0,
+ result_mode,
+ condition,
+ comp,
+ desc,
+ flags);
+ }
}
/**
Silly function
*/
-static void builtin_complete_add( const wcstring_list_t &cmd,
- const wcstring_list_t &path,
- const wchar_t *short_opt,
- wcstring_list_t &gnu_opt,
- wcstring_list_t &old_opt,
- int result_mode,
- int authoritative,
- const wchar_t *condition,
- const wchar_t *comp,
- const wchar_t *desc,
- int flags )
+static void builtin_complete_add(const wcstring_list_t &cmd,
+ const wcstring_list_t &path,
+ const wchar_t *short_opt,
+ wcstring_list_t &gnu_opt,
+ wcstring_list_t &old_opt,
+ int result_mode,
+ int authoritative,
+ const wchar_t *condition,
+ const wchar_t *comp,
+ const wchar_t *desc,
+ int flags)
{
- for( size_t i=0; i<cmd.size(); i++ )
- {
- builtin_complete_add2( cmd.at(i).c_str(),
- COMMAND,
- short_opt,
- gnu_opt,
- old_opt,
- result_mode,
- condition,
- comp,
- desc,
- flags );
-
- if( authoritative != -1 )
+ for (size_t i=0; i<cmd.size(); i++)
{
- complete_set_authoritative( cmd.at(i).c_str(),
- COMMAND,
- authoritative );
+ builtin_complete_add2(cmd.at(i).c_str(),
+ COMMAND,
+ short_opt,
+ gnu_opt,
+ old_opt,
+ result_mode,
+ condition,
+ comp,
+ desc,
+ flags);
+
+ if (authoritative != -1)
+ {
+ complete_set_authoritative(cmd.at(i).c_str(),
+ COMMAND,
+ authoritative);
+ }
+
}
- }
-
- for( size_t i=0; i<path.size(); i++ )
- {
- builtin_complete_add2( path.at(i).c_str(),
- PATH,
- short_opt,
- gnu_opt,
- old_opt,
- result_mode,
- condition,
- comp,
- desc,
- flags );
-
- if( authoritative != -1 )
+ for (size_t i=0; i<path.size(); i++)
{
- complete_set_authoritative( path.at(i).c_str(),
- PATH,
- authoritative );
- }
+ builtin_complete_add2(path.at(i).c_str(),
+ PATH,
+ short_opt,
+ gnu_opt,
+ old_opt,
+ result_mode,
+ condition,
+ comp,
+ desc,
+ flags);
+
+ if (authoritative != -1)
+ {
+ complete_set_authoritative(path.at(i).c_str(),
+ PATH,
+ authoritative);
+ }
- }
+ }
}
/**
Silly function
*/
-static void builtin_complete_remove3( const wchar_t *cmd,
- int cmd_type,
- wchar_t short_opt,
- const wcstring_list_t &long_opt )
+static void builtin_complete_remove3(const wchar_t *cmd,
+ int cmd_type,
+ wchar_t short_opt,
+ const wcstring_list_t &long_opt)
{
- for( size_t i=0; i<long_opt.size(); i++ )
- {
- complete_remove( cmd,
- cmd_type,
- short_opt,
- long_opt.at(i).c_str());
- }
+ for (size_t i=0; i<long_opt.size(); i++)
+ {
+ complete_remove(cmd,
+ cmd_type,
+ short_opt,
+ long_opt.at(i).c_str());
+ }
}
/**
Silly function
*/
-static void builtin_complete_remove2( const wchar_t *cmd,
- int cmd_type,
- const wchar_t *short_opt,
- const wcstring_list_t &gnu_opt,
- const wcstring_list_t &old_opt )
+static void builtin_complete_remove2(const wchar_t *cmd,
+ int cmd_type,
+ const wchar_t *short_opt,
+ const wcstring_list_t &gnu_opt,
+ const wcstring_list_t &old_opt)
{
- const wchar_t *s = (wchar_t *)short_opt;
- if( *s )
- {
- for( ; *s; s++ )
+ const wchar_t *s = (wchar_t *)short_opt;
+ if (*s)
{
- if( old_opt.size() == 0 && gnu_opt.size() == 0 )
- {
- complete_remove(cmd,
- cmd_type,
- *s,
- 0 );
-
- }
- else
- {
- builtin_complete_remove3( cmd,
- cmd_type,
- *s,
- gnu_opt );
- builtin_complete_remove3( cmd,
- cmd_type,
- *s,
- old_opt );
- }
+ for (; *s; s++)
+ {
+ if (old_opt.size() == 0 && gnu_opt.size() == 0)
+ {
+ complete_remove(cmd,
+ cmd_type,
+ *s,
+ 0);
+
+ }
+ else
+ {
+ builtin_complete_remove3(cmd,
+ cmd_type,
+ *s,
+ gnu_opt);
+ builtin_complete_remove3(cmd,
+ cmd_type,
+ *s,
+ old_opt);
+ }
+ }
}
- }
- else
- {
- builtin_complete_remove3( cmd,
- cmd_type,
- 0,
- gnu_opt );
- builtin_complete_remove3( cmd,
- cmd_type,
- 0,
- old_opt );
+ else
+ {
+ builtin_complete_remove3(cmd,
+ cmd_type,
+ 0,
+ gnu_opt);
+ builtin_complete_remove3(cmd,
+ cmd_type,
+ 0,
+ old_opt);
- }
+ }
}
@@ -244,29 +244,29 @@ static void builtin_complete_remove2( const wchar_t *cmd,
/**
Silly function
*/
-static void builtin_complete_remove( const wcstring_list_t &cmd,
- const wcstring_list_t &path,
- const wchar_t *short_opt,
- const wcstring_list_t &gnu_opt,
- const wcstring_list_t &old_opt )
+static void builtin_complete_remove(const wcstring_list_t &cmd,
+ const wcstring_list_t &path,
+ const wchar_t *short_opt,
+ const wcstring_list_t &gnu_opt,
+ const wcstring_list_t &old_opt)
{
- for( size_t i=0; i<cmd.size(); i++ )
- {
- builtin_complete_remove2( cmd.at(i).c_str(),
- COMMAND,
- short_opt,
- gnu_opt,
- old_opt );
- }
-
- for( size_t i=0; i<path.size(); i++ )
- {
- builtin_complete_remove2( path.at(i).c_str(),
- PATH,
- short_opt,
- gnu_opt,
- old_opt );
- }
+ for (size_t i=0; i<cmd.size(); i++)
+ {
+ builtin_complete_remove2(cmd.at(i).c_str(),
+ COMMAND,
+ short_opt,
+ gnu_opt,
+ old_opt);
+ }
+
+ for (size_t i=0; i<path.size(); i++)
+ {
+ builtin_complete_remove2(path.at(i).c_str(),
+ PATH,
+ short_opt,
+ gnu_opt,
+ old_opt);
+ }
}
@@ -274,7 +274,7 @@ static void builtin_complete_remove( const wcstring_list_t &cmd,
const wchar_t *builtin_complete_get_temporary_buffer()
{
ASSERT_IS_MAIN_THREAD();
- return temporary_buffer;
+ return temporary_buffer;
}
/**
@@ -282,345 +282,345 @@ const wchar_t *builtin_complete_get_temporary_buffer()
tab-completions. Calls the functions in complete.c for any heavy
lifting. Defined in builtin_complete.c
*/
-static int builtin_complete( parser_t &parser, wchar_t **argv )
+static int builtin_complete(parser_t &parser, wchar_t **argv)
{
ASSERT_IS_MAIN_THREAD();
- bool res=false;
- int argc=0;
- int result_mode=SHARED;
- int remove = 0;
- int authoritative = -1;
- int flags = COMPLETE_AUTO_SPACE;
+ bool res=false;
+ int argc=0;
+ int result_mode=SHARED;
+ int remove = 0;
+ int authoritative = -1;
+ int flags = COMPLETE_AUTO_SPACE;
- wcstring short_opt;
- wcstring_list_t gnu_opt, old_opt;
- const wchar_t *comp=L"", *desc=L"", *condition=L"";
+ wcstring short_opt;
+ wcstring_list_t gnu_opt, old_opt;
+ const wchar_t *comp=L"", *desc=L"", *condition=L"";
bool do_complete = false;
wcstring do_complete_param;
- wcstring_list_t cmd;
- wcstring_list_t path;
+ wcstring_list_t cmd;
+ wcstring_list_t path;
- static int recursion_level=0;
+ static int recursion_level=0;
- argc = builtin_count_args( argv );
+ argc = builtin_count_args(argv);
- woptind=0;
+ woptind=0;
- while( ! res )
- {
- static const struct woption
- long_options[] =
- {
- {
- L"exclusive", no_argument, 0, 'x'
- }
- ,
- {
- L"no-files", no_argument, 0, 'f'
- }
- ,
- {
- L"require-parameter", no_argument, 0, 'r'
- }
- ,
- {
- L"path", required_argument, 0, 'p'
- }
- ,
- {
- L"command", required_argument, 0, 'c'
- }
- ,
- {
- L"short-option", required_argument, 0, 's'
- }
- ,
- {
- L"long-option", required_argument, 0, 'l'
- }
- ,
- {
- L"old-option", required_argument, 0, 'o'
- }
- ,
- {
- L"description", required_argument, 0, 'd'
- }
- ,
- {
- L"arguments", required_argument, 0, 'a'
- }
- ,
- {
- L"erase", no_argument, 0, 'e'
- }
- ,
- {
- L"unauthoritative", no_argument, 0, 'u'
- }
- ,
- {
- L"authoritative", no_argument, 0, 'A'
- }
- ,
- {
- L"condition", required_argument, 0, 'n'
- }
- ,
- {
- L"do-complete", optional_argument, 0, 'C'
- }
- ,
- {
- L"help", no_argument, 0, 'h'
- }
- ,
+ while (! res)
+ {
+ static const struct woption
+ long_options[] =
{
- 0, 0, 0, 0
+ {
+ L"exclusive", no_argument, 0, 'x'
+ }
+ ,
+ {
+ L"no-files", no_argument, 0, 'f'
+ }
+ ,
+ {
+ L"require-parameter", no_argument, 0, 'r'
+ }
+ ,
+ {
+ L"path", required_argument, 0, 'p'
+ }
+ ,
+ {
+ L"command", required_argument, 0, 'c'
+ }
+ ,
+ {
+ L"short-option", required_argument, 0, 's'
+ }
+ ,
+ {
+ L"long-option", required_argument, 0, 'l'
+ }
+ ,
+ {
+ L"old-option", required_argument, 0, 'o'
+ }
+ ,
+ {
+ L"description", required_argument, 0, 'd'
+ }
+ ,
+ {
+ L"arguments", required_argument, 0, 'a'
+ }
+ ,
+ {
+ L"erase", no_argument, 0, 'e'
+ }
+ ,
+ {
+ L"unauthoritative", no_argument, 0, 'u'
+ }
+ ,
+ {
+ L"authoritative", no_argument, 0, 'A'
+ }
+ ,
+ {
+ L"condition", required_argument, 0, 'n'
+ }
+ ,
+ {
+ L"do-complete", optional_argument, 0, 'C'
+ }
+ ,
+ {
+ L"help", no_argument, 0, 'h'
+ }
+ ,
+ {
+ 0, 0, 0, 0
+ }
}
- }
- ;
+ ;
- int opt_index = 0;
+ int opt_index = 0;
- int opt = wgetopt_long( argc,
- argv,
- L"a:c:p:s:l:o:d:frxeuAn:C::h",
- long_options,
- &opt_index );
- if( opt == -1 )
- break;
+ int opt = wgetopt_long(argc,
+ argv,
+ L"a:c:p:s:l:o:d:frxeuAn:C::h",
+ long_options,
+ &opt_index);
+ if (opt == -1)
+ break;
- switch( opt )
- {
- case 0:
- if(long_options[opt_index].flag != 0)
- break;
- append_format(stderr_buffer,
- BUILTIN_ERR_UNKNOWN,
- argv[0],
- long_options[opt_index].name );
- builtin_print_help( parser, argv[0], stderr_buffer );
+ switch (opt)
+ {
+ case 0:
+ if (long_options[opt_index].flag != 0)
+ break;
+ append_format(stderr_buffer,
+ BUILTIN_ERR_UNKNOWN,
+ argv[0],
+ long_options[opt_index].name);
+ builtin_print_help(parser, argv[0], stderr_buffer);
- res = true;
- break;
+ res = true;
+ break;
- case 'x':
- result_mode |= EXCLUSIVE;
- break;
+ case 'x':
+ result_mode |= EXCLUSIVE;
+ break;
- case 'f':
- result_mode |= NO_FILES;
- break;
+ case 'f':
+ result_mode |= NO_FILES;
+ break;
- case 'r':
- result_mode |= NO_COMMON;
- break;
+ case 'r':
+ result_mode |= NO_COMMON;
+ break;
- case 'p':
- case 'c':
- {
- wcstring tmp = woptarg;
- if (unescape_string(tmp, 1))
+ case 'p':
+ case 'c':
{
- if (opt=='p')
- path.push_back(tmp);
- else
- cmd.push_back(tmp);
+ wcstring tmp = woptarg;
+ if (unescape_string(tmp, 1))
+ {
+ if (opt=='p')
+ path.push_back(tmp);
+ else
+ cmd.push_back(tmp);
+ }
+ else
+ {
+ append_format(stderr_buffer, L"%ls: Invalid token '%ls'\n", argv[0], woptarg);
+ res = true;
+ }
+ break;
}
- else
- {
- append_format(stderr_buffer, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
- res = true;
- }
- break;
- }
- case 'd':
- desc = woptarg;
- break;
+ case 'd':
+ desc = woptarg;
+ break;
- case 'u':
- authoritative=0;
- break;
+ case 'u':
+ authoritative=0;
+ break;
- case 'A':
- authoritative=1;
- break;
+ case 'A':
+ authoritative=1;
+ break;
- case 's':
- short_opt.append(woptarg);
- break;
+ case 's':
+ short_opt.append(woptarg);
+ break;
- case 'l':
- gnu_opt.push_back(woptarg);
- break;
+ case 'l':
+ gnu_opt.push_back(woptarg);
+ break;
- case 'o':
- old_opt.push_back(woptarg);
- break;
+ case 'o':
+ old_opt.push_back(woptarg);
+ break;
- case 'a':
- comp = woptarg;
- break;
+ case 'a':
+ comp = woptarg;
+ break;
- case 'e':
- remove = 1;
- break;
+ case 'e':
+ remove = 1;
+ break;
- case 'n':
- condition = woptarg;
- break;
+ case 'n':
+ condition = woptarg;
+ break;
- case 'C':
- do_complete = true;
- do_complete_param = woptarg ? woptarg : reader_get_buffer();
- break;
+ case 'C':
+ do_complete = true;
+ do_complete_param = woptarg ? woptarg : reader_get_buffer();
+ break;
- case 'h':
- builtin_print_help( parser, argv[0], stdout_buffer );
- return 0;
+ case 'h':
+ builtin_print_help(parser, argv[0], stdout_buffer);
+ return 0;
- case '?':
- builtin_unknown_option( parser, argv[0], argv[woptind-1] );
- res = true;
- break;
+ case '?':
+ builtin_unknown_option(parser, argv[0], argv[woptind-1]);
+ res = true;
+ break;
- }
+ }
- }
+ }
- if( !res )
- {
- if( condition && wcslen( condition ) )
+ if (!res)