Unify shell script style
This commit is contained in:
parent
8d3ae231bb
commit
c84c0e3a99
11 changed files with 81 additions and 83 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
# env
|
||||
# imgresize
|
||||
# Written in 2019 by Lucas
|
||||
# CC0 1.0 Universal/Public domain - No rights reserved
|
||||
#
|
||||
|
@ -10,7 +10,8 @@
|
|||
# Dedication along with this software. If not, see
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
usage() {
|
||||
usage()
|
||||
{
|
||||
cat - <<. >&2
|
||||
Usage:
|
||||
${0##*/} size in-file out-file
|
||||
|
@ -20,24 +21,21 @@ Usage:
|
|||
exit 1
|
||||
}
|
||||
|
||||
check_dimension_format() {
|
||||
err()
|
||||
{
|
||||
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_dimension_format()
|
||||
{
|
||||
printf "%s\n" "$1" | grep -q "^[0-9]*x[0-9]*\$" \
|
||||
&& [ "$1" != "x" ]
|
||||
}
|
||||
|
||||
if [ $# -ne 3 ] || ! check_dimension_format "$1"; then
|
||||
usage
|
||||
fi
|
||||
if [ -z "$2" ]; then
|
||||
printf "%s: Input file name can't be empty.\n" \
|
||||
"${0##*/}" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$3" ]; then
|
||||
printf "%s: Output file name can't be empty.\n" \
|
||||
"${0##*/}" >&2
|
||||
exit 1
|
||||
fi
|
||||
[ $# -eq 3 ] && check_dimension_format "$1" || usage
|
||||
[ -n "$2" ] || err "Input file name can't be empty."
|
||||
[ -n "$3" ] || err "Output file name can't be empty."
|
||||
|
||||
size=$1
|
||||
w=${size%x*}
|
||||
|
@ -52,8 +50,7 @@ case $infile in
|
|||
;;
|
||||
*.png) inprog=pngtopam
|
||||
;;
|
||||
*) printf "%s: Unknown input format.\n" "${0##*/}" >&2
|
||||
exit 1
|
||||
*) err "Unknown input format."
|
||||
;;
|
||||
esac
|
||||
|
||||
|
@ -64,8 +61,7 @@ case $outfile in
|
|||
;;
|
||||
*.png) outprog=pamtopng
|
||||
;;
|
||||
*) printf "%s: Unknown output format.\n" "${0##*/}" >&2
|
||||
exit 1
|
||||
*) err "Unknown output format."
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue