diff options
author | June McEnroe <june@causal.agency> | 2021-01-09 00:47:50 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-01-09 00:47:50 -0500 |
commit | 4e86032c2eb6cfc0d4da82ca29e2b27cc221fcda (patch) | |
tree | 78e3b89a46eaf21079e9ae12590569c9506e679a /bin | |
parent | Update tagline (diff) | |
download | src-4e86032c2eb6cfc0d4da82ca29e2b27cc221fcda.tar.gz src-4e86032c2eb6cfc0d4da82ca29e2b27cc221fcda.zip |
Add c -t flag to print expression type
Also add missing float case.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/c.sh | 33 | ||||
-rw-r--r-- | bin/man1/c.1 | 7 |
2 files changed, 38 insertions, 2 deletions
diff --git a/bin/c.sh b/bin/c.sh index f1143fd3..4439aaee 100644 --- a/bin/c.sh +++ b/bin/c.sh @@ -29,10 +29,12 @@ cat >&3 <<EOF EOF expr= -while getopts 'e:i:' opt; do +type= +while getopts 'e:i:t' opt; do case "${opt}" in (e) expr=$OPTARG;; (i) echo "#include <${OPTARG}>" >&3;; + (t) type=1;; (?) exit 1;; esac done @@ -45,6 +47,34 @@ int main(int argc, char *argv[]) { $*; EOF +if [ -n "${type}" ]; then + cat >&3 <<EOF + printf( + _Generic( + ${expr}, + char: "(char) ", + char *: "(char *) ", + const char *: "(const char *) ", + wchar_t *: "(wchar_t *) ", + const wchar_t *: "(const wchar_t *) ", + signed char: "(signed char) ", + short: "(short) ", + int: "(int) ", + long: "(long) ", + long long: "(long long) ", + unsigned char: "(unsigned char) ", + unsigned short: "(unsigned short) ", + unsigned int: "(unsigned int) ", + unsigned long: "(unsigned long) ", + unsigned long long: "(unsigned long long) ", + float: "(float) ", + double: "(double) ", + default: "(void *) " + ) + ); +EOF +fi + if [ -n "${expr}" ]; then cat >&3 <<EOF printf( @@ -65,6 +95,7 @@ if [ -n "${expr}" ]; then unsigned int: "%u\n", unsigned long: "%lu\n", unsigned long long: "%llu\n", + float: "%g\n", double: "%g\n", default: "%p\n" ), diff --git a/bin/man1/c.1 b/bin/man1/c.1 index 3ae10945..97384ebe 100644 --- a/bin/man1/c.1 +++ b/bin/man1/c.1 @@ -1,4 +1,4 @@ -.Dd May 31, 2020 +.Dd January 9, 2021 .Dt C 1 .Os . @@ -8,6 +8,7 @@ . .Sh SYNOPSIS .Nm +.Op Fl t .Op Fl e Ar expr .Op Fl i Ar include .Op Ar stmts ... @@ -37,4 +38,8 @@ after executing .It Fl i Ar include Add the include file .Ar include . +.It Fl t +With +.Fl e , +print the type of the expression. .El |