Link with C++ linker
[oweals/cde.git] / cde / programs / dtprintinfo / sym2num
1 #! /bin/ksh
2 #
3 # file: sym2num
4 #
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.
8 #
9 #          2. to provide output to standard out which can be used
10 #             by gencat.
11 #
12
13 typeset -u CAP_SYMBOL_NAME
14
15 (( $# != 2 )) && { print "usage: sym2num <symbol name> <source file>" ;\
16                  exit 1 ; }
17
18 SYMBOL_NAME=$1
19 CAP_SYMBOL_NAME=$1   # capitalized symbol name
20 SOURCE_FILE=$2
21 inc_file=${SYMBOL_NAME}_msg.h     # include file
22
23 #### Step 1: Create a header file ####
24 # write first five lines to "<symbolname>_msg.h"
25 cat <<! > ${inc_file}
26 #ifndef _H_${CAP_SYMBOL_NAME}_MSG
27 #define _H_${CAP_SYMBOL_NAME}_MSG
28 #include <limits.h>
29 #include <nl_types.h>
30 #define MF_${CAP_SYMBOL_NAME} "${SYMBOL_NAME}.cat"
31
32
33
34 /* The following was generated from ${SOURCE_FILE}. */
35 !
36
37 # locate all lines which start with "$set", and then increment 
38 # the set counter and reset the message counter to zero.
39 awk '/^\$set/ { SET_NAME=$2; SET_COUNT++; MES_COUNT=0;  
40        printf( "\n/* definitions for set %s */\n", SET_NAME ); 
41        printf( "#define %s %s\n\n", SET_NAME, SET_COUNT) }   #to be continued
42
43 # find all lines which begin with a combination of letters, numbers
44 # and underscores followed by spaces and then a quotation mark,
45 # and increment the message counter. 
46 /^[0-9A-Za-z_]+[ |\t]*\"/ { MES_NAME=$1; MES_COUNT++; 
47       printf( "#define %s %s\n", MES_NAME, MES_COUNT) }
48       END {print "#define LAST_MSG_NO "MES_COUNT"\n\n#endif"}' \
49        ${SOURCE_FILE}  >> ${inc_file}
50
51 #### Step 2: Create input to gencat ####       
52 # cat the definition statements of the include file and cat them to
53 # the source message file.  The awk file only creates define statements
54 # and blank lines.  The output should be sent to the preprocessor.
55 # There are two differences between sym2num and mkcatdefs: sym2num
56 # does not create a $delset line, and sym2num converts all symbols
57 # to numbers, even those in comment statements. 
58 if [[ -f /usr/ccs/lib/cpp ]]   #IBM & SUN
59 then
60    cpp_path=/usr/ccs/lib       
61 elif [[ -f /lib/cpp ]]         #HP
62 then
63    cpp_path=/lib
64 fi
65    ( cat ${inc_file} | sed -n /define/p ; cat ${SOURCE_FILE} ) | \
66    ${cpp_path}/cpp -P | sed '/^$/d' | sed 's/^\([1-9][0-9]*\)[ ]*\(.*\)/\1 \2/'
67
68