1
/* $Xorg: file.c,v 1.5 2001/02/09 02:05:40 xorgcvs Exp $ */
4
Copyright 1988, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
29
/* $XFree86: xc/programs/xdm/file.c,v 1.6 2001/12/14 20:01:21 dawes Exp $ */
32
* xdm - display manager daemon
33
* Author: Keith Packard, MIT X Consortium
39
# include "dm_error.h"
44
DisplayTypeMatch (DisplayType d1, DisplayType d2)
46
return d1.location == d2.location &&
47
d1.lifetime == d2.lifetime &&
48
d1.origin == d2.origin;
52
freeFileArgs (char **args)
56
for (a = args; *a; a++)
62
splitIntoWords (char *s)
64
char **args, **newargs;
72
while (*s && isspace (*s))
77
while (*s && *s != '#' && !isspace (*s))
81
args = (char **) malloc (2 * sizeof (char *));
87
newargs = (char **) realloc ((char *) args,
88
(nargs+2)*sizeof (char *));
96
args[nargs] = malloc (s - wordStart + 1);
102
strncpy (args[nargs], wordStart, s - wordStart);
103
args[nargs][s-wordStart] = '\0';
111
copyArgs (char **args)
113
char **a, **new, **n;
115
for (a = args; *a; a++)
118
new = (char **) malloc ((a - args + 1) * sizeof (char *));
124
while ((*n++ = *a++))
131
freeSomeArgs (char **args, int n)
138
free ((char *) args);
142
ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
144
char **args, **argv, **a;
145
char *name, *class, *type;
148
DisplayType displayType;
150
args = splitIntoWords (source);
155
LogError ("Missing display name in servers file\n");
162
LogError ("Missing display type for %s\n", args[0]);
166
displayType = parseDisplayType (args[1], &usedDefault);
171
* extended syntax; if the second argument doesn't
172
* exactly match a legal display type and the third
173
* argument does, use the second argument as the
174
* display class string
176
if (usedDefault && args[2])
178
displayType = parseDisplayType (args[2], &usedDefault);
186
while (numAcceptable)
188
if (DisplayTypeMatch (*acceptableTypes, displayType))
195
LogError ("Unacceptable display type %s for display %s\n",
198
d = FindDisplayByName (name);
202
if (class && strcmp (d->class, class))
206
newclass = malloc ((unsigned) (strlen (class) + 1));
210
strcpy (newclass, class);
214
Debug ("Found existing display: %s %s %s", d->name, d->class , type);
215
freeFileArgs (d->argv);
219
d = NewDisplay (name, class);
220
Debug ("Found new display: %s %s %s",
221
d->name, d->class ? d->class : "", type);
223
d->displayType = displayType;
224
d->argv = copyArgs (argv);
225
for (a = d->argv; a && *a; a++)
228
freeSomeArgs (args, argv - args);
231
static struct displayMatch {
235
{ "local", { Local, Permanent, FromFile } },
236
{ "foreign", { Foreign, Permanent, FromFile } },
237
{ 0, { Local, Permanent, FromFile } },
241
parseDisplayType (char *string, int *usedDefault)
243
struct displayMatch *d;
245
for (d = displayTypes; d->name; d++)
246
if (!strcmp (d->name, string))