Initial import.
[vtparse.git] / vtparse_test.c
blob4082655a20316fc7b4a2fd2d838800a460f87f8a
1 /*
2 * VTParse - an implementation of Paul Williams' DEC compatible state machine parser
4 * Author: Joshua Haberman <joshua@reverberate.org>
6 * This code is in the public domain.
7 */
9 #include <stdio.h>
10 #include "vtparse.h"
12 void parser_callback(vtparse_t *parser, vtparse_action_t action, unsigned char ch)
14 int i;
16 printf("Received action %s, char=0x%02x\n", ACTION_NAMES[action]);
17 printf("Intermediate chars: '%s'\n", parser->intermediate_chars);
18 printf("%d Parameters:\n", parser->num_params);
19 for(i = 0; i < parser->num_params; i++)
20 printf("\t%d\n", parser->params[i]);
21 printf("\n");
24 int main()
26 unsigned char buf[1024];
27 int bytes;
28 vtparse_t parser;
30 vtparse_init(&parser, parser_callback);
32 while(1) {
33 bytes = read(0, buf, 1024);
34 vtparse(&parser, buf, bytes);