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 FILE_SECBOOT ( PERMITTED );
26 
27 /** @file
28  *
29  * Dynamic keyboard mappings
30  *
31  */
32 
33 #include <stdlib.h>
34 #include <errno.h>
35 #include <ipxe/settings.h>
36 #include <ipxe/keymap.h>
37 
38 /**
39  * Require a keyboard map
40  *
41  * @v name Keyboard map name
42  */
43 #define REQUIRE_KEYMAP( name ) REQUIRE_OBJECT ( keymap_ ## name )
44 
45 /** Keyboard map setting */
46 const struct setting keymap_setting __setting ( SETTING_MISC, keymap ) = {
47  .name = "keymap",
48  .description = "Keyboard map",
49  .type = &setting_type_string,
50 };
51 
52 /**
53  * Apply keyboard map settings
54  *
55  * @ret rc Return status code
56  */
57 static int keymap_apply ( void ) {
58  struct keymap *keymap;
59  char *name;
60  int rc;
61 
62  /* Fetch keyboard map name */
63  fetch_string_setting_copy ( NULL, &keymap_setting, &name );
64 
65  /* Identify keyboard map */
66  if ( name ) {
67  /* Identify named keyboard map */
68  keymap = keymap_find ( name );
69  if ( ! keymap ) {
70  DBGC ( &keymap_setting, "KEYMAP could not identify "
71  "\"%s\"\n", name );
72  rc = -ENOENT;
73  goto err_unknown;
74  }
75  } else {
76  /* Use default keyboard map */
77  keymap = NULL;
78  }
79 
80  /* Set keyboard map */
81  keymap_set ( keymap );
82 
83  /* Success */
84  rc = 0;
85 
86  err_unknown:
87  free ( name );
88  return rc;
89 }
90 
91 /** Keyboard map setting applicator */
92 struct settings_applicator keymap_applicator __settings_applicator = {
94 };
95 
96 /* Provide virtual "dynamic" keyboard map for linker */
97 PROVIDE_SYMBOL ( obj_keymap_dynamic );
98 
99 /* Drag in keyboard maps via keymap_setting */
100 REQUIRING_SYMBOL ( keymap_setting );
101 
102 /* Require all known keyboard maps */
103 REQUIRE_KEYMAP ( al );
104 REQUIRE_KEYMAP ( by );
105 REQUIRE_KEYMAP ( cf );
106 REQUIRE_KEYMAP ( cz );
107 REQUIRE_KEYMAP ( de );
108 REQUIRE_KEYMAP ( dk );
109 REQUIRE_KEYMAP ( es );
110 REQUIRE_KEYMAP ( et );
111 REQUIRE_KEYMAP ( fi );
112 REQUIRE_KEYMAP ( fr );
113 REQUIRE_KEYMAP ( gr );
114 REQUIRE_KEYMAP ( hu );
115 REQUIRE_KEYMAP ( il );
116 REQUIRE_KEYMAP ( it );
117 REQUIRE_KEYMAP ( lt );
118 REQUIRE_KEYMAP ( mk );
119 REQUIRE_KEYMAP ( mt );
120 REQUIRE_KEYMAP ( nl );
121 REQUIRE_KEYMAP ( no );
122 REQUIRE_KEYMAP ( no_latin1 );
123 REQUIRE_KEYMAP ( pl );
124 REQUIRE_KEYMAP ( pt );
125 REQUIRE_KEYMAP ( ro );
126 REQUIRE_KEYMAP ( ru );
127 REQUIRE_KEYMAP ( se );
128 REQUIRE_KEYMAP ( sg );
129 REQUIRE_KEYMAP ( sr_latin );
130 REQUIRE_KEYMAP ( ua );
131 REQUIRE_KEYMAP ( uk );
132 REQUIRE_KEYMAP ( us );
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
Keyboard mappings.
struct settings_applicator keymap_applicator __settings_applicator
Keyboard map setting applicator.
Definition: dynkeymap.c:92
#define REQUIRE_KEYMAP(name)
Require a keyboard map.
Definition: dynkeymap.c:43
const struct setting keymap_setting __setting(SETTING_MISC, keymap)
Keyboard map setting.
uint32_t es
Definition: librm.h:139
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:515
static int keymap_apply(void)
Apply keyboard map settings.
Definition: dynkeymap.c:57
A settings applicator.
Definition: settings.h:252
#define SETTING_MISC
Miscellaneous settings.
Definition: settings.h:81
const char * name
Name.
Definition: settings.h:29
FILE_SECBOOT(PERMITTED)
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:874
Configuration settings.
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A setting.
Definition: settings.h:24
void keymap_set(struct keymap *keymap)
Set keyboard map.
Definition: keymap.c:122
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct keymap * keymap_find(const char *name)
Find keyboard map by name.
Definition: keymap.c:105
int(* apply)(void)
Apply updated settings.
Definition: settings.h:257
A keyboard mapping.
Definition: keymap.h:31
int nl(void)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322