g_ctx -> g
Because it's just plain noise. But I still enjoy the indicator.
This commit is contained in:
parent
00d6c5ede9
commit
f6d552766b
410
hex.c
410
hex.c
|
@ -157,10 +157,10 @@ static struct app_context
|
||||||
|
|
||||||
struct attrs attrs[ATTRIBUTE_COUNT];
|
struct attrs attrs[ATTRIBUTE_COUNT];
|
||||||
}
|
}
|
||||||
g_ctx;
|
g;
|
||||||
|
|
||||||
/// Shortcut to retrieve named terminal attributes
|
/// Shortcut to retrieve named terminal attributes
|
||||||
#define APP_ATTR(name) g_ctx.attrs[ATTRIBUTE_ ## name].attrs
|
#define APP_ATTR(name) g.attrs[ATTRIBUTE_ ## name].attrs
|
||||||
|
|
||||||
// --- Configuration -----------------------------------------------------------
|
// --- Configuration -----------------------------------------------------------
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ load_config_colors (struct config_item *subtree, void *user_data)
|
||||||
const char *value;
|
const char *value;
|
||||||
#define XX(name, config, fg_, bg_, attrs_) \
|
#define XX(name, config, fg_, bg_, attrs_) \
|
||||||
if ((value = get_config_string (subtree, config))) \
|
if ((value = get_config_string (subtree, config))) \
|
||||||
g_ctx.attrs[ATTRIBUTE_ ## name] = attrs_decode (value);
|
g.attrs[ATTRIBUTE_ ## name] = attrs_decode (value);
|
||||||
ATTRIBUTE_TABLE (XX)
|
ATTRIBUTE_TABLE (XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ load_config_colors (struct config_item *subtree, void *user_data)
|
||||||
static void
|
static void
|
||||||
app_load_configuration (void)
|
app_load_configuration (void)
|
||||||
{
|
{
|
||||||
struct config *config = &g_ctx.config;
|
struct config *config = &g.config;
|
||||||
config_register_module (config, "colors", load_config_colors, NULL);
|
config_register_module (config, "colors", load_config_colors, NULL);
|
||||||
|
|
||||||
// Bootstrap configuration, so that we can access schema items at all
|
// Bootstrap configuration, so that we can access schema items at all
|
||||||
|
@ -228,8 +228,8 @@ app_load_configuration (void)
|
||||||
}
|
}
|
||||||
if (root)
|
if (root)
|
||||||
{
|
{
|
||||||
config_load (&g_ctx.config, root);
|
config_load (&g.config, root);
|
||||||
config_schema_call_changed (g_ctx.config.root);
|
config_schema_call_changed (g.config.root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,9 +239,9 @@ static void
|
||||||
app_init_attributes (void)
|
app_init_attributes (void)
|
||||||
{
|
{
|
||||||
#define XX(name, config, fg_, bg_, attrs_) \
|
#define XX(name, config, fg_, bg_, attrs_) \
|
||||||
g_ctx.attrs[ATTRIBUTE_ ## name].fg = fg_; \
|
g.attrs[ATTRIBUTE_ ## name].fg = fg_; \
|
||||||
g_ctx.attrs[ATTRIBUTE_ ## name].bg = bg_; \
|
g.attrs[ATTRIBUTE_ ## name].bg = bg_; \
|
||||||
g_ctx.attrs[ATTRIBUTE_ ## name].attrs = attrs_;
|
g.attrs[ATTRIBUTE_ ## name].attrs = attrs_;
|
||||||
ATTRIBUTE_TABLE (XX)
|
ATTRIBUTE_TABLE (XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
}
|
}
|
||||||
|
@ -256,13 +256,13 @@ app_on_insufficient_color (void)
|
||||||
static void
|
static void
|
||||||
app_init_context (void)
|
app_init_context (void)
|
||||||
{
|
{
|
||||||
poller_init (&g_ctx.poller);
|
poller_init (&g.poller);
|
||||||
g_ctx.config = config_make ();
|
g.config = config_make ();
|
||||||
|
|
||||||
ARRAY_INIT (g_ctx.marks);
|
ARRAY_INIT (g.marks);
|
||||||
g_ctx.mark_strings = str_make ();
|
g.mark_strings = str_make ();
|
||||||
ARRAY_INIT (g_ctx.marks_by_offset);
|
ARRAY_INIT (g.marks_by_offset);
|
||||||
ARRAY_INIT (g_ctx.offset_entries);
|
ARRAY_INIT (g.offset_entries);
|
||||||
|
|
||||||
app_init_attributes ();
|
app_init_attributes ();
|
||||||
}
|
}
|
||||||
|
@ -270,24 +270,24 @@ app_init_context (void)
|
||||||
static void
|
static void
|
||||||
app_free_context (void)
|
app_free_context (void)
|
||||||
{
|
{
|
||||||
config_free (&g_ctx.config);
|
config_free (&g.config);
|
||||||
poller_free (&g_ctx.poller);
|
poller_free (&g.poller);
|
||||||
|
|
||||||
free (g_ctx.marks);
|
free (g.marks);
|
||||||
str_free (&g_ctx.mark_strings);
|
str_free (&g.mark_strings);
|
||||||
free (g_ctx.marks_by_offset);
|
free (g.marks_by_offset);
|
||||||
free (g_ctx.offset_entries);
|
free (g.offset_entries);
|
||||||
|
|
||||||
cstr_set (&g_ctx.message, NULL);
|
cstr_set (&g.message, NULL);
|
||||||
|
|
||||||
cstr_set (&g_ctx.filename, NULL);
|
cstr_set (&g.filename, NULL);
|
||||||
free (g_ctx.data);
|
free (g.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
app_quit (void)
|
app_quit (void)
|
||||||
{
|
{
|
||||||
g_ctx.polling = false;
|
g.polling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Field marking -----------------------------------------------------------
|
// --- Field marking -----------------------------------------------------------
|
||||||
|
@ -296,11 +296,11 @@ app_quit (void)
|
||||||
static ssize_t
|
static ssize_t
|
||||||
app_find_marks (int64_t offset)
|
app_find_marks (int64_t offset)
|
||||||
{
|
{
|
||||||
ssize_t min = 0, end = g_ctx.marks_by_offset_len;
|
ssize_t min = 0, end = g.marks_by_offset_len;
|
||||||
while (min < end)
|
while (min < end)
|
||||||
{
|
{
|
||||||
ssize_t mid = min + (end - min) / 2;
|
ssize_t mid = min + (end - min) / 2;
|
||||||
if (offset >= g_ctx.marks_by_offset[mid].offset)
|
if (offset >= g.marks_by_offset[mid].offset)
|
||||||
min = mid + 1;
|
min = mid + 1;
|
||||||
else
|
else
|
||||||
end = mid;
|
end = mid;
|
||||||
|
@ -312,10 +312,10 @@ static struct marks_by_offset *
|
||||||
app_marks_at_offset (int64_t offset)
|
app_marks_at_offset (int64_t offset)
|
||||||
{
|
{
|
||||||
ssize_t i = app_find_marks (offset);
|
ssize_t i = app_find_marks (offset);
|
||||||
if (i < 0 || (size_t) i >= g_ctx.marks_by_offset_len)
|
if (i < 0 || (size_t) i >= g.marks_by_offset_len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct marks_by_offset *marks = &g_ctx.marks_by_offset[i];
|
struct marks_by_offset *marks = &g.marks_by_offset[i];
|
||||||
if (marks->offset > offset)
|
if (marks->offset > offset)
|
||||||
return NULL;
|
return NULL;
|
||||||
return marks;
|
return marks;
|
||||||
|
@ -336,11 +336,11 @@ app_mark_cmp (const void *first, const void *second)
|
||||||
static size_t
|
static size_t
|
||||||
app_store_marks (struct mark **entries, size_t len)
|
app_store_marks (struct mark **entries, size_t len)
|
||||||
{
|
{
|
||||||
size_t result = g_ctx.offset_entries_len;
|
size_t result = g.offset_entries_len;
|
||||||
ARRAY_RESERVE (g_ctx.offset_entries, len);
|
ARRAY_RESERVE (g.offset_entries, len);
|
||||||
memcpy (g_ctx.offset_entries + g_ctx.offset_entries_len, entries,
|
memcpy (g.offset_entries + g.offset_entries_len, entries,
|
||||||
sizeof *entries * len);
|
sizeof *entries * len);
|
||||||
g_ctx.offset_entries_len += len;
|
g.offset_entries_len += len;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,8 +356,8 @@ app_store_marks (struct mark **entries, size_t len)
|
||||||
static void
|
static void
|
||||||
app_flatten_marks (void)
|
app_flatten_marks (void)
|
||||||
{
|
{
|
||||||
qsort (g_ctx.marks, g_ctx.marks_len, sizeof *g_ctx.marks, app_mark_cmp);
|
qsort (g.marks, g.marks_len, sizeof *g.marks, app_mark_cmp);
|
||||||
if (!g_ctx.marks_len)
|
if (!g.marks_len)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ARRAY (struct mark *, current)
|
ARRAY (struct mark *, current)
|
||||||
|
@ -365,14 +365,14 @@ app_flatten_marks (void)
|
||||||
int current_color = 0;
|
int current_color = 0;
|
||||||
|
|
||||||
// Make offset zero actually point to an empty entry
|
// Make offset zero actually point to an empty entry
|
||||||
g_ctx.offset_entries[g_ctx.offset_entries_len++] = NULL;
|
g.offset_entries[g.offset_entries_len++] = NULL;
|
||||||
|
|
||||||
struct mark *next = g_ctx.marks;
|
struct mark *next = g.marks;
|
||||||
struct mark *end = next + g_ctx.marks_len;
|
struct mark *end = next + g.marks_len;
|
||||||
while (current_len || next < end)
|
while (current_len || next < end)
|
||||||
{
|
{
|
||||||
// Find the closest offset at which marks change
|
// Find the closest offset at which marks change
|
||||||
int64_t closest = g_ctx.data_offset + g_ctx.data_len;
|
int64_t closest = g.data_offset + g.data_len;
|
||||||
if (next < end)
|
if (next < end)
|
||||||
closest = next->offset;
|
closest = next->offset;
|
||||||
for (size_t i = 0; i < current_len; i++)
|
for (size_t i = 0; i < current_len; i++)
|
||||||
|
@ -405,8 +405,8 @@ app_flatten_marks (void)
|
||||||
current_color %= 4;
|
current_color %= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
ARRAY_RESERVE (g_ctx.marks_by_offset, 1);
|
ARRAY_RESERVE (g.marks_by_offset, 1);
|
||||||
g_ctx.marks_by_offset[g_ctx.marks_by_offset_len++] =
|
g.marks_by_offset[g.marks_by_offset_len++] =
|
||||||
(struct marks_by_offset) { closest, marks, color };
|
(struct marks_by_offset) { closest, marks, color };
|
||||||
}
|
}
|
||||||
free (current);
|
free (current);
|
||||||
|
@ -441,7 +441,7 @@ static struct widget *
|
||||||
app_mono_padding (chtype attrs, float width, float height)
|
app_mono_padding (chtype attrs, float width, float height)
|
||||||
{
|
{
|
||||||
struct widget *w = g_xui.ui->padding (attrs, width, height);
|
struct widget *w = g_xui.ui->padding (attrs, width, height);
|
||||||
w->width = width * g_ctx.digitw;
|
w->width = width * g.digitw;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,23 +484,23 @@ app_layout_cell (struct layout *hex, struct layout *ascii, int attrs,
|
||||||
struct marks_by_offset *marks = app_marks_at_offset (addr);
|
struct marks_by_offset *marks = app_marks_at_offset (addr);
|
||||||
int attrs_mark = attrs;
|
int attrs_mark = attrs;
|
||||||
if (marks && marks->color >= 0)
|
if (marks && marks->color >= 0)
|
||||||
attrs_mark = g_ctx.attrs[marks->color].attrs;
|
attrs_mark = g.attrs[marks->color].attrs;
|
||||||
|
|
||||||
if (addr >= g_ctx.view_cursor
|
if (addr >= g.view_cursor
|
||||||
&& addr < g_ctx.view_cursor + 8)
|
&& addr < g.view_cursor + 8)
|
||||||
{
|
{
|
||||||
attrs |= A_UNDERLINE;
|
attrs |= A_UNDERLINE;
|
||||||
attrs_mark |= A_UNDERLINE;
|
attrs_mark |= A_UNDERLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: leave it up to the user to decide what should be colored
|
// TODO: leave it up to the user to decide what should be colored
|
||||||
uint8_t cell = g_ctx.data[addr - g_ctx.data_offset];
|
uint8_t cell = g.data[addr - g.data_offset];
|
||||||
if (addr != g_ctx.view_cursor)
|
if (addr != g.view_cursor)
|
||||||
{
|
{
|
||||||
char s[] = { hexa[cell >> 4], hexa[cell & 0xf], 0 };
|
char s[] = { hexa[cell >> 4], hexa[cell & 0xf], 0 };
|
||||||
app_push (hex, app_mono_label (attrs, s));
|
app_push (hex, app_mono_label (attrs, s));
|
||||||
}
|
}
|
||||||
else if (g_ctx.view_skip_nibble)
|
else if (g.view_skip_nibble)
|
||||||
{
|
{
|
||||||
char s1[] = { hexa[cell >> 4], 0 }, s2[] = { hexa[cell & 0xf], 0 };
|
char s1[] = { hexa[cell >> 4], 0 }, s2[] = { hexa[cell & 0xf], 0 };
|
||||||
app_push (hex, app_mono_label (attrs, s1));
|
app_push (hex, app_mono_label (attrs, s1));
|
||||||
|
@ -530,14 +530,14 @@ app_layout_row (int64_t addr, int y, int attrs)
|
||||||
struct layout ascii = {};
|
struct layout ascii = {};
|
||||||
app_push (&ascii, app_mono_padding (attrs, 2, 1));
|
app_push (&ascii, app_mono_padding (attrs, 2, 1));
|
||||||
|
|
||||||
int64_t end_addr = g_ctx.data_offset + g_ctx.data_len;
|
int64_t end_addr = g.data_offset + g.data_len;
|
||||||
for (int x = 0; x < ROW_SIZE; x++)
|
for (int x = 0; x < ROW_SIZE; x++)
|
||||||
{
|
{
|
||||||
if (x % 8 == 0) app_push (&hex, app_mono_padding (attrs, 1, 1));
|
if (x % 8 == 0) app_push (&hex, app_mono_padding (attrs, 1, 1));
|
||||||
if (x % 2 == 0) app_push (&hex, app_mono_padding (attrs, 1, 1));
|
if (x % 2 == 0) app_push (&hex, app_mono_padding (attrs, 1, 1));
|
||||||
|
|
||||||
int64_t cell_addr = addr + x;
|
int64_t cell_addr = addr + x;
|
||||||
if (cell_addr < g_ctx.data_offset
|
if (cell_addr < g.data_offset
|
||||||
|| cell_addr >= end_addr)
|
|| cell_addr >= end_addr)
|
||||||
{
|
{
|
||||||
app_push (&hex, app_mono_padding (attrs, 2, 1));
|
app_push (&hex, app_mono_padding (attrs, 2, 1));
|
||||||
|
@ -559,10 +559,10 @@ static struct widget *
|
||||||
app_layout_view (void)
|
app_layout_view (void)
|
||||||
{
|
{
|
||||||
struct layout l = {};
|
struct layout l = {};
|
||||||
int64_t end_addr = g_ctx.data_offset + g_ctx.data_len;
|
int64_t end_addr = g.data_offset + g.data_len;
|
||||||
for (int y = 0; y <= app_visible_rows (); y++)
|
for (int y = 0; y <= app_visible_rows (); y++)
|
||||||
{
|
{
|
||||||
int64_t addr = g_ctx.view_top + y * ROW_SIZE;
|
int64_t addr = g.view_top + y * ROW_SIZE;
|
||||||
if (addr >= end_addr)
|
if (addr >= end_addr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -579,10 +579,10 @@ app_layout_info (void)
|
||||||
{
|
{
|
||||||
const struct marks_by_offset *marks;
|
const struct marks_by_offset *marks;
|
||||||
struct layout l = {};
|
struct layout l = {};
|
||||||
if (!(marks = app_marks_at_offset (g_ctx.view_cursor)))
|
if (!(marks = app_marks_at_offset (g.view_cursor)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
struct mark *mark, **iter = g_ctx.offset_entries + marks->marks;
|
struct mark *mark, **iter = g.offset_entries + marks->marks;
|
||||||
for (int y = 0; y <= app_visible_rows (); y++)
|
for (int y = 0; y <= app_visible_rows (); y++)
|
||||||
{
|
{
|
||||||
// TODO: we can use the field background
|
// TODO: we can use the field background
|
||||||
|
@ -590,7 +590,7 @@ app_layout_info (void)
|
||||||
if (!(mark = *iter++))
|
if (!(mark = *iter++))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const char *description = g_ctx.mark_strings.str + mark->description;
|
const char *description = g.mark_strings.str + mark->description;
|
||||||
app_push (&l, app_label (0, description));
|
app_push (&l, app_label (0, description));
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
@ -622,9 +622,9 @@ app_footer_field (char id, int size, const char *fmt, ...)
|
||||||
const char *coding = "";
|
const char *coding = "";
|
||||||
if (size <= 1)
|
if (size <= 1)
|
||||||
;
|
;
|
||||||
else if (g_ctx.endianity == ENDIANITY_LE)
|
else if (g.endianity == ENDIANITY_LE)
|
||||||
coding = "le";
|
coding = "le";
|
||||||
else if (g_ctx.endianity == ENDIANITY_BE)
|
else if (g.endianity == ENDIANITY_BE)
|
||||||
coding = "be";
|
coding = "be";
|
||||||
|
|
||||||
struct layout l = {};
|
struct layout l = {};
|
||||||
|
@ -655,7 +655,7 @@ app_footer_group (struct layout *out, int size, int64_t u, int64_t s, int align)
|
||||||
app_push (&l, app_footer_field ('u', size, "%" PRIu64, u));
|
app_push (&l, app_footer_field ('u', size, "%" PRIu64, u));
|
||||||
app_push (&l, app_footer_field ('s', size, "%" PRId64, s));
|
app_push (&l, app_footer_field ('s', size, "%" PRId64, s));
|
||||||
l.head->width = MAX (l.head->width,
|
l.head->width = MAX (l.head->width,
|
||||||
g_ctx.digitw * align /* sign + ceil(log10(U/INT*_MAX)) */);
|
g.digitw * align /* sign + ceil(log10(U/INT*_MAX)) */);
|
||||||
if (out->head)
|
if (out->head)
|
||||||
app_push (out, app_mono_padding (APP_ATTR (FOOTER), 2, 1));
|
app_push (out, app_mono_padding (APP_ATTR (FOOTER), 2, 1));
|
||||||
app_push (out, xui_vbox (l.head));
|
app_push (out, xui_vbox (l.head));
|
||||||
|
@ -668,11 +668,11 @@ app_layout_footer (void)
|
||||||
app_push (&statusl, app_label (APP_ATTR (BAR), APP_TITLE));
|
app_push (&statusl, app_label (APP_ATTR (BAR), APP_TITLE));
|
||||||
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
||||||
|
|
||||||
if (g_ctx.message)
|
if (g.message)
|
||||||
app_push (&statusl, app_label (APP_ATTR (BAR_HL), g_ctx.message));
|
app_push (&statusl, app_label (APP_ATTR (BAR_HL), g.message));
|
||||||
else if (g_ctx.filename)
|
else if (g.filename)
|
||||||
{
|
{
|
||||||
char *filename = (char *) u8_strconv_from_locale (g_ctx.filename);
|
char *filename = (char *) u8_strconv_from_locale (g.filename);
|
||||||
app_push (&statusl, app_label (APP_ATTR (BAR_HL), filename));
|
app_push (&statusl, app_label (APP_ATTR (BAR_HL), filename));
|
||||||
free (filename);
|
free (filename);
|
||||||
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
||||||
|
@ -680,46 +680,46 @@ app_layout_footer (void)
|
||||||
|
|
||||||
app_push_hfill (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
app_push_hfill (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
||||||
|
|
||||||
char *address = xstrdup_printf ("%08" PRIx64, g_ctx.view_cursor);
|
char *address = xstrdup_printf ("%08" PRIx64, g.view_cursor);
|
||||||
app_push (&statusl, app_mono_label (APP_ATTR (BAR), address));
|
app_push (&statusl, app_mono_label (APP_ATTR (BAR), address));
|
||||||
free (address);
|
free (address);
|
||||||
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
||||||
|
|
||||||
app_push (&statusl, app_mono_label (APP_ATTR (BAR),
|
app_push (&statusl, app_mono_label (APP_ATTR (BAR),
|
||||||
g_ctx.endianity == ENDIANITY_LE ? "LE" : "BE"))->id = WIDGET_ENDIANITY;
|
g.endianity == ENDIANITY_LE ? "LE" : "BE"))->id = WIDGET_ENDIANITY;
|
||||||
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
app_push (&statusl, g_xui.ui->padding (APP_ATTR (BAR), 1, 1));
|
||||||
|
|
||||||
int64_t top = g_ctx.view_top;
|
int64_t top = g.view_top;
|
||||||
int64_t bot = g_ctx.view_top + app_visible_rows () * ROW_SIZE;
|
int64_t bot = g.view_top + app_visible_rows () * ROW_SIZE;
|
||||||
struct str where = str_make ();
|
struct str where = str_make ();
|
||||||
if (top <= g_ctx.data_offset
|
if (top <= g.data_offset
|
||||||
&& bot >= g_ctx.data_offset + g_ctx.data_len)
|
&& bot >= g.data_offset + g.data_len)
|
||||||
str_append (&where, "All");
|
str_append (&where, "All");
|
||||||
else if (top <= g_ctx.data_offset)
|
else if (top <= g.data_offset)
|
||||||
str_append (&where, "Top");
|
str_append (&where, "Top");
|
||||||
else if (bot >= g_ctx.data_offset + g_ctx.data_len)
|
else if (bot >= g.data_offset + g.data_len)
|
||||||
str_append (&where, "Bot");
|
str_append (&where, "Bot");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int64_t end_addr = g_ctx.data_offset + g_ctx.data_len;
|
int64_t end_addr = g.data_offset + g.data_len;
|
||||||
int64_t cur = g_ctx.view_top / ROW_SIZE;
|
int64_t cur = g.view_top / ROW_SIZE;
|
||||||
int64_t max = (end_addr - 1) / ROW_SIZE - app_visible_rows () + 1;
|
int64_t max = (end_addr - 1) / ROW_SIZE - app_visible_rows () + 1;
|
||||||
|
|
||||||
cur -= g_ctx.data_offset / ROW_SIZE;
|
cur -= g.data_offset / ROW_SIZE;
|
||||||
max -= g_ctx.data_offset / ROW_SIZE;
|
max -= g.data_offset / ROW_SIZE;
|
||||||
str_append_printf (&where, "%2d%%", (int) (100 * cur / max));
|
str_append_printf (&where, "%2d%%", (int) (100 * cur / max));
|
||||||
}
|
}
|
||||||
|
|
||||||
app_push (&statusl, app_mono_label (APP_ATTR (BAR), where.str));
|
app_push (&statusl, app_mono_label (APP_ATTR (BAR), where.str));
|
||||||
str_free (&where);
|
str_free (&where);
|
||||||
|
|
||||||
int64_t end_addr = g_ctx.data_offset + g_ctx.data_len;
|
int64_t end_addr = g.data_offset + g.data_len;
|
||||||
if (g_ctx.view_cursor < g_ctx.data_offset
|
if (g.view_cursor < g.data_offset
|
||||||
|| g_ctx.view_cursor >= end_addr)
|
|| g.view_cursor >= end_addr)
|
||||||
return xui_hbox (statusl.head);
|
return xui_hbox (statusl.head);
|
||||||
|
|
||||||
int64_t len = end_addr - g_ctx.view_cursor;
|
int64_t len = end_addr - g.view_cursor;
|
||||||
uint8_t *p = g_ctx.data + (g_ctx.view_cursor - g_ctx.data_offset);
|
uint8_t *p = g.data + (g.view_cursor - g.data_offset);
|
||||||
|
|
||||||
// TODO: The entire bottom part perhaps should be pre-painted
|
// TODO: The entire bottom part perhaps should be pre-painted
|
||||||
// with APP_ATTR (FOOTER).
|
// with APP_ATTR (FOOTER).
|
||||||
|
@ -728,17 +728,17 @@ app_layout_footer (void)
|
||||||
app_footer_group (&groupl, 1, p[0], (int8_t) p[0], 3 + 4);
|
app_footer_group (&groupl, 1, p[0], (int8_t) p[0], 3 + 4);
|
||||||
if (len >= 2)
|
if (len >= 2)
|
||||||
{
|
{
|
||||||
uint16_t value = app_decode (p, 2, g_ctx.endianity);
|
uint16_t value = app_decode (p, 2, g.endianity);
|
||||||
app_footer_group (&groupl, 2, value, (int16_t) value, 6 + 6);
|
app_footer_group (&groupl, 2, value, (int16_t) value, 6 + 6);
|
||||||
}
|
}
|
||||||
if (len >= 4)
|
if (len >= 4)
|
||||||
{
|
{
|
||||||
uint32_t value = app_decode (p, 4, g_ctx.endianity);
|
uint32_t value = app_decode (p, 4, g.endianity);
|
||||||
app_footer_group (&groupl, 4, value, (int32_t) value, 6 + 11);
|
app_footer_group (&groupl, 4, value, (int32_t) value, 6 + 11);
|
||||||
}
|
}
|
||||||
if (len >= 8)
|
if (len >= 8)
|
||||||
{
|
{
|
||||||
uint64_t value = app_decode (p, 8, g_ctx.endianity);
|
uint64_t value = app_decode (p, 8, g.endianity);
|
||||||
app_footer_group (&groupl, 8, value, (int64_t) value, 6 + 20);
|
app_footer_group (&groupl, 8, value, (int64_t) value, 6 + 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -828,8 +828,8 @@ static void
|
||||||
app_lua_coder_free (void *coder)
|
app_lua_coder_free (void *coder)
|
||||||
{
|
{
|
||||||
struct app_lua_coder *self = coder;
|
struct app_lua_coder *self = coder;
|
||||||
luaL_unref (g_ctx.L, LUA_REGISTRYINDEX, self->ref_decode);
|
luaL_unref (g.L, LUA_REGISTRYINDEX, self->ref_decode);
|
||||||
luaL_unref (g_ctx.L, LUA_REGISTRYINDEX, self->ref_detect);
|
luaL_unref (g.L, LUA_REGISTRYINDEX, self->ref_detect);
|
||||||
free (self);
|
free (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,7 +840,7 @@ app_lua_register (lua_State *L)
|
||||||
|
|
||||||
(void) app_lua_getfield (L, 1, "type", LUA_TSTRING, false);
|
(void) app_lua_getfield (L, 1, "type", LUA_TSTRING, false);
|
||||||
const char *type = lua_tostring (L, -1);
|
const char *type = lua_tostring (L, -1);
|
||||||
if (str_map_find (&g_ctx.coders, type))
|
if (str_map_find (&g.coders, type))
|
||||||
luaL_error (L, "a coder has already been registered for `%s'", type);
|
luaL_error (L, "a coder has already been registered for `%s'", type);
|
||||||
|
|
||||||
(void) app_lua_getfield (L, 1, "detect", LUA_TFUNCTION, true);
|
(void) app_lua_getfield (L, 1, "detect", LUA_TFUNCTION, true);
|
||||||
|
@ -849,7 +849,7 @@ app_lua_register (lua_State *L)
|
||||||
struct app_lua_coder *coder = xcalloc (1, sizeof *coder);
|
struct app_lua_coder *coder = xcalloc (1, sizeof *coder);
|
||||||
coder->ref_decode = luaL_ref (L, LUA_REGISTRYINDEX);
|
coder->ref_decode = luaL_ref (L, LUA_REGISTRYINDEX);
|
||||||
coder->ref_detect = luaL_ref (L, LUA_REGISTRYINDEX);
|
coder->ref_detect = luaL_ref (L, LUA_REGISTRYINDEX);
|
||||||
str_map_set (&g_ctx.coders, type, coder);
|
str_map_set (&g.coders, type, coder);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -973,12 +973,12 @@ app_lua_mark (int64_t offset, int64_t len, const char *desc)
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ARRAY_RESERVE (g_ctx.marks, 1);
|
ARRAY_RESERVE (g.marks, 1);
|
||||||
g_ctx.marks[g_ctx.marks_len++] =
|
g.marks[g.marks_len++] =
|
||||||
(struct mark) { offset, len, g_ctx.mark_strings.len };
|
(struct mark) { offset, len, g.mark_strings.len };
|
||||||
|
|
||||||
str_append (&g_ctx.mark_strings, desc);
|
str_append (&g.mark_strings, desc);
|
||||||
str_append_c (&g_ctx.mark_strings, 0);
|
str_append_c (&g.mark_strings, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -986,7 +986,7 @@ app_lua_chunk_mark (lua_State *L)
|
||||||
{
|
{
|
||||||
struct app_lua_chunk *self = luaL_checkudata (L, 1, XLUA_CHUNK_METATABLE);
|
struct app_lua_chunk *self = luaL_checkudata (L, 1, XLUA_CHUNK_METATABLE);
|
||||||
int n_args = lua_gettop (L);
|
int n_args = lua_gettop (L);
|
||||||
lua_rawgeti (L, LUA_REGISTRYINDEX, g_ctx.ref_format);
|
lua_rawgeti (L, LUA_REGISTRYINDEX, g.ref_format);
|
||||||
lua_insert (L, 2);
|
lua_insert (L, 2);
|
||||||
lua_call (L, n_args - 1, 1);
|
lua_call (L, n_args - 1, 1);
|
||||||
app_lua_mark (self->offset, self->len, luaL_checkstring (L, -1));
|
app_lua_mark (self->offset, self->len, luaL_checkstring (L, -1));
|
||||||
|
@ -999,7 +999,7 @@ app_lua_chunk_identify (lua_State *L)
|
||||||
{
|
{
|
||||||
(void) luaL_checkudata (L, 1, XLUA_CHUNK_METATABLE);
|
(void) luaL_checkudata (L, 1, XLUA_CHUNK_METATABLE);
|
||||||
|
|
||||||
struct str_map_iter iter = str_map_iter_make (&g_ctx.coders);
|
struct str_map_iter iter = str_map_iter_make (&g.coders);
|
||||||
struct app_lua_coder *coder;
|
struct app_lua_coder *coder;
|
||||||
while ((coder = str_map_iter_next (&iter)))
|
while ((coder = str_map_iter_next (&iter)))
|
||||||
{
|
{
|
||||||
|
@ -1045,7 +1045,7 @@ app_lua_chunk_decode (lua_State *L)
|
||||||
// While we could call "detect" here, just to be sure, some kinds may not
|
// While we could call "detect" here, just to be sure, some kinds may not
|
||||||
// even be detectable and it's better to leave it up to the plugin
|
// even be detectable and it's better to leave it up to the plugin
|
||||||
|
|
||||||
struct app_lua_coder *coder = str_map_find (&g_ctx.coders, type);
|
struct app_lua_coder *coder = str_map_find (&g.coders, type);
|
||||||
if (!coder)
|
if (!coder)
|
||||||
return luaL_error (L, "unknown type: %s", type);
|
return luaL_error (L, "unknown type: %s", type);
|
||||||
|
|
||||||
|
@ -1067,10 +1067,10 @@ app_lua_chunk_read (lua_State *L)
|
||||||
|
|
||||||
int64_t start = self->offset + self->position;
|
int64_t start = self->offset + self->position;
|
||||||
// XXX: or just return a shorter string in this case?
|
// XXX: or just return a shorter string in this case?
|
||||||
if (start + len > g_ctx.data_offset + g_ctx.data_len)
|
if (start + len > g.data_offset + g.data_len)
|
||||||
return luaL_argerror (L, 2, "chunk is too short");
|
return luaL_argerror (L, 2, "chunk is too short");
|
||||||
|
|
||||||
lua_pushlstring (L, (char *) g_ctx.data + (start - g_ctx.data_offset), len);
|
lua_pushlstring (L, (char *) g.data + (start - g.data_offset), len);
|
||||||
self->position += len;
|
self->position += len;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1092,7 +1092,7 @@ app_lua_chunk_finish_read
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare <string.format>, <format>, <value>
|
// Prepare <string.format>, <format>, <value>
|
||||||
lua_rawgeti (L, LUA_REGISTRYINDEX, g_ctx.ref_format);
|
lua_rawgeti (L, LUA_REGISTRYINDEX, g.ref_format);
|
||||||
lua_pushvalue (L, 2);
|
lua_pushvalue (L, 2);
|
||||||
|
|
||||||
int pre_filter_top = lua_gettop (L);
|
int pre_filter_top = lua_gettop (L);
|
||||||
|
@ -1129,7 +1129,7 @@ static int
|
||||||
app_lua_chunk_cstring (lua_State *L)
|
app_lua_chunk_cstring (lua_State *L)
|
||||||
{
|
{
|
||||||
struct app_lua_chunk *self = luaL_checkudata (L, 1, XLUA_CHUNK_METATABLE);
|
struct app_lua_chunk *self = luaL_checkudata (L, 1, XLUA_CHUNK_METATABLE);
|
||||||
void *s = g_ctx.data + (self->offset - g_ctx.data_offset) + self->position;
|
void *s = g.data + (self->offset - g.data_offset) + self->position;
|
||||||
|
|
||||||
void *nil;
|
void *nil;
|
||||||
if (!(nil = memchr (s, '\0', self->len - self->position)))
|
if (!(nil = memchr (s, '\0', self->len - self->position)))
|
||||||
|
@ -1147,7 +1147,7 @@ app_lua_chunk_decode_int (lua_State *L, struct app_lua_chunk *self, size_t len)
|
||||||
if (self->position + (int64_t) len > self->len)
|
if (self->position + (int64_t) len > self->len)
|
||||||
return luaL_error (L, "unexpected EOF");
|
return luaL_error (L, "unexpected EOF");
|
||||||
|
|
||||||
void *s = g_ctx.data + (self->offset - g_ctx.data_offset) + self->position;
|
void *s = g.data + (self->offset - g.data_offset) + self->position;
|
||||||
return app_decode (s, len, self->endianity);
|
return app_decode (s, len, self->endianity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1213,11 +1213,11 @@ app_lua_load_plugins (const char *plugin_dir)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char *path = xstrdup_printf ("%s/%s", plugin_dir, iter->d_name);
|
char *path = xstrdup_printf ("%s/%s", plugin_dir, iter->d_name);
|
||||||
lua_pushcfunction (g_ctx.L, app_lua_error_handler);
|
lua_pushcfunction (g.L, app_lua_error_handler);
|
||||||
if (luaL_loadfile (g_ctx.L, path)
|
if (luaL_loadfile (g.L, path)
|
||||||
|| lua_pcall (g_ctx.L, 0, 0, -2))
|
|| lua_pcall (g.L, 0, 0, -2))
|
||||||
exit_fatal ("Lua: %s", lua_tostring (g_ctx.L, -1));
|
exit_fatal ("Lua: %s", lua_tostring (g.L, -1));
|
||||||
lua_pop (g_ctx.L, 1);
|
lua_pop (g.L, 1);
|
||||||
free (path);
|
free (path);
|
||||||
}
|
}
|
||||||
if (errno)
|
if (errno)
|
||||||
|
@ -1228,26 +1228,26 @@ app_lua_load_plugins (const char *plugin_dir)
|
||||||
static void
|
static void
|
||||||
app_lua_init (void)
|
app_lua_init (void)
|
||||||
{
|
{
|
||||||
if (!(g_ctx.L = lua_newstate (app_lua_alloc, NULL)))
|
if (!(g.L = lua_newstate (app_lua_alloc, NULL)))
|
||||||
exit_fatal ("Lua initialization failed");
|
exit_fatal ("Lua initialization failed");
|
||||||
|
|
||||||
g_ctx.coders = str_map_make (app_lua_coder_free);
|
g.coders = str_map_make (app_lua_coder_free);
|
||||||
|
|
||||||
lua_atpanic (g_ctx.L, app_lua_panic);
|
lua_atpanic (g.L, app_lua_panic);
|
||||||
luaL_openlibs (g_ctx.L);
|
luaL_openlibs (g.L);
|
||||||
luaL_checkversion (g_ctx.L);
|
luaL_checkversion (g.L);
|
||||||
|
|
||||||
// I don't want to reimplement this and the C function is not exported
|
// I don't want to reimplement this and the C function is not exported
|
||||||
hard_assert (lua_getglobal (g_ctx.L, LUA_STRLIBNAME));
|
hard_assert (lua_getglobal (g.L, LUA_STRLIBNAME));
|
||||||
hard_assert (lua_getfield (g_ctx.L, -1, "format"));
|
hard_assert (lua_getfield (g.L, -1, "format"));
|
||||||
g_ctx.ref_format = luaL_ref (g_ctx.L, LUA_REGISTRYINDEX);
|
g.ref_format = luaL_ref (g.L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
luaL_newlib (g_ctx.L, app_lua_library);
|
luaL_newlib (g.L, app_lua_library);
|
||||||
lua_setglobal (g_ctx.L, PROGRAM_NAME);
|
lua_setglobal (g.L, PROGRAM_NAME);
|
||||||
|
|
||||||
luaL_newmetatable (g_ctx.L, XLUA_CHUNK_METATABLE);
|
luaL_newmetatable (g.L, XLUA_CHUNK_METATABLE);
|
||||||
luaL_setfuncs (g_ctx.L, app_lua_chunk_table, 0);
|
luaL_setfuncs (g.L, app_lua_chunk_table, 0);
|
||||||
lua_pop (g_ctx.L, 1);
|
lua_pop (g.L, 1);
|
||||||
|
|
||||||
struct strv v = strv_make ();
|
struct strv v = strv_make ();
|
||||||
get_xdg_data_dirs (&v);
|
get_xdg_data_dirs (&v);
|
||||||
|
@ -1269,24 +1269,24 @@ app_lua_init (void)
|
||||||
static bool
|
static bool
|
||||||
app_fix_view_range (void)
|
app_fix_view_range (void)
|
||||||
{
|
{
|
||||||
int64_t data_view_start = g_ctx.data_offset / ROW_SIZE * ROW_SIZE;
|
int64_t data_view_start = g.data_offset / ROW_SIZE * ROW_SIZE;
|
||||||
if (g_ctx.view_top < data_view_start)
|
if (g.view_top < data_view_start)
|
||||||
{
|
{
|
||||||
g_ctx.view_top = data_view_start;
|
g.view_top = data_view_start;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the contents are at least as long as the screen, always fill it
|
// If the contents are at least as long as the screen, always fill it
|
||||||
int64_t last_byte = g_ctx.data_offset + g_ctx.data_len - 1;
|
int64_t last_byte = g.data_offset + g.data_len - 1;
|
||||||
int64_t max_view_top =
|
int64_t max_view_top =
|
||||||
(last_byte / ROW_SIZE - app_visible_rows () + 1) * ROW_SIZE;
|
(last_byte / ROW_SIZE - app_visible_rows () + 1) * ROW_SIZE;
|
||||||
// But don't let that suggest a negative offset
|
// But don't let that suggest a negative offset
|
||||||
max_view_top = MAX (max_view_top, 0);
|
max_view_top = MAX (max_view_top, 0);
|
||||||
|
|
||||||
if (g_ctx.view_top > max_view_top)
|
if (g.view_top > max_view_top)
|
||||||
{
|
{
|
||||||
g_ctx.view_top = max_view_top;
|
g.view_top = max_view_top;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1297,7 +1297,7 @@ app_fix_view_range (void)
|
||||||
static bool
|
static bool
|
||||||
app_scroll (int n)
|
app_scroll (int n)
|
||||||
{
|
{
|
||||||
g_ctx.view_top += n * ROW_SIZE;
|
g.view_top += n * ROW_SIZE;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
return app_fix_view_range ();
|
return app_fix_view_range ();
|
||||||
}
|
}
|
||||||
|
@ -1305,11 +1305,11 @@ app_scroll (int n)
|
||||||
static void
|
static void
|
||||||
app_ensure_selection_visible (void)
|
app_ensure_selection_visible (void)
|
||||||
{
|
{
|
||||||
int too_high = g_ctx.view_top / ROW_SIZE - g_ctx.view_cursor / ROW_SIZE;
|
int too_high = g.view_top / ROW_SIZE - g.view_cursor / ROW_SIZE;
|
||||||
if (too_high > 0)
|
if (too_high > 0)
|
||||||
app_scroll (-too_high);
|
app_scroll (-too_high);
|
||||||
|
|
||||||
int too_low = g_ctx.view_cursor / ROW_SIZE - g_ctx.view_top / ROW_SIZE
|
int too_low = g.view_cursor / ROW_SIZE - g.view_top / ROW_SIZE
|
||||||
- app_visible_rows () + 1;
|
- app_visible_rows () + 1;
|
||||||
if (too_low > 0)
|
if (too_low > 0)
|
||||||
app_scroll (too_low);
|
app_scroll (too_low);
|
||||||
|
@ -1319,12 +1319,12 @@ static bool
|
||||||
app_move_cursor_by_rows (int diff)
|
app_move_cursor_by_rows (int diff)
|
||||||
{
|
{
|
||||||
// TODO: disallow partial up/down movement
|
// TODO: disallow partial up/down movement
|
||||||
int64_t fixed = g_ctx.view_cursor += diff * ROW_SIZE;
|
int64_t fixed = g.view_cursor += diff * ROW_SIZE;
|
||||||
fixed = MAX (fixed, g_ctx.data_offset);
|
fixed = MAX (fixed, g.data_offset);
|
||||||
fixed = MIN (fixed, g_ctx.data_offset + g_ctx.data_len - 1);
|
fixed = MIN (fixed, g.data_offset + g.data_len - 1);
|
||||||
|
|
||||||
bool result = g_ctx.view_cursor == fixed;
|
bool result = g.view_cursor == fixed;
|
||||||
g_ctx.view_cursor = fixed;
|
g.view_cursor = fixed;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
|
|
||||||
app_ensure_selection_visible ();
|
app_ensure_selection_visible ();
|
||||||
|
@ -1334,11 +1334,11 @@ app_move_cursor_by_rows (int diff)
|
||||||
static bool
|
static bool
|
||||||
app_jump_to_marks (ssize_t i)
|
app_jump_to_marks (ssize_t i)
|
||||||
{
|
{
|
||||||
if (i < 0 || (size_t) i >= g_ctx.marks_by_offset_len)
|
if (i < 0 || (size_t) i >= g.marks_by_offset_len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_ctx.view_cursor = g_ctx.marks_by_offset[i].offset;
|
g.view_cursor = g.marks_by_offset[i].offset;
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
app_ensure_selection_visible ();
|
app_ensure_selection_visible ();
|
||||||
return true;
|
return true;
|
||||||
|
@ -1372,17 +1372,17 @@ app_process_action (enum action action)
|
||||||
case ACTION_SCROLL_DOWN: app_scroll (1); break;
|
case ACTION_SCROLL_DOWN: app_scroll (1); break;
|
||||||
|
|
||||||
case ACTION_GOTO_TOP:
|
case ACTION_GOTO_TOP:
|
||||||
g_ctx.view_cursor = g_ctx.data_offset;
|
g.view_cursor = g.data_offset;
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
app_ensure_selection_visible ();
|
app_ensure_selection_visible ();
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
break;
|
break;
|
||||||
case ACTION_GOTO_BOTTOM:
|
case ACTION_GOTO_BOTTOM:
|
||||||
if (!g_ctx.data_len)
|
if (!g.data_len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_ctx.view_cursor = g_ctx.data_offset + g_ctx.data_len - 1;
|
g.view_cursor = g.data_offset + g.data_len - 1;
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
app_ensure_selection_visible ();
|
app_ensure_selection_visible ();
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
break;
|
break;
|
||||||
|
@ -1400,29 +1400,29 @@ app_process_action (enum action action)
|
||||||
case ACTION_DOWN: app_move_cursor_by_rows (1); break;
|
case ACTION_DOWN: app_move_cursor_by_rows (1); break;
|
||||||
|
|
||||||
case ACTION_LEFT:
|
case ACTION_LEFT:
|
||||||
if (g_ctx.view_skip_nibble)
|
if (g.view_skip_nibble)
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (g_ctx.view_cursor <= g_ctx.data_offset)
|
if (g.view_cursor <= g.data_offset)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_ctx.view_skip_nibble = true;
|
g.view_skip_nibble = true;
|
||||||
g_ctx.view_cursor--;
|
g.view_cursor--;
|
||||||
app_ensure_selection_visible ();
|
app_ensure_selection_visible ();
|
||||||
}
|
}
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
break;
|
break;
|
||||||
case ACTION_RIGHT:
|
case ACTION_RIGHT:
|
||||||
if (!g_ctx.view_skip_nibble)
|
if (!g.view_skip_nibble)
|
||||||
g_ctx.view_skip_nibble = true;
|
g.view_skip_nibble = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (g_ctx.view_cursor >= g_ctx.data_offset + g_ctx.data_len - 1)
|
if (g.view_cursor >= g.data_offset + g.data_len - 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
g_ctx.view_cursor++;
|
g.view_cursor++;
|
||||||
app_ensure_selection_visible ();
|
app_ensure_selection_visible ();
|
||||||
}
|
}
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
|
@ -1430,37 +1430,37 @@ app_process_action (enum action action)
|
||||||
|
|
||||||
case ACTION_ROW_START:
|
case ACTION_ROW_START:
|
||||||
{
|
{
|
||||||
int64_t new = g_ctx.view_cursor / ROW_SIZE * ROW_SIZE;
|
int64_t new = g.view_cursor / ROW_SIZE * ROW_SIZE;
|
||||||
new = MAX (new, g_ctx.data_offset);
|
new = MAX (new, g.data_offset);
|
||||||
new = MIN (new, g_ctx.data_offset + g_ctx.data_len - 1);
|
new = MIN (new, g.data_offset + g.data_len - 1);
|
||||||
|
|
||||||
g_ctx.view_cursor = new;
|
g.view_cursor = new;
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_ROW_END:
|
case ACTION_ROW_END:
|
||||||
{
|
{
|
||||||
int64_t new = (g_ctx.view_cursor / ROW_SIZE + 1) * ROW_SIZE - 1;
|
int64_t new = (g.view_cursor / ROW_SIZE + 1) * ROW_SIZE - 1;
|
||||||
new = MAX (new, g_ctx.data_offset);
|
new = MAX (new, g.data_offset);
|
||||||
new = MIN (new, g_ctx.data_offset + g_ctx.data_len - 1);
|
new = MIN (new, g.data_offset + g.data_len - 1);
|
||||||
|
|
||||||
g_ctx.view_cursor = new;
|
g.view_cursor = new;
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ACTION_FIELD_PREVIOUS:
|
case ACTION_FIELD_PREVIOUS:
|
||||||
{
|
{
|
||||||
ssize_t i = app_find_marks (g_ctx.view_cursor);
|
ssize_t i = app_find_marks (g.view_cursor);
|
||||||
if (i >= 0 && (size_t) i < g_ctx.marks_by_offset_len
|
if (i >= 0 && (size_t) i < g.marks_by_offset_len
|
||||||
&& g_ctx.marks_by_offset[i].offset == g_ctx.view_cursor)
|
&& g.marks_by_offset[i].offset == g.view_cursor)
|
||||||
i--;
|
i--;
|
||||||
return app_jump_to_marks (i);
|
return app_jump_to_marks (i);
|
||||||
}
|
}
|
||||||
case ACTION_FIELD_NEXT:
|
case ACTION_FIELD_NEXT:
|
||||||
return app_jump_to_marks (app_find_marks (g_ctx.view_cursor) + 1);
|
return app_jump_to_marks (app_find_marks (g.view_cursor) + 1);
|
||||||
|
|
||||||
case ACTION_QUIT:
|
case ACTION_QUIT:
|
||||||
app_quit ();
|
app_quit ();
|
||||||
|
@ -1472,7 +1472,7 @@ app_process_action (enum action action)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_TOGGLE_ENDIANITY:
|
case ACTION_TOGGLE_ENDIANITY:
|
||||||
g_ctx.endianity = (g_ctx.endianity == ENDIANITY_LE)
|
g.endianity = (g.endianity == ENDIANITY_LE)
|
||||||
? ENDIANITY_BE : ENDIANITY_LE;
|
? ENDIANITY_BE : ENDIANITY_LE;
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
break;
|
break;
|
||||||
|
@ -1491,23 +1491,23 @@ app_process_left_mouse_click (struct widget *w, int x, int y)
|
||||||
return app_process_action (ACTION_TOGGLE_ENDIANITY);
|
return app_process_action (ACTION_TOGGLE_ENDIANITY);
|
||||||
|
|
||||||
// XXX: This is really ugly.
|
// XXX: This is really ugly.
|
||||||
x = x / g_ctx.digitw - 2;
|
x = x / g.digitw - 2;
|
||||||
y = w->userdata;
|
y = w->userdata;
|
||||||
switch (w->id)
|
switch (w->id)
|
||||||
{
|
{
|
||||||
case WIDGET_HEX:
|
case WIDGET_HEX:
|
||||||
x -= x/5 + x/21;
|
x -= x/5 + x/21;
|
||||||
g_ctx.view_skip_nibble = x % 2;
|
g.view_skip_nibble = x % 2;
|
||||||
x /= 2;
|
x /= 2;
|
||||||
break;
|
break;
|
||||||
case WIDGET_ASCII:
|
case WIDGET_ASCII:
|
||||||
g_ctx.view_skip_nibble = false;
|
g.view_skip_nibble = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ctx.view_cursor = g_ctx.view_top + y * ROW_SIZE + x;
|
g.view_cursor = g.view_top + y * ROW_SIZE + x;
|
||||||
return app_move_cursor_by_rows (0);
|
return app_move_cursor_by_rows (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1729,19 +1729,19 @@ app_on_signal_pipe_readable (const struct pollfd *fd, void *user_data)
|
||||||
static void
|
static void
|
||||||
app_show_message (char *message)
|
app_show_message (char *message)
|
||||||
{
|
{
|
||||||
cstr_set (&g_ctx.message, message);
|
cstr_set (&g.message, message);
|
||||||
poller_timer_set (&g_ctx.message_timer, 5000);
|
poller_timer_set (&g.message_timer, 5000);
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
app_hide_message (void)
|
app_hide_message (void)
|
||||||
{
|
{
|
||||||
if (!g_ctx.message)
|
if (!g.message)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cstr_set (&g_ctx.message, NULL);
|
cstr_set (&g.message, NULL);
|
||||||
poller_timer_reset (&g_ctx.message_timer);
|
poller_timer_reset (&g.message_timer);
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1791,12 +1791,12 @@ app_on_clipboard_copy (const char *text)
|
||||||
static void
|
static void
|
||||||
app_init_poller_events (void)
|
app_init_poller_events (void)
|
||||||
{
|
{
|
||||||
g_ctx.signal_event = poller_fd_make (&g_ctx.poller, g_signal_pipe[0]);
|
g.signal_event = poller_fd_make (&g.poller, g_signal_pipe[0]);
|
||||||
g_ctx.signal_event.dispatcher = app_on_signal_pipe_readable;
|
g.signal_event.dispatcher = app_on_signal_pipe_readable;
|
||||||
poller_fd_set (&g_ctx.signal_event, POLLIN);
|
poller_fd_set (&g.signal_event, POLLIN);
|
||||||
|
|
||||||
g_ctx.message_timer = poller_timer_make (&g_ctx.poller);
|
g.message_timer = poller_timer_make (&g.poller);
|
||||||
g_ctx.message_timer.dispatcher = app_on_message_timer;
|
g.message_timer.dispatcher = app_on_message_timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -1874,7 +1874,7 @@ main (int argc, char *argv[])
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
if (!decode_size (optarg, &g_ctx.data_offset))
|
if (!decode_size (optarg, &g.data_offset))
|
||||||
exit_fatal ("invalid offset specified");
|
exit_fatal ("invalid offset specified");
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -1900,7 +1900,7 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
if (forced_type && !strcmp (forced_type, "list"))
|
if (forced_type && !strcmp (forced_type, "list"))
|
||||||
{
|
{
|
||||||
struct str_map_iter iter = str_map_iter_make (&g_ctx.coders);
|
struct str_map_iter iter = str_map_iter_make (&g.coders);
|
||||||
while (str_map_iter_next (&iter))
|
while (str_map_iter_next (&iter))
|
||||||
puts (iter.link->key);
|
puts (iter.link->key);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
|
@ -1919,7 +1919,7 @@ main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else if (argc == 1)
|
else if (argc == 1)
|
||||||
{
|
{
|
||||||
g_ctx.filename = xstrdup (argv[0]);
|
g.filename = xstrdup (argv[0]);
|
||||||
if ((input_fd = open (argv[0], O_RDONLY)) < 0)
|
if ((input_fd = open (argv[0], O_RDONLY)) < 0)
|
||||||
exit_fatal ("cannot open `%s': %s", argv[0], strerror (errno));
|
exit_fatal ("cannot open `%s': %s", argv[0], strerror (errno));
|
||||||
}
|
}
|
||||||
|
@ -1932,8 +1932,8 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
// Seek in the file or pipe however we can
|
// Seek in the file or pipe however we can
|
||||||
static char seek_buf[8192];
|
static char seek_buf[8192];
|
||||||
if (lseek (input_fd, g_ctx.data_offset, SEEK_SET) == (off_t) -1)
|
if (lseek (input_fd, g.data_offset, SEEK_SET) == (off_t) -1)
|
||||||
for (uint64_t remaining = g_ctx.data_offset; remaining; )
|
for (uint64_t remaining = g.data_offset; remaining; )
|
||||||
{
|
{
|
||||||
ssize_t n_read = read (input_fd,
|
ssize_t n_read = read (input_fd,
|
||||||
seek_buf, MIN (remaining, sizeof seek_buf));
|
seek_buf, MIN (remaining, sizeof seek_buf));
|
||||||
|
@ -1956,11 +1956,11 @@ main (int argc, char *argv[])
|
||||||
buf.len += n_read;
|
buf.len += n_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ctx.data = (uint8_t *) buf.str;
|
g.data = (uint8_t *) buf.str;
|
||||||
g_ctx.data_len = buf.len;
|
g.data_len = buf.len;
|
||||||
|
|
||||||
g_ctx.view_top = g_ctx.data_offset / ROW_SIZE * ROW_SIZE;
|
g.view_top = g.data_offset / ROW_SIZE * ROW_SIZE;
|
||||||
g_ctx.view_cursor = g_ctx.data_offset;
|
g.view_cursor = g.data_offset;
|
||||||
|
|
||||||
// We only need to convert to and from the terminal encoding
|
// We only need to convert to and from the terminal encoding
|
||||||
if (!setlocale (LC_CTYPE, ""))
|
if (!setlocale (LC_CTYPE, ""))
|
||||||
|
@ -1971,21 +1971,21 @@ main (int argc, char *argv[])
|
||||||
// TODO: eventually we should do this in a separate thread after load
|
// TODO: eventually we should do this in a separate thread after load
|
||||||
// as it may take a long time (-> responsivity) and once we allow the user
|
// as it may take a long time (-> responsivity) and once we allow the user
|
||||||
// to edit the file, each change will need a background rescan
|
// to edit the file, each change will need a background rescan
|
||||||
lua_pushcfunction (g_ctx.L, app_lua_error_handler);
|
lua_pushcfunction (g.L, app_lua_error_handler);
|
||||||
lua_pushcfunction (g_ctx.L, app_lua_chunk_decode);
|
lua_pushcfunction (g.L, app_lua_chunk_decode);
|
||||||
|
|
||||||
struct app_lua_chunk *chunk = app_lua_chunk_new (g_ctx.L);
|
struct app_lua_chunk *chunk = app_lua_chunk_new (g.L);
|
||||||
chunk->offset = g_ctx.data_offset;
|
chunk->offset = g.data_offset;
|
||||||
chunk->len = g_ctx.data_len;
|
chunk->len = g.data_len;
|
||||||
|
|
||||||
if (forced_type)
|
if (forced_type)
|
||||||
lua_pushstring (g_ctx.L, forced_type);
|
lua_pushstring (g.L, forced_type);
|
||||||
else
|
else
|
||||||
lua_pushnil (g_ctx.L);
|
lua_pushnil (g.L);
|
||||||
if (lua_pcall (g_ctx.L, 2, 0, -4))
|
if (lua_pcall (g.L, 2, 0, -4))
|
||||||
exit_fatal ("Lua: decoding failed: %s", lua_tostring (g_ctx.L, -1));
|
exit_fatal ("Lua: decoding failed: %s", lua_tostring (g.L, -1));
|
||||||
|
|
||||||
lua_pop (g_ctx.L, 1);
|
lua_pop (g.L, 1);
|
||||||
#endif // WITH_LUA
|
#endif // WITH_LUA
|
||||||
app_flatten_marks ();
|
app_flatten_marks ();
|
||||||
|
|
||||||
|
@ -1995,28 +1995,28 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
xui_preinit ();
|
xui_preinit ();
|
||||||
app_init_bindings ();
|
app_init_bindings ();
|
||||||
xui_start (&g_ctx.poller,
|
xui_start (&g.poller,
|
||||||
requested_x11, g_ctx.attrs, N_ELEMENTS (g_ctx.attrs));
|
requested_x11, g.attrs, N_ELEMENTS (g.attrs));
|
||||||
xui_invalidate ();
|
xui_invalidate ();
|
||||||
|
|
||||||
struct widget *w = g_xui.ui->label (0, XUI_ATTR_MONOSPACE, "8");
|
struct widget *w = g_xui.ui->label (0, XUI_ATTR_MONOSPACE, "8");
|
||||||
g_ctx.digitw = w->width;
|
g.digitw = w->width;
|
||||||
widget_destroy (w);
|
widget_destroy (w);
|
||||||
|
|
||||||
// Redirect all messages from liberty so that they don't disrupt display
|
// Redirect all messages from liberty so that they don't disrupt display
|
||||||
g_log_message_real = app_log_handler;
|
g_log_message_real = app_log_handler;
|
||||||
|
|
||||||
g_ctx.polling = true;
|
g.polling = true;
|
||||||
while (g_ctx.polling)
|
while (g.polling)
|
||||||
poller_run (&g_ctx.poller);
|
poller_run (&g.poller);
|
||||||
|
|
||||||
xui_stop ();
|
xui_stop ();
|
||||||
g_log_message_real = log_message_stdio;
|
g_log_message_real = log_message_stdio;
|
||||||
app_free_context ();
|
app_free_context ();
|
||||||
|
|
||||||
#ifdef WITH_LUA
|
#ifdef WITH_LUA
|
||||||
str_map_free (&g_ctx.coders);
|
str_map_free (&g.coders);
|
||||||
lua_close (g_ctx.L);
|
lua_close (g.L);
|
||||||
#endif // WITH_LUA
|
#endif // WITH_LUA
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue