Initial implementation of the V, comma-ents stuff

This commit is contained in:
pancake 2015-11-18 13:03:35 +01:00
parent 0d9e29bd26
commit 30b1fcc208
3 changed files with 83 additions and 17 deletions

View File

@ -2165,7 +2165,6 @@ static void handle_print_comments_right (RCore *core, RDisasmState *ds) {
} }
r_cons_strcat (" ; "); r_cons_strcat (" ; ");
} }
//r_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';'); //r_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';');
r_cons_strcat (ds->comment); r_cons_strcat (ds->comment);
if (ds->show_color) { if (ds->show_color) {
@ -2450,7 +2449,6 @@ toro:
if (!(ds->show_comments && ds->show_comment_right && ds->comment)) { if (!(ds->show_comments && ds->show_comment_right && ds->comment)) {
r_cons_newline (); r_cons_newline ();
} }
if (ds->line) { if (ds->line) {
if (ds->show_lines_ret && ds->analop.type == R_ANAL_OP_TYPE_RET) { if (ds->show_lines_ret && ds->analop.type == R_ANAL_OP_TYPE_RET) {
if (strchr (ds->line, '>')) { if (strchr (ds->line, '>')) {

View File

@ -678,6 +678,68 @@ void SetWindow(int Width, int Height) {
} }
#endif #endif
/* retrieves string between ',<' and '>' */
static char *getcommafile(const char *cmt) {
char *c0, *c1;
if (!cmt || !*cmt) return NULL;
c0 = strstr (cmt, ",<");
if (!c0) return NULL;
c1 = strchr (c0+2, '>');
if (!c1) return NULL;
return r_str_ndup (c0+2, (c1-c0-2));
}
static void visual_comma(RCore *core) {
ut64 addr = core->offset; // + (ocursor!=-1)? ocursor: 0;
char *comment, *cwd, *cmtfile;
const char *dir = r_config_get (core->config, "dir.projects");
const char *prj = r_config_get (core->config, "file.project");
if (curset) {
addr += cursor;
}
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
cmtfile = getcommafile (comment);
if (dir && *dir && prj && *prj) {
/* use prjdir as base directory for comma-ent files */
cwd = r_str_newf ("%s"R_SYS_DIR"%s.d",
r_file_abspath (dir), prj);
} else {
/* use cwd as base directory for comma-ent files */
cwd = r_file_abspath (".");
}
if (!cmtfile) {
char *fn;
showcursor (core, true);
fn = r_cons_input ("<commant-file> ");
showcursor (core, false);
if (fn && *fn) {
cmtfile = strdup (fn);
if (!comment || !*comment) {
comment = r_str_newf (",<%s>", fn);
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, comment);
} else {
// append filename in current comment
char *nc = r_str_newf ("%s ,<%s>", comment, fn);
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc);
free (nc);
}
}
free (fn);
}
if (cmtfile) {
char *cwf = r_str_newf ("%s"R_SYS_DIR"%s", cwd, cmtfile);
char *odata = r_file_slurp (cwf, NULL);
char *data = r_core_editor (core, NULL, odata);
r_file_dump (cwf, (const ut8*)data, -1, 0);
free (data);
free (odata);
free (cwf);
} else {
eprintf ("NO CMTFILE\n");
}
free (comment);
}
R_API int r_core_visual_cmd(RCore *core, int ch) { R_API int r_core_visual_cmd(RCore *core, int ch) {
RAsmOp op; RAsmOp op;
ut64 offset = core->offset; ut64 offset = core->offset;
@ -887,6 +949,9 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
} } } }
showcursor (core, false); showcursor (core, false);
break; break;
case ',':
visual_comma (core);
break;
case 'T': case 'T':
if (r_sandbox_enable (0)) { if (r_sandbox_enable (0)) {
eprintf ("sandbox not enabled\n"); eprintf ("sandbox not enabled\n");
@ -1444,7 +1509,6 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
ut64 addr = core->offset; ut64 addr = core->offset;
if (curset) { if (curset) {
addr += cursor; addr += cursor;
r_core_seek (core, addr, 0); r_core_seek (core, addr, 0);
r_core_cmdf (core, "s 0x%"PFMT64x, addr); r_core_cmdf (core, "s 0x%"PFMT64x, addr);
} }

View File

@ -115,11 +115,14 @@ R_API int r_file_is_abspath(const char *file) {
} }
R_API char *r_file_abspath(const char *file) { R_API char *r_file_abspath(const char *file) {
if (strstr (file, "://") != NULL) { char *cwd, *ret = NULL;
if (!file || !strcmp (file, ".") || !strcmp (file, "./")) {
return r_sys_getdir ();
}
if (strstr (file, "://")) {
return strdup (file); return strdup (file);
} }
char *ret = NULL; cwd = r_sys_getdir ();
char *cwd = r_sys_getdir ();
if (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) { if (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) {
ret = r_str_home (file+2); ret = r_str_home (file+2);
} else { } else {
@ -430,6 +433,7 @@ R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append) {
eprintf ("Cannot open '%s' for writing\n", file); eprintf ("Cannot open '%s' for writing\n", file);
return R_FALSE; return R_FALSE;
} }
if (len<0) len = strlen ((const char *)buf);
ret = fwrite (buf, 1, len, fd) == len; ret = fwrite (buf, 1, len, fd) == len;
if (!ret) eprintf ("r_file_dump: fwrite: error\n"); if (!ret) eprintf ("r_file_dump: fwrite: error\n");
fclose (fd); fclose (fd);