Commit 54aa839c0e9d6029ce9f474c2474e4b816ec1876

Daniel Stone 2012-03-14T11:59:52

Remove component listing code Signed-off-by: Daniel Stone <daniel@fooishbar.org>

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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h
index 6ed9884..d023b14 100644
--- a/include/xkbcommon/xkbcommon.h
+++ b/include/xkbcommon/xkbcommon.h
@@ -465,19 +465,6 @@ struct xkb_component_name {
 	char *			name;
 };
 
-struct xkb_component_list {
-	int			num_keymaps;
-	int			num_keycodes;
-	int			num_types;
-	int			num_compat;
-	int			num_symbols;
-	struct xkb_component_name *	keymaps;
-	struct xkb_component_name * 	keycodes;
-	struct xkb_component_name *	types;
-	struct xkb_component_name *	compat;
-	struct xkb_component_name *	symbols;
-};
-
 struct xkb_state {
 	unsigned char   group; /* base + latched + locked */
 	/* FIXME: Why are base + latched short and not char?? */
@@ -531,9 +518,6 @@ xkb_compile_keymap_from_string(const char *string, const char *mapName);
 _X_EXPORT extern void
 xkb_free_keymap(struct xkb_desc *xkb);
 
-_X_EXPORT extern struct xkb_component_list *
-xkb_list_components(struct xkb_component_names * ptrns, int *maxMatch);
-
 /*
  * Canonicalises component names by prepending the relevant component from
  * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
diff --git a/src/xkbcomp/Makefile.am b/src/xkbcomp/Makefile.am
index b438810..0866208 100644
--- a/src/xkbcomp/Makefile.am
+++ b/src/xkbcomp/Makefile.am
@@ -18,7 +18,6 @@ libxkbcomp_la_SOURCES = \
 	keycodes.h \
 	keymap.c \
 	keytypes.c \
-	listing.c \
 	misc.c \
 	misc.h \
 	parseutils.c \
diff --git a/src/xkbcomp/listing.c b/src/xkbcomp/listing.c
deleted file mode 100644
index bef0f7b..0000000
--- a/src/xkbcomp/listing.c
+++ /dev/null
@@ -1,513 +0,0 @@
-/************************************************************
- Copyright 1996 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ********************************************************/
-/***********************************************************
-
-Copyright 1988, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-Copyright 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <X11/keysym.h>
-
-#if defined(sgi)
-#include <malloc.h>
-#endif
-
-#include "xkbcomp.h"
-#include <stdlib.h>
-
-#ifdef _POSIX_SOURCE
-# include <limits.h>
-#else
-# define _POSIX_SOURCE
-# include <limits.h>
-# undef _POSIX_SOURCE
-#endif
-
-#ifndef PATH_MAX
-#ifdef WIN32
-#define PATH_MAX 512
-#else
-#include <sys/param.h>
-#endif
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX MAXPATHLEN
-#else
-#define PATH_MAX 1024
-#endif
-#endif
-#endif
-
-#ifdef WIN32
-# include <windows.h>
-# define FileName(file) file.cFileName
-# undef TEXT
-# undef ALTERNATE
-#else
-# include <dirent.h>
-# define FileName(file) file->d_name
-#endif
-
-#include "xkbmisc.h"
-#include "xkbpath.h"
-#include "parseutils.h"
-#include "misc.h"
-
-#ifndef DFLT_XKB_CONFIG_ROOT
-#define DFLT_XKB_CONFIG_ROOT "/usr/share/X11/xkb"
-#endif
-
-typedef struct _CompPair {
-    int num;
-    int sz;
-
-    struct xkb_component_name * comp;
-} CompPair;
-
-/***====================================================================***/
-
-static Bool
-AddComponent(CompPair *cp, char *fileName, XkbFile *map, unsigned dirsToStrip)
-{
-    if (!cp || !fileName || !map)
-        return False;
-
-    if (cp->num >= cp->sz) {
-        int orig_sz = cp->sz;
-        struct xkb_component_name * orig_comp = cp->comp;
-
-        if (cp->sz < 1)
-            cp->sz = 8;
-        else
-            cp->sz *= 2;
-
-        cp->comp = realloc(cp->comp,
-                               cp->sz * sizeof(struct xkb_component_name));
-        if (!cp->comp) {
-            ERROR("Failed reallocating component name list\n");
-            cp->sz = orig_sz;
-            cp->comp = orig_comp;
-            return False;
-        }
-    }
-
-    /* Strip off leading directories of component */
-    if (dirsToStrip > 0) {
-        char *tmp, *last;
-        int i;
-
-        for (i = 0, tmp = last = fileName; (i <= dirsToStrip) && tmp; i++) {
-            last = tmp;
-            tmp = strchr(tmp, '/');
-            if (tmp != NULL)
-                tmp++;
-        }
-
-        fileName = (tmp ? tmp : last);
-    }
-
-    if (map->name) {
-        size_t len = strlen(fileName) + strlen(map->name) + 3;
-
-        cp->comp[cp->num].name = malloc(len * sizeof(char));
-        if (!cp->comp[cp->num].name) {
-            ERROR("Could not allocate space for component name\n");
-            return False;
-        }
-        sprintf(cp->comp[cp->num].name, "%s(%s)", fileName, map->name);
-    }
-    else {
-        cp->comp[cp->num].name = strdup(fileName);
-        if (!cp->comp[cp->num].name) {
-            ERROR("Could not duplicate component name\n");
-            return False;
-        }
-    }
-
-    cp->comp[cp->num].flags = map->flags;
-    cp->num++;
-
-    return True;
-}
-
-static Bool
-MapMatches(char *mapToConsider, char *ptrn)
-{
-    return ptrn ? XkbcNameMatchesPattern(mapToConsider, ptrn) : True;
-}
-
-static int
-ParseComponents(CompPair *cp, char *path, char *map, int *max, unsigned strip)
-{
-    int extra = 0;
-    FILE *inputFile;
-    XkbFile *rtrn, *mapToUse;
-    unsigned oldWarningLevel;
-
-    if (!cp || !path || !max)
-        return 0;
-
-#ifdef DEBUG
-    if (warningLevel > 9)
-        fprintf(stderr, "should list:\n");
-#endif
-
-    oldWarningLevel = warningLevel;
-    warningLevel = 0;
-
-#ifdef DEBUG
-    if (oldWarningLevel > 9)
-        fprintf(stderr, "%s(%s)\n", path ? path : "*", map ? map : "*");
-#endif
-
-    inputFile = fopen(path, "r");
-    if (!inputFile) {
-        if (oldWarningLevel > 5)
-            WARN("Couldn't open \"%s\"\n", path);
-        return 0;
-    }
-
-    setScanState(path, 1);
-    if (!XKBParseFile(inputFile, &rtrn) || !rtrn) {
-        if (oldWarningLevel > 5)
-            WARN("Couldn't parse file \"%s\"\n", path);
-        fclose(inputFile);
-        return 0;
-    }
-
-    mapToUse = rtrn;
-    for (; mapToUse; mapToUse = (XkbFile *)mapToUse->common.next) {
-        if (!MapMatches(mapToUse->name, map))
-            continue;
-        if (*max <= 0) {
-            extra++;
-            continue;
-        }
-        if (AddComponent(cp, path, mapToUse, strip))
-            (*max)--;
-    }
-
-    warningLevel = oldWarningLevel;
-
-    if (extra)
-        *max = 0;
-
-    return extra;
-}
-
-/***====================================================================***/
-
-static int
-AddDirectory(CompPair *cp, char *head, char *ptrn, char *rest, char *map,
-             int *max, unsigned strip)
-{
-#ifdef WIN32
-    HANDLE dirh;
-    WIN32_FIND_DATA file;
-#else
-    DIR *dirp;
-    struct dirent *file;
-#endif
-    int nMatch;
-    size_t baselen;
-    char path[PATH_MAX];
-
-    if (!head) {
-        ERROR("Must specify directory name\n");
-        return 0;
-    }
-
-    strncpy(path, head, sizeof(path));
-    path[PATH_MAX - 1] = '\0';
-    baselen = strlen(path);
-
-    if (!map) {
-        char *tmp = ptrn;
-
-        if (!rest && ptrn && !strchr(ptrn, '/')) {
-            tmp = ptrn;
-            map = strchr(ptrn, '(');
-        }
-        else if (!rest && !ptrn && !strchr(head, '/')) {
-            tmp = head;
-            map = strchr(head, '(');
-        }
-
-        if (map) {
-            tmp = strchr(tmp, ')');
-            if (!tmp || tmp[1] != '\0') {
-                ERROR("File and map must have the format file(map)\n");
-                return 0;
-            }
-            *map = '\0';
-            map++;
-            *tmp = '\0';
-        }
-    }
-
-#ifdef WIN32
-    if ((dirh = FindFirstFile("*.*", &file)) == INVALID_HANDLE_VALUE)
-        return 0;
-#else
-    if (!(dirp = opendir(head))) {
-        ERROR("Could not open directory \"%s\"\n", head ? head : ".");
-        return 0;
-    }
-#endif
-    nMatch = 0;
-#ifdef WIN32
-    do
-#else
-    while ((file = readdir(dirp)) != NULL)
-#endif
-    {
-        char *filename;
-        struct stat sbuf;
-
-        filename = FileName(file);
-        if (!filename || filename[0] == '.')
-            continue;
-        if (ptrn && (!XkbcNameMatchesPattern(filename, ptrn)))
-            continue;
-
-        snprintf(&path[baselen], sizeof(path) - baselen, "/%s", filename);
-        if (stat(path, &sbuf) < 0) {
-            ERROR("Could not read file \"%s\"\n", path);
-            continue;
-        }
-
-        if ((rest && !S_ISDIR(sbuf.st_mode)) ||
-            (map && S_ISDIR(sbuf.st_mode)))
-            continue;
-
-        if (S_ISDIR(sbuf.st_mode))
-            nMatch += AddDirectory(cp, path, rest, NULL, map, max, strip);
-        else
-            nMatch += ParseComponents(cp, path, map, max, strip);
-    }
-#ifdef WIN32
-    while (FindNextFile(dirh, &file));
-#else
-    closedir(dirp);
-#endif
-    return nMatch;
-}
-
-/***====================================================================***/
-
-static int
-GenerateComponent(struct xkb_component_list * complist, unsigned type, char *head_in,
-                 const char *base, int *max)
-{
-    char *str, *head, *ptrn = NULL, *rest = NULL;
-    char buf[PATH_MAX];
-    size_t len;
-    CompPair cp;
-    unsigned dirsToStrip;
-    int extra;
-
-    if (!complist || !head_in || !max)
-        return 0;
-
-    ptrn = NULL;
-    for (str = head_in; (*str != '\0') && (*str != '?') && (*str != '*');
-         str++)
-    {
-        if ((str != head_in) && (*str == '/'))
-            ptrn = str;
-    }
-
-    if (*str == '\0') {
-        /* no wildcards */
-        head = head_in;
-    }
-    else if (!ptrn) {
-        /* no slash before the first wildcard */
-        head = NULL;
-        ptrn = head_in;
-    }
-    else {
-        /* slash followed by wildcard */
-        head = head_in;
-        *ptrn = '\0';
-        ptrn++;
-    }
-
-    if (ptrn) {
-        rest = strchr(ptrn, '/');
-        if (rest) {
-            *rest = '\0';
-            rest++;
-        }
-    }
-
-    if ((rest && ptrn && (strchr(ptrn, '(') || strchr(ptrn, ')'))) ||
-        (head && (strchr(head, '(') || strchr(head, ')')))) {
-        ERROR("Files/maps to list must have the form file(map)\n");
-        return 0;
-    }
-
-    /* Prepend XKB directory */
-    snprintf(buf, sizeof(buf), "%s%s%s", base ? base : "", base ? "/" : "",
-             XkbDirectoryForInclude(type));
-    len = strlen(buf);
-
-    /* Figure out directory stripping */
-    str = buf;
-    dirsToStrip = 0;
-    while ((str = strchr(str, '/')) != NULL) {
-        str++;
-        dirsToStrip++;
-    }
-
-    if (head)
-        snprintf(&buf[len], PATH_MAX - len, "/%s", head);
-    head = buf;
-
-    memset(&cp, 0, sizeof(CompPair));
-    extra = AddDirectory(&cp, head, ptrn, rest, NULL, max, dirsToStrip);
-
-    /* Trim excess component slots */
-    if (cp.sz > 0 && cp.sz > cp.num) {
-        if (realloc(cp.comp, cp.num * sizeof(struct xkb_component_name)))
-            cp.sz = cp.num;
-        else
-            WARN("Could not reallocate component name list\n");
-    }
-
-    switch (type) {
-    case XkmKeymapFile:
-        complist->num_keymaps = cp.num;
-        complist->keymaps = cp.comp;
-        break;
-    case XkmKeyNamesIndex:
-        complist->num_keycodes = cp.num;
-        complist->keycodes = cp.comp;
-        break;
-    case XkmTypesIndex:
-        complist->num_types = cp.num;
-        complist->types = cp.comp;
-        break;
-    case XkmCompatMapIndex:
-        complist->num_compat = cp.num;
-        complist->compat = cp.comp;
-        break;
-    case XkmSymbolsIndex:
-        complist->num_symbols = cp.num;
-        complist->symbols = cp.comp;
-        break;
-    }
-
-    return extra;
-}
-
-/***====================================================================***/
-
-struct xkb_component_list *
-xkb_list_components(struct xkb_component_names * ptrns, int *maxMatch)
-{
-    struct xkb_component_list * complist = NULL;
-    int extra = 0;
-
-    complist = _XkbTypedCalloc(1, struct xkb_component_list);
-    if (!complist) {
-        ERROR("could not allocate space for listing\n");
-        goto out;
-    }
-
-    if (!maxMatch || *maxMatch <= 0)
-        goto out;
-
-    if (ptrns->keymap && *ptrns->keymap != '\0')
-        extra += GenerateComponent(complist, XkmKeymapFile, ptrns->keycodes,
-                                   DFLT_XKB_CONFIG_ROOT, maxMatch);
-
-    if (ptrns->keycodes && *ptrns->keycodes != '\0')
-        extra += GenerateComponent(complist, XkmKeyNamesIndex, ptrns->keycodes,
-                                   DFLT_XKB_CONFIG_ROOT, maxMatch);
-
-    if (ptrns->types && *ptrns->types != '\0')
-        extra += GenerateComponent(complist, XkmTypesIndex, ptrns->types,
-                                   DFLT_XKB_CONFIG_ROOT, maxMatch);
-
-    if (ptrns->compat && *ptrns->compat != '\0')
-        extra += GenerateComponent(complist, XkmCompatMapIndex, ptrns->compat,
-                                   DFLT_XKB_CONFIG_ROOT, maxMatch);
-
-    if (ptrns->symbols && *ptrns->symbols != '\0')
-        extra += GenerateComponent(complist, XkmSymbolsIndex, ptrns->symbols,
-                                   DFLT_XKB_CONFIG_ROOT, maxMatch);
-
-out:
-    if (maxMatch)
-        *maxMatch = extra;
-    return complist;
-}