#!/bin/sh
#
# makeStatTbl
# share/src/misc $Id$
# makeStatTbl - Create Error Symbol Table
#
# modification history
# --------------------
# 17-JUL-90   mrk   Modified vxWorks makeStatTbl
#
# SYNOPSIS
# createErrSymTbl hdir [...] >errSymTbl.c
#
# DESCRIPTION
# This tool creates a symbol table (ERRSYMTAB) 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.
# A "err.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 an error status table used
# by errPrint, and errSymFind.
#
# FILES
# errMdef.h   module number file for each h directory
#
# SEE ALSO: errnoLib(1), symLib(1)
#*/

tmp=/tmp/mstt$$

#	knts cannot handle this  -kuk-
# trap "rm -f $tmp ; exit" 0 1 2 3 15

cat $* | egrep '^#define[ 	]*S_' >$tmp


echo '/* status code symbol table */'
echo 
echo '/* CREATED BY makeStatTbl'
echo ' *       FROM '`pwd`
echo ' *         ON '`date`
echo ' */'
echo 
echo '#include "errMdef.h"'
echo '#include "errSymTbl.h"'
echo

cat $tmp 

echo
echo 'LOCAL ERRSYMBOL symbols[] ='
echo '    {'

#	-kuk-  had to change  "\2"  into  \"\2\"  for knts
sed -e 's/^.*define[ 	]*\(S_[a-zA-Z0-9_]*\).*\/\*\(.*\)\*\/.*/    {\"\2\", (long) \1},/' \
    $tmp

echo '    };'
echo
echo 'LOCAL ERRSYMTAB symTbl ='
echo '    {'
echo '    NELEMENTS (symbols),	/* current number of symbols in table */'
echo '    symbols,			/* ptr to symbol array */'
echo '    };'
echo 
echo 'ERRSYMTAB_ID errSymTbl = &symTbl;'

exit 0
