Skip to content

Commit 9d7b11f

Browse files
authored
Merge pull request systemd#17395 from keszybz/hwdb-drop-quotes
hwdb: drop quotes from XKB_FIXED_*= properties
2 parents aa5502b + 327d8f3 commit 9d7b11f

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

hwdb.d/60-keyboard.hwdb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@
7272

7373
# A device with a fixed keyboard layout that must not be changed by
7474
# the desktop environment may specify that layout as:
75-
# XKB_FIXED_LAYOUT="us"
76-
# XKB_FIXED_VARIANT=""
75+
# XKB_FIXED_LAYOUT=us
76+
# XKB_FIXED_VARIANT=
7777
# Examples of such devices: the Yubikey or other key-code generating
7878
# devices.
7979

8080
# A device where the scan code to key code mapping is insufficient and
8181
# requires a special key code to symbol configuration may specify that with:
82-
# XKB_FIXED_MODEL="xkbmodel"
82+
# XKB_FIXED_MODEL=xkbmodel
8383
# Examples of such devices: Chromebooks where the top row is used for both
8484
# media and F1-F10 keys.
8585

@@ -1796,8 +1796,8 @@ evdev:input:b0003v1050p0111:*
17961796
evdev:input:b0003v1050p0116:*
17971797
# OKE Electron Company USB barcode reader
17981798
evdev:input:b0003v05FEp1010:*
1799-
XKB_FIXED_LAYOUT="us"
1800-
XKB_FIXED_VARIANT=""
1799+
XKB_FIXED_LAYOUT=us
1800+
XKB_FIXED_VARIANT=
18011801

18021802
######################### LACK OF MODIFIER LEDS ############################
18031803
# This section lists keyboard which do not have their own LEDs for some
@@ -1846,4 +1846,4 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnLENOVO:pn*:pvrThinkPadX1Carbon3rd:*
18461846
# Chromebooks
18471847
evdev:atkbd:dmi:bvn*:bvr*:bd*:svnHewlett-Packard*:pnFalco:*
18481848
evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pnPeppy:*
1849-
XKB_FIXED_MODEL="chromebook"
1849+
XKB_FIXED_MODEL=chromebook

hwdb.d/parse_hwdb.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from pyparsing import (Word, White, Literal, ParserElement, Regex, LineEnd,
3333
OneOrMore, Combine, Or, Optional, Suppress, Group,
3434
nums, alphanums, printables,
35-
stringEnd, pythonStyleComment, QuotedString,
35+
stringEnd, pythonStyleComment,
3636
ParseBaseException)
3737
except ImportError:
3838
print('pyparsing is not available')
@@ -54,7 +54,6 @@
5454
EMPTYLINE = LineEnd()
5555
COMMENTLINE = pythonStyleComment + EOL
5656
INTEGER = Word(nums)
57-
STRING = QuotedString('"')
5857
REAL = Combine((INTEGER + Optional('.' + Optional(INTEGER))) ^ ('.' + INTEGER))
5958
SIGNED_REAL = Combine(Optional(Word('-+')) + REAL)
6059
UDEV_TAG = Word(string.ascii_uppercase, alphanums + '_')
@@ -94,7 +93,8 @@ def hwdb_grammar():
9493
matchline = (matchline_typed | matchline_general) + EOL
9594

9695
propertyline = (White(' ', exact=1).suppress() +
97-
Combine(UDEV_TAG - '=' - Word(alphanums + '_=:@*.!-;, "') - Optional(pythonStyleComment)) +
96+
Combine(UDEV_TAG - '=' - Optional(Word(alphanums + '_=:@*.!-;, "'))
97+
- Optional(pythonStyleComment)) +
9898
EOL)
9999
propertycomment = White(' ', exact=1) + pythonStyleComment + EOL
100100

@@ -114,6 +114,7 @@ def property_grammar():
114114
dpi_setting = (Optional('*')('DEFAULT') + INTEGER('DPI') + Suppress('@') + INTEGER('HZ'))('SETTINGS*')
115115
mount_matrix_row = SIGNED_REAL + ',' + SIGNED_REAL + ',' + SIGNED_REAL
116116
mount_matrix = (mount_matrix_row + ';' + mount_matrix_row + ';' + mount_matrix_row)('MOUNT_MATRIX')
117+
xkb_setting = Optional(Word(alphanums + '+-/@._'))
117118

