Skip to content

Commit 7777f3f

Browse files
radaretrufae
authored andcommitted
Implement the tde command to define types with cfg.editor ##types
1 parent c95b955 commit 7777f3f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

libr/core/cmd_type.inc.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static RCoreHelpMessage help_msg_t = {
1616
"tac", " [file]", "the infamous reverse cat command",
1717
"tc", "[?] [type.name]", "list all/given types in C output format",
1818
"td", " <string>", "load types from string (quote the whole command: \"td ...\")",
19+
"tde", "", "open cfg.editor to define new types",
1920
"te", "[?]", "list all loaded enums",
2021
"tf", "[?]", "list all loaded functions signatures",
2122
"tk", " <sdb-query>", "perform sdb query",
@@ -2272,7 +2273,33 @@ static int cmd_type(void *data, const char *input) {
22722273
case 'd': // "td"
22732274
if (input[1] == '?') {
22742275
// TODO #7967 help refactor: move to detail
2275-
r_core_cmd_help_match (core, help_msg_t, "td");
2276+
r_core_cmd_help_contains (core, help_msg_t, "td");
2277+
} else if (input[1] == 'e') { // "tde"
2278+
for (;;) {
2279+
char *tmp = r_core_editor (core, "*.h", "");
2280+
if (!tmp) {
2281+
break;
2282+
}
2283+
r_str_trim (tmp);
2284+
if (R_STR_ISEMPTY (tmp)) {
2285+
free (tmp);
2286+
break;
2287+
}
2288+
char *errmsg = NULL;
2289+
char *out = r_anal_cparse (core->anal, tmp, &errmsg);
2290+
free (tmp);
2291+
if (out) {
2292+
r_anal_save_parsed_type (core->anal, out);
2293+
free (out);
2294+
free (errmsg);
2295+
break;
2296+
}
2297+
if (errmsg) {
2298+
R_LOG_ERROR ("%s", errmsg);
2299+
free (errmsg);
2300+
}
2301+
r_cons_any_key (core->cons, NULL);
2302+
}
22762303
} else if (input[1] == ' ') {
22772304
char *tmp = r_str_newf ("%s;", input + 2);
22782305
if (!tmp) {

0 commit comments

Comments
 (0)