annotate lcdemu/xrm.c @ 2:bff57443b0f7

lcdemu: pathnames moved to /opt/freecalypso
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Mar 2018 18:29:06 +0000
parents e7f1035f10d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * LCDemu based on HECterm by the same author
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * Xrm functions
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <X11/Xlib.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <X11/Xresource.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <X11/Xutil.h>
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "globals.h"
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
2
bff57443b0f7 lcdemu: pathnames moved to /opt/freecalypso
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
15 static char appdefaults_pathname[] = "/opt/freecalypso/X11/lcdemu-defaults";
0
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 load_resources()
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 xrmquark_topclass = XrmStringToQuark("LCDemu");
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 xrmquark_topinstance = XrmStringToQuark(proginstancename);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 xrmdb_defaults = XrmGetFileDatabase(appdefaults_pathname);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 xrmdb_displayres =
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 XrmGetStringDatabase(XResourceManagerString(mydisplay));
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 /*
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * The following function looks up a resource in all of our databases
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 * and returns a pointer (char *) to the value in a malloced buffer that
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 * can be freed when it is no longer needed. My reading of X11R4
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 * documentation indicates that resource values returned from Xrm functions
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * are not necessarily NUL-terminated (no claim is made that they are
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 * and XrmValue structure has a size field), which is why I copy to
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 * my own buffer and NUL-terminate it there.
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * Returns NULL pointer if not found in any of the databases.
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 */
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char *
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 xrm_lookup(instquarks, classquarks)
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 XrmQuark *instquarks, *classquarks;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 XrmRepresentation reptype;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 XrmValue value;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 register char *buf;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (XrmQGetResource(xrmdb_cmdline, instquarks, classquarks, &reptype,
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 &value))
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 goto found;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (XrmQGetResource(xrmdb_displayres, instquarks, classquarks, &reptype,
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 &value))
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 goto found;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (XrmQGetResource(xrmdb_defaults, instquarks, classquarks, &reptype,
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 &value))
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 goto found;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(NULL);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 found: buf = malloc(value.size + 1);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (!buf) {
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 perror("malloc");
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 bcopy(value.addr, buf, value.size);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 buf[value.size] = '\0';
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return(buf);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 parse_boolean_resource(str)
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 register char *str;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 {
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (!strcasecmp(str, "on") || !strcasecmp(str, "true") ||
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 !strcasecmp(str, "yes"))
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 return(1);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (!strcasecmp(str, "off") || !strcasecmp(str, "false") ||
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 !strcasecmp(str, "no"))
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return(0);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 return(atoi(str));
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 get_boolean_resource(resource, def)
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 char *resource;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 int def;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 {
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 XrmQuark instquarks[3], classquarks[3];
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 register char *cp;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 register int i;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 instquarks[0] = xrmquark_topinstance;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 classquarks[0] = xrmquark_topclass;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 classquarks[1] = instquarks[1] = XrmStringToQuark(resource);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 instquarks[2] = classquarks[2] = NULLQUARK;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 cp = xrm_lookup(instquarks, classquarks);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (cp) {
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 i = parse_boolean_resource(cp);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 free(cp);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 } else
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 i = def;
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 return(i);
e7f1035f10d4 lcdemu: initial import from freecalypso-tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }