Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
#!/usr/bin/env lua51
-- This file:
-- http://angg.twu.net/LUA/flsfiles.lua
-- http://angg.twu.net/LUA/flsfiles.lua.html
--  (find-angg        "LUA/flsfiles.lua")
--
-- flsfile.lua: extract the important files from a ".fls" file.
--
-- The manpage for (recent versions of) tex says:
--
--     -recorder
--
--        Enable the filename recorder. This leaves a trace of the
--        files opened for input and output in a file with extension
--        .fls.
--
-- If we run "lualatex -record foo.tex" it produces a "foo.fls" file
-- that lists all the files that were opened and closed, in a complex
-- format that includes information about which file opened each other
-- one (?). This script converts that to a simple list of files,
-- without repetitions, that is suitable to be used by tar like this:
--
--     tar -cvzf foo.src.tgz $(flsfiles.lua foo.fls | grep -v "^/")
--
-- the resulting "foo.src.tgz" file contains all the non-system-wide
-- files needed to build foo.tex.
--
-- See: (find-es "tex" "latex-recorder")
--      (find-angg ".zshrc" "flsfiles")
--      (find-TH "luatex" "flsfiles")
-- Eduardo Ochs, 2016feb17 / 2018jul24
-- Public domain.

--                                 _     _      
--  _ __  _ __ ___  __ _ _ __ ___ | |__ | | ___ 
-- | '_ \| '__/ _ \/ _` | '_ ` _ \| '_ \| |/ _ \
-- | |_) | | |  __/ (_| | | | | | | |_) | |  __/
-- | .__/|_|  \___|\__,_|_| |_| |_|_.__/|_|\___|
-- |_|                                          
--
-- Some functions from my Lua init file.
-- See: http://angg.twu.net/LUA/lua50init.lua.html
--      http://angg.twu.net/LUA/lua50init.lua
--       (find-angg        "LUA/lua50init.lua")
--       (find-es "lua5" "getdefs")
-- 
ee_expand = function (path)
    path = string.gsub(path, "^~$", "$HOME/", 1)
    path = string.gsub(path, "^~/", "$HOME/", 1)
    path = string.gsub(path, "^%$(%w+)", os.getenv, 1)
    return path
  end
readfile = function (fname)
    local f = assert(io.open(fname, "r"))
    local bigstr = f:read("*a")
    f:close()
    return bigstr
  end
ee_readfile  = function (fname) return readfile(ee_expand(fname)) end
split = function (str, pat)
    local arr = {}
    string.gsub(str, pat or "([^%s]+)", function (word)
        table.insert(arr, word)
      end)
    return arr
  end
keys = function (tbl)
    local ks = {}
    for k,_ in pairs(tbl) do table.insert(ks,k) end
    return ks
  end
sorted = function (tbl, lt) table.sort(tbl, lt); return tbl end

Class = {
    type   = "Class",
    __call = function (class, o) return setmetatable(o, class) end,
  }
setmetatable(Class, Class)

Set = Class {
  type    = "Set",
  new = function () return Set {_={}} end,
  from = function (L) return Set.fromarray(L) end,
  fromarray = function (L)
      local C = Set.new()
      for i,v in ipairs(L) do C._[v]=v end
      return C
    end,
  __add = function (A, B)   -- union
      local C = Set.new()
      for k,v in pairs(A._) do C._[v]=v end
      for k,v in pairs(B._) do C._[v]=v end
      return C
    end,
  __sub = function (A, B)   -- difference
      local C = Set.new()
      for k,v in pairs(A._) do C._[v]=v end
      for k,v in pairs(B._) do C._[v]=nil end
      return C
    end,
  __mul = function (A, B)     -- intersection
      local C = Set.new()
      for k,v in pairs(A._) do if B._[v] then C._[v]=v end end
      return C
    end,
  __len = function (A) return #(keys(A._)) end,  -- number of elements
  __tostring = function (A)
      return "(Set with "..A:n().." elements)"
    end,
  --
  -- Methods
  __index = {
    has = function (A, k) return A._[k] end,
    n   = function (A) return #keys(A._) end,
    k   = function (A) return  keys(A._) end,
    ks  = function (A) return sorted(keys(A._)) end,
    ksc = function (A, sep) return table.concat(A:ks(), sep or "\n") end,
    gen = function (A)
        return cow(function ()
            for i,v in ipairs(A:ks()) do coy(v) end
          end)
      end,
    add = function (A, key, val)
        A._[key] = val or key
        return A
      end,
    del = function (A, key)
        A._[key] = nil
        return A
      end,
  },
}
coy = coroutine.yield
cow = coroutine.wrap