118119
props = (('MOUSE_DPI', Group(OneOrMore(dpi_setting))),
119120
('MOUSE_WHEEL_CLICK_ANGLE', INTEGER),
@@ -138,9 +139,9 @@ def property_grammar():
138139
('POINTINGSTICK_CONST_ACCEL', REAL),
139140
('ID_INPUT_JOYSTICK_INTEGRATION', Or(('internal', 'external'))),
140141
('ID_INPUT_TOUCHPAD_INTEGRATION', Or(('internal', 'external'))),
141-
('XKB_FIXED_LAYOUT', STRING),
142-
('XKB_FIXED_VARIANT', STRING),
143-
('XKB_FIXED_MODEL', STRING),
142+
('XKB_FIXED_LAYOUT', xkb_setting),
143+
('XKB_FIXED_VARIANT', xkb_setting),
144+
('XKB_FIXED_MODEL', xkb_setting),
144145
('KEYBOARD_LED_NUMLOCK', Literal('0')),
145146
('KEYBOARD_LED_CAPSLOCK', Literal('0')),
146147
('ACCEL_MOUNT_MATRIX', mount_matrix),

src/libsystemd/sd-hwdb/hwdb-util.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ static struct trie_node *node_lookup(const struct trie_node *node, uint8_t c) {
105105
}
106106

107107
static void trie_node_cleanup(struct trie_node *node) {
108-
size_t i;
109-
110108
if (!node)
111109
return;
112110

113-
for (i = 0; i < node->children_count; i++)
111+
for (size_t i = 0; i < node->children_count; i++)
114112
trie_node_cleanup(node->children[i].child);
115113
free(node->children);
116114
free(node->values);
@@ -191,10 +189,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
191189
static int trie_insert(struct trie *trie, struct trie_node *node, const char *search,
192190
const char *key, const char *value,
193191
const char *filename, uint16_t file_priority, uint32_t line_number, bool compat) {
194-
size_t i = 0;
195192
int r = 0;
196193

197-
for (;;) {
194+
for (size_t i = 0;; i++) {
198195
size_t p;
199196
uint8_t c;
200197
struct trie_node *child;
@@ -273,7 +270,6 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
273270
}
274271

275272
node = child;
276-
i++;
277273
}
278274
}
279275

@@ -289,20 +285,17 @@ struct trie_f {
289285

290286
/* calculate the storage space for the nodes, children arrays, value arrays */
291287
static void trie_store_nodes_size(struct trie_f *trie, struct trie_node *node, bool compat) {
292-
uint64_t i;
293-
294-
for (i = 0; i < node->children_count; i++)
288+
for (uint64_t i = 0; i < node->children_count; i++)
295289
trie_store_nodes_size(trie, node->children[i].child, compat);
296290

297291
trie->strings_off += sizeof(struct trie_node_f);
298-
for (i = 0; i < node->children_count; i++)
292+
for (uint64_t i = 0; i < node->children_count; i++)
299293
trie->strings_off += sizeof(struct trie_child_entry_f);
300-
for (i = 0; i < node->values_count; i++)
294+
for (uint64_t i = 0; i < node->values_count; i++)
301295
trie->strings_off += compat ? sizeof(struct trie_value_entry_f) : sizeof(struct trie_value_entry2_f);
302296
}
303297

304298
static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, bool compat) {
305-
uint64_t i;
306299
struct trie_node_f n = {
307300
.prefix_off = htole64(trie->strings_off + node->prefix_off),
308301
.children_count = node->children_count,
@@ -318,7 +311,7 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, boo
318311
}
319312

320313
/* post-order recursion */
321-
for (i = 0; i < node->children_count; i++) {
314+
for (uint64_t i = 0; i < node->children_count; i++) {
322315
int64_t child_off;
323316

324317
child_off = trie_store_nodes(trie, node->children[i].child, compat);
@@ -343,7 +336,7 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, boo
343336
}
344337

345338
/* append values array */
346-
for (i = 0; i < node->values_count; i++) {
339+
for (uint64_t i = 0; i < node->values_count; i++) {
347340
struct trie_value_entry2_f v = {
348341
.key_off = htole64(trie->strings_off + node->values[i].key_off),
349342
.value_off = htole64(trie->strings_off + node->values[i].value_off),
@@ -447,7 +440,7 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c
447440
value = strchr(line, '=');
448441
if (!value)
449442
return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
450-
"Key-value pair expected but got \"%s\", ignoring", line);
443+
"Key-value pair expected but got \"%s\", ignoring.", line);
451444

452445
value[0] = '\0';
453446
value++;
@@ -456,10 +449,9 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c
456449
while (isblank(line[0]) && isblank(line[1]))
457450
line++;
458451

459-
if (isempty(line + 1) || isempty(value))
452+
if (isempty(line + 1))
460453
return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
461-
"Empty %s in \"%s=%s\", ignoring",
462-
isempty(line + 1) ? "key" : "value",
454+
"Empty key in \"%s=%s\", ignoring.",
463455
line, value);
464456

465457
STRV_FOREACH(entry, match_list)
@@ -494,7 +486,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
494486
if (r == 0)
495487
break;
496488

497-
++line_number;
489+
line_number ++;
498490

499491
/* comment line */
500492
if (line[0] == '#')
@@ -518,7 +510,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
518510

519511
if (line[0] == ' ') {
520512
r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
521-
"Match expected but got indented property \"%s\", ignoring line", line);
513+
"Match expected but got indented property \"%s\", ignoring line.", line);
522514
break;
523515
}
524516

@@ -534,7 +526,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
534526
case HW_MATCH:
535527
if (len == 0) {
536528
r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
537-
"Property expected, ignoring record with no properties");
529+
"Property expected, ignoring record with no properties.");
538530
state = HW_NONE;
539531
match_list = strv_free(match_list);
540532
break;
@@ -566,7 +558,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
566558

567559
if (line[0] != ' ') {
568560
r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
569-
"Property or empty line expected, got \"%s\", ignoring record", line);
561+
"Property or empty line expected, got \"%s\", ignoring record.", line);
570562
state = HW_NONE;
571563
match_list = strv_free(match_list);
572564
break;
@@ -581,7 +573,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
581573

582574
if (state == HW_MATCH)
583575
log_syntax(NULL, LOG_WARNING, filename, line_number, 0,
584-
"Property expected, ignoring record with no properties");
576+
"Property expected, ignoring record with no properties.");
585577

586578
return r;
587579
}

0 commit comments

Comments
 (0)