mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
RenderHeader
This commit is contained in:
parent
9fd39c72a1
commit
893a318b82
5 changed files with 90 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
|||
CFLAGS=-I../include -DDEBUG -g -O0 -Wall
|
||||
LDFLAGS=-L../src
|
||||
LOADLIBES=-lpsyc
|
||||
TARGETS=testParser testMatch
|
||||
TARGETS=testParser testMatch testRender
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
|
@ -10,3 +10,5 @@ test:
|
|||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
|
||||
it: all
|
||||
|
|
42
test/testRender.c
Normal file
42
test/testRender.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <stdlib.h>
|
||||
#include "../include/psyc/lib.h"
|
||||
#include "../include/psyc/render.h"
|
||||
|
||||
#define myUNI "psyc://10.100.1000/~ludwig"
|
||||
|
||||
/* example renderer generating a presence packet */
|
||||
int writePresence(const char *avail, int availlen, const char *desc, int desclen) {
|
||||
PSYC_RenderState *pb; // a chunk of mem will host both struct and buf1
|
||||
// char *t;
|
||||
// unsigned int l;
|
||||
|
||||
unless (availlen) availlen = strlen(avail);
|
||||
unless (desclen) desclen = strlen(desc);
|
||||
|
||||
if (!(pb = malloc(512))) {
|
||||
P0(("Out of memory\n"))
|
||||
return -1;
|
||||
}
|
||||
// if (PSYC_initBuffer(pb, WHATEVER)) die("PSYC_initBuffer hates me");
|
||||
|
||||
(void) PSYC_renderHeader(pb, "_context", 0,
|
||||
myUNI, sizeof(myUNI), PSYC_FLAG_ROUTING, 0);
|
||||
|
||||
// the first call to PSYC_renderHeader() without PSYC_FLAG_ROUTING adds the
|
||||
// extra newline to the buffer. later vars with PSYC_FLAG_ROUTING cause an error.
|
||||
(void) PSYC_renderHeader(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_MODIFIER_ASSIGN);
|
||||
(void) PSYC_renderHeader(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_MODIFIER_ASSIGN);
|
||||
// presence is to be assigned permanently in distributed state
|
||||
|
||||
(void) PSYC_renderBody(pb, "_notice_presence", 0,
|
||||
NULL, 0); // no data in packet
|
||||
// (void) PSYC_doneRender(pb, &t, &l);
|
||||
// write(stdout, t, l);
|
||||
free(pb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
return writePresence("_here", 0, "I'm omnipresent right now", 0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue