Skip to content

Commit

Permalink
Collapse bit loop into color loop and reduce color scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazula authored and trufae committed Apr 16, 2022
1 parent 2a7b9db commit 9540cb5
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions libr/core/cmd_cmp.c
Expand Up @@ -811,7 +811,6 @@ static int cmd_cp(void *data, const char *input) {
static void cmp_bits(RCore *core, ut64 addr) {
RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal;
const bool use_color = r_config_get_b (core->config, "scr.color");
const char *color = use_color? pal->offset: "";
const char *color_end = use_color? Color_RESET: "";
int i;
ut8 a, b;
Expand All @@ -821,22 +820,20 @@ static void cmp_bits(RCore *core, ut64 addr) {
r_io_nread_at (core->io, core->offset, &a, 1);
r_io_nread_at (core->io, addr, &b, 1);

/* Set up bits and colors */
for (i = 7; i >= 0; i--) {
a_bits[i] = a & 1<<i;
b_bits[i] = b & 1<<i;
}

/* Print offset header if enabled */
if (r_config_get_i (core->config, "hex.header")) {
char *n = r_str_newf ("0x%08"PFMT64x, core->offset);
const char *extra = r_str_pad (' ', strlen (n) - 10);
const char *color = use_color? pal->offset: "";
char *n = r_str_newf ("0x%08" PFMT64x, core->offset);
const char *padding = r_str_pad (' ', strlen (n) - 10);
free (n);
r_cons_printf ("%s- offset -%s 7 6 5 4 3 2 1 0%s\n", color, extra, color_end);
r_cons_printf ("%s- offset -%s 7 6 5 4 3 2 1 0%s\n", color, padding, color_end);
}

color = use_color? pal->graph_false: "";
/* Set up bits and colors */
for (i = 7; i >= 0; i--) {
a_bits[i] = a & (1 << i);
b_bits[i] = b & (1 << i);

if (use_color && a_bits[i] != b_bits[i]) {
a_colors[i] = a_bits[i]? pal->graph_true: pal->graph_false;
b_colors[i] = b_bits[i]? pal->graph_true: pal->graph_false;
Expand Down

0 comments on commit 9540cb5

Please sign in to comment.