diff --git a/Code/Dqn.h b/Code/Dqn.h index d9414ea..98cdd51 100644 --- a/Code/Dqn.h +++ b/Code/Dqn.h @@ -596,8 +596,9 @@ struct Dqn_StringBuilder isize string_len; }; -template -FILE_SCOPE char *Dqn_StringBuilder__GetWriteBufferAndUpdateUsage(Dqn_StringBuilder *builder, usize size_required) +DQN_HEADER_COPY_PROTOTYPE( +template FILE_SCOPE char *, +Dqn_StringBuilder__GetWriteBufferAndUpdateUsage(Dqn_StringBuilder *builder, usize size_required)) { char *result = builder->fixed_mem + builder->fixed_mem_used; usize space = Dqn_ArrayCount(builder->fixed_mem) - builder->fixed_mem_used; @@ -650,8 +651,9 @@ FILE_SCOPE char *Dqn_StringBuilder__GetWriteBufferAndUpdateUsage(Dqn_StringBuild return result; } -template -FILE_SCOPE void Dqn_StringBuilder__BuildOutput(Dqn_StringBuilder const *builder, char *dest, isize dest_size) +DQN_HEADER_COPY_PROTOTYPE( +template FILE_SCOPE void, +Dqn_StringBuilder__BuildOutput(Dqn_StringBuilder const *builder, char *dest, isize dest_size)) { // NOTE: No data appended to builder, just allocate am empty string. But // always allocate, so we avoid adding making nullptr part of the possible @@ -706,9 +708,10 @@ Dqn_StringBuilder_BuildInBuffer(Dqn_StringBuilder const *builder, char *dest, Dqn_StringBuilder__BuildOutput(builder, dest, dest_size); } -// len: Return the length of the allocated string including the null-terminator -template -char *Dqn_StringBuilder_BuildFromMalloc(Dqn_StringBuilder *builder, isize *len = nullptr) +DQN_HEADER_COPY_PROTOTYPE_AND_COMMENT( +"len: Return the length of the allocated string including the null-terminator", +template , +char *Dqn_StringBuilder_BuildFromMalloc(Dqn_StringBuilder *builder, isize *len = nullptr)) { isize len_w_null_terminator = Dqn_StringBuilder_BuildLen(builder); auto *result = static_cast(malloc(len_w_null_terminator)); @@ -717,8 +720,9 @@ char *Dqn_StringBuilder_BuildFromMalloc(Dqn_StringBuilder *builder, isize *le return result; } -template -char *Dqn_StringBuilder_BuildFromArena(Dqn_StringBuilder *builder, Dqn_MemArena *arena, isize *len = nullptr) +DQN_HEADER_COPY_PROTOTYPE( +template , +char *Dqn_StringBuilder_BuildFromArena(Dqn_StringBuilder *builder, Dqn_MemArena *arena, isize *len = nullptr)) { isize len_w_null_terminator = Dqn_StringBuilder_BuildLen(builder); char *result = MEM_ARENA_ALLOC_ARRAY(arena, char, len_w_null_terminator); @@ -727,8 +731,9 @@ char *Dqn_StringBuilder_BuildFromArena(Dqn_StringBuilder *builder, Dqn_MemAre return result; } -template -void Dqn_StringBuilder_VFmtAppend(Dqn_StringBuilder *builder, char const *fmt, va_list va) +DQN_HEADER_COPY_PROTOTYPE( +template , +void Dqn_StringBuilder_VFmtAppend(Dqn_StringBuilder *builder, char const *fmt, va_list va)) { if (!fmt) return; isize require = stbsp_vsnprintf(nullptr, 0, fmt, va) + 1; @@ -737,8 +742,9 @@ void Dqn_StringBuilder_VFmtAppend(Dqn_StringBuilder *builder, char const *fmt builder->string_len += (require - 1); // -1 to exclude null terminator } -template -void Dqn_StringBuilder_FmtAppend(Dqn_StringBuilder *builder, char const *fmt, ...) +DQN_HEADER_COPY_PROTOTYPE( +template , +void Dqn_StringBuilder_FmtAppend(Dqn_StringBuilder *builder, char const *fmt, ...)) { va_list va; va_start(va, fmt); @@ -746,8 +752,9 @@ void Dqn_StringBuilder_FmtAppend(Dqn_StringBuilder *builder, char const *fmt, va_end(va); } -template -void Dqn_StringBuilder_Append(Dqn_StringBuilder *builder, char const *str, isize len = -1) +DQN_HEADER_COPY_PROTOTYPE( +template , +void Dqn_StringBuilder_Append(Dqn_StringBuilder *builder, char const *str, isize len = -1)) { if (!str) return; if (len == -1) len = (isize)strlen(str); @@ -758,8 +765,9 @@ void Dqn_StringBuilder_Append(Dqn_StringBuilder *builder, char const *str, is buf[len] = 0; } -template -void Dqn_StringBuilder_AppendChar(Dqn_StringBuilder *builder, char ch) +DQN_HEADER_COPY_PROTOTYPE( +template , +void Dqn_StringBuilder_AppendChar(Dqn_StringBuilder *builder, char ch)) { char *buf = Dqn_StringBuilder__GetWriteBufferAndUpdateUsage(builder, 1 + 1 /*null terminator*/); *buf++ = ch; @@ -767,8 +775,6 @@ void Dqn_StringBuilder_AppendChar(Dqn_StringBuilder *builder, char ch) buf[1] = 0; } - - // ------------------------------------------------------------------------------------------------- // // NOTE: (Memory) Slices @@ -794,8 +800,9 @@ struct Slice }; #define SLICE_LITERAL(string) Slice(DQN_STR_AND_LEN(string)) -template -inline Slice Slice_CopyNullTerminated(Dqn_MemArena *arena, T const *src, isize len) +DQN_HEADER_COPY_PROTOTYPE( +template , +inline Slice Slice_CopyNullTerminated(Dqn_MemArena *arena, T const *src, isize len)) { Slice result = {}; result.len = len; @@ -805,15 +812,17 @@ inline Slice Slice_CopyNullTerminated(Dqn_MemArena *arena, T const *src, isiz return result; } -template -inline Slice Slice_CopyNullTerminated(Dqn_MemArena *arena, Slice const src) +DQN_HEADER_COPY_PROTOTYPE( +template , +inline Slice Slice_CopyNullTerminated(Dqn_MemArena *arena, Slice const src)) { Slice result = Slice_CopyNullTerminated(arena, src.buf, src.len); return result; } -template -inline Slice Slice_Copy(Dqn_MemArena *arena, T const *src, isize len) +DQN_HEADER_COPY_PROTOTYPE( +template , +inline Slice Slice_Copy(Dqn_MemArena *arena, T const *src, isize len)) { Slice result = {}; result.len = len; @@ -822,8 +831,9 @@ inline Slice Slice_Copy(Dqn_MemArena *arena, T const *src, isize len) return result; } -template -inline Slice Slice_Copy(Dqn_MemArena *arena, Slice const src) +DQN_HEADER_COPY_PROTOTYPE( +template , +inline Slice Slice_Copy(Dqn_MemArena *arena, Slice const src)) { Slice result = Slice_Copy(arena, src.buf, src.len); return result; @@ -834,8 +844,9 @@ inline Slice Slice_Copy(Dqn_MemArena *arena, Slice const src) // NOTE: Asprintf (Allocate Sprintf) // // ------------------------------------------------------------------------------------------------- -template -Slice AsprintfSlice(T *arena, char const *fmt, va_list va) +DQN_HEADER_COPY_PROTOTYPE( +template Slice, +AsprintfSlice(T *arena, char const *fmt, va_list va)) { Slice result = {}; result.len = stbsp_vsnprintf(nullptr, 0, fmt, va) + 1; @@ -845,8 +856,9 @@ Slice AsprintfSlice(T *arena, char const *fmt, va_list va) return result; } -template -Slice AsprintfSlice(T *arena, char const *fmt, ...) +DQN_HEADER_COPY_PROTOTYPE( +template Slice, +AsprintfSlice(T *arena, char const *fmt, ...)) { va_list va; va_start(va, fmt); @@ -855,8 +867,9 @@ Slice AsprintfSlice(T *arena, char const *fmt, ...) return result; } -template -char *Asprintf(T *arena, int *len, char const *fmt, ...) +DQN_HEADER_COPY_PROTOTYPE( +template char *, +Asprintf(T *arena, int *len, char const *fmt, ...)) { va_list va; va_start(va, fmt); @@ -866,8 +879,9 @@ char *Asprintf(T *arena, int *len, char const *fmt, ...) return result.str; } -template -char *Asprintf(T *arena, char const *fmt, ...) +DQN_HEADER_COPY_PROTOTYPE( +template char *, +Asprintf(T *arena, char const *fmt, ...)) { va_list va; va_start(va, fmt); diff --git a/Code/Dqn_UnitTests.cpp b/Code/Dqn_UnitTests.cpp index 2aa0654..5a0f8cb 100644 --- a/Code/Dqn_UnitTests.cpp +++ b/Code/Dqn_UnitTests.cpp @@ -473,7 +473,7 @@ char *Dqn_StrSkipWhitespace(char *buf) char *ParseFunctionReturnType(char *ptr, isize *len) { - char *result = ptr; + char *result = Dqn_StrSkipWhitespace(ptr); isize result_len = 0; for (int scope = 0; ptr; ptr++) // NOTE: Parse the function return type { @@ -552,6 +552,7 @@ int main(char *argv[], int argc) char constexpr HEADER_COPY_PROTOTYPE[] = "DQN_HEADER_COPY_PROTOTYPE"; char constexpr HEADER_COPY_PROTOTYPE_AND_COMMENT[] = "DQN_HEADER_COPY_PROTOTYPE_AND_COMMENT"; + fprintf(stdout, "\n"); char *ptr = buf; char *ptr_end = buf + buf_size; isize ptr_len = buf_size; @@ -571,7 +572,7 @@ int main(char *argv[], int argc) while (ptr[0] != ',') ptr++; ptr++; - fprintf(stdout, "%.*s", (int)comment_len, comment); + fprintf(stdout, "%.*s\n", (int)comment_len, comment); } else { @@ -587,7 +588,7 @@ int main(char *argv[], int argc) char *func_name = ParseFunctionNameAndParameters(ptr, &func_name_len); ptr = func_name + func_name_len + 1; // Ptr is at macro closing paren, skip the paren - fprintf(stdout, "%.*s %.*s", (int)func_type_len, func_type, (int)func_name_len, func_name); + fprintf(stdout, "%.*s %.*s\n", (int)func_type_len, func_type, (int)func_name_len, func_name); } return 0;