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:
parent
0f9f1bdc94
commit
d1ec497ef3
15 changed files with 204 additions and 203 deletions
|
@ -28,7 +28,7 @@ typedef enum
|
|||
{
|
||||
PSYC_FALSE = 0,
|
||||
PSYC_TRUE = 1,
|
||||
} PSYC_Bool;
|
||||
} psycBool;
|
||||
|
||||
/**
|
||||
* PSYC packet parts.
|
||||
|
@ -42,7 +42,7 @@ typedef enum
|
|||
PSYC_PART_METHOD,
|
||||
PSYC_PART_DATA,
|
||||
PSYC_PART_END,
|
||||
} PSYC_Part;
|
||||
} psycPart;
|
||||
|
||||
/**
|
||||
* Different types that a variable can have.
|
||||
|
@ -67,7 +67,7 @@ typedef enum
|
|||
PSYC_TYPE_PAGE,
|
||||
PSYC_TYPE_UNIFORM,
|
||||
PSYC_TYPE_TIME,
|
||||
} PSYC_Type;
|
||||
} psycType;
|
||||
|
||||
/**
|
||||
* List types.
|
||||
|
@ -77,7 +77,7 @@ typedef enum
|
|||
{
|
||||
PSYC_LIST_TEXT = 1,
|
||||
PSYC_LIST_BINARY = 2,
|
||||
} PSYC_ListType;
|
||||
} psycListType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -85,30 +85,30 @@ typedef enum
|
|||
PSYC_MODIFIER_NEED_LENGTH = 1,
|
||||
PSYC_MODIFIER_NO_LENGTH = 2,
|
||||
PSYC_MODIFIER_ROUTING = 3,
|
||||
} PSYC_ModifierFlag;
|
||||
} psycModifierFlag;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_PACKET_CHECK_LENGTH = 0,
|
||||
PSYC_PACKET_NEED_LENGTH = 1,
|
||||
PSYC_PACKET_NO_LENGTH = 2,
|
||||
} PSYC_PacketFlag;
|
||||
} psycPacketFlag;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t length;
|
||||
const char *ptr;
|
||||
} PSYC_String;
|
||||
} psycString;
|
||||
|
||||
/**
|
||||
* Shortcut for creating a PSYC_String.
|
||||
* Shortcut for creating a psycString.
|
||||
*
|
||||
* @param memory Pointer to the buffer.
|
||||
* @param length Length of that buffer.
|
||||
*
|
||||
* @return An instance of the PSYC_String struct.
|
||||
* @return An instance of the psycString struct.
|
||||
*/
|
||||
inline PSYC_String PSYC_newString (const char *str, size_t strlen);
|
||||
inline psycString psyc_newString (const char *str, size_t strlen);
|
||||
|
||||
#define PSYC_C2STR(string) {sizeof(string)-1, string}
|
||||
#define PSYC_C2ARG(string) string, sizeof(string)-1
|
||||
|
@ -117,88 +117,88 @@ inline PSYC_String PSYC_newString (const char *str, size_t strlen);
|
|||
typedef struct
|
||||
{
|
||||
char oper; // not call it 'operator' as C++ may not like that..
|
||||
PSYC_String name;
|
||||
PSYC_String value;
|
||||
PSYC_ModifierFlag flag;
|
||||
} PSYC_Modifier;
|
||||
psycString name;
|
||||
psycString value;
|
||||
psycModifierFlag flag;
|
||||
} psycModifier;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t lines;
|
||||
PSYC_Modifier *modifiers;
|
||||
} PSYC_ModifierArray;
|
||||
psycModifier *modifiers;
|
||||
} psycModifierArray;
|
||||
|
||||
/* intermediate struct for a PSYC packet */
|
||||
typedef struct
|
||||
{
|
||||
PSYC_ModifierArray routing; ///< Routing header.
|
||||
PSYC_ModifierArray entity; ///< Entitiy header.
|
||||
PSYC_String method;
|
||||
PSYC_String data;
|
||||
psycModifierArray routing; ///< Routing header.
|
||||
psycModifierArray entity; ///< Entitiy header.
|
||||
psycString method;
|
||||
psycString data;
|
||||
size_t routingLength; ///< Length of routing part.
|
||||
size_t contentLength; ///< Length of content part.
|
||||
size_t length; ///< Total length of packet.
|
||||
PSYC_PacketFlag flag;
|
||||
} PSYC_Packet;
|
||||
psycPacketFlag flag;
|
||||
} psycPacket;
|
||||
|
||||
inline int PSYC_version();
|
||||
inline int psyc_version();
|
||||
|
||||
inline PSYC_Modifier PSYC_newModifier(char oper, PSYC_String *name, PSYC_String *value,
|
||||
PSYC_ModifierFlag flag);
|
||||
inline psycModifier psyc_newModifier(char oper, psycString *name, psycString *value,
|
||||
psycModifierFlag flag);
|
||||
|
||||
inline PSYC_Modifier PSYC_newModifier2(char oper,
|
||||
inline psycModifier psyc_newModifier2(char oper,
|
||||
const char *name, size_t namelen,
|
||||
const char *value, size_t valuelen,
|
||||
PSYC_ModifierFlag flag);
|
||||
psycModifierFlag flag);
|
||||
|
||||
inline PSYC_Packet PSYC_newPacket(PSYC_ModifierArray *routing,
|
||||
PSYC_ModifierArray *entity,
|
||||
PSYC_String *method, PSYC_String *data,
|
||||
PSYC_PacketFlag flag);
|
||||
inline psycPacket psyc_newPacket(psycModifierArray *routing,
|
||||
psycModifierArray *entity,
|
||||
psycString *method, psycString *data,
|
||||
psycPacketFlag flag);
|
||||
|
||||
inline PSYC_Packet PSYC_newPacket2(PSYC_Modifier *routing, size_t routinglen,
|
||||
PSYC_Modifier *entity, size_t entitylen,
|
||||
inline psycPacket psyc_newPacket2(psycModifier *routing, size_t routinglen,
|
||||
psycModifier *entity, size_t entitylen,
|
||||
const char *method, size_t methodlen,
|
||||
const char *data, size_t datalen,
|
||||
PSYC_PacketFlag flag);
|
||||
psycPacketFlag flag);
|
||||
|
||||
/// Routing vars in alphabetical order.
|
||||
extern const PSYC_String PSYC_routingVars[];
|
||||
extern const psycString PSYC_routingVars[];
|
||||
/// Number of routing vars.
|
||||
extern const size_t PSYC_routingVarsNum;
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PSYC_Bool PSYC_isRoutingVar(const char *name, size_t len);
|
||||
psycBool psyc_isRoutingVar(const char *name, size_t len);
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PSYC_Type PSYC_getVarType(char *name, size_t len);
|
||||
psycType psyc_getVarType(char *name, size_t len);
|
||||
|
||||
/**
|
||||
* Checks if long keyword string inherits from short keyword string.
|
||||
*/
|
||||
int PSYC_inherits(char *sho, size_t slen,
|
||||
int psyc_inherits(char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Checks if short keyword string matches long keyword string.
|
||||
*/
|
||||
int PSYC_matches(char *sho, size_t slen,
|
||||
int psyc_matches(char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Callback for PSYC_text() that produces a value for a match.
|
||||
* 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.
|
||||
* callback return -1, psyc_text leaves the original template text as is.
|
||||
*/
|
||||
typedef int (*PSYC_textCB)(uint8_t *match, size_t mlen,
|
||||
typedef int (*psyctextCB)(uint8_t *match, size_t mlen,
|
||||
uint8_t **buffer, size_t *blen);
|
||||
|
||||
/**
|
||||
|
@ -214,9 +214,9 @@ typedef int (*PSYC_textCB)(uint8_t *match, size_t mlen,
|
|||
*
|
||||
* See also http://about.psyc.eu/psyctext
|
||||
*/
|
||||
int PSYC_text(uint8_t *template, size_t tlen,
|
||||
int psyc_text(uint8_t *template, size_t tlen,
|
||||
uint8_t **buffer, size_t *blen,
|
||||
PSYC_textCB lookupValue,
|
||||
psyctextCB lookupValue,
|
||||
char *braceOpen, char *braceClose);
|
||||
|
||||
#endif // PSYC_H
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
typedef enum
|
||||
{
|
||||
PSYC_PARSE_HEADER_ONLY = 1,
|
||||
} PSYC_ParseFlag;
|
||||
} psycParseFlag;
|
||||
|
||||
/**
|
||||
* The return value definitions for the packet parsing function.
|
||||
* @see PSYC_parse()
|
||||
* @see psyc_parse()
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -59,11 +59,11 @@ typedef enum
|
|||
PSYC_PARSE_COMPLETE = 7,
|
||||
/// Binary value parsing incomplete, used internally.
|
||||
PSYC_PARSE_INCOMPLETE = 8,
|
||||
} PSYC_ParseRC;
|
||||
} psycParseRC;
|
||||
|
||||
/**
|
||||
* The return value definitions for the list parsing function.
|
||||
* @see PSYC_parseList()
|
||||
* @see psyc_parseList()
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ typedef enum
|
|||
PSYC_PARSE_LIST_END = 2,
|
||||
/// Binary list is incomplete.
|
||||
PSYC_PARSE_LIST_INCOMPLETE = 3,
|
||||
} PSYC_ParseListRC;
|
||||
} psycParseListRC;
|
||||
|
||||
/**
|
||||
* Struct for keeping parser state.
|
||||
|
@ -87,16 +87,16 @@ typedef struct
|
|||
{
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t startc; ///< position where the parsing would be resumed
|
||||
PSYC_String buffer; ///< buffer with data to be parsed
|
||||
uint8_t flags; ///< flags for the parser, see PSYC_ParseFlag
|
||||
PSYC_Part part; ///< part of the packet being parsed currently
|
||||
psycString buffer; ///< buffer with data to be parsed
|
||||
uint8_t flags; ///< flags for the parser, see psycParseFlag
|
||||
psycPart part; ///< part of the packet being parsed currently
|
||||
|
||||
size_t contentParsed; ///< number of bytes parsed from the content so far
|
||||
size_t contentLength; ///< expected length of the content
|
||||
PSYC_Bool contentLengthFound; ///< is there a length given for this packet?
|
||||
psycBool contentLengthFound; ///< is there a length given for this packet?
|
||||
size_t valueParsed; ///< number of bytes parsed from the value so far
|
||||
size_t valueLength; ///< expected length of the value
|
||||
} PSYC_ParseState;
|
||||
} psycParseState;
|
||||
|
||||
/**
|
||||
* Struct for keeping list parser state.
|
||||
|
@ -105,60 +105,60 @@ typedef struct
|
|||
{
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t startc; ///< line start position
|
||||
PSYC_String buffer;
|
||||
PSYC_ListType type; ///< list type
|
||||
psycString buffer;
|
||||
psycListType type; ///< list type
|
||||
|
||||
size_t elemParsed; ///< number of bytes parsed from the elem so far
|
||||
size_t elemLength; ///< expected length of the elem
|
||||
} PSYC_ParseListState;
|
||||
} psycParseListState;
|
||||
|
||||
/**
|
||||
* Initiates the state struct.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initiated.
|
||||
*/
|
||||
inline void PSYC_initParseState (PSYC_ParseState* state);
|
||||
inline void psyc_initParseState (psycParseState* state);
|
||||
|
||||
/**
|
||||
* Initiates the state struct with flags.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initiated.
|
||||
* @param flags Flags to be set for the parser, see PSYC_ParseFlag.
|
||||
* @param flags Flags to be set for the parser, see psycParseFlag.
|
||||
*/
|
||||
inline void PSYC_initParseState2 (PSYC_ParseState* state, uint8_t flags);
|
||||
inline void psyc_initParseState2 (psycParseState* state, uint8_t flags);
|
||||
|
||||
/**
|
||||
* Initiates the list state struct.
|
||||
*
|
||||
* @param state Pointer to the list state struct that should be initiated.
|
||||
*/
|
||||
inline void PSYC_initParseListState (PSYC_ParseListState* state);
|
||||
inline void psyc_initParseListState (psycParseListState* state);
|
||||
|
||||
inline void PSYC_nextParseBuffer (PSYC_ParseState* state, PSYC_String newBuf);
|
||||
inline void psyc_nextParseBuffer (psycParseState* state, psycString newBuf);
|
||||
|
||||
inline void PSYC_nextParseListBuffer (PSYC_ParseListState* state, PSYC_String newBuf);
|
||||
inline void psyc_nextParseListBuffer (psycParseListState* state, psycString newBuf);
|
||||
|
||||
inline size_t PSYC_getContentLength (PSYC_ParseState* s);
|
||||
inline size_t psyc_getContentLength (psycParseState* s);
|
||||
|
||||
/**
|
||||
* Parse PSYC packets.
|
||||
*
|
||||
* Generalized line-based packet parser.
|
||||
*
|
||||
* @param state An initialized PSYC_ParseState
|
||||
* @param state An initialized psycParseState
|
||||
* @param operator A pointer to a character. In case of a variable, it will
|
||||
* be set to the operator of that variable
|
||||
* @param name A pointer to a PSYC_String. It will point to the name of
|
||||
* @param name A pointer to a psycString. It will point to the name of
|
||||
* the variable or method and its length will be set accordingly
|
||||
* @param value A pointer to a PSYC_String. It will point to the
|
||||
* @param value A pointer to a psycString. It will point to the
|
||||
* value/body the variable/method and its length will be set accordingly
|
||||
*/
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, PSYC_String* value);
|
||||
psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psycString* value);
|
||||
|
||||
/**
|
||||
* List value parser.
|
||||
*/
|
||||
PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_String *name, PSYC_String* value, PSYC_String* elem);
|
||||
psycParseListRC psyc_parseList(psycParseListState* state, psycString *name, psycString* value, psycString* elem);
|
||||
|
||||
#endif // PSYC_PARSER_H
|
||||
|
||||
|
|
|
@ -17,19 +17,19 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Return codes for PSYC_render.
|
||||
* Return codes for psyc_render.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
//PSYC_RENDER_ERROR_ROUTING = -2,
|
||||
PSYC_RENDER_ERROR = -1,
|
||||
PSYC_RENDER_SUCCESS = 0,
|
||||
} PSYC_RenderRC;
|
||||
} psycRenderRC;
|
||||
|
||||
/**
|
||||
* Render a PSYC packet into a buffer.
|
||||
*/
|
||||
PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen);
|
||||
psycRenderRC psyc_render(psycPacket *packet, char *buffer, size_t buflen);
|
||||
|
||||
/*
|
||||
typedef enum
|
||||
|
@ -38,7 +38,7 @@ typedef enum
|
|||
PSYC_RENDER_NEED_LENGTH = 1,
|
||||
PSYC_RENDER_NO_LENGTH = 2,
|
||||
PSYC_RENDER_ROUTING = 3,
|
||||
} PSYC_RenderFlag;
|
||||
} psycRenderFlag;
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,14 +47,14 @@ typedef enum
|
|||
/*
|
||||
typedef struct
|
||||
{
|
||||
PSYC_RenderFlag flag; ///< flags for the renderer
|
||||
PSYC_Part part; ///< part of the packet being rendered
|
||||
psycRenderFlag flag; ///< flags for the renderer
|
||||
psycPart part; ///< part of the packet being rendered
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t spot; ///< space for rendered length between the headers
|
||||
size_t contentLength; ///< length of the content part
|
||||
size_t length; ///< how big is the buffer we allocated
|
||||
char buffer[]; ///< OMG a C99 feature! variable size buffer!
|
||||
} PSYC_RenderState;
|
||||
} psycRenderState;
|
||||
*/
|
||||
/**
|
||||
* Initiates the state struct.
|
||||
|
@ -62,14 +62,14 @@ typedef struct
|
|||
* @param state Pointer to the state struct that should be initiated.
|
||||
*/
|
||||
/*
|
||||
inline void PSYC_initRenderState (PSYC_RenderState* state);
|
||||
inline void psyc_initRenderState (psycRenderState* state);
|
||||
|
||||
int PSYC_renderModifier(PSYC_RenderState* render,
|
||||
int psyc_renderModifier(psycRenderState* render,
|
||||
const char* name, size_t nlength,
|
||||
const char* value, size_t vlength,
|
||||
PSYC_RenderFlag flags, char oper);
|
||||
psycRenderFlag flags, char oper);
|
||||
|
||||
int PSYC_renderBody(PSYC_RenderState* render,
|
||||
int psyc_renderBody(psycRenderState* render,
|
||||
const char* method, size_t mlength,
|
||||
const char* data, size_t dlength);
|
||||
*/
|
||||
|
|
10
src/match.c
10
src/match.c
|
@ -1,6 +1,6 @@
|
|||
#include "psyc/lib.h"
|
||||
|
||||
int PSYC_inherits(char* sho, size_t slen,
|
||||
int psyc_inherits(char* sho, size_t slen,
|
||||
char* lon, size_t llen) {
|
||||
|
||||
// this allows to pass zero-terminated strings instead of providing
|
||||
|
@ -41,7 +41,7 @@ int PSYC_inherits(char* sho, size_t slen,
|
|||
return 1;
|
||||
}
|
||||
|
||||
int PSYC_matches(char* sho, size_t slen,
|
||||
int psyc_matches(char* sho, size_t slen,
|
||||
char* lon, size_t llen) {
|
||||
char *s, *l, *se, *le;
|
||||
|
||||
|
@ -67,7 +67,7 @@ int PSYC_matches(char* sho, size_t slen,
|
|||
P1(("Same length but different.\nNo match, but they could be related or have a common type.\n"))
|
||||
return -4;
|
||||
}
|
||||
P3(("# PSYC_matches short '%*s' in long '%*s' ?\n", slen, sho, llen, lon))
|
||||
P3(("# psyc_matches short '%*s' in long '%*s' ?\n", slen, sho, llen, lon))
|
||||
|
||||
se = sho+slen;
|
||||
le = lon+llen;
|
||||
|
@ -105,9 +105,9 @@ int main(int argc, char **argv) {
|
|||
printf("Usage: %s <short> <long>\n\nExample: %s _failure_delivery _failure_unsuccessful_delivery_death\n", argv[0], argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (PSYC_matches(argv[1], 0, argv[2], 0) == 0)
|
||||
if (psyc_matches(argv[1], 0, argv[2], 0) == 0)
|
||||
printf("Yes, %s matches %s!\n", argv[1], argv[2]);
|
||||
if (PSYC_inherits(argv[1], 0, argv[2], 0) == 0)
|
||||
if (psyc_inherits(argv[1], 0, argv[2], 0) == 0)
|
||||
printf("Yes, %s inherits from %s!\n", argv[2], argv[1]);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
int PSYC_version() { return 1; }
|
||||
int psyc_version() { return 1; }
|
||||
|
||||
|
|
52
src/packet.c
52
src/packet.c
|
@ -3,16 +3,16 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
inline PSYC_String PSYC_newString(const char *str, size_t strlen)
|
||||
inline psycString psyc_newString(const char *str, size_t strlen)
|
||||
{
|
||||
PSYC_String s = {strlen, str};
|
||||
psycString s = {strlen, str};
|
||||
return s;
|
||||
}
|
||||
|
||||
inline PSYC_Modifier PSYC_newModifier(char oper, PSYC_String *name, PSYC_String *value,
|
||||
PSYC_ModifierFlag flag)
|
||||
inline psycModifier psyc_newModifier(char oper, psycString *name, psycString *value,
|
||||
psycModifierFlag flag)
|
||||
{
|
||||
PSYC_Modifier m = {oper, *name, *value, flag};
|
||||
psycModifier m = {oper, *name, *value, flag};
|
||||
|
||||
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
|
||||
{
|
||||
|
@ -27,18 +27,18 @@ inline PSYC_Modifier PSYC_newModifier(char oper, PSYC_String *name, PSYC_String
|
|||
return m;
|
||||
}
|
||||
|
||||
inline PSYC_Modifier PSYC_newModifier2(char oper,
|
||||
inline psycModifier psyc_newModifier2(char oper,
|
||||
const char *name, size_t namelen,
|
||||
const char *value, size_t valuelen,
|
||||
PSYC_ModifierFlag flag)
|
||||
psycModifierFlag flag)
|
||||
{
|
||||
PSYC_String n = {namelen, name};
|
||||
PSYC_String v = {valuelen, value};
|
||||
psycString n = {namelen, name};
|
||||
psycString v = {valuelen, value};
|
||||
|
||||
return PSYC_newModifier(oper, &n, &v, flag);
|
||||
return psyc_newModifier(oper, &n, &v, flag);
|
||||
}
|
||||
|
||||
inline size_t PSYC_getModifierLength(PSYC_Modifier *m)
|
||||
inline size_t psyc_getModifierLength(psycModifier *m)
|
||||
{
|
||||
size_t length = 1 + // oper
|
||||
m->name.length + 1 + // name\t
|
||||
|
@ -50,12 +50,12 @@ inline size_t PSYC_getModifierLength(PSYC_Modifier *m)
|
|||
return length;
|
||||
}
|
||||
|
||||
inline PSYC_Packet PSYC_newPacket(PSYC_ModifierArray *routing,
|
||||
PSYC_ModifierArray *entity,
|
||||
PSYC_String *method, PSYC_String *data,
|
||||
PSYC_PacketFlag flag)
|
||||
inline psycPacket psyc_newPacket(psycModifierArray *routing,
|
||||
psycModifierArray *entity,
|
||||
psycString *method, psycString *data,
|
||||
psycPacketFlag flag)
|
||||
{
|
||||
PSYC_Packet p = {*routing, *entity, *method, *data, 0, 0, flag};
|
||||
psycPacket p = {*routing, *entity, *method, *data, 0, 0, flag};
|
||||
size_t i;
|
||||
|
||||
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs a length
|
||||
|
@ -72,11 +72,11 @@ inline PSYC_Packet PSYC_newPacket(PSYC_ModifierArray *routing,
|
|||
|
||||
// add routing header length
|
||||
for (i = 0; i < routing->lines; i++)
|
||||
p.routingLength += PSYC_getModifierLength(&routing->modifiers[i]);
|
||||
p.routingLength += psyc_getModifierLength(&routing->modifiers[i]);
|
||||
|
||||
// add entity header length
|
||||
for (i = 0; i < entity->lines; i++)
|
||||
p.contentLength += PSYC_getModifierLength(&entity->modifiers[i]);
|
||||
p.contentLength += psyc_getModifierLength(&entity->modifiers[i]);
|
||||
|
||||
// add length of method, data & delimiter
|
||||
if (method->length)
|
||||
|
@ -92,16 +92,16 @@ inline PSYC_Packet PSYC_newPacket(PSYC_ModifierArray *routing,
|
|||
return p;
|
||||
}
|
||||
|
||||
inline PSYC_Packet PSYC_newPacket2(PSYC_Modifier *routing, size_t routinglen,
|
||||
PSYC_Modifier *entity, size_t entitylen,
|
||||
inline psycPacket psyc_newPacket2(psycModifier *routing, size_t routinglen,
|
||||
psycModifier *entity, size_t entitylen,
|
||||
const char *method, size_t methodlen,
|
||||
const char *data, size_t datalen,
|
||||
PSYC_PacketFlag flag)
|
||||
psycPacketFlag flag)
|
||||
{
|
||||
PSYC_ModifierArray r = {routinglen, routing};
|
||||
PSYC_ModifierArray e = {entitylen, entity};
|
||||
PSYC_String m = {methodlen, method};
|
||||
PSYC_String d = {datalen, data};
|
||||
psycModifierArray r = {routinglen, routing};
|
||||
psycModifierArray e = {entitylen, entity};
|
||||
psycString m = {methodlen, method};
|
||||
psycString d = {datalen, data};
|
||||
|
||||
return PSYC_newPacket(&r, &e, &m, &d, flag);
|
||||
return psyc_newPacket(&r, &e, &m, &d, flag);
|
||||
}
|
||||
|
|
46
src/parser.c
46
src/parser.c
|
@ -15,35 +15,35 @@
|
|||
return ret; \
|
||||
}
|
||||
|
||||
inline void PSYC_initParseState (PSYC_ParseState* state)
|
||||
inline void psyc_initParseState (psycParseState* state)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_ParseState));
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
}
|
||||
|
||||
inline void PSYC_initParseState2 (PSYC_ParseState* state, uint8_t flags)
|
||||
inline void psyc_initParseState2 (psycParseState* state, uint8_t flags)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_ParseState));
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
state->flags = flags;
|
||||
}
|
||||
|
||||
inline void PSYC_initParseListState (PSYC_ParseListState* state)
|
||||
inline void psyc_initParseListState (psycParseListState* state)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_ParseListState));
|
||||
memset(state, 0, sizeof(psycParseListState));
|
||||
}
|
||||
|
||||
inline void PSYC_nextParseBuffer (PSYC_ParseState* state, PSYC_String newBuf)
|
||||
inline void psyc_nextParseBuffer (psycParseState* state, psycString newBuf)
|
||||
{
|
||||
state->buffer = newBuf;
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
inline void PSYC_nextParseListBuffer (PSYC_ParseListState* state, PSYC_String newBuf)
|
||||
inline void psyc_nextParseListBuffer (psycParseListState* state, psycString newBuf)
|
||||
{
|
||||
state->buffer = newBuf;
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
inline size_t PSYC_getContentLength (PSYC_ParseState* s)
|
||||
inline size_t psyc_getContentLength (psycParseState* s)
|
||||
{
|
||||
return s->contentLength;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ inline char isKwChar(uint8_t c)
|
|||
* It should contain one or more keyword characters.
|
||||
* @return PSYC_PARSE_ERROR or PSYC_PARSE_SUCCESS
|
||||
*/
|
||||
inline PSYC_ParseRC PSYC_parseName(PSYC_ParseState* state, PSYC_String* name)
|
||||
inline psycParseRC psyc_parseName(psycParseState* state, psycString* name)
|
||||
{
|
||||
name->ptr = state->buffer.ptr + state->cursor;
|
||||
name->length = 0;
|
||||
|
@ -125,7 +125,7 @@ inline PSYC_ParseRC PSYC_parseName(PSYC_ParseState* state, PSYC_String* name)
|
|||
*
|
||||
* @return PSYC_PARSE_COMPLETE or PSYC_PARSE_INCOMPLETE
|
||||
*/
|
||||
inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParseState* state, PSYC_String* value, size_t* length, size_t* parsed)
|
||||
inline psycParseRC psyc_parseBinaryValue(psycParseState* state, psycString* value, size_t* length, size_t* parsed)
|
||||
{
|
||||
size_t remaining = *length - *parsed;
|
||||
value->ptr = state->buffer.ptr + state->cursor;
|
||||
|
@ -148,12 +148,12 @@ inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParseState* state, PSYC_String* v
|
|||
* Parse simple or binary variable.
|
||||
* @return PSYC_PARSE_ERROR or PSYC_PARSE_SUCCESS
|
||||
*/
|
||||
inline PSYC_ParseRC PSYC_parseModifier(PSYC_ParseState* state, char* oper, PSYC_String* name, PSYC_String* value)
|
||||
inline psycParseRC psyc_parseModifier(psycParseState* state, char* oper, psycString* name, psycString* value)
|
||||
{
|
||||
*oper = *(state->buffer.ptr + state->cursor);
|
||||
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
|
||||
|
||||
if (PSYC_parseName(state, name) != PSYC_PARSE_SUCCESS)
|
||||
if (psyc_parseName(state, name) != PSYC_PARSE_SUCCESS)
|
||||
return PSYC_PARSE_ERROR_VAR_NAME;
|
||||
|
||||
value->length = 0;
|
||||
|
@ -185,7 +185,7 @@ inline PSYC_ParseRC PSYC_parseModifier(PSYC_ParseState* state, char* oper, PSYC_
|
|||
if (state->buffer.length <= ++(state->cursor)) // Incremented cursor inside length?
|
||||
return PSYC_PARSE_ENTITY_INCOMPLETE;
|
||||
|
||||
if (PSYC_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed)) == PSYC_PARSE_INCOMPLETE)
|
||||
if (psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed)) == PSYC_PARSE_INCOMPLETE)
|
||||
return PSYC_PARSE_ENTITY_INCOMPLETE;
|
||||
|
||||
state->cursor++;
|
||||
|
@ -212,7 +212,7 @@ inline PSYC_ParseRC PSYC_parseModifier(PSYC_ParseState* state, char* oper, PSYC_
|
|||
* Parse PSYC packets.
|
||||
* Generalized line-based parser.
|
||||
*/
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, PSYC_String* value)
|
||||
psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psycString* value)
|
||||
{
|
||||
int ret; // a return value
|
||||
size_t pos; // a cursor position
|
||||
|
@ -242,7 +242,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, P
|
|||
// so just test if the first char is a glyph.
|
||||
if (isGlyph(state->buffer.ptr[state->cursor])) // is the first char a glyph?
|
||||
{ // it is a glyph, so a variable starts here
|
||||
ret = PSYC_parseModifier(state, oper, name, value);
|
||||
ret = psyc_parseModifier(state, oper, name, value);
|
||||
return ret == PSYC_PARSE_SUCCESS ? PSYC_PARSE_ROUTING : ret;
|
||||
}
|
||||
else // not a glyph
|
||||
|
@ -291,7 +291,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, P
|
|||
case PSYC_PART_CONTENT:
|
||||
// In case of an incomplete binary variable resume parsing it.
|
||||
if (state->valueParsed < state->valueLength) {
|
||||
ret = PSYC_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed));
|
||||
ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed));
|
||||
state->contentParsed += value->length;
|
||||
return ret == PSYC_PARSE_COMPLETE ? PSYC_PARSE_ENTITY : PSYC_PARSE_ENTITY_INCOMPLETE;
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, P
|
|||
if (isGlyph(state->buffer.ptr[state->cursor]))
|
||||
{
|
||||
pos = state->cursor;
|
||||
ret = PSYC_parseModifier(state, oper, name, value);
|
||||
ret = psyc_parseModifier(state, oper, name, value);
|
||||
state->contentParsed += state->cursor - pos;
|
||||
return ret == PSYC_PARSE_SUCCESS ? PSYC_PARSE_ENTITY : ret;
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, P
|
|||
|
||||
case PSYC_PART_METHOD:
|
||||
pos = state->cursor;
|
||||
if (PSYC_parseName(state, name) == PSYC_PARSE_SUCCESS)
|
||||
if (psyc_parseName(state, name) == PSYC_PARSE_SUCCESS)
|
||||
{ // the method ends with a \n then the data follows
|
||||
if (state->buffer.ptr[state->cursor] != '\n')
|
||||
return PSYC_PARSE_ERROR_METHOD;
|
||||
|
@ -343,7 +343,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, P
|
|||
|
||||
if (state->contentLengthFound) // We know the length of the packet.
|
||||
{
|
||||
if (PSYC_parseBinaryValue(state, value, &(state->contentLength), &(state->contentParsed)) == PSYC_PARSE_INCOMPLETE)
|
||||
if (psyc_parseBinaryValue(state, value, &(state->contentLength), &(state->contentParsed)) == PSYC_PARSE_INCOMPLETE)
|
||||
return PSYC_PARSE_BODY_INCOMPLETE;
|
||||
|
||||
state->cursor++;
|
||||
|
@ -400,9 +400,9 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, P
|
|||
|
||||
/**
|
||||
* List value parser.
|
||||
* @return see PSYC_ListRC.
|
||||
* @return see psycListRC.
|
||||
*/
|
||||
PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_String *name, PSYC_String* value, PSYC_String* elem)
|
||||
psycParseListRC psyc_parseList(psycParseListState* state, psycString *name, psycString* value, psycString* elem)
|
||||
{
|
||||
if (state->cursor >= state->buffer.length)
|
||||
return PSYC_PARSE_LIST_INCOMPLETE;
|
||||
|
@ -473,7 +473,7 @@ PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_String *name, P
|
|||
// Start or resume parsing the binary data
|
||||
if (state->elemParsed < state->elemLength)
|
||||
{
|
||||
if (PSYC_parseBinaryValue((PSYC_ParseState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_PARSE_INCOMPLETE)
|
||||
if (psyc_parseBinaryValue((psycParseState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_PARSE_INCOMPLETE)
|
||||
return PSYC_PARSE_LIST_INCOMPLETE;
|
||||
|
||||
state->elemLength = 0;
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#include <stdint.h>
|
||||
|
||||
struct PSYC_Parser;
|
||||
struct psycParser;
|
||||
|
||||
/** @brief initialize a pstate struct
|
||||
*
|
||||
* @param pstate pointer to an allocated
|
||||
* PSYC_Parser struct.
|
||||
* psycParser struct.
|
||||
*/
|
||||
void PSYC_initState(struct PSYC_Parser* pstate);
|
||||
void psyc_initState(struct psycParser* pstate);
|
||||
|
||||
|
||||
/** @brief parses a packet
|
||||
*
|
||||
* This function parses rawdata
|
||||
* and uses the callbacks in PSYC_Parser
|
||||
* and uses the callbacks in psycParser
|
||||
* to communicate with the caller.
|
||||
*
|
||||
* First the header will be parsed,
|
||||
|
@ -23,7 +23,7 @@ void PSYC_initState(struct PSYC_Parser* pstate);
|
|||
* Then, routingCallback will be called
|
||||
* to find out if further parsing
|
||||
* is desired.
|
||||
* If it returns false, PSYC_parser returns.
|
||||
* If it returns false, psyc_parse returns.
|
||||
* If it returns true, parsing continues
|
||||
* to the body.
|
||||
* After the entitystate has been parsed,
|
||||
|
@ -38,15 +38,15 @@ void PSYC_initState(struct PSYC_Parser* pstate);
|
|||
* raw data that is to be processed.
|
||||
* @param length the amount of bytes to parse
|
||||
* @param pstate pointer to a preallocated
|
||||
* and initialized (PSYC_initState)
|
||||
* and initialized (psyc_initState)
|
||||
* instance of the struct state
|
||||
*
|
||||
*/
|
||||
void PSYC_parse(const uint8_t* data, unsigned int length,
|
||||
struct PSYC_Parser* pstate);
|
||||
void psyc_parse(const uint8_t* data, unsigned int length,
|
||||
struct psycParser* pstate);
|
||||
|
||||
/** @brief FlagMod */
|
||||
enum PSYC_Operator
|
||||
enum psycOperator
|
||||
{
|
||||
// modifier operators
|
||||
ASSIGN = 0x02,
|
||||
|
@ -56,7 +56,7 @@ enum PSYC_Operator
|
|||
QUERY = 0x20,
|
||||
};
|
||||
|
||||
struct PSYC_Parser
|
||||
struct psycParser
|
||||
{
|
||||
/** @brief Callback for the states
|
||||
*
|
||||
|
@ -76,10 +76,10 @@ struct PSYC_Parser
|
|||
* @param modifers modifer of the variable (see Modifer)
|
||||
* @param inEntity wether this variable is an entity
|
||||
* variable(true) or a routing variable(false) */
|
||||
void (*stateCallback)(struct PSYC_Parser* pstate,
|
||||
void (*stateCallback)(struct psycParser* pstate,
|
||||
const uint8_t *name, const unsigned int nlength,
|
||||
const uint8_t *value, const unsigned int vlength,
|
||||
enum PSYC_Operator oper, char inEntity);
|
||||
enum psycOperator oper, char inEntity);
|
||||
|
||||
/** @brief gets called after the routing-header was parsed
|
||||
*
|
||||
|
@ -88,7 +88,7 @@ struct PSYC_Parser
|
|||
* when finished,
|
||||
* if not 0, parser will stop parsing and
|
||||
* calls contentCallback */
|
||||
char (*routingCallback)(struct PSYC_Parser* pstate);
|
||||
char (*routingCallback)(struct psycParser* pstate);
|
||||
|
||||
/** @brief Body callback, gets called when the body was parsed
|
||||
*
|
||||
|
@ -102,7 +102,7 @@ struct PSYC_Parser
|
|||
* containing the data section
|
||||
* @param content not null terminated c-string
|
||||
* @param clength length of the content string */
|
||||
void (*bodyCallback)(struct PSYC_Parser* pstate,
|
||||
void (*bodyCallback)(struct psycParser* pstate,
|
||||
const uint8_t* method, unsigned int mlength,
|
||||
const uint8_t* data, unsigned int dlength,
|
||||
const uint8_t* content, unsigned int clength);
|
||||
|
@ -123,7 +123,7 @@ struct PSYC_Parser
|
|||
*
|
||||
* Any previous state or body callbacks become
|
||||
* invalid and have to be purged.*/
|
||||
void (*errorCallback)(struct PSYC_Parser* pstate,
|
||||
void (*errorCallback)(struct psycParser* pstate,
|
||||
const uint8_t *method, unsigned int mlength);
|
||||
|
||||
/** @brief error state callback
|
||||
|
@ -132,10 +132,10 @@ struct PSYC_Parser
|
|||
* The callback will be called once for each
|
||||
* state variable in the error report packet
|
||||
*/
|
||||
void (*errorStateCallback)(struct PSYC_Parser* pstate,
|
||||
void (*errorStateCallback)(struct psycParser* pstate,
|
||||
const uint8_t *name, const unsigned int nlength,
|
||||
const uint8_t *value, const unsigned int vlength,
|
||||
enum PSYC_Operator oper);
|
||||
enum psycOperator oper);
|
||||
|
||||
|
||||
/*******************************************
|
||||
|
|
20
src/render.c
20
src/render.c
|
@ -2,7 +2,7 @@
|
|||
#include "psyc/render.h"
|
||||
#include "psyc/syntax.h"
|
||||
|
||||
inline size_t PSYC_renderModifier(PSYC_Modifier *m, char *buffer)
|
||||
inline size_t psyc_renderModifier(psycModifier *m, char *buffer)
|
||||
{
|
||||
size_t cur = 0;
|
||||
|
||||
|
@ -24,7 +24,7 @@ inline size_t PSYC_renderModifier(PSYC_Modifier *m, char *buffer)
|
|||
return cur;
|
||||
}
|
||||
|
||||
PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen)
|
||||
psycRenderRC psyc_render(psycPacket *packet, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i, cur = 0;
|
||||
|
||||
|
@ -33,7 +33,7 @@ PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen)
|
|||
|
||||
// render routing modifiers
|
||||
for (i = 0; i < packet->routing.lines; i++)
|
||||
cur += PSYC_renderModifier(&packet->routing.modifiers[i], buffer + cur);
|
||||
cur += psyc_renderModifier(&packet->routing.modifiers[i], buffer + cur);
|
||||
|
||||
// add length if needed
|
||||
if (packet->flag == PSYC_PACKET_NEED_LENGTH) {
|
||||
|
@ -45,7 +45,7 @@ PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen)
|
|||
|
||||
// render entity modifiers
|
||||
for (i = 0; i < packet->entity.lines; i++)
|
||||
cur += PSYC_renderModifier(&packet->entity.modifiers[i], buffer + cur);
|
||||
cur += psyc_renderModifier(&packet->entity.modifiers[i], buffer + cur);
|
||||
|
||||
if (packet->method.length) // add method\n
|
||||
{
|
||||
|
@ -71,15 +71,15 @@ PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen)
|
|||
}
|
||||
|
||||
/*
|
||||
inline void PSYC_initRenderState (PSYC_RenderState *state)
|
||||
inline void psyc_initRenderState (psycRenderState *state)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_RenderState));
|
||||
memset(state, 0, sizeof(psycRenderState));
|
||||
}
|
||||
|
||||
PSYC_RenderRC PSYC_renderModifier(PSYC_RenderState *state,
|
||||
psycRenderRC psyc_renderModifier(psycRenderState *state,
|
||||
const char *name, size_t nlength,
|
||||
const char *value, size_t vlength,
|
||||
const PSYC_RenderFlag flags, char oper)
|
||||
const psycRenderFlag flags, char oper)
|
||||
{
|
||||
size_t startc = state->cursor;
|
||||
|
||||
|
@ -99,7 +99,7 @@ PSYC_RenderRC PSYC_renderModifier(PSYC_RenderState *state,
|
|||
}
|
||||
|
||||
//if (flags == PSYC_RENDER_ROUTING)
|
||||
if (PSYC_isRoutingVar(name, nlength))
|
||||
if (psyc_isRoutingVar(name, nlength))
|
||||
{ // no more routing headers allowed after content started
|
||||
if (state->part != PSYC_PART_ROUTING)
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ PSYC_RenderRC PSYC_renderModifier(PSYC_RenderState *state,
|
|||
return PSYC_RENDER_SUCCESS;
|
||||
}
|
||||
|
||||
PSYC_RenderRC PSYC_renderBody(PSYC_RenderState *state,
|
||||
psycRenderRC psyc_renderBody(psycRenderState *state,
|
||||
const char *method, size_t mlength,
|
||||
const char *data, size_t dlength)
|
||||
{
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
/* PSYC_text() */
|
||||
/* psyc_text() */
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
/// Routing variables in alphabetical order.
|
||||
const PSYC_String PSYC_routingVars[] =
|
||||
const psycString PSYC_routingVars[] =
|
||||
{
|
||||
PSYC_C2STR("_amount_fragments"),
|
||||
PSYC_C2STR("_context"),
|
||||
|
@ -29,7 +29,7 @@ const size_t PSYC_routingVarsNum = sizeof(PSYC_routingVars) / sizeof(*PSYC_routi
|
|||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PSYC_Bool PSYC_isRoutingVar(const char *name, size_t len)
|
||||
psycBool psyc_isRoutingVar(const char *name, size_t len)
|
||||
{
|
||||
size_t cursor = 1;
|
||||
int8_t matching[PSYC_routingVarsNum]; // indexes of matching vars
|
||||
|
@ -68,7 +68,7 @@ PSYC_Bool PSYC_isRoutingVar(const char *name, size_t len)
|
|||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PSYC_Type PSYC_getVarType(char *name, size_t len)
|
||||
psycType psyc_getVarType(char *name, size_t len)
|
||||
{
|
||||
return PSYC_TYPE_UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue