xref: /freebsd/usr.sbin/bsdconfig/share/packages/index.awk (revision 4f8f43b06ed07e96a250855488cc531799d5b78f)
1function _asorti(src, dest)
2{
3	k = nitems = 0
4
5	# Copy src indices to dest and calculate array length
6	for (i in src) dest[++nitems] = i
7
8	# Sort the array of indices (dest) using insertion sort method
9	for (i = 1; i <= nitems; k = i++)
10	{
11		idx = dest[i]
12		while ((k > 0) && (dest[k] > idx))
13		{
14			dest[k+1] = dest[k]
15			k--
16		}
17		dest[k+1] = idx
18	}
19
20	return nitems
21}
22
23function print_category(category, npkgs, desc)
24{
25	cat = category
26	# Accent the category if the first page has been
27	# cached (also acting as a visitation indicator)
28	if ( ENVIRON["_index_page_" varcat "_1"] )
29		cat = cat "*"
30	printf "'\''%s'\'' '\''%s " packages "'\'' '\''%s'\''\n",
31	       cat, npkgs, desc >>tmpfile
32}
33
34BEGIN{
35	cnt=0
36	div=int(npkg / 100)
37	last=0
38	prefix = ""
39}
40{
41	cnt+=1
42	i = int(cnt / div)
43	if (i > last) {
44		last = i
45		print "XXX"
46		print i
47		print msg
48		print "XXX"
49		fflush("/dev/stdout");
50	}
51	varpkg = $1
52	gsub("[^" valid_chars "]", "_", varpkg)
53	print "_categories_" varpkg "=\"" $7 "\"" >> tmpfile
54	split($7, pkg_categories, /[[:space:]]+/)
55	for (pkg_category in pkg_categories)
56		categories[pkg_categories[pkg_category]]++
57	print "_rundeps_" varpkg "=\"" $9 "\"" >> tmpfile
58
59}
60END {
61	n = _asorti(categories, categories_sorted)
62	# Produce package counts for each category
63	for (i = 1; i <= n; i++)
64	{
65		cat = varcat = categories_sorted[i]
66		npkgs = categories[cat]
67		gsub("[^" valid_chars "]", "_", varcat)
68		print "_npkgs_" varcat "=\"" npkgs "\"" >>tmpfile
69	}
70	#
71	# Create menu list and generate list of categories at same time
72	print "CATEGORY_MENU_LIST=\"" >>tmpfile
73	print_category(msg_all, npkg, msg_all_desc)
74	category_list = ""
75	for (i = 1; i <= n; i++)
76	{
77		cat = varcat = categories_sorted[i]
78		npkgs = categories[cat]
79		cur_prefix = tolower(substr(cat, 1, 1))
80		if ( prefix != cur_prefix )
81			prefix = cur_prefix
82		else
83			cat = " " cat
84		gsub("[^" valid_chars "]", "_", varcat)
85		desc = ENVIRON["_category_" varcat]
86		if ( ! desc ) desc = default_desc
87		print_category(cat, npkgs, desc)
88		category_list = category_list " " cat
89	}
90	print "\"" >>tmpfile
91
92	# Produce the list of categories (calculated in above block)
93	sub(/^ /, "", category_list)
94	print "PACKAGE_CATEGORIES=\"" category_list "\"" >> tmpfile
95	print "_npkgs=\""npkg"\"" >>tmpfile
96
97	print "EOF"
98}
99