summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-09-05 12:02:19 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-09-05 12:52:06 +0200
commit893675249d9e3e20f198e8c25783b04c823dec39 (patch)
treeb306f1e9b97390173ca521d017af8e49d10f5456
parentf5b82ca466dfdeb866062132d0fe495bee70f9f2 (diff)
downloadmupdf-893675249d9e3e20f198e8c25783b04c823dec39.tar.xz
mutool run: Pass script path and arguments as scriptPath and scriptArgs.
-rw-r--r--docs/examples/bbox-device.js6
-rw-r--r--docs/examples/draw-document.js2
-rw-r--r--docs/examples/jpx-to-pdf.js8
-rw-r--r--docs/examples/pdf-merge.js8
-rw-r--r--docs/examples/trace-device.js6
-rw-r--r--docs/manual-mutool-run.html5
-rw-r--r--source/tools/murun.c8
7 files changed, 23 insertions, 20 deletions
diff --git a/docs/examples/bbox-device.js b/docs/examples/bbox-device.js
index 52d2cb4a..4a4b9f82 100644
--- a/docs/examples/bbox-device.js
+++ b/docs/examples/bbox-device.js
@@ -79,11 +79,11 @@ function BBoxDevice(bbox) {
};
}
-if (argv.length != 3)
+if (scriptArgs.length != 2)
print("usage: mutool run bbox-device.js document.pdf pageNumber")
else {
- var doc = new Document(argv[1]);
- var page = doc.loadPage(parseInt(argv[2])-1);
+ var doc = new Document(scriptArgs[0]);
+ var page = doc.loadPage(parseInt(scriptArgs[1])-1);
var bbox = [Infinity, Infinity, -Infinity, -Infinity];
page.run(new BBoxDevice(bbox), Identity);
print("original bbox:", page.bound());
diff --git a/docs/examples/draw-document.js b/docs/examples/draw-document.js
index 1e285ede..fe431257 100644
--- a/docs/examples/draw-document.js
+++ b/docs/examples/draw-document.js
@@ -1,6 +1,6 @@
// Draw all pages in a document and save them as PNG files.
-var doc = new Document(argv[1]);
+var doc = new Document(scriptArgs[0]);
var n = doc.countPages();
for (var i = 0; i < n; ++i) {
var page = doc.loadPage(i);
diff --git a/docs/examples/jpx-to-pdf.js b/docs/examples/jpx-to-pdf.js
index ee95ab30..be64044f 100644
--- a/docs/examples/jpx-to-pdf.js
+++ b/docs/examples/jpx-to-pdf.js
@@ -27,13 +27,13 @@ function addJPXPage(filename) {
doc.insertPage(-1, doc.addPage(mediabox, 0, resources, contents));
}
-var i, n = argv.length;
-if (n < 2) {
+var i, n = scriptArgs.length;
+if (n < 1) {
print("usage: mutool run jpx-to-pdf.js file.jpx ...");
quit();
}
-for (i = 1; i < n; ++i) {
- addJPXPage(argv[i]);
+for (i = 0; i < n; ++i) {
+ addJPXPage(scriptArgs[i]);
}
doc.save("out.pdf", "ascii,pretty");
diff --git a/docs/examples/pdf-merge.js b/docs/examples/pdf-merge.js
index d8cdcfcb..ebf2649b 100644
--- a/docs/examples/pdf-merge.js
+++ b/docs/examples/pdf-merge.js
@@ -54,14 +54,14 @@ function pdfmerge() {
var srcDoc, dstDoc, i
dstDoc = new PDFDocument()
- for (i = 2; i < argv.length; ++i) {
- srcDoc = new PDFDocument(argv[i])
+ for (i = 1; i < scriptArgs.length; ++i) {
+ srcDoc = new PDFDocument(scriptArgs[i])
copyAllPages(dstDoc, srcDoc)
}
- dstDoc.save(argv[1], "compress")
+ dstDoc.save(scriptArgs[0], "compress")
}
-if (argv.length < 3)
+if (scriptArgs.length < 2)
print("usage: mutool run pdf-merge.js output.pdf input1.pdf input2.pdf ...")
else
pdfmerge()
diff --git a/docs/examples/trace-device.js b/docs/examples/trace-device.js
index 9d7d4373..d3ddec81 100644
--- a/docs/examples/trace-device.js
+++ b/docs/examples/trace-device.js
@@ -93,10 +93,10 @@ var traceDevice = {
},
}
-if (argv.length != 3)
+if (scriptArgs.length != 2)
print("usage: mutool run trace-device.js document.pdf pageNumber")
else {
- var doc = new Document(argv[1]);
- var page = doc.loadPage(parseInt(argv[2])-1);
+ var doc = new Document(scriptArgs[0]);
+ var page = doc.loadPage(parseInt(scriptArgs[1])-1);
page.run(traceDevice, Identity);
}
diff --git a/docs/manual-mutool-run.html b/docs/manual-mutool-run.html
index 26964081..310c69cc 100644
--- a/docs/manual-mutool-run.html
+++ b/docs/manual-mutool-run.html
@@ -15,8 +15,9 @@
<p>
The 'mutool run' command executes a JavaScript program, which has access to most of the features of the MuPDF library.
The command supports ECMAScript 5 syntax in strict mode.
-All of the MuPDF constructors and functions live in the global object, and the command line arguments are accessible
-from the global 'argv' object.
+All of the MuPDF constructors and functions live in the global object, and the
+command line arguments are accessible from the global 'scriptArgs' object.
+The name of the script is in the global 'scriptPath' variable.
<pre>
mutool run script.js [ arguments ... ]
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 02144df4..810b32ce 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -4882,12 +4882,14 @@ int murun_main(int argc, char **argv)
"a[4] * b[1] + a[5] * b[3] + b[5]];}");
if (argc > 1) {
+ js_pushstring(J, argv[1]);
+ js_setglobal(J, "scriptPath");
js_newarray(J);
- for (i = 1; i < argc; ++i) {
+ for (i = 2; i < argc; ++i) {
js_pushstring(J, argv[i]);
- js_setindex(J, -2, i - 1);
+ js_setindex(J, -2, i - 2);
}
- js_setglobal(J, "argv");
+ js_setglobal(J, "scriptArgs");
if (js_dofile(J, argv[1]))
return 1;
} else {