forked from paroj/gltut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_copyright.lua
92 lines (75 loc) · 2.01 KB
/
make_copyright.lua
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
--The current directory should be the base SDK directory.
require "lfs"
require "ufs"
dofile("file_copyright_info.lua")
local alwaysIgnorePattern =
{
"rapidxml.*%.hpp$",
}
local function CopywriteFile(filename)
for i, ignore in ipairs(alwaysIgnorePattern) do
if(filename:match(ignore)) then
return
end
end
local hInFile = io.open(filename, "rt");
local fileData = hInFile:read("*a");
hInFile:close();
local hOutFile = io.open(filename, "wt");
if(filename:match("%.c$") or filename:match("%.h$")) then
hOutFile:write("/** ", copywriteText, " **/\n");
hOutFile:write("/** ", licenseText, " **/\n");
elseif(filename:match("%.cpp$") or filename:match("%.hpp$")) then
hOutFile:write("//", copywriteText, "\n");
hOutFile:write("//", licenseText, "\n");
else
--???
end
hOutFile:write("\n\n", fileData);
hOutFile:close();
end
local searchPathsToMarkup =
{
"Test",
"framework",
}
local acceptedExtensions = {"cpp", "c", "h", "hpp"}
local function CopywriteDirectory(testPath)
local pathBase = ufs.path(testPath);
for file in lfs.dir(testPath) do
for i, testExt in ipairs(acceptedExtensions) do
if(file:match("%." .. testExt .. "$")) then
CopywriteFile(tostring(pathBase / file));
break;
end
end
end
end
local baseDir = ...;
baseDir = baseDir or ".";
local pathBaseDir = ufs.path(baseDir)
for i, testPath in ipairs(searchPathsToMarkup) do
testPath = tostring(pathBaseDir / testPath)
local mode = lfs.attributes(testPath, "mode");
if(mode == "directory") then
CopywriteDirectory(testPath)
elseif(mode == "file") then
CopywriteFile(testPath);
else
print(testPath, "Is a:", mode);
end
end
local dirPatterns =
{
"^Tut %d%d",
}
for testPath in lfs.dir(baseDir) do
local mode = lfs.attributes(testPath, "mode");
if(mode == "directory") then
for i, pattern in ipairs(dirPatterns) do
if(testPath:match(pattern)) then
CopywriteDirectory(tostring(pathBaseDir / testPath))
end
end
end
end