1 .\" Copyright (c) 2004 Kungliga Tekniska Högskolan
2 .\" (Royal Institute of Technology, Stockholm, Sweden).
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the Institute nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 .Nm rtbl_set_separator ,
43 .Nm rtbl_set_column_prefix ,
44 .Nm rtbl_set_column_affix_by_id ,
46 .Nm rtbl_add_column_by_id ,
47 .Nm rtbl_add_column_entry ,
48 .Nm rtbl_add_column_entry_by_id ,
51 .Nd format data in simple tables
53 The roken library (libroken, -lroken)
57 .Fn rtbl_add_column "rtbl_t table" "const char *column_name" "unsigned int flags"
59 .Fn rtbl_add_column_by_id "rtbl_t table" "unsigned int column_id" "const char *column_header" "unsigned int flags"
61 .Fn rtbl_add_column_entry "rtbl_t table" "const char *column_name" "const char *cell_entry"
63 .Fn rtbl_add_column_entry_by_id "rtbl_t table" "unsigned int column_id" "const char *cell_entry"
65 .Fn rtbl_create "void"
67 .Fn rtbl_destroy "rtbl_t table"
69 .Fn rtbl_new_row "rtbl_t table"
71 .Fn rtbl_set_column_affix_by_id "rtbl_t table" "unsigned int column_id "const char *prefix" "const char *suffix"
73 .Fn rtbl_set_column_prefix "rtbl_t table" "const char *column_name" "const char *prefix"
75 .Fn rtbl_get_flags "rtbl_t table"
77 .Fn rtbl_set_flags "rtbl_t table" "unsigned int flags"
79 .Fn rtbl_set_prefix "rtbl_t table" "const char *prefix"
81 .Fn rtbl_set_separator "rtbl_t table" "const char *separator"
83 .Fn rtbl_format "rtbl_t table "FILE *file"
85 This set of functions assemble a simple table consisting of rows and
86 columns, allowing it to be printed with certain options. Typical use
87 would be output from tools such as
91 where you have a fixed number of columns, but don't know the column
94 A table is created with
99 Global flags on the table are set with
103 At present the only defined flag is
104 .Dv RTBL_HEADER_STYLE_NONE
105 which suppresses printing the header.
107 Before adding data to the table, one or more columns need to be
108 created. This would normally be done with
109 .Fn rtbl_add_column_by_id ,
111 is any number of your choice (it's used only to identify columns),
113 is the header to print at the top of the column, and
115 are flags specific to this column. Currently the only defined flag is
116 .Dv RTBL_ALIGN_RIGHT ,
117 aligning column entries to the right. Columns are printed in the order
120 There's also a way to add columns by column name with
121 .Fn rtbl_add_column ,
122 but this is less flexible (you need unique header names), and is
123 considered deprecated.
125 To add data to a column you use
126 .Fn rtbl_add_column_entry_by_id ,
129 is the same as when the column was added (adding data to a
130 non-existent column is undefined), and
132 is whatever string you wish to include in that cell. It should not
134 For columns added with
137 .Fn rtbl_add_column_entry
141 fills all columns with blank entries until they all have the same
144 Each column can have a separate prefix and suffix, set with
145 .Fa rtbl_set_column_affix_by_id ;
146 .Fa rtbl_set_column_prefix
147 allows setting the prefix only by column name. In addition to this,
148 columns may be separated by a string set with
149 .Fa rtbl_set_separator ( Ns
150 by default columns are not seprated by anything).
152 The finished table is printed to
158 .Bd -literal -offset xxxx
162 main(int argc, char **argv)
165 table = rtbl_create();
166 rtbl_set_separator(table, " ");
167 rtbl_add_column_by_id(table, 0, "Column A", 0);
168 rtbl_add_column_by_id(table, 1, "Column B", RTBL_ALIGN_RIGHT);
169 rtbl_add_column_by_id(table, 2, "Column C", 0);
170 rtbl_add_column_entry_by_id(table, 0, "A-1");
171 rtbl_add_column_entry_by_id(table, 0, "A-2");
172 rtbl_add_column_entry_by_id(table, 0, "A-3");
173 rtbl_add_column_entry_by_id(table, 1, "B-1");
174 rtbl_add_column_entry_by_id(table, 2, "C-1");
175 rtbl_add_column_entry_by_id(table, 2, "C-2");
176 rtbl_add_column_entry_by_id(table, 1, "B-2");
177 rtbl_add_column_entry_by_id(table, 1, "B-3");
178 rtbl_add_column_entry_by_id(table, 2, "C-3");
179 rtbl_add_column_entry_by_id(table, 0, "A-4");
181 rtbl_add_column_entry_by_id(table, 1, "B-4");
183 rtbl_add_column_entry_by_id(table, 2, "C-4");
185 rtbl_format(table, stdout);
191 will output the following:
192 .Bd -literal -offset xxxx
193 Column A Column B Column C