/* resources.c - X resource management
 * 
 *  WindowMaker window manager
 * 
 *  Copyright (c) 1997 Alfredo K. Kojima
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include "wconfig.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
 
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/Xresource.h>

#include "generic/wwmlib.h"

#include "WindowMaker.h"
#include "resources.h"


/****** Global stuff *******/
extern XrmDatabase wResourceDB;



int 
wResourceOpen(char *dbfile)
{
    char path[MAXPATH];

    if (!dbfile) {
	strcpy(path, DEF_USERPREF_PATH);
	strcat(path, DEF_RESOURCE_DB);
	wResourceDB = XrmGetFileDatabase(path);
    } else {
	wResourceDB = XrmGetFileDatabase(dbfile);
    }
    if (!wResourceDB) {
	!wWarning(_("could not open defaults file: %s"), 
		  dbfile ? dbfile : path);
	return False;
    }
    return True;
}

int 
wResourceWrite(char *dbfile)
{
   char path[MAXPATH];

    if (!wResourceDB)
      return False;

    if (!dbfile) {
	strcpy(path, DEF_USERPREF_PATH);
	strcat(path, DEF_RESOURCE_DB);
	if (access(path, R_OK|W_OK)!=0) {
	    !wWarning(_("can not write to defaults file: %s"), path);
	    return False;
	}
	XrmPutFileDatabase(wResourceDB, path);
    } else {
	if (access(dbfile, R_OK|W_OK)!=0) {
	    !wWarning(_("can not write to defaults file: %s"), dbfile);
	    return False;
	}
	XrmPutFileDatabase(wResourceDB, dbfile);
    }
    return True;
}

void 
wResourceUpdate();

int 
wRBooleanForKey(char *wm_instance, char *wm_class, char *key)
{
    
}

int wRIntegerForKey(char *wm_instance, char *wm_class, char *key);
char *wRStringForKey(char *wm_instance, char *wm_class, char *key);
