scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 8b8b25fa24223ca929a77253d26c76b3c596ffd6
parent c31a24c04de5785a76725ea7e2fea652e192b107
Author: Avi Halachmi (:avih) <avihpit@yahoo.com>
Date:   Sun, 15 Feb 2026 22:42:44 +0200

gcc-scc.sh: parse options using getopts

Previously, the options parsing code rejected some valid inputs,
such as -ofile (in one arg).

Now we use standarg getopts which conforms to the POSIX syntax
guidelines.

Additionally, improve the error message on unknown option:
- print to stderr instead of stdout.
- quote it (otherwise these are globs...).
- Add spaces between the options (still less than 70 chars).

Diffstat:
Msrc/libc/gcc-scc.sh | 38+++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/src/libc/gcc-scc.sh b/src/libc/gcc-scc.sh @@ -2,38 +2,34 @@ set -e -for i +while getopts gr:a:s:o:c o do - case "$i" in - -g) - shift + case $o in + g) + # ignored silently ;; - -r) - root=$2 - shift 2 + r) + root=$OPTARG ;; - -a) - abi=$2 - shift 2 + a) + abi=$OPTARG ;; - -s) - sys=$2 - shift 2 + s) + sys=$OPTARG ;; - -o) - out=$2 - shift 2 + o) + out=$OPTARG ;; - -c) - onlycc=1; - shift + c) + onlycc=1 ;; - -*) - echo usage: gcc-scc [-o outfile][-c][-r root][-a abi][-s sys] file + *) + echo >&2 "usage: gcc-scc [-o outfile] [-c] [-r root] [-a abi] [-s sys] file" exit 1 ;; esac done +shift $((OPTIND-1)) sys=${sys:-`uname | tr 'A-Z' 'a-z'`} abi=${abi:-amd64}