Update DN from seasight
This commit is contained in:
parent
ed483537c6
commit
a17925904d
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1550,20 +1550,16 @@ DN_API DN_USize DN_FmtVSize(DN_FMT_ATTRIB char const *fmt, va_list args)
|
||||
DN_API DN_USize DN_CStr8Size(char const *src)
|
||||
{
|
||||
DN_USize result = 0;
|
||||
for (;src && src[0] != 0; src++, result++) {
|
||||
src++;
|
||||
result++;
|
||||
}
|
||||
for (; src && src[0] != 0; src++, result++)
|
||||
;
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_API DN_USize DN_CStr16Size(wchar_t const *src)
|
||||
{
|
||||
DN_USize result = 0;
|
||||
while (src && src[0] != 0) {
|
||||
src++;
|
||||
result++;
|
||||
}
|
||||
for (; src && src[0] != 0; src++, result++)
|
||||
;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -394,7 +394,7 @@ DN_API DN_ProfilerZone DN_Profiler_BeginZone(DN_Profiler *profiler, DN_Str8 name
|
||||
// TODO: We need per-thread-local-storage profiler so that we can use these apis
|
||||
// across threads. For now, we let them overwrite each other but this is not tenable.
|
||||
#if 0
|
||||
if (DN_Str8HasData(anchor->name) && anchor->name != name)
|
||||
if (anchor->name.size && anchor->name != name)
|
||||
DN_AssertF(name == anchor->name, "Potentially overwriting a zone by accident? Anchor is '%.*s', name is '%.*s'", DN_Str8PrintFmt(anchor->name), DN_Str8PrintFmt(name));
|
||||
#endif
|
||||
|
||||
|
||||
@ -602,7 +602,7 @@ void DN_Docs_Demo()
|
||||
DN_ProfilerAnchor *read_anchors = DN_Profiler_ReadBuffer();
|
||||
for (DN_USize index = 0; index < DN_PROFILER_ANCHOR_BUFFER_SIZE; index++) {
|
||||
DN_ProfilerAnchor *anchor = read_anchors + index;
|
||||
if (DN_Str8HasData(anchor->name)) {
|
||||
if (anchor->name.size) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
@ -614,7 +614,7 @@ void DN_Docs_Demo()
|
||||
DN_ProfilerAnchor *write_anchors = DN_Profiler_WriteBuffer();
|
||||
for (DN_USize index = 0; index < DN_PROFILER_ANCHOR_BUFFER_SIZE; index++) {
|
||||
DN_ProfilerAnchor *anchor = write_anchors + index;
|
||||
if (DN_Str8HasData(anchor->name)) {
|
||||
if (anchor->name.size) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
@ -1039,7 +1039,7 @@ void DN_Docs_Demo()
|
||||
|
||||
// NOTE: DN_Str8x32FromFmt
|
||||
{
|
||||
DN_Str8x32 string = DN_Str8x32FromFmt("%" PRIu64, 123123);
|
||||
DN_Str8x32 string = DN_Str8x32FromFmt("%d", 123123);
|
||||
if (0) // Prints "123123"
|
||||
printf("%.*s", DN_Str8PrintFmt(string));
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ static bool DN_CSV_TokeniserValid(DN_CSVTokeniser *tokeniser)
|
||||
static bool DN_CSV_TokeniserNextRow(DN_CSVTokeniser *tokeniser)
|
||||
{
|
||||
bool result = false;
|
||||
if (DN_CSV_TokeniserValid(tokeniser) && DN_Str8HasData(tokeniser->string)) {
|
||||
if (DN_CSV_TokeniserValid(tokeniser) && tokeniser->string.size) {
|
||||
// NOTE: First time querying row iterator is nil, let tokeniser advance
|
||||
if (tokeniser->it) {
|
||||
// NOTE: Only advance the tokeniser if we're at the end of the line and
|
||||
@ -39,7 +39,7 @@ static DN_Str8 DN_CSV_TokeniserNextField(DN_CSVTokeniser *tokeniser)
|
||||
if (!DN_CSV_TokeniserValid(tokeniser))
|
||||
return result;
|
||||
|
||||
if (!DN_Str8HasData(tokeniser->string)) {
|
||||
if (tokeniser->string.size == 0) {
|
||||
tokeniser->bad = true;
|
||||
return result;
|
||||
}
|
||||
@ -146,7 +146,7 @@ static int DN_CSV_TokeniserNextN(DN_CSVTokeniser *tokeniser, DN_Str8 *fields, in
|
||||
int result = 0;
|
||||
for (; result < fields_size; result++) {
|
||||
fields[result] = column_iterator ? DN_CSV_TokeniserNextColumn(tokeniser) : DN_CSV_TokeniserNextField(tokeniser);
|
||||
if (!DN_CSV_TokeniserValid(tokeniser) || !DN_Str8HasData(fields[result]))
|
||||
if (!DN_CSV_TokeniserValid(tokeniser) || fields[result].size == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -176,8 +176,8 @@ static void DN_CSV_TokeniserSkipLineN(DN_CSVTokeniser *tokeniser, int count)
|
||||
static void DN_CSV_PackU64(DN_CSVPack *pack, DN_CSVSerialise serialise, DN_U64 *value)
|
||||
{
|
||||
if (serialise == DN_CSVSerialise_Read) {
|
||||
DN_Str8 csv_value = DN_CSV_TokeniserNextColumn(&pack->read_tokeniser);
|
||||
DN_Str8ToU64Result to_u64 = DN_Str8ToU64(csv_value, 0);
|
||||
DN_Str8 csv_value = DN_CSV_TokeniserNextColumn(&pack->read_tokeniser);
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(csv_value, 0);
|
||||
DN_Assert(to_u64.success);
|
||||
*value = to_u64.value;
|
||||
} else {
|
||||
@ -188,8 +188,8 @@ static void DN_CSV_PackU64(DN_CSVPack *pack, DN_CSVSerialise serialise, DN_U64 *
|
||||
static void DN_CSV_PackI64(DN_CSVPack *pack, DN_CSVSerialise serialise, DN_I64 *value)
|
||||
{
|
||||
if (serialise == DN_CSVSerialise_Read) {
|
||||
DN_Str8 csv_value = DN_CSV_TokeniserNextColumn(&pack->read_tokeniser);
|
||||
DN_Str8ToI64Result to_i64 = DN_Str8ToI64(csv_value, 0);
|
||||
DN_Str8 csv_value = DN_CSV_TokeniserNextColumn(&pack->read_tokeniser);
|
||||
DN_I64FromResult to_i64 = DN_I64FromStr8(csv_value, 0);
|
||||
DN_Assert(to_i64.success);
|
||||
*value = to_i64.value;
|
||||
} else {
|
||||
@ -250,7 +250,7 @@ static void DN_CSV_PackStr8(DN_CSVPack *pack, DN_CSVSerialise serialise, DN_Str8
|
||||
{
|
||||
if (serialise == DN_CSVSerialise_Read) {
|
||||
DN_Str8 csv_value = DN_CSV_TokeniserNextColumn(&pack->read_tokeniser);
|
||||
*str8 = DN_Str8FromStr8(arena, csv_value);
|
||||
*str8 = DN_Str8FromStr8Arena(arena, csv_value);
|
||||
} else {
|
||||
DN_Str8BuilderAppendF(&pack->write_builder, "%s%.*s", pack->write_column++ ? "," : "", DN_Str8PrintFmt(*str8));
|
||||
}
|
||||
|
||||
@ -239,10 +239,10 @@ static void DN_RefImpl_CPUReportDump() // Print out supported instruction set fe
|
||||
static DN_UTCore DN_Tests_Base()
|
||||
{
|
||||
DN_UTCore result = DN_UT_Init();
|
||||
#if defined(DN_PLATFORM_WIN32) && defined(DN_COMPILER_MSVC)
|
||||
DN_RefImplCPUReport ref_cpu_report = DN_RefImplCPUReport_Init();
|
||||
DN_UT_LogF(&result, "DN_Base\n");
|
||||
{
|
||||
#if defined(DN_PLATFORM_WIN32) && defined(DN_COMPILER_MSVC)
|
||||
DN_RefImplCPUReport ref_cpu_report = DN_RefImplCPUReport_Init();
|
||||
for (DN_UT_Test(&result, "Query CPUID")) {
|
||||
DN_CPUReport cpu_report = DN_CPUGetReport();
|
||||
|
||||
@ -278,30 +278,30 @@ static DN_UTCore DN_Tests_Base()
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_SSE4A) == ref_cpu_report.SSE4a());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_SSSE3) == ref_cpu_report.SSSE3());
|
||||
|
||||
// NOTE: Feature flags we haven't bothered detecting yet but are in MSDN's example /////////////
|
||||
#if 0
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_ADX) == DN_RefImplCPUReport::ADX());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_BMI1) == DN_RefImplCPUReport::BMI1());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_BMI2) == DN_RefImplCPUReport::BMI2());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_CLFSH) == DN_RefImplCPUReport::CLFSH());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_CX8) == DN_RefImplCPUReport::CX8());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_ERMS) == DN_RefImplCPUReport::ERMS());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_FSGSBASE) == DN_RefImplCPUReport::FSGSBASE());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_FXSR) == DN_RefImplCPUReport::FXSR());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_HLE) == DN_RefImplCPUReport::HLE());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_INVPCID) == DN_RefImplCPUReport::INVPCID());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_LAHF) == DN_RefImplCPUReport::LAHF());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_LZCNT) == DN_RefImplCPUReport::LZCNT());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_MSR) == DN_RefImplCPUReport::MSR());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_OSXSAVE) == DN_RefImplCPUReport::OSXSAVE());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_PREFETCHWT1) == DN_RefImplCPUReport::PREFETCHWT1());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_RTM) == DN_RefImplCPUReport::RTM());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_SEP) == DN_RefImplCPUReport::SEP());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_SYSCALL) == DN_RefImplCPUReport::SYSCALL());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_TBM) == DN_RefImplCPUReport::TBM());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_XOP) == DN_RefImplCPUReport::XOP());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_XSAVE) == DN_RefImplCPUReport::XSAVE());
|
||||
#endif
|
||||
// NOTE: Feature flags we haven't bothered detecting yet but are in MSDN's example /////////////
|
||||
#if 0
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_ADX) == DN_RefImplCPUReport::ADX());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_BMI1) == DN_RefImplCPUReport::BMI1());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_BMI2) == DN_RefImplCPUReport::BMI2());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_CLFSH) == DN_RefImplCPUReport::CLFSH());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_CX8) == DN_RefImplCPUReport::CX8());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_ERMS) == DN_RefImplCPUReport::ERMS());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_FSGSBASE) == DN_RefImplCPUReport::FSGSBASE());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_FXSR) == DN_RefImplCPUReport::FXSR());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_HLE) == DN_RefImplCPUReport::HLE());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_INVPCID) == DN_RefImplCPUReport::INVPCID());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_LAHF) == DN_RefImplCPUReport::LAHF());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_LZCNT) == DN_RefImplCPUReport::LZCNT());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_MSR) == DN_RefImplCPUReport::MSR());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_OSXSAVE) == DN_RefImplCPUReport::OSXSAVE());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_PREFETCHWT1) == DN_RefImplCPUReport::PREFETCHWT1());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_RTM) == DN_RefImplCPUReport::RTM());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_SEP) == DN_RefImplCPUReport::SEP());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_SYSCALL) == DN_RefImplCPUReport::SYSCALL());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_TBM) == DN_RefImplCPUReport::TBM());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_XOP) == DN_RefImplCPUReport::XOP());
|
||||
DN_UT_Assert(&result, DN_CPUHasFeature(&cpu_report, DN_CPUFeature_XSAVE) == DN_RefImplCPUReport::XSAVE());
|
||||
#endif
|
||||
}
|
||||
#endif // defined(DN_PLATFORM_WIN32) && defined(DN_COMPILER_MSVC)
|
||||
|
||||
@ -309,6 +309,12 @@ static DN_UTCore DN_Tests_Base()
|
||||
char buffer[512];
|
||||
DN_Arena arena = DN_ArenaFromBuffer(buffer, sizeof(buffer), DN_ArenaFlags_NoPoison | DN_ArenaFlags_AllocCanLeak);
|
||||
|
||||
// NOTE: CStr8Size
|
||||
{
|
||||
DN_USize size = DN_CStr8Size("hello");
|
||||
DN_UT_AssertF(&result, size == 5, "size=%zu", size);
|
||||
}
|
||||
|
||||
// NOTE: Str8FromFmtArena
|
||||
{
|
||||
DN_Str8 str8 = DN_Str8FromFmtArena(&arena, "Foo Bar %d", 5);
|
||||
@ -1667,7 +1673,7 @@ DN_Str8 const DN_UT_HASH_STRING_[] =
|
||||
void DN_Tests_KeccakDispatch_(DN_UTCore *test, int hash_type, DN_Str8 input)
|
||||
{
|
||||
DN_OSTLSTMem tmem = DN_OS_TLSTMem(nullptr);
|
||||
DN_Str8 input_hex = DN_CVT_HexFromBytes(tmem.arena, input.data, input.size);
|
||||
DN_Str8 input_hex = DN_HexFromBytesPtrArena(input.data, input.size, tmem.arena);
|
||||
|
||||
switch (hash_type) {
|
||||
case Hash_SHA3_224: {
|
||||
|
||||
@ -196,7 +196,7 @@ DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
|
||||
{
|
||||
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
|
||||
DN_OSDiskSpace result = {};
|
||||
DN_Str8 path_z_terminated = DN_Str8FromStr8(tmem.arena, path);
|
||||
DN_Str8 path_z_terminated = DN_Str8FromStr8Arena(tmem.arena, path);
|
||||
|
||||
struct statvfs info = {};
|
||||
if (statvfs(path_z_terminated.data, &info) != 0)
|
||||
@ -598,7 +598,7 @@ DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
DN_USize path_indexes_size = 0;
|
||||
uint16_t path_indexes[64] = {};
|
||||
|
||||
DN_Str8 copy = DN_Str8FromStr8(tmem.arena, path);
|
||||
DN_Str8 copy = DN_Str8FromStr8Arena(tmem.arena, path);
|
||||
for (DN_USize index = copy.size - 1; index < copy.size; index--) {
|
||||
bool first_char = index == (copy.size - 1);
|
||||
char ch = copy.data[index];
|
||||
@ -910,7 +910,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Slice<DN_Str8> cmd_line,
|
||||
|
||||
for (DN_ForIndexU(arg_index, cmd_line.size)) {
|
||||
DN_Str8 arg = cmd_line.data[arg_index];
|
||||
argv[arg_index] = DN_Str8FromStr8(tmem.arena, arg).data; // NOTE: Copy string to guarantee it is null-terminated
|
||||
argv[arg_index] = DN_Str8FromStr8Arena(tmem.arena, arg).data; // NOTE: Copy string to guarantee it is null-terminated
|
||||
}
|
||||
|
||||
// NOTE: Change the working directory if there is one
|
||||
@ -928,7 +928,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Slice<DN_Str8> cmd_line,
|
||||
|
||||
if (args->working_dir.size) {
|
||||
prev_working_dir = get_current_dir_name();
|
||||
DN_Str8 working_dir = DN_Str8FromStr8(tmem.arena, args->working_dir);
|
||||
DN_Str8 working_dir = DN_Str8FromStr8Arena(tmem.arena, args->working_dir);
|
||||
if (chdir(working_dir.data) == -1) {
|
||||
result.os_error_code = errno;
|
||||
DN_OS_ErrSinkAppendF(
|
||||
@ -1294,7 +1294,7 @@ DN_API void DN_Posix_ThreadSetName(DN_Str8 name)
|
||||
(void)name;
|
||||
#else
|
||||
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
|
||||
DN_Str8 copy = DN_Str8FromStr8(tmem.arena, name);
|
||||
DN_Str8 copy = DN_Str8FromStr8Arena(tmem.arena, name);
|
||||
pthread_t thread = pthread_self();
|
||||
pthread_setname_np(thread, (char *)copy.data);
|
||||
#endif
|
||||
@ -1340,23 +1340,23 @@ DN_API DN_POSIXProcSelfStatus DN_Posix_ProcSelfStatus()
|
||||
result.name_size = DN_Min(str8.size, sizeof(result.name));
|
||||
DN_Memcpy(result.name, str8.data, result.name_size);
|
||||
} else if (DN_Str8StartsWith(line, PID, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 str8 = DN_Str8TrimWhitespaceAround(DN_Str8Slice(line, PID.size, line.size));
|
||||
DN_Str8ToU64Result to_u64 = DN_Str8ToU64(str8, 0);
|
||||
result.pid = to_u64.value;
|
||||
DN_Str8 str8 = DN_Str8TrimWhitespaceAround(DN_Str8Slice(line, PID.size, line.size));
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(str8, 0);
|
||||
result.pid = to_u64.value;
|
||||
DN_Assert(to_u64.success);
|
||||
} else if (DN_Str8StartsWith(line, VM_SIZE, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 size_with_kb = DN_Str8TrimWhitespaceAround(DN_Str8Slice(line, VM_SIZE.size, line.size));
|
||||
DN_Assert(DN_Str8EndsWith(size_with_kb, DN_Str8Lit("kB")));
|
||||
DN_Str8 vm_size = DN_Str8BSplit(size_with_kb, DN_Str8Lit(" ")).lhs;
|
||||
DN_Str8ToU64Result to_u64 = DN_Str8ToU64(vm_size, 0);
|
||||
result.vm_size = DN_Kilobytes(to_u64.value);
|
||||
DN_Str8 vm_size = DN_Str8BSplit(size_with_kb, DN_Str8Lit(" ")).lhs;
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(vm_size, 0);
|
||||
result.vm_size = DN_Kilobytes(to_u64.value);
|
||||
DN_Assert(to_u64.success);
|
||||
} else if (DN_Str8StartsWith(line, VM_PEAK, DN_Str8EqCase_Insensitive)) {
|
||||
DN_Str8 size_with_kb = DN_Str8TrimWhitespaceAround(DN_Str8Slice(line, VM_PEAK.size, line.size));
|
||||
DN_Assert(DN_Str8EndsWith(size_with_kb, DN_Str8Lit("kB")));
|
||||
DN_Str8 vm_size = DN_Str8BSplit(size_with_kb, DN_Str8Lit(" ")).lhs;
|
||||
DN_Str8ToU64Result to_u64 = DN_Str8ToU64(vm_size, 0);
|
||||
result.vm_peak = DN_Kilobytes(to_u64.value);
|
||||
DN_Str8 vm_size = DN_Str8BSplit(size_with_kb, DN_Str8Lit(" ")).lhs;
|
||||
DN_U64FromResult to_u64 = DN_U64FromStr8(vm_size, 0);
|
||||
result.vm_peak = DN_Kilobytes(to_u64.value);
|
||||
DN_Assert(to_u64.success);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ DN_KCBytes32 DN_KC_Keccak256(void const *src, uint64_t size);
|
||||
DN_KCBytes48 DN_KC_Keccak384(void const *src, uint64_t size);
|
||||
DN_KCBytes64 DN_KC_Keccak512(void const *src, uint64_t size);
|
||||
|
||||
#if defined(DN_BASE_STRING_H)
|
||||
#if defined(DN_BASE_H)
|
||||
// NOTE: SHA3 - Helpers for DN data structures ////////////////////////////////////////////////////
|
||||
DN_KCBytes28 DN_KC_SHA3_224Str8(DN_Str8 string);
|
||||
DN_KCBytes32 DN_KC_SHA3_256Str8(DN_Str8 string);
|
||||
@ -239,7 +239,7 @@ DN_KCBytes28 DN_KC_Keccak224Str8(DN_Str8 string);
|
||||
DN_KCBytes32 DN_KC_Keccak256Str8(DN_Str8 string);
|
||||
DN_KCBytes48 DN_KC_Keccak384Str8(DN_Str8 string);
|
||||
DN_KCBytes64 DN_KC_Keccak512Str8(DN_Str8 string);
|
||||
#endif // DN_BASE_STRING_H
|
||||
#endif // DN_BASE_H
|
||||
|
||||
// NOTE: Helper functions //////////////////////////////////////////////////////////////////////////
|
||||
// Convert a binary buffer into its hex representation into dest. The dest
|
||||
@ -262,13 +262,13 @@ int DN_KC_Bytes32Equals(DN_KCBytes32 const *a, DN_KCBytes32 const *b);
|
||||
int DN_KC_Bytes48Equals(DN_KCBytes48 const *a, DN_KCBytes48 const *b);
|
||||
int DN_KC_Bytes64Equals(DN_KCBytes64 const *a, DN_KCBytes64 const *b);
|
||||
|
||||
#if defined(DN_BASE_STRING_H)
|
||||
#if defined(DN_BASE_H)
|
||||
// NOTE: Other helper functions for DN data structures ////////////////////////////////////////////
|
||||
// Converts a 64 character hex string into the 32 byte binary representation.
|
||||
// Invalid hex characters in the string will be represented as 0.
|
||||
// hex: Must be exactly a 64 character hex string.
|
||||
DN_KCBytes32 DN_KC_Hex64ToBytes(DN_Str8 hex);
|
||||
#endif // DN_BASE_STRING_H
|
||||
#endif // DN_BASE_H
|
||||
#endif // DN_KC_H
|
||||
|
||||
#if defined(DN_KC_IMPLEMENTATION)
|
||||
@ -518,7 +518,7 @@ DN_KCBytes64 DN_KC_Keccak512(void const *src, size_t size)
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined(DN_BASE_STRING_H)
|
||||
#if defined(DN_BASE_H)
|
||||
// NOTE: SHA3 - Helpers for DN data structures ////////////////////////////////////////////////////
|
||||
DN_KCBytes28 DN_KC_SHA3_224Str8(DN_Str8 string)
|
||||
{
|
||||
@ -547,9 +547,9 @@ DN_KCBytes64 DN_KC_SHA3_512Str8(DN_Str8 string)
|
||||
DN_KC_SHA3_512Ptr(string.data, string.size, result.data, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
#endif // DN_BASE_STRING_H
|
||||
#endif // DN_BASE_H
|
||||
|
||||
#if defined(DN_BASE_STRING_H)
|
||||
#if defined(DN_BASE_H)
|
||||
// NOTE: Keccak - Helpers for DN data structures //////////////////////////////////////////////////
|
||||
DN_KCBytes28 DN_KC_Keccak224Str8(DN_Str8 string)
|
||||
{
|
||||
@ -578,7 +578,7 @@ DN_KCBytes64 DN_KC_Keccak512Str8(DN_Str8 string)
|
||||
DN_KC_Keccak512Ptr(string.data, string.size, result.data, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
#endif // DN_BASE_STRING_H
|
||||
#endif // DN_BASE_H
|
||||
|
||||
// NOTE: Helper functions //////////////////////////////////////////////////////////////////////////
|
||||
void DN_KC_HexFromBytes(void const *src, size_t src_size, char *dest, size_t dest_size)
|
||||
@ -653,14 +653,14 @@ int DN_KC_Bytes64Equals(DN_KCBytes64 const *a, DN_KCBytes64 const *b)
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined(DN_BASE_STRING_H)
|
||||
#if defined(DN_BASE_H)
|
||||
// NOTE: Other helper functions for DN data structures ////////////////////////////////////////////
|
||||
DN_KCBytes32 DN_KC_Hex64ToBytes(DN_Str8 hex)
|
||||
{
|
||||
DN_KC_ASSERT(hex.size == 64);
|
||||
DN_KCBytes32 result;
|
||||
DN_CVT_BytesFromHexPtr(hex, result.data, sizeof(result));
|
||||
DN_BytesFromHexStr8(hex, result.data, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
#endif // DN_BASE_STRING_H
|
||||
#endif // DN_BASE_H
|
||||
#endif // DN_KC_IMPLEMENTATION
|
||||
|
||||
@ -36,19 +36,19 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
DN_OS_ErrSinkEndAndExitIfErrorF(err, -1, "Failed to load file from '%S' for appending", cpp_path);
|
||||
|
||||
for (DN_Str8 inc_walker = buffer;;) {
|
||||
DN_Str8BSplitResult split = DN_Str8_BSplit(inc_walker, DN_STR8("\n"));
|
||||
if (!DN_Str8_HasData(split.lhs))
|
||||
DN_Str8BSplitResult split = DN_Str8BSplit(inc_walker, DN_Str8Lit("\n"));
|
||||
if (split.lhs.size == 0)
|
||||
break;
|
||||
inc_walker = split.rhs;
|
||||
|
||||
// NOTE: Trim the whitespace, mainly for windows, the file we read will have \r\n whereas we just want to emit \n
|
||||
DN_Str8 line = DN_Str8_TrimTailWhitespace(split.lhs);
|
||||
DN_Str8 line = DN_Str8TrimTailWhitespace(split.lhs);
|
||||
|
||||
// NOTE: Comment out any #include "../dn_.*" matches if we encounter one
|
||||
DN_Str8FindResult find = DN_Str8_FindStr8(line, DN_STR8("#include \"../dn_"), DN_Str8EqCase_Sensitive);
|
||||
DN_Str8FindResult find = DN_Str8FindStr8(line, DN_Str8Lit("#include \"../dn_"), DN_Str8EqCase_Sensitive);
|
||||
{
|
||||
if (find.found) {
|
||||
line = DN_Str8_FromTLSF("%S// DN: Single header generator commented out this header => %S", find.start_to_before_match, DN_Str8_TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
line = DN_Str8FromTLSF("%S// DN: Single header generator commented out this header => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
|
||||
// The only time we use '../dn_.*' is for LSP purposes, so we
|
||||
// don't care about inlining it, hence we don't set 'include_file'
|
||||
@ -59,17 +59,17 @@ static void AppendCppFileLineByLine(DN_Str8Builder *dest, DN_Str8 cpp_path)
|
||||
// (Right now DN only includes stb_sprintf with a relative path)
|
||||
DN_Str8 extra_include_path = {};
|
||||
if (!find.found) {
|
||||
find = DN_Str8_FindStr8(line, DN_STR8("#include \""), DN_Str8EqCase_Sensitive);
|
||||
find = DN_Str8FindStr8(line, DN_Str8Lit("#include \""), DN_Str8EqCase_Sensitive);
|
||||
if (find.found) {
|
||||
line = DN_Str8_FromTLSF("%S// DN: Single header generator commented out this header => %S", find.start_to_before_match, DN_Str8_TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
DN_Str8 rel_include_path = DN_Str8_TrimWhitespaceAround(find.after_match_to_end_of_buffer);
|
||||
DN_Str8 root_dir = DN_Str8_FileDirectoryFromPath(cpp_path);
|
||||
extra_include_path = DN_OS_PathFFromTLS("%S/%S", root_dir, DN_Str8_TrimSuffix(rel_include_path, DN_STR8("\"")));
|
||||
line = DN_Str8FromTLSF("%S// DN: Single header generator commented out this header => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
DN_Str8 rel_include_path = DN_Str8TrimWhitespaceAround(find.after_match_to_end_of_buffer);
|
||||
DN_Str8 root_dir = DN_Str8FileDirectoryFromPath(cpp_path);
|
||||
extra_include_path = DN_OS_PathFFromTLS("%S/%S", root_dir, DN_Str8TrimSuffix(rel_include_path, DN_Str8Lit("\"")));
|
||||
}
|
||||
}
|
||||
|
||||
DN_Str8Builder_AppendRef(dest, line);
|
||||
DN_Str8Builder_AppendRef(dest, DN_STR8("\n"));
|
||||
DN_Str8BuilderAppendRef(dest, line);
|
||||
DN_Str8BuilderAppendRef(dest, DN_Str8Lit("\n"));
|
||||
|
||||
if (extra_include_path.size)
|
||||
AppendCppFileLineByLine(dest, extra_include_path);
|
||||
@ -88,25 +88,25 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
DN_Str8 dn_root_dir = DN_Str8_FromCStr8(argv[1]);
|
||||
DN_Str8 output_dir = DN_Str8_FromCStr8(argv[2]);
|
||||
DN_Str8 dn_root_dir = DN_Str8FromCStr8(argv[1]);
|
||||
DN_Str8 output_dir = DN_Str8FromCStr8(argv[2]);
|
||||
if (!DN_OS_PathMakeDir(output_dir)) {
|
||||
DN_OS_PrintErrF("Failed to make requested output directory: %S", output_dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
File const FILES[] = {
|
||||
{FileType_Header, DN_STR8("dn_base_inc.h")},
|
||||
{FileType_Header, DN_STR8("dn_os_inc.h")},
|
||||
{FileType_Header, DN_STR8("dn_core_inc.h")},
|
||||
{FileType_Impl, DN_STR8("dn_base_inc.cpp")},
|
||||
{FileType_Impl, DN_STR8("dn_os_inc.cpp")},
|
||||
{FileType_Impl, DN_STR8("dn_core_inc.cpp")},
|
||||
{FileType_Header, DN_Str8Lit("dn_base_inc.h")},
|
||||
{FileType_Header, DN_Str8Lit("dn_os_inc.h")},
|
||||
{FileType_Header, DN_Str8Lit("dn_core_inc.h")},
|
||||
{FileType_Impl, DN_Str8Lit("dn_base_inc.cpp")},
|
||||
{FileType_Impl, DN_Str8Lit("dn_os_inc.cpp")},
|
||||
{FileType_Impl, DN_Str8Lit("dn_core_inc.cpp")},
|
||||
};
|
||||
|
||||
for (DN_ForIndexU(type, FileType_Count)) {
|
||||
DN_OSTLSTMem tmem = DN_OS_TLSPushTMem(nullptr);
|
||||
DN_Str8Builder builder = DN_Str8Builder_FromTLS();
|
||||
DN_Str8Builder builder = DN_Str8BuilderFromTLS();
|
||||
for (DN_ForItCArray(it, File const, FILES)) {
|
||||
if (it.data->type != type)
|
||||
continue;
|
||||
@ -120,29 +120,29 @@ int main(int argc, char **argv)
|
||||
|
||||
// NOTE: Walk the top-level dn_*_inc.[h|cpp] files
|
||||
for (DN_Str8 walker = file_buffer;;) {
|
||||
DN_Str8BSplitResult split = DN_Str8_BSplit(walker, DN_STR8("\n"));
|
||||
if (!DN_Str8_HasData(split.lhs))
|
||||
DN_Str8BSplitResult split = DN_Str8BSplit(walker, DN_Str8Lit("\n"));
|
||||
if (split.lhs.size == 0)
|
||||
break;
|
||||
|
||||
// NOTE: Parse the line, if it was a #include, extract it into this string
|
||||
DN_Str8 include_file = {};
|
||||
{
|
||||
walker = split.rhs;
|
||||
DN_Str8 line = DN_Str8_TrimTailWhitespace(split.lhs);
|
||||
DN_Str8 line = DN_Str8TrimTailWhitespace(split.lhs);
|
||||
|
||||
// NOTE: Comment out any #include "dn_.*" matches if we encounter one
|
||||
DN_Str8FindResult find = DN_Str8_FindStr8(line, DN_STR8("#include \""), DN_Str8EqCase_Sensitive);
|
||||
DN_Str8FindResult find = DN_Str8FindStr8(line, DN_Str8Lit("#include \""), DN_Str8EqCase_Sensitive);
|
||||
{
|
||||
if (find.found && DN_Str8_FindStr8(line, DN_STR8("dn_"), DN_Str8EqCase_Sensitive).found) {
|
||||
line = DN_Str8_FromTLSF("%S// DN: Single header generator inlined this file => %S", find.start_to_before_match, DN_Str8_TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
include_file = DN_Str8_BSplit(find.after_match_to_end_of_buffer, DN_STR8("\"")).lhs;
|
||||
if (find.found && DN_Str8FindStr8(line, DN_Str8Lit("dn_"), DN_Str8EqCase_Sensitive).found) {
|
||||
line = DN_Str8FromTLSF("%S// DN: Single header generator inlined this file => %S", find.start_to_before_match, DN_Str8TrimWhitespaceAround(find.match_to_end_of_buffer));
|
||||
include_file = DN_Str8BSplit(find.after_match_to_end_of_buffer, DN_Str8Lit("\"")).lhs;
|
||||
DN_Assert(include_file.size);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Record the line
|
||||
DN_Str8Builder_AppendRef(&builder, line);
|
||||
DN_Str8Builder_AppendRef(&builder, DN_STR8("\n"));
|
||||
DN_Str8BuilderAppendRef(&builder, line);
|
||||
DN_Str8BuilderAppendRef(&builder, DN_Str8Lit("\n"));
|
||||
}
|
||||
|
||||
if (include_file.size) { // NOTE: If the line was a include file, we will inline the included file
|
||||
@ -154,23 +154,23 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
DN_Str8 extra_files[] = {
|
||||
DN_STR8("Extra/dn_math"),
|
||||
DN_STR8("Extra/dn_async"),
|
||||
DN_STR8("Extra/dn_bin_pack"),
|
||||
DN_STR8("Extra/dn_csv"),
|
||||
DN_STR8("Extra/dn_hash"),
|
||||
DN_STR8("Extra/dn_helpers"),
|
||||
DN_Str8Lit("Extra/dn_math"),
|
||||
DN_Str8Lit("Extra/dn_async"),
|
||||
DN_Str8Lit("Extra/dn_bin_pack"),
|
||||
DN_Str8Lit("Extra/dn_csv"),
|
||||
DN_Str8Lit("Extra/dn_hash"),
|
||||
DN_Str8Lit("Extra/dn_helpers"),
|
||||
};
|
||||
DN_Str8 suffix = type == FileType_Header ? DN_STR8("h") : DN_STR8("cpp");
|
||||
DN_Str8 suffix = type == FileType_Header ? DN_Str8Lit("h") : DN_Str8Lit("cpp");
|
||||
for (DN_ForItCArray(extra_it, DN_Str8, extra_files)) {
|
||||
DN_Str8 extra_path = DN_OS_PathFFromTLS("%S/%S.%S", dn_root_dir, *extra_it.data, suffix);
|
||||
AppendCppFileLineByLine(&builder, extra_path);
|
||||
}
|
||||
|
||||
DN_OSDateTime date = DN_OS_DateLocalTimeNow();
|
||||
DN_Str8Builder_PrependF(&builder, "// Generated by the DN single header generator %04u-%02u-%02u %02u:%02u:%02u\n\n", date.year, date.month, date.day, date.hour, date.minutes, date.seconds);
|
||||
DN_Str8BuilderPrependF(&builder, "// Generated by the DN single header generator %04u-%02u-%02u %02u:%02u:%02u\n\n", date.year, date.month, date.day, date.hour, date.minutes, date.seconds);
|
||||
|
||||
DN_Str8 buffer = DN_Str8_TrimWhitespaceAround(DN_Str8Builder_BuildFromTLS(&builder));
|
||||
DN_Str8 buffer = DN_Str8TrimWhitespaceAround(DN_Str8BuilderBuildFromTLS(&builder));
|
||||
DN_Str8 single_header_path = DN_OS_PathFFromTLS("%S/dn_single_header.%S", output_dir, suffix);
|
||||
DN_OSErrSink *err = DN_OS_ErrSinkBeginDefault();
|
||||
DN_OS_FileWriteAllSafe(single_header_path, buffer, err);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user