Commits

Jason McKesson committed c6fec6c

Spec-specific option verification.

Comments (0)

Files changed (4)

modules/CmdLineOptions.lua

 Any "options" that do not conform to option syntax are assumed to be positional arguments. They are stored in an array and returned by the function.
 ]]
 
+local util = require "util"
+
 --Returns nil if not an option. Otherwise returns the option and a possible
 --parameter name if it is of the form "--option=foo".
 local function GetOptionName(option)
 	}
 end
 
-local function InvertTable(tbl)
-	local ret = {}
-	for i, val in ipairs(tbl) do
-		ret[val] = true
-	end
-	return ret
-end
-
 function group:enum(optName, tblName, desc, values, defaultIx, optional)
 	table.insert(self._doc_order, optName)
-	local valuesInv = InvertTable(values)
+	local valuesInv = util.InvertTable(values)
 	self._procs[optName] = {
 		desc = desc,
 		tableName = tblName,

modules/GetOptions.lua

 ]]
 
 local cmd = require "CmdLineOptions"
-local styles = require "Styles"
+local util = require "util"
+local Styles = require "Styles"
+local Specs = require "Specs"
 
 local function FixupExtensionName(ext)
 	return ext
 	"style",
 	"style",
 	{"Export style."},
-	styles.GetStyleList(),
+	Styles.GetStyleList(),
 	1)
 parseOpts:enum(
 	"indent",
 function optTbl.GetOptions(cmd_line)
 	local options, pos_args = parseOpts:ProcessCmdLine(cmd_line)
 	
-	if(options.spec == "gl") then
-		--Check version/profile.
-		parseOpts:AssertParse(options.version, "You must specify an OpenGL version to export.")
+	local spec = Specs.GetSpec(options.spec)
+	
+	if(options.version) then
+		--Check the version against the allowed versions.
+		local versionTest = util.InvertTable(spec.GetCoreVersions())
+		parseOpts:AssertParse(versionTest[options.version], "The version " .. options.version .. " is not a legal version number.")
 	else
-		parseOpts:AssertParse(not options.version, "Versions cannot be specified for wgl/glX")
+		--Check to see that no versions are offered.
+		parseOpts:AssertParse(#spec.GetCoreVersions() == 0, "You cannot specify a version for the specification " .. options.spec)
 	end
 	
+	spec.VerifyOptions(options, parseOpts)
+	
+	--Load and collate the extensions.
 	options.extensions = options.extensions or {}
 	options.extfiles = options.extfiles or {}
 	

modules/Specs.lua

 
 -------------------------------------------------
 -- Spec-specific functions.
+--Validate the options.
+function gl_spec.VerifyOptions(options, parseOpts)
+	if(options.profile == "compatibility") then
+		parseOpts:AssertParse(options.version >= 3.0, "The OpenGL compatibility profile cannot be used with version " .. options.version)
+	end
+end
+
+function wgl_spec.VerifyOptions(options, parseOpts)
+	return "wgl_"
+end
+function glx_spec.VerifyOptions(options, parseOpts)
+	return "glx_"
+end
 
 --Loads the appropriate Lua .spec file.
 function gl_spec.LoadSpec() return LoadSpec.LoadLuaSpec(util.GetSpecFilePath() .. "glspec.lua", gl_spec) end
 	return FixupPath("data/");
 end
 
-return util
-
---[====[
---Works like the regular pairs, but returns the key/value pairs in a key-sorted order.
---sortFunc is the function used to compare them.
-function sortPairs(theTable, sortFunc)
-	local keyTable = {};
-	
-	for key, value in pairs(theTable) do
-		table.insert(keyTable, key);
+function util.InvertTable(tbl)
+	local ret = {}
+	for i, val in ipairs(tbl) do
+		ret[val] = true
 	end
-	
-	table.sort(keyTable, sortFunc);
-	
-	local currIndex = 1;
-	local lenTable = #keyTable;
-	
-	return function()
-		local currKey = keyTable[currIndex];
-		currIndex = currIndex + 1;
-		return currKey, theTable[currKey];
-	end
+	return ret
 end
 
---Works like ipairs, but returns the list as through it were in a sorted order.
---It even returns the "wrong" indices.
---sortFunc is the function used to compare them.
-function isortPairs(theTable, sortFunc)
-	local tempTable = {};
-	
-	for i, value in ipairs(theTable) do
-		table.insert(tempTable, value);
-	end
-	
-	table.sort(tempTable, sortFunc);
-	
-	local currIndex = 1;
-	local lenTable = #tempTable;
-	
-	return function()
-		local tempIndex = currIndex;
-		currIndex = currIndex + 1;
-		return tempIndex, theTable[tempIndex];
-	end
-end
-
---ipairs in reverse order.
-function ripairs(theTable)
-	local currIndex = #theTable;
-
-	return function()
-		local tempIndex = currIndex;
-		currIndex = currIndex - 1;
-		if(currIndex < 0) then return nil, nil; end;
-		return tempIndex, theTable[tempIndex];
-	end
-end
-
---Standard lessthan compare function. For use with the above.
-function CompLess(key1, key2)
-	return key1 < key2;
-end
-
---A combined printf and hFile:write.
-function WriteFormatted(hFile, strFormat, ...)
-	hFile:write(string.format(strFormat, ...));
-end
-
-function WriteForm(hFile, strFormat, ...)
-	hFile:write(string.format(strFormat, ...));
-end
-
-function GetIncludePath()
-	return "../include/glload/";
-end
-
-function GetSourcePath()
-	return "../source/";
-end
-
---This returns the starting part of a header's includeguard. Takes the name of the define.
-function GetFileIncludeGuardStart(defineName)
-	return string.format([[
-#ifndef %s
-#define %s
-
-]], defineName, defineName);
-end
-
---This returns the ending part of a header's includeguard. Takes the name of the define.
-function GetFileIncludeGuardEnd(defineName)
-	return string.format([[
-#endif //%s
-
-]], defineName);
-end
-
---Retrieves the beginning of the extern C block
-function GetExternCStart()
-	return [[
-#ifdef __cplusplus
-extern "C" {
-#endif //__cplusplus
-
-]]
-end
-
---Retrieves the end of the extern C block.
-function GetExternCEnd()
-	return [[
-#ifdef __cplusplus
-}
-#endif //__cplusplus
-
-]]
-end
-
---Retrieves a string for a C-style heading. Takes the name of the heading.
-function GetSectionHeading(headingName)
-	return string.format(
-[[/******************************
-* %s
-******************************/
-]], headingName);
-end
-
-]====]
+return util