3 ms·
If the author sees this, there's a comment on your HTTP Verb parsing post that says: "The major drawback of gperf is that it generates function "exists", while
by benwills 3y ago
If the author sees this, there's a comment on your HTTP Verb parsing post that says:
"The major drawback of gperf is that it generates function "exists", while we need a "lookup"."
gperf allows for returning actual values. I use it in a whole lot of ways (enough that I've written code that imports data to then generate enums, execute gperf and import generated code, etc), including for generating lookups for HTTP Verbs.
Let me know if you want to know how that's done and I can give more details.
- anonymoushn 3y agoSure how do you do that?
- benwills 3y agoHere's a sample gperf config file I just recently used/auto-generated (with the data labels modified): struct SomeData_Gperf_st { const char* strKey; SomeData_et enumVal; }; %compare-lengths %compare-strncmp %enum %ignore-case %includes %readonly-tables %struct-type %define slot-name strKey %define lookup-function-name SomeData_Find %% val 1, SOME_DATA__VAL_1 val 2, SOME_DATA__VAL_2 The important option here is the %struct-type option. Using that, it will find and parse the struct definition (above in the configuration), and use that to create the objects in the lookup table. The lookup table is defined after the two percent signs; %%. You simply use comma separated values. And then you just have to define the const char* to use for the lookup string, as defined by `%define slot-name` So, gperf will then generate a function, SomeData_Find(), which returns a pointer to a SomeData_Gperf_st object. Or NULL if it's not found. There are a number of other options available, but what you're seeing above are the options I use most often. And, finally, I execute a command like this to run it with that config: gperf SomeData.gperf.confg --output-file=SomeData_Find.c --multiple-iterations=100
- benwills 3y agoAlso, if you get stuck with it or want to configure it differently (eg: using a struct definition or values defined elsewhere), feel free to reach out to my username at gmail. Just make sure to use a dot between my first and last name.