Tue Apr 16 23:30:19 2024 UTC (23d)
Be more explicit with sort fields to produce consistent results with gnu
sort (Jan-Benedict Glaw)


(christos)
diff -r1.7 -r1.8 src/bin/sh/mkoptions.sh

cvs diff -r1.7 -r1.8 src/bin/sh/mkoptions.sh (expand / switch to unified diff)

--- src/bin/sh/mkoptions.sh 2024/04/06 14:20:27 1.7
+++ src/bin/sh/mkoptions.sh 2024/04/16 23:30:19 1.8
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1#! /bin/sh 1#! /bin/sh
2 2
3# $NetBSD: mkoptions.sh,v 1.7 2024/04/06 14:20:27 kre Exp $ 3# $NetBSD: mkoptions.sh,v 1.8 2024/04/16 23:30:19 christos Exp $
4 4
5# 5#
6# It would be more sensible to generate 2 .h files, one which 6# It would be more sensible to generate 2 .h files, one which
7# is for everyone to use, defines the "variables" and (perhaps) generates 7# is for everyone to use, defines the "variables" and (perhaps) generates
8# the externs (though they could just be explicit in options.h) 8# the externs (though they could just be explicit in options.h)
9# and one just for options.c which generates the initialisation. 9# and one just for options.c which generates the initialisation.
10# 10#
11# But then I'd have to deal with making the Makefile handle that properly... 11# But then I'd have to deal with making the Makefile handle that properly...
12# (this is simpler there, and it just means a bit more sh compile time.) 12# (this is simpler there, and it just means a bit more sh compile time.)
13 13
14set -f 14set -f
15IFS=' ' # blank, tab (no newline) 15IFS=' ' # blank, tab (no newline)
16export LC_ALL=C # for sort consistency 16export LC_ALL=C # for sort consistency
@@ -42,28 +42,28 @@ exec 6> "${O_FILE}" @@ -42,28 +42,28 @@ exec 6> "${O_FILE}"
42 printf ' */\n\n' 42 printf ' */\n\n'
43 43
44 printf '#ifdef DEFINE_OPTIONS\n' 44 printf '#ifdef DEFINE_OPTIONS\n'
45 printf 'struct optent optlist[] = {\n' 45 printf 'struct optent optlist[] = {\n'
46} >"${OF}" 46} >"${OF}"
47 47
48FIRST=true 48FIRST=true
49 49
50${SED:-sed} <"${IF}" \ 50${SED:-sed} <"${IF}" \
51 -e '/^$/d' \ 51 -e '/^$/d' \
52 -e '/^#/d' \ 52 -e '/^#/d' \
53 -e '/^[ ]*\//d' \ 53 -e '/^[ ]*\//d' \
54 -e '/^[ ]*\*/d' \ 54 -e '/^[ ]*\*/d' \
55 -e '/^[ ]*;/d' | 55 -e '/^[ ]*;/d' |
56sort -b -k2,2f -k2,2 | 56sort -k2b,2f -k2b,2 |
57while read line 57while read line
58do 58do
59 # Look for comments in various styles, and ignore them 59 # Look for comments in various styles, and ignore them
60 # (these should generally be already removed by sed above) 60 # (these should generally be already removed by sed above)
61 61
62 case "${line}" in 62 case "${line}" in
63 '') continue;; 63 '') continue;;
64 /*) continue;; 64 /*) continue;;
65 \**) continue;; 65 \**) continue;;
66 \;*) continue;; 66 \;*) continue;;
67 \#*) continue;; 67 \#*) continue;;
68 esac 68 esac
69 69