File: cat.c

package info (click to toggle)
isl 0.20-2
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 12,708 kB
  • sloc: ansic: 125,702; python: 5,770; sh: 4,291; cpp: 1,057; makefile: 497; lisp: 54; perl: 9
file content (68 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (23)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <assert.h>
#include <isl/obj.h>
#include <isl/printer.h>
#include <isl/stream.h>
#include <isl/options.h>

struct isl_arg_choice cat_format[] = {
	{"isl",		ISL_FORMAT_ISL},
	{"omega",	ISL_FORMAT_OMEGA},
	{"polylib",	ISL_FORMAT_POLYLIB},
	{"ext-polylib",	ISL_FORMAT_EXT_POLYLIB},
	{"latex",	ISL_FORMAT_LATEX},
	{0}
};

struct isl_arg_choice cat_yaml_style[] = {
	{ "block",	ISL_YAML_STYLE_BLOCK },
	{ "flow",	ISL_YAML_STYLE_FLOW },
	{ 0 }
};

struct cat_options {
	struct isl_options	*isl;
	unsigned		 format;
	unsigned		 yaml_style;
};

ISL_ARGS_START(struct cat_options, cat_options_args)
ISL_ARG_CHILD(struct cat_options, isl, "isl", &isl_options_args, "isl options")
ISL_ARG_CHOICE(struct cat_options, format, 0, "format", \
	cat_format,	ISL_FORMAT_ISL, "output format")
ISL_ARG_CHOICE(struct cat_options, yaml_style, 0, "yaml-style", \
	cat_yaml_style, ISL_YAML_STYLE_BLOCK, "output YAML style")
ISL_ARGS_END

ISL_ARG_DEF(cat_options, struct cat_options, cat_options_args)

int main(int argc, char **argv)
{
	struct isl_ctx *ctx;
	isl_stream *s;
	struct isl_obj obj;
	struct cat_options *options;
	isl_printer *p;

	options = cat_options_new_with_defaults();
	assert(options);
	argc = cat_options_parse(options, argc, argv, ISL_ARG_ALL);

	ctx = isl_ctx_alloc_with_options(&cat_options_args, options);

	s = isl_stream_new_file(ctx, stdin);
	obj = isl_stream_read_obj(s);
	isl_stream_free(s);

	p = isl_printer_to_file(ctx, stdout);
	p = isl_printer_set_output_format(p, options->format);
	p = isl_printer_set_yaml_style(p, options->yaml_style);
	p = obj.type->print(p, obj.v);
	p = isl_printer_end_line(p);
	isl_printer_free(p);

	obj.type->free(obj.v);

	isl_ctx_free(ctx);

	return 0;
}