Will Estes [Thu, 25 Feb 2016 01:11:24 +0000 (20:11 -0500)]
Changed type of yy_n_chars to int; gh#53, sf#160.
The variable yy_n_chars had been of type yy_size_t which is incorrect
given its use in read(). While it might be adviseable to look at
defining a yy_ssize_t, there might be some issues doing this and so, for
now, at least, we'll punt back to int.
Will Estes [Wed, 24 Feb 2016 22:50:00 +0000 (17:50 -0500)]
Fixed size of bufferallocation, resolved gh#54.
The value of n_alloc was a count, not a size. Multiplying the value by the element size was incorrect. That multiplication was already being done and having it done twice was incorrect.
Tobias Klauser [Tue, 23 Feb 2016 14:59:42 +0000 (15:59 +0100)]
Emit no #line directives if gen_line_dirs is false, resolves igh#55.
There are two instances in the code which will print a #line directive
to the resulting lexer, regardless of the value of gen_line_dirs. Fix
them, so they also respect gen_line_dirs.
Tobias Klauser [Fri, 29 Jan 2016 13:31:54 +0000 (14:31 +0100)]
Used NULL constant instead of plain integer for NULL pointer.
The sparse static checker warns about using plain integer 0 as NULL
pointers in the generated lexer code. Fix this by using NULL
consistently for pointers.
Tobias Klauser [Fri, 29 Jan 2016 13:26:23 +0000 (14:26 +0100)]
Marked declaration and definition of yy_fatal_error as noreturn.
Only the declaration of yy_fatal_error is marked with
__attribute__((__noreturn__)) in case GCC >= 3 is used, but not the
definition. This leads to the sparse static checker to complain about
function declaration mismatch.
Fix it by defining a macro yynoreturn and using it for both the
declaration and the definition of yy_fatal_error.
Tobias Klauser [Wed, 27 Jan 2016 12:58:08 +0000 (13:58 +0100)]
Fixed declaration mismatch in yy_fatal_error.
The prototype declares yy_fatal_error parameter as "const char msg[]"
while the definition uses "const char* msg" (introduced by commit e9d5fc713f61b) which causes the sparse static checkers to produce an
error.
Fix this by adjusting the definition to use "const char* msg" as well.
Also change the C++ version accordingly so it matches the declaration in
FlexLexer.hpp.
Michael Reed [Fri, 25 Dec 2015 19:49:33 +0000 (14:49 -0500)]
Replace basename2() with basename(3).
Given the following program:
\#include <libgen.h>
\#include <stdio.h>
/* extracts basename from path, optionally stripping the extension "\.*"
* (same concept as /bin/sh `basename`, but different handling of extension). */
static char *basename2 (char *path)
{
char *b;
for (b = path; *path; path++)
if (*path == '/')
b = path + 1;
return b;
}
int main (int argc, char *argv[])
{
// From http://pubs.opengroup.org/onlinepubs/9699919799/
// ``Sample Input and Output Strings''
basename_compare("/usr/lib");
basename_compare("/usr/");
basename_compare("/");
basename_compare("///");
basename_compare("//usr//lib//");
return 0;
}
... and the program's output:
basename: lib
basename2: lib
basename: usr
basename2:
basename: /
basename2:
basename: /
basename2:
basename: lib
basename2:
... we can see that basename2() behaves the same as basename(3) in the
average use case, but messes up pretty severely in others. Besides
that, basename(3) is mandated by POSIX so should be present on modern
Unix-like systems, so we shouldn't define it ourselves.
Some notes:
- it doesn't appear to be mentioned in POSIX, but OpenBSD's basename(3)
returns NULL if the returned path componenet is > PATH_MAX, so add a
check for that
- basename(3) shouldn't return an empty string, so remove the
program_name[0] != '\0' check
Mike Frysinger [Sun, 13 Dec 2015 04:28:43 +0000 (23:28 -0500)]
tests: fixed paths to input files.
The current test wrapper works only when the inputs are specified using
relative paths. If they're specified with absolute paths, the driver
fails to detect the inputs because it always prepends the input dir name
which itself is a relative path:
$ cd tests
$ ./testwrapper.sh -d . -i $PWD/reject.txt -t ./reject_ver.table
<fails to open inputs>
This normally doesn't show up because people run `./configure` or, for
out of tree builds, `../configure`. But if you happen to run configure
with an absolute path, then automake tends to generate absolute paths
as well leading to test failures.
Fix all of this by dropping the implicit input directory prepending.
- INPUT_NAME is often a list of files, not just a single one
- the input directory is used to find the testname tables which are
usually generated, so it's impossible to use files from both source
and build directories
- most of the time, the full/correct path is already specified
This is taken from OpenSSH Portable, which in turn takes it from
OpenBSD.
reallocarray wraps the stdlib's realloc function. It takes two size
arguments and checks for overflow, like calloc, but doesn't zero the
memory. Therefore, it allows us to do overflow-safe array reallocations
and overflow-safe unzeroed array allocations, which the stdlib
allocation functions don't.
We have a bunch of specific array allocation macros, none of
which check for overflow. reallocarray should be able to replace them.
Given the age of the MS-DOS and VMS platforms, it's likely that no one is building flex on them any more. Additionally, the preferred approach is to test for particular platform features rather than to test for particular platforms.
Will Estes [Fri, 11 Dec 2015 15:41:08 +0000 (10:41 -0500)]
Updated build documentation; finished sf#155.
Removed version numbers for build tools. Noted that version requirements for build tools will be noted in configure.ac. Expanded documentation of building texinfo based docs.
The function flex_alloc() was just a wrapper around malloc(). Since this only added unclarity, and the flex_alloc() function is likely a legacy of olden times, remove it in favor of calls to malloc() directly.
Style elements cleaned up:
* superfluous spacing around parentheses
* non-constant initialization in variable declarations
* needless casts
* almost all uses of assignments as subexpressions
Will Estes [Mon, 7 Dec 2015 20:37:01 +0000 (15:37 -0500)]
Built flex with itself.
Changes in scan.l need to be built into flex with the same version of
flex in some cases. Since this build requirement is minimal, we simply
bootstrap flex unconditionally.
We intentionally exclude from version control the bootstrap artifacts as
the extra copy of the lexer, the intermediate scanner and the bootstrap
executable are not of interest.
Like copy_string(), copy_unsigned_string() is just a clone of the
stlib's strdup(). We only use it twice. I'm pretty confident that char
signedness is irrelevant in this case.
Akim Demaille [Fri, 4 Dec 2015 15:37:03 +0000 (16:37 +0100)]
Generated skel.c explicitly in srcdir.
Rewrote the target for skel.c to explicitly mention the srcdir. This
should help when building flex from a directory outside the flex
tree. Spread the rule out over several lines to enhance readability.
Akim Demaille [Fri, 4 Dec 2015 15:36:17 +0000 (16:36 +0100)]
Called glibtoolize if libtoolize run fails.
On Mac OS X, libtoolize is known as glibtoolize. In cases where libtoolize is not present, then calling glibtoolize when bootstrapping the build system gives more folks a shot at getting flex built from the ground up.
Mightyjo [Thu, 3 Dec 2015 02:25:11 +0000 (21:25 -0500)]
Checked for (g)texi2dvi. Better bison, help2man checks.
Added test for presence of (g)texi2dvi program. Gave notice if texi2dvi
is unavailable and set TEXI2DVI=: to avoid giving users headaches.
Enhanced tests for bison and help2man with notices when the programs
aren't found. Set their program variables to use the missing script
in build-aux since it's compatible with them.
copy_string() was a clone of the stdlib's strdup(). For safety,
simplicity, and speed, we should use that instead. We introduce xstrdup() which wraps strdup() in a failure upon memory allocation errors.
Mightyjo [Sat, 28 Nov 2015 02:38:23 +0000 (21:38 -0500)]
Replaced CHAR macro with unsigned char type.
Thanks to Michael McConville for pointing out that the old Char macro
causes problems with static analysis. The macro has been removed and
replaced with 'unsigned char' throughout the flex sources. The macro is
not needed at best and was confusing at worst. It was not used in any of
the example files nor was it mentioned in the manual at all.
Stefan Reinauer [Thu, 14 May 2015 18:16:04 +0000 (11:16 -0700)]
Switch function definitions from mixed K&R to consistent ANSI C.
flex was using K&R function definitions for some functions and
ANSI C style in others, sometimes even in the same file. Change
the code to consistently use ANSI C.
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
lukeallardyce [Fri, 13 Nov 2015 19:48:19 +0000 (14:48 -0500)]
Supplied versioning information in flex libraries.
Resolves sourceforge bug #182. On OSX, and possibly other platforms, building the libfl libraries without versioning information caused a build failures.
Will Estes [Fri, 13 Nov 2015 02:44:07 +0000 (21:44 -0500)]
Cleaned up more precisely after make check.
BUILT_SOURCES is now just the list of headers built as per the
automake manual. We provide the list of files to clean to make
rebuilding the test suite programs easier. We then use the CLEANFILES
list in a dist-hook to clean up the distribution that automake gathers
since not distributing flex generated files is foreign to automake's
mindset, but we need exactly that.
Additionally, we locate inputs to the tables-related tests more
precisely. Some files are in srcdir and some are in builddir, which
the arguments to the log compiler are now made aware of.
Will Estes [Wed, 11 Nov 2015 20:20:56 +0000 (15:20 -0500)]
Changed man page dependencies.
The man page is just the --help output as reformatted by help2man. The
--help option is most likely to change when the flex skeleton changes
or one of the option parsing files changes or the configure.ac script
itself changes. The dependencies reflect this now.
It is still necessary, under some circumstances, to rebuild flex
explicitly before building the man page. In theory, it's possible to
have automake arrange to do this all the time, but doing so works out
to be fragile, given the rest of the build system.
Mightyjo [Tue, 27 Oct 2015 03:35:00 +0000 (20:35 -0700)]
Changed several pointers to istream (and ostream) to references in c++-only sections of the skeleton.
Patched up a variety of expected errors caused by changing istream* to istream&.
Added a stray 'make' at line 545. Oops.
Changed the buffer_state struct to store std::streambuf* instead of std::istream* for C++ mode. Changed interfaces in FlexLexer.h to take std::istream& instead of *. Backward compatibility temporarily broken.
Patched up backward compatibility with reasonable behavior in the presence of null pointers.
Re-added backward-compatible versions of the yyFlexLexer methods that take iostream pointers. All tests passing.