Skip to content

Commit

Permalink
Mingw cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisant996 committed Aug 19, 2024
1 parent 9ef930c commit b9a8a56
Show file tree
Hide file tree
Showing 36 changed files with 176 additions and 83 deletions.
19 changes: 14 additions & 5 deletions clink/app/src/host/host_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,14 @@ BOOL WINAPI host_cmd::read_console(
void* _chars,
DWORD max_chars,
LPDWORD read_in,
__CONSOLE_READCONSOLE_CONTROL* control)
__CONSOLE_READCONSOLE_CONTROL* __control)
{
#if defined(__MINGW32__) || defined(__MINGW64__)
const CONSOLE_READCONSOLE_CONTROL* const control = reinterpret_cast<CONSOLE_READCONSOLE_CONTROL*>(__control);
#else
const CONSOLE_READCONSOLE_CONTROL* const control = __control;
#endif

seh_scope seh;
wchar_t* const chars = reinterpret_cast<wchar_t*>(_chars);

Expand All @@ -494,7 +500,7 @@ BOOL WINAPI host_cmd::read_console(

// if the input handle isn't a console handle then go the default route.
if (GetFileType(input) != FILE_TYPE_CHAR)
return __Real_ReadConsoleW(input, chars, max_chars, read_in, control);
return __Real_ReadConsoleW(input, chars, max_chars, read_in, __control);

host_cmd* const hc = host_cmd::get();

Expand Down Expand Up @@ -529,7 +535,7 @@ BOOL WINAPI host_cmd::read_console(
// Default behaviour.
if (hc->dequeue_char(chars))
return TRUE;
return __Real_ReadConsoleW(input, chars, max_chars, read_in, control);
return __Real_ReadConsoleW(input, chars, max_chars, read_in, __control);
}

s_answered = 0;
Expand Down Expand Up @@ -583,7 +589,7 @@ BOOL WINAPI host_cmd::read_console(
// it ended with a newline.
return true;
}
return __Real_ReadConsoleW(input, chars, max_chars, read_in, control);
return __Real_ReadConsoleW(input, chars, max_chars, read_in, __control);
}

// Respond with a queued line, if available.
Expand Down Expand Up @@ -708,7 +714,10 @@ static void update_pushd_depth(const wchar_t* chars, int32 char_count)
{
str<> expanded;
str<> captured;
to_utf8(captured, wstr_iter(chars, char_count));
{
wstr_iter iter(chars, char_count); // Because MINGW can't handle it inline.
to_utf8(captured, iter);
}
if (prompt_utils::expand_prompt_codes(var.c_str(), expanded, expand_prompt_flags::omit_pushd) &&
expanded.length() <= captured.length())
{
Expand Down
2 changes: 1 addition & 1 deletion clink/app/src/loader/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void translate_history_line(str_base& out, const char* in, uint32 len)
out.concat(begin, int32(walk - begin));
if (!len)
break;
char ctrl[3] = { '^', *walk + 'A' - 1 };
char ctrl[3] = { '^', char(*walk + 'A' - 1) };
out.concat(ctrl, 2);
++walk, --len;
}
Expand Down
4 changes: 2 additions & 2 deletions clink/app/src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <io.h>
#include <locale.h>
#include <stdlib.h>
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <stdint.h>
#endif

Expand All @@ -23,7 +23,7 @@
# pragma warning(disable : 4091)
#endif
#include <Shlobj.h>
#ifndef __MINGW32__
#if !(defined(__MINGW32__) || defined(__MINGW64__))
# include <DbgHelp.h>
#endif
#ifdef _MSC_VER
Expand Down
2 changes: 1 addition & 1 deletion clink/app/src/utils/reset_stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
another way to encounter the problems is by async prompt filtering.
*/

#if !defined(__MINGW32__) && !defined(__MINGW64__)
#if !(defined(__MINGW32__) || defined(__MINGW64__))

//------------------------------------------------------------------------------
static bool s_can_reset = true;
Expand Down
2 changes: 2 additions & 0 deletions clink/core/include/core/bldopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
//#define DEBUG_RESOLVEIMPL
//#define USE_OS_UTF_CONVERSION
//#define REPORT_READLINE_UNDO_LIST_LEAKS
#endif
#if defined(DEBUG) && defined(USE_MEMORY_TRACKING)
#define UNDO_LIST_HEAP_DIAGNOSTICS
#endif

Expand Down
3 changes: 2 additions & 1 deletion clink/core/include/core/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class str_moveable;

class str_base;

#ifndef _S_IFLNK
#define _S_IFLNK (0x0800)
#define S_IFLNK _S_IFLNK

#define S_ISLNK(m) (((m)&S_IFLNK) == S_IFLNK)
#endif

//------------------------------------------------------------------------------
namespace os
Expand Down
16 changes: 8 additions & 8 deletions clink/core/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ static bool load_internal(FILE* in, std::function<void(const char* name, const c

// 'key = value'?
was_comment = false;
char* value = strchr(line_data, '=');
if (value == nullptr)
char* key_end = strchr(line_data, '=');
if (key_end == nullptr)
{
if (!maybe_clink_set)
continue;
Expand All @@ -165,17 +165,17 @@ static bool load_internal(FILE* in, std::function<void(const char* name, const c
// troubleshooting purposes; it isn't the real file format, and it
// may not work properly if a setting name contains a space, etc.
//
value = strchr(line_data, ' ');
if (value == nullptr)
key_end = strchr(line_data, ' ');
if (key_end == nullptr)
continue;
}

*value++ = '\0';
*key_end = '\0';
const char* value = key_end + 1;

// Trim whitespace.
char* key_end = value - 2;
while (key_end >= line_data && isspace(*key_end))
--key_end;
while (--key_end >= line_data && isspace(*key_end))
{}
key_end[1] = '\0';

while (*value && isspace(*value))
Expand Down
9 changes: 9 additions & 0 deletions clink/lib/include/lib/cmd_tokenisers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

#include "word_collector.h"

//------------------------------------------------------------------------------
#ifndef _ENUM_FLAG_CONSTEXPR // Because MINGW is missing this.
# if _MSC_VER >= 1900
# define _ENUM_FLAG_CONSTEXPR constexpr
# else
# define _ENUM_FLAG_CONSTEXPR
# endif
#endif

//------------------------------------------------------------------------------
enum tokeniser_state : int32;

Expand Down
10 changes: 7 additions & 3 deletions clink/lib/include/lib/match_colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

#include "matches.h"

enum indicator_no;
#if defined(__MINGW32__) || defined(__MINGW64__)
#define enum_indicator_no int32
#else
#define enum_indicator_no enum indicator_no
#endif

void parse_match_colors();
bool using_match_colors();
bool get_match_color(const char* filename, match_type type, str_base& out);
const char* get_indicator_color(indicator_no colored_filetype);
const char* get_indicator_color(enum_indicator_no colored_filetype);
const char* get_completion_prefix_color();
bool is_colored(indicator_no colored_filetype);
bool is_colored(enum_indicator_no colored_filetype);
void make_color(const char* seq, str_base& out);
2 changes: 1 addition & 1 deletion clink/lib/include/lib/matches_lookaside.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class match_details
{
public:
match_details(const char* match, const match_extra* extra);
operator bool() const { return m_match; }
operator bool() const { return !!m_match; }
match_type get_type() const { return m_extra->type; }
const char* get_match() const { return m_match; }
const char* get_display() const { return m_match ? m_match + m_extra->display_offset : nullptr; }
Expand Down
6 changes: 5 additions & 1 deletion clink/lib/src/display_readline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#define REPORT_REDISPLAY
#endif

#if defined(__MINGW32__) || defined(__MINGW64__)
#undef REPORT_REDISPLAY
#endif

#include "display_readline.h"
#include "line_buffer.h"
#include "ellipsify.h"
Expand Down Expand Up @@ -966,7 +970,7 @@ void display_lines::set_top(uint32 top)
//------------------------------------------------------------------------------
void display_lines::set_comment_row(str_moveable&& s, comment_row_type type)
{
#ifdef DEBUG
#if defined(DEBUG) && defined(USE_MEMORY_TRACKING)
if (!s.empty())
dbgsetignore(s.c_str());
#endif
Expand Down
1 change: 1 addition & 0 deletions clink/lib/src/line_editor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern setting_enum g_default_bindings;
extern setting_color g_color_histexpand;
// TODO: line_editor_impl vs rl_module.
extern int32 g_suggestion_offset;
void before_display_readline();



Expand Down
36 changes: 20 additions & 16 deletions clink/lib/src/match_colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static char* s_colors[C_NUM_INDICATORS_EXTENDED] = {};
static const char* s_error_context = nullptr;

//------------------------------------------------------------------------------
bool is_colored(indicator_no colored_filetype)
bool is_colored(enum_indicator_no colored_filetype)
{
char const* s = s_colors[colored_filetype];
if (!s || !*s) return false; // Empty.
Expand Down Expand Up @@ -370,7 +370,10 @@ static int32 get_token(str_iter& iter, str_base& token, char delim1, char delim2
if (verbatim)
goto concat_text;
WCHAR wc = num;
to_utf8(token, wstr_iter(&wc, 1));
{
wstr_iter iter(&wc, 1); // Because MINGW can't handle it inline.
to_utf8(token, iter);
}
}
break;

Expand Down Expand Up @@ -483,7 +486,7 @@ static bool parse_rule(str_iter& iter, str<16>& value, color_rule& rule)

str<> token;
bool ever_any = false;
bool not = false;
bool not_operator = false;
while (iter.more())
{
bool quoted;
Expand All @@ -494,7 +497,7 @@ static bool parse_rule(str_iter& iter, str<16>& value, color_rule& rule)

if (token.iequals("not"))
{
not = true;
not_operator = true;
continue;
}

Expand All @@ -507,7 +510,7 @@ static bool parse_rule(str_iter& iter, str<16>& value, color_rule& rule)
{
num_flags++;
rlind = ind.rlind;
if (not)
if (not_operator)
rule.m_not_cflags |= ind.cflag;
else
rule.m_cflags |= ind.cflag;
Expand All @@ -532,12 +535,12 @@ static bool parse_rule(str_iter& iter, str<16>& value, color_rule& rule)
pat.m_pattern.concat(token.c_str(), token.length());
//pat.m_only_filename = !strpbrk(token.c_str(), "/\\");
pat.m_only_filename = true;
pat.m_not = not;
pat.m_not = not_operator;
// printf("pat '%s'%s\n", pat.m_pattern.c_str(), not ? " (not)" : "");
rule.m_patterns.emplace_back(std::move(pat));
}

not = false;
not_operator = false;
}

// Readonly by itself should set CFLAG_READONLY|CFLAG_FILE so by itself it
Expand Down Expand Up @@ -726,7 +729,8 @@ void parse_match_colors()
else
{
color_rule rule;
if (parse_rule(str_iter(token.c_str(), token.length()), value, rule))
str_iter token_iter(token.c_str(), token.length()); // Because MINGW can't handle it inline.
if (parse_rule(token_iter, value, rule))
{
s_colored_stats = true;
s_color_rules.emplace_back(std::move(rule));
Expand Down Expand Up @@ -756,7 +760,7 @@ bool using_match_colors()
}

//------------------------------------------------------------------------------
static void ls_concat_color_indicator(enum indicator_no colored_filetype, str_base& out)
static void ls_concat_color_indicator(enum_indicator_no colored_filetype, str_base& out)
{
const struct bin_str *ind = &LS_COLORS_indicator[colored_filetype];
out.concat(ind->string, ind->len);
Expand Down Expand Up @@ -788,7 +792,7 @@ void make_color(const char* seq, str_base& out)
//------------------------------------------------------------------------------
static bool get_ls_color(const char *f, match_type type, str_base& out)
{
enum indicator_no colored_filetype;
enum_indicator_no colored_filetype;
COLOR_EXT_TYPE *ext; // Color extension.
size_t len; // Length of name.

Expand Down Expand Up @@ -1013,7 +1017,7 @@ bool get_match_color(const char* f, match_type type, str_base& out)

// Identify flags for matching, and identify default color type.
int32 cflags;
indicator_no colored_filetype;
enum_indicator_no colored_filetype;
if (linkok == -1 && s_colors[C_MISSING] != nullptr)
{
colored_filetype = C_MISSING;
Expand Down Expand Up @@ -1072,13 +1076,13 @@ bool get_match_color(const char* f, match_type type, str_base& out)
{
if (is_match_type_readonly(type))
{
colored_filetype = indicator_no(C_READONLY);
colored_filetype = (enum_indicator_no)(C_READONLY);
cflags |= CFLAG_READONLY;
}
// Hidden takes precedence over Readonly, if no rules match.
if (is_match_type_hidden(type))
{
colored_filetype = indicator_no(C_HIDDEN);
colored_filetype = (enum_indicator_no)(C_HIDDEN);
cflags |= CFLAG_HIDDEN;
}
}
Expand All @@ -1100,8 +1104,8 @@ bool get_match_color(const char* f, match_type type, str_base& out)
}
name = tmp.c_str();
// Directory takes precedence over Readonly, if no rules match.
if (colored_filetype == indicator_no(C_READONLY))
colored_filetype = indicator_no(C_DIR);
if (colored_filetype == (enum_indicator_no)(C_READONLY))
colored_filetype = (enum_indicator_no)(C_DIR);
}

// Look for a matching rule. First match wins.
Expand Down Expand Up @@ -1164,7 +1168,7 @@ bool get_match_color(const char* f, match_type type, str_base& out)
}

//------------------------------------------------------------------------------
const char* get_indicator_color(indicator_no colored_filetype)
const char* get_indicator_color(enum_indicator_no colored_filetype)
{
return s_colors[colored_filetype];
}
Expand Down
4 changes: 2 additions & 2 deletions clink/lib/src/recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void recognizer::clear()

m_queue.clear();

for (auto& iter = m_pending.begin(); iter != m_pending.end();)
for (auto iter = m_pending.begin(); iter != m_pending.end();)
{
char* key = iter->second.m_key;
iter = m_pending.erase(iter);
Expand All @@ -288,7 +288,7 @@ void recognizer::clear()
#endif
const time_t age = time(nullptr) - threshold;

for (auto& iter = m_cache.begin(); iter != m_cache.end();)
for (auto iter = m_cache.begin(); iter != m_cache.end();)
{
if (iter->second.m_age < age)
{
Expand Down
2 changes: 1 addition & 1 deletion clink/lib/src/rl/rl_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ static void safe_replace_keymap(Keymap replace, Keymap with)
}
break;
case ISMACR:
free(replace[i].function);
free((void*)replace[i].function);
break;
}

Expand Down
1 change: 1 addition & 0 deletions clink/lua/src/async_lua_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pch.h"
#include "lua_state.h"
#include "lua_input_idle.h"
#include "lua_task_manager.h"
#include "async_lua_task.h"

#include <core/os.h>
Expand Down
Loading

0 comments on commit b9a8a56

Please sign in to comment.