-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowtags.c
77 lines (65 loc) · 1.95 KB
/
showtags.c
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
75
76
/*
* The purpose of this example is to demonstrate how tag information can be
* retrieved and used by an application.
*
* An application can retrieve tags and their types and generate a user
* interface from the intormation at run-time.
*/
#include <stdio.h>
#include <footag/footag.h>
#define IND " "
#define SEPARATOR \
"--------------------------------------------------------------------------"
static void prettytagdesc(int tag, const char *crit)
{
const struct footag_desc *desc = &FOOTAG_DESC[tag];
int type = desc->type;
printf(
IND "%-11s %-8s %-11s %s\n",
desc->name,
crit,
FOOTAG_TYPE_STRING[type],
desc->desc
);
}
static void prettyheader(void)
{
puts(IND SEPARATOR);
printf(
IND "%-11s %-8s %-11s %s\n",
"FOOTAG_",
"REQ/OPT",
"TYPE",
"DESC"
);
puts(IND SEPARATOR);
}
static void showinfo(const struct footag_info *info)
{
printf("=== %s: %s ===\n", info->tname, info->brief);
prettyheader();
for (int *t = info->req; *t != FOOTAG_END; t++) {
prettytagdesc(*t, "required");
}
for (int *t = info->opt; *t != FOOTAG_END; t++) {
prettytagdesc(*t, "optional");
}
puts("");
}
int main(void)
{
const struct footag_info *head;
printf("This program prints footprint types available in Footag.\n\n");
head = footag_getinfo();
for (const struct footag_info *info = head; info; info = info->next) {
showinfo(info);
}
printf("\nThe following tags are always optional:\n");
prettyheader();
const int *opt = footag_getalwaysopt();
for (const int *t = opt; *t != FOOTAG_END; t++) {
prettytagdesc(*t, "optional");
}
puts("");
return 0;
}