Skip to content

Commit

Permalink
build: Fix pnglibconf for the awk implementations that lack asort
Browse files Browse the repository at this point in the history
  • Loading branch information
ctruta committed Feb 17, 2025
1 parent f6aa448 commit 76a76a4
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions scripts/pnglibconf/checksym.awk
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ END {
}

# Sort and print the symbols.
asort(sorted_symbols)
for (i = 1; i <= length(sorted_symbols); i++) {
num = do_sort(sorted_symbols)
for (i = 1; i <= num; i++) {
print " " sorted_symbols[i] >of
}

Expand All @@ -106,3 +106,24 @@ END {

# TODO: Check for symbols that are both defined and removed.
}

# Portable wrapper around the gawk-specific asort function.
function do_sort(arr) {
if ("identifiers" in PROCINFO && "asort" in PROCINFO["identifiers"]) {
# Use asort (available in gawk).
return asort(arr)
}
# Fall back to a hand-made insertion sort, which should be fast enough
# for our use case.
num = length(arr)
for (i = 2; i <= num; i++) {
key = arr[i]
j = i - 1
while (j > 0 && arr[j] > key) {
arr[j + 1] = arr[j]
j = j - 1
}
arr[j + 1] = key
}
return num
}

0 comments on commit 76a76a4

Please sign in to comment.