mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
table parsing
This commit is contained in:
parent
d95aa7f3e7
commit
42c2709378
5 changed files with 293 additions and 24 deletions
|
@ -3,7 +3,7 @@ DEBUG = 2
|
|||
CFLAGS = -I../include -I../src -Wall -std=c99 ${OPT}
|
||||
LDFLAGS = -L../lib
|
||||
LOADLIBES = -lpsyc -lm
|
||||
TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_is_routing var_type uniform_parse
|
||||
TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_is_routing var_type uniform_parse test_table
|
||||
O = test.o
|
||||
WRAPPER =
|
||||
DIET = diet
|
||||
|
@ -48,6 +48,7 @@ test: ${TARGETS}
|
|||
./var_is_routing
|
||||
./var_type
|
||||
./uniform_parse
|
||||
./test_table
|
||||
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./test_psyc -f $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
|
||||
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./test_psyc -rf $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
|
||||
|
||||
|
|
80
test/test_table.c
Normal file
80
test/test_table.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <psyc/parse.h>
|
||||
|
||||
int
|
||||
parse_table (char *buf, size_t buflen)
|
||||
{
|
||||
printf(">> %.*s\n", (int)buflen, buf);
|
||||
|
||||
int ret;
|
||||
PsycString elem;
|
||||
PsycParseTableState state;
|
||||
psyc_parse_table_state_init(&state);
|
||||
psyc_parse_table_buffer_set(&state, buf, buflen);
|
||||
|
||||
do {
|
||||
ret = psyc_parse_table(&state, &elem);
|
||||
switch (ret) {
|
||||
case PSYC_PARSE_TABLE_WIDTH:
|
||||
printf("width: %ld\n", elem.length);
|
||||
break;
|
||||
#ifdef PSYC_PARSE_TABLE_HEAD
|
||||
case PSYC_PARSE_TABLE_NAME_KEY:
|
||||
printf("name key: %.*s\n", (int)PSYC_S2ARG2(elem));
|
||||
break;
|
||||
case PSYC_PARSE_TABLE_NAME_VALUE:
|
||||
printf("name val: %.*s\n", (int)PSYC_S2ARG2(elem));
|
||||
break;
|
||||
#endif
|
||||
case PSYC_PARSE_TABLE_KEY_END:
|
||||
ret = 0;
|
||||
case PSYC_PARSE_TABLE_KEY:
|
||||
printf("key: %.*s\n", (int)PSYC_S2ARG2(elem));
|
||||
break;
|
||||
case PSYC_PARSE_TABLE_VALUE_END:
|
||||
ret = 0;
|
||||
case PSYC_PARSE_TABLE_VALUE:
|
||||
printf("val: %.*s\n", (int)PSYC_S2ARG2(elem));
|
||||
break;
|
||||
default:
|
||||
printf("err: %d\n", ret);
|
||||
}
|
||||
} while (ret > 0);
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
||||
#ifdef PSYC_PARSE_TABLE_HEAD
|
||||
if (!parse_table(PSYC_C2ARG("*2|_key|_val1|_val2 |_foo|bar|baz|_aaa|bbb|ccc")))
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
if (!parse_table(PSYC_C2ARG("*2 |_foo|bar|baz|_aaa|bbb|ccc")))
|
||||
return 2;
|
||||
|
||||
#ifdef PSYC_PARSE_TABLE_HEAD
|
||||
if (!parse_table(PSYC_C2ARG("*1|_key|_val1 |_foo|bar|_baz|aaa|_bbb|ccc")))
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
if (!parse_table(PSYC_C2ARG("*1 |_foo|bar|_baz|aaa|_bbb|ccc")))
|
||||
return 3;
|
||||
|
||||
#ifdef PSYC_PARSE_TABLE_HEAD
|
||||
if (!parse_table(PSYC_C2ARG("*0|_key |foo|bar|baz|aaa|bbb|ccc")))
|
||||
return 4;
|
||||
#endif
|
||||
|
||||
if (!parse_table(PSYC_C2ARG("*0 |foo|bar|baz|aaa|bbb|ccc")))
|
||||
return 4;
|
||||
|
||||
if (!parse_table(PSYC_C2ARG("|foo|bar|baz|aaa|bbb|ccc")))
|
||||
return 5;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue