mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
restyle switch blocks to match project style
I missed restyling a few "switch" blocks to make them consistent with the rest of the code base. This fixes that oversight. This should be the final step in restyling the C++ code to have a consistent style. This also includes a few trivial cleanups elsewhere. I also missed restyling the "complete" module when working my way from a to z so this final change includes restyling that module. Total lint errors decreased 36%. Cppcheck errors went from 47 to 24. Oclint P2 errors went from 819 to 778. Oclint P3 errors went from 3252 to 1842. Resolves #2902.
This commit is contained in:
parent
5c8763be0e
commit
fc44cffac5
19 changed files with 1016 additions and 1472 deletions
|
@ -1,18 +1,18 @@
|
||||||
// The classes responsible for autoloading functions and completions.
|
// The classes responsible for autoloading functions and completions.
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <set>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "autoload.h"
|
#include "autoload.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
#define FISH_AUTOLOAD_H
|
#define FISH_AUTOLOAD_H
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "lru.h"
|
#include "lru.h"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//
|
|
||||||
// Functions for executing builtin functions.
|
// Functions for executing builtin functions.
|
||||||
//
|
//
|
||||||
// How to add a new builtin function:
|
// How to add a new builtin function:
|
||||||
|
@ -1895,17 +1894,18 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
||||||
nchars = fish_wcstoi(w.woptarg, &end, 10);
|
nchars = fish_wcstoi(w.woptarg, &end, 10);
|
||||||
if (errno || *end != 0) {
|
if (errno || *end != 0) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case ERANGE:
|
case ERANGE: {
|
||||||
streams.err.append_format(_(L"%ls: Argument '%ls' is out of range\n"),
|
streams.err.append_format(_(L"%ls: Argument '%ls' is out of range\n"),
|
||||||
argv[0], w.woptarg);
|
argv[0], w.woptarg);
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
builtin_print_help(parser, streams, argv[0], streams.err);
|
||||||
return STATUS_BUILTIN_ERROR;
|
return STATUS_BUILTIN_ERROR;
|
||||||
|
}
|
||||||
default:
|
default: {
|
||||||
streams.err.append_format(
|
streams.err.append_format(
|
||||||
_(L"%ls: Argument '%ls' must be an integer\n"), argv[0], w.woptarg);
|
_(L"%ls: Argument '%ls' must be an integer\n"), argv[0], w.woptarg);
|
||||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
builtin_print_help(parser, streams, argv[0], streams.err);
|
||||||
return STATUS_BUILTIN_ERROR;
|
return STATUS_BUILTIN_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -596,21 +596,24 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch
|
||||||
for (;; f++, direc_length++) {
|
for (;; f++, direc_length++) {
|
||||||
switch (*f) {
|
switch (*f) {
|
||||||
case L'I':
|
case L'I':
|
||||||
case L'\'':
|
case L'\'': {
|
||||||
modify_allowed_format_specifiers(ok, "aAceEosxX", false);
|
modify_allowed_format_specifiers(ok, "aAceEosxX", false);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case '-':
|
case '-':
|
||||||
case '+':
|
case '+':
|
||||||
case ' ':
|
case ' ': {
|
||||||
break;
|
break;
|
||||||
case L'#':
|
}
|
||||||
|
case L'#': {
|
||||||
modify_allowed_format_specifiers(ok, "cdisu", false);
|
modify_allowed_format_specifiers(ok, "cdisu", false);
|
||||||
break;
|
break;
|
||||||
case '0':
|
}
|
||||||
|
case '0': {
|
||||||
modify_allowed_format_specifiers(ok, "cs", false);
|
modify_allowed_format_specifiers(ok, "cs", false);
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
goto no_more_flag_characters;
|
default: { goto no_more_flag_characters; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
no_more_flag_characters:;
|
no_more_flag_characters:;
|
||||||
|
|
|
@ -412,12 +412,11 @@ int builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
builtin_print_help(parser, streams, argv[0], streams.out);
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case '?':
|
case '?': {
|
||||||
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
default:
|
default: { break; }
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -311,20 +311,26 @@ rgb_color_t::rgb_color_t(const std::string &str) : type(), flags() {
|
||||||
|
|
||||||
wcstring rgb_color_t::description() const {
|
wcstring rgb_color_t::description() const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case type_none:
|
case type_none: {
|
||||||
return L"none";
|
return L"none";
|
||||||
case type_named:
|
}
|
||||||
|
case type_named: {
|
||||||
return format_string(L"named(%d: %ls)", (int)data.name_idx,
|
return format_string(L"named(%d: %ls)", (int)data.name_idx,
|
||||||
name_for_color_idx(data.name_idx));
|
name_for_color_idx(data.name_idx));
|
||||||
case type_rgb:
|
}
|
||||||
|
case type_rgb: {
|
||||||
return format_string(L"rgb(0x%02x%02x%02x)", data.color.rgb[0], data.color.rgb[1],
|
return format_string(L"rgb(0x%02x%02x%02x)", data.color.rgb[0], data.color.rgb[1],
|
||||||
data.color.rgb[2]);
|
data.color.rgb[2]);
|
||||||
case type_reset:
|
}
|
||||||
|
case type_reset: {
|
||||||
return L"reset";
|
return L"reset";
|
||||||
case type_normal:
|
}
|
||||||
|
case type_normal: {
|
||||||
return L"normal";
|
return L"normal";
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
abort();
|
abort();
|
||||||
return L"";
|
return L"";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1904
src/complete.cpp
1904
src/complete.cpp
File diff suppressed because it is too large
Load diff
326
src/complete.h
326
src/complete.h
|
@ -1,269 +1,197 @@
|
||||||
/** \file complete.h
|
/// Prototypes for functions related to tab-completion.
|
||||||
Prototypes for functions related to tab-completion.
|
///
|
||||||
|
/// These functions are used for storing and retrieving tab-completion data, as well as for
|
||||||
These functions are used for storing and retrieving tab-completion
|
/// performing tab-completion.
|
||||||
data, as well as for performing tab-completion.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FISH_COMPLETE_H
|
#ifndef FISH_COMPLETE_H
|
||||||
#define FISH_COMPLETE_H
|
#define FISH_COMPLETE_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
/**
|
/// Use all completions.
|
||||||
* Use all completions
|
|
||||||
*/
|
|
||||||
#define SHARED 0
|
#define SHARED 0
|
||||||
/**
|
/// Do not use file completion.
|
||||||
* Do not use file completion
|
|
||||||
*/
|
|
||||||
#define NO_FILES 1
|
#define NO_FILES 1
|
||||||
/**
|
/// Require a parameter after completion.
|
||||||
* Require a parameter after completion
|
|
||||||
*/
|
|
||||||
#define NO_COMMON 2
|
#define NO_COMMON 2
|
||||||
/**
|
/// Only use the argument list specifies with completion after option. This is the same as (NO_FILES
|
||||||
* Only use the argument list specifies with completion after
|
/// | NO_COMMON).
|
||||||
* option. This is the same as (NO_FILES | NO_COMMON)
|
|
||||||
*/
|
|
||||||
#define EXCLUSIVE 3
|
#define EXCLUSIVE 3
|
||||||
|
/// Command is a path.
|
||||||
/**
|
|
||||||
* Command is a path
|
|
||||||
*/
|
|
||||||
#define PATH 1
|
#define PATH 1
|
||||||
/**
|
/// Command is not a path.
|
||||||
* Command is not a path
|
|
||||||
*/
|
|
||||||
#define COMMAND 0
|
#define COMMAND 0
|
||||||
|
/// Separator between completion and description.
|
||||||
/**
|
|
||||||
* Separator between completion and description
|
|
||||||
*/
|
|
||||||
#define COMPLETE_SEP L'\004'
|
#define COMPLETE_SEP L'\004'
|
||||||
|
/// Character that separates the completion and description on programmable completions.
|
||||||
/**
|
|
||||||
* Character that separates the completion and description on
|
|
||||||
* programmable completions
|
|
||||||
*/
|
|
||||||
#define PROG_COMPLETE_SEP L'\t'
|
#define PROG_COMPLETE_SEP L'\t'
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
/// Do not insert space afterwards if this is the only completion. (The default is to try insert
|
||||||
/**
|
/// a space).
|
||||||
Do not insert space afterwards if this is the only completion. (The
|
|
||||||
default is to try insert a space)
|
|
||||||
*/
|
|
||||||
COMPLETE_NO_SPACE = 1 << 0,
|
COMPLETE_NO_SPACE = 1 << 0,
|
||||||
|
/// This is not the suffix of a token, but replaces it entirely.
|
||||||
/** This is not the suffix of a token, but replaces it entirely */
|
|
||||||
COMPLETE_REPLACES_TOKEN = 1 << 2,
|
COMPLETE_REPLACES_TOKEN = 1 << 2,
|
||||||
|
/// This completion may or may not want a space at the end - guess by checking the last
|
||||||
/** This completion may or may not want a space at the end - guess by
|
/// character of the completion.
|
||||||
checking the last character of the completion. */
|
|
||||||
COMPLETE_AUTO_SPACE = 1 << 3,
|
COMPLETE_AUTO_SPACE = 1 << 3,
|
||||||
|
/// This completion should be inserted as-is, without escaping.
|
||||||
/** This completion should be inserted as-is, without escaping. */
|
|
||||||
COMPLETE_DONT_ESCAPE = 1 << 4,
|
COMPLETE_DONT_ESCAPE = 1 << 4,
|
||||||
|
/// If you do escape, don't escape tildes.
|
||||||
/** If you do escape, don't escape tildes */
|
|
||||||
COMPLETE_DONT_ESCAPE_TILDES = 1 << 5
|
COMPLETE_DONT_ESCAPE_TILDES = 1 << 5
|
||||||
};
|
};
|
||||||
typedef int complete_flags_t;
|
typedef int complete_flags_t;
|
||||||
|
|
||||||
|
class completion_t {
|
||||||
class completion_t
|
private:
|
||||||
{
|
// No public default constructor.
|
||||||
|
|
||||||
private:
|
|
||||||
/* No public default constructor */
|
|
||||||
completion_t();
|
completion_t();
|
||||||
public:
|
|
||||||
|
|
||||||
/* Destructor. Not inlining it saves code size. */
|
public:
|
||||||
|
// Destructor. Not inlining it saves code size.
|
||||||
~completion_t();
|
~completion_t();
|
||||||
|
|
||||||
/** The completion string */
|
/// The completion string.
|
||||||
wcstring completion;
|
wcstring completion;
|
||||||
|
/// The description for this completion.
|
||||||
/** The description for this completion */
|
|
||||||
wcstring description;
|
wcstring description;
|
||||||
|
/// The type of fuzzy match.
|
||||||
/** The type of fuzzy match */
|
|
||||||
string_fuzzy_match_t match;
|
string_fuzzy_match_t match;
|
||||||
|
/// Flags determining the completion behaviour.
|
||||||
/**
|
///
|
||||||
Flags determining the completion behaviour.
|
/// Determines whether a space should be inserted after this completion if it is the only
|
||||||
|
/// possible completion using the COMPLETE_NO_SPACE flag. The COMPLETE_NO_CASE can be used to
|
||||||
Determines whether a space should be inserted after this
|
/// signal that this completion is case insensitive.
|
||||||
completion if it is the only possible completion using the
|
|
||||||
COMPLETE_NO_SPACE flag.
|
|
||||||
|
|
||||||
The COMPLETE_NO_CASE can be used to signal that this completion
|
|
||||||
is case insensitive.
|
|
||||||
*/
|
|
||||||
complete_flags_t flags;
|
complete_flags_t flags;
|
||||||
|
|
||||||
/* Construction. Note: defining these so that they are not inlined reduces the executable size. */
|
// Construction. Note: defining these so that they are not inlined reduces the executable size.
|
||||||
explicit completion_t(const wcstring &comp, const wcstring &desc = wcstring(), string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), complete_flags_t flags_val = 0);
|
explicit completion_t(const wcstring &comp, const wcstring &desc = wcstring(),
|
||||||
|
string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact),
|
||||||
|
complete_flags_t flags_val = 0);
|
||||||
completion_t(const completion_t &);
|
completion_t(const completion_t &);
|
||||||
completion_t &operator=(const completion_t &);
|
completion_t &operator=(const completion_t &);
|
||||||
|
|
||||||
/* Compare two completions. No operating overlaoding to make this always explicit (there's potentially multiple ways to compare completions). */
|
// Compare two completions. No operating overlaoding to make this always explicit (there's
|
||||||
|
// potentially multiple ways to compare completions).
|
||||||
/* "Naturally less than" means in a natural ordering, where digits are treated as numbers. For example, foo10 is naturally greater than foo2 (but alphabetically less than it) */
|
//
|
||||||
|
// "Naturally less than" means in a natural ordering, where digits are treated as numbers. For
|
||||||
|
// example, foo10 is naturally greater than foo2 (but alphabetically less than it).
|
||||||
static bool is_naturally_less_than(const completion_t &a, const completion_t &b);
|
static bool is_naturally_less_than(const completion_t &a, const completion_t &b);
|
||||||
static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b);
|
static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b);
|
||||||
|
|
||||||
/* If this completion replaces the entire token, prepend a prefix. Otherwise do nothing. */
|
// If this completion replaces the entire token, prepend a prefix. Otherwise do nothing.
|
||||||
void prepend_token_prefix(const wcstring &prefix);
|
void prepend_token_prefix(const wcstring &prefix);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Sorts and remove any duplicate completions in the completion list, then puts them in priority order. */
|
/// Sorts and remove any duplicate completions in the completion list, then puts them in priority
|
||||||
|
/// order.
|
||||||
void completions_sort_and_prioritize(std::vector<completion_t> *comps);
|
void completions_sort_and_prioritize(std::vector<completion_t> *comps);
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
COMPLETION_REQUEST_DEFAULT = 0,
|
COMPLETION_REQUEST_DEFAULT = 0,
|
||||||
COMPLETION_REQUEST_AUTOSUGGESTION = 1 << 0, // indicates the completion is for an autosuggestion
|
COMPLETION_REQUEST_AUTOSUGGESTION = 1
|
||||||
COMPLETION_REQUEST_DESCRIPTIONS = 1 << 1, // indicates that we want descriptions
|
<< 0, // indicates the completion is for an autosuggestion
|
||||||
COMPLETION_REQUEST_FUZZY_MATCH = 1 << 2 // indicates that we don't require a prefix match
|
COMPLETION_REQUEST_DESCRIPTIONS = 1 << 1, // indicates that we want descriptions
|
||||||
|
COMPLETION_REQUEST_FUZZY_MATCH = 1 << 2 // indicates that we don't require a prefix match
|
||||||
};
|
};
|
||||||
typedef uint32_t completion_request_flags_t;
|
typedef uint32_t completion_request_flags_t;
|
||||||
|
|
||||||
/**
|
/// Add a completion.
|
||||||
|
///
|
||||||
Add a completion.
|
/// All supplied values are copied, they should be freed by or otherwise disposed by the caller.
|
||||||
|
///
|
||||||
All supplied values are copied, they should be freed by or otherwise
|
/// Examples:
|
||||||
disposed by the caller.
|
///
|
||||||
|
/// The command 'gcc -o' requires that a file follows it, so the NO_COMMON option is suitable. This
|
||||||
Examples:
|
/// can be done using the following line:
|
||||||
|
///
|
||||||
The command 'gcc -o' requires that a file follows it, so the
|
/// complete -c gcc -s o -r
|
||||||
NO_COMMON option is suitable. This can be done using the following
|
///
|
||||||
line:
|
/// The command 'grep -d' required that one of the strings 'read', 'skip' or 'recurse' is used. As
|
||||||
|
/// such, it is suitable to specify that a completion requires one of them. This can be done using
|
||||||
complete -c gcc -s o -r
|
/// the following line:
|
||||||
|
///
|
||||||
The command 'grep -d' required that one of the strings 'read',
|
/// complete -c grep -s d -x -a "read skip recurse"
|
||||||
'skip' or 'recurse' is used. As such, it is suitable to specify that
|
///
|
||||||
a completion requires one of them. This can be done using the
|
/// \param cmd Command to complete.
|
||||||
following line:
|
/// \param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
||||||
|
/// path of the program (optionally containing wildcards), otherwise it
|
||||||
complete -c grep -s d -x -a "read skip recurse"
|
/// will be interpreted as the command name.
|
||||||
|
/// \param short_opt The single character name of an option. (-a is a short option,
|
||||||
|
/// --all and -funroll are long options)
|
||||||
\param cmd Command to complete.
|
/// \param long_opt The multi character name of an option. (-a is a short option, --all and
|
||||||
\param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
/// -funroll are long options)
|
||||||
path of the program (optionally containing wildcards), otherwise it
|
/// \param long_mode Whether to use old style, single dash long options.
|
||||||
will be interpreted as the command name.
|
/// \param result_mode Whether to search further completions when this completion has been
|
||||||
\param short_opt The single character name of an option. (-a is a short option,
|
/// succesfully matched. If result_mode is SHARED, any other completions may also be used. If
|
||||||
--all and -funroll are long options)
|
/// result_mode is NO_FILES, file completion should not be used, but other completions may be used.
|
||||||
\param long_opt The multi character name of an option. (-a is a short option,
|
/// If result_mode is NO_COMMON, on option may follow it - only a parameter. If result_mode is
|
||||||
--all and -funroll are long options)
|
/// EXCLUSIVE, no option may follow it, and file completion is not performed.
|
||||||
\param long_mode Whether to use old style, single dash long options.
|
/// \param comp A space separated list of completions which may contain subshells.
|
||||||
\param result_mode Whether to search further completions when this
|
/// \param desc A description of the completion.
|
||||||
completion has been succesfully matched. If result_mode is SHARED,
|
/// \param condition a command to be run to check it this completion should be used. If \c condition
|
||||||
any other completions may also be used. If result_mode is NO_FILES,
|
/// is empty, the completion is always used.
|
||||||
file completion should not be used, but other completions may be
|
/// \param flags A set of completion flags
|
||||||
used. If result_mode is NO_COMMON, on option may follow it - only a
|
enum complete_option_type_t {
|
||||||
parameter. If result_mode is EXCLUSIVE, no option may follow it, and
|
option_type_args_only, // no option
|
||||||
file completion is not performed.
|
option_type_short, // -x
|
||||||
\param comp A space separated list of completions which may contain subshells.
|
option_type_single_long, // -foo
|
||||||
\param desc A description of the completion.
|
option_type_double_long // --foo
|
||||||
\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.
|
|
||||||
\param flags A set of completion flags
|
|
||||||
*/
|
|
||||||
enum complete_option_type_t
|
|
||||||
{
|
|
||||||
option_type_args_only, // no option
|
|
||||||
option_type_short, // -x
|
|
||||||
option_type_single_long, // -foo
|
|
||||||
option_type_double_long // --foo
|
|
||||||
};
|
};
|
||||||
void complete_add(const wchar_t *cmd,
|
void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option,
|
||||||
bool cmd_is_path,
|
complete_option_type_t option_type, int result_mode, const wchar_t *condition,
|
||||||
const wcstring &option,
|
const wchar_t *comp, const wchar_t *desc, int flags);
|
||||||
complete_option_type_t option_type,
|
|
||||||
int result_mode,
|
/// Sets whether the completion list for this command is complete. If true, any options not matching
|
||||||
const wchar_t *condition,
|
/// one of the provided options will be flagged as an error by syntax highlighting.
|
||||||
const wchar_t *comp,
|
|
||||||
const wchar_t *desc,
|
|
||||||
int flags);
|
|
||||||
/**
|
|
||||||
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_authoritative(const wchar_t *cmd, bool cmd_type, bool authoritative);
|
void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authoritative);
|
||||||
|
|
||||||
/**
|
/// Remove a previously defined completion.
|
||||||
Remove a previously defined completion
|
void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option,
|
||||||
*/
|
|
||||||
void complete_remove(const wcstring &cmd,
|
|
||||||
bool cmd_is_path,
|
|
||||||
const wcstring &option,
|
|
||||||
complete_option_type_t type);
|
complete_option_type_t type);
|
||||||
|
|
||||||
/** Removes all completions for a given command */
|
/// Removes all completions for a given command.
|
||||||
void complete_remove_all(const wcstring &cmd, bool cmd_is_path);
|
void complete_remove_all(const wcstring &cmd, bool cmd_is_path);
|
||||||
|
|
||||||
/** Find all completions of the command cmd, insert them into out.
|
/// Find all completions of the command cmd, insert them into out.
|
||||||
*/
|
|
||||||
class env_vars_snapshot_t;
|
class env_vars_snapshot_t;
|
||||||
void complete(const wcstring &cmd,
|
void complete(const wcstring &cmd, std::vector<completion_t> *out_comps,
|
||||||
std::vector<completion_t> *out_comps,
|
completion_request_flags_t flags, const env_vars_snapshot_t &vars);
|
||||||
completion_request_flags_t flags,
|
|
||||||
const env_vars_snapshot_t &vars);
|
|
||||||
|
|
||||||
/**
|
/// Return a list of all current completions.
|
||||||
Return a list of all current completions.
|
|
||||||
*/
|
|
||||||
wcstring complete_print();
|
wcstring complete_print();
|
||||||
|
|
||||||
/**
|
/// Tests if the specified option is defined for the specified command.
|
||||||
Tests if the specified option is defined for the specified command
|
int complete_is_valid_option(const wcstring &str, const wcstring &opt,
|
||||||
*/
|
wcstring_list_t *inErrorsOrNull, bool allow_autoload);
|
||||||
int complete_is_valid_option(const wcstring &str,
|
|
||||||
const wcstring &opt,
|
|
||||||
wcstring_list_t *inErrorsOrNull,
|
|
||||||
bool allow_autoload);
|
|
||||||
|
|
||||||
/**
|
/// Tests if the specified argument is valid for the specified option and command.
|
||||||
Tests if the specified argument is valid for the specified option
|
bool complete_is_valid_argument(const wcstring &str, const wcstring &opt, const wcstring &arg);
|
||||||
and command
|
|
||||||
*/
|
|
||||||
bool complete_is_valid_argument(const wcstring &str,
|
|
||||||
const wcstring &opt,
|
|
||||||
const wcstring &arg);
|
|
||||||
|
|
||||||
|
/// Create a new completion entry.
|
||||||
|
///
|
||||||
|
/// \param completions The array of completions to append to
|
||||||
|
/// \param comp The completion string
|
||||||
|
/// \param desc The description of the completion
|
||||||
|
/// \param flags completion flags
|
||||||
|
void append_completion(std::vector<completion_t> *completions, const wcstring &comp,
|
||||||
|
const wcstring &desc = wcstring(), int flags = 0,
|
||||||
|
string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact));
|
||||||
|
|
||||||
/**
|
/// Function used for testing.
|
||||||
Create a new completion entry
|
|
||||||
|
|
||||||
\param completions The array of completions to append to
|
|
||||||
\param comp The completion string
|
|
||||||
\param desc The description of the completion
|
|
||||||
\param flags completion flags
|
|
||||||
|
|
||||||
*/
|
|
||||||
void append_completion(std::vector<completion_t> *completions, const wcstring &comp, const wcstring &desc = wcstring(), int flags = 0, string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact));
|
|
||||||
|
|
||||||
/* Function used for testing */
|
|
||||||
void complete_set_variable_names(const wcstring_list_t *names);
|
void complete_set_variable_names(const wcstring_list_t *names);
|
||||||
|
|
||||||
/* Support for "wrap targets." A wrap target is a command that completes liek another command. The target chain is the sequence of wraps (A wraps B wraps C...). Any loops in the chain are silently ignored. */
|
/// Support for "wrap targets." A wrap target is a command that completes liek another command. The
|
||||||
|
/// target chain is the sequence of wraps (A wraps B wraps C...). Any loops in the chain are
|
||||||
|
/// silently ignored.
|
||||||
bool complete_add_wrapper(const wcstring &command, const wcstring &wrap_target);
|
bool complete_add_wrapper(const wcstring &command, const wcstring &wrap_target);
|
||||||
bool complete_remove_wrapper(const wcstring &command, const wcstring &wrap_target);
|
bool complete_remove_wrapper(const wcstring &command, const wcstring &wrap_target);
|
||||||
wcstring_list_t complete_get_wrap_chain(const wcstring &command);
|
wcstring_list_t complete_get_wrap_chain(const wcstring &command);
|
||||||
|
|
||||||
/* Wonky interface: returns all wraps. Even-values are the commands, odd values are the targets. */
|
// Wonky interface: returns all wraps. Even-values are the commands, odd values are the targets.
|
||||||
wcstring_list_t complete_get_wrap_pairs();
|
wcstring_list_t complete_get_wrap_pairs();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
17
src/exec.cpp
17
src/exec.cpp
|
@ -257,23 +257,16 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t *out_chain,
|
||||||
shared_ptr<io_data_t> out; // gets allocated via new
|
shared_ptr<io_data_t> out; // gets allocated via new
|
||||||
|
|
||||||
switch (in->io_mode) {
|
switch (in->io_mode) {
|
||||||
default:
|
|
||||||
// Unknown type, should never happen.
|
|
||||||
fprintf(stderr, "Unknown io_mode %ld\n", (long)in->io_mode);
|
|
||||||
abort();
|
|
||||||
break;
|
|
||||||
|
|
||||||
// These redirections don't need transmogrification. They can be passed through.
|
|
||||||
case IO_PIPE:
|
case IO_PIPE:
|
||||||
case IO_FD:
|
case IO_FD:
|
||||||
case IO_BUFFER:
|
case IO_BUFFER:
|
||||||
case IO_CLOSE: {
|
case IO_CLOSE: {
|
||||||
|
// These redirections don't need transmogrification. They can be passed through.
|
||||||
out = in;
|
out = in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transmogrify file redirections.
|
|
||||||
case IO_FILE: {
|
case IO_FILE: {
|
||||||
|
// Transmogrify file redirections.
|
||||||
int fd;
|
int fd;
|
||||||
CAST_INIT(io_file_t *, in_file, in.get());
|
CAST_INIT(io_file_t *, in_file, in.get());
|
||||||
if ((fd = open(in_file->filename_cstr, in_file->flags, OPEN_MASK)) == -1) {
|
if ((fd = open(in_file->filename_cstr, in_file->flags, OPEN_MASK)) == -1) {
|
||||||
|
@ -288,6 +281,12 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t *out_chain,
|
||||||
out.reset(new io_fd_t(in->fd, fd, false));
|
out.reset(new io_fd_t(in->fd, fd, false));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
|
// Unknown type, should never happen.
|
||||||
|
fprintf(stderr, "Unknown io_mode %ld\n", (long)in->io_mode);
|
||||||
|
abort();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out.get() != NULL) result_chain.push_back(out);
|
if (out.get() != NULL) result_chain.push_back(out);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -15,7 +16,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
|
@ -473,9 +473,9 @@ static size_t offset_of_next_item(const char *begin, size_t mmap_length,
|
||||||
offset_of_next_item_fish_1_x(begin, mmap_length, inout_cursor, cutoff_timestamp);
|
offset_of_next_item_fish_1_x(begin, mmap_length, inout_cursor, cutoff_timestamp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
case history_type_unknown:
|
||||||
case history_type_unknown: {
|
default: {
|
||||||
// Oh well
|
// Oh well.
|
||||||
result = (size_t)(-1);
|
result = (size_t)(-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -804,12 +804,13 @@ done:
|
||||||
|
|
||||||
history_item_t history_t::decode_item(const char *base, size_t len, history_file_type_t type) {
|
history_item_t history_t::decode_item(const char *base, size_t len, history_file_type_t type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case history_type_fish_1_x:
|
case history_type_fish_1_x: {
|
||||||
return history_t::decode_item_fish_1_x(base, len);
|
return history_t::decode_item_fish_1_x(base, len);
|
||||||
case history_type_fish_2_0:
|
}
|
||||||
|
case history_type_fish_2_0: {
|
||||||
return history_t::decode_item_fish_2_0(base, len);
|
return history_t::decode_item_fish_2_0(base, len);
|
||||||
default:
|
}
|
||||||
return history_item_t(L"");
|
default: { return history_item_t(L""); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,16 @@
|
||||||
|
|
||||||
// IWYU pragma: no_include <cstddef>
|
// IWYU pragma: no_include <cstddef>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wutil.h" // IWYU pragma: keep
|
#include "wutil.h" // IWYU pragma: keep
|
||||||
|
|
|
@ -256,10 +256,10 @@ void input_set_bind_mode(const wcstring &bm) {
|
||||||
int input_function_arity(int function) {
|
int input_function_arity(int function) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case R_FORWARD_JUMP:
|
case R_FORWARD_JUMP:
|
||||||
case R_BACKWARD_JUMP:
|
case R_BACKWARD_JUMP: {
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
}
|
||||||
return 0;
|
default: { return 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,32 +5,28 @@
|
||||||
|
|
||||||
Type ^C to exit the program.
|
Type ^C to exit the program.
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <termcap.h>
|
#include <termcap.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fallback.h" // IWYU pragma: keep
|
#include "fallback.h" // IWYU pragma: keep
|
||||||
#include "input_common.h"
|
#include "input_common.h"
|
||||||
|
|
||||||
int writestr(char *str)
|
int writestr(char *str) {
|
||||||
{
|
|
||||||
write_ignore(1, str, strlen(str));
|
write_ignore(1, str, strlen(str));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
set_main_thread();
|
set_main_thread();
|
||||||
setup_fork_guards();
|
setup_fork_guards();
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
|
if (argc == 2) {
|
||||||
if (argc == 2)
|
|
||||||
{
|
|
||||||
static char term_buffer[2048];
|
static char term_buffer[2048];
|
||||||
char *termtype = getenv("TERM");
|
char *termtype = getenv("TERM");
|
||||||
char *tbuff = new char[9999];
|
char *tbuff = new char[9999];
|
||||||
|
@ -38,45 +34,35 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
tgetent(term_buffer, termtype);
|
tgetent(term_buffer, termtype);
|
||||||
res = tgetstr(argv[1], &tbuff);
|
res = tgetstr(argv[1], &tbuff);
|
||||||
if (res != 0)
|
if (res != 0) {
|
||||||
{
|
while (*res != 0) {
|
||||||
while (*res != 0)
|
|
||||||
{
|
|
||||||
printf("%d ", *res);
|
printf("%d ", *res);
|
||||||
|
|
||||||
|
|
||||||
res++;
|
res++;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Undefined sequence\n");
|
printf("Undefined sequence\n");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
char scratch[1024];
|
char scratch[1024];
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
|
|
||||||
struct termios modes, /* so we can change the modes */
|
struct termios modes, /* so we can change the modes */
|
||||||
savemodes; /* so we can reset the modes when we're done */
|
savemodes; /* so we can reset the modes when we're done */
|
||||||
|
|
||||||
input_common_init(0);
|
input_common_init(0);
|
||||||
|
|
||||||
|
tcgetattr(0, &modes); /* get the current terminal modes */
|
||||||
|
savemodes = modes; /* save a copy so we can reset them */
|
||||||
|
|
||||||
tcgetattr(0,&modes); /* get the current terminal modes */
|
modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
||||||
savemodes = modes; /* save a copy so we can reset them */
|
|
||||||
|
|
||||||
modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
|
||||||
modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
||||||
modes.c_cc[VMIN]=1;
|
modes.c_cc[VMIN] = 1;
|
||||||
modes.c_cc[VTIME]=0;
|
modes.c_cc[VTIME] = 0;
|
||||||
tcsetattr(0,TCSANOW,&modes); /* set the new modes */
|
tcsetattr(0, TCSANOW, &modes); /* set the new modes */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
if ((c = input_common_readch(0)) == EOF) break;
|
||||||
if ((c=input_common_readch(0)) == EOF)
|
|
||||||
break;
|
|
||||||
if ((c > 31) && (c != 127))
|
if ((c > 31) && (c != 127))
|
||||||
sprintf(scratch, "dec: %u hex: %x char: %c\n", c, c, c);
|
sprintf(scratch, "dec: %u hex: %x char: %c\n", c, c, c);
|
||||||
else
|
else
|
||||||
|
@ -84,7 +70,7 @@ int main(int argc, char **argv)
|
||||||
writestr(scratch);
|
writestr(scratch);
|
||||||
}
|
}
|
||||||
/* reset the terminal to the saved mode */
|
/* reset the terminal to the saved mode */
|
||||||
tcsetattr(0,TCSANOW,&savemodes);
|
tcsetattr(0, TCSANOW, &savemodes);
|
||||||
|
|
||||||
input_common_destroy();
|
input_common_destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -584,26 +584,27 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
||||||
// Handle the case of nothing selected yet.
|
// Handle the case of nothing selected yet.
|
||||||
if (selected_completion_idx == PAGER_SELECTION_NONE) {
|
if (selected_completion_idx == PAGER_SELECTION_NONE) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
// These directions do something sane.
|
|
||||||
case direction_south:
|
case direction_south:
|
||||||
case direction_page_south:
|
case direction_page_south:
|
||||||
case direction_next:
|
case direction_next:
|
||||||
case direction_prev:
|
case direction_prev: {
|
||||||
|
// These directions do something sane.
|
||||||
if (direction == direction_prev) {
|
if (direction == direction_prev) {
|
||||||
selected_completion_idx = completion_infos.size() - 1;
|
selected_completion_idx = completion_infos.size() - 1;
|
||||||
} else {
|
} else {
|
||||||
selected_completion_idx = 0;
|
selected_completion_idx = 0;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
// These do nothing.
|
|
||||||
case direction_north:
|
case direction_north:
|
||||||
case direction_page_north:
|
case direction_page_north:
|
||||||
case direction_east:
|
case direction_east:
|
||||||
case direction_west:
|
case direction_west:
|
||||||
case direction_deselect:
|
case direction_deselect:
|
||||||
default:
|
default: {
|
||||||
|
// These do nothing.
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +652,6 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case direction_page_south: {
|
case direction_page_south: {
|
||||||
if (current_row + page_height < rendering.rows) {
|
if (current_row + page_height < rendering.rows) {
|
||||||
current_row += page_height;
|
current_row += page_height;
|
||||||
|
@ -675,7 +675,6 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case direction_east: {
|
case direction_east: {
|
||||||
// Go east, wrapping to the next row. There is no "row memory," so if we run off the
|
// Go east, wrapping to the next row. There is no "row memory," so if we run off the
|
||||||
// end, wrap.
|
// end, wrap.
|
||||||
|
@ -688,7 +687,6 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case direction_west: {
|
case direction_west: {
|
||||||
// Go west, wrapping to the previous row.
|
// Go west, wrapping to the previous row.
|
||||||
if (current_col > 0) {
|
if (current_col > 0) {
|
||||||
|
@ -699,10 +697,10 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
default:
|
|
||||||
assert(0 && "Unknown cardinal direction");
|
assert(0 && "Unknown cardinal direction");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the new index based on the changed row.
|
// Compute the new index based on the changed row.
|
||||||
|
|
|
@ -540,13 +540,15 @@ wcstring parse_util_escape_string_with_quote(const wcstring &cmd, wchar_t quote)
|
||||||
case L'\n':
|
case L'\n':
|
||||||
case L'\t':
|
case L'\t':
|
||||||
case L'\b':
|
case L'\b':
|
||||||
case L'\r':
|
case L'\r': {
|
||||||
unescapable = true;
|
unescapable = true;
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
if (c == quote) result.push_back(L'\\');
|
if (c == quote) result.push_back(L'\\');
|
||||||
result.push_back(c);
|
result.push_back(c);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,21 +817,25 @@ static wcstring truncate_string(const wcstring &str) {
|
||||||
/// For example, if wc is @, then the variable name was $@ and we suggest $argv.
|
/// For example, if wc is @, then the variable name was $@ and we suggest $argv.
|
||||||
static const wchar_t *error_format_for_character(wchar_t wc) {
|
static const wchar_t *error_format_for_character(wchar_t wc) {
|
||||||
switch (wc) {
|
switch (wc) {
|
||||||
case L'?':
|
case L'?': {
|
||||||
return ERROR_NOT_STATUS;
|
return ERROR_NOT_STATUS;
|
||||||
case L'#':
|
}
|
||||||
|
case L'#': {
|
||||||
return ERROR_NOT_ARGV_COUNT;
|
return ERROR_NOT_ARGV_COUNT;
|
||||||
case L'@':
|
}
|
||||||
|
case L'@': {
|
||||||
return ERROR_NOT_ARGV_AT;
|
return ERROR_NOT_ARGV_AT;
|
||||||
case L'*':
|
}
|
||||||
|
case L'*': {
|
||||||
return ERROR_NOT_ARGV_STAR;
|
return ERROR_NOT_ARGV_STAR;
|
||||||
|
}
|
||||||
case L'$':
|
case L'$':
|
||||||
case VARIABLE_EXPAND:
|
case VARIABLE_EXPAND:
|
||||||
case VARIABLE_EXPAND_SINGLE:
|
case VARIABLE_EXPAND_SINGLE:
|
||||||
case VARIABLE_EXPAND_EMPTY:
|
case VARIABLE_EXPAND_EMPTY: {
|
||||||
return ERROR_NOT_PID;
|
return ERROR_NOT_PID;
|
||||||
default:
|
}
|
||||||
return ERROR_BAD_VAR_CHAR1;
|
default: { return ERROR_BAD_VAR_CHAR1; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1156,7 +1162,6 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
||||||
BACKGROUND_IN_CONDITIONAL_ERROR_MSG);
|
BACKGROUND_IN_CONDITIONAL_ERROR_MSG);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case symbol_job_list: {
|
case symbol_job_list: {
|
||||||
// This isn't very complete, e.g. we don't catch 'foo & ; not and bar'.
|
// This isn't very complete, e.g. we don't catch 'foo & ; not and bar'.
|
||||||
assert(node_tree.get_child(*job_parent, 0) == &node);
|
assert(node_tree.get_child(*job_parent, 0) == &node);
|
||||||
|
@ -1195,9 +1200,7 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default: { break; }
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node.type == symbol_plain_statement) {
|
} else if (node.type == symbol_plain_statement) {
|
||||||
|
@ -1268,23 +1271,24 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
||||||
if (loop_or_function_header != NULL) {
|
if (loop_or_function_header != NULL) {
|
||||||
switch (loop_or_function_header->type) {
|
switch (loop_or_function_header->type) {
|
||||||
case symbol_while_header:
|
case symbol_while_header:
|
||||||
case symbol_for_header:
|
case symbol_for_header: {
|
||||||
// This is a loop header, so we can break or continue.
|
// This is a loop header, so we can break or continue.
|
||||||
found_loop = true;
|
found_loop = true;
|
||||||
end_search = true;
|
end_search = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case symbol_function_header:
|
case symbol_function_header: {
|
||||||
// This is a function header, so we cannot break or
|
// This is a function header, so we cannot break or
|
||||||
// continue. We stop our search here.
|
// continue. We stop our search here.
|
||||||
found_loop = false;
|
found_loop = false;
|
||||||
end_search = true;
|
end_search = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default: {
|
||||||
// Most likely begin / end style block, which makes no
|
// Most likely begin / end style block, which makes no
|
||||||
// difference.
|
// difference.
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ancestor = node_tree.get_parent(*ancestor);
|
ancestor = node_tree.get_parent(*ancestor);
|
||||||
|
|
|
@ -686,8 +686,7 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c) {
|
||||||
case s_separator: {
|
case s_separator: {
|
||||||
if (!iswspace(c) && !is_path_component_character(c)) {
|
if (!iswspace(c) && !is_path_component_character(c)) {
|
||||||
consumed = true; // consumed separator
|
consumed = true; // consumed separator
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
state = s_end;
|
state = s_end;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
// Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting
|
// Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting
|
||||||
// prototypes for getopt.
|
// prototypes for getopt.
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif // GNU C library.
|
#endif // GNU C library.
|
||||||
|
|
||||||
// This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves
|
// This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves
|
||||||
// differently for the user, since it allows the user to intersperse the options with the other
|
// differently for the user, since it allows the user to intersperse the options with the other
|
||||||
|
@ -105,10 +105,10 @@ static wchar_t *my_index(const wchar_t *str, int chr) {
|
||||||
// gcc with -traditional declares the built-in strlen to return int, and has done so at least since
|
// gcc with -traditional declares the built-in strlen to return int, and has done so at least since
|
||||||
// version 2.4.5. -- rms.
|
// version 2.4.5. -- rms.
|
||||||
extern int wcslen(const wchar_t *);
|
extern int wcslen(const wchar_t *);
|
||||||
#endif // not __STDC__
|
#endif // not __STDC__
|
||||||
#endif // __GNUC__
|
#endif // __GNUC__
|
||||||
|
|
||||||
#endif // not __GNU_LIBRARY__
|
#endif // not __GNU_LIBRARY__
|
||||||
|
|
||||||
// Exchange two adjacent subsequences of ARGV. One subsequence is elements
|
// Exchange two adjacent subsequences of ARGV. One subsequence is elements
|
||||||
// [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The
|
// [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The
|
||||||
|
@ -303,10 +303,12 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
||||||
const struct woption *pfound = NULL;
|
const struct woption *pfound = NULL;
|
||||||
int exact = 0;
|
int exact = 0;
|
||||||
int ambig = 0;
|
int ambig = 0;
|
||||||
int indfound = 0; // set to zero by Anton
|
int indfound = 0; // set to zero by Anton
|
||||||
int option_index;
|
int option_index;
|
||||||
|
|
||||||
for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */;
|
for (nameend = nextchar; *nameend && *nameend != '='; nameend++) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
// Test all long options for either exact match or abbreviated matches.
|
// Test all long options for either exact match or abbreviated matches.
|
||||||
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
||||||
|
@ -344,7 +346,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
||||||
woptarg = nameend + 1;
|
woptarg = nameend + 1;
|
||||||
else {
|
else {
|
||||||
if (wopterr) {
|
if (wopterr) {
|
||||||
if (argv[woptind - 1][1] == '-') // --option
|
if (argv[woptind - 1][1] == '-') // --option
|
||||||
fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"),
|
fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"),
|
||||||
argv[0], pfound->name);
|
argv[0], pfound->name);
|
||||||
else
|
else
|
||||||
|
@ -380,7 +382,7 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
||||||
// short option.
|
// short option.
|
||||||
if (!long_only || argv[woptind][1] == '-' || my_index(optstring, *nextchar) == NULL) {
|
if (!long_only || argv[woptind][1] == '-' || my_index(optstring, *nextchar) == NULL) {
|
||||||
if (wopterr) {
|
if (wopterr) {
|
||||||
if (argv[woptind][1] == '-') // --option
|
if (argv[woptind][1] == '-') // --option
|
||||||
fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
|
fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
|
||||||
else
|
else
|
||||||
// +option or -option
|
// +option or -option
|
||||||
|
|
|
@ -68,7 +68,7 @@ class wgetopter_t {
|
||||||
int woptind;
|
int woptind;
|
||||||
|
|
||||||
// The next char to be scanned in the option-element in which the last option character we
|
// The next char to be scanned in the option-element in which the last option character we
|
||||||
// returned was found. This allows us to pick up the scan where we left off.
|
// returned was found. This allows us to pick up the scan where we left off.
|
||||||
//
|
//
|
||||||
// If this is zero, or a null string, it means resume the scan by advancing to the next
|
// If this is zero, or a null string, it means resume the scan by advancing to the next
|
||||||
// ARGV-element.
|
// ARGV-element.
|
||||||
|
|
|
@ -94,7 +94,7 @@ static enum fuzzy_match_type_t wildcard_match_internal(const wchar_t *str, const
|
||||||
bool leading_dots_fail_to_match,
|
bool leading_dots_fail_to_match,
|
||||||
bool is_first) {
|
bool is_first) {
|
||||||
if (*str == 0 && *wc == 0) {
|
if (*str == 0 && *wc == 0) {
|
||||||
return fuzzy_match_exact; // we're done
|
return fuzzy_match_exact; // we're done
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hackish fix for issue #270. Prevent wildcards from matching . or .., but we must still allow
|
// Hackish fix for issue #270. Prevent wildcards from matching . or .., but we must still allow
|
||||||
|
@ -261,7 +261,6 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ANY_STRING: {
|
case ANY_STRING: {
|
||||||
// Hackish. If this is the last character of the wildcard, then just complete with
|
// Hackish. If this is the last character of the wildcard, then just complete with
|
||||||
// the empty string. This fixes cases like "f*<tab>" -> "f*o".
|
// the empty string. This fixes cases like "f*<tab>" -> "f*o".
|
||||||
|
@ -289,14 +288,14 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
||||||
}
|
}
|
||||||
return has_match;
|
return has_match;
|
||||||
}
|
}
|
||||||
|
case ANY_STRING_RECURSIVE: {
|
||||||
case ANY_STRING_RECURSIVE:
|
|
||||||
// We don't even try with this one.
|
// We don't even try with this one.
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
default:
|
default: {
|
||||||
assert(0 && "Unreachable code reached");
|
assert(0 && "Unreachable code reached");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(0 && "Unreachable code reached");
|
assert(0 && "Unreachable code reached");
|
||||||
|
@ -535,9 +534,9 @@ class wildcard_expander_t {
|
||||||
wcstring child_entry;
|
wcstring child_entry;
|
||||||
while (wreaddir_resolving(dir, abs_unique_hierarchy, child_entry, &child_is_dir)) {
|
while (wreaddir_resolving(dir, abs_unique_hierarchy, child_entry, &child_is_dir)) {
|
||||||
if (child_entry.empty() || child_entry.at(0) == L'.') {
|
if (child_entry.empty() || child_entry.at(0) == L'.') {
|
||||||
continue; // either hidden, or . and .. entries -- skip them
|
continue; // either hidden, or . and .. entries -- skip them
|
||||||
} else if (child_is_dir && unique_entry.empty()) {
|
} else if (child_is_dir && unique_entry.empty()) {
|
||||||
unique_entry = child_entry; // first candidate
|
unique_entry = child_entry; // first candidate
|
||||||
} else {
|
} else {
|
||||||
// We either have two or more candidates, or the child is not a directory. We're
|
// We either have two or more candidates, or the child is not a directory. We're
|
||||||
// done.
|
// done.
|
||||||
|
|
Loading…
Reference in a new issue