mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 08:58:01 +00:00
lint: Use early exit/continue
This commit is contained in:
parent
6192e2453e
commit
6c3900ff64
1 changed files with 214 additions and 206 deletions
|
@ -435,7 +435,7 @@ struct find_job_data_t {
|
||||||
|
|
||||||
/// The following function is invoked on the main thread, because the job list is not thread safe.
|
/// The following function is invoked on the main thread, because the job list is not thread safe.
|
||||||
/// It should search the job list for something matching the given proc, and then return 1 to stop
|
/// It should search the job list for something matching the given proc, and then return 1 to stop
|
||||||
/// the search, 0 to continue it .
|
/// the search, 0 to continue it.
|
||||||
static int find_job(const struct find_job_data_t *info) {
|
static int find_job(const struct find_job_data_t *info) {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
|
|
||||||
|
@ -494,7 +494,10 @@ static int find_job(const struct find_job_data_t *info) {
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (found) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
job_iterator_t jobs;
|
job_iterator_t jobs;
|
||||||
while ((j = jobs.next())) {
|
while ((j = jobs.next())) {
|
||||||
if (j->command_is_empty()) continue;
|
if (j->command_is_empty()) continue;
|
||||||
|
@ -511,7 +514,10 @@ static int find_job(const struct find_job_data_t *info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (found) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
jobs.reset();
|
jobs.reset();
|
||||||
while ((j = jobs.next())) {
|
while ((j = jobs.next())) {
|
||||||
process_t *p;
|
process_t *p;
|
||||||
|
@ -522,8 +528,7 @@ static int find_job(const struct find_job_data_t *info) {
|
||||||
size_t offset;
|
size_t offset;
|
||||||
if (match_pid(p->actual_cmd, proc, &offset)) {
|
if (match_pid(p->actual_cmd, proc, &offset)) {
|
||||||
if (flags & EXPAND_FOR_COMPLETIONS) {
|
if (flags & EXPAND_FOR_COMPLETIONS) {
|
||||||
append_completion(&completions,
|
append_completion(&completions, wcstring(p->actual_cmd, offset + wcslen(proc)),
|
||||||
wcstring(p->actual_cmd, offset + wcslen(proc)),
|
|
||||||
COMPLETE_CHILD_PROCESS_DESC, 0);
|
COMPLETE_CHILD_PROCESS_DESC, 0);
|
||||||
} else {
|
} else {
|
||||||
append_completion(&completions, to_string<long>(p->pid), L"", 0);
|
append_completion(&completions, to_string<long>(p->pid), L"", 0);
|
||||||
|
@ -532,8 +537,6 @@ static int find_job(const struct find_job_data_t *info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -746,13 +749,15 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
|
|
||||||
for (long i = last_idx - 1; (i >= 0) && is_ok && !empty; i--) {
|
for (long i = last_idx - 1; (i >= 0) && is_ok && !empty; i--) {
|
||||||
const wchar_t c = instr.at(i);
|
const wchar_t c = instr.at(i);
|
||||||
if ((c == VARIABLE_EXPAND) || (c == VARIABLE_EXPAND_SINGLE)) {
|
if (c != VARIABLE_EXPAND && c != VARIABLE_EXPAND_SINGLE) {
|
||||||
size_t start_pos = i + 1;
|
continue;
|
||||||
size_t stop_pos;
|
}
|
||||||
|
|
||||||
long var_len;
|
long var_len;
|
||||||
int is_single = (c == VARIABLE_EXPAND_SINGLE);
|
int is_single = (c == VARIABLE_EXPAND_SINGLE);
|
||||||
|
size_t start_pos = i + 1;
|
||||||
|
size_t stop_pos = start_pos;
|
||||||
|
|
||||||
stop_pos = start_pos;
|
|
||||||
while (stop_pos < insize) {
|
while (stop_pos < insize) {
|
||||||
const wchar_t nc = instr.at(stop_pos);
|
const wchar_t nc = instr.at(stop_pos);
|
||||||
if (nc == VARIABLE_EXPAND_EMPTY) {
|
if (nc == VARIABLE_EXPAND_EMPTY) {
|
||||||
|
@ -797,8 +802,8 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
size_t bad_pos;
|
size_t bad_pos;
|
||||||
all_vars = 0;
|
all_vars = 0;
|
||||||
const wchar_t *in = instr.c_str();
|
const wchar_t *in = instr.c_str();
|
||||||
bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list,
|
bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list, var_pos_list,
|
||||||
var_pos_list, var_item_list.size());
|
var_item_list.size());
|
||||||
if (bad_pos != 0) {
|
if (bad_pos != 0) {
|
||||||
append_syntax_error(errors, stop_pos + bad_pos, L"Invalid index value");
|
append_syntax_error(errors, stop_pos + bad_pos, L"Invalid index value");
|
||||||
is_ok = false;
|
is_ok = false;
|
||||||
|
@ -836,7 +841,10 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_ok) {
|
if (!is_ok) {
|
||||||
|
return is_ok;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_single) {
|
if (is_single) {
|
||||||
wcstring res(instr, 0, i);
|
wcstring res(instr, 0, i);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -861,7 +869,7 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
} else {
|
} else {
|
||||||
for (size_t j = 0; j < var_item_list.size(); j++) {
|
for (size_t j = 0; j < var_item_list.size(); j++) {
|
||||||
const wcstring &next = var_item_list.at(j);
|
const wcstring &next = var_item_list.at(j);
|
||||||
if (is_ok && (i == 0) && stop_pos == insize) {
|
if (is_ok && i == 0 && stop_pos == insize) {
|
||||||
append_completion(out, next);
|
append_completion(out, next);
|
||||||
} else {
|
} else {
|
||||||
if (is_ok) {
|
if (is_ok) {
|
||||||
|
@ -883,7 +891,6 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return is_ok;
|
return is_ok;
|
||||||
}
|
}
|
||||||
|
@ -934,7 +941,6 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
||||||
return is_ok;
|
return is_ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
append_completion(out, instr);
|
append_completion(out, instr);
|
||||||
|
@ -1543,8 +1549,11 @@ static std::string escape_single_quoted_hack_hack_hack_hack(const char *str) {
|
||||||
|
|
||||||
bool fish_xdm_login_hack_hack_hack_hack(std::vector<std::string> *cmds, int argc,
|
bool fish_xdm_login_hack_hack_hack_hack(std::vector<std::string> *cmds, int argc,
|
||||||
const char *const *argv) {
|
const char *const *argv) {
|
||||||
|
if (!cmds || cmds->size() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (cmds && cmds->size() == 1) {
|
|
||||||
const std::string &cmd = cmds->at(0);
|
const std::string &cmd = cmds->at(0);
|
||||||
if (cmd == "exec \"${@}\"" || cmd == "exec \"$@\"") {
|
if (cmd == "exec \"${@}\"" || cmd == "exec \"$@\"") {
|
||||||
// We're going to construct a new command that starts with exec, and then has the
|
// We're going to construct a new command that starts with exec, and then has the
|
||||||
|
@ -1561,7 +1570,6 @@ bool fish_xdm_login_hack_hack_hack_hack(std::vector<std::string> *cmds, int argc
|
||||||
cmds->at(0) = new_cmd;
|
cmds->at(0) = new_cmd;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue