Merge pull request #457 from vivien/text-variable
[tig.git] / tools / doc-gen.c
blob5b8762bd252bd3825edbd4e5d506a03a89ef716d
1 /* Copyright (c) 2006-2015 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include "tig/tig.h"
15 #include "tig/request.h"
16 #include "tig/util.h"
18 struct doc_action_iterator {
19 bool end_group;
20 const char *group;
23 static void
24 doc_action_group_name_print(const char *group)
26 printf("%s\n", group);
27 while (*group++)
28 printf("^");
29 printf("\n\n");
32 static void
33 doc_action_table_print(bool start)
35 if (start)
36 printf("[frame=\"none\",grid=\"none\",cols=\"25<m,75<\"]\n");
37 printf("|=============================================================================\n");
40 static bool
41 doc_action_print(void *data, const struct request_info *req_info, const char *group)
43 struct doc_action_iterator *iterator = data;
45 if (iterator->group != group) {
46 if (iterator->end_group) {
47 doc_action_table_print(false);
48 printf("\n");
51 doc_action_group_name_print(group);
52 doc_action_table_print(true);
54 iterator->group = group;
55 iterator->end_group = true;
58 printf("|%-24s|%s\n", enum_name(req_info->name), req_info->help);
59 return true;
62 static void
63 doc_actions_print(void)
65 struct doc_action_iterator iterator = { false };
67 foreach_request(doc_action_print, &iterator);
68 doc_action_table_print(false);
71 int
72 main(int argc, const char *argv[])
74 int i;
76 for (i = 1; i < argc; i++) {
77 if (!strcmp(argv[i], "actions"))
78 doc_actions_print();
81 return EXIT_SUCCESS;
84 /* vim: set ts=8 sw=8 noexpandtab: */