[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.9 ‘gperf-code’ - emit the source of the generated gperf program

Usage: (gperf-code st-name)
Returns the contents of the emitted code, suitable for inclusion in another program. The interface contains the following elements:

struct <st-name>_index

containg the fields: {char const * name, int const id; };

<st-name>_hash()

This is the hashing function with local only scope (static).

<st-name>_find()

This is the searching and validation function. The first argument is the string to look up, the second is its length. It returns a pointer to the corresponding <st-name>_index entry.

Use this in your template as follows where "<st-name>" was set to be "lookup":

 
[+ (make-gperf "lookup" (join "\n" (stack "name_list")))
(gperf-code "lookup") +]
void my_fun(char * str) {
struct lookup_index * li = lookup_find(str, strlen(str));
if (li != NULL) printf("%s yields %d\n", str, li->idx);

Arguments:
st-name - the name of the gperf hash list


This document was generated by Bruce Korb on August 30, 2014 using texi2html 1.82.