Skip to content

Commit

Permalink
Enhance @@ foreach operator
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed May 13, 2017
1 parent 02fa7b9 commit 842623c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
57 changes: 39 additions & 18 deletions libr/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2346,37 +2346,58 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) {
return 0;
}

static void foreachOffset (RCore *core, const char *cmd, const char *each) {
char *str = strdup (cmd);
static void foreachOffset (RCore *core, const char *_cmd, const char *each) {
char *cmd = strdup (_cmd);
char *str = cmd;
char *nextLine = NULL;
ut64 addr;
/* foreach list of items */
do {
while (each) {
// skip spaces
while (*each == ' ') {
each++;
}
// stahp if empty string
if (!*each) {
break;
}
// find newline
char *nl = strchr (each, '\n');
if (nl) {
*nl = 0;
each = nl + 1;
}
str = strchr (each, ' ');
if (str) {
*str = '\0';
addr = r_num_math (core->num, each);
*str = ' ';
each = str + 1;
nextLine = nl + 1;
} else {
addr = r_num_math (core->num, each);
nextLine = NULL;
}
//eprintf ("; 0x%08"PFMT64x":\n", addr);
r_core_seek (core, addr, 1);
r_core_cmd (core, cmd, 0);
r_cons_flush ();
} while (str != NULL);
free (str);
// chop comment in line
nl = strchr (each, '#');
if (nl) {
*nl = 0;
}
// space separated numbers
while (each && *each) {
// find spaces
while (*each== ' ') each++;
str = strchr (each, ' ');
if (str) {
*str = '\0';
addr = r_num_math (core->num, each);
*str = ' ';
each = str + 1;
} else {
if (!*each) {
break;
}
addr = r_num_math (core->num, each);
each = NULL;
}
r_core_seek (core, addr, 1);
r_core_cmd (core, cmd, 0);
r_cons_flush ();
}
each = nextLine;
}
free (cmd);
}

R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
Expand Down
7 changes: 4 additions & 3 deletions libr/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,15 +1050,16 @@ static void ds_print_show_cursor(RDisasmState *ds) {
RCore *core = ds->core;
char res[] = " ";
void *p;
int q, t;
if (!ds->show_marks) {
return;
}
q = core->print->cur_enabled &&
int q = core->print->cur_enabled &&
ds->cursor >= ds->index &&
ds->cursor < (ds->index + ds->asmop.size);
p = r_bp_get_at (core->dbg->bp, ds->at);
t = ds->midflags && handleMidFlags (core, ds, false) > 0;
if (ds->midflags) {
(void)handleMidFlags (core, ds, false);
}
if (p) {
res[0] = 'b';
}
Expand Down

0 comments on commit 842623c

Please sign in to comment.