Commit f3e4335fc65d6eeb448d30bd2e2dc88f8730ef7a

Ran Benita 2012-02-24T16:07:17

Fix all constness warnings These are all trivial/obvious fixes which clear a bunch of warnings. Signed-off-by: Ran Benita <ran234@gmail.com>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
diff --git a/src/keysym.c b/src/keysym.c
index 5ff1313..7580cdd 100644
--- a/src/keysym.c
+++ b/src/keysym.c
@@ -114,7 +114,7 @@ xkb_string_to_keysym(const char *s)
         entry = &_XkeyTable[idx];
 
         if ((entry[0] == sig1) && (entry[1] == sig2) &&
-            !strcmp(s, (char *)entry + 6))
+            !strcmp(s, (const char *)entry + 6))
         {
             val = (entry[2] << 24) | (entry[3] << 16) |
                   (entry[4] << 8)  | entry[5];
diff --git a/src/maprules.c b/src/maprules.c
index 894f202..49761be 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -208,7 +208,7 @@ Bool	endOfFile,spacePending,slashPending,inComment;
 #define	PART_MASK	0x000F
 #define	COMPONENT_MASK	0x03F0
 
-static	char *	cname[MAX_WORDS] = {
+static	const char * cname[MAX_WORDS] = {
 	"model", "layout", "variant", "option",
 	"keycodes", "symbols", "types", "compat", "geometry", "keymap"
 };
@@ -228,9 +228,9 @@ typedef struct _FileSpec {
 } FileSpec;
 
 typedef struct {
-	char *			model;
-	char *			layout[XkbNumKbdGroups+1];
-	char *			variant[XkbNumKbdGroups+1];
+	const char *		model;
+	const char *		layout[XkbNumKbdGroups+1];
+	const char *		variant[XkbNumKbdGroups+1];
 	char *			options;
 } XkbRF_MultiDefsRec, *XkbRF_MultiDefsPtr;
 
@@ -531,11 +531,11 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
        } else {
            char *p;
            int i;
-           mdefs->layout[1] = _XkbDupString(defs->layout);
-	   if (mdefs->layout[1] == NULL)
-	      return False;
-           squeeze_spaces(mdefs->layout[1]);
-           p = mdefs->layout[1];
+           p = _XkbDupString(defs->layout);
+           if (p == NULL)
+              return False;
+           squeeze_spaces(p);
+           mdefs->layout[1] = p;
            for (i = 2; i <= XkbNumKbdGroups; i++) {
               if ((p = strchr(p, ','))) {
                  *p++ = '\0';
@@ -555,11 +555,11 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
        } else {
            char *p;
            int i;
-           mdefs->variant[1] = _XkbDupString(defs->variant);
-	   if (mdefs->variant[1] == NULL)
-	      return False;
-           squeeze_spaces(mdefs->variant[1]);
-           p = mdefs->variant[1];
+           p = _XkbDupString(defs->variant);
+           if (p == NULL)
+              return False;
+           squeeze_spaces(p);
+           mdefs->variant[1] = p;
            for (i = 2; i <= XkbNumKbdGroups; i++) {
               if ((p = strchr(p, ','))) {
                  *p++ = '\0';
@@ -578,9 +578,13 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
 static void
 FreeMultiDefs(XkbRF_MultiDefsPtr defs)
 {
-  if (defs->options) free(defs->options);
-  if (defs->layout[1])  free(defs->layout[1]);
-  if (defs->variant[1])  free(defs->variant[1]);
+  if (defs->options)
+    free(defs->options);
+  /* Avoid -Wcast-qual warnings. */
+  if (defs->layout[1])
+    free((void *)(uintptr_t)defs->layout[1]);
+  if (defs->variant[1])
+     free((void *)(uintptr_t)defs->variant[1]);
 }
 
 static void
@@ -612,11 +616,11 @@ XkbRF_ApplyRule(	XkbRF_RulePtr 		rule,
 
 static Bool
 CheckGroup(	XkbRF_RulesPtr          rules,
-		char * 			group_name,
-		char * 			name)
+		const char * 		group_name,
+		const char * 		name)
 {
    int i;
-   char *p;
+   const char *p;
    XkbRF_GroupPtr group;
 
    for (i = 0, group = rules->groups; i < rules->num_groups; i++, group++) {
diff --git a/src/text.c b/src/text.c
index c913ff3..d5a7549 100644
--- a/src/text.c
+++ b/src/text.c
@@ -55,7 +55,7 @@ tbGetBuffer(unsigned int size)
     return rtrn;
 }
 
-static char *
+static const char *
 XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
 {
     int len;
@@ -89,11 +89,12 @@ XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
     return rtrn;
 }
 
-char *
+const char *
 XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
 {
     int i, bit, len, rem;
-    char *mm = NULL, *rtrn, *str;
+    const char *mm = NULL;
+    char *rtrn, *str;
     char buf[BUFFER_SIZE];
 
     if ((modMask == 0) && (mask == 0))
@@ -138,7 +139,7 @@ XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
     return rtrn;
 }
 
-static char *modNames[XkbNumModifiers] = {
+static const char *modNames[XkbNumModifiers] = {
     "Shift",
     "Lock",
     "Control",
@@ -149,7 +150,7 @@ static char *modNames[XkbNumModifiers] = {
     "Mod5"
 };
 
-char *
+const char *
 XkbcModIndexText(unsigned ndx)
 {
     char *buf;
@@ -165,7 +166,7 @@ XkbcModIndexText(unsigned ndx)
     return buf;
 }
 
-char *
+const char *
 XkbcModMaskText(unsigned mask, Bool cFormat)
 {
     int i, rem, bit;
@@ -198,7 +199,7 @@ XkbcModMaskText(unsigned mask, Bool cFormat)
     return buf;
 }
 
-char *
+const char *
 XkbcConfigText(unsigned config)
 {
     switch (config) {
@@ -228,7 +229,7 @@ XkbcConfigText(unsigned config)
     }
 }
 
-char *
+const char *
 XkbcGeomFPText(int val)
 {
     char *buf;
@@ -246,7 +247,7 @@ XkbcGeomFPText(int val)
     return buf;
 }
 
-static char *actionTypeNames[XkbSA_NumActions]= {
+static const char *actionTypeNames[XkbSA_NumActions]= {
     "NoAction",         /* XkbSA_NoAction */
     "SetMods",          /* XkbSA_SetMods */
     "LatchMods",        /* XkbSA_LatchMods */
@@ -270,7 +271,7 @@ static char *actionTypeNames[XkbSA_NumActions]= {
     "DeviceValuator"    /* XkbSA_DeviceValuator */
 };
 
-char *
+const char *
 XkbcActionTypeText(unsigned type)
 {
     if (type <= XkbSA_LastAction)
@@ -278,7 +279,7 @@ XkbcActionTypeText(unsigned type)
     return "Private";
 }
 
-char *
+const char *
 XkbcKeysymText(uint32_t sym)
 {
     static char buffer[16];
@@ -288,7 +289,7 @@ XkbcKeysymText(uint32_t sym)
     return buffer;
 }
 
-char *
+const char *
 XkbcKeyNameText(char *name)
 {
     char *buf;
@@ -305,7 +306,7 @@ XkbcKeyNameText(char *name)
     return buf;
 }
 
-static char *siMatchText[5] = {
+static const char *siMatchText[5] = {
     "NoneOf",       /* XkbSI_NoneOf */
     "AnyOfOrNone",  /* XkbSI_AnyOfOrNone */
     "AnyOf",        /* XkbSI_AnyOf */
@@ -313,7 +314,7 @@ static char *siMatchText[5] = {
     "Exactly"       /* XkbSI_Exactly */
 };
 
-char *
+const char *
 XkbcSIMatchText(unsigned type)
 {
     char *buf;
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index f87b5ef..e065919 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -323,7 +323,8 @@ ReportActionNotArray(unsigned action, unsigned field)
 }
 
 static Bool
-ReportNotFound(unsigned action, unsigned field, const char *what, char *bad)
+ReportNotFound(unsigned action, unsigned field, const char *what,
+               const char *bad)
 {
     ERROR("%s named %s not found\n", what, bad);
     ACTION("Ignoring the %s field of an %s action\n", fieldText(field),
diff --git a/src/xkbcomp/alias.c b/src/xkbcomp/alias.c
index 32d2e1e..35c5273 100644
--- a/src/xkbcomp/alias.c
+++ b/src/xkbcomp/alias.c
@@ -213,10 +213,10 @@ ApplyAliases(struct xkb_desc * xkb, Bool toGeom, AliasInfo ** info_in)
             {
                 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
                 {
-                    AliasInfo old;
-                    InitAliasInfo(&old, MergeAugment, 0, a->alias, a->real);
-                    HandleCollision(&old, info);
-                    memcpy(old.real, a->real, XkbKeyNameLength);
+                    AliasInfo old_info;
+                    InitAliasInfo(&old_info, MergeAugment, 0, a->alias, a->real);
+                    HandleCollision(&old_info, info);
+                    memcpy(old_info.real, a->real, XkbKeyNameLength);
                     info->alias[0] = '\0';
                     nNew--;
                     break;
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 13f8745..c5b8655 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -713,7 +713,7 @@ ExprResolveString(ExprDef * expr,
     ExprResult leftRtrn, rightRtrn;
     ExprDef *left;
     ExprDef *right;
-    char *bogus = NULL;
+    const char *bogus = NULL;
 
     switch (expr->op)
     {
@@ -795,7 +795,7 @@ int
 ExprResolveKeyName(ExprDef * expr,
                    ExprResult * val_rtrn)
 {
-    char *bogus = NULL;
+    const char *bogus = NULL;
 
     switch (expr->op)
     {
@@ -893,7 +893,7 @@ ExprResolveMaskLookup(ExprDef * expr,
     int ok = 0;
     ExprResult leftRtrn, rightRtrn;
     ExprDef *left, *right;
-    char *bogus = NULL;
+    const char *bogus = NULL;
 
     switch (expr->op)
     {
diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c
index c6e7ba1..fb5eef2 100644
--- a/src/xkbcomp/geometry.c
+++ b/src/xkbcomp/geometry.c
@@ -1505,7 +1505,7 @@ SetTextDoodadField(DoodadInfo * di,
     ExprResult tmp;
     unsigned def;
     unsigned type;
-    char *typeName = "text doodad";
+    const char *typeName = "text doodad";
     union
     {
         uint32_t *str;
@@ -1695,7 +1695,7 @@ SetLogoDoodadField(DoodadInfo * di,
                    ExprDef * value, SectionInfo * si, GeometryInfo * info)
 {
     ExprResult tmp;
-    char *typeName = "logo doodad";
+    const char *typeName = "logo doodad";
 
     if ((!uStrCaseCmp(field, "corner"))
         || (!uStrCaseCmp(field, "cornerradius")))
@@ -2859,7 +2859,7 @@ HandleGeometryFile(XkbFile * file,
                    struct xkb_desc * xkb, unsigned merge, GeometryInfo * info)
 {
     ParseCommon *stmt;
-    char *failWhat;
+    const char *failWhat;
 
     if (merge == MergeDefault)
         merge = MergeAugment;
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index e8d19db..e24764e 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -32,7 +32,7 @@
 #include "misc.h"
 #include "alias.h"
 
-char *
+const char *
 longText(unsigned long val)
 {
     char buf[4];
diff --git a/src/xkbcomp/keycodes.h b/src/xkbcomp/keycodes.h
index 37702ac..c64b082 100644
--- a/src/xkbcomp/keycodes.h
+++ b/src/xkbcomp/keycodes.h
@@ -29,7 +29,7 @@
 
 #define	KeyNameToLong(n)	((((unsigned long)n[0])<<24)|(((unsigned long)n[1])<<16)|(((unsigned long)n[2])<<8)|n[3])
 
-extern char *longText(unsigned long /* val */
+extern const char *longText(unsigned long /* val */
     );
 
 extern void LongToKeyName(unsigned long /* val */ ,
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index f00a521..12ea942 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -547,7 +547,7 @@ AddPreserve(struct xkb_desc * xkb,
         }
         if (report && (warningLevel > 0))
         {
-            char *str;
+            const char *str;
             WARN("Multiple definitions for preserve[%s] in %s\n",
                   PreserveIndexTxt(xkb, old), TypeTxt(type));
 
diff --git a/src/xkbcomp/listing.c b/src/xkbcomp/listing.c
index dbedca6..0fe8288 100644
--- a/src/xkbcomp/listing.c
+++ b/src/xkbcomp/listing.c
@@ -363,7 +363,7 @@ AddDirectory(CompPair *cp, char *head, char *ptrn, char *rest, char *map,
 
 static int
 GenerateComponent(struct xkb_component_list * complist, unsigned type, char *head_in,
-                 char *base, int *max)
+                 const char *base, int *max)
 {
     char *str, *head, *ptrn = NULL, *rest = NULL;
     char buf[PATH_MAX];
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index dea25e6..c646494 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -183,7 +183,7 @@ extern void yyerror(const char *        /* s */
 extern int yylex(void);
 extern int yyparse(void);
 
-extern void setScanState(char * /* file */ ,
+extern void setScanState(const char * /* file */ ,
                          int     /* line */
     );
 
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index cc3b52d..45a385b 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -68,7 +68,7 @@ XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
     geometry = CreateXKBFile(XkmGeometryIndex, NULL, (ParseCommon *)inc, 0);
     AppendStmt(&keycodes->common, &geometry->common);
 
-    return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : "",
+    return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : strdup(""),
                          &keycodes->common, 0);
 }
 
@@ -90,7 +90,7 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
     }
 
     if (!loaded) {
-        rulesFile = XkbFindFileInPath((char *)rules, XkmRulesFile, &rulesPath);
+        rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath);
         if (!rulesFile) {
             ERROR("could not find \"%s\" rules in XKB path\n", rules);
             goto out;
@@ -146,10 +146,10 @@ xkb_compile_keymap_from_rules(const struct xkb_rule_names *rmlvo)
         return NULL;
     }
 
-    defs.model = (char *) rmlvo->model;
-    defs.layout = (char *) rmlvo->layout;
-    defs.variant = (char *) rmlvo->variant;
-    defs.options = (char *) rmlvo->options;
+    defs.model = rmlvo->model;
+    defs.layout = rmlvo->layout;
+    defs.variant = rmlvo->variant;
+    defs.options = rmlvo->options;
 
     names = XkbComponentsFromRules(rmlvo->rules, &defs);
     if (!names) {
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index c1a0f01..be256b5 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -399,7 +399,7 @@ XkbFindFileInCache(char *name, unsigned type, char **pathRtrn)
  * pathRtrn is undefined.
  */
 FILE *
-XkbFindFileInPath(char *name, unsigned type, char **pathRtrn)
+XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
 {
     register int i;
     FILE *file = NULL;
diff --git a/src/xkbcomp/xkbpath.h b/src/xkbcomp/xkbpath.h
index ca818a5..f527d19 100644
--- a/src/xkbcomp/xkbpath.h
+++ b/src/xkbcomp/xkbpath.h
@@ -34,7 +34,7 @@
 extern char *XkbDirectoryForInclude(unsigned    /* type */
     );
 
-extern FILE *XkbFindFileInPath(char * /* name */ ,
+extern FILE *XkbFindFileInPath(const char * /* name */ ,
                                unsigned /* type */ ,
                                char **  /* pathRtrn */
     );
diff --git a/src/xkbcomp/xkbscan.l b/src/xkbcomp/xkbscan.l
index d32cf39..83f0db0 100644
--- a/src/xkbcomp/xkbscan.l
+++ b/src/xkbcomp/xkbscan.l
@@ -194,7 +194,7 @@ yyerror(const char *s)
     return;
 }
 
-void setScanState(char *file, int lineno)
+void setScanState(const char *file, int lineno)
 {
   yylineno = 1;
   if (scanFile)
diff --git a/src/xkbmisc.h b/src/xkbmisc.h
index 6600d52..40f1334 100644
--- a/src/xkbmisc.h
+++ b/src/xkbmisc.h
@@ -75,31 +75,31 @@ XkbcAtomGetString(uint32_t atom);
 extern const char *
 XkbcAtomText(uint32_t atm);
 
-extern char *
+extern const char *
 XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask);
 
-extern char *
+extern const char *
 XkbcModIndexText(unsigned ndx);
 
-extern char *
+extern const char *
 XkbcModMaskText(unsigned mask, Bool cFormat);
 
-extern char *
+extern const char *
 XkbcConfigText(unsigned config);
 
-extern char *
+extern const char *
 XkbcGeomFPText(int val);
 
-extern char *
+extern const char *
 XkbcActionTypeText(unsigned type);
 
-extern char *
+extern const char *
 XkbcKeysymText(uint32_t sym);
 
-extern char *
+extern const char *
 XkbcKeyNameText(char *name);
 
-extern char *
+extern const char *
 XkbcSIMatchText(unsigned type);
 
 #endif /* _XKBMISC_H_ */
diff --git a/src/xkbrules.h b/src/xkbrules.h
index c9082f5..08c1c04 100644
--- a/src/xkbrules.h
+++ b/src/xkbrules.h
@@ -74,10 +74,10 @@ authorization from the authors.
 #define _XkbErrBadImplementation    26
 
 typedef struct _XkbRF_VarDefs {
-    char *          model;
-    char *          layout;
-    char *          variant;
-    char *          options;
+    const char *    model;
+    const char *    layout;
+    const char *    variant;
+    const char *    options;
     unsigned short  sz_extra;
     unsigned short  num_extra;
     char *          extra_names;