1
/* $Xorg: xmodmap.c,v 1.4 2001/02/09 02:05:56 xorgcvs Exp $ */
4
Copyright 1988, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
29
/* $XFree86: xc/programs/xmodmap/xmodmap.c,v 1.8tsi Exp $ */
38
const char *ProgramName;
40
int min_keycode, max_keycode;
42
Bool dontExecute = False;
55
chk_malloc(size_t n_bytes)
57
void *buf = malloc(n_bytes);
59
fprintf(stderr, "%s: Could not allocate %d bytes\n", ProgramName, (int)n_bytes);
65
static const char help_message[] =
66
"\nwhere options include:\n"
67
" -display host:dpy X server to use\n"
68
" -verbose, -quiet turn logging on or off\n"
69
" -n don't execute changes, just show like make\n"
70
" -e expression execute string\n"
71
" -pm print modifier map\n"
72
" -pk print keymap table\n"
73
" -pke print keymap table as expressions\n"
74
" -pp print pointer map\n"
75
" -grammar print out short help on allowable input\n"
76
" - read standard input\n"
83
fprintf (stderr, "usage: %s [-options ...] [filename]\n", ProgramName);
84
fprintf (stderr, "%s\n", help_message);
88
static const char grammar_message[] =
89
" pointer = default reset pointer buttons to default\n"
90
" pointer = NUMBER ... set pointer button codes\n"
91
" keycode NUMBER = [KEYSYM ...] map keycode to given keysyms\n"
92
" keysym KEYSYM = [KEYSYM ...] look up keysym and do a keycode operation\n"
93
" clear MODIFIER remove all keys for this modifier\n"
94
" add MODIFIER = KEYSYM ... add the keysyms to the modifier\n"
95
" remove MODIFIER = KEYSYM ... remove the keysyms from the modifier\n"
97
"where NUMBER is a decimal, octal, or hex constant; KEYSYM is a valid\n"
98
"Key Symbol name; and MODIFIER is one of the eight modifier names: Shift,\n"
99
"Lock, Control, Mod1, Mod2, Mod3, Mod4, or Mod5. Lines beginning with\n"
100
"an exclamation mark (!) are taken as comments. Case is significant except\n"
101
"for MODIFIER names.\n"
103
"Keysyms on the left hand side of the = sign are looked up before any changes\n"
104
"are made; keysyms on the right are looked up after all of those on the left\n"
105
"have been resolved. This makes it possible to swap modifier keys.\n"
112
fprintf (stderr, "%s accepts the following input expressions:\n\n",
114
fprintf (stderr, "%s\n", grammar_message);
118
int parse_errors = 0;
121
main(int argc, char *argv[])
124
char *displayname = NULL;
126
Bool printMap = False;
127
Bool printKeyTable = False;
128
Bool printKeyTableExprs = False;
129
Bool printPointerMap = False;
130
Bool didAnything = False;
132
ProgramName = argv[0];
135
* scan the arg list once to find out which display to use
138
for (i = 1; i < argc; i++) {
139
if (strncmp (argv[i], "-d", 2) == 0) {
140
if (++i >= argc) usage ();
141
displayname = argv[i];
145
dpy = XOpenDisplay (displayname);
147
fprintf (stderr, "%s: unable to open display '%s'\n",
148
ProgramName, XDisplayName (displayname));
152
XDisplayKeycodes (dpy, &min_keycode, &max_keycode);
157
* scan the arg list again to do the actual work (since it requires
158
* the display being open.
162
for (i = 1; i < argc; i++) {
167
case 'd': /* -display host:dpy */
168
++i; /* handled above */
170
case 'v': /* -verbose */
173
case 'q': /* -quiet */
176
case 'n': /* -n (like make) */
179
case 'e': /* -e expression */
181
if (++i >= argc) usage ();
182
process_line (argv[i]);
184
case 'p': /* -p... */
190
case 'k': /* -pk, -pke */
193
printKeyTable = True;
196
printKeyTableExprs = True;
203
printPointerMap = True;
211
case 'g': /* -grammar */
214
case '\0': /* - (use standard input) */
220
* provide old xmodmap args
224
process_line ("clear shift");
228
process_line ("clear lock");
232
process_line ("clear control");
239
char cmd[11] = "clear modX";
249
if (++i >= argc) usage ();
250
cmd = chk_malloc (strlen ("remove control = ") + strlen (argv[i]) + 1);
251
(void) sprintf (cmd, "remove %s = %s",
252
((arg[1] == 's') ? "shift" :
253
((arg[1] == 'l') ? "lock" :
254
"control")), argv[i]);
262
} else if (arg[0] == '+') { /* old xmodmap args */
271
if (++i >= argc) usage ();
272
cmd = chk_malloc (strlen ("add modX = ") + strlen (argv[i]) + 1);
273
(void) sprintf (cmd, "add mod%c = %s", arg[1], argv[i]);
280
arg[1] = tolower (arg[1]);
281
/* fall through to handler below */
287
if (++i >= argc) usage ();
288
cmd = chk_malloc (strlen ("add control = ") + strlen (argv[i]) + 1);
289
(void) sprintf (cmd, "add %s = %s",
290
((arg[1] == 's') ? "shift" :
291
((arg[1] == 'l') ? "lock" :
292
"control")), argv[i]);
306
/* for compatibility */
307
if (!didAnything) printMap = True;
310
* at this point, the work list has been built and we can view it or
319
if (parse_errors != 0) {
320
fprintf (stderr, "%s: %d error%s encountered, aborting.\n",
321
ProgramName, parse_errors,
322
(parse_errors == 1 ? "" : "s"));
323
status = -1; /* return an error condition */
325
status = execute_work_queue ();
329
print_modifier_map ();
333
print_key_table (False);
336
if (printKeyTableExprs) {
337
print_key_table (True);
340
if (printPointerMap) {
341
print_pointer_map ();
344
Exit (status < 0 ? 1 : 0);