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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_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 */
46const 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 */
57static 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 */
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 */
82
83 /* Success */
84 rc = 0;
85
86 err_unknown:
87 free ( name );
88 return rc;
89}
90
91/** Keyboard map setting applicator */
92struct settings_applicator keymap_applicator __settings_applicator = {
93 .apply = keymap_apply,
94};
95
96/* Provide virtual "dynamic" keyboard map for linker */
97PROVIDE_SYMBOL ( obj_keymap_dynamic );
98
99/* Drag in keyboard maps via keymap_setting */
100REQUIRING_SYMBOL ( keymap_setting );
101
102/* Require all known keyboard maps */
122REQUIRE_KEYMAP ( no_latin1 );
129REQUIRE_KEYMAP ( sr_latin );
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * name
Definition ath9k_hw.c:1986
int nl(void)
#define REQUIRE_KEYMAP(name)
Require a keyboard map.
Definition dynkeymap.c:43
static int keymap_apply(void)
Apply keyboard map settings.
Definition dynkeymap.c:57
Error codes.
#define DBGC(...)
Definition compiler.h:505
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ENOENT
No such file or directory.
Definition errno.h:515
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define SETTING_MISC
Miscellaneous settings.
Definition settings.h:81
#define REQUIRING_SYMBOL(symbol)
Specify the file's requiring symbol.
Definition compiler.h:140
#define PROVIDE_SYMBOL(symbol)
Provide a symbol within this object file.
Definition compiler.h:84
Configuration settings.
#define __setting(setting_order, name)
Declare a configuration setting.
Definition settings.h:57
#define __settings_applicator
Declare a settings applicator.
Definition settings.h:265
void keymap_set(struct keymap *keymap)
Set keyboard map.
Definition keymap.c:122
struct keymap * keymap_find(const char *name)
Find keyboard map by name.
Definition keymap.c:105
Keyboard mappings.
uint32_t es
Definition librm.h:4
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
uint8_t al
Definition registers.h:0
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition settings.c:874
A keyboard mapping.
Definition keymap.h:31
A setting.
Definition settings.h:24
A settings applicator.
Definition settings.h:252