1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

psyc_text params

This commit is contained in:
Gabor Adam Toth 2012-01-04 23:32:01 +01:00
parent aad05d8483
commit 5fc5c5079a
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 * PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text
* leaves the original template text as is. * leaves the original template text as is.
*/ */
typedef PsycTextValueRC (*PsycTextCB) (const char *name, size_t len, typedef PsycTextValueRC (*PsycTextCB) (void *cls, const char *name, size_t namelen,
PsycString *value, void *extra); PsycString *value);
/** /**
* Initializes the PSYC text state struct. * Initializes the PSYC text state struct.
@ -156,7 +156,7 @@ psyc_text_bytes_written (PsycTextState *state)
* @see http://about.psyc.eu/psyctext * @see http://about.psyc.eu/psyctext
**/ **/
PsycTextRC 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; 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 static inline size_t
psyc_render_modifier (PsycModifier * mod, char *buffer) psyc_render_modifier (PsycModifier *mod, char *buffer)
{ {
size_t cur = 0; size_t cur = 0;
@ -87,7 +87,7 @@ psyc_render_modifier (PsycModifier * mod, char *buffer)
static inline static inline
#endif #endif
PsycRenderRC 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; size_t i, cur = 0, len;

View file

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

View file

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