change width

master
Avril 4 years ago
parent 74e3c6af64
commit 7788284b9e
Signed by: flanchan
GPG Key ID: 284488987C31F630

2
.gitignore vendored

@ -1,3 +1,3 @@
*~
build/
test.*
test*

@ -1,8 +1,8 @@
SRC:=src/*.cpp
INCLUDE:=include/
BUILD:=build
CFLAGS:=-Wall -pedantic -O3 -march=native --std=gnu++20
LFLAGS:=-ltickit -lfmt
CFLAGS:=-Wall -pedantic -O3 -march=native --std=gnu++20 -fgraphite -flto
LFLAGS:=-O2 -flto -ltickit -lfmt
hexview:
g++ $(SRC) $(CFLAGS) -I$(INCLUDE) -o $(BUILD)/$@ $(LFLAGS)

@ -2,18 +2,28 @@
#include <graphics.hpp>
static int on_geomchange(TickitWindow* win, TickitEventFlags flags, void* info, void* data)
{
tickit_window_expose(win, NULL);
gr::Context* ctx = (gr::Context*)data;
}
namespace gr
{
struct Context::_impl
{
Tickit* context;
TickitWindow* root;
};
Context::Context()
: impl(std::make_unique<_impl>())
{
//TODO: Graphics.
//TODO: Change hex.cpp print_screen to use these graphics instead of stdout with fmt
impl->context = tickit_new_stdtty();
impl->root = tickit_get_rootwin(impl->context);
if(!impl->root) throw "couldn't create window.";
}
Context::~Context()

@ -20,26 +20,28 @@ const static constexpr char ascii_map[255] = {
'.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.',
};
const constexpr int ROW_SZ = 24;
namespace hv {
void print_screen(const span<unsigned char> memory, unsigned long offset)
{
fmt::print("0x{:016x} ", offset);
char ascii[17];
ascii[16] = 0;
char ascii[1 + ROW_SZ];
ascii[ROW_SZ] = 0;
std::size_t i=0;
for(;i<memory.size();i++) {
if (i && i % 16 == 0) {
if (i && i % ROW_SZ == 0) {
fmt::print(" {}", ascii);
fmt::print("\n0x{:016x} ", i+offset);
}
fmt::print("{:02x} ", memory[i]);
ascii[i%16] = ascii_map[memory[i]];
ascii[i%ROW_SZ] = ascii_map[memory[i]];
}
if (memory.size() % 16 != 0)
if (memory.size() % ROW_SZ != 0)
{
auto rest = memory.size() % 16;
auto rest = memory.size() % ROW_SZ;
ascii[rest] = 0;
for(std::size_t j=0;j< 16 - rest;j++)
for(std::size_t j=0;j< ROW_SZ - rest;j++)
fmt::print(" ");
}

@ -15,9 +15,14 @@ inline auto map_file(const char* filename)
return hv::memory_map(filesize(filename), filename);
}
int main(void)
int main(int argc, char** argv)
{
auto map = map_file("test.txt");
if(!argv[1]) {
fmt::print("Usage: {} <file>\n", argv[0]);
return 1;
}
auto map = map_file(argv[1]);
auto memory = map.span();
hv::print_screen(memory, 0);

Loading…
Cancel
Save