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.
23 #include "openvswitch/json.h"
28 /* Manipulating tables and their rows and columns. */
32 struct column
*columns
;
33 size_t n_columns
, allocated_columns
;
34 size_t n_rows
, allocated_rows
;
35 size_t current_column
;
40 void table_init(struct table
*);
41 void table_destroy(struct table
*);
42 void table_set_caption(struct table
*, char *caption
);
43 void table_set_timestamp(struct table
*, bool timestamp
);
45 void table_add_column(struct table
*, const char *heading
, ...)
46 OVS_PRINTF_FORMAT(2, 3);
47 void table_add_row(struct table
*);
57 const struct ovsdb_type
*type
;
60 struct cell
*table_add_cell(struct table
*);
62 /* Table formatting. */
65 TF_TABLE
, /* 2-d table. */
66 TF_LIST
, /* One cell per line, one row per paragraph. */
67 TF_HTML
, /* HTML table. */
68 TF_CSV
, /* Comma-separated lines. */
73 CF_STRING
, /* String format. */
74 CF_BARE
, /* String format without most punctuation. */
79 enum table_format format
; /* TF_*. */
80 enum cell_format cell_format
; /* CF_*. */
81 bool headings
; /* Include headings? */
82 int json_flags
; /* CF_JSON: Flags for json_to_string(). */
83 int max_column_width
; /* CF_STRING: Limit for column width. */
86 #define TABLE_STYLE_DEFAULT { TF_LIST, CF_STRING, true, JSSF_SORT, 0 }
87 static const struct table_style table_style_default
= TABLE_STYLE_DEFAULT
;
89 #define TABLE_OPTION_ENUMS \
95 #define TABLE_LONG_OPTIONS \
96 {"format", required_argument, NULL, 'f'}, \
97 {"data", required_argument, NULL, 'd'}, \
98 {"no-headings", no_argument, NULL, OPT_NO_HEADINGS}, \
99 {"pretty", no_argument, NULL, OPT_PRETTY}, \
100 {"bare", no_argument, NULL, OPT_BARE}, \
101 {"max-column-width", required_argument, NULL, OPT_MAX_COLUMN_WIDTH}
103 #define TABLE_OPTION_HANDLERS(STYLE) \
105 table_parse_format(STYLE, optarg); \
109 table_parse_cell_format(STYLE, optarg); \
112 case OPT_NO_HEADINGS: \
113 (STYLE)->headings = false; \
117 (STYLE)->json_flags |= JSSF_PRETTY; \
121 (STYLE)->format = TF_LIST; \
122 (STYLE)->cell_format = CF_BARE; \
123 (STYLE)->headings = false; \
126 case OPT_MAX_COLUMN_WIDTH: \
127 (STYLE)->max_column_width = atoi(optarg); \
130 void table_parse_format(struct table_style
*, const char *format
);
131 void table_parse_cell_format(struct table_style
*, const char *format
);
133 void table_print(const struct table
*, const struct table_style
*);
134 void table_format(const struct table
*, const struct table_style
*,
136 void table_format_reset(void);
137 void table_usage(void);