view lcdemu/xrm.c @ 923:10b4bed10192

gsm-fw/L1: fix for the DSP patch corruption bug The L1 code we got from the LoCosto fw contains a feature for DSP CPU load measurement. This feature is a LoCosto-ism, i.e., not applicable to earlier DBB chips (Calypso) with their respective earlier DSP ROMs. Most of the code dealing with that feature is conditionalized as #if (DSP >= 38), but one spot was missed, and the MCU code was writing into an API word dealing with this feature. In TCS211 this DSP API word happens to be used by the DSP code patch, hence that write was corrupting the patched DSP code.
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Mon, 19 Oct 2015 17:13:56 +0000
parents 312778104f54
children
line wrap: on
line source

/*
 * LCDemu based on HECterm by the same author
 * Xrm functions
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include "globals.h"

static char appdefaults_pathname[] =
		"/usr/local/share/freecalypso/lcdemu-defaults";

load_resources()
{
	xrmquark_topclass = XrmStringToQuark("LCDemu");
	xrmquark_topinstance = XrmStringToQuark(proginstancename);
	xrmdb_defaults = XrmGetFileDatabase(appdefaults_pathname);
	xrmdb_displayres =
		XrmGetStringDatabase(XResourceManagerString(mydisplay));
}

/*
 * The following function looks up a resource in all of our databases
 * and returns a pointer (char *) to the value in a malloced buffer that
 * can be freed when it is no longer needed.  My reading of X11R4
 * documentation indicates that resource values returned from Xrm functions
 * are not necessarily NUL-terminated (no claim is made that they are
 * and XrmValue structure has a size field), which is why I copy to
 * my own buffer and NUL-terminate it there.
 *
 * Returns NULL pointer if not found in any of the databases.
 */
char *
xrm_lookup(instquarks, classquarks)
	XrmQuark *instquarks, *classquarks;
{
	XrmRepresentation reptype;
	XrmValue value;
	register char *buf;

	if (XrmQGetResource(xrmdb_cmdline, instquarks, classquarks, &reptype,
	    &value))
		goto found;
	if (XrmQGetResource(xrmdb_displayres, instquarks, classquarks, &reptype,
	    &value))
		goto found;
	if (XrmQGetResource(xrmdb_defaults, instquarks, classquarks, &reptype,
	    &value))
		goto found;
	return(NULL);
found:	buf = malloc(value.size + 1);
	if (!buf) {
		perror("malloc");
		exit(1);
	}
	bcopy(value.addr, buf, value.size);
	buf[value.size] = '\0';
	return(buf);
}

parse_boolean_resource(str)
	register char *str;
{
	if (!strcasecmp(str, "on") || !strcasecmp(str, "true") ||
	    !strcasecmp(str, "yes"))
		return(1);
	if (!strcasecmp(str, "off") || !strcasecmp(str, "false") ||
	    !strcasecmp(str, "no"))
		return(0);
	return(atoi(str));
}

get_boolean_resource(resource, def)
	char *resource;
	int def;
{
	XrmQuark instquarks[3], classquarks[3];
	register char *cp;
	register int i;

	instquarks[0] = xrmquark_topinstance;
	classquarks[0] = xrmquark_topclass;
	classquarks[1] = instquarks[1] = XrmStringToQuark(resource);
	instquarks[2] = classquarks[2] = NULLQUARK;
	cp = xrm_lookup(instquarks, classquarks);
	if (cp) {
		i = parse_boolean_resource(cp);
		free(cp);
	} else
		i = def;
	return(i);
}