1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

Ignore comments at the beginning of the declarations section.

This commit is contained in:
Bruno Haible
2003-05-02 03:59:36 +00:00
parent c170151d67
commit 31f7c8a49e
3 changed files with 102 additions and 5 deletions

View File

@@ -1,3 +1,10 @@
2003-03-19 Bruno Haible <bruno@clisp.org>
* src/input.cc (Input::read_input): Ignore comments at the beginning
of the declarations section.
* doc/gperf.texi (Controls for GNU indent): New section.
Reported by Bruce Lilly <blilly@erols.com>.
2003-03-19 Bruno Haible <bruno@clisp.org> 2003-03-19 Bruno Haible <bruno@clisp.org>
* src/output.cc (Output::output_hash_function): Avoid lint warning if * src/output.cc (Output::output_hash_function): Avoid lint warning if

View File

@@ -122,6 +122,7 @@ Input Format to @code{gperf}
* Declarations:: Declarations. * Declarations:: Declarations.
* Keywords:: Format for Keyword Entries. * Keywords:: Format for Keyword Entries.
* Functions:: Including Additional C Functions. * Functions:: Including Additional C Functions.
* Controls for GNU indent:: Where to place directives for GNU @code{indent}.
Declarations Declarations
@@ -330,6 +331,7 @@ input format for each section.
* Declarations:: Declarations. * Declarations:: Declarations.
* Keywords:: Format for Keyword Entries. * Keywords:: Format for Keyword Entries.
* Functions:: Including Additional C Functions. * Functions:: Including Additional C Functions.
* Controls for GNU indent:: Where to place directives for GNU @code{indent}.
@end menu @end menu
It is possible to omit the declaration section entirely, if the @samp{-t} It is possible to omit the declaration section entirely, if the @samp{-t}
@@ -685,7 +687,7 @@ declaration section. If the @samp{-t} option (or, equivalently, the
these fields are simply ignored. All previous examples except the last these fields are simply ignored. All previous examples except the last
one contain keyword attributes. one contain keyword attributes.
@node Functions, , Keywords, Input Format @node Functions, Controls for GNU indent, Keywords, Input Format
@subsection Including Additional C Functions @subsection Including Additional C Functions
The optional third section also corresponds closely with conventions The optional third section also corresponds closely with conventions
@@ -695,6 +697,52 @@ file, is included verbatim into the generated output file. Naturally,
it is your responsibility to ensure that the code contained in this it is your responsibility to ensure that the code contained in this
section is valid C. section is valid C.
@node Controls for GNU indent, , Functions, Input Format
@subsection Where to place directives for GNU @code{indent}.
If you want to invoke GNU @code{indent} on a @code{gperf} input file,
you will see that GNU @code{indent} doesn't understand the @samp{%%},
@samp{%@{} and @samp{%@}} directives that control @code{gperf}'s
interpretation of the input file. Therefore you have to insert some
directives for GNU @code{indent}. More precisely, assuming the most
general input file structure
@example
@group
declarations part 1
%@{
verbatim code
%@}
declarations part 2
%%
keywords
%%
functions
@end group
@end example
@noindent
you would insert @samp{*INDENT-OFF*} and @samp{*INDENT-ON*} comments
as follows:
@example
@group
/* *INDENT-OFF* */
declarations part 1
%@{
/* *INDENT-ON* */
verbatim code
/* *INDENT-OFF* */
%@}
declarations part 2
%%
keywords
%%
/* *INDENT-ON* */
functions
@end group
@end example
@node Output Format, Binary Strings, Input Format, Description @node Output Format, Binary Strings, Input Format, Description
@section Output Format for Generated C Code with @code{gperf} @section Output Format for Generated C Code with @code{gperf}
@cindex hash table @cindex hash table

View File

@@ -620,15 +620,57 @@ Input::read_input ()
{ {
if (struct_decl) if (struct_decl)
{ {
/* Drop leading whitespace. */ /* Drop leading whitespace and comments. */
{ {
char *p = struct_decl; char *p = struct_decl;
unsigned int *l = struct_decl_linenos; unsigned int *l = struct_decl_linenos;
while (p[0] == '\n' || p[0] == ' ' || p[0] == '\t') for (;;)
{ {
if (p[0] == ' ' || p[0] == '\t')
{
p++;
continue;
}
if (p[0] == '\n') if (p[0] == '\n')
l++; {
p++; l++;
p++;
continue;
}
if (p[0] == '/')
{
if (p[1] == '*')
{
/* Skip over ANSI C style comment. */
p += 2;
while (p[0] != '\0')
{
if (p[0] == '*' && p[1] == '/')
{
p += 2;
break;
}
if (p[0] == '\n')
l++;
p++;
}
continue;
}
if (p[1] == '/')
{
/* Skip over ISO C99 or C++ style comment. */
p += 2;
while (p[0] != '\0' && p[0] != '\n')
p++;
if (p[0] == '\n')
{
l++;
p++;
}
continue;
}
}
break;
} }
if (p != struct_decl) if (p != struct_decl)
{ {