2 * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 /* Manipulating tables and their rows and columns. */
30 struct column *columns;
31 size_t n_columns, allocated_columns;
32 size_t n_rows, allocated_rows;
33 size_t current_column;
38 void table_init(struct table *);
39 void table_destroy(struct table *);
40 void table_set_caption(struct table *, char *caption);
41 void table_set_timestamp(struct table *, bool timestamp);
43 void table_add_column(struct table *, const char *heading, ...)
45 void table_add_row(struct table *);
55 const struct ovsdb_type *type;
58 struct cell *table_add_cell(struct table *);
60 /* Table formatting. */
63 TF_TABLE, /* 2-d table. */
64 TF_LIST, /* One cell per line, one row per paragraph. */
65 TF_HTML, /* HTML table. */
66 TF_CSV, /* Comma-separated lines. */
71 CF_STRING, /* String format. */
72 CF_BARE, /* String format without most punctuation. */
77 enum table_format format; /* TF_*. */
78 enum cell_format cell_format; /* CF_*. */
79 bool headings; /* Include headings? */
80 int json_flags; /* CF_JSON: Flags for json_to_string(). */
83 #define TABLE_STYLE_DEFAULT { TF_TABLE, CF_STRING, true, JSSF_SORT }
85 #define TABLE_OPTION_ENUMS \
90 #define TABLE_LONG_OPTIONS \
91 {"format", required_argument, NULL, 'f'}, \
92 {"data", required_argument, NULL, 'd'}, \
93 {"no-headings", no_argument, NULL, OPT_NO_HEADINGS}, \
94 {"pretty", no_argument, NULL, OPT_PRETTY}, \
95 {"bare", no_argument, NULL, OPT_BARE}
97 #define TABLE_OPTION_HANDLERS(STYLE) \
99 table_parse_format(STYLE, optarg); \
103 table_parse_cell_format(STYLE, optarg); \
106 case OPT_NO_HEADINGS: \
107 (STYLE)->headings = false; \
111 (STYLE)->json_flags |= JSSF_PRETTY; \
115 (STYLE)->format = TF_LIST; \
116 (STYLE)->cell_format = CF_BARE; \
117 (STYLE)->headings = false; \
120 void table_parse_format(struct table_style *, const char *format);
121 void table_parse_cell_format(struct table_style *, const char *format);
123 void table_print(const struct table *, const struct table_style *);