Add support for #!python -e and other rlang plugins
This commit is contained in:
parent
50b798c837
commit
31468882cc
|
@ -210,12 +210,25 @@ static int cmd_hash_bang (RCore *core, const char *input) {
|
|||
return true;
|
||||
}
|
||||
p = strchr (input, ' ');
|
||||
if (p) *p=0;
|
||||
bool doEval = false;
|
||||
if (p) {
|
||||
*p++ = 0;
|
||||
char *_e = strstr (p, "-e");
|
||||
if (_e) {
|
||||
doEval = true;
|
||||
p = _e + 2;
|
||||
p = r_str_chop (p);
|
||||
}
|
||||
}
|
||||
// TODO: set argv here
|
||||
if (r_lang_use (core->lang, lang)) {
|
||||
r_lang_setup (core->lang);
|
||||
if (p) {
|
||||
r_lang_run_file (core->lang, p+1);
|
||||
if (doEval) {
|
||||
r_lang_run_string (core->lang, p);
|
||||
} else {
|
||||
r_lang_run_file (core->lang, p);
|
||||
}
|
||||
} else {
|
||||
if (r_config_get_i (core->config, "scr.interactive")) {
|
||||
r_lang_prompt (core->lang);
|
||||
|
|
|
@ -30,7 +30,7 @@ typedef struct r_lang_plugin_t {
|
|||
const char **help;
|
||||
const char *ext;
|
||||
int (*init)(RLang *user);
|
||||
int (*setup)(RLang *user);
|
||||
bool (*setup)(RLang *user);
|
||||
int (*fini)(RLang *user);
|
||||
int (*prompt)(RLang *user);
|
||||
int (*run)(RLang *user, const char *code, int len);
|
||||
|
@ -47,15 +47,15 @@ typedef struct r_lang_def_t {
|
|||
#ifdef R_API
|
||||
R_API RLang *r_lang_new(void);
|
||||
R_API void *r_lang_free(RLang *lang);
|
||||
R_API int r_lang_setup(RLang *lang);
|
||||
R_API int r_lang_add(RLang *lang, RLangPlugin *foo);
|
||||
R_API int r_lang_list(RLang *lang);
|
||||
R_API int r_lang_use(RLang *lang, const char *name);
|
||||
R_API bool r_lang_setup(RLang *lang);
|
||||
R_API bool r_lang_add(RLang *lang, RLangPlugin *foo);
|
||||
R_API bool r_lang_list(RLang *lang);
|
||||
R_API bool r_lang_use(RLang *lang, const char *name);
|
||||
R_API int r_lang_run(RLang *lang, const char *code, int len);
|
||||
R_API int r_lang_run_string(RLang *lang, const char *code);
|
||||
/* TODO: user_ptr must be deprecated */
|
||||
R_API void r_lang_set_user_ptr(RLang *lang, void *user);
|
||||
R_API int r_lang_set_argv(RLang *lang, int argc, char **argv);
|
||||
R_API bool r_lang_set_argv(RLang *lang, int argc, char **argv);
|
||||
R_API int r_lang_run(RLang *lang, const char *code, int len);
|
||||
R_API int r_lang_run_file(RLang *lang, const char *file);
|
||||
R_API int r_lang_prompt(RLang *lang);
|
||||
|
@ -64,7 +64,7 @@ R_API RLangPlugin *r_lang_get_by_name(RLang *lang, const char *name);
|
|||
R_API RLangPlugin *r_lang_get_by_extension(RLang *lang, const char *ext);
|
||||
// TODO: rename r_Lang_add for r_lang_plugin_add
|
||||
|
||||
R_API int r_lang_define(RLang *lang, const char *type, const char *name, void *value);
|
||||
R_API bool r_lang_define(RLang *lang, const char *type, const char *name, void *value);
|
||||
R_API void r_lang_undef(RLang *lang, const char *name);
|
||||
R_API void r_lang_def_free(RLangDef *def);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2016 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2017 - pancake */
|
||||
|
||||
#include <r_lang.h>
|
||||
#include <r_util.h>
|
||||
|
@ -14,7 +14,6 @@ R_LIB_VERSION(r_lang);
|
|||
#include "p/cpipe.c" // hardcoded
|
||||
#endif
|
||||
|
||||
|
||||
static RLang *__lang = NULL;
|
||||
|
||||
R_API void r_lang_plugin_free (RLangPlugin *p) {
|
||||
|
@ -55,7 +54,9 @@ R_API RLang *r_lang_new() {
|
|||
}
|
||||
|
||||
R_API void *r_lang_free(RLang *lang) {
|
||||
if (!lang) return NULL;
|
||||
if (!lang) {
|
||||
return NULL;
|
||||
}
|
||||
__lang = NULL;
|
||||
r_lang_undef (lang, NULL);
|
||||
r_list_free (lang->langs);
|
||||
|
@ -73,7 +74,7 @@ R_API void r_lang_set_user_ptr(RLang *lang, void *user) {
|
|||
lang->user = user;
|
||||
}
|
||||
|
||||
R_API int r_lang_define(RLang *lang, const char *type, const char *name, void *value) {
|
||||
R_API bool r_lang_define(RLang *lang, const char *type, const char *name, void *value) {
|
||||
RLangDef *def;
|
||||
RListIter *iter;
|
||||
r_list_foreach (lang->defs, iter, def) {
|
||||
|
@ -116,25 +117,26 @@ R_API void r_lang_undef(RLang *lang, const char *name) {
|
|||
}
|
||||
}
|
||||
|
||||
R_API int r_lang_setup(RLang *lang) {
|
||||
if (lang->cur && lang->cur->setup) {
|
||||
R_API bool r_lang_setup(RLang *lang) {
|
||||
if (lang && lang->cur && lang->cur->setup) {
|
||||
return lang->cur->setup (lang);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_lang_add(RLang *lang, RLangPlugin *foo) {
|
||||
R_API bool r_lang_add(RLang *lang, RLangPlugin *foo) {
|
||||
if (foo && (!r_lang_get_by_name (lang, foo->name))) {
|
||||
if (foo->init) {
|
||||
foo->init (lang);
|
||||
}
|
||||
r_list_append (lang->langs, foo);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO: deprecate all list methods */
|
||||
R_API int r_lang_list(RLang *lang) {
|
||||
R_API bool r_lang_list(RLang *lang) {
|
||||
RListIter *iter;
|
||||
RLangPlugin *h;
|
||||
if (!lang) {
|
||||
|
@ -173,7 +175,7 @@ R_API RLangPlugin *r_lang_get_by_name (RLang *lang, const char *name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_lang_use(RLang *lang, const char *name) {
|
||||
R_API bool r_lang_use(RLang *lang, const char *name) {
|
||||
RLangPlugin *h = r_lang_get_by_name (lang, name);
|
||||
if (h) {
|
||||
lang->cur = h;
|
||||
|
@ -183,7 +185,7 @@ R_API int r_lang_use(RLang *lang, const char *name) {
|
|||
}
|
||||
|
||||
// TODO: store in r_lang and use it from the plugin?
|
||||
R_API int r_lang_set_argv(RLang *lang, int argc, char **argv) {
|
||||
R_API bool r_lang_set_argv(RLang *lang, int argc, char **argv) {
|
||||
if (lang->cur && lang->cur->set_argv) {
|
||||
return lang->cur->set_argv (lang, argc, argv);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue