aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/builtin_complete.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-01-16 22:42:14 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-01-16 22:42:14 -0800
commit766176443d6edbbd47f1dbe1080d9d1becf2b0c0 (patch)
treed8021e46acd13d2c6898cb5ab21de33f30a1e4d9 /src/builtin_complete.cpp
parent3552d073f62149ca908efbcb2ea5acae103ff382 (diff)
Clean up completion removal
Rather than passing a triple of short, long, is_old, pass an option as a string and then a type
Diffstat (limited to 'src/builtin_complete.cpp')
-rw-r--r--src/builtin_complete.cpp110
1 files changed, 25 insertions, 85 deletions
diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp
index 6fd4349f..ee7f235a 100644
--- a/src/builtin_complete.cpp
+++ b/src/builtin_complete.cpp
@@ -163,114 +163,54 @@ static void builtin_complete_add(const wcstring_list_t &cmd,
}
}
-/**
- Silly function
-*/
-static void builtin_complete_remove3(const wchar_t *cmd,
- int cmd_type,
- wchar_t short_opt,
- const wcstring_list_t &long_opt,
- int long_mode)
+static void builtin_complete_remove_cmd(const wcstring &cmd,
+ int cmd_type,
+ const wchar_t *short_opt,
+ const wcstring_list_t &gnu_opt,
+ const wcstring_list_t &old_opt)
{
- for (size_t i=0; i<long_opt.size(); i++)
+ bool removed = false;
+ size_t i;
+ for (i=0; short_opt[i] != L'\0'; i++)
{
- complete_remove(cmd,
- cmd_type,
- short_opt,
- long_opt.at(i).c_str(),
- long_mode);
+ complete_remove(cmd, cmd_type, wcstring(1, short_opt[i]), option_type_short);
+ removed = true;
}
-}
-
-/**
- Silly function
-*/
-static void builtin_complete_remove2(const wchar_t *cmd,
- int cmd_type,
- const wchar_t *short_opt,
- const wcstring_list_t &gnu_opt,
- const wcstring_list_t &old_opt)
-{
- const wchar_t *s = (wchar_t *)short_opt;
- if (*s)
+
+ for (i=0; i < old_opt.size(); i++)
{
- for (; *s; s++)
- {
- if (old_opt.empty() && gnu_opt.empty())
- {
- complete_remove(cmd,
- cmd_type,
- *s,
- 0,
- 0);
-
- }
- else
- {
- builtin_complete_remove3(cmd,
- cmd_type,
- *s,
- gnu_opt,
- 0);
- builtin_complete_remove3(cmd,
- cmd_type,
- *s,
- old_opt,
- 1);
- }
- }
+ complete_remove(cmd, cmd_type, old_opt.at(i), option_type_single_long);
+ removed = true;
}
- else if (gnu_opt.empty() && old_opt.empty())
+
+ for (i=0; i < gnu_opt.size(); i++)
{
- complete_remove(cmd,
- cmd_type,
- 0,
- 0,
- 0);
+ complete_remove(cmd, cmd_type, gnu_opt.at(i), option_type_double_long);
+ removed = true;
}
- else
+
+ if (! removed)
{
- builtin_complete_remove3(cmd,
- cmd_type,
- 0,
- gnu_opt,
- 0);
- builtin_complete_remove3(cmd,
- cmd_type,
- 0,
- old_opt,
- 1);
-
+ // This means that all loops were empty
+ complete_remove_all(cmd, cmd_type);
}
-
-
}
-/**
- Silly function
-*/
static void builtin_complete_remove(const wcstring_list_t &cmd,
const wcstring_list_t &path,
const wchar_t *short_opt,
const wcstring_list_t &gnu_opt,
const wcstring_list_t &old_opt)
{
+
for (size_t i=0; i<cmd.size(); i++)
{
- builtin_complete_remove2(cmd.at(i).c_str(),
- COMMAND,
- short_opt,
- gnu_opt,
- old_opt);
+ builtin_complete_remove_cmd(cmd.at(i), COMMAND, short_opt, gnu_opt, old_opt);
}
for (size_t i=0; i<path.size(); i++)
{
- builtin_complete_remove2(path.at(i).c_str(),
- PATH,
- short_opt,
- gnu_opt,
- old_opt);
+ builtin_complete_remove_cmd(path.at(i), PATH, short_opt, gnu_opt, old_opt);
}
}