Update, rename and clean up various scripts

Rename contrib/tools/chkfmt to contrib/tools/chkfmt.sh; refactor:
 * Increase the max line length for contrib/**/*.[ch] from 96 to 100.
 * Set the max line length for ci_*.sh to 100.
 * Use `basename $0` instead of the hard-coded script name.
 * Update comments.

Remove contrib/tools/reindent. For automated code formatting, including
indentation, we need a robust solution.

Add an empty line after the hashbang line in all scripts.

Remove the "last changed" version info from comment headers.
(The version control system maintains this information automatically.)
This commit is contained in:
Cosmin Truta 2022-11-20 20:21:41 +02:00
parent 689e06516b
commit f6036c0aeb
7 changed files with 46 additions and 63 deletions

View File

@ -1,12 +1,10 @@
#!/bin/sh #!/bin/sh
#
# Make a set of test PNG files, MAKEPNG is the name of the makepng executable # Make a set of test PNG files, MAKEPNG is the name of the makepng executable
# built from contrib/libtests/makepng.c # built from contrib/libtests/makepng.c
# Copyright (c) 2015 John Cunningham Bowler # Copyright (c) 2015 John Cunningham Bowler
# Last changed in libpng 1.6.20 [December 3, 2015]
# This code is released under the libpng license. # This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer # For conditions of distribution and use, see the disclaimer
# and license in png.h # and license in png.h

View File

@ -1,14 +1,18 @@
#!/bin/sh #!/bin/sh
# chkfmt # chkfmt.sh
# #
# COPYRIGHT: Written by John Cunningham Bowler, 2010. # COPYRIGHT:
# Written by John Cunningham Bowler, 2010.
# Revised by Cosmin Truta, 2022.
# To the extent possible under law, the author has waived all copyright and # To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from: # related or neighboring rights to this work. The author published this work
# United States. # from the United States.
# #
# Check the format of the source files in the current directory - checks for a # Check the format of the source files in the current directory:
# line length of 80 characters max and no tab characters. #
# * The lines should not exceed a predefined maximum length.
# * Tab characters should appear only where necessary (e.g. in makefiles).
# #
# Optionally arguments are files or directories to check. # Optionally arguments are files or directories to check.
# #
@ -16,6 +20,9 @@
# -e: spawn an editor for each file that needs a change ($EDITOR must be # -e: spawn an editor for each file that needs a change ($EDITOR must be
# defined). When using -e the script MUST be run from an interactive # defined). When using -e the script MUST be run from an interactive
# command line. # command line.
script_name=`basename "$0"`
verbose= verbose=
edit= edit=
vers= vers=
@ -32,14 +39,14 @@ test "$1" = "-e" && {
# Copy the standard streams for the editor # Copy the standard streams for the editor
exec 3>&0 4>&1 5>&2 exec 3>&0 4>&1 5>&2
else else
echo "chkfmt -e: EDITOR must be defined" >&2 echo "$script_name -e: EDITOR must be defined" >&2
exit 1 exit 1
fi fi
} }
# Function to edit a single file - if the file isn't changed ask the user # Function to edit a single file - if the file isn't changed ask the user
# whether or not to continue. This stuff only works if the script is run from # whether or not to continue. This stuff only works if the script is run
# the command line (otherwise, don't specify -e or you will be sorry). # from the command line (otherwise, don't specify -e or you will be sorry).
doed(){ doed(){
cp "$file" "$file".orig cp "$file" "$file".orig
"$EDITOR" "$file" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- || exit 1 "$EDITOR" "$file" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- || exit 1
@ -53,19 +60,22 @@ doed(){
return 0 return 0
} }
# In beta versions the version string which appears in files can be a little # In beta versions, the version string which appears in files can be a little
# long and cause spuriously overlong lines. To avoid this substitute the version # long and cause spuriously overlong lines. To avoid this, substitute the
# string with a 'standard' version a.b.cc before checking for long lines. # version string with a placeholder string "a.b.cc" before checking for long
# lines.
# (Starting from libpng version 1.6.36, we switched to a conventional Git
# workflow, and we are no longer publishing beta versions.)
if test -r png.h if test -r png.h
then then
vers="`sed -n -e \ vers="`sed -n -e \
's/^#define PNG_LIBPNG_VER_STRING .\([0-9]\.[0-9]\.[0-9][0-9a-z]*\).$/\1/p' \ 's/^#define PNG_LIBPNG_VER_STRING .\([0-9]\.[0-9]\.[0-9][0-9a-z]*\).$/\1/p' \
png.h`" png.h`"
echo "chkfmt: checking version $vers" echo "$script_name: checking version $vers"
fi fi
if test -z "$vers" if test -z "$vers"
then then
echo "chkfmt: png.h not found, ignoring version number" >&2 echo "$script_name: png.h not found, ignoring version number" >&2
fi fi
test -n "$1" || set -- . test -n "$1" || set -- .
@ -89,13 +99,16 @@ find "$@" \( -type d \( -name '.git' -o -name '.libs' -o -name 'projects' \) \
check_tabs= check_tabs=
line_length=100;; line_length=100;;
*.awk) *.awk)
# Includes literal tabs # Allow literal tabs.
check_tabs= check_tabs=
# The following is arbitrary # Mainframe line printer, anyone?
line_length=132;; line_length=132;;
*/ci_*.sh)
check_tabs=yes
line_length=100;;
*contrib/*/*.[ch]) *contrib/*/*.[ch])
check_tabs=yes check_tabs=yes
line_length=96;; line_length=100;;
*) *)
check_tabs=yes check_tabs=yes
line_length=80;; line_length=80;;

