summaryrefslogtreecommitdiff
path: root/source/tools
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-04-25 15:50:44 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-04-26 15:12:57 +0200
commit47fb8ab2dd34e0adc60f415c2ebe58b18f1a5e8b (patch)
tree75c117f1e1377f2d824a0d25c2ab4a0b0465672d /source/tools
parenta2f62569da0bb87b9d4c4d54e51d43be63ceb968 (diff)
downloadmupdf-47fb8ab2dd34e0adc60f415c2ebe58b18f1a5e8b.tar.xz
murun: Print result of evaluating a line in interactive mode.
Diffstat (limited to 'source/tools')
-rw-r--r--source/tools/murun.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 03e092f7..eba987bb 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -23,6 +23,25 @@ static void *alloc(void *actx, void *ptr, unsigned int n)
return fz_malloc_array(ctx, n, 1);
}
+static int eval_print(js_State *J, const char *source)
+{
+ if (js_ploadstring(J, "[string]", source)) {
+ fprintf(stderr, "%s\n", js_tostring(J, -1));
+ js_pop(J, 1);
+ return 1;
+ }
+ js_pushglobal(J);
+ if (js_pcall(J, 0)) {
+ fprintf(stderr, "%s\n", js_tostring(J, -1));
+ js_pop(J, 1);
+ return 1;
+ }
+ if (js_isdefined(J, -1))
+ printf("%s\n", js_tostring(J, -1));
+ js_pop(J, 1);
+ return 0;
+}
+
static void jsB_propfun(js_State *J, const char *name, js_CFunction cfun, int n)
{
const char *realname = strchr(name, '.');
@@ -3174,7 +3193,7 @@ int murun_main(int argc, char **argv)
char line[256];
fputs(PS1, stdout);
while (fgets(line, sizeof line, stdin)) {
- js_dostring(J, line);
+ eval_print(J, line);
fputs(PS1, stdout);
}
putchar('\n');