diff options
author | dteske <dteske@FreeBSD.org> | 2013-11-30 23:47:18 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-11-30 23:47:18 +0000 |
commit | 9a51d4481d9630963966a5871e799c43d9c8f292 (patch) | |
tree | f01ea0a3e7cf4b552321b529f90d8946b7aa8364 /usr.sbin | |
parent | 44c01df17391f4429ee371e8039ae4fd802c2a8e (diff) | |
download | FreeBSD-src-9a51d4481d9630963966a5871e799c43d9c8f292.zip FreeBSD-src-9a51d4481d9630963966a5871e799c43d9c8f292.tar.gz |
Sort function output on name of the function.
Diffstat (limited to 'usr.sbin')
-rwxr-xr-x | usr.sbin/bsdconfig/includes/includes | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/usr.sbin/bsdconfig/includes/includes b/usr.sbin/bsdconfig/includes/includes index 95be4f3..db32115 100755 --- a/usr.sbin/bsdconfig/includes/includes +++ b/usr.sbin/bsdconfig/includes/includes @@ -69,16 +69,36 @@ show_include() -v use_color=${USE_COLOR:-0} \ -v re="$pattern" \ -v show_desc=${SHOW_DESC:-0} ' + function asorti(src, dest) + { + # Copy src indices to dest and calculate array length + nitems = 0; for (i in src) dest[++nitems] = i + + # Sort the array of indices (dest) using insertion sort method + for (i = 1; i <= nitems; k = i++) + { + idx = dest[i] + while ((k > 0) && (dest[k] > idx)) + { + dest[k+1] = dest[k] + k-- + } + dest[k+1] = idx + } + + return nitems + } /^$/,/^#/ { if ($0 ~ /^# f_/) { if (!match($2, re)) next + fn = $2 if (use_color) - printf "+%s[1;31m%s[0m%s\n", + syntax[fn] = sprintf("+%s[1;31m%s[0m%s\n", substr($0, 2, RSTART), substr($0, 2 + RSTART, RLENGTH), - substr($0, 2 + RSTART + RLENGTH) + substr($0, 2 + RSTART + RLENGTH)) else - print "+" substr($0, 2) + syntax[fn] = "+" substr($0, 2) "\n" if (show_desc) print_more = 1 else @@ -87,15 +107,20 @@ show_include() if (show_desc && print_more) { getline while ($0 ~ /^#/) { - print " " substr($0, 2) + syntax[fn] = syntax[fn] " " substr($0, 2) "\n" getline } print_more = 0 } else while (print_more) { getline - print " " substr($0, 2) + syntax[fn] = syntax[fn] " " substr($0, 2) "\n" print_more = substr($0, length($0)) == "\\" } + } + END { + n = asorti(syntax, sorted_indices) + for (i = 1; i <= n; i++) + printf "%s", syntax[sorted_indices[i]] }' "$file" ) if [ "$output" ]; then if [ ! "$SHOW_FUNCS" ]; then |