View File

@ -1,13 +1,11 @@
#!/bin/sh #!/bin/sh
#
# intgamma.sh # intgamma.sh
# #
# Last changed in libpng 1.6.0 [February 14, 2013]
#
# COPYRIGHT: Written by John Cunningham Bowler, 2013. # COPYRIGHT: Written by John Cunningham Bowler, 2013.
# To the extent possible under law, the author has waived all copyright and # To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from: # related or neighboring rights to this work. The author published this work
# United States. # from the United States.
# #
# Shell script to generate png.c 8-bit and 16-bit log tables (see the code in # Shell script to generate png.c 8-bit and 16-bit log tables (see the code in
# png.c for details). # png.c for details).
@ -17,10 +15,10 @@
# (0..255) value and a similar table for the exponent calculation. # (0..255) value and a similar table for the exponent calculation.
# #
# "bc" must be on the path when the script is executed, and the math library # "bc" must be on the path when the script is executed, and the math library
# (-lm) must be available # (-lm) must be available.
#
# function to print out a list of numbers as integers; the function truncates # Function to print out a list of numbers as integers; the function truncates
# the integers which must be one-per-line # the integers which must be one-per-line.
function print(){ function print(){
awk 'BEGIN{ awk 'BEGIN{
str = "" str = ""

View File

@ -1,25 +0,0 @@
#!/bin/sh
# reindent a libpng C source
# COPYRIGHT: Written by Glenn Randers-Pehrson, 2016.
# To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from:
# United States.
# Usage:
# reindent inputtabsize outputtabsize inputcontinuestring outputcontinuestring
#
# Assumes that continued lines begin with indentation plus one space, and
# that continued comments begin with indentation plus " *".
#
# eg, to change libpng coding style from 3-space indentation with 4-space
# continuations to 4-space indentation with 2-space continuations:
#
# reindent 3 4 "\t " " " < example.c > example.c_4_2
# and to restore the file back to libpng coding style
# reindent 4 3 " " " " < example.c_4_2 > example.c_3_4
unexpand --first-only --t $1 | \
sed -e "/^ *$3[^\*]/{s/$3/$4/}" | \
expand -t $2

View File

@ -1,4 +1,5 @@
#!/bin/awk -f #!/bin/awk -f
# Check a list of symbols against the master definition # Check a list of symbols against the master definition
# (official) list. Arguments: # (official) list. Arguments:
# #

View File

@ -1,8 +1,7 @@
#!/bin/awk -f #!/bin/awk -f
# scripts/dfn.awk - process a .dfn file # scripts/dfn.awk - process a .dfn file
# #
# last changed in libpng version 1.5.19 - August 21, 2014
#
# Copyright (c) 2013-2014 Glenn Randers-Pehrson # Copyright (c) 2013-2014 Glenn Randers-Pehrson
# #
# This code is released under the libpng license. # This code is released under the libpng license.

View File

@ -1,8 +1,7 @@
#!/bin/awk -f #!/bin/awk -f
# scripts/options.awk - library build configuration control # scripts/options.awk - library build configuration control
# #
# last changed in libpng version 1.6.11 - June 5, 2014
#
# Copyright (c) 1998-2014 Glenn Randers-Pehrson # Copyright (c) 1998-2014 Glenn Randers-Pehrson
# #
# This code is released under the libpng license. # This code is released under the libpng license.