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/ build/
test.* test*

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

@ -2,18 +2,28 @@
#include <graphics.hpp> #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 namespace gr
{ {
struct Context::_impl struct Context::_impl
{ {
Tickit* context; Tickit* context;
TickitWindow* root;
}; };
Context::Context() Context::Context()
: impl(std::make_unique<_impl>()) : impl(std::make_unique<_impl>())
{ {
//TODO: Graphics. impl->context = tickit_new_stdtty();
//TODO: Change hex.cpp print_screen to use these graphics instead of stdout with fmt impl->root = tickit_get_rootwin(impl->context);
if(!impl->root) throw "couldn't create window.";
} }
Context::~Context() Context::~Context()

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

@ -15,9 +15,14 @@ inline auto map_file(const char* filename)
return hv::memory_map(filesize(filename), 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(); auto memory = map.span();
hv::print_screen(memory, 0); hv::print_screen(memory, 0);

Loading…
Cancel
Save