* Add ?ip and r_cons_hud_path()

- atm only for files
  - o `?y` doesnt works with path with spaces
* Add r_file_is_directory()
* Documentate ?V command
* Add support for prompt in r_cons_hud()
This commit is contained in:
pancake 2012-02-01 03:32:14 +01:00
parent 8886b07375
commit 0104a6cd6d
5 changed files with 47 additions and 12 deletions

View File

@ -44,7 +44,7 @@ R_API char *r_cons_hud_string(const char *s) {
os = o+i+1;
}
}
ret = r_cons_hud (fl);
ret = r_cons_hud (fl, NULL);
r_list_free (fl);
return ret;
}
@ -69,7 +69,7 @@ static char *strmatch (char *pos, char *buf) {
return strcasestr (pos, os);
}
R_API char *r_cons_hud(RList *list) {
R_API char *r_cons_hud(RList *list, const char *prompt) {
int ch, nch, first, n, j, i = 0;
int choose = 0;
char *p, buf[128];
@ -83,6 +83,8 @@ R_API char *r_cons_hud(RList *list) {
r_cons_gotoxy (0, 0);
n = 0;
match = NULL;
if (prompt && *prompt)
r_cons_printf (">> %s\n", prompt);
r_cons_printf ("> %s|\n", buf);
r_list_foreach (list, iter, pos) {
if (!buf[0] || strmatch (pos, buf)) {
@ -154,11 +156,33 @@ R_API char *r_cons_hud(RList *list) {
}
R_API char *r_cons_hud_path(const char *path, int dir) {
char *ret;
RList *files = r_sys_dir (path);
// TODO
ret = r_cons_hud (files);
return ret;
char *tmp = NULL, *ret = NULL;
RList *files;
while (*path==' ') path++;
if (!path || !*path)
tmp = strdup ("./");
else tmp = strdup (path);
files = r_sys_dir (tmp);
if (files) {
ret = r_cons_hud (files, tmp);
if (ret) {
tmp = r_str_concat (tmp, "/");
tmp = r_str_concat (tmp, ret);
ret = r_file_abspath (tmp);
free (tmp);
tmp = ret;
if (r_file_is_directory (tmp)) {
ret = r_cons_hud_path (tmp, dir);
free (tmp);
tmp = ret;
}
}
} else eprintf ("No files found\n");
if (!ret) {
free (tmp);
return NULL;
}
return tmp;
}
// TODO: Add fmt support
@ -167,7 +191,7 @@ R_API char *r_cons_message(const char *msg) {
int len = strlen (msg);
cols = r_cons_get_size (&rows);
r_cons_clear();
r_cons_clear ();
r_cons_gotoxy ((cols-len)/2, rows/2); // XXX
/// TODO: add square, or talking clip here
r_cons_printf ("%s\n", msg);
@ -186,7 +210,7 @@ main() {
r_flist_set (fl, 2, "funny to see you here");
r_cons_new ();
res = r_cons_hud (fl);
res = r_cons_hud (fl, NULL);
r_cons_clear ();
if (res) {
r_cons_printf ("%s\n", res);

View File

@ -1312,7 +1312,7 @@ static int cmd_help(void *data, const char *input) {
case '$':
return cmd_help (data, " $?");
case 'V':
r_cons_printf ("r2-%s\n", R2_VERSION);
r_cons_printf ("%s\n", R2_VERSION);
break;
case 'l':
for (input++; input[0]==' '; input++);
@ -1412,7 +1412,7 @@ static int cmd_help(void *data, const char *input) {
r_cons_message (input+2);
} else
if (input[1]=='p') {
char *p = r_cons_hud_path (input+2);
char *p = r_cons_hud_path (input+2, 0);
core->yank = (ut8*)p;
core->yank_len = p? strlen (p): 0;
core->num->value = (p != NULL);
@ -1457,6 +1457,7 @@ static int cmd_help(void *data, const char *input) {
"Usage: ?[?[?]] expression\n"
" ? eip-0x804800 ; show hex and dec result for this math expr\n"
" ?v eip-0x804800 ; show hex value of math expr\n"
" ?V ; show library version of r_core\n"
" ?= eip-0x804800 ; same as above without user feedback\n"
" ?? [cmd] ; ? == 0 run command when math matches\n"
" ?i[ynmkp] arg ; prompt for number or Yes,No,Msg,Key,Path and store in $$?\n"

View File

@ -213,7 +213,8 @@ R_API int r_cons_html_print(const char *ptr);
// TODO: use gets() .. MUST BE DEPRECATED
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv);
R_API char *r_cons_hud(RList *list);
R_API char *r_cons_hud(RList *list, const char *prompt);
R_API char *r_cons_hud_path(const char *path, int dir);
R_API char *r_cons_hud_string(const char *s);
R_API char *r_cons_hud_file(const char *f);

View File

@ -219,6 +219,7 @@ R_API void r_graph_push (RGraph *t, ut64 addr, void *data);
R_API RGraphNode* r_graph_pop(RGraph *t);
R_API int r_file_size(const char *str);
R_API boolt r_file_is_directory(const char *str);
R_API RMmap *r_file_mmap (const char *file, boolt rw);
R_API void r_file_mmap_free (RMmap *m);

View File

@ -19,6 +19,13 @@ R_API const char *r_file_basename (const char *path) {
return path;
}
R_API boolt r_file_is_directory(const char *str) {
struct stat buf;
if (stat (str, &buf)==-1)
return R_FALSE;
return ((S_IFDIR &buf.st_mode))? R_TRUE: R_FALSE;
}
R_API boolt r_file_exist(const char *str) {
struct stat buf;
if (stat (str, &buf)==-1)
@ -44,6 +51,7 @@ R_API char *r_file_abspath(const char *file) {
ret = r_str_dup_printf ("%s/%s", cwd, file);
#endif
free (cwd);
// TODO: remove // and ./
return ret? ret: strdup (file);
}