summaryrefslogtreecommitdiff
path: root/Master/tlpkg/archive/lua/texlive/utils.tlu
blob: a31475b351c72c08cb63e3252dbd2f503db4f6c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- texlive/utils.tlu
-- $Id$
-- 
-- Copyright (C) 2008 Reinhard Kotucha, Norbert Preining
-- You may freely use, modify and/or distribute this file.
--
-- general utilities for TeX Live lua scripts

function setupperl()
  -- For Windows we use the shipped perl interpreter, otherwise we expect
  -- a perl to be installed
  local perlbin
  if os.type == 'windows' then
    perlbin=TEXDIR..'/tlpkg/tlperl/bin/perl.exe'
    os.setenv('PERL5LIB', TEXDIR..'/tlpkg/tlperl/lib')
  else
    perlbin = 'perl'
  end
  return perlbin
end

function findscript(scriptname)
  local script = kpse.find_file(scriptname, 'texmfscripts')
  if script then
    return script
  else
    io.stderr:write(filename..': Cannot find script '..scriptname)
    return false
  end
end

-- fix arguments for windows
function fixwin(args_unix)
   if os.type == 'windows' then
      local args_win={}  -- new table
      args_win[0]=args_unix[1]
      for i=1, #args_unix do  
         args_win[i]='"'..args_unix[i]..'"'
      end
      return args_win
   else
      return args_unix
   end
end

function rmtree (path)
  if lfs.isdir(path) then
    for file in lfs.dir(path) do
      if file ~= '.' and file ~= '..' then
        local f = path..'/'..file
        if lfs.isdir(f) then
          rmtree(f)
          lfs.rmdir(f)
        else
          os.remove(f)
        end
      end
    end
    lfs.rmdir(path)
  end
end


function list (t)
    local i = 0
    return function ()
        i = i + 1
        return t[i]
    end
end


-- Local Variables:
-- lua-indent-level: 2
-- tab-width: 2
-- indent-tabs-mode: nil
-- End:
-- vim:set tabstop=2 expandtab: #