Andre Noll [Wed, 12 Jul 2017 09:23:48 +0000 (11:23 +0200)]
config_file.l: Make the scanner reentrant.
This replaces the three global variables by a structure and modifies
lls_convert_config() to call yylex_init_extra() instead of yy_init()
to make a reference to the structure available to the actions.
Andre Noll [Wed, 12 Jul 2017 09:43:25 +0000 (11:43 +0200)]
config_file.l: Instruct flex to create a reentrant scanner.
This requires some modifications:
* Most functions take an additional yyscan_t argument.
* We must call yylex_init and yylex_destroy().
* Accessor methods must be used to get yytext and yylen.
We used to set the initial start condition in lls_convert_config(),
before the call to yylex(). For reentrant scanners, however,
the BEGIN macro can not be used in the user code section where
lls_convert_config() is located. But pushing a state works and should
be equivalent.
The generated scanner is not reentrant yet because it still has global
variables. This issue will be addressed in a subsequent patch.
Andre Noll [Tue, 11 Jul 2017 20:24:10 +0000 (22:24 +0200)]
config_file.l: Move helper functions to user code section.
These functions refer to the global variables yytext and yylen.
Reentrant scanners need to use accessor methods instead of accessing
the global variables directly. But these methods are not available
in the definitions section.
As a preparation for making the scanner reentrant, this patch moves
the three helper functions from the definitions section to the user
code section. Since the functions are called from the actions of the
pattern rules, we need to provide forward declarations.
Andre Noll [Tue, 11 Jul 2017 19:41:47 +0000 (21:41 +0200)]
config_file.l: Change default prefix for global symbols.
Without this, applications which use flex for their own work might run
into problems due to duplicate symbols when linking against liblopsub.
Since this is an ABI change, we have to increment the ABI version
number.
No changes in the source code are necessary since flex provides macros
which allow to still refer to the variables and functions with the
usual yy prefixed names. However, the command
nm -e liblopsub.a
shows that the external symbols are now prefixed with lls_yy.
Note that the patch only changes config_file.l. We don't bother to
adjust lopsubgen.l in the same way because the object file which
is derived from lopsubgen.l is not part of the library. It is only
linked into the lopsubgen executable.
Andre Noll [Wed, 12 Jul 2017 09:33:48 +0000 (11:33 +0200)]
version-gen.sh: Make it work in conflicted state.
If the working tree contains unmerged paths, git update-index -q
prints a "file: needs merge" message to stdout. This message confuses
the build system which runs this git command via version-gen.sh and
expects it to output a git version string.
This commit redirects stdout of the git command to /dev/null to make
sure that version-gen.sh outputs only the version string.
Andre Noll [Fri, 21 Apr 2017 22:02:05 +0000 (00:02 +0200)]
lopsub.c: Fix a NULL pointer dereference and a double free.
The error path of lls_deserialize_parse_result() has two issues:
* if the allocation of lor->value fails, we dereference a NULL pointer
in the cleanup part after label free_options because in
free(lor->value[j].string_val);
lor->value is NULL.
* if the strdup() for a multiple option fails in the inner loop, we
deallocate all previously allocated strings, jump to the free_options
label, and attempt to free the same values again.
The root of both bugs is that we start the cleanup in the error case
using the current value of the outer loop index i. The fix is to
perform cleanup of the allocated memory for option i already in the
allocation loop and let the cleanup loop iterate downwards from i - 1.
Andre Noll [Fri, 21 Apr 2017 00:55:53 +0000 (02:55 +0200)]
Avoid warning about yywrap being redefined.
The flex documentation says
If you do not supply your own version of 'yywrap()', then you must
either use '%option noyywrap' (in which case the scanner behaves as
though 'yywrap()' returned 1), or you must link with '-lfl' to obtain
the default version of the routine, which always returns 1.
Unfortunately, if noyywrap is given, gcc-5.4.0 complains with
config_file.c:417:0: warning: "yywrap" redefined
^
config_file.c:74:0: note: this is the location of the previous definition
Just provide our own yywrap() to silence the warning.
Andre Noll [Sat, 22 Oct 2016 13:47:12 +0000 (15:47 +0200)]
The long option parser for subcommands (lopsub).
This library was under development for over a year and is now ready
for prime time. The code is believed to be mature and no bugs are
known at this time. The API is fully documented and stable, and no
new features are planned. Future fixes and enhancements will take
backwards compatibility into account.
The code used to be part of the paraslash package, but has been
moved to its own repository. All prior commits have been discarded,
so this repository contains only the final result as a single commit.
The input files for the lopsubgen utility and the config file parser
are based on flex. The API documentation is created with gendoc.m4,
a simple m4 file which is part of this repository.
Documentation includes the three man pages lopsub.7, lopsubgen.1 and
lopsub.suite.5 which describe different aspects of the library. There
is also an example application called lopsubex which illustrates
various features of the library.