aboutsummaryrefslogtreecommitdiffstats
path: root/src/remove_comments.awk
blob: 74d14e532e91b218c1e2f3ccc4b30bff9a80af50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# This is an awk script which removes comments in c files.
# it does not follow #include directives.
#

BEGIN{
	incomment=0
}

# eliminate comments
{
    # remove all comments fully contained on a single line
	gsub("\\/\\*.*\\*\\/", "")
	if (incomment) {
		if ($0 ~ /\*\//) {
			incomment = 0;
			gsub(".*\\*\\/", "")
		} else {
			next
		}
	} else {
		# start of multi-line comment
		if ($0 ~ /\/\*/)
		{
			incomment = 1;
			sub("\\/\\*.*", "")
		} else if ($0 ~ /\*\//) {
			incomment = 0;
			sub(".*\\*\\/", "")
		}
	}
	print $0
}

END{
}