diff options
author | Sunil Nimmagadda <sunil@cvs.openbsd.org> | 2019-02-18 11:05:44 +0000 |
---|---|---|
committer | Sunil Nimmagadda <sunil@cvs.openbsd.org> | 2019-02-18 11:05:44 +0000 |
commit | fd43f8849911513679dd2daceba42f53a78c312e (patch) | |
tree | 8d04db09ebf786de780470539b531d0bc388a8d0 | |
parent | 2e8c0699e661decc7fad6370c560f880a3839521 (diff) |
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) |