diff options
Diffstat (limited to 'support/gregoriotex/tex/luatex/gregoriotex.lua')
-rw-r--r-- | support/gregoriotex/tex/luatex/gregoriotex.lua | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/support/gregoriotex/tex/luatex/gregoriotex.lua b/support/gregoriotex/tex/luatex/gregoriotex.lua index f3ad902b5a..e16f193552 100644 --- a/support/gregoriotex/tex/luatex/gregoriotex.lua +++ b/support/gregoriotex/tex/luatex/gregoriotex.lua @@ -1,6 +1,6 @@ --GregorioTeX Lua file. -- ---Copyright (C) 2008-2019 The Gregorio Project (see CONTRIBUTORS.md) +--Copyright (C) 2008-2021 The Gregorio Project (see CONTRIBUTORS.md) -- --This file is part of Gregorio. -- @@ -24,16 +24,16 @@ local hpack, traverse, traverse_id, has_attribute, count, remove, insert_after, gregoriotex = gregoriotex or {} local gregoriotex = gregoriotex -local internalversion = '5.2.1' -- GREGORIO_VERSION (comment used by VersionManager.py) +local internalversion = '6.0.0-beta1' -- GREGORIO_VERSION (comment used by VersionManager.py) local err, warn, info, log = luatexbase.provides_module({ name = "gregoriotex", - version = '5.2.1', -- GREGORIO_VERSION + version = '6.0.0-beta1', -- GREGORIO_VERSION greinternalversion = internalversion, - date = "2019/04/06", -- GREGORIO_DATE_LTX + date = "2021/02/23", -- GREGORIO_DATE_LTX description = "GregorioTeX module.", author = "The Gregorio Project (see CONTRIBUTORS.md)", - copyright = "2008-2019 - The Gregorio Project", + copyright = "2008-2021 - The Gregorio Project", license = "GPLv3+", }) @@ -146,7 +146,7 @@ local function gregorio_exe() local exe_version -- first look for one with the exact version - real_gregorio_exe = 'gregorio-5_2_1' -- FILENAME_VERSION + real_gregorio_exe = 'gregorio-6_0_0-beta1' -- FILENAME_VERSION local cmd = string.format([[%s -o "%%s" "%s"]], real_gregorio_exe, test_snippet_filename) exe_version = get_prog_output(cmd, '*line') @@ -769,11 +769,10 @@ local function clean_old_gtex_files(file_withdir) string.find(os.getenv("PATH"),";",1,true) if onwindows then sep = "\\" - dirpath = string.match(file_withdir, "(.*)"..sep) else sep = "/" - dirpath = string.match(file_withdir, "(.*)"..sep) end + dirpath = string.match(file_withdir, "(.*)"..sep) if dirpath then -- dirpath is nil if current directory filename = "^"..file_withdir:match(".*/".."(.*)").."%-%d+_%d+_%d+[-%a%d]*%.gtex$" for a in lfs.dir(dirpath) do @@ -854,6 +853,37 @@ local function compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated) end end +local function locate_file(filename) + local result + if not gre_input_path then + gre_input_path = {""} + end + for i,k in pairs(gre_input_path) do + log("Looking in %s", k) + if lfs.isfile(k .. filename) then + result = k..filename + if result == filename then + log("Found %s directly", filename) + else + log("Found %s in %s", filename, k) + end + break + end + end + if not result then + result = kpse.find_file(filename) + if result then + log("Found %s at\n%s using kpsewhich", filename, result) + if string.match(result," ") then + warn("%s contains a space in the path\nTeX will likely complain about this", filename) + end + else + log("Cannot find %s", filename) + end + end + return result +end + local function include_score(input_file, force_gabccompile, allow_deprecated) if string.match(input_file, "[#%%]") then err("GABC filename contains invalid character(s): # %%\n" @@ -872,15 +902,17 @@ local function include_score(input_file, force_gabccompile, allow_deprecated) end local cleaned_filename = input_name:gsub("[%s%+%&%*%?$@:;!\"\'`]", "-") - local gabc_file = string.format("%s%s.gabc", file_dir, input_name) - local gtex_file = string.format("%s%s-%s.gtex", file_dir, cleaned_filename, + local gabc_filename = string.format("%s%s.gabc", file_dir, input_name) + local gabc_file = locate_file(gabc_filename) + local gtex_filename = string.format("%s%s-%s.gtex", file_dir, cleaned_filename, internalversion:gsub("%.", "_")) + local gtex_file = locate_file(gtex_filename) local glog_file = string.format("%s%s-%s.glog", file_dir, cleaned_filename, internalversion:gsub("%.", "_")) - if not lfs.isfile(gtex_file) then + if not gtex_file then clean_old_gtex_files(file_dir..cleaned_filename) - log("The file %s does not exist. Searching for a gabc file", gtex_file) - if lfs.isfile(gabc_file) then + log("The file %s does not exist. Will use gabc file", gtex_filename) + if gabc_file then local gabc = io.open(gabc_file, 'r') if gabc == nil then err("\n Unable to open %s", gabc_file) @@ -888,14 +920,18 @@ local function include_score(input_file, force_gabccompile, allow_deprecated) else gabc:close() end - compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated) - tex.print(string.format([[\input %s\relax]], gtex_file)) + compile_gabc(gabc_file, gtex_filename, glog_file, allow_deprecated) + tex.print(string.format([[\input %s\relax]], gtex_filename)) return else - err("The file %s does not exist.", gabc_file) + err("The file %s does not exist", gabc_filename) return end end + if not gabc_file then + tex.print(string.format([[\input %s\relax]], gtex_file)) + return + end local gtex_timestamp = lfs.attributes(gtex_file).modification local gabc_timestamp = lfs.attributes(gabc_file).modification -- open the gabc file for reading so that LuaTeX records input from it @@ -930,7 +966,7 @@ local function direct_gabc(gabc, header, allow_deprecated) local f = io.open(snippet_filename, 'w') -- trims spaces on both ends (trim6 from http://lua-users.org/wiki/StringTrim) gabc = gabc:match('^()%s*$') and '' or gabc:match('^%s*(.*%S)') - f:write('name:direct-gabc;\n'..(header or '')..'\n%%\n'..gabc:gsub('\\par ', '\n')) + f:write('name:direct-gabc;\n'..(header or '')..'\n%%\n'..gabc:gsub('\\par', '\n')) f:close() local cmd = string.format([[%s -W %s-o "%%s" -l "%s" "%s"]], gregorio_exe(), deprecated, snippet_logname, snippet_filename) @@ -959,8 +995,10 @@ local function direct_gabc(gabc, header, allow_deprecated) end glog:close() end - os.remove(snippet_filename) - os.remove(snippet_logname) + if not (debug_types_activated['snippet'] or debug_types_activated['all']) then + os.remove(snippet_filename) + os.remove(snippet_logname) + end end local function get_gregoriotexluaversion() |