Skip to content

Commit

Permalink
* Fix build of python plugin in ArchLinux (python2.6 instead of 2.5)
Browse files Browse the repository at this point in the history
* Simplify the perl plugin
* Drop stupid \n debug in dietline O:)
  • Loading branch information
radare committed Feb 15, 2009
1 parent 5832a61 commit 33d94ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 80 deletions.
11 changes: 9 additions & 2 deletions libr/lang/p/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ all: lua.so dummy.so ruby.so python.so perl.so
@true

python.so:
-${CC} ${CFLAGS} -I/usr/include/python2.5 \
-fPIC -shared -o python.so python.c -lpython >/dev/null 2>&1
-gcc -lpython >/dev/null 2>&1 ; \
if [ $$? = 0 ]; then \
${CC} ${CFLAGS} -I/usr/include/python2.5 \
-fPIC -shared -o python.so python.c -lpython ; \
else \
${CC} ${CFLAGS} -I/usr/include/python2.5 \
-fPIC -shared -o python.so python.c \
-I/usr/include/python2.6/ -lpython2.6 ; \
fi

lua.so: lua.o
-${CC} ${CFLAGS} -fPIC -shared -o lua.so lua.c -Wl,-R..
Expand Down
93 changes: 16 additions & 77 deletions libr/lang/p/perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,37 @@
#include "r_core.h"
static struct r_core_t *core = NULL;

extern PerlInterpreter *my_perl;
PerlInterpreter *my_perl = NULL;
static PerlInterpreter *my_perl = NULL;

extern void xs_init (pTHX);

void radare_perl(pTHX_ CV* cv)
static void perl_radare_cmd(pTHX_ CV* cv)
{
char *cmd;
dXSARGS;

char *str;
dXSARGS;
cmd = sv_pv(ST(0));
str = r_core_cmd_str(core, cmd);
ST(0) = newSVpvn(str, strlen(str));
free(str);
XSRETURN(1);
#if 0
if (!config.debug) {
char *str;
cmd = sv_pv(ST(0));
str = pipe_command_to_string(cmd);
ST(0) = newSVpvn(str, strlen(str));
free(str);
XSRETURN(1);
} else {
char str[4096];
// XXX pipe_stdout_to_tmp_file is a br0ken idea
str[0]='\0';
cmd = sv_pv(ST(0));
if (! pipe_stdout_to_tmp_file(file, cmd) ) {
ST(0) = newSVpvn("", 0);
return;
}
fd = fopen(file, "r");
if (fd == NULL) {
fprintf(stderr, "Cannot open tmpfile\n");
unlink(file);
ST(0) = newSVpvn("", 0);
return;
} else {
while(!feof(fd)) {
fgets(buf, 1023, fd);
if (feof(fd)) break;
if (strlen(buf)+strlen(str)> 4000) {
fprintf(stderr, "Input line too large\n");
break;
}
strcat(str, buf);
}
fclose(fd);
}
unlink(file);
}
#endif
str = items; /* dummy */
}

void xs_init(pTHX)
static void xs_init(pTHX)
{
newXS("r", radare_perl, __FILE__);
newXS("r", perl_radare_cmd, __FILE__);
}

static int init(void *user)
{
char *perl_embed[] = { "", "-e", "0" };
core = user;
my_perl = perl_alloc();
if (my_perl == NULL) {
printf("Cannot init perl module\n");
return R_FALSE;
}
perl_construct(my_perl);
perl_parse(my_perl, xs_init, 3, perl_embed, (char **)NULL);

return R_TRUE;
}
Expand All @@ -96,55 +57,33 @@ static int fini(void *user)
return R_TRUE;
}

/* TODO: handle multi-line */
static int prompt(void *user)
{
char str[1025];

/* prepare array */
{
char *perl_embed[] = { "", "-e", "0" };
perl_parse(my_perl, xs_init, 3, perl_embed, (char **)NULL);
}
while(1) {
printf("perl> ");
fflush(stdout);
fgets(str, 1023, stdin);
if (feof(stdin))
break;
str[strlen(str)-1]='\0';
if (!strcmp(str, "q"))
break;
eval_pv(str, TRUE);
}

return R_TRUE;
}

static int run(void *user, const char *code, int len)
{
/* TODO: catcth errors */
eval_pv(code, TRUE);
return R_TRUE;
}

static int run_file(void *user, const char *file)
static int setargv(void *user, int argc, char **argv)
{
perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
return R_TRUE;
}

static const char *help =
"Perl plugin usage:\n"
" print \"r(pd 10)\\n\";\n";
" print \"r(\"pd 10\")\\n\";\n";

static struct r_lang_handle_t r_lang_plugin_perl = {
.name = "perl",
.desc = "Perl language extension",
.init = &init,
.fini = &fini,
.help = &help,
.prompt = &prompt,
.prompt = NULL,
.run = &run,
.run_file = &run_file,
.set_argv = NULL,
.run_file = NULL,
.set_argv = setargv,
};

struct r_lib_struct_t radare_plugin = {
Expand Down
1 change: 0 additions & 1 deletion libr/line/dietline.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,5 @@ char *r_line_readline(int argc, const char **argv)
r_line_hist_list();
return r_line_nullstr;
}
IFDBG write(1,"\n",1);
return r_line_buffer;
}

0 comments on commit 33d94ab

Please sign in to comment.