fea62286455b1508fe5dfaf8e7f9763b2b24e83d
[platform/upstream/isl.git] / cat.c
1 #include <assert.h>
2 #include <isl/obj.h>
3 #include <isl/printer.h>
4 #include <isl/stream.h>
5
6 struct isl_arg_choice cat_format[] = {
7         {"isl",         ISL_FORMAT_ISL},
8         {"omega",       ISL_FORMAT_OMEGA},
9         {"polylib",     ISL_FORMAT_POLYLIB},
10         {"ext-polylib", ISL_FORMAT_EXT_POLYLIB},
11         {"latex",       ISL_FORMAT_LATEX},
12         {0}
13 };
14
15 struct cat_options {
16         struct isl_options      *isl;
17         unsigned                 format;
18 };
19
20 ISL_ARGS_START(struct cat_options, cat_options_args)
21 ISL_ARG_CHILD(struct cat_options, isl, "isl", &isl_options_args, "isl options")
22 ISL_ARG_CHOICE(struct cat_options, format, 0, "format", \
23         cat_format,     ISL_FORMAT_ISL, "output format")
24 ISL_ARGS_END
25
26 ISL_ARG_DEF(cat_options, struct cat_options, cat_options_args)
27
28 int main(int argc, char **argv)
29 {
30         struct isl_ctx *ctx;
31         struct isl_stream *s;
32         struct isl_obj obj;
33         struct cat_options *options;
34         isl_printer *p;
35
36         options = cat_options_new_with_defaults();
37         assert(options);
38         argc = cat_options_parse(options, argc, argv, ISL_ARG_ALL);
39
40         ctx = isl_ctx_alloc_with_options(&cat_options_args, options);
41
42         s = isl_stream_new_file(ctx, stdin);
43         obj = isl_stream_read_obj(s);
44         isl_stream_free(s);
45
46         p = isl_printer_to_file(ctx, stdout);
47         p = isl_printer_set_output_format(p, options->format);
48         p = obj.type->print(p, obj.v);
49         p = isl_printer_end_line(p);
50         isl_printer_free(p);
51
52         obj.type->free(obj.v);
53
54         isl_ctx_free(ctx);
55
56         return 0;
57 }