-
Notifications
You must be signed in to change notification settings - Fork 6
/
abcnode
executable file
·72 lines (64 loc) · 1.48 KB
/
abcnode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
# abc2svg with raw nodeJS
progdir=`dirname $0`
cat ${progdir}/abc2svg-1.js ${progdir}/cmdline.js > /tmp/toto.js
case $1 in
*.js)
cat $1 >> /tmp/toto.js
shift
;;
esac
if ! grep 'abc2svg.abc_init =' $1 > /dev/null; then
cat ${progdir}/toxhtml.js >> /tmp/toto.js
fi
cat <<EOF >> /tmp/toto.js
var progdir='${progdir}/'
// interpreter specific functions
abc2svg.print = function(str) {
process.stdout.write(str + '\n')
}
abc2svg.printErr = function(str) {
process.stderr.write(str + '\n')
}
abc2svg.quit = function() {
process.exit(1)
}
abc2svg.readFile = function(fname) {
var fs = require("fs");
return fs.readFileSync(fname).toString()
}
abc2svg.loadjs = function(fn, relay, onerror) {
try {
var geval = eval;
geval(abc2svg.readFile(progdir + fn))
if (relay)
relay()
} catch(e) {
if (onerror)
onerror()
else
abc2svg.printErr('Cannot read file ' + fn)
}
}
// (this file is wrapped)
global.Abc = Abc
global.abc2svg = abc2svg
// main
var args = process.argv
if (!args[2]) {
abc2svg.print('ABC translator with nodeJS\
and abc2svg-' + abc2svg.version + ' ' + abc2svg.vdate + '\n\
Usage:\n\
abcnode [script.js] [g_options] ABC_file [f_options] [ABC_file [f_options]]*\n\
Arguments:\n\
script.js generation script to load - default: toxhtml.js (XHTML+SVG)\n\
g_options global ABC options\n\
ABC_file ABC file\n\
f_options file options');
abc2svg.quit(1)
}
args.shift()
args.shift()
abc_cmd("abcnode", args)
EOF
node /tmp/toto.js "$@"