Format string refactor
This commit is contained in:
@@ -363,7 +363,7 @@ function OnOpen(path, meta)
|
||||
end
|
||||
|
||||
Coroutines = {}
|
||||
function AddCo(f)
|
||||
function CoAdd(f)
|
||||
local i = #Coroutines + 1
|
||||
Coroutines[i] = coroutine.create(f)
|
||||
coroutine.resume(Coroutines[i])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Style.WaitForEvents = 0
|
||||
|
||||
-- AddCo(function()
|
||||
-- CoAdd(function()
|
||||
-- Play{
|
||||
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
|
||||
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
|
||||
|
||||
@@ -14,7 +14,6 @@ Needs to change:
|
||||
- How to design popup view (input field)?
|
||||
- How to design search view? or search and replace view?
|
||||
- Window management, splitting, GC
|
||||
- add modified stb_sprintf
|
||||
|
||||
Things I like:
|
||||
- Basic editing
|
||||
@@ -58,3 +58,5 @@ union Color {
|
||||
};
|
||||
uint32_t value;
|
||||
};
|
||||
|
||||
#define PI32 3.14159265359f
|
||||
|
||||
@@ -482,7 +482,7 @@ API void Advance(FileIter *it) {
|
||||
it->filename = ToString(it->allocator, (char16_t *)data->cFileName, WideLength((char16_t *)data->cFileName));
|
||||
const char *is_dir = it->is_directory ? "/" : "";
|
||||
const char *separator = it->path.data[it->path.len - 1] == '/' ? "" : "/";
|
||||
it->relative_path = Format(it->allocator, "%.*s%s%.*s%s", FmtString(it->path), separator, FmtString(it->filename), is_dir);
|
||||
it->relative_path = Format(it->allocator, "%S%s%S%s", it->path, separator, it->filename, is_dir);
|
||||
it->absolute_path = GetAbsolutePath(it->allocator, it->relative_path);
|
||||
it->is_valid = true;
|
||||
|
||||
@@ -504,7 +504,7 @@ API FileIter IterateFiles(Allocator alo, String path) {
|
||||
it.allocator = alo;
|
||||
it.path = path;
|
||||
|
||||
String modified_path = Format(it.allocator, "%.*s\\*", FmtString(path));
|
||||
String modified_path = Format(it.allocator, "%S\\*", path);
|
||||
String16 modified_path16 = ToString16(it.allocator, modified_path);
|
||||
|
||||
it.w32 = AllocType(it.allocator, Win32_FileIter);
|
||||
@@ -672,7 +672,7 @@ static void Win32ReportError(String msg, String cmd) {
|
||||
char *buff = (char *)lpMsgBuf;
|
||||
size_t buffLen = strlen((const char *)buff);
|
||||
if (buffLen > 0 && buff[buffLen - 1] == '\n') buff[buffLen - 1] = 0;
|
||||
Error("%.*s: %.*s! %s", FmtString(msg), FmtString(cmd), (char *)lpMsgBuf);
|
||||
Error("%S: %S! %s", msg, cmd, (char *)lpMsgBuf);
|
||||
}
|
||||
|
||||
static void Win32CloseProcess(Process *process) {
|
||||
@@ -715,7 +715,7 @@ API Process SpawnProcess(String command_line, String working_dir, String write_s
|
||||
Win32Process *p = (Win32Process *)process.platform;
|
||||
|
||||
Scratch scratch;
|
||||
command_line = Format(scratch, "/C %.*s", FmtString(command_line));
|
||||
command_line = Format(scratch, "/C %S", command_line);
|
||||
|
||||
p->handle = INVALID_HANDLE_VALUE;
|
||||
p->child_stdout_write = INVALID_HANDLE_VALUE;
|
||||
@@ -759,6 +759,7 @@ API Process SpawnProcess(String command_line, String working_dir, String write_s
|
||||
String16 cmd = ToString16(scratch, command_line);
|
||||
|
||||
char *env = NULL;
|
||||
// TODO: FIX ARENA ALLOCATION USING PushSize, Prealloc maybe? Maybe we want a block arena
|
||||
if (enviroment.len) {
|
||||
Int size = GetSize(enviroment) + enviroment.len + 1;
|
||||
env = (char *)PushSize(scratch, size);
|
||||
|
||||
@@ -83,7 +83,6 @@ API String Copy(Allocator allocator, char *string);
|
||||
API void NormalizePathInPlace(String s);
|
||||
API String NormalizePath(Allocator allocator, String s);
|
||||
|
||||
#define FmtString(string) (int)(string).len, (string).data
|
||||
API String FormatV(Allocator allocator, const char *data, va_list args1);
|
||||
API String Format(Allocator allocator, const char *data, ...);
|
||||
#define STRING_FORMAT(allocator, data, result) \
|
||||
|
||||
@@ -574,11 +574,6 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
|
||||
char num[STBSP__NUMSZ];
|
||||
char lead[8];
|
||||
char tail[8];
|
||||
struct stb__string {
|
||||
char *data;
|
||||
int64_t len;
|
||||
} S;
|
||||
|
||||
char *s;
|
||||
char const *h;
|
||||
stbsp__uint32 l, n, cs;
|
||||
@@ -588,6 +583,11 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
|
||||
#endif
|
||||
stbsp__int32 dp;
|
||||
char const *sn;
|
||||
struct stb__string {
|
||||
char *data;
|
||||
int64_t len;
|
||||
};
|
||||
struct stb__string S;
|
||||
|
||||
case 'S':
|
||||
// get the string
|
||||
@@ -596,7 +596,8 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
|
||||
S.data = (char *)"null";
|
||||
S.len = 4;
|
||||
}
|
||||
l = (unsigned int)S.len;
|
||||
s = S.data;
|
||||
l = stbsp__strlen_limited(S.data, ((int)S.len >= 0) ? (int)S.len : ~0u);
|
||||
lead[0] = 0;
|
||||
tail[0] = 0;
|
||||
pr = 0;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "basic/basic.h"
|
||||
#include "basic/basic.cpp"
|
||||
|
||||
int main() {
|
||||
InitScratch();
|
||||
void Test() {
|
||||
// Basic constructors
|
||||
{
|
||||
String a = "thing";
|
||||
@@ -36,26 +35,18 @@ int main() {
|
||||
Vec2 b = 2 + a;
|
||||
}
|
||||
|
||||
|
||||
printf("hello world\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
InitScratch();
|
||||
|
||||
// #define BASIC_IMPL
|
||||
// #include "basic/basic.h"
|
||||
// #include "basic/filesystem.h"
|
||||
Scratch scratch;
|
||||
String data = ReadFile(scratch, "../data/init.lua");
|
||||
Array<String> array = {scratch};
|
||||
|
||||
// int main() {
|
||||
// InitScratch();
|
||||
|
||||
// Scratch scratch;
|
||||
// String data = ReadFile(scratch, "../data/init.lua");
|
||||
// Array<String> array = {scratch};
|
||||
|
||||
// Add(&array, String{"String BaseLuaConfig = R\"==(\n"});
|
||||
// Add(&array, data);
|
||||
// Add(&array, String{"\n)==\";\n"});
|
||||
// String result = Merge(scratch, array, "");
|
||||
// WriteFile("../src/text_editor/generated_config.cpp", result);
|
||||
|
||||
// }
|
||||
Add(&array, String{"String BaseLuaConfig = R\"==(\n"});
|
||||
Add(&array, data);
|
||||
Add(&array, String{"\n)==\";\n"});
|
||||
String result = Merge(scratch, array, "");
|
||||
WriteFile("../src/text_editor/generated_config.cpp", result);
|
||||
}
|
||||
@@ -296,36 +296,12 @@ void PushVertex2D(Allocator allocator, VertexList2D *list, Vertex2D *vertices, i
|
||||
|
||||
void PushQuad2D(Allocator arena, VertexList2D *list, Rect2 rect, Rect2 tex, Color color, float rotation = 0.f, Vec2 rotation_point = {}) {
|
||||
Vertex2D *v = AllocVertex2D(arena, list, 6);
|
||||
v[0] = {
|
||||
{rect.min.x, rect.max.y},
|
||||
{ tex.min.x, tex.max.y},
|
||||
color
|
||||
};
|
||||
v[1] = {
|
||||
{rect.max.x, rect.max.y},
|
||||
{ tex.max.x, tex.max.y},
|
||||
color
|
||||
};
|
||||
v[2] = {
|
||||
{rect.min.x, rect.min.y},
|
||||
{ tex.min.x, tex.min.y},
|
||||
color
|
||||
};
|
||||
v[3] = {
|
||||
{rect.min.x, rect.min.y},
|
||||
{ tex.min.x, tex.min.y},
|
||||
color
|
||||
};
|
||||
v[4] = {
|
||||
{rect.max.x, rect.max.y},
|
||||
{ tex.max.x, tex.max.y},
|
||||
color
|
||||
};
|
||||
v[5] = {
|
||||
{rect.max.x, rect.min.y},
|
||||
{ tex.max.x, tex.min.y},
|
||||
color
|
||||
};
|
||||
v[0] = { {rect.min.x, rect.max.y}, { tex.min.x, tex.max.y}, color };
|
||||
v[1] = { {rect.max.x, rect.max.y}, { tex.max.x, tex.max.y}, color };
|
||||
v[2] = { {rect.min.x, rect.min.y}, { tex.min.x, tex.min.y}, color };
|
||||
v[3] = { {rect.min.x, rect.min.y}, { tex.min.x, tex.min.y}, color };
|
||||
v[4] = { {rect.max.x, rect.max.y}, { tex.max.x, tex.max.y}, color };
|
||||
v[5] = { {rect.max.x, rect.min.y}, { tex.max.x, tex.min.y}, color };
|
||||
if (rotation != 0.f) {
|
||||
float s = sinf(rotation);
|
||||
float c = cosf(rotation);
|
||||
@@ -385,7 +361,6 @@ Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw =
|
||||
return result;
|
||||
}
|
||||
|
||||
#define PI32 3.14159265359f
|
||||
void DrawCircle(Vec2 pos, float radius, Color color) {
|
||||
const int segment_count = 16;
|
||||
const int vertex_count = segment_count * 3;
|
||||
|
||||
@@ -26,7 +26,7 @@ void Wait(mco_coro *co) {
|
||||
|
||||
void PlayTestOpen(mco_coro *co) {
|
||||
// Open file, move a little, then open again and verify the caret didn't move
|
||||
String basic_env_cpp = Format(SysAllocator, "%.*s/basic_env/basic_env.cpp", FmtString(TestDir));
|
||||
String basic_env_cpp = Format(SysAllocator, "%S/basic_env/basic_env.cpp", TestDir);
|
||||
|
||||
AddCtrlPress(SDLK_P);
|
||||
Add(&EventPlayback, {EVENT_KEY_PRESS, SDLK_UP, 1280, 720});
|
||||
@@ -69,7 +69,7 @@ void PlayTestOpen(mco_coro *co) {
|
||||
buffer_len = main.buffer->len;
|
||||
}
|
||||
|
||||
AddText(Format(SysAllocator, "%.*s:20", FmtString(basic_env_cpp)));
|
||||
AddText(Format(SysAllocator, "%S:20", basic_env_cpp));
|
||||
AddCtrlPress(SDLK_Q);
|
||||
Wait(co);
|
||||
|
||||
@@ -98,7 +98,7 @@ void PlayTestOpen(mco_coro *co) {
|
||||
}
|
||||
|
||||
void Test(mco_coro *co) {
|
||||
WorkDir = Format(SysAllocator, "%.*s/basic_env", FmtString(TestDir));
|
||||
WorkDir = Format(SysAllocator, "%S/basic_env", TestDir);
|
||||
PlayTestOpen(co);
|
||||
|
||||
|
||||
@@ -114,5 +114,5 @@ void InitTests() {
|
||||
file = ChopLastSlash(file);
|
||||
TestDir = file;
|
||||
}
|
||||
AddCo(Test);
|
||||
CoAdd(Test);
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ void ReportErrorf(const char *fmt, ...) {
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
|
||||
View *view = GetView(NullViewID);
|
||||
Command_Appendf(view, "%.*s\n", FmtString(string));
|
||||
Command_Appendf(view, "%S\n", string);
|
||||
ActiveWindow = NullWindowID;
|
||||
}
|
||||
|
||||
@@ -212,21 +212,21 @@ void ReportConsolef(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
View *view = GetView(NullViewID);
|
||||
Command_Appendf(view, "%.*s\n", FmtString(string));
|
||||
Command_Appendf(view, "%S\n", string);
|
||||
}
|
||||
|
||||
void ReportWarningf(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
View *null_view = GetView(NullViewID);
|
||||
Command_Appendf(null_view, "%.*s\n", FmtString(string));
|
||||
Command_Appendf(null_view, "%S\n", string);
|
||||
ActiveWindow = NullWindowID;
|
||||
}
|
||||
|
||||
void ReportDebugf(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
Command_Appendf(TraceView, "%.*s\n", FmtString(string));
|
||||
Command_Appendf(TraceView, "%S\n", string);
|
||||
}
|
||||
|
||||
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
||||
@@ -681,7 +681,7 @@ void SaveBuffer(Buffer *buffer) {
|
||||
buffer->dirty = false;
|
||||
buffer->garbage = false;
|
||||
} else {
|
||||
ReportWarningf("Failed to save file with name: %.*s", FmtString(buffer->name));
|
||||
ReportWarningf("Failed to save file with name: %S", buffer->name);
|
||||
}
|
||||
}
|
||||
void Command_Save() {
|
||||
@@ -987,7 +987,7 @@ void New(Window *window, String name = "") {
|
||||
String dir = GetDir(buffer);
|
||||
if (name != "") {
|
||||
if (!IsAbsolute(name)) {
|
||||
name = Format(scratch, "%.*s/%.*s", FmtString(dir), FmtString(name));
|
||||
name = Format(scratch, "%S/%S", dir, name);
|
||||
}
|
||||
name = GetAbsolutePath(scratch, name);
|
||||
} else {
|
||||
@@ -1016,7 +1016,7 @@ void NewDir(Window *window, String name = "") {
|
||||
String dir = GetDir(buffer);
|
||||
if (name != "") {
|
||||
if (!IsAbsolute(name)) {
|
||||
name = Format(scratch, "%.*s/%.*s", FmtString(dir), FmtString(name));
|
||||
name = Format(scratch, "%S/%S", dir, name);
|
||||
}
|
||||
name = GetAbsolutePath(scratch, name);
|
||||
} else {
|
||||
@@ -1070,7 +1070,7 @@ void ListFilesRecursive(Buffer *buffer, String dir) {
|
||||
if (!good) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(buffer, "%-80.*s || %.*s\n", FmtString(it.filename), FmtString(it.absolute_path));
|
||||
RawAppendf(buffer, "%-80S || %S\n", it.filename, it.absolute_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1126,9 +1126,9 @@ BSet Command_Open(Window *window, String path, String meta, bool set_active = tr
|
||||
}
|
||||
if (IsDir(ores.file_path)) {
|
||||
JumpGarbageBuffer(&set, GetUniqueBufferName(ores.file_path, "temp", ".dirlisting"));
|
||||
Command_Appendf(set.view, "..\n", FmtString(ores.file_path));
|
||||
Command_Appendf(set.view, "..\n");
|
||||
for (FileIter it = IterateFiles(scratch, ores.file_path); IsValid(it); Advance(&it)) {
|
||||
Command_Appendf(set.view, "%.*s\n", FmtString(it.filename));
|
||||
Command_Appendf(set.view, "%S\n", it.filename);
|
||||
}
|
||||
} else {
|
||||
CheckpointBeforeGoto(set.window);
|
||||
@@ -1230,7 +1230,7 @@ void Command_ListBuffers() {
|
||||
ActiveWindow = main.window->id;
|
||||
JumpGarbageBuffer(&main);
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
RawAppendf(main.buffer, "%-80.*s || %.*s\n", FmtString(SkipToLastSlash(it->name)), FmtString(it->name));
|
||||
RawAppendf(main.buffer, "%-80S || %S\n", SkipToLastSlash(it->name), it->name);
|
||||
}
|
||||
main.view->fuzzy_search = true;
|
||||
main.view->update_scroll = true;
|
||||
@@ -1248,7 +1248,7 @@ void Command_ListViews() {
|
||||
JumpGarbageBuffer(&main);
|
||||
for (View *it = FirstView; it; it = it->next) {
|
||||
Buffer *buffer = GetBuffer(it->active_buffer);
|
||||
Command_Appendf(main.view, "%d %.*s\n", (int)it->id.id, FmtString(buffer->name));
|
||||
Command_Appendf(main.view, "%d %S\n", (int)it->id.id, buffer->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
typedef void CoroutineProc(mco_coro *co);
|
||||
Array<mco_coro *> ActiveCoroutines;
|
||||
|
||||
mco_coro *AddCo(CoroutineProc *proc) {
|
||||
mco_coro *CoAdd(CoroutineProc *proc) {
|
||||
mco_desc desc = mco_desc_init(proc, 0);
|
||||
|
||||
mco_coro *coro = NULL;
|
||||
@@ -16,7 +16,7 @@ mco_coro *AddCo(CoroutineProc *proc) {
|
||||
return coro;
|
||||
}
|
||||
|
||||
void UpdateCo(Event *event) {
|
||||
void CoUpdate(Event *event) {
|
||||
IterRemove(ActiveCoroutines) {
|
||||
IterRemovePrepare(ActiveCoroutines);
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ function OnOpen(path, meta)
|
||||
end
|
||||
|
||||
Coroutines = {}
|
||||
function AddCo(f)
|
||||
function CoAdd(f)
|
||||
local i = #Coroutines + 1
|
||||
Coroutines[i] = coroutine.create(f)
|
||||
coroutine.resume(Coroutines[i])
|
||||
|
||||
@@ -4,7 +4,7 @@ int Lua_print(lua_State *L) {
|
||||
View *null_view = GetView(NullViewID);
|
||||
for (int i = 1; i <= nargs; i += 1) {
|
||||
String string = lua_tostring(L, i);
|
||||
Command_Appendf(null_view, "%.*s ", FmtString(string));
|
||||
Command_Appendf(null_view, "%S ", string);
|
||||
}
|
||||
Command_Appendf(null_view, "\n");
|
||||
lua_pop(L, nargs);
|
||||
@@ -16,7 +16,7 @@ int Lua_Print(lua_State *L) {
|
||||
int nargs = lua_gettop(L);
|
||||
for (int i = 1; i <= nargs; i += 1) {
|
||||
String string = lua_tostring(L, i);
|
||||
Command_Appendf(TraceView, "%.*s ", FmtString(string));
|
||||
Command_Appendf(TraceView, "%S ", string);
|
||||
}
|
||||
Command_Appendf(TraceView, "\n");
|
||||
lua_pop(L, nargs);
|
||||
@@ -263,7 +263,7 @@ extern String BaseLuaConfig;
|
||||
|
||||
void LoadLuaBuffer(Buffer *lua_buffer) {
|
||||
if (!lua_buffer) return;
|
||||
ReportConsolef("reloading config: %.*s", FmtString(lua_buffer->name));
|
||||
ReportConsolef("reloading config: %S", lua_buffer->name);
|
||||
|
||||
Scratch scratch;
|
||||
String string = AllocCharString(scratch, lua_buffer);
|
||||
@@ -345,7 +345,7 @@ OnOpenResult CallOnOpen(Allocator allocator, String path, String meta) {
|
||||
result.file_path = file_path;
|
||||
if (!IsAbsolute(result.file_path)) {
|
||||
String dir = Command_GetMainDir();
|
||||
result.file_path = Format(allocator, "%.*s/%.*s", FmtString(dir), FmtString(result.file_path));
|
||||
result.file_path = Format(allocator, "%S/%S", dir, result.file_path);
|
||||
}
|
||||
if (col_string.len) {
|
||||
result.col = strtoll(col_string.data, NULL, 10);
|
||||
@@ -431,13 +431,13 @@ void InitLuaConfig() {
|
||||
Buffer *lua_buffer = NULL;
|
||||
|
||||
Scratch scratch;
|
||||
String lua_config_exe = Format(scratch, "%.*s/init.lua", FmtString(GetExeDir(scratch)));
|
||||
String lua_config_exe = Format(scratch, "%S/init.lua", GetExeDir(scratch));
|
||||
if (FileExists(lua_config_exe)) {
|
||||
lua_buffer = BufferOpenFile(lua_config_exe);
|
||||
}
|
||||
|
||||
if (lua_buffer == NULL) {
|
||||
String lua_config_remote = Format(scratch, "%.*s/init.lua", FmtString(ConfigDir));
|
||||
String lua_config_remote = Format(scratch, "%S/init.lua", ConfigDir);
|
||||
// #if DEBUG_BUILD
|
||||
// // WARNING! Delete config to make sure we are running this code more frequently
|
||||
// SDL_RemovePath(lua_config_remote.data);
|
||||
@@ -447,7 +447,7 @@ void InitLuaConfig() {
|
||||
if (lua_buffer->len == 0) {
|
||||
String16 string16 = ToString16(scratch, BaseLuaConfig);
|
||||
RawReplaceText(lua_buffer, {}, string16);
|
||||
ReportConsolef("no config at: %.*s - creating config buffer", FmtString(lua_config_remote));
|
||||
ReportConsolef("no config at: %S - creating config buffer", lua_config_remote);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ String GetUniqueBufferName(String working_dir, String prepend_name, String exten
|
||||
Scratch scratch;
|
||||
String buffer_name = {};
|
||||
for (int i = 1; i < INT_MAX; i += 1) {
|
||||
buffer_name = Format(scratch, "%.*s/%.*s%d%.*s", FmtString(working_dir), FmtString(prepend_name), i, FmtString(extension));
|
||||
buffer_name = Format(scratch, "%S/%S%d%S", working_dir, prepend_name, i, extension);
|
||||
buffer_name = GetAbsolutePath(scratch, buffer_name);
|
||||
Buffer *exists = FindBuffer(buffer_name);
|
||||
if (!exists && !FileExists(buffer_name)) {
|
||||
@@ -428,7 +428,7 @@ Buffer *BufferOpenFile(String path) {
|
||||
if (!FileExists(path)) {
|
||||
buffer = CreateBuffer(sys_allocator, path);
|
||||
} else if (IsDir(path)) {
|
||||
ReportWarningf("failed to open, it's a directory: %.*s", FmtString(path));
|
||||
ReportWarningf("failed to open, it's a directory: %S", path);
|
||||
return GetBuffer(NullBufferID);
|
||||
} else {
|
||||
String string = ReadFile(scratch, path);
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
Array<Process> ActiveProcesses = {};
|
||||
// @todo: I think I need to push strings onto the arena with alignment zero
|
||||
// they should be of format a\0b\0c\0\0. Then it will probably work. It doesn'
|
||||
// make a good api so it will have to be done in 2 steps. Platform dependent one
|
||||
// and platform independent one
|
||||
Array<String> Enviroment = {};
|
||||
|
||||
// WARNING: seems that this maybe can't work reliably?
|
||||
@@ -30,7 +26,7 @@ void UpdateProcesses() {
|
||||
|
||||
void Exec(ViewID view, bool scroll_to_end, String cmd, String working_dir) {
|
||||
Process process = SpawnProcess(cmd, working_dir, {}, Enviroment);
|
||||
ReportDebugf("process %lld start. is_valid = %d cmd = %.*s working_dir = %.*s", process.id, process.is_valid, FmtString(cmd), FmtString(working_dir));
|
||||
ReportDebugf("process %lld start. is_valid = %d cmd = %S working_dir = %S", process.id, process.is_valid, cmd, working_dir);
|
||||
process.view_id = view.id;
|
||||
process.scroll_to_end = scroll_to_end;
|
||||
if (process.is_valid) Add(&ActiveProcesses, process);
|
||||
@@ -43,7 +39,7 @@ void Exec(ViewID view, bool scroll_to_end, String16 cmd16, String working_dir) {
|
||||
}
|
||||
|
||||
Buffer *ExecAndWait(Allocator allocator, String cmd, String working_dir, String stdin_string = {}) {
|
||||
ReportDebugf("ExecAndWait cmd = %.*s working_dir = %.*s stdin_string = %.*s", FmtString(cmd), FmtString(working_dir), FmtString(stdin_string));
|
||||
ReportDebugf("ExecAndWait cmd = %S working_dir = %S stdin_string = %S", cmd, working_dir, stdin_string);
|
||||
|
||||
Buffer *temp_buffer = CreateTempBuffer(allocator, 4096 * 4);
|
||||
for (Process process = SpawnProcess(cmd, working_dir, stdin_string, Enviroment); IsValid(&process);) {
|
||||
|
||||
@@ -3,7 +3,7 @@ struct Serializer {
|
||||
};
|
||||
|
||||
void Serialize(Serializer *s, String name, Int *datum) {
|
||||
RawAppendf(s->buffer, "%.*s = %lld, ", FmtString(name), (long long)*datum);
|
||||
RawAppendf(s->buffer, "%S = %lld, ", name, (long long)*datum);
|
||||
}
|
||||
|
||||
void Serialize(Serializer *s, String name, uint32_t *datum) {
|
||||
@@ -25,12 +25,12 @@ void Serialize(Serializer *s, String name, int16_t *datum) {
|
||||
}
|
||||
|
||||
void Serialize(Serializer *s, String name, float *datum) {
|
||||
RawAppendf(s->buffer, "%.*s = %f, ", FmtString(name), *datum);
|
||||
RawAppendf(s->buffer, "%S = %f, ", name, *datum);
|
||||
}
|
||||
|
||||
void Serialize(Serializer *s, String name, char **text) {
|
||||
String str = *text;
|
||||
RawAppendf(s->buffer, "%.*s = \"%.*s\", ", FmtString(name), FmtString(str));
|
||||
RawAppendf(s->buffer, "%S = \"%S\", ", name, str);
|
||||
}
|
||||
|
||||
void SerializeBegin(Serializer *s) {
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "external/minicoro.h"
|
||||
#define LUA_USE_LONGJMP
|
||||
#include "external/luaunity.c"
|
||||
#include "render/generated_font.cpp"
|
||||
|
||||
SDL_Window *SDLWindow;
|
||||
bool IsInFullscreen;
|
||||
@@ -19,6 +18,7 @@ int FullScreenSizeX, FullScreenSizeY;
|
||||
int FullScreenPositionX, FullScreenPositionY;
|
||||
|
||||
#include "generated_variables.cpp"
|
||||
#include "render/generated_font.cpp"
|
||||
#include "render/font.cpp"
|
||||
#include "render/opengl.cpp"
|
||||
|
||||
@@ -250,7 +250,7 @@ void Update(Event event) {
|
||||
if (it->is_title_bar) ReplaceTitleBarData(it);
|
||||
}
|
||||
UpdateProcesses();
|
||||
UpdateCo(&event);
|
||||
CoUpdate(&event);
|
||||
ReloadLuaConfigs();
|
||||
CallLuaOnUpdate(&event);
|
||||
UpdateDebugBuffer();
|
||||
@@ -300,7 +300,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
|
||||
Scratch scratch;
|
||||
String working_dir = WorkDir;
|
||||
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
|
||||
String cmd = Format(scratch, "\"%.*s\" && set", FmtString(StyleVCVarsall));
|
||||
String cmd = Format(scratch, "\"%S\" && set", StyleVCVarsall);
|
||||
view = Command_ExecHidden(buffer_name, cmd, working_dir);
|
||||
}
|
||||
for (;;) {
|
||||
@@ -357,7 +357,7 @@ void MainLoop() {
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
const char *dirty = buffer->dirty ? " !" : "";
|
||||
String string = Format(scratch, "%.*s%s", FmtString(buffer->name), dirty);
|
||||
String string = Format(scratch, "%S%s", buffer->name, dirty);
|
||||
SDL_SetWindowTitle(SDLWindow, string.data);
|
||||
}
|
||||
|
||||
@@ -498,11 +498,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
ReportConsolef("WorkDir = %.*s", FmtString(WorkDir));
|
||||
ReportConsolef("WorkDir = %S", WorkDir);
|
||||
InitLuaConfig();
|
||||
if (testing) InitTests();
|
||||
#if OS_WINDOWS
|
||||
AddCo(Windows_SetupVCVarsall);
|
||||
CoAdd(Windows_SetupVCVarsall);
|
||||
#endif
|
||||
#if OS_WASM
|
||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||
|
||||
@@ -19,7 +19,7 @@ void UpdateDebugBuffer() {
|
||||
RawAppendf(buffer, "BufferID id = %d\n", main.buffer->id.id);
|
||||
RawAppendf(buffer, "Buffer *next = %zu\n", main.buffer->next);
|
||||
RawAppendf(buffer, "Buffer *prev = %zu\n", main.buffer->prev);
|
||||
RawAppendf(buffer, "String name = %.*s\n", FmtString(main.buffer->name));
|
||||
RawAppendf(buffer, "String name = %S\n", main.buffer->name);
|
||||
RawAppendf(buffer, "Int change_id = %lld\n", (long long)main.buffer->change_id);
|
||||
RawAppendf(buffer, "Int user_change_id = %lld\n", (long long)main.buffer->user_change_id);
|
||||
RawAppendf(buffer, "Int file_mod_time = %lld\n", (long long)main.buffer->file_mod_time);
|
||||
@@ -75,7 +75,7 @@ void ReplaceTitleBarData(Window *window) {
|
||||
name = GetAbsolutePath(scratch, name);
|
||||
if (FindBuffer(name)) {
|
||||
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
||||
ReportConsolef("there is already buffer with name: %.*s", FmtString(name));
|
||||
ReportConsolef("there is already buffer with name: %S", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -115,10 +115,10 @@ void ReplaceTitleBarData(Window *window) {
|
||||
|
||||
// replace data up to separator with filename and stuff
|
||||
const char *reopen = main.buffer->changed_on_disk ? " Reopen()" : "";
|
||||
String s = Format(scratch, "%.*s:%lld:%lld%s", FmtString(main.buffer->name), (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen);
|
||||
String s = Format(scratch, "%S:%lld:%lld%s", main.buffer->name, (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen);
|
||||
For (ActiveProcesses) {
|
||||
if (it.view_id == main.view->id.id) {
|
||||
s = Format(scratch, "%.*s %lld", FmtString(s), (long long)it.id);
|
||||
s = Format(scratch, "%S %lld", s, (long long)it.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Window *CreateSearchBar(WindowID parent_window_id) {
|
||||
|
||||
static int BarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%.*s/searchbar%d", FmtString(WorkDir), ++BarCount);
|
||||
String name = Format(sys_allocator, "%S/searchbar%d", WorkDir, ++BarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
@@ -37,7 +37,7 @@ Window *CreateTitlebar(WindowID parent_window_id) {
|
||||
|
||||
static int TitlebarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%.*s/titlebar%d", FmtString(WorkDir), ++TitlebarCount);
|
||||
String name = Format(sys_allocator, "%S/titlebar%d", WorkDir, ++TitlebarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
|
||||
Reference in New Issue
Block a user