aboutsummaryrefslogtreecommitdiff
path: root/tests/tforlan.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tforlan.c')
-rw-r--r--tests/tforlan.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/tforlan.c b/tests/tforlan.c
new file mode 100644
index 0000000..9fc3495
--- /dev/null
+++ b/tests/tforlan.c
@@ -0,0 +1,100 @@
1/* This file is part of Eclat.
2 Copyright (C) 2012 Sergey Poznyakoff.
3
4 Eclat is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Eclat is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <config.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <unistd.h>
21#ifdef HAVE_GETOPT_H
22# include <getopt.h>
23#endif
24#include <errno.h>
25#include <sysexits.h>
26#include <libeclat.h>
27#include "forlan.h"
28#include <sys/stat.h>
29
30void
31usage()
32{
33 printf("usage: %s [-dD] FILE [INPUT]\n");
34}
35
36int
37main(int argc, char **argv)
38{
39 FILE *fp;
40 char *buf;
41 size_t len;
42 struct stat st;
43 struct grecs_locus_point pt;
44 int rc;
45 int dump_option = 0;
46
47 set_program_name(argv[0]);
48 forlan_init();
49
50 while ((rc = getopt(argc, argv, "Dd:h")) != EOF)
51 switch (rc) {
52 case 'D':
53 dump_option++;
54 break;
55
56 case 'd':
57 if (parse_debug_level(optarg))
58 die(EX_USAGE, "bad debug category or level");
59 break;
60
61 case 'h':
62 usage();
63 return 0;
64
65 default:
66 exit(EX_USAGE);
67 }
68 argc -= optind;
69 argv += optind;
70
71
72 if (argc == 0 || argc > 2)
73 die(EX_USAGE, "one or two arguments expected");
74 if (stat(argv[0], &st))
75 die(EX_UNAVAILABLE, "cannot stat input file \"%s\": %s",
76 argv[0], strerror(errno));
77 len = st.st_size;
78 buf = grecs_malloc(len);
79 fp = fopen(argv[0], "r");
80 if (!fp)
81 die(EX_UNAVAILABLE, "cannot open input file \"%s\": %s",
82 argv[0], strerror(errno));
83 if (fread(buf, len, 1, fp) != 1)
84 die(EX_UNAVAILABLE, "error reading from \"%s\": %s",
85 argv[0], strerror(errno));
86 fclose(fp);
87
88 pt.file = argv[0];
89 pt.line = 1;
90 pt.col = 0;
91
92 rc = forlan_parse(buf, len, &pt);
93 if (rc == 0) {
94 if (dump_option)
95 forlan_dump_tree(stdout, forlan_parse_tree);
96 forlan_node_free(forlan_parse_tree);
97 }
98 return rc ? EX_UNAVAILABLE : 0;
99}
100

Return to:

Send suggestions and report system problems to the System administrator.