Debian Codegraph @

lib/ChordPro/res/abc/cmd.js

raw symbols SCIP
1 // abc2svg - cmd.js - stripped down version of cmdline.js
2
3 // user definitions
4 var user = {
5 read_file: function(fn) { // read a file (main or included)
6 var i,
7 p = fn,
8 file = abc2svg.readFile(p)
9
10 if (!file && fn[0] != '/') {
11 for (i = 0; i < abc2svg.path.length; i++) {
12 p = abc2svg.path[i] + '/' + fn
13 file = abc2svg.readFile(p)
14 if (file)
15 break
16 }
17 }
18
19 if (!file)
20 return file
21
22 // memorize the file path
23 i = p.lastIndexOf('/')
24 if (i > 0) {
25 p = p.slice(0, i)
26 if (abc2svg.path.indexOf(p) < 0)
27 abc2svg.path.unshift(p)
28 }
29
30 // convert the file content into a Unix string
31 i = file.indexOf('\r')
32 if (i >= 0) {
33 if (file[i + 1] == '\n')
34 file = file.replace(/\r\n/g, '\n') // M$
35 else
36 file = file.replace(/\r/g, '\n') // Mac
37 }
38
39 // load the required modules (synchronous)
40 abc2svg.modules.load(file)
41
42 return file
43 },
44 errtxt: '',
45 errmsg: // print or store the error messages
46 typeof abc2svg.printErr == 'function'
47 ? function(msg, l, c) { abc2svg.printErr(msg) }
48 : function(msg, l, c) { user.errtxt += msg + '\n' }
49 } // user
50
51 var abc // (global for 'toxxx.js')
52 var s // (var for do_begin_end - grid3)
53 var cl // (var for grid3)
54
55 abc2svg.path = [] // path to ABC files
56
57 // treat a file
58 function do_file(fn) {
59 var file = user.read_file(fn)
60
61 if (!file) {
62 user.errmsg("Cannot read file '" + fn + "'")
63 return
64 }
65
66 // generate
67 try {
68 abc.tosvg(fn, file)
69 }
70 catch (e) {
71 abc2svg.abort(e)
72 }
73 } // do_file()
74
75 function abc_cmd(cmd, args, interp_name) {
76 var fn = args[0]
77 abc2svg.abort = function(e) {
78 abc2svg.printErr('javascript error: ' + e.message +
79 '\nStack:\n' + e.stack)
80 if (abc) {
81 abc.parse.state = 0 // force block flush
82 abc.blk_flush()
83 abc2svg.abc_end()
84 }
85 abc2svg.quit()
86 } // abort()
87
88 // initialize the backend
89 abc = new abc2svg.Abc(user)
90 abc2svg.abc_init(args)
91 do_file(fn)
92 // abc.tosvg('cmd', '%%select\n')
93 abc2svg.abc_end()
94 }
95
96 //Local Variables:
97 //tab-width: 4
98 //End: