/*
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <stdbool.h>
#include <stddef.h>
#include "compiler.h"
+#include "openvswitch/json.h"
+struct ds;
struct table_style;
\f
/* Manipulating tables and their rows and columns. */
size_t n_rows, allocated_rows;
size_t current_column;
char *caption;
+ bool timestamp;
};
void table_init(struct table *);
void table_destroy(struct table *);
void table_set_caption(struct table *, char *caption);
+void table_set_timestamp(struct table *, bool timestamp);
void table_add_column(struct table *, const char *heading, ...)
- PRINTF_FORMAT(2, 3);
+ OVS_PRINTF_FORMAT(2, 3);
void table_add_row(struct table *);
\f
/* Table cells. */
enum cell_format cell_format; /* CF_*. */
bool headings; /* Include headings? */
int json_flags; /* CF_JSON: Flags for json_to_string(). */
+ int max_column_width; /* CF_STRING: Limit for column width. */
};
-#define TABLE_STYLE_DEFAULT { TF_TABLE, CF_STRING, true, JSSF_SORT }
+#define TABLE_STYLE_DEFAULT { TF_LIST, CF_STRING, true, JSSF_SORT, 0 }
+static const struct table_style table_style_default = TABLE_STYLE_DEFAULT;
#define TABLE_OPTION_ENUMS \
OPT_NO_HEADINGS, \
OPT_PRETTY, \
- OPT_BARE
+ OPT_BARE, \
+ OPT_MAX_COLUMN_WIDTH
-#define TABLE_LONG_OPTIONS \
- {"format", required_argument, 0, 'f'}, \
- {"data", required_argument, 0, 'd'}, \
- {"no-headings", no_argument, 0, OPT_NO_HEADINGS}, \
- {"pretty", no_argument, 0, OPT_PRETTY}, \
- {"bare", no_argument, 0, OPT_BARE}
+#define TABLE_LONG_OPTIONS \
+ {"format", required_argument, NULL, 'f'}, \
+ {"data", required_argument, NULL, 'd'}, \
+ {"no-headings", no_argument, NULL, OPT_NO_HEADINGS}, \
+ {"pretty", no_argument, NULL, OPT_PRETTY}, \
+ {"bare", no_argument, NULL, OPT_BARE}, \
+ {"max-column-width", required_argument, NULL, OPT_MAX_COLUMN_WIDTH}
#define TABLE_OPTION_HANDLERS(STYLE) \
case 'f': \
(STYLE)->format = TF_LIST; \
(STYLE)->cell_format = CF_BARE; \
(STYLE)->headings = false; \
+ break; \
+ \
+ case OPT_MAX_COLUMN_WIDTH: \
+ (STYLE)->max_column_width = atoi(optarg); \
break;
void table_parse_format(struct table_style *, const char *format);
void table_parse_cell_format(struct table_style *, const char *format);
void table_print(const struct table *, const struct table_style *);
+void table_format(const struct table *, const struct table_style *,
+ struct ds *);
+void table_format_reset(void);
+void table_usage(void);
#endif /* table.h */