File: test_parse.c

package info (click to toggle)
librnd 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,812 kB
  • sloc: ansic: 126,990; sh: 2,602; makefile: 2,145; awk: 7
file content (41 lines) | stat: -rw-r--r-- 707 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <string.h>
#include <librnd/core/base64.c>
#include "proto_lowcommon.h"
#include "proto_lowparse.h"
#include "proto_lowdbg.h"

int main()
{
	int line = 1, col = 1;
	proto_ctx_t pctx;

	memset(&pctx, 0, sizeof(pctx));

	for(;;) {
		parse_res_t res;
		int c = getchar();
		if (c == EOF)
			return -1;
		if (c == '\n') {
			col = 1;
			line++;
		}
		else
			col++;
		res = parse_char(&pctx, c);
		switch(res) {
			case PRES_ERR:
				printf("parse error at %d:%d\n", line, col);
				return 1;
			case PRES_GOT_MSG:
				printf("msg '%s'\n", pctx.pcmd);
				proto_node_print(pctx.targ, 1);
				printf("\n");
				proto_node_free(pctx.targ);
				break;
			case PRES_PROCEED:
				break;
		}
	}
	return 0;
}