>
>
>
>    1. Add a %F flag that gives the whole path *without* the extension. I 
>    can't count how many times I wanted this flag.
>    2. 
>    
> Here is a small patch that extends the lua parser with a %F flag. Patch 
may contain errors as I could not test some (commented out) part.

Also a bug in %B %b %e (according to my understandings) has also been 
resolved, as invalid input with multiple files were accepted by the parser:

tup.rule( '*', 'echo %o', '%B.%e' )                -- it should fail as %B 
and %e has no "valid" meaning in this case.
tup.foreach_rule( '*', 'echo %o', '%B.%e' )  -- it is legal and works as 
expected

Please feel free to update/comment the patch. And please apply to the git 
repo if applicable. 

Regards Gzp.

PS: The parser.c was not modified. If I were the tup maintainer I'd drop 
the parser as soon as possible in favor of lua.

-- 
-- 
tup-users mailing list
email: [email protected]
unsubscribe: [email protected]
options: http://groups.google.com/group/tup-users?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"tup-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/luabuiltin/builtin.lua b/src/luabuiltin/builtin.lua
index b128354..ab9b5b2 100644
--- a/src/luabuiltin/builtin.lua
+++ b/src/luabuiltin/builtin.lua
@@ -58,6 +58,28 @@ local concat_filenames = function(files)
 	return res
 end
 
+local concat_filenames_extless = function(files)
+	local res = ''
+	if files then
+		for k, v in ipairs(files) do
+			-- <groups> are ignored in %f/%o/etc
+			if not v:find('<') then
+				if res != '' then
+					res = res .. ' '
+				end
+				res = res .. tup.extless(v):gsub('%%', '%%%%')
+			end
+		end
+	end
+	return res
+end
+
+local function tablelength(T)
+  local count = 0
+  for _ in pairs(T) do count = count + 1 end
+  return count
+end
+
 tup.file = function(filename)
 	-- Returns filename sans preceeding dir/'s
 	return (string.gsub(filename, '[^/\\]*[/\\]', ''))
@@ -74,12 +96,17 @@ tup.ext = function(filename)
 	return match and match or ''
 end
 
+tup.extless = function(filename)
+	-- Returns the full filename without the extension
+	return (string.gsub(filename, '%.%w*$', ''))
+end
+
 tup.frule = function(arguments)
 	-- Takes inputs, outputs, and commands as in tup.definerule,
 	-- additionally accepts, input and output which may be either tables or strings
 	-- Replaces $(), @(), and %d in inputs with proper values
-	-- Replaces $(), @(), %d, %f, %b, %B in outputs with proper values
-	-- Replaces $(), @(), %d, %f, %b, %B, %o in command with proper values
+	-- Replaces $(), @(), %d, %f, %F, %b, %B in outputs with proper values
+	-- Replaces $(), @(), %d, %f, %F, %b, %B, %o in command with proper values
 	-- Returns the expanded outputs
 
 	function evalGlobals(text)
@@ -139,6 +166,13 @@ tup.frule = function(arguments)
 	elseif arguments.output and type(arguments.output) ~= 'table' then
 		if arguments.output == '%f' then
 			outputs = inputs
+
+		-- what is this section, could not find a valid usecase
+		--elseif arguments.output == '%F' then
+		--	for index, input in ipairs(inputs) do
+		--		table.insert( outputs, tup.extless(input) )
+		--	end
+
 		else
 			outputs = {arguments.output}
 		end
@@ -154,15 +188,16 @@ tup.frule = function(arguments)
 			newoutput = evalGlobals(newoutput)
 			newoutput = evalConfig(newoutput)
 
-			if not inputs or not inputs[1] then
-				if output:match('%%b') or output:match('%%B') or output:match('%%e') then
-					error 'tup.frule can only use output formatters %b, %B, or %e with exactly one input.'
+			if output:match('%%b') or output:match('%%B') or output:match('%%F') or output:match('%%e') then
+				if not inputs or tablelength(inputs) ~= 1 or not inputs[1] then
+					error 'tup.frule can only use output formatters %b, %B, %F, or %e with exactly one input.'
+				else
+					newoutput = newoutput
+						:gsub('%%b', tup.file(inputs[1]))
+						:gsub('%%B', tup.base(inputs[1]))
+						:gsub('%%e', tup.ext(inputs[1]))
+						:gsub('%%F', tup.extless(inputs[1]))
 				end
-			else
-				newoutput = newoutput
-					:gsub('%%b', tup.file(inputs[1]))
-					:gsub('%%B', tup.base(inputs[1]))
-					:gsub('%%e', tup.ext(inputs[1]))
 			end
 
 			newoutput = newoutput:gsub('%%d', tup.getdirectory())
@@ -191,15 +226,18 @@ tup.frule = function(arguments)
 		local inputreplacement = concat_filenames(inputs)
 		command = command:gsub('%%f', inputreplacement)
 
-		if not inputs or not inputs[1] then
-			if command:match('%%b') or command:match('%%B') or command:match('%%e') then
+		local inputreplacement = concat_filenames_extless(inputs)
+		command = command:gsub('%%F', inputreplacement)
+
+		if command:match('%%b') or command:match('%%B') or command:match('%%e') then
+			if not inputs or tablelength(inputs) ~= 1 or not inputs[1] then
 				error 'tup.frule can only use command formatters %b, %B, or %e with exactly one input.'
+			else
+				command = command
+					:gsub('%%b', tup.file(inputs[1]))
+					:gsub('%%B', tup.base(inputs[1]))
+					:gsub('%%e', tup.ext(inputs[1]))
 			end
-		else
-			command = command
-				:gsub('%%b', tup.file(inputs[1]))
-				:gsub('%%B', tup.base(inputs[1]))
-				:gsub('%%e', tup.ext(inputs[1]))
 		end
 
 		command = command:gsub('%%d', tup.getdirectory())

Reply via email to