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

new style: psyc_functions, psycTypes, PSYC_MACROS

This commit is contained in:
psyc://psyced.org/~lynX 2011-04-25 23:40:38 +02:00
parent 7dc8effab6
commit e48a6ab1eb
15 changed files with 204 additions and 203 deletions

View file

@ -19,8 +19,8 @@ int main(int argc, char** argv)
int i;
for (i = 0; i < sizeof(vars) / sizeof(*vars); i++)
{
printf(">> %s: %ld %ld\n", vars[i], sizeof(vars[i]), sizeof(*vars[i]));
printf("%s: %d\n", vars[i], PSYC_isRoutingVar(vars[i], strlen(vars[i])));
printf(">> %s: %d %d\n", vars[i], sizeof(vars[i]), sizeof(*vars[i]));
printf("%s: %d\n", vars[i], psyc_isRoutingVar(vars[i], strlen(vars[i])));
}
return 0;

View file

@ -2,19 +2,19 @@
#include "../include/psyc/lib.h"
int main() {
if (PSYC_matches("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -1;
if (PSYC_matches("_failure_trash", 8, "_failure_unsuccessful_delivery_death", 0)) return -2;
if (PSYC_matches("_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -3;
unless (PSYC_matches("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -4;
unless (PSYC_matches("_truthahn", 0, "_failure_unsuccessful_delivery_death", 0)) return -5;
if (psyc_matches("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -1;
if (psyc_matches("_failure_trash", 8, "_failure_unsuccessful_delivery_death", 0)) return -2;
if (psyc_matches("_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -3;
unless (psyc_matches("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -4;
unless (psyc_matches("_truthahn", 0, "_failure_unsuccessful_delivery_death", 0)) return -5;
puts("PSYC_matches passed all tests.");
puts("psyc_matches passed all tests.");
unless (PSYC_inherits("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -11;
if (PSYC_inherits("_failure_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -12;
unless (PSYC_inherits("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -13;
unless (psyc_inherits("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -11;
if (psyc_inherits("_failure_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -12;
unless (psyc_inherits("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -13;
puts("PSYC_inherits passed all tests.");
puts("psyc_inherits passed all tests.");
return 0; // passed all tests
}

View file

@ -8,9 +8,9 @@ int main(int argc, char** argv)
{
int indx, ret;
char buffer[2048], oper;
PSYC_String name, value, elem;
PSYC_ParseState state;
PSYC_ParseListState listState;
psycString name, value, elem;
psycParseState state;
psycParseListState listState;
int file = open(argv[1],O_RDONLY);
if(file < 0)
@ -21,11 +21,11 @@ int main(int argc, char** argv)
write(1, buffer, indx);
write(1, ">> PARSE\n", 9);
PSYC_initParseState(&state);
PSYC_nextParseBuffer(&state, PSYC_newString(buffer, indx));
psyc_initParseState(&state);
psyc_nextParseBuffer(&state, psyc_newString(buffer, indx));
// try parsing that now
while ((ret = PSYC_parse(&state, &oper, &name, &value)))
while ((ret = psyc_parse(&state, &oper, &name, &value)))
{
switch (ret)
{
@ -41,9 +41,9 @@ int main(int argc, char** argv)
if (memcmp(name.ptr, "_list", 5) == 0)
{
write(1, ">>> LIST START\n", 15);
PSYC_initParseListState(&listState);
PSYC_nextParseListBuffer(&listState, value);
while ((ret = PSYC_parseList(&listState, &name, &value, &elem)))
psyc_initParseListState(&listState);
psyc_nextParseListBuffer(&listState, value);
while ((ret = psyc_parseList(&listState, &name, &value, &elem)))
{
switch (ret)
{

View file

@ -2,28 +2,29 @@
#include <unistd.h>
#include "../include/psyc/lib.h"
#include "../include/psyc/render.h"
#include "../include/psyc/syntax.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_Modifier routing[] = {
PSYC_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_source"), PSYC_C2ARG(myUNI),
psycModifier routing[] = {
psyc_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_source"), PSYC_C2ARG(myUNI),
PSYC_MODIFIER_ROUTING),
PSYC_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
psyc_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
PSYC_MODIFIER_ROUTING),
};
PSYC_Modifier entity[] = {
psycModifier entity[] = {
// presence is to be assigned permanently in distributed state
PSYC_newModifier2(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_degree_availability"),
psyc_newModifier2(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_degree_availability"),
avail, availlen, PSYC_PACKET_CHECK_LENGTH),
PSYC_newModifier2(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_description_presence"),
psyc_newModifier2(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_description_presence"),
desc, desclen, PSYC_PACKET_CHECK_LENGTH),
};
PSYC_Packet packet = PSYC_newPacket2(routing, PSYC_NUM_ELEM(routing),
psycPacket packet = psyc_newPacket2(routing, PSYC_NUM_ELEM(routing),
entity, PSYC_NUM_ELEM(entity),
PSYC_C2ARG("_notice_presence"),
NULL, 0,
@ -31,11 +32,11 @@ int writePresence(const char *avail, int availlen, const char *desc, int desclen
PSYC_PACKET_CHECK_LENGTH);
char buffer[512];
PSYC_render(&packet, buffer, sizeof(buffer));
psyc_render(&packet, buffer, sizeof(buffer));
write(0, buffer, packet.length);
/*
PSYC_RenderState *pb; // a chunk of mem will host both struct and buf1
psycRenderState *pb; // a chunk of mem will host both struct and buf1
// char *t;
// unsigned int l;
@ -46,20 +47,20 @@ int writePresence(const char *avail, int availlen, const char *desc, int desclen
P0(("Out of memory\n"))
return -1;
}
// if (PSYC_initBuffer(pb, WHATEVER)) die("PSYC_initBuffer hates me");
// if (psyc_initBuffer(pb, WHATEVER)) die("psyc_initBuffer hates me");
(void) PSYC_renderModifier(pb, "_context", 0,
(void) psyc_renderModifier(pb, "_context", 0,
myUNI, sizeof(myUNI), PSYC_RENDER_ROUTING, 0);
// the first call to PSYC_renderHeader() without PSYC_RENDER_ROUTING adds the
// the first call to psyc_renderHeader() without PSYC_RENDER_ROUTING adds the
// extra newline to the buffer. later vars with PSYC_RENDER_ROUTING cause an error.
(void) PSYC_renderModifier(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_OPERATOR_ASSIGN);
(void) PSYC_renderModifier(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_OPERATOR_ASSIGN);
(void) psyc_renderModifier(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_OPERATOR_ASSIGN);
(void) psyc_renderModifier(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_OPERATOR_ASSIGN);
// presence is to be assigned permanently in distributed state
(void) PSYC_renderBody(pb, "_notice_presence", 0,
(void) psyc_renderBody(pb, "_notice_presence", 0,
NULL, 0); // no data in packet
// (void) PSYC_doneRender(pb, &t, &l);
// (void) psyc_doneRender(pb, &t, &l);
// write(stdout, t, l);
free(pb);
*/