mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
definition of PSYC_text()
This commit is contained in:
parent
5197f53f62
commit
e7772acb02
4 changed files with 34 additions and 0 deletions
|
@ -8,3 +8,31 @@
|
||||||
int PSYC_matches(uint8_t* sho, unsigned int slen,
|
int PSYC_matches(uint8_t* sho, unsigned int slen,
|
||||||
uint8_t* lon, unsigned int llen);
|
uint8_t* lon, unsigned int llen);
|
||||||
|
|
||||||
|
/** @brief Callback for PSYC_text() that produces a value for a match
|
||||||
|
*
|
||||||
|
* The application looks up a match such as _fruit from [_fruit] and
|
||||||
|
* if found writes its current value from its variable store into the
|
||||||
|
* outgoing buffer.. "Apple" for example. The template returns the
|
||||||
|
* number of bytes written. 0 is a legal return value. Should the
|
||||||
|
* callback return -1, PSYC_text leaves the original template text as is.
|
||||||
|
*/
|
||||||
|
typedef int (*PSYC_textCB)(uint8_t* match, unsigned int mlen,
|
||||||
|
uint8_t** buffer, unsigned int* blen);
|
||||||
|
|
||||||
|
/** @brief Fills out text templates by asking a callback for content
|
||||||
|
*
|
||||||
|
* Copies the contents of the template into the buffer while looking
|
||||||
|
* for braceOpen and braceClose strings and calling the callback for
|
||||||
|
* each enclosed string between these braces. Should the callback
|
||||||
|
* return -1, the original template text is copied as is.
|
||||||
|
*
|
||||||
|
* By default PSYC's "[" and "]" are used but you can provide any other
|
||||||
|
* brace strings such as "${" and "}" or "<!--" and "-->".
|
||||||
|
*
|
||||||
|
* See also http://about.psyc.eu/psyctext
|
||||||
|
*/
|
||||||
|
int PSYC_text(uint8_t* template, unsigned int tlen,
|
||||||
|
uint8_t** buffer, unsigned int* blen,
|
||||||
|
PSYC_textCB lookupValue,
|
||||||
|
char* braceOpen, char* braceClose);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "psyc/lib.h"
|
#include "psyc/lib.h"
|
||||||
|
|
||||||
|
/* TODO: PSYC_inherits() */
|
||||||
|
|
||||||
int PSYC_matches(uint8_t* sho, unsigned int slen,
|
int PSYC_matches(uint8_t* sho, unsigned int slen,
|
||||||
uint8_t* lon, unsigned int llen) {
|
uint8_t* lon, unsigned int llen) {
|
||||||
uint8_t *s, *l, *se, *le;
|
uint8_t *s, *l, *se, *le;
|
||||||
|
@ -30,6 +32,7 @@ int PSYC_matches(uint8_t* sho, unsigned int slen,
|
||||||
|
|
||||||
se = sho+slen;
|
se = sho+slen;
|
||||||
le = lon+llen;
|
le = lon+llen;
|
||||||
|
/* doesn't always work this way.. FIXME */
|
||||||
*se = *le = '_';
|
*se = *le = '_';
|
||||||
sho++; lon++;
|
sho++; lon++;
|
||||||
while(s = strchr(sho, '_')) {
|
while(s = strchr(sho, '_')) {
|
||||||
|
|
1
src/render.c
Normal file
1
src/render.c
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/* render PSYC packets */
|
2
src/text.c
Normal file
2
src/text.c
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/* PSYC_text() */
|
||||||
|
|
Loading…
Reference in a new issue