mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
fixes for inline functions, c99 mode, formatting
This commit is contained in:
parent
09e8943afe
commit
259b51966c
14 changed files with 368 additions and 295 deletions
117
include/psyc.h
117
include/psyc.h
|
@ -24,6 +24,9 @@
|
|||
|
||||
#define PSYC_EPOCH 1440444041 // 2015-08-24 21:20:41 CET (Monday)
|
||||
|
||||
#define PSYC_C2STR(string) {sizeof(string)-1, string}
|
||||
#define PSYC_C2ARG(string) string, sizeof(string)-1
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_FALSE = 0,
|
||||
|
@ -79,28 +82,6 @@ typedef enum
|
|||
PSYC_LIST_BINARY = 2,
|
||||
} psycListType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_MODIFIER_CHECK_LENGTH = 0,
|
||||
PSYC_MODIFIER_NEED_LENGTH = 1,
|
||||
PSYC_MODIFIER_NO_LENGTH = 2,
|
||||
PSYC_MODIFIER_ROUTING = 3,
|
||||
} psycModifierFlag;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_LIST_CHECK_LENGTH = 0,
|
||||
PSYC_LIST_NEED_LENGTH = 1,
|
||||
PSYC_LIST_NO_LENGTH = 2,
|
||||
} psycListFlag;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_PACKET_CHECK_LENGTH = 0,
|
||||
PSYC_PACKET_NEED_LENGTH = 1,
|
||||
PSYC_PACKET_NO_LENGTH = 2,
|
||||
} psycPacketFlag;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t length;
|
||||
|
@ -121,92 +102,18 @@ typedef struct
|
|||
*
|
||||
* @return An instance of the psycString struct.
|
||||
*/
|
||||
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
|
||||
|
||||
/* intermediate struct for a PSYC variable modification */
|
||||
typedef struct
|
||||
static inline
|
||||
psycString psyc_newString (const char *str, size_t strlen)
|
||||
{
|
||||
char oper; // not call it 'operator' as C++ may not like that..
|
||||
psycString name;
|
||||
psycString value;
|
||||
psycModifierFlag flag;
|
||||
} psycModifier;
|
||||
psycString s = {strlen, str};
|
||||
return s;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
static inline
|
||||
unsigned int psyc_version ()
|
||||
{
|
||||
size_t lines;
|
||||
psycModifier *modifiers;
|
||||
} psycHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t num_elems;
|
||||
psycString *elems;
|
||||
size_t length;
|
||||
psycListFlag flag;
|
||||
} psycList;
|
||||
|
||||
/** intermediate struct for a PSYC packet */
|
||||
typedef struct
|
||||
{
|
||||
psycHeader routing; ///< Routing header.
|
||||
psycHeader entity; ///< Entity 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.
|
||||
psycPacketFlag flag;
|
||||
} psycPacket;
|
||||
|
||||
inline int psyc_version();
|
||||
|
||||
/** Check if a modifier needs length */
|
||||
inline psycModifierFlag psyc_checkModifierLength(psycModifier *m);
|
||||
|
||||
/** Get the total length of a modifier. */
|
||||
inline size_t psyc_getModifierLength(psycModifier *m);
|
||||
|
||||
/** Create new modifier */
|
||||
inline psycModifier psyc_newModifier(char oper, psycString *name, psycString *value,
|
||||
psycModifierFlag flag);
|
||||
|
||||
/** Create new modifier */
|
||||
inline psycModifier psyc_newModifier2(char oper,
|
||||
const char *name, size_t namelen,
|
||||
const char *value, size_t valuelen,
|
||||
psycModifierFlag flag);
|
||||
|
||||
/** Check if a list needs length */
|
||||
inline psycListFlag psyc_checkListLength(psycList *list);
|
||||
|
||||
/** Get the total length of a list. */
|
||||
inline psycListFlag psyc_getListLength(psycList *list);
|
||||
|
||||
/** Check if a packet needs length */
|
||||
inline psycPacketFlag psyc_checkPacketLength(psycPacket *p);
|
||||
|
||||
/** Calculate and set the length of packet parts and total packet length */
|
||||
inline size_t psyc_setPacketLength(psycPacket *p);
|
||||
|
||||
/** Create new list */
|
||||
inline psycList psyc_newList(psycString *elems, size_t num_elems, psycListFlag flag);
|
||||
|
||||
/** Create new packet */
|
||||
inline psycPacket psyc_newPacket(psycHeader *routing,
|
||||
psycHeader *entity,
|
||||
psycString *method, psycString *data,
|
||||
psycPacketFlag flag);
|
||||
|
||||
/** Create new packet */
|
||||
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,
|
||||
psycPacketFlag flag);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Routing vars in alphabetical order.
|
||||
extern const psycString PSYC_routingVars[];
|
||||
|
|
138
include/psyc/packet.h
Normal file
138
include/psyc/packet.h
Normal file
|
@ -0,0 +1,138 @@
|
|||
#ifndef PSYC_PACKET_H
|
||||
# define PSYC_PACKET_H
|
||||
|
||||
#include <psyc.h>
|
||||
#include <psyc/syntax.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_MODIFIER_CHECK_LENGTH = 0,
|
||||
PSYC_MODIFIER_NEED_LENGTH = 1,
|
||||
PSYC_MODIFIER_NO_LENGTH = 2,
|
||||
PSYC_MODIFIER_ROUTING = 3,
|
||||
} psycModifierFlag;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_LIST_CHECK_LENGTH = 0,
|
||||
PSYC_LIST_NEED_LENGTH = 1,
|
||||
PSYC_LIST_NO_LENGTH = 2,
|
||||
} psycListFlag;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_PACKET_CHECK_LENGTH = 0,
|
||||
PSYC_PACKET_NEED_LENGTH = 1,
|
||||
PSYC_PACKET_NO_LENGTH = 2,
|
||||
} psycPacketFlag;
|
||||
|
||||
/** intermediate struct for a PSYC variable modification */
|
||||
typedef struct
|
||||
{
|
||||
char oper;
|
||||
psycString name;
|
||||
psycString value;
|
||||
psycModifierFlag flag;
|
||||
} psycModifier;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t lines;
|
||||
psycModifier *modifiers;
|
||||
} psycHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t num_elems;
|
||||
psycString *elems;
|
||||
size_t length;
|
||||
psycListFlag flag;
|
||||
} psycList;
|
||||
|
||||
/** intermediate struct for a PSYC packet */
|
||||
typedef struct
|
||||
{
|
||||
psycHeader routing; ///< Routing header.
|
||||
psycHeader entity; ///< Entity 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.
|
||||
psycPacketFlag flag;
|
||||
} psycPacket;
|
||||
|
||||
/** Check if a modifier needs length */
|
||||
static inline
|
||||
psycModifierFlag psyc_checkModifierLength (psycModifier *m)
|
||||
{
|
||||
psycModifierFlag flag;
|
||||
|
||||
if (m->value.length > PSYC_MODIFIER_SIZE_THRESHOLD)
|
||||
flag = PSYC_MODIFIER_NEED_LENGTH;
|
||||
else if (memchr(m->value.ptr, (int)'\n', m->value.length))
|
||||
flag = PSYC_MODIFIER_NEED_LENGTH;
|
||||
else
|
||||
flag = PSYC_MODIFIER_NO_LENGTH;
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
/** Create new modifier */
|
||||
static inline
|
||||
psycModifier psyc_newModifier (char oper, psycString *name, psycString *value,
|
||||
psycModifierFlag flag)
|
||||
{
|
||||
psycModifier m = {oper, *name, *value, flag};
|
||||
|
||||
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
|
||||
m.flag = psyc_checkModifierLength(&m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/** Create new modifier */
|
||||
static inline
|
||||
psycModifier psyc_newModifier2 (char oper,
|
||||
const char *name, size_t namelen,
|
||||
const char *value, size_t valuelen,
|
||||
psycModifierFlag flag)
|
||||
{
|
||||
psycString n = {namelen, name};
|
||||
psycString v = {valuelen, value};
|
||||
|
||||
return psyc_newModifier(oper, &n, &v, flag);
|
||||
}
|
||||
|
||||
/** Get the total length of a modifier. */
|
||||
size_t psyc_getModifierLength (psycModifier *m);
|
||||
|
||||
/** Check if a list needs length */
|
||||
psycListFlag psyc_checkListLength (psycList *list);
|
||||
|
||||
/** Get the total length of a list. */
|
||||
psycListFlag psyc_getListLength (psycList *list);
|
||||
|
||||
/** Check if a packet needs length */
|
||||
psycPacketFlag psyc_checkPacketLength (psycPacket *p);
|
||||
|
||||
/** Calculate and set the length of packet parts and total packet length */
|
||||
size_t psyc_setPacketLength (psycPacket *p);
|
||||
|
||||
/** Create new list */
|
||||
psycList psyc_newList (psycString *elems, size_t num_elems, psycListFlag flag);
|
||||
|
||||
/** Create new packet */
|
||||
psycPacket psyc_newPacket (psycHeader *routing,
|
||||
psycHeader *entity,
|
||||
psycString *method, psycString *data,
|
||||
psycPacketFlag flag);
|
||||
|
||||
/** Create new packet */
|
||||
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,
|
||||
psycPacketFlag flag);
|
||||
|
||||
#endif // PSYC_PACKET_H
|
|
@ -131,7 +131,7 @@ typedef struct
|
|||
* @param state Pointer to the state struct that should be initiated.
|
||||
*/
|
||||
static inline
|
||||
void psyc_initParseState ( psycParseState* state )
|
||||
void psyc_initParseState (psycParseState* state)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ void psyc_initParseState ( psycParseState* state )
|
|||
* @param flags Flags to be set for the parser, see psycParseFlag.
|
||||
*/
|
||||
static inline
|
||||
void psyc_initParseState2 ( psycParseState* state, uint8_t flags )
|
||||
void psyc_initParseState2 (psycParseState* state, uint8_t flags)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
state->flags = flags;
|
||||
|
@ -160,7 +160,7 @@ void psyc_initParseState2 ( psycParseState* state, uint8_t flags )
|
|||
* @see psycString
|
||||
*/
|
||||
static inline
|
||||
void psyc_setParseBuffer ( psycParseState* state, psycString buffer )
|
||||
void psyc_setParseBuffer (psycParseState* state, psycString buffer)
|
||||
{
|
||||
state->buffer = buffer;
|
||||
state->cursor = 0;
|
||||
|
@ -181,7 +181,7 @@ void psyc_setParseBuffer ( psycParseState* state, psycString buffer )
|
|||
* @see psycString
|
||||
*/
|
||||
static inline
|
||||
void psyc_setParseBuffer2 ( psycParseState* state, char *buffer, size_t length )
|
||||
void psyc_setParseBuffer2 (psycParseState* state, char *buffer, size_t length)
|
||||
{
|
||||
psyc_setParseBuffer(state, psyc_newString(buffer, length));
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ void psyc_setParseBuffer2 ( psycParseState* state, char *buffer, size_t length )
|
|||
* @param state Pointer to the list state struct that should be initiated.
|
||||
*/
|
||||
static inline
|
||||
void psyc_initParseListState ( psycParseListState* state )
|
||||
void psyc_initParseListState (psycParseListState* state)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseListState));
|
||||
}
|
||||
|
@ -201,20 +201,20 @@ void psyc_initParseListState ( psycParseListState* state )
|
|||
* Sets a new buffer in the list parser state struct with data to be parsed.
|
||||
*/
|
||||
static inline
|
||||
void psyc_setParseListBuffer ( psycParseListState* state, psycString buffer )
|
||||
void psyc_setParseListBuffer (psycParseListState* state, psycString buffer)
|
||||
{
|
||||
state->buffer = buffer;
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
void psyc_setParseListBuffer2 ( psycParseListState* state, char *buffer, size_t length )
|
||||
void psyc_setParseListBuffer2 (psycParseListState* state, char *buffer, size_t length)
|
||||
{
|
||||
psyc_setParseListBuffer(state, psyc_newString(buffer, length));
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getContentLength ( psycParseState* s )
|
||||
size_t psyc_getContentLength (psycParseState* s)
|
||||
{
|
||||
return s->contentLength;
|
||||
}
|
||||
|
@ -232,12 +232,12 @@ size_t psyc_getContentLength ( psycParseState* s )
|
|||
* @param value A pointer to a psycString. It will point to the
|
||||
* value/body the variable/method and its length will be set accordingly
|
||||
*/
|
||||
psycParseRC psyc_parse ( psycParseState* state, char* oper, psycString* name, psycString* value);
|
||||
psycParseRC psyc_parse (psycParseState* state, char* oper, psycString* name, psycString* value);
|
||||
|
||||
/**
|
||||
* List value parser.
|
||||
*/
|
||||
psycParseListRC psyc_parseList ( psycParseListState* state, psycString *name, psycString* value, psycString* elem);
|
||||
psycParseListRC psyc_parseList (psycParseListState* state, psycString *name, psycString* value, psycString* elem);
|
||||
|
||||
#endif // PSYC_PARSER_H
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef PSYC_RENDER_H
|
||||
# define PSYC_RENDER_H
|
||||
|
||||
#include <psyc/packet.h>
|
||||
|
||||
/**
|
||||
* @file psyc/render.h
|
||||
* @brief Interface for PSYC packet rendering.
|
||||
|
@ -29,12 +31,12 @@ typedef enum
|
|||
/**
|
||||
* Render a PSYC packet into a buffer.
|
||||
*/
|
||||
psycRenderRC psyc_render(psycPacket *packet, char *buffer, size_t buflen);
|
||||
psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Render a PSYC list into a buffer.
|
||||
*/
|
||||
psycRenderRC psyc_renderList(psycList *list, char *buffer, size_t buflen);
|
||||
psycRenderRC psyc_renderList (psycList *list, char *buffer, size_t buflen);
|
||||
|
||||
#endif // PSYC_RENDER_H
|
||||
|
||||
|
|
|
@ -93,4 +93,4 @@ void psyc_setTextBuffer2 (psycTextState* state,
|
|||
* See also http://about.psyc.eu/psyctext
|
||||
*/
|
||||
|
||||
psycTextRC psyc_text(psycTextState *state, psycTextCB getValue);
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue