Commits

Jason McKesson committed 9865828

Extension file loading now is relative to various directories.

Comments (0)

Files changed (2)

modules/GetOptions.lua

 	"Base filename (sans extension)",
 	"outname")
 	
-local function LoadExtFile(extensions, extfilename)
+local function LoadExtFile(extensions, extfilename, baseDir)
+	if(baseDir) then
+		extfilename = baseDir .. extfilename
+	end
 	local hFile = assert(io.open(extfilename, "rt"), "Could not find the file " .. extfilename)
 	
 	for line in hFile:lines() do
 		local ext = line:match("(%S+)")
 		if(ext) then
 			if(ext == "#include") then
-				local file = line:match('%#include [%"%<](.+)[%"%>]')
+				local file = line:match('%#include [%"](.+)[%"]')
 				assert(file, "Bad #include statement in extension file " ..
 					extfilename)
 				if(file) then
-					--Probably should provide a way to make this
-					--prevent loops. And to use directories.
-					LoadExtFile(extensions, file)
+					local name, dir = util.ParsePath(file)
+					if(baseDir and dir) then
+						dir = baseDir .. dir
+					elseif(baseDir) then
+						dir = baseDir
+					end
+					
+					file = name
+					
+					LoadExtFile(extensions, file, dir)
 				end
 			else
 				table.insert(extensions, ext)
 	options.extfiles = options.extfiles or {}
 	
 	for _, file in ipairs(options.extfiles) do
-		LoadExtFile(options.extensions, file)
+		LoadExtFile(options.extensions, util.ParsePath(file)) --vararg
 	end
 	
 	--Fixup names and remove duplicates.
 	return ret
 end
 
+--Returns two values: the base filename and the directory.
+--If the base filename is nil, it doesn't have a pathname.
+--If the directory is nil, then there was no directory.
+function util.ParsePath(pathname)
+	local base = pathname:match("([^\\/]+)$")
+	local dir = pathname:match("^(.*[\\/])")
+	
+	return base, dir
+end
+
 return util