mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-26 22:50:48 +00:00
Fix #23588 - remove empty lines when sorting and add grep+end test ##cons
This commit is contained in:
parent
f72f3e0f63
commit
41b9e74305
@ -178,7 +178,7 @@ R_API void r_cons_grep_expression(const char *str) {
|
||||
case '{':
|
||||
if (ptr[1] == ':') {
|
||||
grep->human = true; // human friendly indentation ij~{:
|
||||
grep->json = 1;
|
||||
grep->json = true;
|
||||
if (r_str_startswith (ptr, "{:...")) {
|
||||
grep->hud = true;
|
||||
} else if (r_str_startswith (ptr, "{:..")) {
|
||||
@ -189,7 +189,7 @@ R_API void r_cons_grep_expression(const char *str) {
|
||||
ptr += 2;
|
||||
} else if (ptr[1] == '}') {
|
||||
// standard json indentation
|
||||
grep->json = 1;
|
||||
grep->json = true;
|
||||
if (r_str_startswith (ptr, "{}...")) {
|
||||
grep->hud = true;
|
||||
} else if (r_str_startswith (ptr, "{}..")) {
|
||||
@ -202,7 +202,7 @@ R_API void r_cons_grep_expression(const char *str) {
|
||||
*jsonPathEnd = 0;
|
||||
free (grep->json_path);
|
||||
grep->json_path = jsonPath;
|
||||
grep->json = 1;
|
||||
grep->json = true;
|
||||
} else {
|
||||
free (jsonPath);
|
||||
}
|
||||
@ -367,16 +367,8 @@ R_API void r_cons_grep_expression(const char *str) {
|
||||
} else {
|
||||
*p = '\0';
|
||||
grep->range_line = 1;
|
||||
if (*token) {
|
||||
grep->f_line = r_num_get (cons->num, token);
|
||||
} else {
|
||||
grep->f_line = 0;
|
||||
}
|
||||
if (p[2]) {
|
||||
grep->l_line = r_num_get (cons->num, p + 2);
|
||||
} else {
|
||||
grep->l_line = 0;
|
||||
}
|
||||
grep->f_line = *token? r_num_get (cons->num, token): 0;
|
||||
grep->l_line = p[2]? r_num_get (cons->num, p + 2): 0;
|
||||
}
|
||||
}
|
||||
if (end_ptr) {
|
||||
@ -386,12 +378,7 @@ R_API void r_cons_grep_expression(const char *str) {
|
||||
len = strlen (ptr) - 1;
|
||||
if (len > 1 && ptr[len] == '$' && ptr[len - 1] != '\\') {
|
||||
#if R2_USE_NEW_ABI
|
||||
{
|
||||
RConsGrepWord *word = r_list_last (grep->strings);
|
||||
if (word) {
|
||||
word->end = true;
|
||||
}
|
||||
}
|
||||
gw_end = true;
|
||||
#else
|
||||
grep->end[i] = true;
|
||||
#endif
|
||||
@ -421,6 +408,7 @@ R_API void r_cons_grep_expression(const char *str) {
|
||||
gw->begin = gw_begin;
|
||||
gw->neg = gw_neg;
|
||||
gw->end = gw_end;
|
||||
gw_end = false;
|
||||
r_list_append (grep->strings, gw);
|
||||
#else
|
||||
if (wlen >= R_CONS_GREP_WORD_SIZE - 1) {
|
||||
@ -814,8 +802,8 @@ R_API void r_cons_grepbuf(void) {
|
||||
char *sbuf = strdup (cons->context->buffer);
|
||||
r_str_ansi_filter (sbuf, NULL, NULL, -1);
|
||||
char *out = r_str_ss (sbuf, NULL, 0);
|
||||
free (cons->context->buffer);
|
||||
free (sbuf);
|
||||
free (cons->context->buffer);
|
||||
cons->context->buffer = out;
|
||||
cons->context->buffer_len = strlen (out);
|
||||
cons->context->buffer_sz = cons->context->buffer_len;
|
||||
@ -823,8 +811,13 @@ R_API void r_cons_grepbuf(void) {
|
||||
}
|
||||
if (grep->zoom) {
|
||||
char *sin = calloc (cons->context->buffer_len + 2, 4);
|
||||
if (R_UNLIKELY (!sin)) {
|
||||
grep->zoom = 0;
|
||||
grep->zoomy = 0;
|
||||
return;
|
||||
}
|
||||
strcpy (sin, cons->context->buffer);
|
||||
char *out = r_str_scale (in, grep->zoom * 2, grep->zoomy?grep->zoomy:grep->zoom);
|
||||
char *out = r_str_scale (in, grep->zoom * 2, grep->zoomy? grep->zoomy: grep->zoom);
|
||||
if (out) {
|
||||
free (cons->context->buffer);
|
||||
cons->context->buffer = out;
|
||||
@ -870,7 +863,7 @@ R_API void r_cons_grepbuf(void) {
|
||||
cons->context->buffer = u;
|
||||
cons->context->buffer_len = strlen (u);
|
||||
cons->context->buffer_sz = cons->context->buffer_len + 1;
|
||||
grep->json = 0;
|
||||
grep->json = false;
|
||||
r_cons_newline ();
|
||||
}
|
||||
R_FREE (grep->json_path);
|
||||
@ -917,7 +910,6 @@ R_API void r_cons_grepbuf(void) {
|
||||
grep->nstrings--;
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
if (grep->hud) {
|
||||
grep->hud = false;
|
||||
r_cons_hud_string (cons->context->buffer);
|
||||
@ -928,7 +920,6 @@ R_API void r_cons_grepbuf(void) {
|
||||
r_cons_less_str (cons->context->buffer, NULL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if R2_USE_NEW_ABI
|
||||
if (r_list_empty (grep->strings)) {
|
||||
@ -1119,17 +1110,19 @@ continuation:
|
||||
}
|
||||
|
||||
if (grep->sort != -1 || grep->sort_invert) {
|
||||
#define INSERT_LINES(list)\
|
||||
if (list) {\
|
||||
r_list_foreach (list, iter, str) {\
|
||||
int slen = strlen (str);\
|
||||
memcpy (ptr, str, slen);\
|
||||
memcpy (ptr + slen, "\n", 2);\
|
||||
ptr += slen + 1;\
|
||||
nl++;\
|
||||
}\
|
||||
#define INSERT_LINES(list) \
|
||||
if (list) { \
|
||||
*ptr = 0; \
|
||||
r_list_foreach (list, iter, str) { \
|
||||
int slen = strlen (str); \
|
||||
if (slen > 0) { \
|
||||
memcpy (ptr, str, slen); \
|
||||
memcpy (ptr + slen, "\n", 2); \
|
||||
ptr += slen + 1; \
|
||||
} \
|
||||
nl++; \
|
||||
} \
|
||||
}
|
||||
|
||||
RListIter *iter;
|
||||
int nl = 0;
|
||||
char *ptr = cons->context->buffer;
|
||||
@ -1274,18 +1267,18 @@ R_API int r_cons_grep_line(char *buf, int len) {
|
||||
tok = r_str_tok_r (i? NULL: in, delims, &save_ptr);
|
||||
if (tok) {
|
||||
if (grep->tokens[i]) {
|
||||
int toklen = strlen (tok);
|
||||
const size_t toklen = strlen (tok);
|
||||
memcpy (out + outlen, tok, toklen);
|
||||
memcpy (out + outlen + toklen, " ", 2);
|
||||
outlen += toklen + 1;
|
||||
if (!(*out)) {
|
||||
if (*out == 0) {
|
||||
free (in);
|
||||
free (out);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((*out)) {
|
||||
if (*out) {
|
||||
break;
|
||||
}
|
||||
free (in);
|
||||
@ -1309,7 +1302,7 @@ R_API int r_cons_grep_line(char *buf, int len) {
|
||||
free (in);
|
||||
free (out);
|
||||
if (grep->sort_invert && grep->sort == -1) {
|
||||
char ch = buf[len];
|
||||
const char ch = buf[len];
|
||||
buf[len] = 0;
|
||||
if (!ctx->sorted_lines) {
|
||||
ctx->sorted_lines = r_list_newf (free);
|
||||
@ -1320,7 +1313,7 @@ R_API int r_cons_grep_line(char *buf, int len) {
|
||||
r_list_append (ctx->sorted_lines, strdup (buf));
|
||||
buf[len] = ch;
|
||||
} else if (grep->sort != -1) {
|
||||
char ch = buf[len];
|
||||
const char ch = buf[len];
|
||||
buf[len] = 0;
|
||||
if (!ctx->sorted_lines) {
|
||||
ctx->sorted_lines = r_list_newf (free);
|
||||
@ -1328,11 +1321,9 @@ R_API int r_cons_grep_line(char *buf, int len) {
|
||||
if (!ctx->unsorted_lines) {
|
||||
ctx->unsorted_lines = r_list_newf (free);
|
||||
}
|
||||
if (cons->lines >= grep->sort_row) {
|
||||
r_list_append (ctx->sorted_lines, strdup (buf));
|
||||
} else {
|
||||
r_list_append (ctx->unsorted_lines, strdup (buf));
|
||||
}
|
||||
RList *target = (cons->lines >= grep->sort_row)?
|
||||
ctx->sorted_lines: ctx->unsorted_lines;
|
||||
r_list_append (target, strdup (buf));
|
||||
buf[len] = ch;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ NAME=CL address
|
||||
FILE=bins/elf/dwarf3_line
|
||||
CMDS=CL~$$addr
|
||||
EXPECT=<<EOF
|
||||
|
||||
addr: 0x00001139
|
||||
addr: 0x00001141
|
||||
addr: 0x0000114a
|
||||
@ -34,7 +33,6 @@ NAME=CL dwarf5 address
|
||||
FILE=bins/elf/dwarf5_line
|
||||
CMDS=CL~$$addr
|
||||
EXPECT=<<EOF
|
||||
|
||||
addr: 0x00001139
|
||||
addr: 0x00001141
|
||||
addr: 0x0000114a
|
||||
@ -66,7 +64,6 @@ NAME=CL clang address
|
||||
FILE=bins/elf/dwarf3_line_cl
|
||||
CMDS=CL~$$addr
|
||||
EXPECT=<<EOF
|
||||
|
||||
addr: 0x00001140
|
||||
addr: 0x00001148
|
||||
addr: 0x0000114d
|
||||
@ -104,7 +101,6 @@ NAME=CL dwarf5 clang address
|
||||
FILE=bins/elf/dwarf5_line_cl
|
||||
CMDS=CL~$$addr
|
||||
EXPECT=<<EOF
|
||||
|
||||
addr: 0x00001140
|
||||
addr: 0x00001148
|
||||
addr: 0x0000114d
|
||||
@ -142,7 +138,6 @@ NAME=CL file
|
||||
FILE=bins/elf/dwarf3_line
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line//bar.c
|
||||
@ -153,7 +148,6 @@ NAME=CL dwarf5 file
|
||||
FILE=bins/elf/dwarf5_line
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line//bar.c
|
||||
@ -164,7 +158,6 @@ NAME=CL rel file
|
||||
FILE=bins/elf/dwarf3_line_rel
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line//bar.c
|
||||
@ -175,7 +168,6 @@ NAME=CL dwarf5 rel file
|
||||
FILE=bins/elf/dwarf5_line_rel
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line//bar.c
|
||||
@ -186,7 +178,6 @@ NAME=CL clang file
|
||||
FILE=bins/elf/dwarf3_line_cl
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/./dwarf-line/bar.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
@ -197,7 +188,6 @@ NAME=CL dwarf5 clang file
|
||||
FILE=bins/elf/dwarf5_line_cl
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/./dwarf-line/bar.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
@ -208,7 +198,6 @@ NAME=CL rel clang file
|
||||
FILE=bins/elf/dwarf3_line_rel_cl
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line/bar.c
|
||||
@ -219,7 +208,6 @@ NAME=CL dwarf5 rel clang file
|
||||
FILE=bins/elf/dwarf5_line_rel_cl
|
||||
CMDS=CL~$$file
|
||||
EXPECT=<<EOF
|
||||
|
||||
file: /tmp/dwarf-line-foo.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line.c
|
||||
file: /usr/w/g/radare2/test/bins/src/dwarf-line/bar.c
|
||||
|
@ -667,3 +667,25 @@ hello
|
||||
world
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=grep $foo
|
||||
FILE=bins/mach0/mac-ls4
|
||||
ARGS=-a arm -b 64
|
||||
CMDS=<<EOF
|
||||
pd~78
|
||||
?e ----
|
||||
pd~78$
|
||||
?e ----
|
||||
pd~$call
|
||||
?e ----
|
||||
pd~$foo
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
||,=< 0x100003b6c 600000b4 cbz x0, 0x100003b78
|
||||
|||`-> 0x100003b78 a88301d1 sub x8, x29, 0x60
|
||||
----
|
||||
||,=< 0x100003b6c 600000b4 cbz x0, 0x100003b78
|
||||
----
|
||||
----
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
Reference in New Issue
Block a user