diff options
author | 2019-02-18 11:05:43 +0000 | |
---|---|---|
committer | 2019-02-18 11:05:43 +0000 | |
commit | 027e3329c9b458fc3a594eb32b57cd966434bec3 (patch) | |
tree | feca491255c1479ddddd6a142c4c2264b4e2962d | |
parent | Fix in-place stripping by using correct form of parameter substitution. (diff) | |
download | wireguard-openbsd-027e3329c9b458fc3a594eb32b57cd966434bec3.tar.xz wireguard-openbsd-027e3329c9b458fc3a594eb32b57cd966434bec3.zip |
Using getopt(1) is more idiomatic and consistent with other scripts.
Ok mpi@
-rw-r--r-- | usr.bin/ctfconv/ctfstrip | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/usr.bin/ctfconv/ctfstrip b/usr.bin/ctfconv/ctfstrip index 1dd7449de5b..95fb369def0 100644 --- a/usr.bin/ctfconv/ctfstrip +++ b/usr.bin/ctfconv/ctfstrip @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: ctfstrip,v 1.9 2019/02/18 11:01:48 sunil Exp $ +# $OpenBSD: ctfstrip,v 1.10 2019/02/18 11:05:43 sunil Exp $ # # Copyright (c) 2017 Martin Pieuchot # @@ -23,31 +23,31 @@ cleanup() { exit 1 } -trap "cleanup" 1 2 3 13 15 +usage() { + echo "usage: $(basename $0) [-S] [-o outfile] file" >&2 + exit 1 +} -USAGE="usage: ${0##*/} [-S] [-o outfile] file" +trap "cleanup" 1 2 3 13 15 -for arg in "$@"; do - if [ -n "$OSET" ]; then - OUTFILE="$arg" - unset OSET - shift - continue - fi - case "$arg" in - -o) OSET=1; shift; continue;; - -S) STRIPFLAG=-g; shift; continue;; - esac - shift - set -- "$@" "$arg" - INFILE="$arg" +args=$(getopt So: $*) +if [ $? -ne 0 ]; then + usage +fi +set -- $args +while [ $# -ne 0 ]; do + case "$1" in + -S) STRIPFLAG=-g; shift;; + -o) OUTFILE="$2"; shift; shift;; + --) shift; break;; + esac done -if [ $# -eq 0 ]; then - echo "${USAGE}" >&2 - exit 1 +if [ $# -ne 1 ]; then + usage fi +INFILE="$1" LABEL="unknown" TMPFILE=$(mktemp /tmp/.ctf.XXXXXXXXXX) |