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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#!/usr/bin/env texlua
--*-Lua-*-
-- $Id$
-- Copyright (C) 2015 Reinhard Kotucha.
-- You may freely use, modify and/or distribute this file.
kpse.set_program_name('texlua')
local function qquote (s)
-- doublequote string
return '"'..s..'"'
end
local function action (s)
-- print message and return string with padding
local msg=s..' ...'
local done='[done]'
io.write(msg)
local padding=string.rep(' ', 77-string.len(msg)-string.len(done))
return string.format('%s%s', padding, done)
end
local function get_path (envvar)
-- get environment variable
local path=os.getenv(envvar)
if not path then
error('Environment Variable '..envvar..' not set.')
end
-- we can't use backslashes in the config file
path=path:gsub('\\', '/')
-- remove trailing slash if present
if path:match('/$') then path=path:gsub('/$', '') end
--check path
if not lfs.isdir(path) then
error('Path '..qquote(path)..' doesn\'t esist.')
end
return path
end
local function find_datafile (file)
-- locate data file
local format='TeX system documentation'
local datafile=kpse.find_file(file, format)
-- check
if not datafile then
error('File '..file..' not found. Did you run mktexlsr?')
end
return datafile
end
local function install_data (source, targetdir)
-- create target directory and extract zip file
if not lfs.isdir (targetdir) then
assert(lfs.mkdir(targetdir),
"Can't create directory "..targetdir..': Permission denied.')
end
-- os.execute() doesn't quote arguments automatically
local cmd='unzip -q -o -d "'..targetdir..'" "'..source..'"'
local retval=os.execute(cmd)
if retval ~= 0 then
error('unzip.exe returned error code '..retval..'.')
end
end
local function write_xpdfrc (FILE, datadir, xpdfrc_raw)
local xpdfrc=xpdfrc_raw:explode('\n')
for _,line in ipairs (xpdfrc) do
line=line:gsub('%s+', ' ')
line=line:gsub('@XPDF%-DATA%-DIR@', datadir)
if line:match('#----- begin') then FILE:write('\n') end
FILE:write(line..'\n')
end
end
local xpdfrc=[===[
# xpdfrc (for xpdf utilities)
#
# This file was created by install-xpdf-data. Don't edit
#
#----- begin Arabic support package (2011-sep-02)
unicodeMap ISO-8859-6 "@XPDF-DATA-DIR@/arabic/ISO-8859-6.unicodeMap"
#----- end Arabic support package
#----- begin Chinese Simplified support package (2011-sep-02)
cidToUnicode Adobe-GB1 "@XPDF-DATA-DIR@/chinese-simplified/Adobe-GB1.cidToUnicode"
unicodeMap ISO-2022-CN "@XPDF-DATA-DIR@/chinese-simplified/ISO-2022-CN.unicodeMap"
unicodeMap EUC-CN "@XPDF-DATA-DIR@/chinese-simplified/EUC-CN.unicodeMap"
unicodeMap GBK "@XPDF-DATA-DIR@/chinese-simplified/GBK.unicodeMap"
cMapDir Adobe-GB1 "@XPDF-DATA-DIR@/chinese-simplified/CMap"
toUnicodeDir "@XPDF-DATA-DIR@/chinese-simplified/CMap"
#fontFileCC Adobe-GB1 c:/windows/fonts/gkai00mp.ttf
#----- end Chinese Simplified support package
#----- begin Chinese Traditional support package (2011-sep-02)
cidToUnicode Adobe-CNS1 "@XPDF-DATA-DIR@/chinese-traditional/Adobe-CNS1.cidToUnicode"
unicodeMap Big5 "@XPDF-DATA-DIR@/chinese-traditional/Big5.unicodeMap"
unicodeMap Big5ascii "@XPDF-DATA-DIR@/chinese-traditional/Big5ascii.unicodeMap"
cMapDir Adobe-CNS1 "@XPDF-DATA-DIR@/chinese-traditional/CMap"
toUnicodeDir "@XPDF-DATA-DIR@/chinese-traditional/CMap"
#fontFileCC Adobe-CNS1 c:/windows/fonts/bkai00mp.ttf
#----- end Chinese Traditional support package
#----- begin Cyrillic support package (2011-aug-15)
nameToUnicode "@XPDF-DATA-DIR@/cyrillic/Bulgarian.nameToUnicode"
unicodeMap KOI8-R "@XPDF-DATA-DIR@/cyrillic/KOI8-R.unicodeMap"
#----- end Cyrillic support package
#----- begin Greek support package (2011-aug-15)
nameToUnicode "@XPDF-DATA-DIR@/greek/Greek.nameToUnicode"
unicodeMap ISO-8859-7 "@XPDF-DATA-DIR@/greek/ISO-8859-7.unicodeMap"
#----- end Greek support package
#----- begin Hebrew support package (2011-aug-15)
unicodeMap ISO-8859-8 "@XPDF-DATA-DIR@/hebrew/ISO-8859-8.unicodeMap"
unicodeMap Windows-1255 "@XPDF-DATA-DIR@/hebrew/Windows-1255.unicodeMap"
#----- end Hebrew support package
#----- begin Japanese support package (2011-sep-02)
cidToUnicode Adobe-Japan1 "@XPDF-DATA-DIR@/japanese/Adobe-Japan1.cidToUnicode"
unicodeMap ISO-2022-JP "@XPDF-DATA-DIR@/japanese/ISO-2022-JP.unicodeMap"
unicodeMap EUC-JP "@XPDF-DATA-DIR@/japanese/EUC-JP.unicodeMap"
unicodeMap Shift-JIS "@XPDF-DATA-DIR@/japanese/Shift-JIS.unicodeMap"
cMapDir Adobe-Japan1 "@XPDF-DATA-DIR@/japanese/CMap"
toUnicodeDir "@XPDF-DATA-DIR@/japanese/CMap"
#fontFileCC Adobe-Japan1 c:/windows/fonts/msmincho.ttf
#----- end Japanese support package
#----- begin Korean support package (2011-sep-02)
cidToUnicode Adobe-Korea1 "@XPDF-DATA-DIR@/korean/Adobe-Korea1.cidToUnicode"
unicodeMap ISO-2022-KR "@XPDF-DATA-DIR@/korean/ISO-2022-KR.unicodeMap"
cMapDir Adobe-Korea1 "@XPDF-DATA-DIR@/korean/CMap"
toUnicodeDir "@XPDF-DATA-DIR@/korean/CMap"
#fontFileCC Adobe-Korea1 c:/windows/fonts/batang.ttf
#fontFileCC Unidocs-Korea1 c:/windows/fonts/batang.ttf
#----- end Korean support package
#----- begin Latin2 support package (2011-aug-15)
unicodeMap Latin2 "@XPDF-DATA-DIR@/latin2/Latin2.unicodeMap"
#----- end Latin2 support package
#----- begin Thai support package (2011-aug-15)
nameToUnicode "@XPDF-DATA-DIR@/thai/Thai.nameToUnicode"
unicodeMap TIS-620 "@XPDF-DATA-DIR@/thai/TIS-620.unicodeMap"
#----- end Thai support package
#----- begin Turkish support package (2011-aug-15)
unicodeMap ISO-8859-9 "@XPDF-DATA-DIR@/turkish/ISO-8859-9.unicodeMap"
#----- end Turkish support package
]===]
-- main --
local datafile=find_datafile('xpdfutil-supp.zip')
local xpdf_datadir=get_path('APPDATA')..'/xpdfutil'
local xpdf_config =get_path('USERPROFILE')..'/xpdfrc'
print('Source: '..qquote(datafile))
print('Directory for Data Files: '..qquote(xpdf_datadir))
print('Config File: '..qquote(xpdf_config))
print()
local done=action('Extracting Data Files')
install_data(datafile, xpdf_datadir)
print(done)
local done=action('Installing Config File')
local CONF=assert(io.open(xpdf_config, 'wb'),
"Can't open file "..qquote(xpdf_config))
write_xpdfrc(CONF, xpdf_datadir, xpdfrc)
io.close(CONF)
print(done)
print('Done.')
-- Local Variables:
-- lua-indent-level: 2
-- tab-width: 2
-- indent-tabs-mode: nil
-- End:
-- vim:set tabstop=2 expandtab: #
|