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
|
#!/usr/bin/env texlua
--[===[--
whatsnew.lua -- Scan Context for changes in Lua libraries.
Part of the Lualibs package.
https://github.com/lualatex/lualibs
Copyright 2013 Philipp Gesang
License: GPL v2.0
--]===]--
-----------------------------------------------------------------------
--- configuration
-----------------------------------------------------------------------
local prefixsep = "-"
local namespace = "lualibs"
local luasuffix = ".lua"
local basedir = "/home/phg/context/tex/texmf-context/tex/context/base"
local cmd_diff = [[diff "%s" "%s"]]
-----------------------------------------------------------------------
--- locals
-----------------------------------------------------------------------
local iopopen = io.popen
local stringexplode = string.explode
local stringformat = string.format
local stringsub = string.sub
local tableunpack = table.unpack
-----------------------------------------------------------------------
--- files
-----------------------------------------------------------------------
--- (prefix, keep) hash_t
local namespaces = { { "l" , false },
{ "util" , true },
{ "trac" , true }, }
--- (prefix, name list) hash_t
local filenames = {
["l"] = {
"boolean",
"dir",
"file",
"function",
"gzip",
"io",
"lpeg",
"lua",
"math",
"md5",
"number",
"os",
"package",
"set",
"string",
"table",
"unicode",
"url",
},
["trac"] = { "inf" },
["util"] = {
"deb",
"dim",
"jsn",
"lua",
"prs",
"sta",
"sto",
"str",
"tab",
"tpl",
},
}
-----------------------------------------------------------------------
--- helpers
-----------------------------------------------------------------------
--- string -> string -> bool -> (string, string)
local mknames = function (pfx, name, keeppfx)
local libname = basedir .. "/" .. pfx
.. prefixsep .. name .. luasuffix
local ourname = prefixsep .. name .. luasuffix
if keeppfx == true then
ourname = prefixsep .. pfx .. ourname
end
ourname = namespace .. ourname
ourname = "./" .. ourname
return ourname, libname
end
--- string -> (int * int)
local count_changes = function (str)
local added, removed = 0, 0
for n, line in next, stringexplode(str, "\n") do
local first = stringsub(line, 1, 1)
if first == "<" then
removed = removed + 1
elseif first == ">" then
added = added + 1
end
end
return added, removed
end
--- string -> string -> (int * int)
local run_diff = function (f1, f2)
local cmd = stringformat(cmd_diff, f1, f2)
local res = iopopen(cmd, "r")
local dat = res:read"*all"
res:close()
return count_changes(dat)
end
-----------------------------------------------------------------------
--- main
-----------------------------------------------------------------------
local libs_done = 0
local total_added = 0
local total_removed = 0
for n, namespace in next, namespaces do
local pfx, keeppfx = tableunpack(namespace)
local libs = filenames[pfx]
for i=1, #libs do
libs_done = libs_done + 1
local current = libs[i]
local from, to = mknames(pfx, current, keeppfx)
if lfs.isfile(from) and lfs.isfile(to) then
local added, removed = run_diff (from, to)
if added > 0 or removed > 0 then
total_added = total_added + added
total_removed = total_removed + removed
print(stringformat(
"(library %q (plus %d) (minus %d))",
from, added, removed
))
end
else
if not lfs.isfile(from) then
print("cannot read file", from)
elseif not lfs.isfile(to) then
print("cannot read file", to)
end
goto fail
end
end
end
::done::
if total_added == 0 and total_removed == 0 then
print "stagnation"
else
print(stringformat(
"(progress (n-files %d) (added %d) (removed %d))",
libs_done, total_added, total_removed
))
end
os.exit(0)
::fail::
print "fatal error"
os.exit(1)
|