pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/help mk/help: sort keywords



details:   https://anonhg.NetBSD.org/pkgsrc/rev/733aeb12ed49
branches:  trunk
changeset: 376702:733aeb12ed49
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Mar 07 00:14:57 2018 +0000

description:
mk/help: sort keywords

diffstat:

 mk/help/help.awk |  29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diffs (50 lines):

diff -r 302b0c6833b6 -r 733aeb12ed49 mk/help/help.awk
--- a/mk/help/help.awk  Tue Mar 06 23:49:37 2018 +0000
+++ b/mk/help/help.awk  Wed Mar 07 00:14:57 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: help.awk,v 1.29 2018/03/06 23:49:37 rillig Exp $
+# $NetBSD: help.awk,v 1.30 2018/03/07 00:14:57 rillig Exp $
 #
 
 # This program extracts the inline documentation from *.mk files.
@@ -56,10 +56,7 @@
                        print "";
                found_anything = yes;
 
-               kw = "";
-               for (i in keywords)
-                       kw = kw " " i;
-               print "===> "last_fname " (keywords:" kw "):";
+               print "===> " last_fname " (keywords:" sorted_keys(keywords) "):";
 
                for (i = 0; i < nlines; i++) {
                        if (print_noncomment_lines || (lines[i] ~ /^#/))
@@ -69,6 +66,28 @@
        cleanup();
 }
 
+function sorted_keys(array,   elem, list, listlen, i, j, tmp, joined) {
+       listlen = 0;
+       for (elem in array)
+               list[listlen++] = elem;
+
+       for (i = 0; i < listlen; i++) {
+               for (j = i + 1; j < listlen; j++) {
+                       if (list[j] < list[i]) {
+                               tmp = list[i];
+                               list[i] = list[j];
+                               list[j] = tmp;
+                       }
+               }
+       }
+
+       joined = "";
+       for (i = 0; i < listlen; i++) {
+               joined = joined " " list[i];
+       }
+       return joined;
+}
+
 function cleanup() {
        ignore_next_empty_line = yes;
        delete lines;



Home | Main Index | Thread Index | Old Index