#! /bin/sh
#  -*- Mode: Sh -*-
# ----------------------------------------------------------------------
# hex-test --- %d specifier
#
# Author:	      Bruce Korb  <bkorb@gnu.org>
# Maintainer:	  Gary V. Vaughan <gary@gnu.org>
# Created:	      Thu Nov 26 15:50:31 1998
# Last Modified:  $Date: 2001/08/23 03:22:05 $
#            by:  Bruce
# ----------------------------------------------------------------------
# @(#) $Id: hex-test,v 1.2 2001/08/23 03:22:05 bkorb Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2001 Bruce Korb
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that also links with and
# uses the libopts library from AutoGen, you may include it under
# the same distribution terms used by the libopts library.

# Code:

# Common definitions
if test -z "$srcdir"; then
    srcdir=`echo "$0" | sed 's,[^/]*$,,'`
    test "$srcdir" = "$0" && srcdir=.
    test -z "$srcdir" && srcdir=.
    test "${VERBOSE+set}" != set && VERBOSE=1
fi
. $srcdir/defs


# this is the output we should expect to see
cat <<\EOF >ok
1 '\377'
*** printfv returned 8 chars.
2 '\001'
*** printfv returned 8 chars.
3 0xDEADBEEF
*** printfv returned 12 chars.
EOF

cat <<\EOF >errok
EOF

exec 3>&2
ct=0
while read num fmt
do
  case "${num}" in
  [-+0-9]* )
    ct=`expr $ct + 1`
    echo "$ct ${fmt} w/ ${num}" >&3
    $SNPRINTFV "$ct ${fmt}" ${num} || echo "${ct} FAILED $?"
    ;;
  esac
done 2> err > out <<'EOF'

# Try an octal value
0377  '\\%03o'
   1  '\\%03o'
0xDEADBEEF 0x%08X
## -2142593009L 0x%08X
EOF

# Test against expected output
if ${CMP} -s out ok; then
    :
else
    diff ok out >&2
    exit 1
fi

# Munge error output to remove leading directories, `lt-' or trailing `.exe'
sed -e "s,^[^:]*[lt-]*snprintfv-test[.ex]*:,snprintfv-test:," err >sederr \
    && mv sederr err

# Show stderr if doesn't match expected output if VERBOSE == 1
if "$CMP" -s err errok; then
    :
else
    diff errok err >&2
    exit 1
fi

# hex-test ends here
