NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dump.c File Reference

Dump key bindings. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "pager/lib.h"
#include "parse/lib.h"
+ Include dependency graph for dump.c:

Go to the source code of this file.

Functions

static int print_bind (enum MenuType menu, FILE *fp)
 Display the bindings for one menu.
 
static void colon_bind (enum MenuType menu, FILE *fp)
 Dump the key bindings.
 
static int print_macro (enum MenuType menu, FILE *fp)
 Display the macros for one menu.
 
static void colon_macro (enum MenuType menu, FILE *fp)
 Dump the macros.
 
enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse 'bind' and 'macro' commands - Implements Command::parse() -.
 

Detailed Description

Dump key bindings.

Authors
  • Richard Russon
  • Dennis Schön

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file dump.c.

Function Documentation

◆ print_bind()

static int print_bind ( enum MenuType  menu,
FILE *  fp 
)
static

Display the bindings for one menu.

Parameters
menuMenu type
fpFile to write to
Return values
numNumber of bindings

Definition at line 47 of file dump.c.

48{
49 struct BindingInfoArray bia_bind = ARRAY_HEAD_INITIALIZER;
50
51 gather_menu(menu, &bia_bind, NULL);
52 if (ARRAY_EMPTY(&bia_bind))
53 return 0;
54
55 ARRAY_SORT(&bia_bind, binding_sort, NULL);
56 const int wb0 = measure_column(&bia_bind, 0);
57 const int wb1 = measure_column(&bia_bind, 1);
58
59 const char *menu_name = mutt_map_get_name(menu, MenuNames);
60
61 struct BindingInfo *bi = NULL;
62 ARRAY_FOREACH(bi, &bia_bind)
63 {
64 //XXX use description?
65 fprintf(fp, "bind %s %*s %*s # %s\n", menu_name, -wb0, bi->a[0], -wb1,
66 bi->a[1], bi->a[2]);
67 }
68
69 const int count = ARRAY_SIZE(&bia_bind);
70 ARRAY_FOREACH(bi, &bia_bind)
71 {
72 // we only need to free the keybinding
73 FREE(&bi->a[0]);
74 }
75
76 return count;
77}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:335
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:214
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
int binding_sort(const void *a, const void *b, void *sdata)
Compare two BindingInfo by their keybinding - Implements sort_t -.
Definition: lib.c:405
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition: lib.c:419
void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
Gather info about one menu.
Definition: lib.c:624
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define FREE(x)
Definition: memory.h:55
Info about one keybinding.
Definition: lib.h:94
const char * a[3]
Array of info.
Definition: lib.h:95
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colon_bind()

static void colon_bind ( enum MenuType  menu,
FILE *  fp 
)
static

Dump the key bindings.

Parameters
menuMenu type
fpFile to write to

Definition at line 84 of file dump.c.

85{
86 if (menu == MENU_MAX)
87 {
88 for (enum MenuType i = 1; i < MENU_MAX; i++)
89 {
90 print_bind(i, fp);
91
92 //XXX need to elide last blank line
93 fprintf(fp, "\n");
94 }
95 }
96 else
97 {
98 print_bind(menu, fp);
99 }
100}
static int print_bind(enum MenuType menu, FILE *fp)
Display the bindings for one menu.
Definition: dump.c:47
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_MAX
Definition: type.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_macro()

static int print_macro ( enum MenuType  menu,
FILE *  fp 
)
static

Display the macros for one menu.

Parameters
menuMenu type
fpFile to write to
Return values
numNumber of macros

Definition at line 108 of file dump.c.

109{
110 struct BindingInfoArray bia_macro = ARRAY_HEAD_INITIALIZER;
111
112 gather_menu(menu, NULL, &bia_macro);
113 if (ARRAY_EMPTY(&bia_macro))
114 return 0;
115
116 ARRAY_SORT(&bia_macro, binding_sort, NULL);
117 const int wm0 = measure_column(&bia_macro, 0);
118
119 const char *menu_name = mutt_map_get_name(menu, MenuNames);
120
121 struct BindingInfo *bi = NULL;
122 ARRAY_FOREACH(bi, &bia_macro)
123 {
124 if (bi->a[2]) // description
125 {
126 fprintf(fp, "macro %s %*s \"%s\" \"%s\"\n", menu_name, -wm0, bi->a[0],
127 bi->a[1], bi->a[2]);
128 }
129 else
130 {
131 fprintf(fp, "macro %s %*s \"%s\"\n", menu_name, -wm0, bi->a[0], bi->a[1]);
132 }
133 }
134
135 const int count = ARRAY_SIZE(&bia_macro);
136 ARRAY_FOREACH(bi, &bia_macro)
137 {
138 // free the keybinding and the macro text
139 FREE(&bi->a[0]);
140 FREE(&bi->a[1]);
141 }
142
143 ARRAY_FREE(&bia_macro);
144 return count;
145}
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colon_macro()

static void colon_macro ( enum MenuType  menu,
FILE *  fp 
)
static

Dump the macros.

Parameters
menuMenu type
fpFile to write to

Definition at line 152 of file dump.c.

153{
154 if (menu == MENU_MAX)
155 {
156 for (enum MenuType i = 1; i < MENU_MAX; i++)
157 {
158 if (print_macro(i, fp) > 0)
159 {
160 //XXX need to elide last blank line
161 fprintf(fp, "\n");
162 }
163 }
164 }
165 else
166 {
167 print_macro(menu, fp);
168 }
169}
static int print_macro(enum MenuType menu, FILE *fp)
Display the macros for one menu.
Definition: dump.c:108
+ Here is the call graph for this function:
+ Here is the caller graph for this function: