Jason McKesson avatar Jason McKesson committed 3a63fe0

Issue #43: Updated copyright info.

Comments (0)

Files changed (4)

 - The version number of the tutorials.
 ]]--
 
+require("ex")
+require "ufs"
 require "lfs"
+require "_FindFileInPath"
 
-local destDir, hgChangelist, versionNum = ...
+local baseDir, hgChangelist, versionNum = ...
 
---local test = {...}
---print(#test, ...)
-assert(#({...}) == 3, "Not enough commandline parameters. You provided: " .. #({...}));
+if(#({...}) ~= 3) then
+	print("Not enough commandline parameters. You provided: " .. #({...}));
+	print("Paramters:")
+	print("\tDestination dir, relative to this path.")
+	print("\tMercurial revision to archive.")
+	print("\tVersion number of the SDK.")
+	return
+end
 
+local buildDirname = "graph_tuts_" .. versionNum
+
+lfs.mkdir(baseDir);
+local pathDestDir = ufs.path(baseDir) / buildDirname;
+local destDir = tostring(pathDestDir);
 lfs.mkdir(destDir);
 
+local pathCurrent = ufs.current_path();
+local pathDest = pathCurrent / destDir;
+local pathBase = pathCurrent / baseDir;
 
 -------------------------------------------
--- Use the other Lua script to copy the HTML to the destination.
+-- Use the other Lua script to copy the HTML and PDFs to the destination.
 local CopyWebsite = assert(loadfile("CopyWebsite.lua"));
-CopyWebsite(destDir .. "\\html\\");
+--CopyWebsite(destDir .. "\\html\\");
 
 --Generate the PDF files.
-lfs.mkdir("pdfs");
-
+local pdfOutDir = "..\\..\\" .. destDir .. "\\"
 local cwd = lfs.currentdir();
 lfs.chdir("Documents\\Build");
 local BuildPrintBW = assert(loadfile("BuildPrintBWFO.lua"));
-BuildPrintBW(cwd .. "\\pdfs\\");
+--BuildPrintBW(pdfOutDir);
 local BuildKindleFO = assert(loadfile("BuildKindleFO.lua"));
-BuildKindleFO(cwd .. "\\pdfs\\");
+--BuildKindleFO(pdfOutDir);
 local BuildComputerFO = assert(loadfile("BuildComputerFO.lua"));
-BuildComputerFO(cwd .. "\\pdfs\\");
+--BuildComputerFO(pdfOutDir);
 lfs.chdir(cwd);
 
---------------------------------------------
--- Copy other files.
-os.execute(string.format([[copy "pdfs\TutorialsPrintBW.pdf" "%s\"]], destDir));
-os.execute(string.format([[copy "pdfs\TutorialsKindle.pdf" "%s\"]], destDir));
-os.execute(string.format([[copy "pdfs\TutorialsComp.pdf" "%s\"]], destDir));
-
 ------------------------------------------
 -- Use Mercurial to get a version in the destination directory.
 local clone = [[hg archive -r "%s" "%s"]];
 print(clone);
 os.execute(clone);
 
+---------------------------------------------------------------
+-- Apply Copyright Info
+local luaFilename = "lua.exe"
+local pathLua = ufs.path(FindFileInPath(luaFilename))
+local luaCopyScriptName = "make_copyright.lua"
+
+if(pathLua:empty()) then
+	print("Could not find Lua. Since this is a Lua script, that's kinda confusing...");
+	return;
+end
+
+local copyProc = ex.spawn(tostring(pathLua),
+	{args={luaCopyScriptName, tostring(pathDest)}});
+copyProc:wait(copyProc);
+
 -------------------------------------------
 -- Generate the ancillary files
 
 printer. TutorialsKindle.pdf is a PDF that is sized specifically for the screen
 of the Kindle 2.
 
-The source of the documentation is found in the Documents directory. This
-source documentation is in the DocBook 5 format. All other formats were
-generated automatically from these source files.
-
 The License.txt file contains the licensing information for the materials distributed in these tutorials.
 ]===], versionNum))
 readme:close()
 local index_html = io.open(destDir .. "\\index.html", "wt");
 index_html:write(
 [===[
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html>
+<head>
+	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+	<meta HTTP-EQUIV="REFRESH" content="0; url=html/index.html"/>
+</head>
 <body>
-<h1>OpenGL Tutorials</h1>
-<p><a href="html/index.html">HTML Tutorials</a></p>
 </body>
-</html>
 ]===]
 )
 index_html:close();
 
+------------------------------------------------------------
+-- Delete select files from the destination location.
+local toDelete =
+{
+	--files
+	--Distro building
+	"BuildDistro.lua", "CopyWebsite.lua",
+	"_FindFileInPath.lua", "file_copyright_info.lua", "make_copyright.lua",
+	--Mercurial
+	".hgignore", ".hgtags", ".hg_archival.txt",
+	--directories
+	"glimg\\Test", "glload\\Test", "glload\\codegen",
+	"Documents",
+}
 
 
+for i, filename in ipairs(toDelete) do
+	local pathFile = pathDest / filename;
+	print("deleting:", pathFile);
+	ufs.remove_all(pathFile);
+end
 
+------------------------------------------------------------
+-- Create Zip archive of the distro.
+local szFilename = "7z.exe"
+local archiveName = buildDirname .. ".7z"
+local pathSZ = ufs.path(FindFileInPath(szFilename))
 
+if(pathSZ:empty()) then
+	print("Could not find 7zip.");
+	return;
+end
 
+ufs.current_path(pathBase);
 
+local depProc = ex.spawn(tostring(pathSZ),
+	{args={"a", "-r", archiveName, buildDirname}});
+depProc:wait(depProc);
 
+------------------------------------------------------------
+-- Destroy the directory.
+ufs.remove_all(pathDest);
+
+
+
+
+
+
+
+
+

_FindFileInPath.lua

+
+require("ex")
+require "ufs"
+
+function FindFileInPath(filename)
+	local path = ex.getenv("PATH");
+
+	for pathname in path:gmatch("([^%;%\"]+)%;?") do
+		pathname = ufs.path(pathname);
+		
+		local testName = pathname / filename;
+		
+		if(ufs.exists(testName)) then
+			return tostring(testName);
+		end
+	end
+	
+	return nil;
+end
+
+

make_copyright.lua

+--The current directory should be the base SDK directory.
+
+require "lfs"
+require "ufs"
+
+dofile("file_copyright_info.lua")
+
+local alwaysIgnorePattern =
+{
+	"stb_image%.c$",
+	"stb_image%.h$",
+}
+
+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
+
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.