4 #include "commands/cmd.h"
7 #define CMD_ARR_STACK_SIZE 4
10 SHORT_HELP, /* One line per command */
11 FULL_HELP, /* One line and long desc for all commands */
12 WIKI_HELP, /* Wiki-formated help for all commands */
13 COMMAND_HELP, /* One line and long desc for a specific command */
16 void print_one_line(const cmd_des_t *des)
18 printf("%s - %s\n", des->name, des->help);
21 void print_long(const cmd_des_t *des)
24 printf("%s", des->long_help);
27 void print_wiki(const cmd_des_t *des)
29 printf("## %s ##\n", des->name);
30 printf("%s\n", des->help);
31 printf("%s", des->long_help);
34 static int cmp_des(const void *p1, const void *p2)
36 const cmd_des_t *const *c1 = p1, *const *c2 = p2;
38 return strcmp((*c1)->name, (*c2)->name);
42 int main(int argc, char *argv[])
45 const cmd_des_t **des_arr = cmd_list_main;
46 cmd_des_t const **arr_stack[CMD_ARR_STACK_SIZE];
48 enum disp_mode mode = SHORT_HELP;
51 const cmd_des_t *sorted_des[LEN];
55 if (strcmp(argv[1], "full") == 0)
57 else if (strcmp(argv[1], "wiki") == 0) {
59 printf("This page is generated automatically by " __FILE__ " and is valid for version ");
61 system("git describe --always");
64 else if (strcmp(argv[1], "pdfdoc") == 0) {
75 if (!arr_stack_sp) break;
76 des_arr = arr_stack[--arr_stack_sp];
79 if (des == CMD_DES_CONTINUE_AT_ID) {
80 /* list continues at new address */
81 des_arr = (const cmd_des_t **)*des_arr;
84 if (des == CMD_DES_INCLUDE_SUBLIST_ID) {
85 /* list includes commands from sublists */
86 if (arr_stack_sp >= CMD_ARR_STACK_SIZE)
89 arr_stack[arr_stack_sp++] = des_arr+1;
90 des_arr = (const cmd_des_t **)*des_arr;
95 sorted_des[num++] = des;
98 qsort(sorted_des, num, sizeof(*sorted_des), cmp_des);
100 for (int i = 0; i < num; i++) {
114 if (strcmp(argv[1], des->name) == 0)