1
0
Fork 0
arangodb/utils/flex-c.sh

40 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
FLEX="$1"
OUTPUT="$2"
INPUT="$3"
if test "x$FLEX" = "x" -o "x$OUTPUT" = "x" -o "x$INPUT" = "x"; then
echo "usage: $0 <flex> <output> <input>"
exit 1
fi
#############################################################################
## flex
#############################################################################
${FLEX} -L -o${OUTPUT} ${INPUT}
#############################################################################
## sanity checks
#############################################################################
test -f ${OUTPUT} || exit 1
#############################################################################
## fix casts
#############################################################################
cat ${OUTPUT} \
| sed -e 's:yy_n_chars, (size_t) num_to_read );:yy_n_chars, (int) num_to_read );:' \
| sed -e 's:i = 0; i < _yybytes_len; :i = 0; i < (int) _yybytes_len; :' \
| sed -e 's:yyl = 0; yyl < yyleng; :yyl = 0; yyl < (int) yyleng; :' \
| awk '$0 == "extern int isatty (int );" {print "#ifndef _WIN32"; print $0; print "#endif"; next;} {print $0}' \
> ${OUTPUT}.tmp
# give some information
diff -u ${OUTPUT} ${OUTPUT}.tmp
# and move the files to the final destination
mv ${OUTPUT}.tmp ${OUTPUT} || exit 1