2013-01-17 02:29:46 +00:00
|
|
|
/* radare - LGPL - Copyright 2008-2013 - pancake */
|
2009-02-17 09:59:26 +00:00
|
|
|
|
|
|
|
#include <r_flags.h>
|
2013-01-17 02:29:46 +00:00
|
|
|
#include <r_cons.h>
|
2009-02-17 09:59:26 +00:00
|
|
|
|
2012-11-12 23:53:52 +00:00
|
|
|
R_API int r_flag_space_get(RFlag *f, const char *name) {
|
2011-02-16 23:58:54 +00:00
|
|
|
int i;
|
2012-11-12 23:53:52 +00:00
|
|
|
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
2011-02-16 23:58:54 +00:00
|
|
|
if (f->spaces[i] != NULL)
|
|
|
|
if (!strcmp (name, f->spaces[i]))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-18 00:16:56 +00:00
|
|
|
R_API const char *r_flag_space_get_i (RFlag *f, int idx) {
|
2011-02-04 17:34:20 +00:00
|
|
|
if (idx==-1 || idx>255 || f->spaces[idx]=='\0')
|
2009-02-17 09:59:26 +00:00
|
|
|
return "";
|
2011-02-04 17:34:20 +00:00
|
|
|
return f->spaces[idx];
|
2009-02-17 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2010-12-22 00:23:35 +00:00
|
|
|
void flag_space_init(struct r_flag_t *f) {
|
2009-02-17 09:59:26 +00:00
|
|
|
static int init = 0;
|
|
|
|
int i;
|
|
|
|
if (init)
|
|
|
|
return;
|
|
|
|
init = 1;
|
|
|
|
for(i=0;i<R_FLAG_SPACES_MAX;i++)
|
|
|
|
f->space[i] = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-12-22 00:23:35 +00:00
|
|
|
R_API void r_flag_space_set(RFlag *f, const char *name) {
|
2009-02-17 09:59:26 +00:00
|
|
|
int i;
|
2010-03-19 01:49:30 +00:00
|
|
|
if (name == NULL || *name == '*') {
|
|
|
|
f->space_idx = -1;
|
|
|
|
return;
|
|
|
|
}
|
2009-04-02 00:44:24 +00:00
|
|
|
|
2013-03-07 22:47:41 +00:00
|
|
|
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
2011-02-04 17:34:20 +00:00
|
|
|
if (f->spaces[i] != NULL)
|
|
|
|
if (!strcmp (name, f->spaces[i])) {
|
2013-03-07 22:47:41 +00:00
|
|
|
f->space_idx = i;
|
2009-02-17 09:59:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* not found */
|
2013-03-07 22:47:41 +00:00
|
|
|
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
2011-02-04 17:34:20 +00:00
|
|
|
if (f->spaces[i] == NULL) {
|
|
|
|
f->spaces[i] = strdup (name);
|
2009-02-17 09:59:26 +00:00
|
|
|
f->space_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-17 02:29:46 +00:00
|
|
|
R_API int r_flag_space_list(RFlag *f, int mode) {
|
|
|
|
int i, j = 0;
|
|
|
|
if (mode == 'j')
|
|
|
|
r_cons_printf ("[");
|
|
|
|
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
|
|
|
if (!f->spaces[i]) continue;
|
|
|
|
if (mode=='j') {
|
|
|
|
r_cons_printf ("%s{\"name\":\"%s\"%s}",
|
|
|
|
j? ",":"", f->spaces[i],
|
|
|
|
(i==f->space_idx)?
|
|
|
|
",\"selected\":true":"");
|
|
|
|
} else if (mode=='*') {
|
|
|
|
r_cons_printf ("fs %02d %c %s\n", j++,
|
|
|
|
(i==f->space_idx)?'*':' ',
|
|
|
|
f->spaces[i]);
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("%02d %c %s\n", j++,
|
|
|
|
(i==f->space_idx)?'*':' ',
|
|
|
|
f->spaces[i]);
|
|
|
|
}
|
|
|
|
j++;
|
2009-02-17 09:59:26 +00:00
|
|
|
}
|
2013-01-17 02:29:46 +00:00
|
|
|
if (mode == 'j')
|
|
|
|
r_cons_printf ("]\n");
|
|
|
|
return j;
|
2009-02-17 09:59:26 +00:00
|
|
|
}
|
2013-03-07 22:47:41 +00:00
|
|
|
|
|
|
|
R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname) {
|
|
|
|
int i;
|
|
|
|
if (!oname) {
|
|
|
|
if (f->space_idx == -1)
|
|
|
|
return R_FALSE;
|
|
|
|
oname = f->spaces[f->space_idx];
|
|
|
|
}
|
|
|
|
if (!nname) return R_FALSE;
|
|
|
|
while (*oname==' ') oname++;
|
|
|
|
while (*nname==' ') nname++;
|
|
|
|
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
|
|
|
if (f->spaces[i] && !strcmp (oname, f->spaces[i])) {
|
|
|
|
free (f->spaces[i]);
|
|
|
|
f->spaces[i] = strdup (nname);
|
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return R_FALSE;
|
|
|
|
}
|