summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-05-02 03:59:36 +0000
committerBruno Haible <bruno@clisp.org>2003-05-02 03:59:36 +0000
commit31f7c8a49ebd4e8ccd4b4d01c7aca9922ff407f0 (patch)
tree77357a74f570488c06f7eebc0ed48e71aa380888
parentc170151d6755c4229439882784e275f9584ab186 (diff)
downloadgperf-31f7c8a49ebd4e8ccd4b4d01c7aca9922ff407f0.tar.gz
Ignore comments at the beginning of the declarations section.
-rw-r--r--ChangeLog7
-rw-r--r--doc/gperf.texi50
-rw-r--r--src/input.cc50
3 files changed, 102 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index d68c70c..febaf98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
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>
+
* src/output.cc (Output::output_hash_function): Avoid lint warning if
not all arguments of the hash function are used. Avoid lint warning
for fallthrough in switch.
diff --git a/doc/gperf.texi b/doc/gperf.texi
index 5901e23..902da6d 100644
--- a/doc/gperf.texi
+++ b/doc/gperf.texi
@@ -122,6 +122,7 @@ Input Format to @code{gperf}
* Declarations:: Declarations.
* Keywords:: Format for Keyword Entries.
* Functions:: Including Additional C Functions.
+* Controls for GNU indent:: Where to place directives for GNU @code{indent}.
Declarations
@@ -330,6 +331,7 @@ input format for each section.
* Declarations:: Declarations.
* Keywords:: Format for Keyword Entries.
* Functions:: Including Additional C Functions.
+* Controls for GNU indent:: Where to place directives for GNU @code{indent}.
@end menu
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
one contain keyword attributes.
-@node Functions, , Keywords, Input Format
+@node Functions, Controls for GNU indent, Keywords, Input Format
@subsection Including Additional C Functions
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
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
@section Output Format for Generated C Code with @code{gperf}
@cindex hash table
diff --git a/src/input.cc b/src/input.cc
index dc9a2c6..0c0c819 100644
--- a/src/input.cc
+++ b/src/input.cc
@@ -620,15 +620,57 @@ Input::read_input ()
{
if (struct_decl)
{
- /* Drop leading whitespace. */
+ /* Drop leading whitespace and comments. */
{
char *p = struct_decl;
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')
- 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)
{