aboutsummaryrefslogtreecommitdiffstats
path: root/tools/runlex.sh
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-03-30 18:44:01 -0700
committerGuy Harris <guy@alum.mit.edu>2016-04-03 22:21:29 +0000
commit59816ef00c6dd09532d80b393ba03f8194aba236 (patch)
treef5e84c67ebe0e69542db94d56db70fa476c0db6c /tools/runlex.sh
parente42a43bc58a36848316adae19981878a5f430c46 (diff)
Make the Flex scanners and YACC parser in libraries reentrant.
master-branch libpcap now generates a reentrant Flex scanner and Bison/Berkeley YACC parser for capture filter expressions, so it requires versions of Flex and Bison/Berkeley YACC that support that. We might as well do the same. For libwiretap, it means we could actually have multiple K12 text or Ascend/Lucent text files open at the same time. For libwireshark, it might not be as useful, as we only read configuration files at startup (which should only happen once, in one thread) or on demand (in which case, if we ever support multiple threads running libwireshark, we'd need a mutex to ensure that only one file reads it), but it's still the right thing to do. We also require a version of Flex that can write out a header file, so we change the runlex script to generate the header file ourselves. This means we require a version of Flex new enough to support --header-file. Clean up some other stuff encountered in the process. Change-Id: Id23078c6acea549a52fc687779bb55d715b55c16 Reviewed-on: https://code.wireshark.org/review/14719 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'tools/runlex.sh')
-rwxr-xr-xtools/runlex.sh91
1 files changed, 38 insertions, 53 deletions
diff --git a/tools/runlex.sh b/tools/runlex.sh
index 0592acb318..e78c8b0ed5 100755
--- a/tools/runlex.sh
+++ b/tools/runlex.sh
@@ -2,10 +2,9 @@
#
# runlex.sh
-# Script to run Lex/Flex.
+# Script to run Flex.
# First argument is the (quoted) name of the command; if it's null, that
-# means that neither Flex nor Lex was found, so we report an error and
-# quit.
+# means that Flex wasn't found, so we report an error and quit.
# Second arg is the sed executable
#
# Wireshark - Network traffic analyzer
@@ -30,9 +29,9 @@
#
# Get the name of the command to run, and then shift to get the arguments.
#
-if [ $# -eq 0 ]
+if [ $# -lt 2 ]
then
- echo "Usage: runlex <lex/flex command to run> [ arguments ]" 1>&2
+ echo "Usage: runlex <Flex command to run> <path to sed> [ arguments ]" 1>&2
exit 1
fi
@@ -51,18 +50,18 @@ esac
shift
#
-# Check whether we have it.
+# Check whether we have Flex.
#
if [ -z "${LEX}" ]
then
- echo "Neither lex nor flex was found" 1>&2
+ echo "Flex was not found" 1>&2
exit 1
fi
SED="$1"
shift
#
-# Check whether we have it.
+# Check whether we have sed.
#
if [ -z "${SED}" ]
then
@@ -72,7 +71,7 @@ fi
#
# Process the flags. We don't use getopt because we don't want to
-# embed complete knowledge of what options are supported by Lex/Flex.
+# embed complete knowledge of what options are supported by Flex.
#
flags=""
outfile=lex.yy.c
@@ -105,20 +104,27 @@ do
done
#
-# OK, run it.
+# Construct the name of the header file to generate; if the .c file is
+# .../foo.c, the header file will be .../foo_lex.h.
#
-#echo "Running ${LEX} -o$outfile $flags $@"
-${LEX} -o"$outfile" $flags "$@"
+#echo "Getting header file name"
+header_file=`dirname "$outfile"`/`basename "$outfile" .c`_lex.h
+
+#
+# OK, run Flex.
+#
+#echo "Running ${LEX} -o\"$outfile\" --header-file=\"$header_file\" $flags \"$@\""
+${LEX} -o"$outfile" --header-file="$header_file" $flags "$@"
#
# Did it succeed?
#
-if [ $? -ne 0 ]
+exitstatus=$?
+if [ $exitstatus -ne 0 ]
then
#
# No. Exit with the failing exit status.
#
- exitstatus=$?
echo "${LEX} failed: exit status $exitstatus"
exit $exitstatus
fi
@@ -129,6 +135,9 @@ fi
# This gets in the way of building in a directory different from the
# source directory. Try to work around this.
#
+# XXX - where is this an issue?
+#
+#
# Is the outfile where we think it is?
#
outfile_base=`basename "$outfile"`
@@ -138,6 +147,7 @@ then
# No, it's not, but it is in the current directory. Put it
# where it's supposed to be.
#
+echo "Moving $outfile_base to $outfile"
mv "$outfile_base" "$outfile"
if [ $? -ne 0 ]
then
@@ -145,47 +155,22 @@ then
fi
fi
-echo "Wrote `basename $outfile`"
-
-#
-# OK, now let's generate a header file declaring the relevant functions
-# defined by the .c file; if the .c file is .../foo.c, the header file
-# will be .../foo_lex.h.
#
-# This works around some other Flex suckage, wherein it doesn't declare
-# the lex routine before defining it, causing compiler warnings.
-# XXX - newer versions of Flex support --header-file=, to generate the
-# appropriate header file. With those versions, we should use that option.
-#
-
+# Is the header file where we think it is?
#
-# Get the name of the prefix; scan the source files for a %option prefix
-# line. We use the last one.
-#
-#echo "Getting prefix"
-prefix=`${SED} -n 's/%option[ ][ ]*prefix="\(.*\)".*/\1/p' "$@" | tail -1`
-if [ ! -z "$prefix" ]
+header_file_base=`basename "$header_file"`
+if [ "$header_file_base" != "$header_file" -a \( ! -r "$header_file" \) -a -r "$header_file_base" ]
then
- prefixline="#define yylex ${prefix}lex"
+ #
+ # No, it's not, but it is in the current directory. Put it
+ # where it's supposed to be.
+ #
+echo "Moving $header_file_base to $header_file"
+ mv "$header_file_base" "$header_file"
+ if [ $? -ne 0 ]
+ then
+ echo $?
+ fi
fi
-#
-# Construct the name of the header file.
-#
-#echo "Getting header file name"
-header_file=`dirname "$outfile"`/`basename "$outfile" .c`_lex.h
-
-#
-# Spew out the declaration.
-#
-#echo "Writing $header_file"
-cat <<EOF >$header_file
-/* This is generated by runlex.sh. Do not edit it. */
-$prefixline
-#ifndef YY_DECL
-#define YY_DECL int yylex(void)
-#endif
-YY_DECL;
-EOF
-
-echo "Wrote `basename $header_file`"
+echo "Wrote $outfile and $header_file"