mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
Formatting and style updates
This commit is contained in:
parent
d4c881791f
commit
2da81b0ae7
18 changed files with 115 additions and 79 deletions
|
@ -214,7 +214,7 @@ wcstring builtin_help_get(parser_t &parser, const wchar_t *name)
|
|||
/* This won't ever work if no_exec is set */
|
||||
if (no_exec)
|
||||
return wcstring();
|
||||
|
||||
|
||||
wcstring_list_t lst;
|
||||
wcstring out;
|
||||
const wcstring name_esc = escape_string(name, 1);
|
||||
|
|
|
@ -100,23 +100,46 @@ static int hex_to_bin(const wchar_t &c)
|
|||
{
|
||||
switch (c)
|
||||
{
|
||||
case L'0': return 0;
|
||||
case L'1': return 1;
|
||||
case L'2': return 2;
|
||||
case L'3': return 3;
|
||||
case L'4': return 4;
|
||||
case L'5': return 5;
|
||||
case L'6': return 6;
|
||||
case L'7': return 7;
|
||||
case L'8': return 8;
|
||||
case L'9': return 9;
|
||||
case L'a': case L'A': return 10;
|
||||
case L'b': case L'B': return 11;
|
||||
case L'c': case L'C': return 12;
|
||||
case L'd': case L'D': return 13;
|
||||
case L'e': case L'E': return 14;
|
||||
case L'f': case L'F': return 15;
|
||||
default: return -1;
|
||||
case L'0':
|
||||
return 0;
|
||||
case L'1':
|
||||
return 1;
|
||||
case L'2':
|
||||
return 2;
|
||||
case L'3':
|
||||
return 3;
|
||||
case L'4':
|
||||
return 4;
|
||||
case L'5':
|
||||
return 5;
|
||||
case L'6':
|
||||
return 6;
|
||||
case L'7':
|
||||
return 7;
|
||||
case L'8':
|
||||
return 8;
|
||||
case L'9':
|
||||
return 9;
|
||||
case L'a':
|
||||
case L'A':
|
||||
return 10;
|
||||
case L'b':
|
||||
case L'B':
|
||||
return 11;
|
||||
case L'c':
|
||||
case L'C':
|
||||
return 12;
|
||||
case L'd':
|
||||
case L'D':
|
||||
return 13;
|
||||
case L'e':
|
||||
case L'E':
|
||||
return 14;
|
||||
case L'f':
|
||||
case L'F':
|
||||
return 15;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,15 +147,24 @@ static int octal_to_bin(wchar_t c)
|
|||
{
|
||||
switch (c)
|
||||
{
|
||||
case L'0': return 0;
|
||||
case L'1': return 1;
|
||||
case L'2': return 2;
|
||||
case L'3': return 3;
|
||||
case L'4': return 4;
|
||||
case L'5': return 5;
|
||||
case L'6': return 6;
|
||||
case L'7': return 7;
|
||||
default: return -1;
|
||||
case L'0':
|
||||
return 0;
|
||||
case L'1':
|
||||
return 1;
|
||||
case L'2':
|
||||
return 2;
|
||||
case L'3':
|
||||
return 3;
|
||||
case L'4':
|
||||
return 4;
|
||||
case L'5':
|
||||
return 5;
|
||||
case L'6':
|
||||
return 6;
|
||||
case L'7':
|
||||
return 7;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,9 +390,9 @@ long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0)
|
|||
uni_value = uni_value * 16 + hex_to_bin(*p);
|
||||
p++;
|
||||
}
|
||||
|
||||
|
||||
/* PCA GNU printf respects the limitations described in ISO N717, about which universal characters "shall not" be specified. I believe this limitation is for the benefit of compilers; I see no reason to impose it in builtin_printf.
|
||||
|
||||
|
||||
If __STDC_ISO_10646__ is defined, then it means wchar_t can and does hold Unicode code points, so just use that. If not defined, use the %lc printf conversion; this probably won't do anything good if your wide character set is not Unicode, but such platforms are exceedingly rare.
|
||||
*/
|
||||
if (uni_value > 0x10FFFF)
|
||||
|
|
|
@ -568,7 +568,7 @@ wcstring wsetlocale(int category, const wchar_t *locale)
|
|||
|
||||
// U+23CE is the "return" character
|
||||
omitted_newline_char = unicode ? L'\x23CE' : L'~';
|
||||
|
||||
|
||||
if (!res)
|
||||
return wcstring();
|
||||
else
|
||||
|
|
|
@ -89,7 +89,7 @@ enum
|
|||
|
||||
/** This completion should be inserted as-is, without escaping. */
|
||||
COMPLETE_DONT_ESCAPE = 1 << 4,
|
||||
|
||||
|
||||
/** If you do escape, don't escape tildes */
|
||||
COMPLETE_DONT_ESCAPE_TILDES = 1 << 5
|
||||
};
|
||||
|
|
2
event.h
2
event.h
|
@ -49,7 +49,7 @@ enum
|
|||
*/
|
||||
struct event_t
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
/** Type of event */
|
||||
int type;
|
||||
|
|
5
exec.cpp
5
exec.cpp
|
@ -590,7 +590,8 @@ void exec(parser_t &parser, job_t *j)
|
|||
CHECK(j,);
|
||||
CHECK_BLOCK();
|
||||
|
||||
if (no_exec) {
|
||||
if (no_exec)
|
||||
{
|
||||
exec_no_exec(parser, j);
|
||||
return;
|
||||
}
|
||||
|
@ -1312,7 +1313,7 @@ void exec(parser_t &parser, job_t *j)
|
|||
/* Get argv and envv before we fork */
|
||||
null_terminated_array_t<char> argv_array;
|
||||
convert_wide_array_to_narrow(p->get_argv_array(), &argv_array);
|
||||
|
||||
|
||||
/* Ensure that stdin is blocking before we hand it off (see issue #176). It's a little strange that we only do this with stdin and not with stdout or stderr. However in practice, setting or clearing O_NONBLOCK on stdin also sets it for the other two fds, presumably because they refer to the same underlying file (/dev/tty?) */
|
||||
make_fd_blocking(STDIN_FILENO);
|
||||
|
||||
|
|
28
expand.cpp
28
expand.cpp
|
@ -1490,7 +1490,7 @@ static void expand_home_directory(wcstring &input)
|
|||
{
|
||||
size_t tail_idx;
|
||||
wcstring username = get_home_directory_name(input, &tail_idx);
|
||||
|
||||
|
||||
bool tilde_error = false;
|
||||
wcstring home;
|
||||
if (username.empty())
|
||||
|
@ -1539,7 +1539,7 @@ static void unexpand_tildes(const wcstring &input, std::vector<completion_t> *co
|
|||
// If it does not, there's nothing to do
|
||||
if (input.empty() || input.at(0) != L'~')
|
||||
return;
|
||||
|
||||
|
||||
// We only operate on completions that replace their contents
|
||||
// If we don't have any, we're done.
|
||||
// In particular, empty vectors are common.
|
||||
|
@ -1554,15 +1554,15 @@ static void unexpand_tildes(const wcstring &input, std::vector<completion_t> *co
|
|||
}
|
||||
if (! has_candidate_completion)
|
||||
return;
|
||||
|
||||
|
||||
size_t tail_idx;
|
||||
wcstring username_with_tilde = L"~";
|
||||
username_with_tilde.append(get_home_directory_name(input, &tail_idx));
|
||||
|
||||
|
||||
// Expand username_with_tilde
|
||||
wcstring home = username_with_tilde;
|
||||
expand_tilde(home);
|
||||
|
||||
|
||||
// Now for each completion that starts with home, replace it with the username_with_tilde
|
||||
for (size_t i=0; i < completions->size(); i++)
|
||||
{
|
||||
|
@ -1570,7 +1570,7 @@ static void unexpand_tildes(const wcstring &input, std::vector<completion_t> *co
|
|||
if ((comp.flags & COMPLETE_REPLACES_TOKEN) && string_prefixes_string(home, comp.completion))
|
||||
{
|
||||
comp.completion.replace(0, home.size(), username_with_tilde);
|
||||
|
||||
|
||||
// And mark that our tilde is literal, so it doesn't try to escape it
|
||||
comp.flags |= COMPLETE_DONT_ESCAPE_TILDES;
|
||||
}
|
||||
|
@ -1607,9 +1607,9 @@ static void remove_internal_separator(wcstring &str, bool conv)
|
|||
|
||||
|
||||
int expand_string(const wcstring &input, std::vector<completion_t> &output, expand_flags_t flags)
|
||||
{
|
||||
{
|
||||
parser_t parser(PARSER_TYPE_ERRORS_ONLY, true /* show errors */);
|
||||
|
||||
|
||||
size_t i;
|
||||
int res = EXPAND_OK;
|
||||
|
||||
|
@ -1618,7 +1618,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
output.push_back(completion_t(input));
|
||||
return EXPAND_OK;
|
||||
}
|
||||
|
||||
|
||||
std::vector<completion_t> clist1, clist2;
|
||||
std::vector<completion_t> *in = &clist1, *out = &clist2;
|
||||
|
||||
|
@ -1642,7 +1642,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
if (! cmdsubst_ok)
|
||||
return EXPAND_ERROR;
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i < in->size(); i++)
|
||||
{
|
||||
/*
|
||||
|
@ -1785,19 +1785,19 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
}
|
||||
else
|
||||
{
|
||||
if (! (flags & ACCEPT_INCOMPLETE))
|
||||
if (!(flags & ACCEPT_INCOMPLETE))
|
||||
{
|
||||
out->push_back(completion_t(next_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Hack to un-expand tildes (see #647)
|
||||
if (! (flags & EXPAND_SKIP_HOME_DIRECTORIES))
|
||||
if (!(flags & EXPAND_SKIP_HOME_DIRECTORIES))
|
||||
{
|
||||
unexpand_tildes(input, out);
|
||||
}
|
||||
|
||||
|
||||
// Return our output
|
||||
output.insert(output.end(), out->begin(), out->end());
|
||||
|
||||
|
|
2
fish.cpp
2
fish.cpp
|
@ -462,7 +462,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
/* Stop the exit status of any initialization commands (#635) */
|
||||
proc_set_last_status(STATUS_BUILTIN_OK);
|
||||
|
||||
|
||||
/* Run the commands specified as arguments, if any */
|
||||
if (! cmds.empty())
|
||||
{
|
||||
|
|
|
@ -1701,7 +1701,7 @@ int main(int argc, char **argv)
|
|||
setlocale(LC_ALL, "");
|
||||
srand(time(0));
|
||||
configure_thread_assertions_for_testing();
|
||||
|
||||
|
||||
program_name=L"(ignore)";
|
||||
|
||||
say(L"Testing low-level functionality");
|
||||
|
@ -1714,7 +1714,7 @@ int main(int argc, char **argv)
|
|||
builtin_init();
|
||||
reader_init();
|
||||
env_init();
|
||||
|
||||
|
||||
test_format();
|
||||
test_escape();
|
||||
test_convert();
|
||||
|
|
|
@ -1377,9 +1377,12 @@ void highlight_shell(const wcstring &buff, std::vector<int> &color, size_t pos,
|
|||
for (size_t i=0; i < buff.size(); i++)
|
||||
{
|
||||
int ¤t_val = color.at(i);
|
||||
if (current_val >= 0) {
|
||||
if (current_val >= 0)
|
||||
{
|
||||
last_val = current_val;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
current_val = last_val; //note - this writes into the vector
|
||||
}
|
||||
}
|
||||
|
|
10
history.cpp
10
history.cpp
|
@ -70,7 +70,7 @@ class history_output_buffer_t
|
|||
return s ? strlen(s) : 0;
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/* Add a bit more to HISTORY_OUTPUT_BUFFER_SIZE because we flush once we've exceeded that size */
|
||||
history_output_buffer_t() : buffer(HISTORY_OUTPUT_BUFFER_SIZE + 128, '\0'), offset(0)
|
||||
|
@ -1070,14 +1070,14 @@ bool history_search_t::go_backwards()
|
|||
return false;
|
||||
|
||||
const bool main_thread = is_main_thread();
|
||||
|
||||
|
||||
while (++idx < max_idx)
|
||||
{
|
||||
if (main_thread ? reader_interrupted() : reader_thread_job_is_stale())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const history_item_t item = history->item_at_index(idx);
|
||||
/* We're done if it's empty or we cancelled */
|
||||
if (item.empty())
|
||||
|
@ -1165,7 +1165,7 @@ static void unescape_yaml(std::string &str)
|
|||
{
|
||||
// Operate on a const version of str, to avoid needless COWs that at() does.
|
||||
const std::string &const_str = str;
|
||||
|
||||
|
||||
// Look for a backslash
|
||||
size_t backslash = const_str.find('\\', cursor);
|
||||
if (backslash == std::string::npos || backslash + 1 >= size)
|
||||
|
@ -1429,7 +1429,7 @@ bool history_t::save_internal_via_appending()
|
|||
*/
|
||||
|
||||
/* So far so good. Write all items at or after first_unwritten_new_item_index */
|
||||
|
||||
|
||||
bool errored = false;
|
||||
history_output_buffer_t buffer;
|
||||
while (first_unwritten_new_item_index < new_items.size())
|
||||
|
|
|
@ -796,8 +796,8 @@ bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq)
|
|||
{
|
||||
errno = err;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*out_seq = format_string(L"%s", res);
|
||||
return true;
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ static void input_flush_callbacks(void)
|
|||
/* Nothing to do if nothing to do */
|
||||
if (callback_queue.empty())
|
||||
return;
|
||||
|
||||
|
||||
/* We move the queue into a local variable, so that events queued up during a callback don't get fired until next round. */
|
||||
callback_queue_t local_queue;
|
||||
std::swap(local_queue, callback_queue);
|
||||
|
|
12
io.h
12
io.h
|
@ -3,13 +3,13 @@
|
|||
|
||||
#include <vector>
|
||||
#if __cplusplus > 199711L
|
||||
// C++11
|
||||
#include <memory>
|
||||
using std::shared_ptr;
|
||||
// C++11
|
||||
#include <memory>
|
||||
using std::shared_ptr;
|
||||
#else
|
||||
// C++03
|
||||
#include <tr1/memory>
|
||||
using std::tr1::shared_ptr;
|
||||
// C++03
|
||||
#include <tr1/memory>
|
||||
using std::tr1::shared_ptr;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
4
proc.cpp
4
proc.cpp
|
@ -1060,7 +1060,7 @@ void job_continue(job_t *j, bool cont)
|
|||
{
|
||||
/* Put the job into the foreground. Hack: ensure that stdin is marked as blocking first (#176). */
|
||||
make_fd_blocking(STDIN_FILENO);
|
||||
|
||||
|
||||
signal_block();
|
||||
|
||||
bool ok = terminal_give_to_job(j, cont);
|
||||
|
@ -1202,7 +1202,7 @@ void job_continue(job_t *j, bool cont)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Put the shell back in the foreground. */
|
||||
if (job_get_flag(j, JOB_TERMINAL) && job_get_flag(j, JOB_FOREGROUND))
|
||||
{
|
||||
|
|
|
@ -874,7 +874,7 @@ void reader_react_to_color_change()
|
|||
{
|
||||
if (! data)
|
||||
return;
|
||||
|
||||
|
||||
if (! data->repaint_needed || ! data->screen_reset_needed)
|
||||
{
|
||||
data->repaint_needed = true;
|
||||
|
@ -1006,7 +1006,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
|||
if (do_escape)
|
||||
{
|
||||
/* Respect COMPLETE_DONT_ESCAPE_TILDES */
|
||||
bool no_tilde = !! (flags & COMPLETE_DONT_ESCAPE_TILDES);
|
||||
bool no_tilde = !!(flags & COMPLETE_DONT_ESCAPE_TILDES);
|
||||
escaped = escape(val, ESCAPE_ALL | ESCAPE_NO_QUOTED | (no_tilde ? ESCAPE_NO_TILDE : 0));
|
||||
sb.append(escaped);
|
||||
move_cursor = wcslen(escaped);
|
||||
|
@ -1328,7 +1328,7 @@ struct autosuggestion_context_t
|
|||
this->autosuggestion = special_suggestion;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Maybe cancel here */
|
||||
if (reader_thread_job_is_stale())
|
||||
return 0;
|
||||
|
@ -3087,7 +3087,7 @@ const wchar_t *reader_readline(void)
|
|||
|
||||
/* Start the cycle at the beginning */
|
||||
completion_cycle_idx = (size_t)(-1);
|
||||
|
||||
|
||||
/* Repaint */
|
||||
reader_repaint_if_needed();
|
||||
}
|
||||
|
|
10
wildcard.cpp
10
wildcard.cpp
|
@ -729,7 +729,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
|
|||
debug(2, L"Got null string on line %d of file %s", __LINE__, __FILE__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const size_t base_dir_len = wcslen(base_dir);
|
||||
|
||||
if (flags & ACCEPT_INCOMPLETE)
|
||||
|
@ -897,7 +897,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
|
|||
|
||||
/* new_dir is a scratch area containing the full path to a file/directory we are iterating over */
|
||||
wcstring new_dir = base_dir;
|
||||
|
||||
|
||||
wcstring name_str;
|
||||
while (wreaddir(dir, name_str))
|
||||
{
|
||||
|
@ -926,11 +926,11 @@ static int wildcard_expand_internal(const wchar_t *wc,
|
|||
{
|
||||
struct stat buf;
|
||||
int new_res;
|
||||
|
||||
|
||||
// new_dir is base_dir + some other path components
|
||||
// Replace everything after base_dir with the new path component
|
||||
new_dir.replace(base_dir_len, wcstring::npos, name_str);
|
||||
|
||||
|
||||
int stat_res = wstat(new_dir, &buf);
|
||||
|
||||
if (!stat_res)
|
||||
|
@ -942,7 +942,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
|
|||
if (S_ISDIR(buf.st_mode) && (visited_files.insert(file_id).second || ! is_recursive))
|
||||
{
|
||||
new_dir.push_back(L'/');
|
||||
|
||||
|
||||
/*
|
||||
Regular matching
|
||||
*/
|
||||
|
|
|
@ -294,7 +294,7 @@ int make_fd_nonblocking(int fd)
|
|||
{
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
int err = 0;
|
||||
if (! (flags & O_NONBLOCK))
|
||||
if (!(flags & O_NONBLOCK))
|
||||
{
|
||||
err = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue