#!/bin/sh
#
# makeStatTbl - make a table of status values
#
# modification history
# --------------------
# 01f,17nov88,llk   included rpctypes.h, xdr_nfs.h auth.h, and clnt.h.
# 01e,28sep88,gae   documentation.
# 01d,21apr88,gae   added special "errno.h" case for UNIX style error statuses.
# 01c,18nov87,gae   Fixed removing of temporary file on exit.
# 01b,05nov87,jlf   Documentation update, mod history added
#
# SYNOPSIS
# makeStatTbl hdir [...]
#
# DESCRIPTION
# This tool creates a symbol table (SYMTAB) structure which contains the
# names and values of all the status codes defined in the .h files in the
# specified directory(s).  The status codes must be prefixed with "S_"
# in order to be included in this table.  The one exception to the "S_"
# prefix is in the UNIX compatible errno.h header file.
# A "*ModNum.h" file must exist in each hdir which defines the module
# numbers, eg. "M_".  The table is created on standard output.
#
# This tool's primary use is for creating the VxWorks status table used
# by printErrno (2), but may be used by applications as well.  For
# an example, look at vw/config/all/statTbl.c, which is generated by this 
# tool from vw/h/*.
#
# FILES
#  hdir/*ModNum.h   module number file for each h directory
#  symLib.h         symbol header file 
#
# SEE ALSO: errnoLib(1), symLib(1)
#*/

tmp=/tmp/mstt$$
tmpe=/tmp/mstte$$

trap "rm -f $tmp $tmpe; exit" 0 1 2 3 15

cat </dev/null >$tmp

for dir in $*
do
    {
    (cd $dir; cat *.h) | egrep "^#define[ 	]*S_" >>$tmp

    if (test -f $dir/errno.h) then
	cat $dir/errno.h | egrep "^#define" >$tmpe
    fi
    }
done

echo "/* status code symbol table */

/* CREATED BY makeStatTbl"

for dir in $*
do
    {
    echo " *       FROM `cd $dir; pwd`"
    }
done

echo " *         ON `date`
 */
"'
#include "vxWorks.h"
#include "symLib.h"
#include "rpctypes.h"
#include "xdr_nfs.h"
#include "auth.h"
#include "clnt.h"
'
for dir in $*
do
    {
    echo "#include \"`cd $dir; echo *ModNum.h`"\"
    }
done

echo

cat $tmp $tmpe

echo '
LOCAL SYMBOL symbols[] =
    {'

sed -e 's/^.*define[ 	]*\([a-zA-Z0-9_]*\).*/    {"S_errno_\1", (char *) (M_errno | \1), 0},/' \
    $tmpe

sed -e 's/^.*define[ 	]*\(S_[a-zA-Z0-9_]*\).*/    {"\1", (char *) \1, 0},/' \
    $tmp

echo "    };

LOCAL SYMTAB symTbl =
    {
    NELEMENTS (symbols),	/* current number of symbols in table */
    NELEMENTS (symbols),	/* maximum number of symbols in table */
    100,			/* maximum symbol length */
    symbols,			/* ptr to symbol array */
    };

SYMTAB_ID statSymTbl = &symTbl;"

exit 0
