Add Julian Scheid to credits, and add TODO note about character set support.
[vtparse.git] / vtparse_test.c
blob5019c815366f9b3fe63d7ff822b9e520c8bd50c4
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 <unistd.h>
11 #include "vtparse.h"
13 void parser_callback(vtparse_t *parser, vtparse_action_t action, unsigned char ch)
15 int i;
17 printf("Received action %s\n", ACTION_NAMES[action]);
18 if(ch != 0) printf("Char: 0x%02x ('%c')\n", ch, ch);
19 if(parser->num_intermediate_chars > 0)
21 printf("%d Intermediate chars:\n", parser->num_intermediate_chars);
22 for(i = 0; i < parser->num_intermediate_chars; i++)
23 printf(" 0x%02x ('%c')\n", parser->intermediate_chars[i],
24 parser->intermediate_chars[i]);
26 if(parser->num_params > 0)
28 printf("%d Parameters:\n", parser->num_params);
29 for(i = 0; i < parser->num_params; i++)
30 printf("\t%d\n", parser->params[i]);
33 printf("\n");
36 int main()
38 unsigned char buf[1024];
39 int bytes;
40 vtparse_t parser;
42 vtparse_init(&parser, parser_callback);
44 do {
45 bytes = read(STDIN_FILENO, buf, 1024);
46 vtparse(&parser, buf, bytes);
47 } while(bytes > 0);
49 return 0;