1 /************************************************************
2 Copyright 1996 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
26 /***********************************************************
28 Copyright 1988, 1998 The Open Group
30 Permission to use, copy, modify, distribute, and sell this software and its
31 documentation for any purpose is hereby granted without fee, provided that
32 the above copyright notice appear in all copies and that both that
33 copyright notice and this permission notice appear in supporting
36 The above copyright notice and this permission notice shall be included in
37 all copies or substantial portions of the Software.
39 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
43 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 Except as contained in this notice, the name of The Open Group shall not be
47 used in advertising or otherwise to promote the sale, use or other dealings
48 in this Software without prior written authorization from The Open Group.
51 Copyright 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
55 Permission to use, copy, modify, and distribute this software and its
56 documentation for any purpose and without fee is hereby granted,
57 provided that the above copyright notice appear in all copies and that
58 both that copyright notice and this permission notice appear in
59 supporting documentation, and that the name of Digital not be
60 used in advertising or publicity pertaining to distribution of the
61 software without specific, written prior permission.
63 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
64 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
65 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
66 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
67 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
68 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
71 ******************************************************************/
75 #include <sys/types.h>
77 #include <X11/keysym.h>
83 #define DEBUG_VAR listingDebug
90 # define _POSIX_SOURCE
99 #include <sys/param.h>
103 #define PATH_MAX MAXPATHLEN
105 #define PATH_MAX 1024
111 # include <windows.h>
112 # define FileName(file) file.cFileName
117 # define FileName(file) file->d_name
121 #include "parseutils.h"
124 #include <X11/extensions/XKBgeomcommon.h>
126 #define lowbit(x) ((x) & (-(x)))
128 unsigned int listingDebug;
130 static int szListing = 0;
131 static int nListed = 0;
132 static int nFilesListed = 0;
134 typedef struct _Listing
140 static int szMapOnly;
142 static char **mapOnly;
144 static Listing *list = NULL;
146 /***====================================================================***/
149 AddMapOnly(char *map)
151 if (nMapOnly >= szMapOnly)
157 mapOnly = uTypedRealloc(list, szMapOnly, char *);
160 WSGO("Couldn't allocate list of maps\n");
164 mapOnly[nMapOnly++] = map;
169 AddListing(char *file, char *map)
171 if (nListed >= szListing)
177 list = uTypedRealloc(list, szListing, Listing);
180 WSGO("Couldn't allocate list of files and maps\n");
186 list[nListed].file = file;
187 list[nListed].map = map;
194 /***====================================================================***/
197 ListFile(FILE * outFile, char *fileName, XkbFile * map)
199 register unsigned flags;
203 if ((flags & XkbLC_Hidden) && (!(verboseLevel & WantHiddenMaps)))
205 if ((flags & XkbLC_Partial) && (!(verboseLevel & WantPartialMaps)))
207 if (verboseLevel & WantLongListing)
209 fprintf(outFile, (flags & XkbLC_Hidden) ? "h" : "-");
210 fprintf(outFile, (flags & XkbLC_Default) ? "d" : "-");
211 fprintf(outFile, (flags & XkbLC_Partial) ? "p" : "-");
212 fprintf(outFile, "----- ");
213 if (map->type == XkmSymbolsIndex)
215 fprintf(outFile, (flags & XkbLC_AlphanumericKeys) ? "a" : "-");
216 fprintf(outFile, (flags & XkbLC_ModifierKeys) ? "m" : "-");
217 fprintf(outFile, (flags & XkbLC_KeypadKeys) ? "k" : "-");
218 fprintf(outFile, (flags & XkbLC_FunctionKeys) ? "f" : "-");
219 fprintf(outFile, (flags & XkbLC_AlternateGroup) ? "g" : "-");
220 fprintf(outFile, "--- ");
223 fprintf(outFile, "-------- ");
226 if ((!(verboseLevel & WantFullNames)) && ((flags & XkbLC_Default) != 0))
232 for (i = 0, tmp = last = fileName; (i < dirsToStrip) && tmp; i++)
235 tmp = strchr(tmp, '/');
239 fileName = (tmp ? tmp : last);
242 fprintf(outFile, "%s(%s)\n", fileName, mapName);
244 fprintf(outFile, "%s\n", fileName);
248 /***====================================================================***/
251 AddDirectory(char *head, char *ptrn, char *rest, char *map)
255 WIN32_FIND_DATA file;
265 if ((rest == NULL) && (ptrn != NULL) && (strchr(ptrn, '/') == NULL))
268 map = strchr(ptrn, '(');
270 else if ((rest == NULL) && (ptrn == NULL) &&
271 (head != NULL) && (strchr(head, '/') == NULL))
274 map = strchr(head, '(');
278 tmp = strchr(tmp, ')');
279 if ((tmp == NULL) || (tmp[1] != '\0'))
281 ERROR1("File and map must have the format file(map)\n");
290 if ((dirh = FindFirstFile("*.*", &file)) == INVALID_HANDLE_VALUE)
293 if ((dirp = opendir((head ? head : "."))) == NULL)
300 while ((file = readdir(dirp)) != NULL)
303 char *tmp, *filename;
306 filename = FileName(file);
307 if (!filename || filename[0] == '.')
309 if (ptrn && (!XkbNameMatchesPattern(filename, ptrn)))
312 (char *) uAlloc((head ? strlen(head) : 0) + strlen(filename) + 2);
315 sprintf(tmp, "%s%s%s", (head ? head : ""), (head ? "/" : ""),
317 if (stat(tmp, &sbuf) < 0)
322 if (((rest != NULL) && (!S_ISDIR(sbuf.st_mode))) ||
323 ((map != NULL) && (S_ISDIR(sbuf.st_mode))))
328 if (S_ISDIR(sbuf.st_mode))
330 if ((rest != NULL) || (verboseLevel & ListRecursive))
331 nMatch += AddDirectory(tmp, rest, NULL, map);
334 nMatch += AddListing(tmp, map);
337 while (FindNextFile(dirh, &file));
342 /***====================================================================***/
345 AddMatchingFiles(char *head_in)
347 char *str, *head, *ptrn, *rest = NULL;
352 for (str = head_in; (*str != '\0') && (*str != '?') && (*str != '*');
355 if ((str != head_in) && (*str == '/'))
364 else if (ptrn == NULL)
365 { /* no slash before the first wildcard */
370 { /* slash followed by wildcard */
377 rest = strchr(ptrn, '/');
385 && ((strchr(ptrn, '(') != NULL) || (strchr(ptrn, ')') != NULL)))
387 && ((strchr(head, '(') != NULL) || (strchr(head, ')') != NULL))))
389 ERROR1("Files/maps to list must have the form file(map)\n");
390 ACTION("Illegal specifier ignored\n");
393 return AddDirectory(head, ptrn, rest, NULL);
396 /***====================================================================***/
399 MapMatches(char *mapToConsider, char *ptrn)
404 return XkbNameMatchesPattern(mapToConsider, ptrn);
407 for (i = 0; i < nMapOnly; i++)
409 if (XkbNameMatchesPattern(mapToConsider, mapOnly[i]))
416 GenerateListing(char *out_name)
419 FILE *inputFile, *outFile;
420 XkbFile *rtrn, *mapToUse;
421 unsigned oldWarningLevel;
424 if (nFilesListed < 1)
426 ERROR1("Must specify at least one file or pattern to list\n");
429 if ((!out_name) || ((out_name[0] == '-') && (out_name[1] == '\0')))
431 else if ((outFile = fopen(out_name, "w")) == NULL)
433 ERROR1("Cannot open \"%s\" to write keyboard description\n",
439 if (warningLevel > 9)
440 fprintf(stderr, "should list:\n");
442 for (i = 0; i < nListed; i++)
445 if (warningLevel > 9)
447 fprintf(stderr, "%s(%s)\n",
448 (list[i].file ? list[i].file : "*"),
449 (list[i].map ? list[i].map : "*"));
452 oldWarningLevel = warningLevel;
458 if (stat(list[i].file, &sbuf) < 0)
460 if (oldWarningLevel > 5)
461 WARN1("Couldn't open \"%s\"\n", list[i].file);
464 if (S_ISDIR(sbuf.st_mode))
466 if (verboseLevel & ListRecursive)
467 AddDirectory(list[i].file, NULL, NULL, NULL);
471 inputFile = fopen(list[i].file, "r");
474 if (oldWarningLevel > 5)
475 WARN1("Couldn't open \"%s\"\n", list[i].file);
478 setScanState(list[i].file, 1);
479 if (XKBParseFile(inputFile, &rtrn) && (rtrn != NULL))
481 mapName = list[i].map;
483 for (; mapToUse; mapToUse = (XkbFile *) mapToUse->common.next)
485 if (!MapMatches(mapToUse->name, mapName))
487 ListFile(outFile, list[i].file, mapToUse);
492 warningLevel = oldWarningLevel;