psyc_text params

This commit is contained in:
tg(x) 2012-01-04 23:32:01 +01:00
parent 30351302bc
commit cd2e898c40
4 changed files with 11 additions and 11 deletions

View File

@ -62,8 +62,8 @@ typedef struct {
* PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text
* leaves the original template text as is.
*/
typedef PsycTextValueRC (*PsycTextCB) (const char *name, size_t len,
PsycString *value, void *extra);
typedef PsycTextValueRC (*PsycTextCB) (void *cls, const char *name, size_t namelen,
PsycString *value);
/**
* Initializes the PSYC text state struct.
@ -156,7 +156,7 @@ psyc_text_bytes_written (PsycTextState *state)
* @see http://about.psyc.eu/psyctext
**/
PsycTextRC
psyc_text (PsycTextState *state, PsycTextCB getValue, void *extra);
psyc_text (PsycTextState *state, PsycTextCB get_value, void *get_value_cls);
extern const PsycTemplates psyc_templates;

View File

@ -60,7 +60,7 @@ psyc_render_table (PsycTable *table, char *buffer, size_t buflen)
}
static inline size_t
psyc_render_modifier (PsycModifier * mod, char *buffer)
psyc_render_modifier (PsycModifier *mod, char *buffer)
{
size_t cur = 0;
@ -87,7 +87,7 @@ psyc_render_modifier (PsycModifier * mod, char *buffer)
static inline
#endif
PsycRenderRC
psyc_render (PsycPacket * packet, char *buffer, size_t buflen)
psyc_render (PsycPacket *packet, char *buffer, size_t buflen)
{
size_t i, cur = 0, len;

View File

@ -6,7 +6,7 @@ const PsycTemplates psyc_templates = { .s = {
}};
PsycTextRC
psyc_text (PsycTextState *state, PsycTextCB get_value, void *extra)
psyc_text (PsycTextState *state, PsycTextCB get_value, void *get_value_cls)
{
const char *start = state->tmpl.data, *end; // start & end of variable name
const char *prev = state->tmpl.data + state->cursor;
@ -38,8 +38,8 @@ psyc_text (PsycTextState *state, PsycTextCB get_value, void *extra)
continue; // [] is invalid, name can't be empty
}
ret = get_value(start + state->open.length,
end - start - state->open.length, &value, extra);
ret = get_value(get_value_cls, start + state->open.length,
end - start - state->open.length, &value);
if (ret < 0)
continue; // value not found, no substitution

View File

@ -8,7 +8,7 @@
uint8_t verbose;
PsycTextValueRC
getValueFooBar (const char *name, size_t len, PsycString *value, void *extra)
getValueFooBar (void *cls, const char *name, size_t len, PsycString *value)
{
if (verbose)
printf("> getValue: %.*s\n", (int)len, name);
@ -18,7 +18,7 @@ getValueFooBar (const char *name, size_t len, PsycString *value, void *extra)
}
PsycTextValueRC
getValueEmpty (const char *name, size_t len, PsycString *value, void *extra)
getValueEmpty (void *cls, const char *name, size_t len, PsycString *value)
{
if (verbose)
printf("> getValue: %.*s\n", (int)len, name);
@ -28,7 +28,7 @@ getValueEmpty (const char *name, size_t len, PsycString *value, void *extra)
}
PsycTextValueRC
getValueNotFound (const char *name, size_t len, PsycString *value, void *extra)
getValueNotFound (void *cls, const char *name, size_t len, PsycString *value)
{
if (verbose)
printf("> getValue: %.*s\n", (int)len, name);