Add RParse.justify() to easily fix commas and spaces ##disasm

This commit is contained in:
pancake 2022-10-06 19:13:26 +02:00 committed by pancake
parent 22bec6b0e0
commit fac19dcc2a
8 changed files with 27 additions and 25 deletions

View File

@ -71,7 +71,7 @@ R_API bool r_parse_subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, cha
R_API char *r_parse_immtrim(char *opstr);
/* c */
// why we have anal scoped things in rparse
R_API char *r_parse_justify(char *str);
R_API char *r_parse_c_string(RAnal *anal, const char *code, char **error_msg);
R_API char *r_parse_c_file(RAnal *anal, const char *path, const char *dir, char **error_msg);
R_API void r_parse_c_reset(RParse *p);

View File

@ -274,25 +274,7 @@ static int parse(RParse *p, const char *data, char *str) {
free (s);
}
free (buf);
// add space after commas
{
char *os = strdup (str);
int i, j;
for (i = j = 0; os[i]; i++,j++) {
char ch = os[i];
str[j] = ch;
if (ch == ',') {
j++;
str[j] = ' ';
while (os[i + 1] == ' ') {
i++;
}
}
}
str[j] = 0;
free (os);
}
r_str_trim_tail (str);
str = r_parse_justify (str);
return true;
}

View File

@ -298,7 +298,7 @@ static int parse(RParse *p, const char *data, char *str) {
} else {
replace (nw, wa, str);
}
r_str_trim (str);
str = r_parse_justify (str);
free (buf);
return true;
}

View File

@ -130,6 +130,27 @@ R_API bool r_parse_parse(RParse *p, const char *data, char *str) {
? p->cur->parse (p, data, str) : false;
}
R_API char *r_parse_justify(char *str) {
// add space after commas
char *os = strdup (str);
int i, j;
for (i = j = 0; os[i]; i++,j++) {
char ch = os[i];
str[j] = ch;
if (ch == ',') {
j++;
str[j] = ' ';
while (os[i + 1] == ' ') {
i++;
}
}
}
str[j] = 0;
free (os);
r_str_trim_tail (str);
return str;
}
R_API char *r_parse_immtrim(char *opstr) {
if (R_STR_ISEMPTY (opstr)) {
return NULL;

View File

@ -12,7 +12,7 @@ address: 0x0
opcode: add 0x1
esilcost: 0
disasm: add 0x1
pseudo: 0x1 +=
pseudo: 0x1 +=
mnemonic: add
description: add src to dst (32-bit)
mask: ffffffffffffffff

View File

@ -29,7 +29,6 @@ address: 0x4
opcode: jump
esilcost: 1
disasm: jump
pseudo: jum
mnemonic: jump
mask: ff
prefix: 0

View File

@ -135,7 +135,7 @@ EXPECT=<<EOF
{
"opcode": "la r4, 8(r15)",
"disasm": "la r4, 8(r15)",
"pseudo": "la r4, 8 (r15) ",
"pseudo": "la r4, 8 (r15)",
"description": "Load Address",
"mnemonic": "la",
"mask": "ffffffff",

View File

@ -3428,7 +3428,7 @@ address: 0x0
opcode: nop
esilcost: 0
disasm: nop
pseudo: no
pseudo: no
mnemonic: nop
description: no operation
mask: ff