unsupported ?÷#!/usr/bin/env texlua -- ----------------------------------------------------------------- -- checkcites.lua -- Copyright 2012, 2019, Enrico Gregorio, Paulo Cereda -- Copyright 2022, Enrico Gregorio, Island of TeX -- -- This work may be distributed and/or modified under the conditions -- of the LaTeX Project Public License, either version 1.3 of this -- license or (at your option) any later version. -- -- The latest version of this license is in -- -- http://www.latex-project.org/lppl.txt -- -- and version 1.3 or later is part of all distributions of LaTeX -- version 2005/12/01 or later. -- -- This work has the LPPL maintenance status `maintained'. The -- current maintainers of this work are the Island of TeX. This -- work consists of the file checkcites.lua. -- -- Project repository: https://gitlab.com/islandoftex/checkcites -- ----------------------------------------------------------------- -- Checks if the table contains the element. -- @param a Table. -- @param hit Element. -- @return Boolean value if the table contains the element. local function exists(a, hit) for _, v in ipairs(a) do if v == hit then return true end end return false end -- Parses the list of arguments based on a configuration map. -- @param map Configuration map. -- @param args List of command line arguments. -- @return Table containing the valid keys and entries. -- @return Table containing the invalid keys. local function parse(map, args) local keys, key, unknown = {}, 'unpaired', {} local a, b for _, v in ipairs(args) do a, _, b = string.find(v, '^%-(%w)$') if a then for _, x in ipairs(map) do key = 'unpaired' if x['short'] == b then key = x['long'] break end end if key == 'unpaired' then table.insert(unknown, '-' .. b) end if not keys[key] then keys[key] = {} end else a, _, b = string.find(v, '^%-%-([%w-]+)$') if a then for _, x in ipairs(map) do key = 'unpaired' if x['long'] == b then key = b break end end if key == 'unpaired' then if not exists(unknown, '--' .. b) then table.insert(unknown, '--' .. b) end end if not keys[key] then keys[key] = {} end else if not keys[key] then keys[key] = {} end if key ~= 'unpaired' then for _, x in ipairs(map) do if x['long'] == key then if not (x['argument'] and #keys[key] == 0) then key = 'unpaired' end break end end if not keys[key] then keys[key] = {} end table.insert(keys[key], v) else if not keys[key] then keys[key] = {} end table.insert(keys[key], v) end end end end return keys, unknown end -- Calculates the difference between two tables. -- @param a First table. -- @param b Second table. -- @return Table containing the difference between two tables. local function difference(a, b) local result = {} for _, v in ipairs(a) do if not exists(b, v) then table.insert(result, v) end end return result end -- Splits the string based on a pattern. -- @param str String. -- @param pattern Pattern. local function split(str, pattern) local result = {} string.gsub(str, pattern, function(a) table.insert(result, a) end) return result end -- Reads lines from a file. -- @param file File. -- @returns Table representing the lines. local function read(file) local handler = io.open(file, 'r') local lines = {} if handler then for line in handler:lines() do table.insert(lines, line) end handler:close() end return lines end -- Gets a pluralized word based on a counter. -- @param i Counter. -- @param a Word in singular. -- @param b Word in plural. -- @return Eithe