[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] calling all automake'ers ...
From: |
Ralph Corderoy |
Subject: |
Re: [Groff] calling all automake'ers ... |
Date: |
Sat, 18 Apr 2015 15:57:56 +0100 |
Hi Mike,
> I know the current code uses diff -Dname option which is not
> universal.
As an aside, I see POSIX has diff support -e for ed(1) output. And -s
for running a script. How about turning -e's output into ed that
inserts the cpp(1) commands and carrying on as before? Have a poke at
--8<--snip--
#! /bin/bash
seq 10 >foo
seq 12 | sed '3,4d; 6s/./&&/; 7p' >bar
diff -Dfoo foo bar
echo
cp foo foo.new
diff -e foo bar |
awk -F, '
copy {
if ($0 == ".") {
if (closing)
print closing
copy = 0
}
print
next
}
# 42a -> 42,a
/[acd]$/ {
$0 = substr($0, 1, length - 1) FS substr($0, length)
}
# 42,a -> 42,42,a
NF == 2 {
$0 = $1 FS $1 FS $2
}
{
print "\t=" $0
}
# 42,a
$NF == "a" {
print $1 "a"
print "#ifdef foo"
closing = "#endif /* foo */"
copy = 1
next
}
# 42,314,c
$NF == "c" {
print $1 "i"
print "#ifndef foo"
print "."
print ($2 + 1) "a" # Bumped on by insert.
print "#else /* foo */"
copy = 1
closing = "#endif /* foo */"
next
}
# 42,314,d
$NF == "d" {
print $2 "a"
print "#endif /* ! foo */"
print "."
print $1 "i"
print "#ifndef foo"
print "."
next
}
END {
print "w\nq"
}
' >foo.ed
cat foo.ed
echo
sed -i '/^\t=/d' foo.ed
ed -s foo.new <foo.ed
diff <(diff -Dfoo foo bar) foo.new && echo ok
--8<--snip--
It's not had much testing as I've just knocked it up, but it shows the
idea. And you might want to ditch the cpp commands and switch to
something that's nicer to handle in the rest of the script. Or maybe do
the .mk-up directly.
Cheers, Ralph.