X-Git-Url: http://dolda2000.com/gitweb/?p=utils.git;a=blobdiff_plain;f=sztest;h=9ca4e1f41dca34cc2e9954617023c28c93c18266;hp=239397121cc23eff36a5764ab02a2825303f901a;hb=refs%2Fheads%2Fmaster;hpb=c5f010d44d71cb874e5aaf80c51c6cadaf9cfe98 diff --git a/sztest b/sztest index 2393971..9ca4e1f 100755 --- a/sztest +++ b/sztest @@ -1,16 +1,26 @@ -#!/bin/sh +#!/bin/bash -if [ $# -lt 1 ]; then - echo "usage: sztest [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]" >&2 - exit 1 -fi +usage() { + echo "usage: sztest [-hab] [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]" +} +mode=size sheaders= lheaders= while [ "${1:0:1}" = "-" ]; do opt="$1" shift case "$opt" in + "-h") + usage + exit 0 + ;; + "-a") + mode=align + ;; + "-b") + mode=both + ;; "-H") sheaders="$sheaders $1" shift @@ -21,6 +31,10 @@ while [ "${1:0:1}" = "-" ]; do ;; esac done +if [ $# -lt 1 ]; then + usage >&2 + exit 1 +fi type="$1" shift file="$(mktemp /tmp/sztestXXXXXX)" @@ -40,7 +54,19 @@ done cat >>"$file.c" <>"$file.c" + ;; + align) + echo " printf(\"%zi\\n\", __alignof__($type));" >>"$file.c" + ;; + both) + echo " printf(\"%zi %zi\\n\", sizeof($type), __alignof__($type));" >>"$file.c" + ;; +esac +cat >>"$file.c" <