#!/bin/sh # # checksize -- # # Author: Takaaki Tateishi # Time-stamp: "1999-03-10 07:38:57 ttate" # # Options: # -h: help # -n: not print to stderr if test "$CC" = "" then CC=gcc fi OPTS= TYPE= NUM=1 TMPFILE= EXEFILE= STDERR=true if test "$1" = "" then echo "type was not specified" exit fi while test "$1" != "" do case "$1" in "-h"|"--help") echo "checksize [-h|--help] [-n] type options ..." exit;; "-n") STDERR=false; shift;; *) if test "$TYPE" = "" then TYPE=$1 else OPTS="$OPTS $1" fi shift;; esac done NUM=1 while test -f exe$NUM do NUM=`expr $NUM + 1` done EXEFILE=exe$NUM NUM=1 while test -f tmp$NUM.c do NUM=`expr $NUM + 1` done TMPFILE=tmp$NUM.c if test "$STDERR" = "true" then cat > $TMPFILE < int main(int argc, char *argv[]) { int size = sizeof($TYPE); fprintf(stdout,"%d\n",size); fprintf(stderr,"%d\n",size); return 0; }; EOF else cat > $TMPFILE < int main(int argc, char *argv[]) { int size = sizeof($TYPE); fprintf(stdout,"%d\n",size); return 0; }; EOF fi if test "$STDERR" = "true" then echo -n "sizeof($TYPE) ..... " 1>&2 fi $CC $OPTS $TMPFILE -o $EXEFILE 2> /dev/null 1> /dev/null if test -f $EXEFILE then ./$EXEFILE rm -f $TMPFILE $EXEFILE exit 0 else echo false if test "$STDERR" = "true" then echo false 1>&2 fi rm -f $TMPFILE $EXEFILE exit 1 fi