iPXE
dynkeymap.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * Dynamic keyboard mappings
29  *
30  */
31 
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <ipxe/settings.h>
35 #include <ipxe/keymap.h>
36 
37 /**
38  * Require a keyboard map
39  *
40  * @v name Keyboard map name
41  */
42 #define REQUIRE_KEYMAP( name ) REQUIRE_OBJECT ( keymap_ ## name )
43 
44 /** Keyboard map setting */
45 const struct setting keymap_setting __setting ( SETTING_MISC, keymap ) = {
46  .name = "keymap",
47  .description = "Keyboard map",
48  .type = &setting_type_string,
49 };
50 
51 /**
52  * Apply keyboard map settings
53  *
54  * @ret rc Return status code
55  */
56 static int keymap_apply ( void ) {
57  struct keymap *keymap;
58  char *name;
59  int rc;
60 
61  /* Fetch keyboard map name */
62  fetch_string_setting_copy ( NULL, &keymap_setting, &name );
63 
64  /* Identify keyboard map */
65  if ( name ) {
66  /* Identify named keyboard map */
67  keymap = keymap_find ( name );
68  if ( ! keymap ) {
69  DBGC ( &keymap_setting, "KEYMAP could not identify "
70  "\"%s\"\n", name );
71  rc = -ENOENT;
72  goto err_unknown;
73  }
74  } else {
75  /* Use default keyboard map */
76  keymap = NULL;
77  }
78 
79  /* Set keyboard map */
80  keymap_set ( keymap );
81 
82  /* Success */
83  rc = 0;
84 
85  err_unknown:
86  free ( name );
87  return rc;
88 }
89 
90 /** Keyboard map setting applicator */
91 struct settings_applicator keymap_applicator __settings_applicator = {
93 };
94 
95 /* Provide virtual "dynamic" keyboard map for linker */
96 PROVIDE_SYMBOL ( obj_keymap_dynamic );
97 
98 /* Drag in keyboard maps via keymap_setting */
99 REQUIRING_SYMBOL ( keymap_setting );
100 
101 /* Require all known keyboard maps */
102 REQUIRE_KEYMAP ( al );
103 REQUIRE_KEYMAP ( by );
104 REQUIRE_KEYMAP ( cf );
105 REQUIRE_KEYMAP ( cz );
106 REQUIRE_KEYMAP ( de );
107 REQUIRE_KEYMAP ( dk );
108 REQUIRE_KEYMAP ( es );
109 REQUIRE_KEYMAP ( et );
110 REQUIRE_KEYMAP ( fi );
111 REQUIRE_KEYMAP ( fr );
112 REQUIRE_KEYMAP ( gr );
113 REQUIRE_KEYMAP ( hu );
114 REQUIRE_KEYMAP ( il );
115 REQUIRE_KEYMAP ( it );
116 REQUIRE_KEYMAP ( lt );
117 REQUIRE_KEYMAP ( mk );
118 REQUIRE_KEYMAP ( mt );
119 REQUIRE_KEYMAP ( nl );
120 REQUIRE_KEYMAP ( no );
121 REQUIRE_KEYMAP ( no_latin1 );
122 REQUIRE_KEYMAP ( pl );
123 REQUIRE_KEYMAP ( pt );
124 REQUIRE_KEYMAP ( ro );
125 REQUIRE_KEYMAP ( ru );
126 REQUIRE_KEYMAP ( se );
127 REQUIRE_KEYMAP ( sg );
128 REQUIRE_KEYMAP ( sr_latin );
129 REQUIRE_KEYMAP ( ua );
130 REQUIRE_KEYMAP ( uk );
131 REQUIRE_KEYMAP ( us );
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
Keyboard mappings.
struct settings_applicator keymap_applicator __settings_applicator
Keyboard map setting applicator.
Definition: dynkeymap.c:91
#define REQUIRE_KEYMAP(name)
Require a keyboard map.
Definition: dynkeymap.c:42
const struct setting keymap_setting __setting(SETTING_MISC, keymap)
Keyboard map setting.
uint32_t es
Definition: librm.h:253
Error codes.
PROVIDE_SYMBOL(obj_keymap_dynamic)
#define DBGC(...)
Definition: compiler.h:505
REQUIRING_SYMBOL(keymap_setting)
#define ENOENT
No such file or directory.
Definition: errno.h:514
static int keymap_apply(void)
Apply keyboard map settings.
Definition: dynkeymap.c:56
A settings applicator.
Definition: settings.h:251
#define SETTING_MISC
Miscellaneous settings.
Definition: settings.h:80
const char * name
Name.
Definition: settings.h:28
uint8_t al
Definition: registers.h:84
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:873
Configuration settings.
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A setting.
Definition: settings.h:23
void keymap_set(struct keymap *keymap)
Set keyboard map.
Definition: keymap.c:121
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct keymap * keymap_find(const char *name)
Find keyboard map by name.
Definition: keymap.c:104
int(* apply)(void)
Apply updated settings.
Definition: settings.h:256
A keyboard mapping.
Definition: keymap.h:30
int nl(void)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321