ambevar-dotfiles/.scripts/strip-comments

33 lines
752 B
Plaintext
Raw Normal View History

#!/usr/bin/awk -f
## Default to C block comments. You can change the comment delimiters from
## command line. The delims are regexes. For instance call this script with
##
2013-11-01 20:33:17 +01:00
## awk -v begin="#" -v end="$" -f <this-script> <files>
##
## to use shell comment delimiters.
BEGIN {
2013-11-01 20:33:17 +01:00
## Since 'begin' and 'end' are regexes, we need to escape some sequences.
if(begin == "")
begin="/\\*"
if(end == "")
end="\\*/"
}
{
2013-11-01 20:33:17 +01:00
while (match ($0, begin))
2013-10-06 19:54:15 +02:00
{
before = substr ($0, 1, RSTART-1)
$0 = substr($0, RSTART)
2013-10-30 15:57:24 +01:00
printf("%s", before)
2013-11-01 20:33:17 +01:00
## Reach line where first 'end' is found.
while (! match($0, end) )
getline
2013-11-01 20:33:17 +01:00
$0 = substr($0, RSTART + length(end) -1)
}
print
}