--  _               _       
-- | |__   ___   __| |_   _ 
-- | '_ \ / _ \ / _` | | | |
-- | |_) | (_) | (_| | |_| |
-- |_.__/ \___/ \__,_|\__, |
--                    |___/ 

flsfiles_nontrivial0 = function (bigstr)
    return cow(function ()
        for li in bigstr:gmatch "[^\n]+" do
          local fn = li:match("^INPUT (.*)")
          if fn and
             not fn:match "/usr/share/" and
             not fn:match "/%.texmf%-var/" and
             not fn:match "%.aux$" and
             not fn:match "%.out$" and
             true
          then
            if fn:match "^%./" then fn = fn:sub(3) end
            coy(fn)
          end
        end
      end)
  end
flsfiles_nontrivial = function (fname)
    return flsfiles_nontrivial0(ee_readfile(fname))
  end
flsfiles_nontrivialset = function (fname)
    local s = Set:new()
    for fn in flsfiles_nontrivial(fname) do s:add(fn) end
    return s
  end

local fname = ...
if fname then
  local s = flsfiles_nontrivialset(fname)
  print(s:ksc())
end

--[[
-- Tests etc
-- (find-LATEX "2015-2-GA-P1-gab.tex")
-- (find-LATEX "2015-2-GA-P1-gab.fls")
-- (find-LATEX "2015-2-GA-P1-gab.files")

* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "flsfiles.lua"
s = flsfiles_nontrivialset "~/LATEX/2015-2-GA-P1-gab.fls"
= s:ksc()
= s:del("/home/edrx/dednat6/dednat6.lua"):ksc()

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd /tmp/
cp -v ~/LATEX/2017planar-has-1.fls /tmp/
export LUA_INIT=
lua5.1 ~/LUA/flsfiles.lua 2017planar-has-1.fls
lua5.1 ~/LUA/flsfiles.lua 2017planar-has-1.fls | grep -v "^/"

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
~/LUA/flsfiles.lua ~/LATEX/2015-2-GA-P1-gab.fls |
  grep -v "^/" |
  tee ~/LATEX/2015-2-GA-P1-gab.files

cd ~/LATEX/
zip 2015-2-GA-P1-gab.zip $(~/LUA/flsfiles.lua 2015-2-GA-P1-gab.fls | grep -v "^/")
tar -cvzf 2015-2-GA-P1-gab.tgz $(~/LUA/flsfiles.lua 2015-2-GA-P1-gab.fls | grep -v "^/")
tar -cvzf 2015-2-GA-P1-gab.tgz $(flsfiles 2015-2-GA-P1-gab.fls | grep -v "^/")

# (find-angg ".zshrc" "flsfiles")
cd ~/LATEX/
flsfiles     2015-2-GA-P1-gab.fls
flsfiles-tgz 2015-2-GA-P1-gab.fls 2015-2-GA-P1-gab.tgz
flsfiles-zip 2015-2-GA-P1-gab.fls 2015-2-GA-P1-gab.zip

~/LUA/flsfiles.lua ~/LATEX/2015-2-GA-P1-gab.fls |
  grep -v "^/" |
  tee ~/LATEX/2015-2-GA-P1-gab.files

rm -v   /tmp/z.zip
rm -Rfv /tmp/z/
mkdir   /tmp/z/
cd ~/LATEX/
zip     /tmp/z.zip $(cat 2015-2-GA-P1-gab.files)
cd      /tmp/z/
unzip -d /tmp/z/ /tmp/z.zip
lualatex 2015-2-GA-P1-gab.tex

# (find-fline "/tmp/")
# (find-fline "/tmp/z/")
# (find-fline "/tmp/z.zip")
# (find-man "unzip")
# (find-sh "cd /tmp/z/ && grep diagxy $(find * -type f)")
# (find-sh "cd /tmp/z/ && grep edrxdnt $(find * -type f)")


--]]


-- Local Variables:
-- coding: raw-text-unix
-- End: