Compare commits
No commits in common. "f1756e6f586e020fba23b32d40f5cab111fcd03f" and "1ed51d11cb22f6eb31163c4d34c335e99299b554" have entirely different histories.
f1756e6f58
...
1ed51d11cb
@ -6,7 +6,6 @@
|
||||
#include "memory/Heap.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "video/TextConsole.h"
|
||||
#include <Units.h>
|
||||
|
||||
Result<void> init()
|
||||
{
|
||||
@ -52,14 +51,6 @@ Result<void> init()
|
||||
|
||||
TRY(destroy(mem));
|
||||
|
||||
char buffer[64];
|
||||
to_dynamic_unit(MemoryManager::free(), buffer, sizeof(buffer));
|
||||
Serial::printf("Free memory: %s\n", buffer);
|
||||
to_dynamic_unit(MemoryManager::used(), buffer, sizeof(buffer));
|
||||
Serial::printf("Used memory: %s\n", buffer);
|
||||
to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer));
|
||||
Serial::printf("Reserved memory: %s\n", buffer);
|
||||
|
||||
while (1)
|
||||
{
|
||||
while ((Timer::ticks_ms() - start) < 20) { CPU::wait_for_interrupt(); }
|
||||
|
@ -2,7 +2,6 @@ set(FREESTANDING_SOURCES
|
||||
Format.cpp
|
||||
NumberParsing.cpp
|
||||
String.cpp
|
||||
Units.cpp
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
|
@ -468,42 +468,3 @@ Result<usize> cstyle_format(const char* format, callback_t callback, void* arg,
|
||||
|
||||
return state.count;
|
||||
}
|
||||
|
||||
struct StringFormatInfo
|
||||
{
|
||||
char* buffer;
|
||||
size_t remaining;
|
||||
};
|
||||
|
||||
Result<usize> vstring_format(char* buf, size_t max, const char* format, va_list ap)
|
||||
{
|
||||
StringFormatInfo info = {.buffer = buf, .remaining = max - 1};
|
||||
|
||||
usize result = TRY(cstyle_format(
|
||||
format,
|
||||
[](char c, void* arg) -> Result<void> {
|
||||
StringFormatInfo* info_arg = (StringFormatInfo*)arg;
|
||||
if (!info_arg->remaining) return {};
|
||||
*(info_arg->buffer) = c;
|
||||
info_arg->buffer++;
|
||||
info_arg->remaining--;
|
||||
return {};
|
||||
},
|
||||
&info, ap));
|
||||
|
||||
*(info.buffer) = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<usize> string_format(char* buf, size_t max, const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
usize result = TRY(vstring_format(buf, max, format, ap));
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
@ -6,5 +6,3 @@
|
||||
typedef Result<void> (*callback_t)(char, void*);
|
||||
|
||||
Result<usize> cstyle_format(const char* format, callback_t callback, void* arg, va_list ap);
|
||||
Result<usize> vstring_format(char* buf, size_t max, const char* format, va_list ap);
|
||||
Result<usize> string_format(char* buf, size_t max, const char* format, ...);
|
@ -1,17 +0,0 @@
|
||||
#include <Format.h>
|
||||
#include <Units.h>
|
||||
#include <limits.h>
|
||||
|
||||
Result<usize> to_dynamic_unit(usize value, char* buffer, size_t max)
|
||||
{
|
||||
if (value < 1024) { return string_format(buffer, max, "%u bytes", value); }
|
||||
|
||||
const char* unit_prefixes = "KMGTPE";
|
||||
for (int i = 40; i >= 0 && value > (0xfffccccccccccccUL >> i); i -= 10)
|
||||
{
|
||||
value >>= 10;
|
||||
unit_prefixes++;
|
||||
}
|
||||
|
||||
return string_format(buffer, max, "%u.%u %ciB", value / 1024, (value % 1024) / 103, *unit_prefixes);
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
#include <Result.h>
|
||||
|
||||
Result<usize> to_dynamic_unit(usize value, char* buffer, usize max);
|
Loading…
Reference in New Issue
Block a user