diff --git a/src/basic/basic_alloc.cpp b/src/basic/basic_alloc.cpp index c215496..9262302 100644 --- a/src/basic/basic_alloc.cpp +++ b/src/basic/basic_alloc.cpp @@ -92,6 +92,7 @@ API bool VDecommit(void *p, size_t size) { #endif API void *SystemAllocatorProc(void *object, int kind, void *p, size_t size) { + Unused(object); void *result = NULL; if (kind == AllocatorKind_Allocate) { result = malloc(size); @@ -125,6 +126,7 @@ thread_local Array MemoryTrackingRecord; API void *TrackingAllocatorProc(void *object, int kind, void *p, size_t size) { + Unused(object); void *result = NULL; if (kind == AllocatorKind_Allocate) { @@ -249,6 +251,7 @@ API void PopToPos(VirtualArena *arena, size_t pos) { } API void *ArenaAllocatorProc(void *object, int kind, void *p, size_t size) { + Unused(p); if (kind == AllocatorKind_Allocate) { return PushSize((VirtualArena *)object, size); } else if (AllocatorKind_Deallocate) { @@ -316,6 +319,7 @@ API void Unwind(BlockArena *arena, U8 *pos) { } API void *BlockArenaAllocatorProc(void *object, int kind, void *p, size_t size) { + Unused(p); BlockArena *arena = (BlockArena *)object; if (kind == AllocatorKind_Allocate) { return PushSize(arena, size); diff --git a/src/basic/basic_alloc.h b/src/basic/basic_alloc.h index 9e43444..c7cf20b 100644 --- a/src/basic/basic_alloc.h +++ b/src/basic/basic_alloc.h @@ -28,9 +28,13 @@ API Allocator GetTrackingAllocator(); #define MemoryZero(x, size) memset(x, 0, size) #define MemoryZeroStruct(x) memset(x, 0, sizeof(*x)) -#define MemoryCopy(dst, src, size) memcpy(dst, src, size) #define MemoryMove(dst, src, size) memmove(dst, src, size) +static inline void MemoryCopy(void *dst, void *src, size_t size) { + if (src == NULL) return; + memcpy(dst, src, size); +} + /////////////////// // Block Arena /////////////////// diff --git a/src/basic/basic_array.h b/src/basic/basic_array.h index 84c8a94..5178fef 100644 --- a/src/basic/basic_array.h +++ b/src/basic/basic_array.h @@ -165,7 +165,7 @@ Slice GetSlice(Slice &arr, int64_t first_index = 0, int64_t one_past_last_ } // Make arrays resize on every item -#define ARRAY_DEBUG BUILD_SLOW +#define ARRAY_DEBUG 0 #if ARRAY_DEBUG #define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF #else @@ -211,12 +211,11 @@ void Reserve(Array *arr, int64_t size) { T *new_data = AllocArray(arr->allocator, T, size); Assert(new_data); - memcpy(new_data, arr->data, arr->len * sizeof(T)); - Dealloc(arr->allocator, arr->data); - + MemoryCopy(new_data, arr->data, arr->len * sizeof(T)); + if (arr->data) Dealloc(arr->allocator, arr->data); arr->data = new_data; arr->cap = size; - } +} } template @@ -493,16 +492,16 @@ struct ReverseIter { friend bool operator==(const ReverseIter &a, const ReverseIter &b) { return a.data == b.data; }; friend bool operator!=(const ReverseIter &a, const ReverseIter &b) { return a.data != b.data; }; - ReverseIter begin() { return ReverseIter{arr->end() - 1, arr}; } - ReverseIter end() { return ReverseIter{arr->begin() - 1, arr}; } + ReverseIter begin() { return ReverseIter{arr->end() ? arr->end() - 1 : NULL, arr}; } + ReverseIter end() { return ReverseIter{arr->begin() ? arr->begin() - 1 : NULL, arr}; } }; template ReverseIter IterateInReverse(Array *arr) { - return {arr->end() - 1, &arr->slice}; + return {arr->end() ? arr->end() - 1 : NULL, &arr->slice}; } template ReverseIter IterateInReverse(Slice *slice) { - return {slice->end() - 1, slice}; + return {slice->end ? slice->end() - 1 : NULL, slice}; } diff --git a/src/basic/basic_head.h b/src/basic/basic_head.h index 19bec0d..dcf74fe 100644 --- a/src/basic/basic_head.h +++ b/src/basic/basic_head.h @@ -117,8 +117,9 @@ EM_JS(void, JS_Breakpoint, (), { #define MiB(x) (KiB(x) * 1024ull) #define GiB(x) (MiB(x) * 1024ull) #define TiB(x) (GiB(x) * 1024ull) -#define Lengthof(x) ((int64_t)((sizeof(x) / sizeof((x)[0])))) #define SLICE_LAST INT64_MAX +#define Lengthof(x) ((int64_t)((sizeof(x) / sizeof((x)[0])))) +#define Unused(x) (void)(x) using U8 = uint8_t; using U16 = uint16_t; @@ -132,6 +133,8 @@ using Int = S64; using UInt = U64; using Float = double; +#define IntMax INT64_MAX + template T Min(T a, T b) { if (a > b) return b; @@ -247,3 +250,14 @@ inline uint64_t GetRandomU64(RandomSeed *state) { #define STRINGIFY(x) STRINGIFY_(x) #define CONCAT_(a, b) a ## b #define CONCAT(a, b) CONCAT_(a, b) + +Int SizeToInt(size_t size) { + Assert(size <= (size_t)IntMax); + return (Int)size; +} + +Int Strlen(const char *string) { + size_t size = strlen(string); + Int result = SizeToInt(size); + return result; +} \ No newline at end of file diff --git a/src/basic/basic_os.cpp b/src/basic/basic_os.cpp index d2bf5c2..c3d79f2 100644 --- a/src/basic/basic_os.cpp +++ b/src/basic/basic_os.cpp @@ -24,10 +24,12 @@ API void (*Error)(const char *, ...); struct backtrace_state *backtrace_state = NULL; void BacktraceOnError(void *data, const char *msg, int errnum) { + Unused(data); Error("libbacktrace error: %s (errnum: %d)\n", msg, errnum); } int BacktraceOnPrint(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) { + Unused(data); Unused(pc); bool printed = false; if (filename != NULL) { char buffer[1024]; @@ -46,6 +48,7 @@ int BacktraceOnPrint(void *data, uintptr_t pc, const char *filename, int lineno, } void CrashHandler(int signal, siginfo_t* info, void* context) { + Unused(signal); Unused(info); Unused(context); backtrace_full(backtrace_state, 2, BacktraceOnPrint, BacktraceOnError, NULL); exit(1); } @@ -102,7 +105,7 @@ API bool WriteFile(String path, String data) { FILE *f = fopen((const char *)null_term.data, "w"); if (f) { size_t written = fwrite(data.data, 1, data.len, f); - if (written == data.len) { + if (SizeToInt(written) == data.len) { result = true; } fclose(f); diff --git a/src/basic/basic_string.cpp b/src/basic/basic_string.cpp index 6b2a72a..00055dd 100644 --- a/src/basic/basic_string.cpp +++ b/src/basic/basic_string.cpp @@ -188,7 +188,7 @@ API String Copy(Allocator allocator, String string) { } API String Copy(Allocator allocator, char *string) { - return Copy(allocator, {string, (int64_t)strlen(string)}); + return Copy(allocator, {string, Strlen(string)}); } API void NormalizePathInPlace(String s) { diff --git a/src/basic/basic_string.h b/src/basic/basic_string.h index a9c2a7d..644e2ee 100644 --- a/src/basic/basic_string.h +++ b/src/basic/basic_string.h @@ -5,9 +5,9 @@ struct String { int64_t len; String() = default; - String(char *s) : data(s), len(strlen(s)) {} + String(char *s) : data(s), len(Strlen(s)) {} String(char *s, int64_t l) : data((char *)s), len(l) {} - String(const char *s) : data((char *)s), len(strlen((char *)s)) {} + String(const char *s) : data((char *)s), len(Strlen((char *)s)) {} String(const char *s, int64_t l) : data((char *)s), len(l) {} diff --git a/src/basic/basic_string16.cpp b/src/basic/basic_string16.cpp index 1fdc96a..3423087 100644 --- a/src/basic/basic_string16.cpp +++ b/src/basic/basic_string16.cpp @@ -39,7 +39,7 @@ API bool IsDigit(char16_t a) { } API bool IsHexDigit(char16_t a) { - bool result = a >= u'0' && a <= u'9' || a == 'a' || a == 'b' || a == 'c' || a == 'd' || a == 'e' || a == 'f'; + bool result = (a >= u'0' && a <= u'9') || a == 'a' || a == 'b' || a == 'c' || a == 'd' || a == 'e' || a == 'f'; return result; } diff --git a/src/external/minicoro.h b/src/external/minicoro.h index bc8fd7e..5c592f5 100644 --- a/src/external/minicoro.h +++ b/src/external/minicoro.h @@ -429,8 +429,8 @@ MCO_API const char *mco_result_description(mco_result res); /* Get the descripti #else #ifdef thread_local #define MCO_THREAD_LOCAL thread_local - #elif __STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__) - #define MCO_THREAD_LOCAL _Thread_local + // #elif __STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__) + // #define MCO_THREAD_LOCAL _Thread_local #elif defined(_WIN32) && (defined(_MSC_VER) || defined(__ICL) || defined(__DMC__) || defined(__BORLANDC__)) #define MCO_THREAD_LOCAL __declspec(thread) #elif defined(__GNUC__) || defined(__SUNPRO_C) || defined(__xlC__) diff --git a/src/render/opengl.cpp b/src/render/opengl.cpp index 902fb62..806f2e7 100644 --- a/src/render/opengl.cpp +++ b/src/render/opengl.cpp @@ -75,6 +75,7 @@ static const char *glsl_fshader_es3 = R"==(#version 300 es void ReportWarningf(const char *fmt, ...); void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) { + Unused(source); Unused(type); Unused(id); Unused(length); Unused(user); ReportWarningf("OpenGL message: %s", message); if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL); diff --git a/src/test/tests.cpp b/src/test/tests.cpp index fc6aa06..33609a2 100644 --- a/src/test/tests.cpp +++ b/src/test/tests.cpp @@ -26,6 +26,7 @@ void Wait(mco_coro *co) { } void PlayTestOpen(mco_coro *co) { + Unused(co); // Open file, move a little, then open again and verify the caret didn't move // String basic_env_cpp = Format(SysAllocator, "%S/test_env", TestDir); diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 2e793b4..84e52b4 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -64,11 +64,6 @@ API Range GetBufferEndAsRange(Buffer *buffer) { return result; } -API Range GetBufferBeginAsRange(Buffer *buffer) { - Range result = {0, 0}; - return result; -} - API Range GetRange(Buffer *buffer) { Range result = {0, buffer->len}; return result; @@ -467,10 +462,6 @@ API Int GetBufferEnd(Buffer *buffer) { return buffer->len; } -API Int GetBufferStart(Buffer *buffer) { - return 0; -} - API Int GetNextEmptyLineStart(Buffer *buffer, Int pos) { Int result = pos; Int next_line = PosToLine(buffer, pos) + 1; @@ -903,7 +894,7 @@ API void RedoEdit(Buffer *buffer, Array *carets) { ProfileFunction(); if (buffer->no_history) return; - for (int i = 0; buffer->redo_stack.len > 0; i += 1) { + for (;buffer->redo_stack.len > 0;) { HistoryEntry entry = Pop(&buffer->redo_stack); HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->undo_stack, *carets); e->time = entry.time; @@ -1251,7 +1242,7 @@ void RunBufferTest() { Assert(buffer.data[15] == L'\n'); Assert(buffer.data[16] == L't'); - RawReplaceText(&buffer, GetBufferBeginAsRange(&buffer), u"Things as is\nand stuff\n"); + RawReplaceText(&buffer, {}, u"Things as is\nand stuff\n"); Assert(buffer.line_starts.len == 4); Assert(PosToLine(&buffer, 12) == 0); Assert(buffer.data[12] == L'\n'); @@ -1266,7 +1257,7 @@ void RunBufferTest() { Assert(PosToLine(&buffer, 39) == 3); Assert(buffer.data[39] == L't'); - RawReplaceText(&buffer, GetBufferBeginAsRange(&buffer), u"a"); + RawReplaceText(&buffer, {}, u"a"); Assert(buffer.line_starts.len == 4); Assert(PosToLine(&buffer, 13) == 0); Assert(PosToLine(&buffer, 14) == 1); @@ -1458,7 +1449,7 @@ Int ConvertUTF8ToUTF16UnixLine(String string, char16_t *buffer, Int buffer_cap) } if (string.data[i] == '\t') { // @WARNING: DONT INCREASE THE SIZE CARELESSLY, WE NEED TO ADJUST BUFFER SIZE - for (Int i = 0; i < 4; i += 1) buffer[buffer_len++] = u' '; + for (Int ii = 0; ii < 4; ii += 1) buffer[buffer_len++] = u' '; i += 1; continue; } diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 5faa360..d2213cb 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -75,8 +75,12 @@ void ReportErrorf(const char *fmt, ...) { BREAK(); } - Appendf(LogView, "%S\n", string); - ShowUIMessagef("%S", string); + if (LogView) { + Appendf(LogView, "%S\n", string); + ShowUIMessagef("%S", string); + } else { + printf("%.*s\n", (int)string.len, string.data); + } } void ReportConsolef(const char *fmt, ...) { diff --git a/src/text_editor/commands_clipboard.cpp b/src/text_editor/commands_clipboard.cpp index 4b36192..51925a8 100644 --- a/src/text_editor/commands_clipboard.cpp +++ b/src/text_editor/commands_clipboard.cpp @@ -45,7 +45,7 @@ void ClipboardCopy(View *view) { Range line_range = GetLineRange(buffer, line, &eof); it.range = line_range; if (eof) { - it.range.min = ClampBottom(0ll, it.range.min - 1); + it.range.min = ClampBottom(0ll, it.range.min - 1ll); } } } @@ -84,9 +84,9 @@ void ClipboardPaste(View *view) { Array edits = BeginEdit(scratch, buffer, view->carets); MergeCarets(buffer, &view->carets); for (int64_t i = 0; i < view->carets.len; i += 1) { - String16 string = SavedClipboardCarets[i]; - Caret &it = view->carets[i]; - AddEdit(&edits, it.range, string); + String16 saved_string = SavedClipboardCarets[i]; + Caret &it = view->carets[i]; + AddEdit(&edits, it.range, saved_string); } EndEdit(buffer, &edits, &view->carets, EndEdit_KillSelection); } diff --git a/src/text_editor/config.cpp b/src/text_editor/config.cpp index ec4705a..9187236 100644 --- a/src/text_editor/config.cpp +++ b/src/text_editor/config.cpp @@ -227,7 +227,7 @@ void TestParser() { Scratch scratch; { char *cmd = "ctrl-b"; - Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"}; + Lexer base_lex = {scratch, cmd, cmd, cmd + Strlen(cmd), "keybinding"}; Trigger *trigger = ParseKeyCatchAll(&base_lex); Assert(trigger->kind == TriggerKind_Key); Assert(trigger->key == SDLK_B); @@ -237,7 +237,7 @@ void TestParser() { { char *cmd = "ctrl-b shift-ctrl-a"; - Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"}; + Lexer base_lex = {scratch, cmd, cmd, cmd + Strlen(cmd), "keybinding"}; Trigger *trigger = ParseKeyCatchAll(&base_lex); Assert(trigger->kind == TriggerKind_Binary); Assert(trigger->key == ' '); @@ -253,7 +253,7 @@ void TestParser() { { char *cmd = "ctrl-b shift-ctrl-a | ctrl-c | ctrl-d"; - Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"}; + Lexer base_lex = {scratch, cmd, cmd, cmd + Strlen(cmd), "keybinding"}; Trigger *trigger = ParseKeyCatchAll(&base_lex); Assert(trigger->kind == TriggerKind_Binary); Assert(trigger->key == '|'); diff --git a/src/text_editor/draw.cpp b/src/text_editor/draw.cpp index b73cf7e..1f58324 100644 --- a/src/text_editor/draw.cpp +++ b/src/text_editor/draw.cpp @@ -212,9 +212,7 @@ void DrawWindow(Window *window, Event &event) { Vec2I mouse = MouseVec2I(); bool mouse_in_document = AreOverlapping(mouse, window->document_rect); if (mouse_in_document) { - View *view = GetView(window->active_view); - Buffer *buffer = GetBuffer(view->active_buffer); - Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse); + Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse); if (p != -1) { Range range = EncloseLoadWord(buffer, p); if (InBounds(caret.range, p)) range = caret.range; diff --git a/src/text_editor/event.cpp b/src/text_editor/event.cpp index 60cb793..971c14c 100644 --- a/src/text_editor/event.cpp +++ b/src/text_editor/event.cpp @@ -347,18 +347,18 @@ struct { String string; SDL_Keycode value; } SDLKeycodeConversionTable[] = { }; void FillEventWithBasicData(Event *event) { - if (OS_WINDOWS) { +#if OS_WINDOWS if (GetKeyState(VK_SHIFT) & 0x8000) event->shift = 1; if (GetKeyState(VK_CONTROL) & 0x8000) event->ctrl = 1; if (GetKeyState(VK_MENU) & 0x8000) event->alt = 1; if (GetKeyState(VK_LWIN) & 0x8000) event->super = 1; - } else { +#else SDL_Keymod mod = SDL_GetModState(); event->shift = (mod & SDL_KMOD_SHIFT) != 0; event->ctrl = (mod & SDL_KMOD_CTRL) != 0; event->alt = (mod & SDL_KMOD_ALT) != 0; event->super = (mod & SDL_KMOD_GUI) != 0; - } +#endif float xmouse, ymouse; SDL_GetMouseState(&xmouse, &ymouse); @@ -499,10 +499,10 @@ void GetEventsForFrame(Array *events) { } if (events->len == 0) { - Event event = {}; - FillEventWithBasicData(&event); - event.kind = EVENT_UPDATE; - Add(events, event); + Event ev = {}; + FillEventWithBasicData(&ev); + ev.kind = EVENT_UPDATE; + Add(events, ev); } Assert(events->len); diff --git a/src/text_editor/fuzzy_search_view.cpp b/src/text_editor/fuzzy_search_view.cpp index ff75aa6..bd5cdd1 100644 --- a/src/text_editor/fuzzy_search_view.cpp +++ b/src/text_editor/fuzzy_search_view.cpp @@ -1,8 +1,8 @@ -float NewFuzzyRate(String16 s, String16 p) { - float score = 0; - // try to do this: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go - return score; -} +// float NewFuzzyRate(String16 s, String16 p) { +// float score = 0; +// // try to do this: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go +// return score; +// } float FuzzyRate(String16 s, String16 p) { float score = 0; diff --git a/src/text_editor/plugin_build_window.cpp b/src/text_editor/plugin_build_window.cpp index 3680cd7..5403708 100644 --- a/src/text_editor/plugin_build_window.cpp +++ b/src/text_editor/plugin_build_window.cpp @@ -22,6 +22,7 @@ void InitBuildWindow() { } void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy) { + Unused(wx); Unused(wy); Window *window = GetWindow(BuildWindowID); Rect2I copy_rect = *rect; if (!window->visible) { diff --git a/src/text_editor/plugin_command_window.cpp b/src/text_editor/plugin_command_window.cpp index 629cffd..0b192fb 100644 --- a/src/text_editor/plugin_command_window.cpp +++ b/src/text_editor/plugin_command_window.cpp @@ -12,7 +12,7 @@ void CMD_ShowCommands() { } } command_bar.view->update_scroll = true; - SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); + SelectRange(command_bar.view, Range{}); } RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window"); void CMD_ShowDebugBufferList() { @@ -31,7 +31,7 @@ void CMD_ShowDebugBufferList() { RawAppendf(command_bar.buffer, "\n%S", it->name); } command_bar.view->update_scroll = true; - SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); + SelectRange(command_bar.view, Range{}); } RegisterCommand(CMD_ShowDebugBufferList, "ctrl-shift-alt-p", "Show full list of buffers, including the special ones that normally just clutter list"); void CMD_ShowBufferList() { @@ -50,10 +50,11 @@ void CMD_ShowBufferList() { RawAppendf(command_bar.buffer, "\n%S", it->name); } command_bar.view->update_scroll = true; - SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); + SelectRange(command_bar.view, Range{}); } RegisterCommand(CMD_ShowBufferList, "ctrl-p", "List open buffers inside the command window that you can fuzzy search over"); void LayoutCommandWindow(Rect2I *rect, int16_t wx, int16_t wy) { + Unused(wy); Window *window = GetWindow(CommandWindowID); Rect2I copy_rect = *rect; if (!window->visible) { diff --git a/src/text_editor/plugin_config.cpp b/src/text_editor/plugin_config.cpp index 88e6df8..2f424fd 100644 --- a/src/text_editor/plugin_config.cpp +++ b/src/text_editor/plugin_config.cpp @@ -82,7 +82,7 @@ BufferID LoadConfig(String config_path) { #define ExpectP(x, ...) \ if (!(x)) { \ - ReportErrorf("Failed to parse '" __FUNCTION__ "' command, " __VA_ARGS__); \ + ReportErrorf("Failed to parse command " __VA_ARGS__); \ return; \ } diff --git a/src/text_editor/plugin_debug_window.cpp b/src/text_editor/plugin_debug_window.cpp index 5ad0490..4e31d86 100644 --- a/src/text_editor/plugin_debug_window.cpp +++ b/src/text_editor/plugin_debug_window.cpp @@ -25,6 +25,7 @@ void InitDebugWindow() { } void LayoutDebugWindow(Rect2I *rect, int16_t wx, int16_t wy) { + Unused(rect); Window *window = GetWindow(DebugWindowID); Rect2 screen_rect = Rect0Size((float)wx, (float)wy); Vec2 size = GetSize(screen_rect); @@ -47,9 +48,7 @@ void UpdateDebugWindow() { return; } - BSet main = GetBSet(PrimaryWindowID); RawReplaceText(set.buffer, GetRange(set.buffer), u"Active buffers and views:\n"); - For (Views) { Buffer *buffer = GetBuffer(it->active_buffer); RawAppendf(set.buffer, "view->id:%lld, buffer->id:%lld, buffer->name:%S\n", (long long)it->id.id, (long long)buffer->id.id, buffer->name); diff --git a/src/text_editor/plugin_directory_navigation.cpp b/src/text_editor/plugin_directory_navigation.cpp index fd09e13..3eec84d 100644 --- a/src/text_editor/plugin_directory_navigation.cpp +++ b/src/text_editor/plugin_directory_navigation.cpp @@ -61,7 +61,7 @@ void OpenDirectoryNavigation(View *view) { // view->update_hook = UpdateDirectoryNavigation; Buffer *buffer = GetBuffer(view->active_buffer); InsertDirectoryNavigation(buffer); - SelectRange(view, GetBufferBeginAsRange(buffer)); + SelectRange(view, Range{}); } #if 0 diff --git a/src/text_editor/plugin_file_commands.cpp b/src/text_editor/plugin_file_commands.cpp index cd2d1b0..77f50c1 100644 --- a/src/text_editor/plugin_file_commands.cpp +++ b/src/text_editor/plugin_file_commands.cpp @@ -108,7 +108,6 @@ void CO_Close(mco_coro *co) { void CMD_DeleteFile() { BSet main = GetBSet(PrimaryWindowID); - String buffer_name = main.buffer->name; DeleteFile(main.buffer->name); Close(main.buffer->id); } RegisterCommand(CMD_DeleteFile, "", "Close the open buffer and delete it's corresponding file on disk"); diff --git a/src/text_editor/plugin_profiler.h b/src/text_editor/plugin_profiler.h index 24511a8..24fd307 100644 --- a/src/text_editor/plugin_profiler.h +++ b/src/text_editor/plugin_profiler.h @@ -294,6 +294,7 @@ SPALL_FN bool spall_flush(SpallProfile *ctx) { } SPALL_FN bool spall_buffer_init(SpallProfile *ctx, SpallBuffer *wb) { + (void)(ctx); // Fails if buffer is not big enough to contain at least one event! if (wb->length < sizeof(SpallBufferHeader) + sizeof(SpallBeginEventMax)) { return false; diff --git a/src/text_editor/plugin_search_window.cpp b/src/text_editor/plugin_search_window.cpp index 4a09825..30e0fb2 100644 --- a/src/text_editor/plugin_search_window.cpp +++ b/src/text_editor/plugin_search_window.cpp @@ -84,6 +84,7 @@ void InitSearchWindow() { } void LayoutSearchWindow(Rect2I *rect, int16_t wx, int16_t wy) { + Unused(wx); Unused(wy); Window *window = GetWindow(SearchWindowID); Rect2I copy_rect = *rect; if (!window->visible) { diff --git a/src/text_editor/plugin_status_window.cpp b/src/text_editor/plugin_status_window.cpp index 795cabb..6c64a85 100644 --- a/src/text_editor/plugin_status_window.cpp +++ b/src/text_editor/plugin_status_window.cpp @@ -18,6 +18,7 @@ void InitStatusWindow() { } void LayoutStatusWindow(Rect2I *rect, int16_t wx, int16_t wy) { + Unused(wx); Unused(wy); Window *window = GetWindow(StatusWindowID); Rect2I copy_rect = *rect; if (!window->visible) { diff --git a/src/text_editor/plugin_word_complete.cpp b/src/text_editor/plugin_word_complete.cpp index 7dc9766..313eb49 100644 --- a/src/text_editor/plugin_word_complete.cpp +++ b/src/text_editor/plugin_word_complete.cpp @@ -55,7 +55,7 @@ void CWSLexIdentifiers(Array *out_idents, Buffer *buffer) { Array idents = {CWS.arena}; String16 string = GetString(buffer); Lexer2 lexer = BeginLexing(string.data); - for (int i = 0;; i += 1) { + for (;;) { String16 token = Next(&lexer); if (token.len <= 0) { break; @@ -141,12 +141,9 @@ void WordComplete(mco_coro *co) { goto yield; } } - StringAndDistance it = idents[i]; - String16 ident = Copy16(CWS.arena, it.string); - CWS.last_string = ident; - Range range = EncloseWord(CWS.buffer, CWS.original_caret_pos); - SelectRange(CWS.view, range); - Replace(CWS.view, ident); + CWS.last_string = Copy16(CWS.arena, idents[i].string); + SelectRange(CWS.view, EncloseWord(CWS.buffer, CWS.original_caret_pos)); + Replace(CWS.view, CWS.last_string); yield:; mco_yield(co); if (CWS.direction == -1 && i > 0 && i == idents.len) { @@ -155,7 +152,7 @@ void WordComplete(mco_coro *co) { i -= 1; } i += CWS.direction; - i = Clamp(i, 0ll, idents.len); + i = Clamp(i, (Int)0, idents.len); } } @@ -183,7 +180,7 @@ void WordComplete(View *view, Int pos) { CWS.original_caret_pos = pos; CWS.prefix_string = Copy16(CWS.arena, prefix); - mco_desc desc = mco_desc_init(WordComplete, NULL); + mco_desc desc = mco_desc_init(WordComplete, 0); mco_result res = mco_create(&CWS.co, &desc); Assert(res == MCO_SUCCESS); } diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index ec4e40b..7990f33 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -408,9 +408,7 @@ void OnCommand(Event event) { } } - BSet main = GetBSet(PrimaryWindowID); BSet active = GetBSet(ActiveWindowID); - bool executed = false; For (active.view->commands) { if (it.trigger && MatchEvent(it.trigger, &event)) { @@ -459,8 +457,11 @@ void OnCommand(Event event) { } } - IF_SLOW_BUILD(AssertRanges(main.view->carets)); - IF_SLOW_BUILD(AssertRanges(active.view->carets)); +#if SLOW_BUILD + BSet main = GetBSet(PrimaryWindowID); + AssertRanges(main.view->carets); + AssertRanges(active.view->carets); +#endif } void EvalCommand(String command) { @@ -845,7 +846,7 @@ void MainLoop() { SDL_GL_SwapWindow(SDLWindow); } -#if _WIN32 +#if OS_WINDOWS int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) #else extern char **environ; @@ -853,7 +854,7 @@ int main(int argc, char **argv) #endif { InitScratch(); - InitOS((OSErrorReport *)printf); + InitOS(ReportErrorf); #if OS_WINDOWS int argc = __argc; char **argv = __argv; @@ -912,8 +913,6 @@ int main(int argc, char **argv) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay(); - const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id); // int w8 = (int)(display_mode->w * 0.8); // int h8 = (int)(display_mode->h * 0.8); @@ -923,6 +922,8 @@ int main(int argc, char **argv) int xhalf = 100; int yhalf = 100; #else + SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay(); + const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id); int whalf = (int)(display_mode->w * 0.5) - 10; int hhalf = (int)(display_mode->h) - 120; int xhalf = whalf; diff --git a/src/text_editor/ui.cpp b/src/text_editor/ui.cpp index 5152a72..474f94e 100644 --- a/src/text_editor/ui.cpp +++ b/src/text_editor/ui.cpp @@ -84,7 +84,6 @@ void DetectUserFileCallback(Window *window, ResolvedOpen *resolved) { String16 QueryUserString(mco_coro *co, String ask) { BSet main = GetBSet(PrimaryWindowID); - Buffer *original_buffer = main.buffer; JumpTempBuffer(&main); NextActiveWindowID = main.window->id; RawAppendf(main.buffer, R"==( diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 6007118..684e7b7 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -618,18 +618,18 @@ void IndentSelectedLines(View *view, bool shift = false) { indent_string.len = IndentSize; if (!shift) { AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, indent_string); - For (saved_xy) { - if (it.front.y == i) it.front.x += indent_string.len; - if (it.back.y == i) it.back.x += indent_string.len; + ForItem (xy, saved_xy) { + if (xy.front.y == i) xy.front.x += indent_string.len; + if (xy.back.y == i) xy.back.x += indent_string.len; } } else { Int whitespace_len = 0; - for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == u' '; i += 1) { + for (Int ii = 0; ii < IndentSize && ii < string.len && string.data[ii] == u' '; ii += 1) { whitespace_len += 1; } - For (saved_xy) { - if (it.front.y == i) it.front.x -= whitespace_len; - if (it.back.y == i) it.back.x -= whitespace_len; + ForItem (xy, saved_xy) { + if (xy.front.y == i) xy.front.x -= whitespace_len; + if (xy.back.y == i) xy.back.x -= whitespace_len; } AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min + whitespace_len}, u""); diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index 3794152..45aced0 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -279,30 +279,29 @@ void GotoNextInList(Window *window, Int line_offset = 1) { bool opened = false; for (Int i = line + line_offset; i >= 0 && i < buffer_goto->line_starts.len; i += line_offset) { Range line_range = GetLineRangeWithoutNL(buffer_goto, i); - String16 line = GetString(buffer_goto, line_range); + String16 string_line = GetString(buffer_goto, line_range); { Int idx = 0; String16 delim = u"||>"; - if (Seek(line, delim, &idx, SeekFlag_None)) { - line = Skip(line, idx + delim.len); + if (Seek(string_line, delim, &idx, SeekFlag_None)) { + string_line = Skip(string_line, idx + delim.len); } } view_goto->carets[0] = MakeCaret(line_range.min); window->goto_list_pos = line_range.min; - line = Trim(line); + string_line = Trim(string_line); MergeCarets(buffer_goto, &view_goto->carets); IF_DEBUG(AssertRanges(view_goto->carets)); - if (line.len == 0) { + if (string_line.len == 0) { continue; } - Buffer *active_view_buffer = GetBuffer(active_view->active_buffer); Range before_jump_range = active_view->carets[0].range; - BSet set = Open(line, ResolveOpenMeta_DontError | ResolveOpenMeta_DontExec); + BSet set = Open(string_line, ResolveOpenMeta_DontError | ResolveOpenMeta_DontExec); if (set.window == NULL) { continue; } @@ -402,12 +401,12 @@ BSet GetBSet(WindowID window_id) { return result; } -String GetPrimaryDirectory() { - BSet main = GetBSet(PrimaryWindowID); - return GetDirectory(main.buffer); +String GetDirectory(Window *window) { + BSet set = GetBSet(window->id); + return GetDirectory(set.buffer); } -String GetDirectory(Window *window) { +String GetPrimaryDirectory() { BSet main = GetBSet(PrimaryWindowID); return GetDirectory(main.buffer); }