From ab30ef650c623bfbf08b83013a6ff53c27722f8d Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Fri, 6 May 2011 15:26:28 +0200 Subject: [PATCH] psycString init --- include/psyc/parser.h | 6 ++++-- include/psyc/text.h | 22 ++++++++++++---------- test/testParser.c | 2 +- test/testServer.c | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/psyc/parser.h b/include/psyc/parser.h index b28d064..a9bf74f 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -184,7 +184,8 @@ void psyc_setParseBuffer (psycParseState *state, psycString buffer) static inline void psyc_setParseBuffer2 (psycParseState *state, char *buffer, size_t length) { - psyc_setParseBuffer(state, psyc_newString(buffer, length)); + psycString buf = {length, buffer}; + psyc_setParseBuffer(state, buf); } /** @@ -211,7 +212,8 @@ void psyc_setParseListBuffer (psycParseListState *state, psycString buffer) static inline void psyc_setParseListBuffer2 (psycParseListState *state, char *buffer, size_t length) { - psyc_setParseListBuffer(state, psyc_newString(buffer, length)); + psycString buf = {length, buffer}; + psyc_setParseListBuffer(state, buf); } static inline diff --git a/include/psyc/text.h b/include/psyc/text.h index 8f3b1f0..3f4746f 100644 --- a/include/psyc/text.h +++ b/include/psyc/text.h @@ -78,11 +78,12 @@ void psyc_initTextState (psycTextState *state, char *template, size_t tlen, char *buffer, size_t blen) { - state->cursor = state->written = 0; - state->template = psyc_newString(template, tlen); - state->buffer = psyc_newString(buffer, blen); - state->open = psyc_newString("[", 1); - state->close = psyc_newString("]", 1); + state->cursor = 0; + state->written = 0; + state->template = {tlen, template}; + state->buffer = {blen, buffer}; + state->open = {1, "["}; + state->close = {1, "]"}; } /** @@ -105,10 +106,10 @@ void psyc_initTextState2 (psycTextState *state, char *open, size_t openlen, char *close, size_t closelen) { - state->template = psyc_newString(template, tlen); - state->buffer = psyc_newString(buffer, blen); - state->open = psyc_newString(open, openlen); - state->close = psyc_newString(close, closelen); + state->template = {tlen, template}; + state->buffer = {blen, buffer}; + state->open = {openlen, open}; + state->close = {closelen, close}; } /** @@ -128,7 +129,8 @@ static inline void psyc_setTextBuffer2 (psycTextState *state, char *buffer, size_t length) { - psyc_setTextBuffer(state, psyc_newString(buffer, length)); + psycString buf = {length, buffer}; + psyc_setTextBuffer(state, buf); } static inline diff --git a/test/testParser.c b/test/testParser.c index 38a1d46..8634bcb 100644 --- a/test/testParser.c +++ b/test/testParser.c @@ -33,7 +33,7 @@ int main (int argc, char **argv) else psyc_initParseState(&state); - psyc_setParseBuffer(&state, psyc_newString(buffer, idx)); + psyc_setParseBuffer2(&state, buffer, idx); // try parsing that now do diff --git a/test/testServer.c b/test/testServer.c index 182377d..95a8caa 100644 --- a/test/testServer.c +++ b/test/testServer.c @@ -234,7 +234,7 @@ int main (int argc, char **argv) { // we got some data from a client parsebuf = recvbuf - contbytes; - psyc_setParseBuffer(&parsers[i], psyc_newString(parsebuf, contbytes + nbytes)); + psyc_setParseBuffer2(&parsers[i], parsebuf, contbytes + nbytes); contbytes = 0; oper = 0; name.length = 0;