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.
13 void parser_callback(vtparse_t
*parser
, vtparse_action_t action
, unsigned char ch
)
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
]);
38 unsigned char buf
[1024];
42 vtparse_init(&parser
, parser_callback
);
45 bytes
= read(STDIN_FILENO
, buf
, 1024);
46 vtparse(&parser
, buf
, bytes
);