File: sort-includes.awk

package info (click to toggle)
kadu 4.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 54,532 kB
  • sloc: cpp: 128,331; sh: 988; awk: 105; makefile: 75
file content (46 lines) | stat: -rwxr-xr-x 893 bytes parent folder | download | duplicates (3)
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
37
38
39
40
41
42
43
44
45
46
function printSortedIncluded(include_group)
{
	if (length(include_group) > 0)
	{
		# new arrays
		split("", current_dir_include_group)
		split("", other_dir_include_group)

		for (x in include_group)
			if (include_group[x] ~ /\//)
				other_dir_include_group[length(other_dir_include_group)] = include_group[x]
			else
				current_dir_include_group[length(current_dir_include_group)] = include_group[x]

		n = asort(other_dir_include_group)
		for (i = 1; i <= n; i++)
			print(other_dir_include_group[i])

		n = asort(current_dir_include_group)
		for (i = 1; i <= n; i++)
			print(current_dir_include_group[i])
	}

	# clear array
	split("", include_group)
}

BEGIN {
	# declare array
	split("", include_group)
	done = 0
}

/\#include/ {
	include_group[length(include_group)] = $0
}

!/\#include/ {
	printSortedIncluded(include_group)

	print $0
}

END {
	printSortedIncluded(include_group)
}