5 # purpose: 1. to create a header file containing the identifiers
6 # and replacement list consisting of the symbols used
7 # in a message set as well as the messages themselves.
9 # 2. to provide output to standard out which can be used
13 (( $# != 2 )) && { print "usage: sym2num <symbol name> <source file>" ;\
17 CAP_SYMBOL_NAME=`echo $1 | tr '[:lower:]' '[:upper:]'` # capitalized symbol
19 inc_file=${SYMBOL_NAME}_msg.h # include file
21 #### Step 1: Create a header file ####
22 # write first five lines to "<symbolname>_msg.h"
24 #ifndef _H_${CAP_SYMBOL_NAME}_MSG
25 #define _H_${CAP_SYMBOL_NAME}_MSG
28 #define MF_${CAP_SYMBOL_NAME} "${SYMBOL_NAME}.cat"
32 /* The following was generated from ${SOURCE_FILE}. */
35 # locate all lines which start with "$set", and then increment
36 # the set counter and reset the message counter to zero.
37 awk '/^\$set/ { SET_NAME=$2; SET_COUNT++; MES_COUNT=0;
38 printf( "\n/* definitions for set %s */\n", SET_NAME );
39 printf( "#define %s %s\n\n", SET_NAME, SET_COUNT) } #to be continued
41 # find all lines which begin with a combination of letters, numbers
42 # and underscores followed by spaces and then a quotation mark,
43 # and increment the message counter.
44 /^[0-9A-Za-z_]+[ |\t]*\"/ { MES_NAME=$1; MES_COUNT++;
45 printf( "#define %s %s\n", MES_NAME, MES_COUNT) }
46 END {print "#define LAST_MSG_NO "MES_COUNT"\n\n#endif"}' \
47 ${SOURCE_FILE} >> ${inc_file}
49 #### Step 2: Create input to gencat ####
50 # cat the definition statements of the include file and cat them to
51 # the source message file. The awk file only creates define statements
52 # and blank lines. The output should be sent to the preprocessor.
53 # There are two differences between sym2num and mkcatdefs: sym2num
54 # does not create a $delset line, and sym2num converts all symbols
55 # to numbers, even those in comment statements.
56 if [[ -f /usr/ccs/lib/cpp ]] #IBM & SUN
59 elif [[ -f /usr/libexec/cpp ]] #BSD
62 elif [[ -f /usr/bin/cpp ]] #BSD
65 elif [[ -f /lib/cpp ]] #HP
69 ( cat ${inc_file} | sed -n /define/p ; cat ${SOURCE_FILE} ) | \
70 ${cpp_path}/cpp -P | sed -e '/^$/d' -e 's/^\$$/\$ /' \
71 -e 's/\"\"$/\"/' -e 's/XDQUOTE/\"/' -e "s/XSQUOTE/\'/" \
72 -e 's/^\([1-9][0-9]*\)[ ]*[\"]*\(\"\)\(.*\)/\1 \2\3/'