Ejemplo n.º 1
0
static int
getit(struct get_options *opt, const char *name, int argc, char **argv)
{
    int i;
    krb5_error_code ret;
    struct get_entry_data data;

    if(opt->long_flag == -1 && (opt->short_flag == 1 || opt->terse_flag == 1))
	opt->long_flag = 0;
    if(opt->short_flag == -1 && (opt->long_flag == 1 || opt->terse_flag == 1))
	opt->short_flag = 0;
    if(opt->terse_flag == -1 && (opt->long_flag == 1 || opt->short_flag == 1))
	opt->terse_flag = 0;
    if(opt->long_flag == 0 && opt->short_flag == 0 && opt->terse_flag == 0)
	opt->short_flag = 1;

    if (opt->terse_flag)
        return listit(name, argc, argv);

    data.table = NULL;
    data.chead = NULL;
    data.ctail = &data.chead;
    data.mask = 0;
    data.extra_mask = 0;

    if(opt->short_flag) {
	data.table = rtbl_create();
	rtbl_set_separator(data.table, "  ");
	data.format = print_entry_short;
    } else
	data.format = print_entry_long;
    if(opt->column_info_string == NULL) {
	if(opt->long_flag)
	    ret = setup_columns(&data, DEFAULT_COLUMNS_LONG);
	else
	    ret = setup_columns(&data, DEFAULT_COLUMNS_SHORT);
    } else
	ret = setup_columns(&data, opt->column_info_string);

    if(ret != 0) {
	if(data.table != NULL)
	    rtbl_destroy(data.table);
	return 0;
    }

    for(i = 0; i < argc; i++)
	ret = foreach_principal(argv[i], do_get_entry, name, &data);

    if(data.table != NULL) {
	rtbl_format(data.table, stdout);
	rtbl_destroy(data.table);
    }
    free_columns(&data);
    return ret != 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	struct libscols_table *tb;
	struct libscols_line *ln, *xln;

	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */

	scols_init_debug(0);

	tb = scols_new_table();
	if (!tb)
		err(EXIT_FAILURE, "faild to create output table");

	scols_table_enable_colors(tb, 1);
	setup_columns(tb);

	ln = add_line(tb, NULL, "A");
	add_line(tb, ln, "aa");
	add_line(tb, ln, "ab");

	ln = add_line(tb, NULL, "B");
	xln = add_line(tb, ln, "ba");
	add_line(tb, xln, "baa");
	add_line(tb, xln, "bab");
	add_line(tb, ln, "bb");

	scols_print_table(tb);
	scols_unref_table(tb);
	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	struct libscols_table *tb;
	struct libscols_symbols *sy;
	struct libscols_cell *title;

	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */

	scols_init_debug(0);

	tb = scols_new_table();
	if (!tb)
		err(EXIT_FAILURE, "failed to create output table");

	scols_table_enable_colors(tb, isatty(STDOUT_FILENO));
	setup_columns(tb);
	add_line(tb, "foo", "bla bla bla");
	add_line(tb, "bar", "alb alb alb");

	title = scols_table_get_title(tb);

	/* right */
	scols_cell_set_data(title, "This is right title");
	scols_cell_set_color(title, "red");
	scols_cell_set_flags(title, SCOLS_CELL_FL_RIGHT);
	scols_print_table(tb);

	/* center */
	sy = scols_new_symbols();
	if (!sy)
		err_oom();
	scols_table_set_symbols(tb, sy);

	scols_symbols_set_title_padding(sy, "=");
	scols_cell_set_data(title, "This is center title (with padding)");
	scols_cell_set_color(title, "green");
	scols_cell_set_flags(title, SCOLS_CELL_FL_CENTER);
	scols_print_table(tb);

	/* left */
	scols_symbols_set_title_padding(sy, "-");
	scols_cell_set_data(title, "This is left title (with padding)");
	scols_cell_set_color(title, "blue");
	scols_cell_set_flags(title, SCOLS_CELL_FL_LEFT);
	scols_print_table(tb);

	scols_unref_table(tb);
	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	struct libscols_table *tb;
	int c, notree = 0, nstart = -1, nend = -1;


	static const struct option longopts[] = {
		{ "ascii",	0, 0, 'i' },
		{ "csv",        0, 0, 'c' },
		{ "list",       0, 0, 'l' },
		{ "noheadings",	0, 0, 'n' },
		{ "pairs",      0, 0, 'p' },
		{ "json",       0, 0, 'J' },
		{ "raw",        0, 0, 'r' },
		{ "range-start",1, 0, 'S' },
		{ "range-end",  1, 0, 'E' },
		{ NULL, 0, 0, 0 },
	};

	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */

	scols_init_debug(0);

	tb = scols_new_table();
	if (!tb)
		err(EXIT_FAILURE, "failed to create output table");

	while((c = getopt_long(argc, argv, "ciJlnprS:E:", longopts, NULL)) != -1) {
		switch(c) {
		case 'c':
			scols_table_set_column_separator(tb, ",");
			scols_table_enable_raw(tb, 1);
			notree = 1;
			break;
		case 'i':
			scols_table_enable_ascii(tb, 1);
			break;
		case 'J':
			scols_table_set_name(tb, "scolstest");
			scols_table_enable_json(tb, 1);
			break;
		case 'l':
			notree = 1;
			break;
		case 'n':
			scols_table_enable_noheadings(tb, 1);
			break;
		case 'p':
			scols_table_enable_export(tb, 1);
			notree = 1;
			break;
		case 'r':
			scols_table_enable_raw(tb, 1);
			notree = 1;
			break;
		case 'S':
			nstart = strtos32_or_err(optarg, "failed to parse range start") - 1;
			break;
		case 'E':
			nend = strtos32_or_err(optarg, "failed to parse range end") - 1;
			break;
		default:
			usage(stderr);
		}
	}

	scols_table_enable_colors(tb, 1);
	setup_columns(tb, notree);

	if (optind == argc)
		add_lines(tb, ".");
	else while (optind < argc)
		add_lines(tb, argv[optind++]);

	if (nstart >= 0 || nend >= 0) {
		/* print subset */
		struct libscols_line *start = NULL, *end = NULL;

		if (nstart >= 0)
			start = scols_table_get_line(tb, nstart);
		if (nend >= 0)
			end = scols_table_get_line(tb, nend);

		if (start || end)
			scols_table_print_range(tb, start, end);
	} else
		/* print all table */
		scols_print_table(tb);

	scols_unref_table(tb);
	return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	struct libscols_table *tb;
	struct libscols_line *ln;		/* any line */
	struct libscols_line *g1, *g2, *g3;	/* groups */
	struct libscols_line *p1;		/* parents */
	int c;

	static const struct option longopts[] = {
		{ "maxout", 0, NULL, 'm' },
		{ "width",  1, NULL, 'w' },
		{ "help",   1, NULL, 'h' },

		{ NULL, 0, NULL, 0 },
	};

	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */

	scols_init_debug(0);

	tb = scols_new_table();
	if (!tb)
		err(EXIT_FAILURE, "failed to create output table");

	while((c = getopt_long(argc, argv, "hmw:", longopts, NULL)) != -1) {
		switch(c) {
		case 'h':
			printf("%s [--help | --maxout | --width <num>]\n", program_invocation_short_name);
			break;
		case 'm':
			scols_table_enable_maxout(tb, TRUE);
			break;
		case 'w':
			scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS);
			scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
			break;
		}
	}

	scols_table_enable_colors(tb, isatty(STDOUT_FILENO));
	setup_columns(tb);

	add_line(tb, NULL, "Alone", "bla bla bla");

	p1 = add_line(tb, NULL, "A", "bla bla bla");
	     add_line(tb, p1,   "A:B", "bla bla bla");
	     add_line(tb, p1,   "A:C", "bla bla bla");

	g1 = add_line(tb, NULL, "B", "bla bla bla");

	g2 = add_line(tb, NULL, "C", "bla bla bla");
	ln = add_line(tb, NULL, "D", "bla bla bla");
	scols_table_group_lines(tb, g2, ln, 0);

	ln = add_line(tb, NULL, "G2:A", "alb alb alb");
	scols_line_link_group(ln, g2, 0);

	ln = add_line(tb, NULL, "E", "bla bla bla");
	scols_table_group_lines(tb, g1, ln, 0);


	ln = add_line(tb, NULL, "G1:A", "alb alb alb");
	scols_line_link_group(ln, g1, 0);

	add_line(tb, NULL, "G", "bla bla bla");

	g3 = ln = add_line(tb, NULL, "G1:B", "alb alb alb");
	scols_line_link_group(ln, g1, 0);

	ln = add_line(tb, NULL, "F", "bla bla bla");
	scols_table_group_lines(tb, g3, ln, 0);

	ln = add_line(tb, NULL, "G3:A", "alb alb alb");
	scols_line_link_group(ln, g3, 0);

	add_line(tb, NULL, "foo", "bla bla bla");
	add_line(tb, NULL, "bar", "bla bla bla");

	scols_print_table(tb);

	scols_unref_table(tb);
	return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
	struct libscols_table *tb;
	struct libscols_symbols *sy;
	struct libscols_cell *title;
	int c;

	static const struct option longopts[] = {
		{ "maxout", 0, NULL, 'm' },
		{ "width",  1, NULL, 'w' },
		{ NULL, 0, NULL, 0 },
	};

	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */

	scols_init_debug(0);

	tb = scols_new_table();
	if (!tb)
		err(EXIT_FAILURE, "failed to create output table");

	while((c = getopt_long(argc, argv, "mw:", longopts, NULL)) != -1) {
		switch(c) {
		case 'm':
			scols_table_enable_maxout(tb, TRUE);
			break;
		case 'w':
			scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS);
			scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
			break;
		}
	}

	scols_table_enable_colors(tb, isatty(STDOUT_FILENO));
	setup_columns(tb);
	add_line(tb, "foo", "bla bla bla");
	add_line(tb, "bar", "alb alb alb");

	title = scols_table_get_title(tb);

	/* right */
	scols_cell_set_data(title, "This is right title");
	scols_cell_set_color(title, "red");
	scols_cell_set_flags(title, SCOLS_CELL_FL_RIGHT);
	scols_print_table(tb);

	/* center */
	sy = scols_new_symbols();
	if (!sy)
		err_oom();
	scols_table_set_symbols(tb, sy);

	scols_symbols_set_title_padding(sy, "=");
	scols_cell_set_data(title, "This is center title (with padding)");
	scols_cell_set_color(title, "green");
	scols_cell_set_flags(title, SCOLS_CELL_FL_CENTER);
	scols_print_table(tb);

	/* left */
	scols_symbols_set_title_padding(sy, "-");
	scols_cell_set_data(title, "This is left title (with padding)");
	scols_cell_set_color(title, "blue");
	scols_cell_set_flags(title, SCOLS_CELL_FL_LEFT);
	scols_print_table(tb);

	scols_unref_table(tb);
	return EXIT_SUCCESS;
}