diff options
author | Karl Berry <karl@freefriends.org> | 2019-09-01 21:37:14 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-09-01 21:37:14 +0000 |
commit | 53cc98ad16d1da0f9d11e72271050d64cdbc032a (patch) | |
tree | 7711f49e2e6076c44102a994ef74f77607aead96 /Build/source/texk | |
parent | b86ebaa1aaa88bc9dee6503795da8b37647f4763 (diff) |
checkcites (1sep19)
git-svn-id: svn://tug.org/texlive/trunk@52011 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk')
-rwxr-xr-x | Build/source/texk/texlive/linked_scripts/checkcites/checkcites.lua | 94 |
1 files changed, 86 insertions, 8 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/checkcites/checkcites.lua b/Build/source/texk/texlive/linked_scripts/checkcites/checkcites.lua index c6ff0e396af..349b0c1fc3d 100755 --- a/Build/source/texk/texlive/linked_scripts/checkcites/checkcites.lua +++ b/Build/source/texk/texlive/linked_scripts/checkcites/checkcites.lua @@ -211,6 +211,36 @@ local function extract(lines) return result end +-- Extracts the cross-references found +-- in lines of the bibligraphy file. +-- @param lines Line of a file. +-- @return Table containing cross-references. +local function crossref(lines) + local result, lookup, key, hit = {}, '' + for _, line in ipairs(lines) do + key, hit = string.match(line, + '^%s*%@(%w+%s*){%s*(.+),') + if key and allowed(key) then + lookup = normalize(hit) + else + key, hit = string.match(line, + '^%s*(%w+)%s*=%s*(.+)$') + if key then + key = string.lower(key) + if key == 'crossref' then + if string.sub(hit, -1) == ',' then + hit = string.sub(hit, 2, -3) + else + hit = string.sub(hit, 2, -2) + end + result[lookup] = hit + end + end + end + end + return result +end + -- Adds the extension if the file does not have it. -- @param file File. -- @param extension Extension. @@ -411,6 +441,21 @@ local function flatten(t) return result end +-- Organizes a key/value table of tables into only one table. +-- @param t Table. +-- @return Flattened key/value table. +local function organize(t) + local result = {} + for _, v in ipairs(t) do + for j, k in pairs(v) do + if not result[j] then + result[j] = k + end + end + end + return result +end + -- Applies a function to elements of a table. -- @param c Table. -- @param f Function. @@ -453,7 +498,7 @@ local operations = {} -- @param citations Citations. -- @param references References. -- @return Integer representing the status. -operations.unused = function(citations, references) +operations.unused = function(citations, references, crossrefs) print() print(pad('-', 74)) print(wrap('Report of unused references in your TeX ' .. @@ -461,6 +506,20 @@ operations.unused = function(citations, references) 'bibliography files, but not cited in ' .. 'the TeX source file)', 74)) print(pad('-', 74)) + + local z = {} + for _, citation in ipairs(citations) do + if crossrefs[citation] then + table.insert(z, crossrefs[citation]) + end + end + + for _, i in ipairs(z) do + if not exists(i, citations) then + table.insert(citations, i) + end + end + local r = difference(references, citations) print() print(wrap('Unused references in your TeX document: ' .. @@ -479,7 +538,7 @@ end -- @param citations Citations. -- @param references References. -- @return Integer value indicating the status. -operations.undefined = function(citations, references) +operations.undefined = function(citations, references, crossrefs) print() print(pad('-', 74)) print(wrap('Report of undefined references in your TeX ' .. @@ -487,6 +546,20 @@ operations.undefined = function(citations, references) 'TeX source file, but not present in the ' .. 'bibliography files)', 74)) print(pad('-', 74)) + + local z = {} + for _, citation in ipairs(citations) do + if crossrefs[citation] then + table.insert(z, crossrefs[citation]) + end + end + + for _, i in ipairs(z) do + if not exists(i, citations) then + table.insert(citations, i) + end + end + local r = difference(citations, references) print() print(wrap('Undefined references in your TeX document: ' .. @@ -505,10 +578,10 @@ end -- @param citations Citations. -- @param references References. -- @return Integer value indicating the status. -operations.all = function(citations, references) +operations.all = function(citations, references, crossrefs) local x, y - x = operations.unused(citations, references) - y = operations.undefined(citations, references) + x = operations.unused(citations, references, crossrefs) + y = operations.undefined(citations, references, crossrefs) if x + y > 0 then return 1 else @@ -555,6 +628,7 @@ local function checkcites(args) { short = 'U', long = 'undefined', argument = false }, { short = 'v', long = 'version', argument = false }, { short = 'h', long = 'help', argument = false }, + { short = 'c', long = 'crossrefs', argument = false }, { short = 'b', long = 'backend', argument = true } } @@ -596,8 +670,8 @@ local function checkcites(args) if keys['version'] or keys['help'] then if keys['version'] then print() - print(wrap('checkcites.lua, version 2.1 (dated July ' .. - '26, 2019)', 74)) + print(wrap('checkcites.lua, version 2.3 (dated September ' .. + '1, 2019)', 74)) print(pad('-', 74)) print(wrap('You can find more details about this ' .. @@ -623,6 +697,7 @@ local function checkcites(args) print('-a,--all list all unused and undefined references') print('-u,--unused list only unused references in your bibliography files') print('-U,--undefined list only undefined references in your TeX source file') + print('-c,--crossrefs enable cross-reference checks (disabled by default)') print('-b,--backend <arg> set the backend-based file lookup policy') print('-h,--help print the help message') print('-v,--version print the script version') @@ -773,6 +848,9 @@ local function checkcites(args) local references = flatten(apply(bibliography, function(a) return extract(read(a)) end)) + local crossrefs = (keys['crossrefs'] and organize(apply(bibliography, + function(a) return crossref(read(a)) end))) or {} + print() print(wrap('Fantastic, I found ' .. tostring(#references) .. ' ' .. plural(#references, 'reference', @@ -782,7 +860,7 @@ local function checkcites(args) plural(((check == 'all' and 2) or 1), 'report is', 'reports are') .. ' generated.', 74)) - return operations[check](citations, references) + return operations[check](citations, references, crossrefs) end -- Call and exit |