xref: /freebsd/contrib/less/lesskey.h (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1 /*
2  * Copyright (C) 1984-2024  Mark Nudelman
3  *
4  * You may distribute under the terms of either the GNU General Public
5  * License or the Less License, as specified in the README file.
6  *
7  * For more information, see the README file.
8  */
9 
10 #include "lang.h"
11 #include "xbuf.h"
12 
13 /*
14  * Format of a lesskey file:
15  *
16  *      LESSKEY_MAGIC (4 bytes)
17  *       sections...
18  *      END_LESSKEY_MAGIC (4 bytes)
19  *
20  * Each section is:
21  *
22  *      section_MAGIC (1 byte)
23  *      section_length (2 bytes)
24  *      key table (section_length bytes)
25  */
26 #define C0_LESSKEY_MAGIC        '\0'
27 #define C1_LESSKEY_MAGIC        'M'
28 #define C2_LESSKEY_MAGIC        '+'
29 #define C3_LESSKEY_MAGIC        'G'
30 
31 #define CMD_SECTION             'c'
32 #define EDIT_SECTION            'e'
33 #define VAR_SECTION             'v'
34 #define END_SECTION             'x'
35 
36 #define C0_END_LESSKEY_MAGIC    'E'
37 #define C1_END_LESSKEY_MAGIC    'n'
38 #define C2_END_LESSKEY_MAGIC    'd'
39 
40 /* */
41 #define KRADIX          64
42 
43 struct lesskey_cmdname
44 {
45 	constant char *cn_name;
46 	int cn_action;
47 };
48 
49 struct lesskey_table
50 {
51 	constant struct lesskey_cmdname *names;
52 	struct xbuffer buf;
53 	int is_var;
54 };
55 
56 struct lesskey_tables
57 {
58 	struct lesskey_table *currtable;
59 	struct lesskey_table cmdtable;
60 	struct lesskey_table edittable;
61 	struct lesskey_table vartable;
62 };
63 
64 extern int parse_lesskey(constant char *infile, struct lesskey_tables *tables);
65 extern int parse_lesskey_content(constant char *content, struct lesskey_tables *tables);
66 
67 /* keep in sync with less.h */
68 #if HAVE_SNPRINTF
69 #define SNPRINTF1(str, size, fmt, v1)             snprintf((str), (size), (fmt), (v1))
70 #define SNPRINTF2(str, size, fmt, v1, v2)         snprintf((str), (size), (fmt), (v1), (v2))
71 #define SNPRINTF3(str, size, fmt, v1, v2, v3)     snprintf((str), (size), (fmt), (v1), (v2), (v3))
72 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
73 #else
74 /* Use unsafe sprintf if we don't have snprintf. */
75 #define SNPRINTF1(str, size, fmt, v1)             sprintf((str), (fmt), (v1))
76 #define SNPRINTF2(str, size, fmt, v1, v2)         sprintf((str), (fmt), (v1), (v2))
77 #define SNPRINTF3(str, size, fmt, v1, v2, v3)     sprintf((str), (fmt), (v1), (v2), (v3))
78 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
79 #endif
80