Debian Codegraph @

texk/texlive/linked_scripts/runtexshebang/runtexshebang.lua

raw symbols SCIP
1 #!/usr/bin/env texlua
2
3 -- This program is licensed under the terms of the MIT License.
4 --
5 -- Copyright (c) 2021-2023 Munehiro Yamamoto <[email protected]>
6 --
7 -- Permission is hereby granted, free of charge, to any person obtaining a copy
8 -- of this software and associated documentation files (the "Software"), to deal
9 -- in the Software without restriction, including without limitation the rights
10 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 -- copies of the Software, and to permit persons to whom the Software is
12 -- furnished to do so, subject to the following conditions:
13 --
14 -- The above copyright notice and this permission notice shall be included in
15 -- all copies or substantial portions of the Software.
16 --
17 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 -- THE SOFTWARE.
24
25 NAME = "runtexshebang"
26 VERSION = "20231117 v0.5"
27 USAGE = [[
28 Usage: runtexshebang [input.tex]
29
30 Options:
31 --dry-run print the TeX-style shebang line of [input.tex]
32 -h, --help print help
33 -v, --version print version
34
35 See also:
36 The command
37 texdoc runtexshebang
38 should give you access to the README.
39 ]]
40
41 function whoami()
42 print(NAME .. " " .. VERSION)
43 end
44
45 function help()
46 whoami()
47 print()
48 print(USAGE)
49 end
50
51 if #arg == 0 then
52 help()
53 os.exit(0)
54 end
55
56 --
57 is_dryrun = false
58 texfilename = ""
59 narg = 1
60 repeat
61 this_arg = arg[narg]
62 -- replace double dash by single dash at the beginning
63 this_arg = string.gsub(this_arg, "^%-%-", "-")
64
65 if this_arg == "-h" or this_arg == "-help" then
66 help()
67 os.exit(0)
68 elseif this_arg == "-v" or this_arg == "-version" then
69 whoami()
70 os.exit(0)
71 elseif this_arg == "-dry-run" then
72 is_dryrun = true
73 else
74 texfilename = this_arg
75 end --if this_arg == ...
76 narg = narg+1
77 until narg > #arg
78
79 -- main process
80 whoami()
81
82 if ( texfilename == "" ) then
83 print("No filename argument given, exiting.\n")
84 os.exit(1)
85 end
86
87 line_ctr = 0
88 for line in io.lines(texfilename) do
89 line_ctr = line_ctr + 1
90 if line_ctr > 20 then break end
91
92 if string.match(line, "^%%#!") then
93 tex_cmd, err=string.gsub(line, "%%#!", "")
94
95 if is_dryrun then
96 print(tex_cmd .. "\n")
97 os.exit(0)
98 end
99
100 tex_return = os.execute(tex_cmd)
101
102 -- if os.execute(texcmd) returns -1 on Windows, then
103 -- cmd.exe is not included in PATH, or some invalid string found before cmd.exe
104 if os.type == 'windows' and tex_return == -1 then
105 print("Invalid PATH setting found. Please ensure that cmd.exe can be found.\n")
106 os.exit(1)
107 end
108
109 -- if not tex_return == 0 then
110 -- print("TeX-style shebang processing of the below failed.\n" .. tex_cmd .. "\n")
111 -- os.exit(1)
112 -- end
113
114 os.exit(0)
115
116 -- else
117 -- print("TeX-style shebang not matched.\n")
118 end
119 end
120
121 print("TeX-style shebang not found.\n")
122 os.exit(2)