mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
psyc_text: added extra param
This commit is contained in:
parent
340b164f6d
commit
f0e3038e68
4 changed files with 10 additions and 10 deletions
|
@ -64,7 +64,7 @@ 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);
|
||||
typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *value, void *extra);
|
||||
|
||||
/**
|
||||
* Initializes the PSYC text state struct.
|
||||
|
@ -158,7 +158,7 @@ size_t psyc_getTextBytesWritten (psycTextState *state)
|
|||
*
|
||||
* @see http://about.psyc.eu/psyctext
|
||||
**/
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue);
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue, void *extra);
|
||||
|
||||
/** @} */ // end of text group
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ prefix = /usr
|
|||
libdir = ${prefix}/lib
|
||||
|
||||
INSTALL = install
|
||||
LIBS = libpsyc.a
|
||||
LIBS = libpsyc.a libpsyc.so
|
||||
|
||||
install: ${LIBS}
|
||||
|
||||
|
@ -10,7 +10,7 @@ libdir:
|
|||
${INSTALL} -d ${libdir}
|
||||
|
||||
${LIBS}: libdir
|
||||
${INSTALL} $@ ${libdir}
|
||||
-${INSTALL} $@ ${libdir}
|
||||
|
||||
clean:
|
||||
rm -f ${LIBS}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "lib.h"
|
||||
#include <psyc/text.h>
|
||||
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue)
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue, void* extra)
|
||||
{
|
||||
const char *start = state->tmpl.ptr, *end; // start & end of variable name
|
||||
const char *prev = state->tmpl.ptr + state->cursor;
|
||||
|
@ -35,7 +35,7 @@ psycTextRC psyc_text (psycTextState *state, psycTextCB getValue)
|
|||
continue; // [] is invalid, name can't be empty
|
||||
}
|
||||
|
||||
ret = getValue(start + state->open.length, end - start - state->open.length, &value);
|
||||
ret = getValue(start + state->open.length, end - start - state->open.length, &value, extra);
|
||||
|
||||
if (ret < 0)
|
||||
continue; // value not found, no substitution
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
uint8_t verbose;
|
||||
|
||||
psycTextValueRC getValueFooBar (const char *name, size_t len, psycString *value)
|
||||
psycTextValueRC getValueFooBar (const char *name, size_t len, psycString *value, void *extra)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -16,7 +16,7 @@ psycTextValueRC getValueFooBar (const char *name, size_t len, psycString *value)
|
|||
return PSYC_TEXT_VALUE_FOUND;
|
||||
}
|
||||
|
||||
psycTextValueRC getValueEmpty (const char *name, size_t len, psycString *value)
|
||||
psycTextValueRC getValueEmpty (const char *name, size_t len, psycString *value, void *extra)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -25,7 +25,7 @@ psycTextValueRC getValueEmpty (const char *name, size_t len, psycString *value)
|
|||
return PSYC_TEXT_VALUE_FOUND;
|
||||
}
|
||||
|
||||
psycTextValueRC getValueNotFound (const char *name, size_t len, psycString *value)
|
||||
psycTextValueRC getValueNotFound (const char *name, size_t len, psycString *value, void *extra)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -41,7 +41,7 @@ int testText (char *template, size_t tmplen, char *buffer, size_t buflen, psycSt
|
|||
psyc_initTextState(&state, template, tmplen, buffer, buflen);
|
||||
do
|
||||
{
|
||||
ret = psyc_text(&state, getValue);
|
||||
ret = psyc_text(&state, getValue, NULL);
|
||||
length += psyc_getTextBytesWritten(&state);
|
||||
switch (ret)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue