App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/res/abc/abc2svg/cmdline.js view on Meta::CPAN
// abc2svg - cmdline.js - command line
//
// Copyright (C) 2014-2023 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with abc2svg. If not, see <http://www.gnu.org/licenses/>.
// user definitions
var user = {
read_file: function(fn) { // read a file (main or included)
var i,
p = fn,
file = abc2svg.readFile(p)
if (!file && fn[0] != '/') {
for (i = 0; i < abc2svg.path.length; i++) {
p = abc2svg.path[i] + '/' + fn
file = abc2svg.readFile(p)
if (file)
break
}
}
if (!file)
return file
// memorize the file path
i = p.lastIndexOf('/')
if (i > 0) {
p = p.slice(0, i)
if (abc2svg.path.indexOf(p) < 0)
abc2svg.path.unshift(p)
}
// convert the file content into a Unix string
i = file.indexOf('\r')
if (i >= 0) {
if (file[i + 1] == '\n')
file = file.replace(/\r\n/g, '\n') // M$
else
file = file.replace(/\r/g, '\n') // Mac
}
// load the required modules (synchronous)
abc2svg.modules.load(file)
return file
},
errtxt: '',
errmsg: // print or store the error messages
typeof abc2svg.printErr == 'function'
? function(msg, l, c) { abc2svg.printErr(msg) }
: function(msg, l, c) { user.errtxt += msg + '\n' }
} // user
var abc // (global for 'toxxx.js')
if (!abc2svg.path)
abc2svg.path = [] // path to ABC files - from env ABCPATH
// treat a file
function do_file(fn) {
var file = user.read_file(fn)
if (!file) {
if (fn != "default.abc")
user.errmsg("Cannot read file '" + fn + "'")
return
}
// if (typeof(utf_convert) == "function")
// file = utf_convert(file)
// generate
try {
abc.tosvg(fn, file)
} catch (e) {
abc2svg.abort(e)
}
} // do_file()
function abc_cmd(cmd, args, interp_name) {
var arg, parm, fn;
abc2svg.abort = function(e) {
abc2svg.printErr('javascript error: ' + e.message +
'\nStack:\n' + e.stack)
if (abc) {
abc.get_parse().state = 0 // force block flush
abc.blk_flush()
abc2svg.abc_end()
}
abc2svg.quit()
} // abort()
// put the last options before the last file
function arg_reorder(a) {
var f,
i = a.length - 2
while (i > 2 && a[i].slice(0, 2) == '--')
i -= 2
f = a[--i]
a.splice(i, 1)
a.push(f)
( run in 1.686 second using v1.01-cache-2.11-cpan-98e64b0badf )