Gentoo Archives: gentoo-commits

From: Alexandre Restovtsev <tetromino@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/openrc-settingsd:master commit in: src/
Date: Mon, 19 Mar 2012 02:05:37
Message-Id: 1332122681.04e58bfae74958fd2f37afc8304ed32668840965.tetromino@gentoo
1 commit: 04e58bfae74958fd2f37afc8304ed32668840965
2 Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
3 AuthorDate: Mon Mar 19 02:04:41 2012 +0000
4 Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
5 CommitDate: Mon Mar 19 02:04:41 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=04e58bfa
7
8 Fix xorg.conf.d parsing
9
10 ---
11 src/localed.c | 88 +++++++++++++++++++++++++++++++++++++++++++++-----------
12 1 files changed, 70 insertions(+), 18 deletions(-)
13
14 diff --git a/src/localed.c b/src/localed.c
15 index 0dc8765..706a8ed 100644
16 --- a/src/localed.c
17 +++ b/src/localed.c
18 @@ -190,6 +190,20 @@ xorg_confd_line_entry_free (struct xorg_confd_line_entry *entry)
19 g_free (entry);
20 }
21
22 +/* Note that string and value are not duplicated */
23 +static struct xorg_confd_line_entry *
24 +xorg_confd_line_entry_new (const gchar *string,
25 + const gchar *value,
26 + enum XORG_CONFD_LINE_TYPE type)
27 +{
28 + struct xorg_confd_line_entry *entry;
29 +
30 + entry = g_new0 (struct xorg_confd_line_entry, 1);
31 + entry->string = g_strdup (string);
32 + entry->value = g_strdup (value);
33 + entry->type = type;
34 +}
35 +
36 static void
37 xorg_confd_parser_free (struct xorg_confd_parser *parser)
38 {
39 @@ -239,9 +253,7 @@ xorg_confd_parser_new (GFile *xorg_confd_file,
40 GMatchInfo *match_info = NULL;
41 gboolean matched = FALSE;
42
43 - entry = g_new0 (struct xorg_confd_line_entry, 1);
44 - entry->string = *linebuf;
45 - entry->type = XORG_CONFD_LINE_TYPE_UNKNOWN;
46 + entry = xorg_confd_line_entry_new (*linebuf, NULL, XORG_CONFD_LINE_TYPE_UNKNOWN);
47
48 if (g_regex_match (xorg_confd_line_comment_re, *linebuf, 0, &match_info)) {
49 g_debug ("Parsed line '%s' as comment", *linebuf);
50 @@ -330,6 +342,7 @@ xorg_confd_parser_new (GFile *xorg_confd_file,
51
52 out:
53 g_free (filebuf);
54 + g_strfreev (lines);
55 return parser;
56
57 parse_fail:
58 @@ -414,7 +427,7 @@ xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
59 const gchar *variant,
60 const gchar *options)
61 {
62 - GList *curr = NULL;
63 + GList *curr = NULL, *end = NULL;
64 gboolean layout_found = FALSE, model_found = FALSE, variant_found = FALSE, options_found = FALSE;
65
66 if (parser == NULL)
67 @@ -424,19 +437,16 @@ xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
68 struct xorg_confd_line_entry *entry = NULL;
69 GList *section = NULL;
70
71 - entry = g_new0 (struct xorg_confd_line_entry, 1);
72 - entry->string = g_strdup("Section \"InputClass\"\n");
73 - entry->type = XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS;
74 + entry = xorg_confd_line_entry_new ("Section \"InputClass\"\n", NULL, XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS);
75 + section = g_list_prepend (section, entry);
76 +
77 + entry = xorg_confd_line_entry_new (" Identifier \"keyboard-all\"\n", NULL, XORG_CONFD_LINE_TYPE_UNKNOWN);
78 section = g_list_prepend (section, entry);
79
80 - entry = g_new0 (struct xorg_confd_line_entry, 1);
81 - entry->string = g_strdup("MatchIsKeyboard \"on\"\n");
82 - entry->type = XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD;
83 + entry = entry = xorg_confd_line_entry_new (" MatchIsKeyboard \"on\"\n", NULL, XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD);
84 section = g_list_prepend (section, entry);
85
86 - entry = g_new0 (struct xorg_confd_line_entry, 1);
87 - entry->string = g_strdup("EndSection\n");
88 - entry->type = XORG_CONFD_LINE_TYPE_END_SECTION;
89 + entry = entry = xorg_confd_line_entry_new ("EndSection\n", NULL, XORG_CONFD_LINE_TYPE_END_SECTION);
90 section = g_list_prepend (section, entry);
91
92 section = g_list_reverse (section);
93 @@ -447,16 +457,58 @@ xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
94 for (curr = parser->section; curr != NULL; curr = curr->next) {
95 struct xorg_confd_line_entry *entry = (struct xorg_confd_line_entry *) curr->data;
96
97 - if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION)
98 + if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION) {
99 + end = curr;
100 break;
101 - else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_LAYOUT)
102 + } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_LAYOUT) {
103 + layout_found = TRUE;
104 curr = xorg_confd_parser_line_set_or_delete (curr, layout, xorg_confd_line_xkb_layout_re);
105 - else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_MODEL)
106 + } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_MODEL) {
107 + model_found = TRUE;
108 curr = xorg_confd_parser_line_set_or_delete (curr, model, xorg_confd_line_xkb_model_re);
109 - else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_VARIANT)
110 + } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_VARIANT) {
111 + variant_found = TRUE;
112 curr = xorg_confd_parser_line_set_or_delete (curr, variant, xorg_confd_line_xkb_variant_re);
113 - else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_OPTIONS)
114 + } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_OPTIONS) {
115 + options_found = TRUE;
116 curr = xorg_confd_parser_line_set_or_delete (curr, options, xorg_confd_line_xkb_options_re);
117 + }
118 + }
119 + if (!layout_found && layout != NULL && g_strcmp0 (layout, "")) {
120 + struct xorg_confd_line_entry *entry;
121 + gchar *string;
122 +
123 + string = g_strdup_printf (" Option \"XkbLayout\" \"%s\"", layout);
124 + entry = xorg_confd_line_entry_new (string, layout, XORG_CONFD_LINE_TYPE_XKB_LAYOUT);
125 + parser->line_list = g_list_insert_before (parser->line_list, end, entry);
126 + g_free (string);
127 + }
128 + if (!model_found && model != NULL && g_strcmp0 (model, "")) {
129 + struct xorg_confd_line_entry *entry;
130 + gchar *string;
131 +
132 + string = g_strdup_printf (" Option \"XkbModel\" \"%s\"", model);
133 + entry = xorg_confd_line_entry_new (string, model, XORG_CONFD_LINE_TYPE_XKB_MODEL);
134 + parser->line_list = g_list_insert_before (parser->line_list, end, entry);
135 + g_free (string);
136 + }
137 + if (!variant_found && variant != NULL && g_strcmp0 (variant, "")) {
138 + struct xorg_confd_line_entry *entry;
139 + gchar *string;
140 +
141 + string = g_strdup_printf (" Option \"XkbVariant\" \"%s\"", variant);
142 + entry = xorg_confd_line_entry_new (string, variant, XORG_CONFD_LINE_TYPE_XKB_VARIANT);
143 + parser->line_list = g_list_insert_before (parser->line_list, end, entry);
144 + g_free (string);
145 + }
146 + if (!options_found && options != NULL && g_strcmp0 (options, "")) {
147 + struct xorg_confd_line_entry *entry;
148 + gchar *string;
149 +
150 + string = g_strdup_printf (" Option \"XkbOptions\" \"%s\"", options);
151 + entry = xorg_confd_line_entry_new (string, options, XORG_CONFD_LINE_TYPE_XKB_OPTIONS);
152 + parser->line_list = g_list_insert_before (parser->line_list, end, entry);
153 + g_free (string);
154 }
155 }