| 1 |
#!/bin/sh - |
| 2 |
# $Id$ |
| 3 |
# |
| 4 |
# Automatically generate message id. |
| 5 |
|
| 6 |
# Usage: A BDB#### would be replaced with an unused message id in: |
| 7 |
# 1) DB_STR(BDB#### |
| 8 |
# 2) DB_STR_A(BDB#### |
| 9 |
# NOTE: Do not add whitespace between DB_STR( or DB_STR_A( and the message ID. |
| 10 |
|
| 11 |
# NOTE: Please update the MSG_DIRS if there is any new source dir. |
| 12 |
MSG_DIRS="../src/ ../util/ ../lang/dbm/ ../dist/gen_msg.awk" |
| 13 |
|
| 14 |
# Environment Configuration |
| 15 |
GREP_CMDS="grep ggrep" |
| 16 |
for i in $GREP_CMDS; do |
| 17 |
if [ "`which $i`" = "" ]; then |
| 18 |
continue |
| 19 |
fi |
| 20 |
echo "s_message_id test" > s_message_id.tmp |
| 21 |
$i "s_message_id test" s_message_id.tmp -o --include=*.tmp | \ |
| 22 |
$i -v "s_message_id.txt" > s_message_id.tmp.out 2>&1 |
| 23 |
if [ `$i "unrecognized option" s_message_id.tmp.out | wc -l` \ |
| 24 |
-eq 0 ] && [ `$i "invalid option" s_message_id.tmp.out | \ |
| 25 |
wc -l` -eq 0 ] && [ `$i "can't open" s_message_id.tmp.out | \ |
| 26 |
wc -l` -eq 0 ]; then |
| 27 |
GREP_CMD=$i |
| 28 |
break |
| 29 |
fi |
| 30 |
rm s_message_id.tmp s_message_id.tmp.out |
| 31 |
done |
| 32 |
if [ "$GREP_CMD" = "" ]; then |
| 33 |
echo "UNSUPPORTED COMMAND: (g)grep -o --include" |
| 34 |
echo "Please try other platform" |
| 35 |
exit |
| 36 |
fi |
| 37 |
|
| 38 |
pref=MSG_INDX |
| 39 |
|
| 40 |
get_value() { |
| 41 |
value=${1}${2} |
| 42 |
eval "echo $`echo $value`" |
| 43 |
} |
| 44 |
|
| 45 |
get_max() { |
| 46 |
if [ ${1} -gt ${2} ] ; then |
| 47 |
eval "echo ${1}" |
| 48 |
else |
| 49 |
eval "echo ${2}" |
| 50 |
fi |
| 51 |
} |
| 52 |
|
| 53 |
# Iterate source files and replace "BDB####" with the real message id. |
| 54 |
for i in $MSG_DIRS; do |
| 55 |
for f in `$GREP_CMD BDB#### -r $i -wl --include=*.c --include=*.h \ |
| 56 |
--include=*.in --include=*.awk | \ |
| 57 |
$GREP_CMD -v "../util/db_dump185.c" | \ |
| 58 |
$GREP_CMD -v "../util/db_sql_codegen"`; do |
| 59 |
IFS='/' |
| 60 |
set $f |
| 61 |
# There are 11 categories in the MSG_DIRS: |
| 62 |
# 1) COMMON; 2) DB; 3) AM; 4) ENV; 5) LOCK; 6) LOG; |
| 63 |
# 7) MPOOL; 8) REP; 9) SEQUENCE; 10) TXN; 11) UTIL. |
| 64 |
# |
| 65 |
# NOTE: Please add a new block (see below) and assign the values |
| 66 |
# of cat_indx and cat_dirs if there is new group, or update the |
| 67 |
# existing block if there is new source tree under the existing |
| 68 |
# group. |
| 69 |
if [ "$i" = "../util/" ] || [ "$i" = "../lang/dbm/" ]; then |
| 70 |
cat_indx=10 |
| 71 |
cat_dirs="../util/ ../lang/dbm/" |
| 72 |
elif [ "$3" = "common" ] || [ "$3" = "crypto" ] || \ |
| 73 |
[ "$3" = "fileops" ] || [ "$3" = "hmac" ] || \ |
| 74 |
[ "$3" = "os" ] || [ "$3" = "os_qnx" ] || \ |
| 75 |
[ "$3" = "os_vxworks" ] || [ "$3" = "os_windows" ]; then |
| 76 |
cat_indx=0 |
| 77 |
cat_dirs=$i"common "$i"crypto "$i"fileops " |
| 78 |
cat_dirs=$cat_dirs$i"hmac "$i"os "$i"os_qnx " |
| 79 |
cat_dirs=$cat_dirs$i"os_vxworks "$i"os_windows" |
| 80 |
elif [ "$3" = "db" ] || [ "$3" = "dbinc" ] || \ |
| 81 |
[ "$3" = "dbinc_auto" ]; then |
| 82 |
cat_indx=1 |
| 83 |
cat_dirs=$i"db "$i"dbinc "$i"dbinc_auto" |
| 84 |
elif [ "$3" = "btree" ] || [ "$3" = "hash" ] || \ |
| 85 |
[ "$3" = "heap" ] || [ "$3" = "qam" ]; then |
| 86 |
cat_indx=2 |
| 87 |
cat_dirs=$i"btree "$i"hash "$i"heap "$i"qam" |
| 88 |
elif [ "$3" = "dbreg" ] || [ "$3" = "env" ] ; then |
| 89 |
cat_indx=3 |
| 90 |
cat_dirs=$i"dbreg "$i"env" |
| 91 |
elif [ "$3" = "lock" ] || [ "$3" = "mutex" ]; then |
| 92 |
cat_indx=4 |
| 93 |
cat_dirs=$i"lock "$i"mutex" |
| 94 |
elif [ "$3" = "log" ]; then |
| 95 |
cat_indx=5 |
| 96 |
cat_dirs=$i"log" |
| 97 |
elif [ "$3" = "mp" ]; then |
| 98 |
cat_indx=6 |
| 99 |
cat_dirs=$i"mp" |
| 100 |
elif [ "$3" = "rep" ] || [ "$3" = "repmgr" ] || \ |
| 101 |
[ "$3" = "gen_msg.awk" ] ; then |
| 102 |
cat_indx=7 |
| 103 |
cat_dirs="../src/rep ../src/repmgr ../dist/gen_msg.awk" |
| 104 |
elif [ "$3" = "sequence" ]; then |
| 105 |
cat_indx=8 |
| 106 |
cat_dirs=$i"sequence" |
| 107 |
elif [ "$3" = "txn" ] || [ "$3" = "xa" ]; then |
| 108 |
cat_indx=9 |
| 109 |
cat_dirs=$i"txn "$i"xa" |
| 110 |
else |
| 111 |
echo "ERROR UNKNOWN PATH:" "$i""$3" |
| 112 |
exit |
| 113 |
fi |
| 114 |
|
| 115 |
unset IFS |
| 116 |
|
| 117 |
# Initialize MSG_INDX for each group if it is never initialized. |
| 118 |
if [ "`get_value $pref $cat_indx`" = "" ]; then |
| 119 |
# Get the start index, that is the next available number |
| 120 |
# for the current group. If there is no existing message |
| 121 |
# marked by DB_STR or DB_STR_A, the start index is the |
| 122 |
# first available integer in its range. Unless, it is |
| 123 |
# the next available integer in its range. |
| 124 |
MSG_START_NUM=`expr $cat_indx \* 500 + 1` |
| 125 |
DB_STR_NUM=`$GREP_CMD -E "DB_STR\(\"[0-9]{4}\"" -r \ |
| 126 |
$cat_dirs | wc -l` |
| 127 |
if [ $DB_STR_NUM -eq 0 ]; then |
| 128 |
DB_STR_NUM=`expr 0 + $MSG_START_NUM` |
| 129 |
else |
| 130 |
DB_STR_NUM=`$GREP_CMD -E "DB_STR\(\"[0-9]{4}\"" -oh \ |
| 131 |
-r $cat_dirs | sort | tail -n 1 | \ |
| 132 |
sed -e "s/DB_STR(//g" | sed -e "s/\"//g"` |
| 133 |
DB_STR_NUM=`expr 1 + $DB_STR_NUM` |
| 134 |
fi |
| 135 |
|
| 136 |
DB_STR_A_NUM=`$GREP_CMD -E "DB_STR_A\(\"[0-9]{4}\"" -r \ |
| 137 |
$cat_dirs | wc -l` |
| 138 |
if [ $DB_STR_A_NUM -eq 0 ]; then |
| 139 |
DB_STR_A_NUM=`expr 0 + $MSG_START_NUM` |
| 140 |
else |
| 141 |
DB_STR_A_NUM=`$GREP_CMD -E \ |
| 142 |
"DB_STR_A\(\"[0-9]{4}\"" -oh -r $cat_dirs | \ |
| 143 |
sort | tail -n 1 | \ |
| 144 |
sed -e "s/DB_STR_A(//g" | sed -e "s/\"//g"` |
| 145 |
DB_STR_A_NUM=`expr 1 + $DB_STR_A_NUM` |
| 146 |
fi |
| 147 |
|
| 148 |
MSG_START_INDX=`get_max $DB_STR_NUM $DB_STR_A_NUM` |
| 149 |
eval "$pref$cat_indx=$MSG_START_INDX" |
| 150 |
fi |
| 151 |
|
| 152 |
cat $f | awk '{ |
| 153 |
if(num<max && sub(/BDB####/, fill(num))==1) num++; |
| 154 |
print $0>"tmp.tmp" |
| 155 |
}END{ |
| 156 |
printf("%s", num)>"tmp.num"} |
| 157 |
function fill(i) { |
| 158 |
s="" |
| 159 |
j=4-length(i) |
| 160 |
while(j) { |
| 161 |
s=0""s |
| 162 |
j-- |
| 163 |
} |
| 164 |
return "\""s""i"\"" |
| 165 |
}' num=`get_value $pref $cat_indx` \ |
| 166 |
max=`expr \( $cat_indx + 1 \) \* 500` |
| 167 |
cp tmp.tmp $f |
| 168 |
eval "$pref$cat_indx=`sed 'q' tmp.num`" |
| 169 |
if [ "$cat_indx" -lt 11 ]; then |
| 170 |
if [ `get_value $pref $cat_indx` -ge \ |
| 171 |
`expr \( $cat_indx + 1 \) \* 500` ]; then |
| 172 |
echo "RANGE FULL" |
| 173 |
fi |
| 174 |
else |
| 175 |
echo "ERROR CATEGORY NUMBER: " $cat_indx |
| 176 |
fi |
| 177 |
rm tmp.tmp tmp.num |
| 178 |
done |
| 179 |
done |
| 180 |
|
| 181 |
# Check if there is any remaining "BDB####". |
| 182 |
# NOTE: If "BDB####" is not .c, .h, .in files, they won't be updated with the |
| 183 |
# real message id. |
| 184 |
if [ `$GREP_CMD "BDB####" -r $MSG_DIRS | wc -l` -gt 0 ]; then |
| 185 |
echo "WARNING: There is remaining BDB####. Please check:" |
| 186 |
$GREP_CMD "BDB####" -r $MSG_DIRS |
| 187 |
fi |