(root)/
util-linux-2.39/
libsmartcols/
samples/
maxout.c
       1  /*
       2   * Copyright (C) 2016 Karel Zak <kzak@redhat.com>
       3   *
       4   * This file may be redistributed under the terms of the
       5   * GNU Lesser General Public License.
       6   */
       7  #include <stdlib.h>
       8  #include <unistd.h>
       9  #include <string.h>
      10  #include <errno.h>
      11  #include <sys/types.h>
      12  #include <sys/stat.h>
      13  #include <dirent.h>
      14  #include <getopt.h>
      15  
      16  #include "c.h"
      17  #include "nls.h"
      18  #include "libsmartcols.h"
      19  
      20  enum { COL_LEFT, COL_FOO, COL_RIGHT };
      21  
      22  int main(int argc, char *argv[])
      23  {
      24  	struct libscols_table *tb;
      25  	int rc = -1, nlines = 3;
      26  
      27  	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */
      28  
      29  	scols_init_debug(0);
      30  
      31  	tb = scols_new_table();
      32  	if (!tb)
      33  		err(EXIT_FAILURE, "failed to create output table");
      34  
      35  	scols_table_enable_maxout(tb, TRUE);
      36  	if (!scols_table_new_column(tb, "LEFT", 0, 0))
      37  		goto done;
      38  	if (!scols_table_new_column(tb, "FOO", 0, 0))
      39  		goto done;
      40  	if (!scols_table_new_column(tb, "RIGHT", 0, SCOLS_FL_RIGHT))
      41  		goto done;
      42  
      43  	while (nlines--) {
      44  		struct libscols_line *ln = scols_table_new_line(tb, NULL);
      45  
      46  		rc = scols_line_set_data(ln, COL_LEFT, "A");
      47  		if (!rc)
      48  			rc = scols_line_set_data(ln, COL_FOO, "B");
      49  		if (!rc)
      50  			rc = scols_line_set_data(ln, COL_RIGHT, "C");
      51  		if (rc)
      52  			err(EXIT_FAILURE, "failed to set line data");
      53  	}
      54  
      55  	scols_print_table(tb);
      56  	rc = 0;
      57  done:
      58  	scols_unref_table(tb);
      59  	return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
      60  }