2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: SmXdef.c /main/4 1995/10/30 09:39:16 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /*************************************<+>*************************************
31 *****************************************************************************
35 ** Project: DT Session Manager (dtsession)
39 ** This file contains routines to manage the Xdefaults file.
41 ** SmXdefMerge() - merge .Xdefaults file into RESOURCE_MANAGER
42 ** SmXdefSubtract() - subtract .Xdefaults file from given database
44 *****************************************************************************
45 *************************************<+>*************************************/
48 #include <X11/Intrinsic.h>
54 * dbXdefaults - copy of .Xdefaults in Xrm database form
56 static XrmDatabase dbXdefaults = NULL;
62 * The memory for dbXdefaults is freed only upon dtsession termination
64 * This code is currently restricted to handling the .Xdefaults file,
65 * but can easily be extended to handle other default resource files.
70 /*************************************<->*************************************
72 * SmXdefMerge(display)
76 * Merge the .Xdefaults file into the RESOURCE_MANAGER database
80 * display - display connection
89 *************************************<->***********************************/
91 SmXdefMerge(Display *display)
99 if ((home = getenv("HOME")) == NULL)
102 if( (xdefaults = (char *)malloc(strlen(home)+12)) != NULL)
104 sprintf(xdefaults,"%s/%s",home,".Xdefaults");
105 if(access(xdefaults,R_OK) == 0)
110 struct stat statinfo;
113 * Determine size of file.
115 if (stat(xdefaults, &statinfo) == -1)
117 statinfo.st_size = 0;
123 if (statinfo.st_size > 0)
125 b = (char *)SM_MALLOC(statinfo.st_size + 1);
131 * Read file into memory.
133 if ((fp = fopen(xdefaults, "r")) != NULL)
135 size = fread(b, 1, statinfo.st_size, fp);
139 if (size == statinfo.st_size)
142 * Merge .Xdefaults string into RESOURCE_MANAGER database, and
143 * also convert to Xrm database form for later subtraction.
146 _DtAddToResource(display, b);
147 dbXdefaults = XrmGetStringDatabase(b);
157 /*************************************<->*************************************
163 * Subract prior merged .Xdefaults file from given database
167 * db - Xrm database from which to subtract .Xdefaults
174 * dbResult - result database
178 * Caller is responsible for freeing dbResult using XrmDestroyDatabase()
181 *************************************<->***********************************/
183 SmXdefSubtract(XrmDatabase db)
185 XrmDatabase dbResult;
189 dbResult = SmXrmSubtractDatabase(dbXdefaults, db);