| 1 | #include <assert.h> |
| 2 | #include <isl/obj.h> |
| 3 | #include <isl/printer.h> |
| 4 | #include <isl/stream.h> |
| 5 | #include <isl/options.h> |
| 6 | |
| 7 | struct isl_arg_choice cat_format[] = { |
| 8 | {"isl" , ISL_FORMAT_ISL}, |
| 9 | {"omega" , ISL_FORMAT_OMEGA}, |
| 10 | {"polylib" , ISL_FORMAT_POLYLIB}, |
| 11 | {"ext-polylib" , ISL_FORMAT_EXT_POLYLIB}, |
| 12 | {"latex" , ISL_FORMAT_LATEX}, |
| 13 | {"C" , ISL_FORMAT_C}, |
| 14 | {0} |
| 15 | }; |
| 16 | |
| 17 | struct isl_arg_choice cat_yaml_style[] = { |
| 18 | { "block" , ISL_YAML_STYLE_BLOCK }, |
| 19 | { "flow" , ISL_YAML_STYLE_FLOW }, |
| 20 | { 0 } |
| 21 | }; |
| 22 | |
| 23 | struct cat_options { |
| 24 | struct isl_options *isl; |
| 25 | unsigned format; |
| 26 | unsigned yaml_style; |
| 27 | }; |
| 28 | |
| 29 | ISL_ARGS_START(struct cat_options, cat_options_args) |
| 30 | ISL_ARG_CHILD(struct cat_options, isl, "isl" , &isl_options_args, "isl options" ) |
| 31 | ISL_ARG_CHOICE(struct cat_options, format, 0, "format" , \ |
| 32 | cat_format, ISL_FORMAT_ISL, "output format" ) |
| 33 | ISL_ARG_CHOICE(struct cat_options, yaml_style, 0, "yaml-style" , \ |
| 34 | cat_yaml_style, ISL_YAML_STYLE_BLOCK, "output YAML style" ) |
| 35 | ISL_ARGS_END |
| 36 | |
| 37 | ISL_ARG_DEF(cat_options, struct cat_options, cat_options_args) |
| 38 | |
| 39 | int main(int argc, char **argv) |
| 40 | { |
| 41 | struct isl_ctx *ctx; |
| 42 | isl_stream *s; |
| 43 | struct isl_obj obj; |
| 44 | struct cat_options *options; |
| 45 | isl_printer *p; |
| 46 | |
| 47 | options = cat_options_new_with_defaults(); |
| 48 | assert(options); |
| 49 | argc = cat_options_parse(opt: options, argc, argv, ISL_ARG_ALL); |
| 50 | |
| 51 | ctx = isl_ctx_alloc_with_options(args: &cat_options_args, opt: options); |
| 52 | |
| 53 | s = isl_stream_new_file(ctx, stdin); |
| 54 | obj = isl_stream_read_obj(s); |
| 55 | isl_stream_free(s); |
| 56 | |
| 57 | p = isl_printer_to_file(ctx, stdout); |
| 58 | p = isl_printer_set_output_format(p, output_format: options->format); |
| 59 | p = isl_printer_set_yaml_style(p, yaml_style: options->yaml_style); |
| 60 | p = obj.type->print(p, obj.v); |
| 61 | p = isl_printer_end_line(p); |
| 62 | isl_printer_free(printer: p); |
| 63 | |
| 64 | obj.type->free(obj.v); |
| 65 | |
| 66 | isl_ctx_free(ctx); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |