mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
renaming & moving stuff around; psyc logo
This commit is contained in:
parent
13ffb3a120
commit
0841b3676f
29 changed files with 153 additions and 73 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,7 +1,9 @@
|
|||
doc/
|
||||
doc/html
|
||||
doc/latex
|
||||
doc/man
|
||||
src/match
|
||||
tests/testMatch
|
||||
tests/testParser
|
||||
test/testMatch
|
||||
test/testParser
|
||||
|
||||
.config
|
||||
~$*
|
||||
|
|
4
Doxyfile
4
Doxyfile
|
@ -44,7 +44,7 @@ PROJECT_BRIEF = "PSYC core library"
|
|||
# exceed 55 pixels and the maximum width should not exceed 200 pixels.
|
||||
# Doxygen will copy the logo to the output directory.
|
||||
|
||||
PROJECT_LOGO =
|
||||
PROJECT_LOGO = doc/psyc.svg
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||
# base path where the generated documentation will be put.
|
||||
|
@ -875,7 +875,7 @@ HTML_FOOTER =
|
|||
# the style sheet file to the HTML output directory, so don't put your own
|
||||
# stylesheet in the HTML output directory as well, or it will be erased!
|
||||
|
||||
HTML_STYLESHEET =
|
||||
HTML_STYLESHEET = doc/psyc.css
|
||||
|
||||
# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
|
||||
# Doxygen will adjust the colors in the stylesheet and background images
|
||||
|
|
12
Makefile
12
Makefile
|
@ -1,8 +1,8 @@
|
|||
.PHONY: doc
|
||||
.PHONY: tests
|
||||
.PHONY: test
|
||||
|
||||
default:
|
||||
@/bin/echo -e "Usage:\n\tmake diet - compile with diet libc\n\tmake lib - compile with normal gnu libc\n\tmake tests\n\tmake doc"
|
||||
@/bin/echo -e "Usage:\n\tmake diet - compile with diet libc\n\tmake lib - compile with normal gnu libc\n\tmake test\n\tmake doc"
|
||||
|
||||
lib:
|
||||
make -C src lib
|
||||
|
@ -10,13 +10,13 @@ lib:
|
|||
diet:
|
||||
make -C src diet
|
||||
|
||||
tests:
|
||||
make -C tests
|
||||
test:
|
||||
make -C test
|
||||
|
||||
doc:
|
||||
doxygen
|
||||
|
||||
clean:
|
||||
make -C src clean
|
||||
make -C tests clean
|
||||
rm -rf doc
|
||||
make -C test clean
|
||||
rm -rf doc/html doc/latex doc/man
|
||||
|
|
3
doc/psyc.css
Normal file
3
doc/psyc.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
#projectlogo img {
|
||||
height: 50px;
|
||||
}
|
71
doc/psyc.svg
Normal file
71
doc/psyc.svg
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
id="svg4025"
|
||||
version="1.1"
|
||||
width="715.59717"
|
||||
height="145.17674"
|
||||
xml:space="preserve"><g
|
||||
id="g4035"
|
||||
transform="matrix(1.25,0,0,-1.25,-0.93316256,156.86281)"><g
|
||||
id="g4037"
|
||||
transform="scale(0.1,0.1)"><path
|
||||
d="m 223.621,1244.61 5292.459,0 c 113.7,0 205.87,-92.17 205.87,-205.86 l 0,-729.109 c 0,-113.696 -92.17,-205.86 -205.87,-205.86 l -5292.459,0 c -113.695,0 -205.8632,92.164 -205.8632,205.86 l 0,729.109 c 0,113.69 92.1682,205.86 205.8632,205.86"
|
||||
style="fill:#e45e3b;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4039" /><path
|
||||
d="m 223.621,1244.61 5292.459,0 c 113.7,0 205.87,-92.17 205.87,-205.86 l 0,-729.109 c 0,-113.696 -92.17,-205.86 -205.87,-205.86 l -5292.459,0 c -113.695,0 -205.8632,92.164 -205.8632,205.86 l 0,729.109 c 0,113.69 92.1682,205.86 205.8632,205.86 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:20.58499908;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4041" /><path
|
||||
d="m 2533.52,256.535 -1075.5,0 84.9,233.25 861.36,0 46.52,127.824 303.49,0 C 2733.09,465.156 2650.01,334.555 2533.52,256.535"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4043" /><path
|
||||
d="m 2533.52,256.535 -1075.5,0 84.9,233.25 861.36,0 46.52,127.824 303.49,0 C 2733.09,465.156 2650.01,334.555 2533.52,256.535 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4045" /><path
|
||||
d="m 4050.01,727.609 -347.76,0.235 -75.14,0 -474.03,-0.235 c -116.49,78.028 -199.58,208.625 -220.77,361.081 l 303.48,0 46.53,-127.827 345.14,0.235 74.43,0 218.89,-0.235 46.52,127.827 303.49,0 C 4249.59,936.234 4166.51,805.637 4050.01,727.609"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4047" /><path
|
||||
d="m 4050.01,727.609 -347.76,0.235 -75.14,0 -474.03,-0.235 c -116.49,78.028 -199.58,208.625 -220.77,361.081 l 303.48,0 46.53,-127.827 345.14,0.235 74.43,0 218.89,-0.235 46.52,127.827 303.49,0 C 4249.59,936.234 4166.51,805.637 4050.01,727.609 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4049" /><path
|
||||
d="m 1229.7,1089.38 -1075.493,0 84.898,-233.247 861.355,0 46.53,-127.828 303.48,0 C 1429.28,880.758 1346.2,1011.36 1229.7,1089.38"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4051" /><path
|
||||
d="m 1229.7,1089.38 -1075.493,0 84.898,-233.247 861.355,0 46.53,-127.828 303.48,0 C 1429.28,880.758 1346.2,1011.36 1229.7,1089.38 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4053" /><path
|
||||
d="m 4492.29,1089.38 1075.49,0 -84.9,-233.251 -861.36,0 -46.52,-127.828 -303.48,0 c 21.19,152.453 104.27,283.059 220.77,361.079"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4055" /><path
|
||||
d="m 4492.29,1089.38 1075.49,0 -84.9,-233.251 -861.36,0 -46.52,-127.828 -303.48,0 c 21.19,152.453 104.27,283.059 220.77,361.079 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4057" /><path
|
||||
d="m 4483.71,256.535 1075.49,0 -84.89,233.25 -861.36,0 -46.53,127.824 -303.48,0 c 21.19,-152.453 104.27,-283.054 220.77,-361.074"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4059" /><path
|
||||
d="m 4483.71,256.535 1075.49,0 -84.89,233.25 -861.36,0 -46.53,127.824 -303.48,0 c 21.19,-152.453 104.27,-283.054 220.77,-361.074 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4061" /><path
|
||||
d="m 1764.57,1089.38 1075.49,0 -84.89,-233.247 -861.36,0 -46.53,-127.828 -303.48,0 c 21.19,152.453 104.28,283.055 220.77,361.075"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4063" /><path
|
||||
d="m 1764.57,1089.38 1075.49,0 -84.89,-233.247 -861.36,0 -46.53,-127.828 -303.48,0 c 21.19,152.453 104.28,283.055 220.77,361.075 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4065" /><path
|
||||
d="m 3531.01,615.176 151.19,0 c 56.85,0 102.93,-46.082 102.93,-102.93 l 0,-151.191 c 0,-56.848 -46.08,-102.93 -102.93,-102.93 l -151.19,0 c -56.85,0 -102.94,46.082 -102.94,102.93 l 0,151.191 c 0,56.848 46.09,102.93 102.94,102.93"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4067" /><path
|
||||
d="m 3531.01,615.176 151.19,0 c 56.85,0 102.93,-46.082 102.93,-102.93 l 0,-151.191 c 0,-56.848 -46.08,-102.93 -102.93,-102.93 l -151.19,0 c -56.85,0 -102.94,46.082 -102.94,102.93 l 0,151.191 c 0,56.848 46.09,102.93 102.94,102.93 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4069" /><path
|
||||
d="m 345.469,617.238 151.191,0 c 56.848,0 102.934,-46.082 102.934,-102.929 l 0,-151.192 c 0,-56.847 -46.086,-102.933 -102.934,-102.933 l -151.191,0 c -56.848,0 -102.934,46.086 -102.934,102.933 l 0,151.192 c 0,56.847 46.086,102.929 102.934,102.929"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
id="path4071" /><path
|
||||
d="m 345.469,617.238 151.191,0 c 56.848,0 102.934,-46.082 102.934,-102.929 l 0,-151.192 c 0,-56.847 -46.086,-102.933 -102.934,-102.933 l -151.191,0 c -56.848,0 -102.934,46.086 -102.934,102.933 l 0,151.192 c 0,56.847 46.086,102.929 102.934,102.929 z"
|
||||
style="fill:none;stroke:#231f20;stroke-width:34.30899811;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.8636899;stroke-opacity:1;stroke-dasharray:none"
|
||||
id="path4073" /></g></g></svg>
|
After Width: | Height: | Size: 6.6 KiB |
|
@ -30,6 +30,20 @@ typedef enum
|
|||
PSYC_TRUE = 1,
|
||||
} PSYC_Bool;
|
||||
|
||||
/**
|
||||
* PSYC packet parts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PSYC_PART_RESET = -1,
|
||||
PSYC_PART_HEADER = 0,
|
||||
PSYC_PART_LENGTH,
|
||||
PSYC_PART_CONTENT,
|
||||
PSYC_PART_METHOD,
|
||||
PSYC_PART_DATA,
|
||||
PSYC_PART_END,
|
||||
} PSYC_Part;
|
||||
|
||||
/**
|
||||
* Different types that a variable can have.
|
||||
*
|
||||
|
@ -54,6 +68,16 @@ typedef enum
|
|||
PSYC_TYPE_TIME,
|
||||
} PSYC_Type;
|
||||
|
||||
/**
|
||||
* List types.
|
||||
* Possible types are text and binary.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PSYC_LIST_TEXT = 1,
|
||||
PSYC_LIST_BINARY = 2,
|
||||
} PSYC_ListType;
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
|
@ -64,7 +88,6 @@ PSYC_Type PSYC_getVarType(char* name, size_t len);
|
|||
*/
|
||||
PSYC_Bool PSYC_isRoutingVar(char* name, size_t len);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if long keyword string inherits from short keyword string.
|
||||
*/
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
typedef enum
|
||||
{
|
||||
PSYC_HEADER_ONLY = 1,
|
||||
} PSYC_ParserFlag;
|
||||
} PSYC_ParseFlag;
|
||||
|
||||
/**
|
||||
* The return value definitions for the packet parsing function.
|
||||
|
@ -78,36 +78,12 @@ typedef enum
|
|||
PSYC_LIST_END = 2,
|
||||
/// Binary list is incomplete.
|
||||
PSYC_LIST_INCOMPLETE = 3,
|
||||
} PSYC_ListRC;
|
||||
|
||||
/**
|
||||
* PSYC packet parts.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PSYC_PART_RESET = -1,
|
||||
PSYC_PART_HEADER = 0,
|
||||
PSYC_PART_LENGTH,
|
||||
PSYC_PART_CONTENT,
|
||||
PSYC_PART_METHOD,
|
||||
PSYC_PART_DATA,
|
||||
PSYC_PART_END,
|
||||
} PSYC_Part;
|
||||
|
||||
/**
|
||||
* List types.
|
||||
* Possible types are text and binary.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PSYC_LIST_TEXT = 1,
|
||||
PSYC_LIST_BINARY = 2,
|
||||
} PSYC_ListType;
|
||||
} PSYC_ParseListRC;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t length;
|
||||
const uint8_t * ptr; // just an unsigned char for opaque data
|
||||
const uint8_t* ptr; // just an unsigned char for opaque data
|
||||
} PSYC_Array; // to be renamed or solved differently..
|
||||
|
||||
/**
|
||||
|
@ -117,8 +93,8 @@ typedef struct
|
|||
{
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t startc; ///< position where the parsing would be resumed
|
||||
PSYC_Array buffer;
|
||||
uint8_t flags; ///< flags for the parser, see PSYC_ParserFlag
|
||||
PSYC_Array 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
|
||||
|
||||
size_t contentParsed; ///< number of bytes parsed from the content so far
|
||||
|
@ -126,7 +102,7 @@ typedef struct
|
|||
PSYC_Bool 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_ParserState;
|
||||
} PSYC_ParseState;
|
||||
|
||||
/**
|
||||
* Struct for keeping list parser state.
|
||||
|
@ -140,7 +116,7 @@ typedef struct
|
|||
|
||||
size_t elemParsed; ///< number of bytes parsed from the elem so far
|
||||
size_t elemLength; ///< expected length of the elem
|
||||
} PSYC_ListState;
|
||||
} PSYC_ParseListState;
|
||||
|
||||
#ifndef PSYC_COMPILE_LIBRARY
|
||||
/**
|
||||
|
@ -161,11 +137,11 @@ inline PSYC_Array PSYC_createArray (uint8_t* const memory, size_t length)
|
|||
* 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_ParserFlag.
|
||||
* @param flags Flags to be set for the parser, see PSYC_ParseFlag.
|
||||
*/
|
||||
inline void PSYC_initState2 (PSYC_ParserState* state, uint8_t flags )
|
||||
inline void PSYC_initState2 (PSYC_ParseState* state, uint8_t flags)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_ParserState));
|
||||
memset(state, 0, sizeof(PSYC_ParseState));
|
||||
state->flags = flags;
|
||||
}
|
||||
|
||||
|
@ -174,9 +150,9 @@ inline void PSYC_initState2 (PSYC_ParserState* state, uint8_t flags )
|
|||
*
|
||||
* @param state Pointer to the state struct that should be initiated.
|
||||
*/
|
||||
inline void PSYC_initState (PSYC_ParserState* state)
|
||||
inline void PSYC_initState (PSYC_ParseState* state)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_ParserState));
|
||||
memset(state, 0, sizeof(PSYC_ParseState));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,24 +160,24 @@ inline void PSYC_initState (PSYC_ParserState* state)
|
|||
*
|
||||
* @param state Pointer to the list state struct that should be initiated.
|
||||
*/
|
||||
inline void PSYC_initListState (PSYC_ListState* state)
|
||||
inline void PSYC_initListState (PSYC_ParseListState* state)
|
||||
{
|
||||
memset(state, 0, sizeof(PSYC_ListState));
|
||||
memset(state, 0, sizeof(PSYC_ParseListState));
|
||||
}
|
||||
|
||||
inline void PSYC_nextBuffer (PSYC_ParserState* state, PSYC_Array newBuf)
|
||||
inline void PSYC_nextBuffer (PSYC_ParseState* state, PSYC_Array newBuf)
|
||||
{
|
||||
state->buffer = newBuf;
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
inline void PSYC_nextListBuffer (PSYC_ListState* state, PSYC_Array newBuf)
|
||||
inline void PSYC_nextListBuffer (PSYC_ParseListState* state, PSYC_Array newBuf)
|
||||
{
|
||||
state->buffer = newBuf;
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
inline size_t PSYC_getContentLength (PSYC_ParserState* s)
|
||||
inline size_t PSYC_getContentLength (PSYC_ParseState* s)
|
||||
{
|
||||
return s->contentLength;
|
||||
}
|
||||
|
@ -213,7 +189,7 @@ inline size_t PSYC_getContentLength (PSYC_ParserState* s)
|
|||
*
|
||||
* Generalized line-based packet parser.
|
||||
*
|
||||
* @param state An initialized PSYC_ParserState
|
||||
* @param state An initialized PSYC_ParseState
|
||||
* @param modifier A pointer to a character. In case of a variable, it will
|
||||
* be set to the modifier of that variable
|
||||
* @param name A pointer to a PSYC_Array. It will point to the name of
|
||||
|
@ -221,12 +197,12 @@ inline size_t PSYC_getContentLength (PSYC_ParserState* s)
|
|||
* @param value A pointer to a PSYC_Array. It will point to the
|
||||
* value/body the variable/method and its length will be set accordingly
|
||||
*/
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value);
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value);
|
||||
|
||||
/**
|
||||
* List value parser.
|
||||
*/
|
||||
PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem);
|
||||
PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem);
|
||||
|
||||
#endif // PSYC_PARSER_H
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* Struct for keeping render state.
|
||||
*/
|
||||
typedef enum {
|
||||
PSYC_FINE = 0,
|
||||
PSYC_NEED_LENGTH = 1
|
||||
|
@ -5,22 +8,23 @@ typedef enum {
|
|||
|
||||
typedef struct {
|
||||
PSYC_RenderFlag flag; ///< flags for the renderer
|
||||
PSYC_Part part; ///< part of the packet being rendered
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t start; ///< position where the rendered packet starts
|
||||
size_t contentLength; ///< length of the content part
|
||||
size_t length; ///< how big is the buffer we allocated
|
||||
uint8_t buffer[]; ///< OMG a C99 feature! variable size buffer!
|
||||
} PSYC_RenderState;
|
||||
|
||||
int PSYC_renderHeader(PSYC_RenderState render,
|
||||
int PSYC_renderHeader(PSYC_RenderState* render,
|
||||
const uint8_t* name, const size_t nlength,
|
||||
const uint8_t* value, const size_t vlength,
|
||||
const uint8_t flags, const uint8_t modifier);
|
||||
|
||||
int PSYC_renderBody(PSYC_RenderState render,
|
||||
int PSYC_renderBody(PSYC_RenderState* render,
|
||||
const uint8_t* method, const size_t mlength,
|
||||
const uint8_t* data, const size_t dlength,
|
||||
const uint8_t flags);
|
||||
|
||||
int PSYC_doneRender(PSYC_RenderState render,
|
||||
int PSYC_doneRender(PSYC_RenderState* render,
|
||||
uint8_t** buf, size_t* written);
|
||||
|
||||
|
|
12
src/parser.c
12
src/parser.c
|
@ -68,7 +68,7 @@ inline char isKwChar(uint8_t c)
|
|||
* It should contain one or more keyword characters.
|
||||
* @return PSYC_ERROR or PSYC_SUCCESS
|
||||
*/
|
||||
inline PSYC_ParseRC PSYC_parseName(PSYC_ParserState* state, PSYC_Array* name)
|
||||
inline PSYC_ParseRC PSYC_parseName(PSYC_ParseState* state, PSYC_Array* name)
|
||||
{
|
||||
name->ptr = state->buffer.ptr + state->cursor;
|
||||
name->length = 0;
|
||||
|
@ -92,7 +92,7 @@ inline PSYC_ParseRC PSYC_parseName(PSYC_ParserState* state, PSYC_Array* name)
|
|||
*
|
||||
* @return PSYC_COMPLETE or PSYC_INCOMPLETE
|
||||
*/
|
||||
inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParserState* state, PSYC_Array* value, size_t* length, size_t* parsed)
|
||||
inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParseState* state, PSYC_Array* value, size_t* length, size_t* parsed)
|
||||
{
|
||||
size_t remaining = *length - *parsed;
|
||||
value->ptr = state->buffer.ptr + state->cursor;
|
||||
|
@ -115,7 +115,7 @@ inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParserState* state, PSYC_Array* v
|
|||
* Parse simple or binary variable.
|
||||
* @return PSYC_ERROR or PSYC_SUCCESS
|
||||
*/
|
||||
inline PSYC_ParseRC PSYC_parseVar(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
||||
inline PSYC_ParseRC PSYC_parseVar(PSYC_ParseState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
||||
{
|
||||
*modifier = *(state->buffer.ptr + state->cursor);
|
||||
ADVANCE_CURSOR_OR_RETURN(PSYC_INSUFFICIENT);
|
||||
|
@ -179,7 +179,7 @@ inline PSYC_ParseRC PSYC_parseVar(PSYC_ParserState* state, uint8_t* modifier, PS
|
|||
* Parse PSYC packets.
|
||||
* Generalized line-based parser.
|
||||
*/
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
||||
{
|
||||
int ret; // a return value
|
||||
size_t pos; // a cursor position
|
||||
|
@ -369,7 +369,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array*
|
|||
* List value parser.
|
||||
* @return see PSYC_ListRC.
|
||||
*/
|
||||
PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem)
|
||||
PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem)
|
||||
{
|
||||
if (state->cursor >= state->buffer.length)
|
||||
return PSYC_LIST_INCOMPLETE;
|
||||
|
@ -440,7 +440,7 @@ PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array*
|
|||
// Start or resume parsing the binary data
|
||||
if (state->elemParsed < state->elemLength)
|
||||
{
|
||||
if (PSYC_parseBinaryValue((PSYC_ParserState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_INCOMPLETE)
|
||||
if (PSYC_parseBinaryValue((PSYC_ParseState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_INCOMPLETE)
|
||||
return PSYC_LIST_INCOMPLETE;
|
||||
|
||||
state->elemLength = 0;
|
||||
|
|
10
src/render.c
10
src/render.c
|
@ -4,21 +4,21 @@
|
|||
|
||||
/* render PSYC packets */
|
||||
|
||||
int PSYC_renderBody(PSYC_RenderState render,
|
||||
int PSYC_renderBody(PSYC_RenderState* render,
|
||||
const uint8_t* method, const size_t mlength,
|
||||
const uint8_t* data, const size_t dlength,
|
||||
const uint8_t flags) {
|
||||
|
||||
// find out if this packet needs a prepended length
|
||||
if (dlength == 1 && data[0] == C_GLYPH_PACKET_DELIMITER)
|
||||
render.flag = PSYC_NEED_LENGTH;
|
||||
render->flag = PSYC_NEED_LENGTH;
|
||||
else if (dlength > 404)
|
||||
render.flag = PSYC_NEED_LENGTH;
|
||||
render->flag = PSYC_NEED_LENGTH;
|
||||
else if (memmem(data, dlength, PSYC_PACKET_DELIMITER,
|
||||
sizeof(PSYC_PACKET_DELIMITER)))
|
||||
render.flag = PSYC_NEED_LENGTH;
|
||||
render->flag = PSYC_NEED_LENGTH;
|
||||
else
|
||||
render.flag = PSYC_FINE;
|
||||
render->flag = PSYC_FINE;
|
||||
|
||||
// TBD
|
||||
return 0;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <psyc.h>
|
||||
#include <psyc/parser.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
@ -8,8 +9,8 @@ int main(int argc, char** argv)
|
|||
int index, ret;
|
||||
uint8_t buffer[2048], modifier;
|
||||
PSYC_Array name, value, elem;
|
||||
PSYC_ParserState state;
|
||||
PSYC_ListState listState;
|
||||
PSYC_ParseState state;
|
||||
PSYC_ParseListState listState;
|
||||
|
||||
int file = open(argv[1],O_RDONLY);
|
||||
if(file < 0)
|
Loading…
Reference in a new issue