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

38 lines
1.1 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 );:' \
| 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