1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/bin/sh
#######################################################################
#
# pgAdmin III - PostgreSQL Tools
# Copyright (C) 2002 - 2012, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# parser.sh - Runs Flex and Bison and processes the generated files
#
#######################################################################
# Directory containing pgScript includes (relative to the src directory)
INCLUDEDIR="include/pgscript"
# Directory containing pgScript sources (relative to the src directory)
SOURCEDIR="pgscript"
# Headers generated by Bison that need to be moved to ${INCLUDEDIR}
FILESTOMOVE=( "location.hh" "parser.tab.hh" "position.hh" "stack.hh" )
# Flex destination
LEXER="pgscript/lex.pgs.cc"
# A temporary file
AUX="pgscript/auxfile"
# Bison destination
PARSER="pgscript/parser.tab.cc"
#######################################################################
# Find the current directory
THISDIR=`dirname $0`
PREVDIR="$PWD"
# Go to the directory on top of the script directory
echo -n "cd ${THISDIR}/.. ... "
cd "${THISDIR}/.."
echo "done"
pwd
echo ""
# Generate Bison file
echo -n "+ Generating Bison output... "
bison -o"${PARSER}" "${SOURCEDIR}/pgsParser.yy"
echo "done"
# Generate Flex file
echo -n "+ Generating Flex output... "
flex -o"${LEXER}" "${SOURCEDIR}/pgsScanner.ll"
echo "done"
# Add pgAdmin3.h include at the beginning and change <FlexLexer.h> to
# "pgscript/FlexLexer.h" for the Flex output
echo -n "+ Processing Flex output... "
cat "${LEXER}" | awk 'BEGIN {print "#include \"pgAdmin3.h\"\n\n"}{print $0}' \
| sed -e 's/<FlexLexer\.h>/"pgscript\/FlexLexer\.h"/g' > "${AUX}"
mv -f "${AUX}" "${LEXER}"
echo "done"
# Add pgAdmin3.h include at the beginning and a pragma and change
# "parser.tab.hh" to "pgscript/parser.tab.hh" to the Bison output
echo -n "+ Processing Bison output... "
cat "${PARSER}" | awk 'BEGIN {print "#include \"pgAdmin3.h\"\n#if _MSC_VER > 1000\n#pragma warning(disable: 4800)\n#endif\n"}{print $0}' | \
sed -e 's/"parser.tab.hh"/"pgscript\/parser\.tab\.hh"/g' > "${AUX}"
sleep 1
mv -f "${AUX}" "${PARSER}"
echo "done"
# Move Bison include files to the include directory
echo + "Moving Bison header files... "
for file in ${FILESTOMOVE[@]}
do
echo " + mv ${SOURCEDIR}/${file} ${INCLUDEDIR}/${file}"
mv "${SOURCEDIR}/${file}" "${INCLUDEDIR}/${file}"
done
echo "... done"
# Go back to the previous directory
echo ""
echo -n "cd $PREVDIR ... "
cd "$PREVDIR"
echo "done"
|