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

ready for testing now.

This commit is contained in:
Marenz 2011-04-17 13:59:07 +02:00
parent b6ef420efa
commit fc829ecbb3
4 changed files with 55 additions and 43 deletions

View file

@ -30,7 +30,7 @@ typedef struct
PSYC_Array buffer; PSYC_Array buffer;
uint8_t flags; uint8_t flags;
char inHeader; char inBody;
unsigned int length; unsigned int length;
unsigned int contentLength; unsigned int contentLength;
} PSYC_State; } PSYC_State;
@ -59,8 +59,6 @@ inline void PSYC_nextBuffer (PSYC_State* state, PSYC_Array newBuf)
state->buffer = newBuf; state->buffer = newBuf;
} }
inline unsigned int PSYC_getBodyLength (PSYC_State* state) inline unsigned int PSYC_getBodyLength (PSYC_State* state)
{ {
return state->length; return state->length;

View file

@ -12,7 +12,7 @@ diet:
/opt/diet/bin/diet ar rcs libpsyc.a $O /opt/diet/bin/diet ar rcs libpsyc.a $O
lib: $S lib: $S
${CC} -static -c -Os $S -lc -DDEBUG -DPSYC_COMPILE_LIBRARY ${CC} -static -c -g -O0 $S -lc -DDEBUG -DPSYC_COMPILE_LIBRARY
ar rcs libpsyc.a $O ar rcs libpsyc.a $O
match: match.c match: match.c

View file

@ -61,7 +61,7 @@ start:
/* each line of the header starts with a glyph. /* each line of the header starts with a glyph.
* iE :_name, -_name +_name etc, so just test if * iE :_name, -_name +_name etc, so just test if
* the first char is a glyph. */ * the first char is a glyph. */
if(1==state->inHeader) if(0==state->inBody)
{ {
if(!isGlyph(state->buffer.ptr[state->cursor])) // is the first char not a glyph? if(!isGlyph(state->buffer.ptr[state->cursor])) // is the first char not a glyph?
{ {
@ -95,7 +95,7 @@ start:
// is complete(empty packet) or that the method started. // is complete(empty packet) or that the method started.
if(isAlphaNumeric(state->buffer.ptr[state->cursor])) if(isAlphaNumeric(state->buffer.ptr[state->cursor]))
{ {
state->inHeader = 0; state->inBody = 1;
if (state->flags & PSYC_HEADER_ONLY) if (state->flags & PSYC_HEADER_ONLY)
return PSYC_HEADER_COMPLETE; // return header finished return PSYC_HEADER_COMPLETE; // return header finished
else else
@ -113,6 +113,7 @@ start:
if(state->buffer.ptr[state->cursor]=='\n') if(state->buffer.ptr[state->cursor]=='\n')
{ {
++(state->cursor); ++(state->cursor);
state->inBody = 0;
return PSYC_COMPLETE; // return packet finished return PSYC_COMPLETE; // return packet finished
} }
} }
@ -130,55 +131,62 @@ start:
name->ptr = state->buffer.ptr + state->cursor; name->ptr = state->buffer.ptr + state->cursor;
name->length = 0; name->length = 1;
} }
} } // endif inBody=0
char method=0; char method=0;
/* each line of the header starts with a glyph.
* iE :_name, -_name +_name etc, so just test if
* the first char is a glyph. */
/* in the body, the same applies, only that the /* in the body, the same applies, only that the
* method does not start with a glyph.*/ * method does not start with a glyph.*/
if(0==state->inHeader && !isGlyph(state->buffer.ptr[state->cursor])) if(1==state->inBody)
{ {
if(!isAlphaNumeric(state->buffer.ptr[state->cursor]) && state->buffer.ptr[state->cursor] != '_') if(!isGlyph(state->buffer.ptr[state->cursor]))
{ {
// the body rule is optional, which means if(!isAlphaNumeric(state->buffer.ptr[state->cursor]) && state->buffer.ptr[state->cursor] != '_')
// that now also just |\n can follow.
if(state->buffer.ptr[state->cursor] == '|')
{ {
if(state->buffer.length<=++(state->cursor)) // incremented cursor inside lenght? // the body rule is optional, which means
// that now also just |\n can follow.
if(state->buffer.ptr[state->cursor] == '|')
{ {
state->cursor=startc; // set to start value if(state->buffer.length<=++(state->cursor)) // incremented cursor inside lenght?
return PSYC_INSUFFICIENT; // return insufficient {
} state->cursor=startc; // set to start value
return PSYC_INSUFFICIENT; // return insufficient
}
if(state->buffer.ptr[state->cursor]=='\n') if(state->buffer.ptr[state->cursor]=='\n')
{ {
++(state->cursor); ++(state->cursor);
return PSYC_COMPLETE; // return packet finished state->inBody = 0;
return PSYC_COMPLETE; // return packet finished
}
} }
return -5; // report error
}
else
{
name->ptr = state->buffer.ptr+state->cursor;
name->length=1;
method=1;
} }
return -5; // report error
} }
else else
{ {
*modifier = *(state->buffer.ptr+state->cursor);
if (state->buffer.length <= ++(state->cursor))
{
state->cursor = startc; // rewind
return PSYC_INSUFFICIENT; // return insufficient
}
name->ptr = state->buffer.ptr+state->cursor; name->ptr = state->buffer.ptr+state->cursor;
name->length=1; name->length=1;
method=1;
} }
} }
else
{
*modifier = *(state->buffer.ptr+state->cursor);
if (state->buffer.length <= ++(state->cursor))
{
state->cursor = startc; // rewind
return PSYC_INSUFFICIENT; // return insufficient
}
name->ptr = state->buffer.ptr+state->cursor;
name->length=1;
}
/* validate the incremented cursor */ /* validate the incremented cursor */
if(state->buffer.length <= ++(state->cursor)) if(state->buffer.length <= ++(state->cursor))
@ -293,6 +301,7 @@ start:
{ {
/* packet finishes here */ /* packet finishes here */
state->cursor+=3; state->cursor+=3;
state->inBody = 0;
return PSYC_COMPLETE; return PSYC_COMPLETE;
} }
@ -302,7 +311,7 @@ start:
} }
} }
} }
else if(state->inHeader == 0 && method==0 && state->buffer.ptr[state->cursor] == ' ') // oi, its a binary var! else if(state->inBody == 1 && method==0 && state->buffer.ptr[state->cursor] == ' ') // oi, its a binary var!
{ // after SP the length follows. { // after SP the length follows.
unsigned int binLength= 0; unsigned int binLength= 0;
@ -344,7 +353,7 @@ start:
/* if there was a \t, then we parsed up until the /* if there was a \t, then we parsed up until the
* \n char from the simple-arg rule ( \t arg-state->buffer.ptr \n ) * \n char from the simple-arg rule ( \t arg-data \n )
* *
* Now, if there would be no \t, we still would be at * Now, if there would be no \t, we still would be at
* the point where a \n must follow. * the point where a \n must follow.
@ -366,16 +375,20 @@ start:
return PSYC_INSUFFICIENT; // return insufficient return PSYC_INSUFFICIENT; // return insufficient
} }
if(1 == state->inHeader && state->buffer.ptr[state->cursor] == '\n') if(0 == state->inBody && state->buffer.ptr[state->cursor] == '\n')
{ {
state->cursor+=1; state->cursor+=1;
state->inHeader = 0; state->inBody = 1;
return 2; // line is complete, but body starts now.
if (state->flags & PSYC_HEADER_ONLY)
return PSYC_HEADER_COMPLETE; // return header finished
else
goto start;
} }
if(state->buffer.ptr[state->cursor] != '|') // no pipe, then only line complete, not the packet. if(state->buffer.ptr[state->cursor] != '|') // no pipe, then only line complete, not the packet.
{ {
if (state->inHeader == 1) if (state->inBody == 0)
return PSYC_ROUTING; return PSYC_ROUTING;
else else
return PSYC_ENTITY; return PSYC_ENTITY;
@ -389,6 +402,7 @@ start:
return -4; return -4;
state->cursor+=1; state->cursor+=1;
state->inBody = 0;
return PSYC_COMPLETE; // packet is complete return PSYC_COMPLETE; // packet is complete
} }

View file

@ -2,7 +2,7 @@ CFLAGS=-I.. -DDEBUG
LDFLAGS=-L.. -lpsyc LDFLAGS=-L.. -lpsyc
works: works:
cc -I../../include -DDEBUG -L.. parser/testParser.c -o testParser -lpsyc cc -I../../include -g -O0 -DDEBUG -L.. parser/testParser.c -o testParser -lpsyc
it: testParser it: testParser