small refactor

This commit is contained in:
silverweed 2024-08-08 16:43:39 +02:00
parent 6accff3cbd
commit 0c21fd35db

View file

@ -699,10 +699,8 @@ struct Try_Sec_Hover_Fn {
}
return false;
}
};
internal
b8 hover_try_key(const Try_Sec_Hover_Fn &try_sec_hover, const u8 *data, u64 start)
b8 tkey() const
{
u16 version_be;
memcpy(&version_be, data + start + 4, sizeof(u16));
@ -710,49 +708,41 @@ b8 hover_try_key(const Try_Sec_Hover_Fn &try_sec_hover, const u8 *data, u64 star
b8 is_big = version > 1000;
if (is_big) {
return try_sec_hover.field<u32>("NBytes: %u")
|| try_sec_hover.field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {
return field<u32>("NBytes: %u")
|| field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {
x = bswap(x);
x -= (x > 1000) * 1000;
x -= 1000;
return push_str8_node_child(arena, prev, fmt, x);
})
|| try_sec_hover.field<u32>("Obj Len: %u")
|| try_sec_hover.field<u32>("Datetime: ", hover_display_datetime_str)
|| try_sec_hover.field<u16>("Key Len: %u")
|| try_sec_hover.field<u16>("Cycle: %u")
|| try_sec_hover.field<u64>("Seek Key: 0x%lX")
|| try_sec_hover.field<u64>("Seek Pdir: 0x%lX")
|| try_sec_hover.field<String8>("Class Name: %s")
|| try_sec_hover.field<String8>("Obj Name: %s")
|| try_sec_hover.field<String8>("Obj Title: %s")
|| field<u32>("Obj Len: %u")
|| field<u32>("Datetime: ", hover_display_datetime_str)
|| field<u16>("Key Len: %u")
|| field<u16>("Cycle: %u")
|| field<u64>("Seek Key: 0x%lX")
|| field<u64>("Seek Pdir: 0x%lX")
|| field<String8>("Class Name: %s")
|| field<String8>("Obj Name: %s")
|| field<String8>("Obj Title: %s")
;
} else {
return try_sec_hover.field<u32>("NBytes: %u")
|| try_sec_hover.field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {
return field<u32>("NBytes: %u")
|| field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {
x = bswap(x);
x -= (x > 1000) * 1000;
return push_str8_node_child(arena, prev, fmt, x);
})
|| try_sec_hover.field<u32>("Obj Len: %u")
|| try_sec_hover.field<u32>("Datetime: ", hover_display_datetime_str)
|| try_sec_hover.field<u16>("Key Len: %u")
|| try_sec_hover.field<u16>("Cycle: %u")
|| try_sec_hover.field<u32>("Seek Key: 0x%lX")
|| try_sec_hover.field<u32>("Seek Pdir: 0x%lX")
|| try_sec_hover.field<String8>("Class Name: %s")
|| try_sec_hover.field<String8>("Obj Name: %s")
|| try_sec_hover.field<String8>("Obj Title: %s")
|| field<u32>("Obj Len: %u")
|| field<u32>("Datetime: ", hover_display_datetime_str)
|| field<u16>("Key Len: %u")
|| field<u16>("Cycle: %u")
|| field<u32>("Seek Key: 0x%lX")
|| field<u32>("Seek Pdir: 0x%lX")
|| field<String8>("Class Name: %s")
|| field<String8>("Obj Name: %s")
|| field<String8>("Obj Title: %s")
;
}
}
internal
b8 hover_try_object(const Try_Sec_Hover_Fn &try_sec_hover)
{
return try_sec_hover.field<u16>("Version: %u")
|| try_sec_hover.field<u32>("Unique ID: %u")
|| try_sec_hover.field<u32>("Bits: %u");
}
};
// `off` is the absolute offset into `data`.
internal
@ -772,7 +762,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
switch (section.id) {
case Sec_RNTuple_Anchor: {
hover_try_key(try_sec_hover, data, start)
try_sec_hover.tkey()
|| try_sec_hover.field<u32>("Object len: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u32 x) {
x = bswap(x);
x -= 0x4000'0000;
@ -838,7 +828,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
} break;
case Sec_TFile_Object: {
if (!hover_try_key(try_sec_hover, data, start)) {
if (!try_sec_hover.tkey()) {
b8 ok = try_sec_hover.field<String8>("File Name: %s")
|| try_sec_hover.field<String8>("File Title: %s")
;
@ -885,7 +875,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
case Sec_RNTuple_Header:
case Sec_RNTuple_Footer:
case Sec_Page_List: {
hover_try_key(try_sec_hover, data, start)
try_sec_hover.tkey()
|| try_sec_hover.maybe_rootzip(data, start)
|| try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve
|| try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le)
@ -893,7 +883,8 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
} break;
case Sec_Page: {
b8 ok = section.pre_size && hover_try_key(try_sec_hover, data, start);
// only try hovering a key if this is the first page of the cluster (<=> pre_size != 0)
b8 ok = section.pre_size && try_sec_hover.tkey();
ok = ok || try_sec_hover.maybe_rootzip(data, start)
|| try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve
|| try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le)
@ -901,7 +892,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
} break;
case Sec_TFile_Info: {
hover_try_key(try_sec_hover, data, start)
try_sec_hover.tkey()
|| try_sec_hover.maybe_rootzip(data, start)
// || try_sec_hover.field<u32>("Byte Count: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u32 x) {
// x = bswap(x);
@ -917,9 +908,31 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
} break;
case Sec_TFile_FreeList: {
hover_try_key(try_sec_hover, data, start)
|| try_sec_hover.range("Payload", section.range.len) // TODO: improve
if (!try_sec_hover.tkey()) {
u16 version_be;
memcpy(&version_be, data + start + try_sec_hover.cur_field_off, sizeof(u16));
u32 version = bswap(version_be);
b8 is_big = version > 1000;
if (is_big) {
try_sec_hover.field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {
x = bswap(x);
x -= 1000;
return push_str8_node_child(arena, prev, fmt, x);
})
|| try_sec_hover.field<u64>("First: 0x%lX")
|| try_sec_hover.field<u64>("Last: 0x%lX")
;
} else {
try_sec_hover.field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {
x = bswap(x);
return push_str8_node_child(arena, prev, fmt, x);
})
|| try_sec_hover.field<u32>("First: 0x%X")
|| try_sec_hover.field<u32>("Last: 0x%X")
;
}
}
} break;
default:;