compiles now. setting of expectedBytes and parsing of length is still missing

This commit is contained in:
Mathias L. Baumann 2011-04-16 11:30:26 +02:00
parent 453011001d
commit c688bab1f8
3 changed files with 26 additions and 28 deletions

View File

@ -1,15 +1,11 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
enum
{
}
typedef struct typedef struct
{ {
unsigned int length; unsigned int length;
const uint8_t *ptr; const uint8_t * ptr;
} PSYC_Array; } PSYC_Array;
typedef struct typedef struct
@ -23,7 +19,7 @@ typedef struct
} PSYC_State; } PSYC_State;
inline PSYC_Array (const uint8_t memory, unsigned int length) inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length)
{ {
PSYC_Array arr = {length, memory}; PSYC_Array arr = {length, memory};
@ -41,11 +37,9 @@ inline void PSYC_nextBuffer (PSYC_State* state, PSYC_Array newBuf)
} }
int PSYC_parse(PSYC_State* state, inline int PSYC_parse(PSYC_State* state,
PSYC_ConstArray name, PSYC_Array* name, PSYC_Array* value,
PSYC_ConstArray value, uint8_t* modifier, unsigned long *expectedBytes);
uint8_t modifier,
unsigned long *expectedBytes);
inline unsigned int PSYC_getBodyLength (PSYC_State* state) inline unsigned int PSYC_getBodyLength (PSYC_State* state)

View File

@ -9,5 +9,5 @@ diet:
/opt/diet/bin/diet ar rcs libpsyc.a libpsyc.o /opt/diet/bin/diet ar rcs libpsyc.a libpsyc.o
lib: lib:
${CC} -static -c -Os parser.c -lc -o libpsyc.o -DDEBUG ${CC} -static -c -Os parser.c -lc -o libpsyc.o -DDEBUG -I../include
ar rcs libpsyc.a libpsyc.o ar rcs libpsyc.a libpsyc.o

View File

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
#include <psyc/parser.h>
/** @brief isGlyph /** @brief isGlyph
* *
@ -44,22 +44,10 @@ inline char isAlphaNumeric(uint8_t c)
int PSYC_parse(PSYC_State* state,
PSYC_ConstArray name,
PSYC_ConstArray value,
uint8_t modifier,
unsigned long *expectedBytes)
{
}
/** @brief generalized linebased parser */ /** @brief generalized linebased parser */
inline int PSYC_parse( inline int PSYC_parse(
PSYC_State* state, PSYC_State* state,
PSYC_Array* name, PSYC_Array* value PSYC_Array* name, PSYC_Array* value,
uint8_t* modifier, unsigned long* expectedBytes) uint8_t* modifier, unsigned long* expectedBytes)
{ {
/* first we test if we can access the first char */ /* first we test if we can access the first char */
@ -101,7 +89,16 @@ inline int PSYC_parse(
return -6; // report error return -6; // report error
}else // it is a glyph, so a variable name starts here }else // it is a glyph, so a variable name starts here
{ {
*modifier = *state->buffer.ptr+state->cursor; *modifier = *(state->buffer.ptr+state->cursor);
if (state->buffer.length <= ++(state->cursor))
{
state->cursor = startc; // rewind to start of line
return 1; // return insufficient
}
name->ptr = state->buffer.ptr + state->cursor;
name->length = 0; name->length = 0;
} }
} }
@ -140,6 +137,14 @@ inline int PSYC_parse(
} }
else else
{ {
*modifier = *(state->buffer.ptr+state->cursor);
if (state->buffer.length <= ++(state->cursor))
{
state->cursor = startc; // rewind
return 1; // return insufficient
}
name->ptr = state->buffer.ptr+state->cursor; name->ptr = state->buffer.ptr+state->cursor;
name->length=1; name->length=1;
} }
@ -177,7 +182,6 @@ inline int PSYC_parse(
break; // not valid? then stop the loop right here break; // not valid? then stop the loop right here
++(name->length); // was a valid char, increase length ++(name->length); // was a valid char, increase length
} }
/* we now parsed the variable name successfully /* we now parsed the variable name successfully