Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Aug 2006 13:34:53 GMT
From:      Todd Miller <millert@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 104221 for review
Message-ID:  <200608161334.k7GDYr5d069957@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=104221

Change 104221 by millert@millert_macbook on 2006/08/16 13:34:52

	asort() is a gawk extension, use the qsort() function from
	the awk book instead.

Affected files ...

.. //depot/projects/trustedbsd/sedarwin8/policies/sedarwin/refpolicy/policy/flask/mkaccess_vector.sh#2 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin8/policies/sedarwin/refpolicy/policy/flask/mkaccess_vector.sh#2 (text+ko) ====

@@ -15,6 +15,23 @@
 av_perm_to_string="av_perm_to_string.h"
 
 cat $* | $awk "
+	# Quicksort function for awk arrays, from The AWK Programming
+	# Language, by Aho, Kernighan and Weinberger.
+	# Call qsort(array, smallestindex, largestindex)
+	function qsort(a,left,right,	i,last) {
+		if (left >= right) return
+		swap(a, left, left + int((right-left+1)*rand()))
+		last = left
+		for (i=left+1; i<=right; i++)
+		    if (a[i] < a[left]) swap(a, ++last, i)
+		swap(a, left, last)
+		qsort(a, left, last-1)
+		qsort(a, last+1, right)
+	}
+	function swap(a,i,j,	t) {
+		t = a[i]; a[i] = a[j]; a[j] = t;
+	}
+
 BEGIN	{
 		outfile = \"$av_permissions\"
 		inheritfile = \"$av_inherit\"
@@ -102,12 +119,12 @@
 				}
 			}
 
-                        j = 1;
+                        n = 0;
                         for (i in inherited_perms) {
-                            ind[j] = i + 0;
-                            j++;
+                            n++;
+                            ind[n] = i + 0;
                         }
-                        n = asort(ind);
+                        qsort(ind, 1, n);
 			for (i = 1; i <= n; i++) {
 				perm = inherited_perms[ind[i]];
 				printf("#define %s__%s", toupper(tclass), toupper(perm)) > outfile; 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608161334.k7GDYr5d069957>