Convert constant macros to constexpr expressions

Also convert some `const[expr] static xxx` to `const[expr] xxx` where it makes
sense to let the compiler deduce on its own whether or not to allocate storage
for a constant variable rather than imposing our view that it should have STATIC
storage set aside for it.

A few call sites were not making use of the `XXX_LEN` definitions and were
calling `strlen(XXX)` - these have been updated to use `const_strlen(XXX)`
instead.

I'm not sure if any toolchains will have raise any issues with these changes...
CI will tell!
This commit is contained in:
Mahmoud Al-Qudsi 2022-09-19 17:13:47 -05:00
parent 549958a7ea
commit e1626818f7
37 changed files with 115 additions and 116 deletions

View file

@ -17,7 +17,7 @@
#include "wutil.h" // IWYU pragma: keep
/// The time before we'll recheck an autoloaded file.
static const int kAutoloadStalenessInterval = 15;
const int kAutoloadStalenessInterval = 15;
/// Represents a file that we might want to autoload.
namespace {

View file

@ -224,7 +224,8 @@ static maybe_t<int> builtin_generic(parser_t &parser, io_streams_t &streams, con
// How many bytes we read() at once.
// Since this is just for counting, it can be massive.
#define COUNT_CHUNK_SIZE (512 * 256)
constexpr int COUNT_CHUNK_SIZE = 512 * 256;
/// Implementation of the builtin count command, used to count the number of arguments sent to it.
static maybe_t<int> builtin_count(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
UNUSED(parser);
@ -413,7 +414,7 @@ static constexpr builtin_data_t builtin_datas[] = {
};
ASSERT_SORTED_BY_NAME(builtin_datas);
#define BUILTIN_COUNT (sizeof builtin_datas / sizeof *builtin_datas)
constexpr int BUILTIN_COUNT = sizeof builtin_datas / sizeof *builtin_datas;
/// Look up a builtin_data_t for a specified builtin
///

View file

@ -19,7 +19,7 @@
#include "../wutil.h" // IWYU pragma: keep
// The maximum number of points after the decimal that we'll print.
static constexpr int kDefaultScale = 6;
constexpr int kDefaultScale = 6;
// The end of the range such that every integer is representable as a double.
// i.e. this is the first value such that x + 1 == x (or == x + 2, depending on rounding mode).

View file

@ -34,7 +34,7 @@
// How many bytes we read() at once.
// We use PATH_MAX here so we always get at least one path,
// and so we can automatically detect NULL-separated input.
#define PATH_CHUNK_SIZE PATH_MAX
constexpr int PATH_CHUNK_SIZE = PATH_MAX;
static void path_error(io_streams_t &streams, const wchar_t *fmt, ...) {
streams.err.append(L"path ");

View file

@ -247,7 +247,7 @@ static int read_interactive(parser_t &parser, wcstring &buff, int nchars, bool s
/// Bash uses 128 bytes for its chunk size. Very informal testing I did suggested that a smaller
/// chunk size performed better. However, we're going to use the bash value under the assumption
/// they've done more extensive testing.
#define READ_CHUNK_SIZE 128
constexpr int READ_CHUNK_SIZE = 128;
/// Read from the fd in chunks until we see newline or null, as requested, is seen. This is only
/// used when the fd is seekable (so not from a tty or pipe) and we're not reading a specific number

View file

@ -34,7 +34,7 @@
// Empirically determined.
// This is probably down to some pipe buffer or some such,
// but too small means we need to call `read(2)` and str2wcstring a lot.
#define STRING_CHUNK_SIZE 1024
constexpr int STRING_CHUNK_SIZE = 1024;
namespace {

View file

@ -81,7 +81,7 @@ static const struct resource_t resource_arr[] = {
/// This is likely to be the same as RLIMIT_INFINITY, but it shouldn't get used
/// in the same context (that is, compared to the result of a getrlimit call).
#define RLIMIT_UNKNOWN -1
constexpr int RLIMIT_UNKNOWN = -1;
/// Get the implicit multiplication factor for the specified resource limit.
static int get_multiplier(int what) {

View file

@ -1372,7 +1372,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
if (unescape_special && input_position == 0 &&
!std::wcscmp(input, PROCESS_EXPAND_SELF_STR)) {
to_append_or_none = PROCESS_EXPAND_SELF;
input_position += PROCESS_EXPAND_SELF_STR_LEN - 1; // skip over 'self's
input_position += const_strlen(PROCESS_EXPAND_SELF_STR) - 1; // skip over 'self's
}
break;
}

View file

@ -55,34 +55,34 @@
#endif
// Common string type.
typedef std::wstring wcstring;
typedef std::vector<wcstring> wcstring_list_t;
using wcstring = std::wstring;
using wcstring_list_t = std::vector<wcstring>;
struct termsize_t;
// Highest legal ASCII value.
#define ASCII_MAX 127u
constexpr char ASCII_MAX = 127U;
// Highest legal 16-bit Unicode value.
#define UCS2_MAX 0xFFFFu
constexpr uint16_t UCS2_MAX = 0xFFFF;
// Highest legal byte value.
#define BYTE_MAX 0xFFu
constexpr uint8_t BYTE_MAX = 0xFF;
// Unicode BOM value.
#define UTF8_BOM_WCHAR 0xFEFFu
constexpr uint16_t UTF8_BOM_WCHAR = 0xFEFF;
// Use Unicode "noncharacters" for internal characters as much as we can. This
// gives us 32 "characters" for internal use that we can guarantee should not
// appear in our input stream. See http://www.unicode.org/faq/private_use.html.
#define RESERVED_CHAR_BASE static_cast<wchar_t>(0xFDD0)
#define RESERVED_CHAR_END static_cast<wchar_t>(0xFDF0)
constexpr wchar_t RESERVED_CHAR_BASE = static_cast<wchar_t>(0xFDD0);
constexpr wchar_t RESERVED_CHAR_END = static_cast<wchar_t>(0xFDF0);
// Split the available noncharacter values into two ranges to ensure there are
// no conflicts among the places we use these special characters.
#define EXPAND_RESERVED_BASE RESERVED_CHAR_BASE
#define EXPAND_RESERVED_END (EXPAND_RESERVED_BASE + 16)
#define WILDCARD_RESERVED_BASE EXPAND_RESERVED_END
#define WILDCARD_RESERVED_END (WILDCARD_RESERVED_BASE + 16)
constexpr wchar_t EXPAND_RESERVED_BASE = RESERVED_CHAR_BASE;
constexpr wchar_t EXPAND_RESERVED_END = (EXPAND_RESERVED_BASE + 16);
constexpr wchar_t WILDCARD_RESERVED_BASE = EXPAND_RESERVED_END;
constexpr wchar_t WILDCARD_RESERVED_END = (WILDCARD_RESERVED_BASE + 16);
// Make sure the ranges defined above don't exceed the range for noncharacters.
// This is to make sure we didn't do something stupid in subdividing the
// Unicode range for our needs.
@ -102,8 +102,8 @@ struct termsize_t;
// Note: We don't use the highest 8 bit range (0xF800 - 0xF8FF) because we know
// of at least one use of a codepoint in that range: the Apple symbol (0xF8FF)
// on Mac OS X. See http://www.unicode.org/faq/private_use.html.
#define ENCODE_DIRECT_BASE static_cast<wchar_t>(0xF600)
#define ENCODE_DIRECT_END (ENCODE_DIRECT_BASE + 256)
constexpr wchar_t ENCODE_DIRECT_BASE = static_cast<wchar_t>(0xF600);
constexpr wchar_t ENCODE_DIRECT_END = (ENCODE_DIRECT_BASE + 256);
// NAME_MAX is not defined on Solaris
#if !defined(NAME_MAX)
@ -140,7 +140,7 @@ enum {
UNESCAPE_INCOMPLETE = 1 << 1, // allow incomplete escape sequences
UNESCAPE_NO_BACKSLASHES = 1 << 2, // don't handle backslash escapes
};
typedef unsigned int unescape_flags_t;
using unescape_flags_t = unsigned int;
// Flags for the escape_string() function. These are only applicable when the escape style is
// "script" (i.e., STRING_STYLE_SCRIPT).
@ -156,7 +156,7 @@ enum {
/// Replace nonprintable control characters with Unicode symbols.
ESCAPE_SYMBOLIC = 1 << 3
};
typedef unsigned int escape_flags_t;
using escape_flags_t = unsigned int;
/// A user-visible job ID.
using job_id_t = int;
@ -300,7 +300,7 @@ std::string wcs2string(const wchar_t *in, size_t len);
void wcs2string_appending(const wchar_t *in, size_t len, std::string *receiver);
// Check if we are running in the test mode, where we should suppress error output
#define TESTS_PROGRAM_NAME L"(ignore)"
constexpr const wchar_t TESTS_PROGRAM_NAME[] = L"(ignore)";
bool should_suppress_stderr_for_tests();
/// Branch prediction hints. Idea borrowed from Linux kernel. Just used for asserts.
@ -637,7 +637,7 @@ enum {
// Custom hash function used by unordered_map/unordered_set when key is const
#ifndef CONST_WCSTRING_HASH
#define CONST_WCSTRING_HASH 1
#define CONST_WCSTRING_HASH
namespace std {
template <>
struct hash<const wcstring> {

View file

@ -27,7 +27,7 @@ struct completion_mode_t {
};
/// Character that separates the completion and description on programmable completions.
#define PROG_COMPLETE_SEP L'\t'
constexpr char PROG_COMPLETE_SEP = L'\t';
class parser_t;

View file

@ -38,19 +38,19 @@
#include "wutil.h" // IWYU pragma: keep
/// Some configuration path environment variables.
#define FISH_DATADIR_VAR L"__fish_data_dir"
#define FISH_SYSCONFDIR_VAR L"__fish_sysconf_dir"
#define FISH_HELPDIR_VAR L"__fish_help_dir"
#define FISH_BIN_DIR L"__fish_bin_dir"
#define FISH_CONFIG_DIR L"__fish_config_dir"
#define FISH_USER_DATA_DIR L"__fish_user_data_dir"
constexpr const wchar_t FISH_DATADIR_VAR[] = L"__fish_data_dir";
constexpr const wchar_t FISH_SYSCONFDIR_VAR[] = L"__fish_sysconf_dir";
constexpr const wchar_t FISH_HELPDIR_VAR[] = L"__fish_help_dir";
constexpr const wchar_t FISH_BIN_DIR[] = L"__fish_bin_dir";
constexpr const wchar_t FISH_CONFIG_DIR[] = L"__fish_config_dir";
constexpr const wchar_t FISH_USER_DATA_DIR[] = L"__fish_user_data_dir";
/// At init, we read all the environment variables from this array.
extern char **environ;
/// The character used to delimit path and non-path variables in exporting and in string expansion.
static constexpr wchar_t PATH_ARRAY_SEP = L':';
static constexpr wchar_t NONPATH_ARRAY_SEP = L' ';
constexpr wchar_t PATH_ARRAY_SEP = L':';
constexpr wchar_t NONPATH_ARRAY_SEP = L' ';
bool curses_initialized = false;

View file

@ -55,16 +55,16 @@
#endif // Haiku
/// Error message.
#define PARSE_ERR L"Unable to parse universal variable message: '%ls'"
constexpr const wchar_t PARSE_ERR[] = L"Unable to parse universal variable message: '%ls'";
/// Small note about not editing ~/.fishd manually. Inserted at the top of all .fishd files.
#define SAVE_MSG "# This file contains fish universal variable definitions.\n"
constexpr const char SAVE_MSG[] = "# This file contains fish universal variable definitions.\n";
/// Version for fish 3.0
#define UVARS_VERSION_3_0 "3.0"
// Maximum file size we'll read.
static constexpr size_t k_max_read_size = 16 * 1024 * 1024;
constexpr size_t k_max_read_size = 16 * 1024 * 1024;
// Fields used in fish 2.x uvars.
namespace fish2x_uvars {
@ -211,11 +211,11 @@ static bool append_file_entry(env_var_t::env_var_flags_t flags, const wcstring &
}
/// Encoding of a null string.
static const wchar_t *const ENV_NULL = L"\x1d";
constexpr const wchar_t ENV_NULL[] = L"\x1d";
/// Character used to separate arrays in universal variables file.
/// This is 30, the ASCII record separator.
static const wchar_t UVAR_ARRAY_SEP = 0x1e;
constexpr const wchar_t UVAR_ARRAY_SEP = 0x1e;
/// Decode a serialized universal variable value into a list.
static wcstring_list_t decode_serialized(const wcstring &val) {
@ -869,7 +869,7 @@ void env_universal_t::parse_message_2x_internal(const wcstring &msgstr, var_tabl
}
/// Maximum length of hostname. Longer hostnames are truncated.
#define HOSTNAME_LEN 255
constexpr int HOSTNAME_LEN = 255;
/// Function to get an identifier based on the hostname.
bool get_hostname_identifier(wcstring &result) {
@ -898,8 +898,8 @@ class universal_notifier_shmem_poller_t final : public universal_notifier_t {
uint32_t universal_variable_seed;
};
#define SHMEM_MAGIC_NUMBER 0xF154
#define SHMEM_VERSION_CURRENT 1000
constexpr int SHMEM_MAGIC_NUMBER = 0xF154;
constexpr int SHMEM_VERSION_CURRENT = 1000;
private:
long long last_change_time{0};

View file

@ -19,7 +19,7 @@
struct io_streams_t;
/// The process id that is used to match any process id.
#define EVENT_ANY_PID 0
constexpr int EVENT_ANY_PID = 0;
/// Enumeration of event types.
enum class event_type_t {

View file

@ -39,9 +39,9 @@
/// Characters which make a string unclean if they are the first character of the string. See \c
/// expand_is_clean().
#define UNCLEAN_FIRST L"~%"
constexpr const wchar_t UNCLEAN_FIRST[] = L"~%";
/// Unclean characters. See \c expand_is_clean().
#define UNCLEAN L"$*?\\\"'({})"
constexpr const wchar_t UNCLEAN[] = L"$*?\\\"'({})";
static void remove_internal_separator(wcstring *s, bool conv);

View file

@ -133,8 +133,7 @@ struct expand_result_t {
};
/// The string represented by PROCESS_EXPAND_SELF
#define PROCESS_EXPAND_SELF_STR L"%self"
#define PROCESS_EXPAND_SELF_STR_LEN 5
constexpr const wchar_t PROCESS_EXPAND_SELF_STR[] = L"%self";
/// Perform various forms of expansion on in, such as tilde expansion (\~USER becomes the users home
/// directory), variable expansion (\$VAR_NAME becomes the value of the environment variable

View file

@ -14,7 +14,7 @@
#include "iothread.h"
#include "wutil.h"
static constexpr uint64_t kUsecPerMsec = 1000;
constexpr uint64_t kUsecPerMsec = 1000;
fd_monitor_t::fd_monitor_t() = default;

View file

@ -19,9 +19,9 @@
// The first fd in the "high range." fds below this are allowed to be used directly by users in
// redirections, e.g. >&3
const int k_first_high_fd = 10;
static constexpr uint64_t kUsecPerMsec = 1000;
static constexpr uint64_t kUsecPerSec [[gnu::unused]] = 1000 * kUsecPerMsec;
constexpr int k_first_high_fd = 10;
constexpr uint64_t kUsecPerMsec = 1000;
constexpr uint64_t kUsecPerSec [[gnu::unused]] = 1000 * kUsecPerMsec;
void autoclose_fd_t::close() {
if (fd_ < 0) return;

View file

@ -56,7 +56,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
// The number of spaces per indent isn't supposed to be configurable.
// See discussion at https://github.com/fish-shell/fish-shell/pull/6790
#define SPACES_PER_INDENT 4
constexpr int SPACES_PER_INDENT = 4;
static bool dump_parse_tree = false;
static int ret = 0;

View file

@ -121,11 +121,11 @@ static bool should_test_function(const char *func_name, bool default_on = true)
}
/// The number of tests to run.
#define ESCAPE_TEST_COUNT 100000
constexpr int ESCAPE_TEST_COUNT = 100000;
/// The average length of strings to unescape.
#define ESCAPE_TEST_LENGTH 100
constexpr int ESCAPE_TEST_LENGTH = 100;
/// The highest character number of character to try and escape.
#define ESCAPE_TEST_CHAR 4000
constexpr int ESCAPE_TEST_CHAR = 4000;
/// Number of encountered errors.
static int err_count = 0;
@ -3928,8 +3928,8 @@ static void test_undo() {
do_test(line.text() == L"abc");
}
#define UVARS_PER_THREAD 8
#define UVARS_TEST_PATH L"test/fish_uvars_test/varsfile.txt"
constexpr int UVARS_PER_THREAD = 8;
constexpr const wchar_t UVARS_TEST_PATH[] = L"test/fish_uvars_test/varsfile.txt";
static int test_universal_helper(int x) {
callback_data_list_t callbacks;

View file

@ -550,7 +550,7 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base
// Hacky support for %self which must be an unquoted literal argument.
if (buffstr == PROCESS_EXPAND_SELF_STR) {
std::fill_n(colors, std::wcslen(PROCESS_EXPAND_SELF_STR), highlight_role_t::operat);
std::fill_n(colors, const_strlen(PROCESS_EXPAND_SELF_STR), highlight_role_t::operat);
return;
}

View file

@ -52,21 +52,21 @@
// Newlines are replaced by \n. Backslashes are replaced by \\.
// This is the history session ID we use by default if the user has not set env var fish_history.
#define DFLT_FISH_HISTORY_SESSION_ID L"fish"
constexpr const wchar_t DFLT_FISH_HISTORY_SESSION_ID[] = L"fish";
// When we rewrite the history, the number of items we keep.
#define HISTORY_SAVE_MAX (1024 * 256)
constexpr int HISTORY_SAVE_MAX = 1024 * 256;
// Default buffer size for flushing to the history file.
#define HISTORY_OUTPUT_BUFFER_SIZE (64 * 1024)
constexpr int HISTORY_OUTPUT_BUFFER_SIZE = 64 * 1024;
// The file access mode we use for creating history files
static constexpr int history_file_mode = 0600;
constexpr int history_file_mode = 0600;
// How many times we retry to save
// Saving may fail if the file is modified in between our opening
// the file and taking the lock
static constexpr int max_save_tries = 1024;
constexpr int max_save_tries = 1024;
namespace {

View file

@ -32,7 +32,7 @@
#include "wutil.h" // IWYU pragma: keep
/// A name for our own key mapping for nul.
static const wchar_t *k_nul_mapping_name = L"nul";
constexpr const wchar_t k_nul_mapping_name[] = L"nul";
/// Struct representing a keybinding. Returned by input_get_mappings.
struct input_mapping_t {
@ -72,7 +72,7 @@ struct terminfo_mapping_t {
terminfo_mapping_t(const wchar_t *name, std::string s) : name(name), seq(std::move(s)) {}
};
static constexpr size_t input_function_count = R_END_INPUT_FUNCTIONS;
constexpr size_t input_function_count = R_END_INPUT_FUNCTIONS;
/// Input function metadata. This list should be kept in sync with the key code list in
/// input_common.h.

View file

@ -14,8 +14,8 @@
#include "input_common.h"
#include "maybe.h"
#define FISH_BIND_MODE_VAR L"fish_bind_mode"
#define DEFAULT_BIND_MODE L"default"
constexpr wchar_t FISH_BIND_MODE_VAR[] = L"fish_bind_mode";
constexpr wchar_t DEFAULT_BIND_MODE[]= L"default";
class event_queue_peeker_t;
class parser_t;

View file

@ -30,7 +30,7 @@
/// Time in milliseconds to wait for another byte to be available for reading
/// after \x1B is read before assuming that escape key was pressed, and not an
/// escape sequence.
#define WAIT_ON_ESCAPE_DEFAULT 30
constexpr int WAIT_ON_ESCAPE_DEFAULT = 30;
static int wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT;
input_event_queue_t::input_event_queue_t(int in) : in_(in) {}

View file

@ -26,7 +26,7 @@
#define NOCLOB_ERROR _(L"The file '%ls' already exists")
/// Base open mode to pass to calls to open.
#define OPEN_MASK 0666
constexpr int OPEN_MASK = 0666;
/// Provide the fd monitor used for background fillthread operations.
static fd_monitor_t &fd_monitor() {

View file

@ -21,7 +21,7 @@
#include "maybe.h"
/// We just define a thread limit of 1024.
#define IO_MAX_THREADS 1024
constexpr int IO_MAX_THREADS = 1024;
// iothread has a thread pool. Sometimes there's no work to do, but extant threads wait around for a
// while (on a condition variable) in case new work comes soon. However condition variables are not
@ -29,9 +29,9 @@
// See https://github.com/google/sanitizers/issues/1259
// When using TSan, disable the wait-around feature.
#ifdef FISH_TSAN_WORKAROUNDS
#define IO_WAIT_FOR_WORK_DURATION_MS 0
constexpr int IO_WAIT_FOR_WORK_DURATION_MS = 0;
#else
#define IO_WAIT_FOR_WORK_DURATION_MS 500
constexpr int IO_WAIT_FOR_WORK_DURATION_MS = 500;
#endif
using void_function_t = std::function<void()>;

View file

@ -30,16 +30,16 @@ using comp_t = pager_t::comp_t;
using comp_info_list_t = std::vector<comp_t>;
/// The minimum width (in characters) the terminal must to show completions at all.
#define PAGER_MIN_WIDTH 16
constexpr int PAGER_MIN_WIDTH = 16;
/// Minimum height to show completions
#define PAGER_MIN_HEIGHT 4
constexpr int PAGER_MIN_HEIGHT = 4;
/// The maximum number of columns of completion to attempt to fit onto the screen.
#define PAGER_MAX_COLS 6
constexpr int PAGER_MAX_COLS = 6;
/// Width of the search field.
#define PAGER_SEARCH_FIELD_WIDTH 12
constexpr int PAGER_SEARCH_FIELD_WIDTH = 12;
/// Text we use for the search field.
#define SEARCH_FIELD_PROMPT _(L"search: ")

View file

@ -15,7 +15,7 @@
struct termsize_t;
#define PAGER_SELECTION_NONE static_cast<size_t>(-1)
constexpr size_t PAGER_SELECTION_NONE = static_cast<size_t>(-1);
/// Represents rendering from the pager.
class page_rendering_t {
@ -56,11 +56,11 @@ enum class selection_motion_t {
};
// The space between adjacent completions.
#define PAGER_SPACER_STRING L" "
#define PAGER_SPACER_STRING_WIDTH 2
constexpr const wchar_t PAGER_SPACER_STRING[] = L" ";
constexpr int PAGER_SPACER_STRING_WIDTH = const_strlen(PAGER_SPACER_STRING);
// How many rows we will show in the "initial" pager.
#define PAGER_UNDISCLOSED_MAX_ROWS 4
constexpr int PAGER_UNDISCLOSED_MAX_ROWS = 4;
class pager_t {
size_t available_term_width{0};

View file

@ -189,13 +189,13 @@ struct parse_error_t {
wcstring describe_with_prefix(const wcstring &src, const wcstring &prefix, bool is_interactive,
bool skip_caret) const;
};
typedef std::vector<parse_error_t> parse_error_list_t;
using parse_error_list_t = std::vector<parse_error_t>;
wcstring token_type_user_presentable_description(parse_token_type_t type,
parse_keyword_t keyword = parse_keyword_t::none);
// Special source_start value that means unknown.
#define SOURCE_LOCATION_UNKNOWN (static_cast<size_t>(-1))
constexpr size_t SOURCE_LOCATION_UNKNOWN = static_cast<size_t>(-1);
/// Helper function to offset error positions by the given amount. This is used when determining
/// errors in a substring of a larger source buffer.
@ -209,7 +209,7 @@ enum class pipeline_position_t : uint8_t {
};
/// Maximum number of function calls.
#define FISH_MAX_STACK_DEPTH 128
constexpr int FISH_MAX_STACK_DEPTH = 128;
/// Error message on a function that calls itself immediately.
#define INFINITE_FUNC_RECURSION_ERR_MSG \

View file

@ -43,7 +43,7 @@
#define TIME_IN_PIPELINE_ERR_MSG _(L"The 'time' command may only be at the beginning of a pipeline")
/// Maximum length of a variable name to show in error reports before truncation
static constexpr int var_err_len = 16;
constexpr int var_err_len = 16;
int parse_util_lineno(const wcstring &str, size_t offset) {
// Return the line number of position offset, starting with 1.

View file

@ -10,15 +10,14 @@
#include "common.h"
#define CMD_LEN 1024
#define HELP_ERR "Could not show help message\n"
constexpr int CMD_LEN = 1024;
constexpr char HELP_ERR[] = "Could not show help message\n";
void print_help(const char *c, int fd) {
char cmd[CMD_LEN];
int printed = snprintf(cmd, CMD_LEN, "fish -c '__fish_print_help %s >&%d'", c, fd);
if (printed < CMD_LEN && system(cmd) == -1) {
write_loop(2, HELP_ERR, std::strlen(HELP_ERR));
write_loop(2, HELP_ERR, const_strlen(HELP_ERR));
}
}

View file

@ -83,47 +83,47 @@
// Name of the variable that tells how long it took, in milliseconds, for the previous
// interactive command to complete.
#define ENV_CMD_DURATION L"CMD_DURATION"
constexpr const wchar_t ENV_CMD_DURATION[] = L"CMD_DURATION";
/// Maximum length of prefix string when printing completion list. Longer prefixes will be
/// ellipsized.
#define PREFIX_MAX_LEN 9
constexpr int PREFIX_MAX_LEN = 9;
/// A simple prompt for reading shell commands that does not rely on fish specific commands, meaning
/// it will work even if fish is not installed. This is used by read_i.
#define DEFAULT_PROMPT L"echo -n \"$USER@$hostname $PWD \"'> '"
constexpr const wchar_t DEFAULT_PROMPT[] = L"echo -n \"$USER@$hostname $PWD \"'> '";
/// The name of the function that prints the fish prompt.
#define LEFT_PROMPT_FUNCTION_NAME L"fish_prompt"
constexpr const wchar_t LEFT_PROMPT_FUNCTION_NAME[] = L"fish_prompt";
/// The name of the function that prints the fish right prompt (RPROMPT).
#define RIGHT_PROMPT_FUNCTION_NAME L"fish_right_prompt"
constexpr const wchar_t RIGHT_PROMPT_FUNCTION_NAME[] = L"fish_right_prompt";
/// The name of the function to use in place of the left prompt if we're in the debugger context.
#define DEBUG_PROMPT_FUNCTION_NAME L"fish_breakpoint_prompt"
constexpr const wchar_t DEBUG_PROMPT_FUNCTION_NAME[] = L"fish_breakpoint_prompt";
/// The name of the function for getting the input mode indicator.
#define MODE_PROMPT_FUNCTION_NAME L"fish_mode_prompt"
constexpr const wchar_t MODE_PROMPT_FUNCTION_NAME[] = L"fish_mode_prompt";
/// The default title for the reader. This is used by reader_readline.
#define DEFAULT_TITLE L"echo (status current-command) \" \" $PWD"
constexpr const wchar_t DEFAULT_TITLE[] = L"echo (status current-command) \" \" $PWD";
/// The maximum number of characters to read from the keyboard without repainting. Note that this
/// readahead will only occur if new characters are available for reading, fish will never block for
/// more input without repainting.
static constexpr size_t READAHEAD_MAX = 256;
constexpr size_t READAHEAD_MAX = 256;
/// When tab-completing with a wildcard, we expand the wildcard up to this many results.
/// If expansion would exceed this many results, beep and do nothing.
static const size_t TAB_COMPLETE_WILDCARD_MAX_EXPANSION = 256;
constexpr size_t TAB_COMPLETE_WILDCARD_MAX_EXPANSION = 256;
/// A mode for calling the reader_kill function. In this mode, the new string is appended to the
/// current contents of the kill buffer.
#define KILL_APPEND 0
constexpr int KILL_APPEND = 0;
/// A mode for calling the reader_kill function. In this mode, the new string is prepended to the
/// current contents of the kill buffer.
#define KILL_PREPEND 1
constexpr int KILL_PREPEND = 1;
enum class jump_direction_t { forward, backward };
enum class jump_precision_t { till, to };
@ -169,7 +169,7 @@ static operation_context_t get_bg_context(const std::shared_ptr<environment_t> &
/// typed. But we do not want it to block forever - e.g. it may hang on determining if an arbitrary
/// argument is a path. This is how long we'll wait (in milliseconds) before giving up and
/// performing a no-io syntax highlighting. See #7418, #5912.
static constexpr long kHighlightTimeoutForExecutionMs = 250;
constexpr long kHighlightTimeoutForExecutionMs = 250;
/// Get the debouncer for autosuggestions and background highlighting.
/// These are deliberately leaked to avoid shutdown dtor registration.

View file

@ -45,7 +45,7 @@
#include "termsize.h"
/// The number of characters to indent new blocks.
#define INDENT_STEP 4u
constexpr uint32_t INDENT_STEP = 4U;
/// RAII class to begin and end buffering around an outputter.
namespace {

View file

@ -26,17 +26,17 @@ enum class token_type_t : uint8_t {
/// Flag telling the tokenizer to accept incomplete parameters, i.e. parameters with mismatching
/// parenthesis, etc. This is useful for tab-completion.
#define TOK_ACCEPT_UNFINISHED 1
constexpr int TOK_ACCEPT_UNFINISHED = 1;
/// Flag telling the tokenizer not to remove comments. Useful for syntax highlighting.
#define TOK_SHOW_COMMENTS 2
constexpr int TOK_SHOW_COMMENTS = 2;
/// Ordinarily, the tokenizer ignores newlines following a newline, or a semicolon. This flag tells
/// the tokenizer to return each of them as a separate END.
#define TOK_SHOW_BLANK_LINES 4
constexpr int TOK_SHOW_BLANK_LINES = 4;
/// Make an effort to continue after an error.
#define TOK_CONTINUE_AFTER_ERROR 8
constexpr int TOK_CONTINUE_AFTER_ERROR = 8;
using tok_flags_t = unsigned int;

View file

@ -24,12 +24,12 @@
#include "common.h"
#define _NXT 0x80
#define _SEQ2 0xc0
#define _SEQ3 0xe0
#define _SEQ4 0xf0
constexpr char _NXT = 0x80;
constexpr char _SEQ2 = 0xc0;
constexpr char _SEQ3 = 0xe0;
constexpr char _SEQ4 = 0xf0;
#define _BOM 0xfeff
constexpr uint16_t _BOM = 0xfeff;
// We can tweak the following typedef to allow us to simulate Windows-style 16 bit wchar's on Unix.
using utf8_wchar_t = wchar_t;

View file

@ -22,8 +22,8 @@
#include <string>
#define UTF8_IGNORE_ERROR 0x01
#define UTF8_SKIP_BOM 0x02
constexpr int UTF8_IGNORE_ERROR = 0x01;
constexpr int UTF8_SKIP_BOM = 0x02;
/// Convert a string between UTF8 and UCS-2/4 (depending on size of wchar_t). Returns true if
/// successful, storing the result of the conversion in *result*.

View file

@ -176,7 +176,7 @@ struct dir_t {
};
#ifndef HASH_FILE_ID
#define HASH_FILE_ID 1
#define HASH_FILE_ID
namespace std {
template <>
struct hash<file_id_t> {