1
0
Fork 0
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:
Gabor Adam Toth 2011-06-12 21:04:11 +02:00
parent 340b164f6d
commit f0e3038e68
4 changed files with 10 additions and 10 deletions

View file

@ -64,7 +64,7 @@ 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, psycString *value); typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *value, void *extra);
/** /**
* Initializes the PSYC text state struct. * Initializes the PSYC text state struct.
@ -158,7 +158,7 @@ size_t psyc_getTextBytesWritten (psycTextState *state)
* *
* @see http://about.psyc.eu/psyctext * @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 /** @} */ // end of text group

View file

@ -2,7 +2,7 @@ prefix = /usr
libdir = ${prefix}/lib libdir = ${prefix}/lib
INSTALL = install INSTALL = install
LIBS = libpsyc.a LIBS = libpsyc.a libpsyc.so
install: ${LIBS} install: ${LIBS}
@ -10,7 +10,7 @@ libdir:
${INSTALL} -d ${libdir} ${INSTALL} -d ${libdir}
${LIBS}: libdir ${LIBS}: libdir
${INSTALL} $@ ${libdir} -${INSTALL} $@ ${libdir}
clean: clean:
rm -f ${LIBS} rm -f ${LIBS}

View file

@ -1,7 +1,7 @@
#include "lib.h" #include "lib.h"
#include <psyc/text.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 *start = state->tmpl.ptr, *end; // start & end of variable name
const char *prev = state->tmpl.ptr + state->cursor; 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 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) if (ret < 0)
continue; // value not found, no substitution continue; // value not found, no substitution

View file

@ -7,7 +7,7 @@
uint8_t verbose; 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) if (verbose)
printf("> getValue: %.*s\n", (int)len, name); 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; 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) if (verbose)
printf("> getValue: %.*s\n", (int)len, name); 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; 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) if (verbose)
printf("> getValue: %.*s\n", (int)len, name); 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); psyc_initTextState(&state, template, tmplen, buffer, buflen);
do do
{ {
ret = psyc_text(&state, getValue); ret = psyc_text(&state, getValue, NULL);
length += psyc_getTextBytesWritten(&state); length += psyc_getTextBytesWritten(&state);
switch (ret) switch (ret)
{ {