From afd4e1d21c1343317953c459aa99d168b2afa2c0 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 16 Aug 2024 07:23:50 +0200 Subject: [PATCH] Misc --- build_file.cpp | 4 +++- src/basic/basic.h | 14 ++------------ src/basic/string16.cpp | 4 ++-- src/profiler/profiler.cpp | 2 +- src/text_editor/buffer.cpp | 20 ++++++++++++++++++++ src/text_editor/management.cpp | 7 ++++--- src/text_editor/notes_vcvarsall | 10 ++++++++++ src/text_editor/text_editor.cpp | 2 +- src/text_editor/text_editor.h | 1 + 9 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 src/text_editor/notes_vcvarsall diff --git a/build_file.cpp b/build_file.cpp index 58a69d4..42aaa86 100644 --- a/build_file.cpp +++ b/build_file.cpp @@ -130,7 +130,9 @@ int CompileTextEditor() { int result = 0; Array libs = {}; - libs.add(PrepareSDLDynamic()); + // if (Profile == PROFILE_DEBUG) libs.add(PrepareSDLDynamic()); + // else + libs.add(PrepareSDL()); libs.add(PrepareLua()); libs.add(PrepareGlad()); diff --git a/src/basic/basic.h b/src/basic/basic.h index 1485e73..56cea9c 100644 --- a/src/basic/basic.h +++ b/src/basic/basic.h @@ -796,23 +796,13 @@ int64_t CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *i inline bool operator==(String a, String b) { return AreEqual(a, b); } inline bool operator!=(String a, String b) { return !AreEqual(a, b); } -#if defined(__has_attribute) && defined(_MSC_VER) && !defined(__clang__) - #if __has_attribute(format) - #define PrintfFormatAttribute(fmt, va) __attribute__((format(printf, fmt, va))) - #endif -#endif - -#ifndef PrintfFormatAttribute - #define PrintfFormatAttribute(fmt, va) -#endif - #define STRING_FORMAT(allocator, data, result) \ va_list args1; \ va_start(args1, data); \ String result = FormatV(allocator, data, args1); \ va_end(args1) -String Format(Allocator allocator, const char *data, ...) PrintfFormatAttribute(2, 3); +String Format(Allocator allocator, const char *data, ...); String FormatV(Allocator allocator, const char *data, va_list args1); String ToString(Allocator allocator, String16 string); String ToString(Allocator allocator, wchar_t *string, int64_t len); @@ -1569,7 +1559,7 @@ String FormatV(Allocator allocator, const char *data, va_list args1) { return res; } -String Format(Allocator allocator, const char *data, ...) PrintfFormatAttribute(2, 3) { +String Format(Allocator allocator, const char *data, ...) { STRING_FORMAT(allocator, data, result); return result; } diff --git a/src/basic/string16.cpp b/src/basic/string16.cpp index 51af109..72cd22c 100644 --- a/src/basic/string16.cpp +++ b/src/basic/string16.cpp @@ -237,7 +237,7 @@ bool StartsWith(String16 a, String16 start, unsigned ignore_case = false) { return result; } -String16 Copy(Allocator allocator, String16 string) { +String16 Copy16(Allocator allocator, String16 string) { wchar_t *copy = (wchar_t *)AllocSize(allocator, sizeof(wchar_t) * (string.len + 1)); memcpy(copy, string.data, string.len); copy[string.len] = 0; @@ -245,7 +245,7 @@ String16 Copy(Allocator allocator, String16 string) { return result; } -String16 Copy(Allocator allocator, wchar_t *string) { +String16 Copy16(Allocator allocator, wchar_t *string) { String16 s = {string, (int64_t)WideLength(string)}; return Copy(allocator, s); } diff --git a/src/profiler/profiler.cpp b/src/profiler/profiler.cpp index 797dbb6..1417396 100644 --- a/src/profiler/profiler.cpp +++ b/src/profiler/profiler.cpp @@ -1,4 +1,4 @@ -#if 1 +#if DEBUG_BUILD #include "spall.h" static SpallProfile spall_ctx; diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 754dfe4..21e0552 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -28,6 +28,7 @@ void OffsetAllLinesForward(Buffer *buffer, Int line, Int *_offset) { } void UpdateLines(Buffer *buffer, Range range, String16 string) { + if (buffer->no_line_starts) return; ProfileFunction(); Array &ls = buffer->line_starts; Int min_line_number = PosToLine(buffer, range.min); @@ -125,3 +126,22 @@ void IKnowWhatImDoing_Appendf(Buffer *buffer, const char *fmt, ...) { String16 string16 = ToString16(scratch, string); IKnowWhatImDoing_ReplaceText(buffer, GetEndAsRange(buffer), string16); } + +void IKnowWhatImDoing_Append(Buffer *buffer, Int num) { + IKnowWhatImDoing_Appendf(buffer, "%d", num); +} + +// Buffer &operator<<(Buffer &buffer, Int num) { +// IKnowWhatImDoing_Appendf(&buffer, "%lld", (long long)num); +// return buffer; +// } + +// Buffer &operator<<(Buffer &buffer, double num) { +// IKnowWhatImDoing_Appendf(&buffer, "%f", num); +// return buffer; +// } + +// Buffer &operator<<(Buffer &buffer, String16 string) { +// IKnowWhatImDoing_Append(&buffer, string); +// return buffer; +// } diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index 107adec..4ecfd3d 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -101,7 +101,7 @@ void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 409 buffer->line_starts.allocator = allocator; buffer->undo_stack.allocator = allocator; buffer->redo_stack.allocator = allocator; - Add(&buffer->line_starts, (Int)0); + if (!buffer->no_line_starts) Add(&buffer->line_starts, (Int)0); } Buffer *CreateBuffer(Allocator allocator, String name, Int size) { @@ -112,8 +112,9 @@ Buffer *CreateBuffer(Allocator allocator, String name, Int size) { } Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) { - Buffer *result = AllocType(allocator, Buffer); - result->no_history = true; + Buffer *result = AllocType(allocator, Buffer); + result->no_history = true; + result->no_line_starts = true; InitBuffer(allocator, result, "*temp*", size); return result; } diff --git a/src/text_editor/notes_vcvarsall b/src/text_editor/notes_vcvarsall new file mode 100644 index 0000000..5370885 --- /dev/null +++ b/src/text_editor/notes_vcvarsall @@ -0,0 +1,10 @@ +-- this is going to output all the enviroment variables into the bar after it executes vcvarsall. +-- Sentinel is for separating errors from data +local id = C '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 && echo SOME_SENTINEL_VALUE && set' +local buffer_id = GetBufferID(id) +while ProcessIsRunning(id) do coroutine.yield() end + +local string = GetBufferString(buffer_id) +local lines = SplitIntoLines(string) +Skip past sentinel value +Parse the enviroment and then pass that value into new processes \ No newline at end of file diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 064e4b0..732be37 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -226,9 +226,9 @@ int main(int argc, char **argv) char **argv = __argv; #endif BeginProfiler(); - InitScratch(); InitArena(&Perm); + WorkingDir = GetWorkingDir(Perm); ExeDir = GetExeDir(Perm); { diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index a68d206..f0c7243 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -41,6 +41,7 @@ struct Buffer { int edit_phase; struct { int no_history : 1; + int no_line_starts : 1; int dirty : 1; int is_directory : 1; int gc : 1;