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 91c396c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 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,20 @@ END {

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

# Portable replacement for the gawk-specific asort function.
function do_sort(arr) {
# Perform 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 the array size, as in the asort function.
return num
}

0 comments on commit 91c396c

Please sign in to comment.