From f42f7b7208117f18b52643320631c2a6e14cb82f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 03:39:53 -0600 Subject: [PATCH] Clean up detritus of process expansion --- src/expand.cpp | 77 ++------------------------------------------------ src/expand.h | 2 -- 2 files changed, 3 insertions(+), 76 deletions(-) diff --git a/src/expand.cpp b/src/expand.cpp index 631c6638a..7605ed353 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -564,68 +564,6 @@ static void find_process(const wchar_t *proc, expand_flags_t flags, } } -/// Process id expansion. -static bool expand_pid(const wcstring &instr_with_sep, expand_flags_t flags, - std::vector *out, parse_error_list_t *errors) { - // Hack. If there's no INTERNAL_SEP and no PROCESS_EXPAND, then there's nothing to do. Check out - // this "null terminated string." - const wchar_t some_chars[] = {INTERNAL_SEPARATOR, PROCESS_EXPAND, L'\0'}; - if (instr_with_sep.find_first_of(some_chars) == wcstring::npos) { - // Nothing to do. - append_completion(out, instr_with_sep); - return true; - } - - // expand_string calls us with internal separators in instr...sigh. - wcstring instr = instr_with_sep; - remove_internal_separator(&instr, false); - - if (instr.empty() || instr.at(0) != PROCESS_EXPAND) { - // Not a process expansion. - append_completion(out, instr); - return true; - } - - const wchar_t *const in = instr.c_str(); - - // We know we are a process expansion now. - assert(in[0] == PROCESS_EXPAND); - return true; - - if (flags & EXPAND_FOR_COMPLETIONS) { - if (wcsncmp(in + 1, SELF_STR, wcslen(in + 1)) == 0) { - append_completion(out, &SELF_STR[wcslen(in + 1)], COMPLETE_SELF_DESC, 0); - } else if (wcsncmp(in + 1, LAST_STR, wcslen(in + 1)) == 0) { - append_completion(out, &LAST_STR[wcslen(in + 1)], COMPLETE_LAST_DESC, 0); - } - } else { - if (wcscmp((in + 1), SELF_STR) == 0) { - append_completion(out, to_string(getpid())); - return true; - } - if (wcscmp((in + 1), LAST_STR) == 0) { - if (proc_last_bg_pid > 0) { - append_completion(out, to_string(proc_last_bg_pid)); - } - return true; - } - } - - // This is sort of crummy - find_process doesn't return any indication of success, so instead we - // check to see if it inserted any completions. - const size_t prev_count = out->size(); - find_process(in + 1, flags, out); - - if (prev_count == out->size() && !(flags & EXPAND_FOR_COMPLETIONS)) { - // We failed to find anything. - append_syntax_error(errors, 1, FAILED_EXPANSION_PROCESS_ERR_MSG, - escape_string(in + 1, ESCAPE_NO_QUOTED).c_str()); - return false; - } - - return true; -} - /// Parse an array slicing specification Returns 0 on success. If a parse error occurs, returns the /// index of the bad token. Note that 0 can never be a bad index because the string always starts /// with [. @@ -1341,7 +1279,7 @@ static expand_error_t expand_stage_brackets(const wcstring &input, std::vector *out, expand_flags_t flags, parse_error_list_t *errors) { wcstring next = input; @@ -1349,16 +1287,7 @@ static expand_error_t expand_stage_home_and_pid(const wcstring &input, if (!(EXPAND_SKIP_HOME_DIRECTORIES & flags)) { expand_home_directory(next); } - - if (flags & EXPAND_FOR_COMPLETIONS) { - if (!next.empty() && next.at(0) == PROCESS_EXPAND) { - expand_pid(next, flags, out, NULL); - return EXPAND_OK; - } - append_completion(out, next); - } else if (!expand_pid(next, flags, out, errors)) { - return EXPAND_ERROR; - } + append_completion(out, next); return EXPAND_OK; } @@ -1464,7 +1393,7 @@ expand_error_t expand_string(const wcstring &input, std::vector *o // Our expansion stages. const expand_stage_t stages[] = {expand_stage_cmdsubst, expand_stage_variables, - expand_stage_brackets, expand_stage_home_and_pid, + expand_stage_brackets, expand_stage_home, expand_stage_wildcards}; // Load up our single initial completion. diff --git a/src/expand.h b/src/expand.h index 2d8605457..771d8773b 100644 --- a/src/expand.h +++ b/src/expand.h @@ -60,8 +60,6 @@ class completion_t; enum { /// Character representing a home directory. HOME_DIRECTORY = EXPAND_RESERVED_BASE, - /// Character representing process expansion. - PROCESS_EXPAND, /// Character representing variable expansion. VARIABLE_EXPAND, /// Character representing variable expansion into a single element.