File: table.h

package info (click to toggle)
s390-tools 2.35.0-2
  • links: PTS
  • area: main
  • in suites: forky
  • size: 12,248 kB
  • sloc: ansic: 184,236; sh: 12,152; cpp: 4,954; makefile: 2,763; perl: 2,519; asm: 1,085; python: 697; xml: 29
file content (74 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * zdev - Modify and display the persistent configuration of devices
 *
 * Copyright IBM Corp. 2016, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#ifndef TABLE_H
#define TABLE_H

#include "exit_code.h"

#define COLUMN(a, b, c, d, e) \
	{ \
		.name = (a), \
		.align = (b), \
		.id = (c), \
		.def = (d), \
		.desc = (e), \
	}

#define COLUMN_ARRAY(...) \
	((struct column[]) { __VA_ARGS__, { .name = NULL } })

/* Alignment of table cell text. */
typedef enum {
	align_right,
	align_left,
} align_t;

/**
 * column - Definition of a table column
 * @name: Name of column. A name ending with ':' indicates that it can be
 *        followed by arbitrary text (e.g. ATTR:online)
 * @desc: Description of column
 * @align: Alignment of column values.
 * @id: ID of column. This value is passed to get_value_cb_t
 * @def: If set, include column in default table
 */
struct column {
	const char *name;
	const char *desc;
	align_t align;
	int id;
	unsigned int def:1;
};

struct util_list;

/**
 * table_value_cb_t - Retrieve table cell value
 * @item: Item for which a cell value should be retrieved
 * @id: Column ID of the column to retrieve for the item
 * @heading: The full heading of the column
 * @data: Arbitrary data pointer passed to table_print()
 *
 * This callback function should retrieve the specified table cell value
 * and return it as a newly allocated string to the caller. It may return
 * %NULL if no value of the specified type is defined for the specified item.
 */
typedef char *(*table_value_cb_t)(void *item, int id, const char *heading,
				  void *data);

struct column *table_get_column(struct column *, const char *);
exit_code_t table_print(struct column *, table_value_cb_t, void *,
			struct util_list *, struct util_list *, int, int, int,
			int, int);
exit_code_t table_check_columns(struct column *, struct util_list *);
void table_print_columns(struct column *, struct util_list *, int, int);
void table_set_default(struct column *, int, int);

#endif /* TABLE_H */