Skip to content

Commit

Permalink
Fixed #16, problems with $T in doskey macros.
Browse files Browse the repository at this point in the history
- Fixed output while running multiline doskey macros, and don't load
lua or history to improve speed since they aren't needed while replaying
doskey macros.
- Fixed doskey macros that start with $T or have multiple adjacent $T.
  • Loading branch information
chrisant996 committed Nov 4, 2020
1 parent 57d4cdf commit bf0c950
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
14 changes: 9 additions & 5 deletions clink/app/src/host/doskey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ bool doskey_alias::next(str_base& out)
if (!*m_cursor)
return false;

out.copy(m_cursor);
out.clear();
while (*m_cursor)
{
char c = *m_cursor++;
if (c == '\n')
break;
out.concat(&c, 1);
}

while (*m_cursor++);
return true;
}

Expand Down Expand Up @@ -233,7 +239,7 @@ bool doskey::resolve_impl(const str_iter& in, str_stream* out)
case 'g': case 'G': stream << '>'; continue;
case 'l': case 'L': stream << '<'; continue;
case 'b': case 'B': stream << '|'; continue;
case 't': case 'T': stream << '\0'; continue;
case 't': case 'T': stream << '\n'; continue;
}

// Unknown tag? Perhaps it is a argument one?
Expand Down Expand Up @@ -314,8 +320,6 @@ void doskey::resolve(const char* chars, doskey_alias& out)
else if (!resolve_impl(str_iter(chars), &stream))
return;

// Double null-terminated as aliases with $T become and array of commands.
stream << '\0';
stream << '\0';

// Collect the resolve result
Expand Down
62 changes: 36 additions & 26 deletions clink/app/src/host/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,19 @@ bool host::edit_line(const char* prompt, str_base& out)
}
str_compare_scope compare(cmp_mode);

bool init_scripts = !m_doskey_alias;
bool init_history = !m_doskey_alias;

// Set up Lua and load scripts into it.
str<288> script_path;
app_context::get()->get_script_path(script_path);
host_lua lua(script_path.c_str());
prompt_filter prompt_filter(lua);
initialise_lua(lua);
lua.load_scripts();
if (init_scripts)
{
initialise_lua(lua);
lua.load_scripts();
}

// Unfortunately we need to load settings again because some settings don't
// exist until after Lua's up and running. But.. we can't load Lua scripts
Expand All @@ -302,10 +308,13 @@ bool host::edit_line(const char* prompt, str_base& out)
line_editor::desc desc = {};
initialise_editor_desc(desc);

// Filter the prompt.
// Filter the prompt. Unless processing a multiline doskey macro.
str<256> filtered_prompt;
prompt_filter.filter(prompt, filtered_prompt);
desc.prompt = filtered_prompt.c_str();
if (init_scripts)
{
prompt_filter.filter(prompt, filtered_prompt);
desc.prompt = filtered_prompt.c_str();
}

// Set the terminal that will handle all IO while editing.
desc.input = m_terminal.in;
Expand All @@ -315,27 +324,30 @@ bool host::edit_line(const char* prompt, str_base& out)
// Create the editor and add components to it.
line_editor* editor = line_editor_create(desc);

editor->add_generator(lua);
editor->add_generator(file_match_generator());

if (g_save_history.get())
{
if (!m_history)
m_history = new history_db;
}
else
if (init_history)
{
if (m_history)
editor->add_generator(lua);
editor->add_generator(file_match_generator());

if (g_save_history.get())
{
delete m_history;
m_history = nullptr;
if (!m_history)
m_history = new history_db;
}
else
{
if (m_history)
{
delete m_history;
m_history = nullptr;
}
}
}

if (m_history)
{
m_history->initialise();
m_history->load_rl_history();
if (m_history)
{
m_history->initialise();
m_history->load_rl_history();
}
}

s_history_db = m_history;
Expand All @@ -354,10 +366,7 @@ bool host::edit_line(const char* prompt, str_base& out)
if (m_doskey_alias.next(out))
{
m_terminal.out->begin();
m_terminal.out->write(filtered_prompt.c_str(), filtered_prompt.length());
m_terminal.out->write(out.c_str(), out.length());
m_terminal.out->end();
write_line_feed();
resolved = true;
ret = true;
}
Expand Down Expand Up @@ -415,7 +424,8 @@ bool host::edit_line(const char* prompt, str_base& out)
if (!resolved)
{
m_doskey.resolve(out.c_str(), m_doskey_alias);
m_doskey_alias.next(out);
if (m_doskey_alias)
out.clear();
}

s_history_db = nullptr;
Expand Down

0 comments on commit bf0c950

Please sign in to comment.
-