Can gperf accept macro-defined keywords?

I would like something like the following gperf input file:

%{
#include <keywords.h>
// the contents of which contain
// #define KEYWORD1_MACRO "keyword1"
// #define KEYWORD2_MACRO "keyword2"
%}
%%
KEYWORD1_MACRO
KEYWORD2_MACRO
%%

      

Unfortunately gperf will interpret them as "KEYWORD1_MACRO" bites, etc.

The reason for this is that I have a protocol specification provided by the other party as a header file containing such #define

s. So I have no control over how they are defined and I would rather not write another preprocessing tool in the #include

header and output the macro expansion as quoted strings, only then to be used as input to the gperf file.

+3


source to share


1 answer


I did the following experiment which uses gcc -E

to handle these #include

s.

keywords.h:

#define KEYWORD1_MACRO "keyword1"
#define KEYWORD2_MACRO "keyword2"

      

test.c:



%{
#include "keywords.h"
%}
%%
KEYWORD1_MACRO
KEYWORD2_MACRO
%%

      

Team: gcc -E -o test.out.txt test.c

.
Then the content in the test.out.txt file:

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"
%{
# 1 "keywords.h" 1
# 3 "test.c" 2
%}
%%
"keyword1"
"keyword2"
%%

      

#include

processed automatically. Then you can do some word processing and file in gperf

.

+2


source







All Articles