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.
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <pthread.h>
|
||||
#include <stddef.h>
|
||||
#include <set>
|
||||
#include <time.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "autoload.h"
|
||||
#include "common.h"
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#define FISH_AUTOLOAD_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <time.h>
|
||||
#include <set>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "lru.h"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
//
|
||||
// Functions for executing builtin functions.
|
||||
//
|
||||
// How to add a new builtin function:
|
||||
|
@ -1895,19 +1894,20 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
|||
nchars = fish_wcstoi(w.woptarg, &end, 10);
|
||||
if (errno || *end != 0) {
|
||||
switch (errno) {
|
||||
case ERANGE:
|
||||
case ERANGE: {
|
||||
streams.err.append_format(_(L"%ls: Argument '%ls' is out of range\n"),
|
||||
argv[0], w.woptarg);
|
||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
streams.err.append_format(
|
||||
_(L"%ls: Argument '%ls' must be an integer\n"), argv[0], w.woptarg);
|
||||
builtin_print_help(parser, streams, argv[0], streams.err);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
|
|
|
@ -596,21 +596,24 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch
|
|||
for (;; f++, direc_length++) {
|
||||
switch (*f) {
|
||||
case L'I':
|
||||
case L'\'':
|
||||
case L'\'': {
|
||||
modify_allowed_format_specifiers(ok, "aAceEosxX", false);
|
||||
break;
|
||||
}
|
||||
case '-':
|
||||
case '+':
|
||||
case ' ':
|
||||
case ' ': {
|
||||
break;
|
||||
case L'#':
|
||||
}
|
||||
case L'#': {
|
||||
modify_allowed_format_specifiers(ok, "cdisu", false);
|
||||
break;
|
||||
case '0':
|
||||
}
|
||||
case '0': {
|
||||
modify_allowed_format_specifiers(ok, "cs", false);
|
||||
break;
|
||||
default:
|
||||
goto no_more_flag_characters;
|
||||
}
|
||||
default: { goto 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);
|
||||
return 0;
|
||||
}
|
||||
case '?':
|
||||
case '?': {
|
||||
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -311,20 +311,26 @@ rgb_color_t::rgb_color_t(const std::string &str) : type(), flags() {
|
|||
|
||||
wcstring rgb_color_t::description() const {
|
||||
switch (type) {
|
||||
case type_none:
|
||||
case type_none: {
|
||||
return L"none";
|
||||
case type_named:
|
||||
}
|
||||
case type_named: {
|
||||
return format_string(L"named(%d: %ls)", (int)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],
|
||||
data.color.rgb[2]);
|
||||
case type_reset:
|
||||
}
|
||||
case type_reset: {
|
||||
return L"reset";
|
||||
case type_normal:
|
||||
}
|
||||
case type_normal: {
|
||||
return L"normal";
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
abort();
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1826
src/complete.cpp
1826
src/complete.cpp
File diff suppressed because it is too large
Load diff
312
src/complete.h
312
src/complete.h
|
@ -1,269 +1,197 @@
|
|||
/** \file complete.h
|
||||
Prototypes for functions related to tab-completion.
|
||||
|
||||
These functions are used for storing and retrieving tab-completion
|
||||
data, as well as for performing tab-completion.
|
||||
*/
|
||||
|
||||
/// Prototypes for functions related to tab-completion.
|
||||
///
|
||||
/// These functions are used for storing and retrieving tab-completion data, as well as for
|
||||
/// performing tab-completion.
|
||||
#ifndef FISH_COMPLETE_H
|
||||
#define FISH_COMPLETE_H
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Use all completions
|
||||
*/
|
||||
/// Use all completions.
|
||||
#define SHARED 0
|
||||
/**
|
||||
* Do not use file completion
|
||||
*/
|
||||
/// Do not use file completion.
|
||||
#define NO_FILES 1
|
||||
/**
|
||||
* Require a parameter after completion
|
||||
*/
|
||||
/// Require a parameter after completion.
|
||||
#define NO_COMMON 2
|
||||
/**
|
||||
* Only use the argument list specifies with completion after
|
||||
* option. This is the same as (NO_FILES | NO_COMMON)
|
||||
*/
|
||||
/// Only use the argument list specifies with completion after option. This is the same as (NO_FILES
|
||||
/// | NO_COMMON).
|
||||
#define EXCLUSIVE 3
|
||||
|
||||
/**
|
||||
* Command is a path
|
||||
*/
|
||||
/// Command is a path.
|
||||
#define PATH 1
|
||||
/**
|
||||
* Command is not a path
|
||||
*/
|
||||
/// Command is not a path.
|
||||
#define COMMAND 0
|
||||
|
||||
/**
|
||||
* Separator between completion and description
|
||||
*/
|
||||
/// Separator between completion and description.
|
||||
#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'
|
||||
|
||||
enum
|
||||
{
|
||||
/**
|
||||
Do not insert space afterwards if this is the only completion. (The
|
||||
default is to try insert a space)
|
||||
*/
|
||||
enum {
|
||||
/// Do not insert space afterwards if this is the only completion. (The default is to try insert
|
||||
/// a space).
|
||||
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,
|
||||
|
||||
/** This completion may or may not want a space at the end - guess by
|
||||
checking the last character of the completion. */
|
||||
/// This completion may or may not want a space at the end - guess by checking the last
|
||||
/// character of the completion.
|
||||
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,
|
||||
|
||||
/** If you do escape, don't escape tildes */
|
||||
/// If you do escape, don't escape tildes.
|
||||
COMPLETE_DONT_ESCAPE_TILDES = 1 << 5
|
||||
};
|
||||
typedef int complete_flags_t;
|
||||
|
||||
|
||||
class completion_t
|
||||
{
|
||||
|
||||
private:
|
||||
/* No public default constructor */
|
||||
class completion_t {
|
||||
private:
|
||||
// No public default constructor.
|
||||
completion_t();
|
||||
public:
|
||||
|
||||
/* Destructor. Not inlining it saves code size. */
|
||||
public:
|
||||
// Destructor. Not inlining it saves code size.
|
||||
~completion_t();
|
||||
|
||||
/** The completion string */
|
||||
/// The completion string.
|
||||
wcstring completion;
|
||||
|
||||
/** The description for this completion */
|
||||
/// The description for this completion.
|
||||
wcstring description;
|
||||
|
||||
/** The type of fuzzy match */
|
||||
/// The type of fuzzy match.
|
||||
string_fuzzy_match_t match;
|
||||
|
||||
/**
|
||||
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 signal that this completion
|
||||
is case insensitive.
|
||||
*/
|
||||
/// 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
|
||||
/// signal that this completion is case insensitive.
|
||||
complete_flags_t flags;
|
||||
|
||||
/* 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);
|
||||
// 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);
|
||||
completion_t(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). */
|
||||
|
||||
/* "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) */
|
||||
// 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).
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
};
|
||||
|
||||
/** 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);
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
COMPLETION_REQUEST_DEFAULT = 0,
|
||||
COMPLETION_REQUEST_AUTOSUGGESTION = 1 << 0, // indicates the completion is for an autosuggestion
|
||||
COMPLETION_REQUEST_AUTOSUGGESTION = 1
|
||||
<< 0, // indicates the completion is for an autosuggestion
|
||||
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;
|
||||
|
||||
/**
|
||||
|
||||
Add a completion.
|
||||
|
||||
All supplied values are copied, they should be freed by or otherwise
|
||||
disposed by the caller.
|
||||
|
||||
Examples:
|
||||
|
||||
The command 'gcc -o' requires that a file follows it, so the
|
||||
NO_COMMON option is suitable. This can be done using the following
|
||||
line:
|
||||
|
||||
complete -c gcc -s o -r
|
||||
|
||||
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 the
|
||||
following line:
|
||||
|
||||
complete -c grep -s d -x -a "read skip recurse"
|
||||
|
||||
|
||||
\param cmd Command to complete.
|
||||
\param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
||||
path of the program (optionally containing wildcards), otherwise it
|
||||
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 long_opt The multi character name of an option. (-a is a short option,
|
||||
--all and -funroll are long options)
|
||||
\param long_mode Whether to use old style, single dash long options.
|
||||
\param result_mode Whether to search further completions when this
|
||||
completion has been succesfully matched. If result_mode is SHARED,
|
||||
any other completions may also be used. If result_mode is NO_FILES,
|
||||
file completion should not be used, but other completions may be
|
||||
used. If result_mode is NO_COMMON, on option may follow it - only a
|
||||
parameter. If result_mode is EXCLUSIVE, no option may follow it, and
|
||||
file completion is not performed.
|
||||
\param comp A space separated list of completions which may contain subshells.
|
||||
\param desc A description of the completion.
|
||||
\param 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
|
||||
{
|
||||
/// Add a completion.
|
||||
///
|
||||
/// All supplied values are copied, they should be freed by or otherwise disposed by the caller.
|
||||
///
|
||||
/// Examples:
|
||||
///
|
||||
/// The command 'gcc -o' requires that a file follows it, so the NO_COMMON option is suitable. This
|
||||
/// can be done using the following line:
|
||||
///
|
||||
/// complete -c gcc -s o -r
|
||||
///
|
||||
/// 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
|
||||
/// the following line:
|
||||
///
|
||||
/// complete -c grep -s d -x -a "read skip recurse"
|
||||
///
|
||||
/// \param cmd Command to complete.
|
||||
/// \param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
||||
/// path of the program (optionally containing wildcards), otherwise it
|
||||
/// 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 long_opt The multi character name of an option. (-a is a short option, --all and
|
||||
/// -funroll are long options)
|
||||
/// \param long_mode Whether to use old style, single dash long options.
|
||||
/// \param result_mode Whether to search further completions when this completion has been
|
||||
/// succesfully matched. If result_mode is SHARED, any other completions may also be used. If
|
||||
/// result_mode is NO_FILES, file completion should not be used, but other completions may be used.
|
||||
/// If result_mode is NO_COMMON, on option may follow it - only a parameter. If result_mode is
|
||||
/// EXCLUSIVE, no option may follow it, and file completion is not performed.
|
||||
/// \param comp A space separated list of completions which may contain subshells.
|
||||
/// \param desc A description of the completion.
|
||||
/// \param 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,
|
||||
bool cmd_is_path,
|
||||
const wcstring &option,
|
||||
complete_option_type_t option_type,
|
||||
int result_mode,
|
||||
const wchar_t *condition,
|
||||
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_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option,
|
||||
complete_option_type_t option_type, int result_mode, const wchar_t *condition,
|
||||
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);
|
||||
|
||||
/**
|
||||
Remove a previously defined completion
|
||||
*/
|
||||
void complete_remove(const wcstring &cmd,
|
||||
bool cmd_is_path,
|
||||
const wcstring &option,
|
||||
/// Remove a previously defined completion.
|
||||
void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option,
|
||||
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);
|
||||
|
||||
/** 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;
|
||||
void complete(const wcstring &cmd,
|
||||
std::vector<completion_t> *out_comps,
|
||||
completion_request_flags_t flags,
|
||||
const env_vars_snapshot_t &vars);
|
||||
void complete(const wcstring &cmd, std::vector<completion_t> *out_comps,
|
||||
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();
|
||||
|
||||
/**
|
||||
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);
|
||||
/// 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);
|
||||
|
||||
/**
|
||||
Tests if the specified argument is valid for the specified option
|
||||
and command
|
||||
*/
|
||||
bool complete_is_valid_argument(const wcstring &str,
|
||||
const wcstring &opt,
|
||||
const wcstring &arg);
|
||||
/// Tests if the specified argument is valid for the specified option 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));
|
||||
|
||||
/**
|
||||
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 */
|
||||
/// Function used for testing.
|
||||
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_remove_wrapper(const wcstring &command, const wcstring &wrap_target);
|
||||
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();
|
||||
|
||||
#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
|
||||
|
||||
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_FD:
|
||||
case IO_BUFFER:
|
||||
case IO_CLOSE: {
|
||||
// These redirections don't need transmogrification. They can be passed through.
|
||||
out = in;
|
||||
break;
|
||||
}
|
||||
|
||||
// Transmogrify file redirections.
|
||||
case IO_FILE: {
|
||||
// Transmogrify file redirections.
|
||||
int fd;
|
||||
CAST_INIT(io_file_t *, in_file, in.get());
|
||||
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));
|
||||
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);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -15,7 +16,6 @@
|
|||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "common.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);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case history_type_unknown: {
|
||||
// Oh well
|
||||
case history_type_unknown:
|
||||
default: {
|
||||
// Oh well.
|
||||
result = (size_t)(-1);
|
||||
break;
|
||||
}
|
||||
|
@ -804,12 +804,13 @@ done:
|
|||
|
||||
history_item_t history_t::decode_item(const char *base, size_t len, history_file_type_t 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);
|
||||
case history_type_fish_2_0:
|
||||
}
|
||||
case history_type_fish_2_0: {
|
||||
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>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
|
|
@ -256,10 +256,10 @@ void input_set_bind_mode(const wcstring &bm) {
|
|||
int input_function_arity(int function) {
|
||||
switch (function) {
|
||||
case R_FORWARD_JUMP:
|
||||
case R_BACKWARD_JUMP:
|
||||
case R_BACKWARD_JUMP: {
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
default: { return 0; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,32 +5,28 @@
|
|||
|
||||
Type ^C to exit the program.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termcap.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "input_common.h"
|
||||
|
||||
int writestr(char *str)
|
||||
{
|
||||
int writestr(char *str) {
|
||||
write_ignore(1, str, strlen(str));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
set_main_thread();
|
||||
setup_fork_guards();
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
if (argc == 2) {
|
||||
static char term_buffer[2048];
|
||||
char *termtype = getenv("TERM");
|
||||
char *tbuff = new char[9999];
|
||||
|
@ -38,24 +34,17 @@ int main(int argc, char **argv)
|
|||
|
||||
tgetent(term_buffer, termtype);
|
||||
res = tgetstr(argv[1], &tbuff);
|
||||
if (res != 0)
|
||||
{
|
||||
while (*res != 0)
|
||||
{
|
||||
if (res != 0) {
|
||||
while (*res != 0) {
|
||||
printf("%d ", *res);
|
||||
|
||||
|
||||
res++;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("Undefined sequence\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
char scratch[1024];
|
||||
unsigned int c;
|
||||
|
||||
|
@ -64,19 +53,16 @@ int main(int argc, char **argv)
|
|||
|
||||
input_common_init(0);
|
||||
|
||||
|
||||
tcgetattr(0,&modes); /* get the current terminal modes */
|
||||
tcgetattr(0, &modes); /* get the current terminal modes */
|
||||
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_cc[VMIN]=1;
|
||||
modes.c_cc[VTIME]=0;
|
||||
tcsetattr(0,TCSANOW,&modes); /* set the new modes */
|
||||
while (1)
|
||||
{
|
||||
if ((c=input_common_readch(0)) == EOF)
|
||||
break;
|
||||
modes.c_cc[VMIN] = 1;
|
||||
modes.c_cc[VTIME] = 0;
|
||||
tcsetattr(0, TCSANOW, &modes); /* set the new modes */
|
||||
while (1) {
|
||||
if ((c = input_common_readch(0)) == EOF) break;
|
||||
if ((c > 31) && (c != 127))
|
||||
sprintf(scratch, "dec: %u hex: %x char: %c\n", c, c, c);
|
||||
else
|
||||
|
@ -84,7 +70,7 @@ int main(int argc, char **argv)
|
|||
writestr(scratch);
|
||||
}
|
||||
/* reset the terminal to the saved mode */
|
||||
tcsetattr(0,TCSANOW,&savemodes);
|
||||
tcsetattr(0, TCSANOW, &savemodes);
|
||||
|
||||
input_common_destroy();
|
||||
}
|
||||
|
|
|
@ -584,28 +584,29 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
|||
// Handle the case of nothing selected yet.
|
||||
if (selected_completion_idx == PAGER_SELECTION_NONE) {
|
||||
switch (direction) {
|
||||
// These directions do something sane.
|
||||
case direction_south:
|
||||
case direction_page_south:
|
||||
case direction_next:
|
||||
case direction_prev:
|
||||
case direction_prev: {
|
||||
// These directions do something sane.
|
||||
if (direction == direction_prev) {
|
||||
selected_completion_idx = completion_infos.size() - 1;
|
||||
} else {
|
||||
selected_completion_idx = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
// These do nothing.
|
||||
}
|
||||
case direction_north:
|
||||
case direction_page_north:
|
||||
case direction_east:
|
||||
case direction_west:
|
||||
case direction_deselect:
|
||||
default:
|
||||
default: {
|
||||
// These do nothing.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ok, we had something selected already. Select something different.
|
||||
size_t new_selected_completion_idx = selected_completion_idx;
|
||||
|
@ -651,7 +652,6 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case direction_page_south: {
|
||||
if (current_row + page_height < rendering.rows) {
|
||||
current_row += page_height;
|
||||
|
@ -675,7 +675,6 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case direction_east: {
|
||||
// Go east, wrapping to the next row. There is no "row memory," so if we run off the
|
||||
// end, wrap.
|
||||
|
@ -688,7 +687,6 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case direction_west: {
|
||||
// Go west, wrapping to the previous row.
|
||||
if (current_col > 0) {
|
||||
|
@ -699,11 +697,11 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
default: {
|
||||
assert(0 && "Unknown cardinal direction");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the new index based on the changed row.
|
||||
new_selected_completion_idx = current_col * rendering.rows + current_row;
|
||||
|
|
|
@ -540,15 +540,17 @@ wcstring parse_util_escape_string_with_quote(const wcstring &cmd, wchar_t quote)
|
|||
case L'\n':
|
||||
case L'\t':
|
||||
case L'\b':
|
||||
case L'\r':
|
||||
case L'\r': {
|
||||
unescapable = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
if (c == quote) result.push_back(L'\\');
|
||||
result.push_back(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unescapable) {
|
||||
result = escape_string(cmd, ESCAPE_ALL | ESCAPE_NO_QUOTED);
|
||||
|
@ -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.
|
||||
static const wchar_t *error_format_for_character(wchar_t wc) {
|
||||
switch (wc) {
|
||||
case L'?':
|
||||
case L'?': {
|
||||
return ERROR_NOT_STATUS;
|
||||
case L'#':
|
||||
}
|
||||
case L'#': {
|
||||
return ERROR_NOT_ARGV_COUNT;
|
||||
case L'@':
|
||||
}
|
||||
case L'@': {
|
||||
return ERROR_NOT_ARGV_AT;
|
||||
case L'*':
|
||||
}
|
||||
case L'*': {
|
||||
return ERROR_NOT_ARGV_STAR;
|
||||
}
|
||||
case L'$':
|
||||
case VARIABLE_EXPAND:
|
||||
case VARIABLE_EXPAND_SINGLE:
|
||||
case VARIABLE_EXPAND_EMPTY:
|
||||
case VARIABLE_EXPAND_EMPTY: {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
case symbol_job_list: {
|
||||
// This isn't very complete, e.g. we don't catch 'foo & ; not and bar'.
|
||||
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;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
} else if (node.type == symbol_plain_statement) {
|
||||
|
@ -1268,25 +1271,26 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
|||
if (loop_or_function_header != NULL) {
|
||||
switch (loop_or_function_header->type) {
|
||||
case symbol_while_header:
|
||||
case symbol_for_header:
|
||||
case symbol_for_header: {
|
||||
// This is a loop header, so we can break or continue.
|
||||
found_loop = true;
|
||||
end_search = true;
|
||||
break;
|
||||
|
||||
case symbol_function_header:
|
||||
}
|
||||
case symbol_function_header: {
|
||||
// This is a function header, so we cannot break or
|
||||
// continue. We stop our search here.
|
||||
found_loop = false;
|
||||
end_search = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
// Most likely begin / end style block, which makes no
|
||||
// difference.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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: {
|
||||
if (!iswspace(c) && !is_path_component_character(c)) {
|
||||
consumed = true; // consumed separator
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
state = s_end;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -306,7 +306,9 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
|||
int indfound = 0; // set to zero by Anton
|
||||
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.
|
||||
for (p = longopts, option_index = 0; p->name; p++, option_index++)
|
||||
|
|
|
@ -261,7 +261,6 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ANY_STRING: {
|
||||
// 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".
|
||||
|
@ -289,16 +288,16 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc,
|
|||
}
|
||||
return has_match;
|
||||
}
|
||||
|
||||
case ANY_STRING_RECURSIVE:
|
||||
case ANY_STRING_RECURSIVE: {
|
||||
// We don't even try with this one.
|
||||
return false;
|
||||
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
assert(0 && "Unreachable code reached");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(0 && "Unreachable code reached");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue