Skip to content

Commit

Permalink
Formatting and style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ridiculousfish committed May 5, 2013
1 parent d4c8817 commit 2da81b0
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 79 deletions.
2 changes: 1 addition & 1 deletion builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
88 changes: 60 additions & 28 deletions builtin_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,71 @@ 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;
}
}

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;
}
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion complete.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion event.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum
*/
struct event_t
{
public:
public:

/** Type of event */
int type;
Expand Down
5 changes: 3 additions & 2 deletions exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
28 changes: 14 additions & 14 deletions expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand All @@ -1554,23 +1554,23 @@ 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++)
{
completion_t &comp = completions->at(i);
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;
}
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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++)
{
/*
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion fish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
4 changes: 2 additions & 2 deletions fish_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -1714,7 +1714,7 @@ int main(int argc, char **argv)
builtin_init();
reader_init();
env_init();

test_format();
test_escape();
test_convert();
Expand Down
7 changes: 5 additions & 2 deletions highlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &current_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
}
}
Expand Down
10 changes: 5 additions & 5 deletions history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion input_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Loading

0 comments on commit 2da81b0

Please sign in to comment.