11ab64890Smrg 21ab64890Smrg/* 31ab64890Smrg 41ab64890SmrgCopyright 1990, 1998 The Open Group 51ab64890Smrg 61ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 71ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 81ab64890Smrgthe above copyright notice appear in all copies and that both that 91ab64890Smrgcopyright notice and this permission notice appear in supporting 101ab64890Smrgdocumentation. 111ab64890Smrg 121ab64890SmrgThe above copyright notice and this permission notice shall be included in 131ab64890Smrgall copies or substantial portions of the Software. 141ab64890Smrg 151ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161ab64890SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171ab64890SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 181ab64890SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 191ab64890SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 201ab64890SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 211ab64890Smrg 221ab64890SmrgExcept as contained in this notice, the name of The Open Group shall not be 231ab64890Smrgused in advertising or otherwise to promote the sale, use or other dealings 241ab64890Smrgin this Software without prior written authorization from The Open Group. 251ab64890Smrg 261ab64890Smrg*/ 271ab64890Smrg 281ab64890Smrg#ifdef HAVE_CONFIG_H 291ab64890Smrg#include <config.h> 301ab64890Smrg#endif 311ab64890Smrg#include "Xlibint.h" 321ab64890Smrg#include <X11/Xresource.h> 331ab64890Smrg#include <X11/keysymdef.h> 34eb411b4bSmrg#include "Xresinternal.h" 351ab64890Smrg 361ab64890Smrg#include <stdio.h> /* sprintf */ 371ab64890Smrg 381ab64890Smrg#define NEEDVTABLE 391ab64890Smrg#include "ks_tables.h" 401ab64890Smrg#include "Key.h" 411ab64890Smrg 421ab64890Smrg 431ab64890Smrgtypedef struct _GRNData { 441ab64890Smrg char *name; 451ab64890Smrg XrmRepresentation type; 461ab64890Smrg XrmValuePtr value; 471ab64890Smrg} GRNData; 481ab64890Smrg 491ab64890Smrg/*ARGSUSED*/ 501ab64890Smrgstatic Bool 511ab64890SmrgSameValue( 521ab64890Smrg XrmDatabase* db, 531ab64890Smrg XrmBindingList bindings, 541ab64890Smrg XrmQuarkList quarks, 551ab64890Smrg XrmRepresentation* type, 561ab64890Smrg XrmValuePtr value, 571ab64890Smrg XPointer data 581ab64890Smrg) 591ab64890Smrg{ 601ab64890Smrg GRNData *gd = (GRNData *)data; 611ab64890Smrg 621ab64890Smrg if ((*type == gd->type) && (value->size == gd->value->size) && 631ab64890Smrg !strncmp((char *)value->addr, (char *)gd->value->addr, value->size)) 641ab64890Smrg { 651ab64890Smrg gd->name = XrmQuarkToString(*quarks); /* XXX */ 661ab64890Smrg return True; 671ab64890Smrg } 681ab64890Smrg return False; 691ab64890Smrg} 701ab64890Smrg 711ab64890Smrgchar *XKeysymToString(KeySym ks) 721ab64890Smrg{ 731ab64890Smrg XrmDatabase keysymdb; 741ab64890Smrg 751ab64890Smrg if (!ks || (ks & ((unsigned long) ~0x1fffffff)) != 0) 761ab64890Smrg return ((char *)NULL); 771ab64890Smrg if (ks == XK_VoidSymbol) 781ab64890Smrg ks = 0; 791ab64890Smrg if (ks <= 0x1fffffff) 801ab64890Smrg { 81eb411b4bSmrg unsigned char val1 = ks >> 24; 82eb411b4bSmrg unsigned char val2 = (ks >> 16) & 0xff; 83eb411b4bSmrg unsigned char val3 = (ks >> 8) & 0xff; 84eb411b4bSmrg unsigned char val4 = ks & 0xff; 85eb411b4bSmrg int i = ks % VTABLESIZE; 86eb411b4bSmrg int h = i + 1; 87eb411b4bSmrg int n = VMAXHASH; 88eb411b4bSmrg int idx; 891ab64890Smrg while ((idx = hashKeysym[i])) 901ab64890Smrg { 91eb411b4bSmrg const unsigned char *entry = &_XkeyTable[idx]; 921ab64890Smrg if ((entry[0] == val1) && (entry[1] == val2) && 931ab64890Smrg (entry[2] == val3) && (entry[3] == val4)) 941ab64890Smrg return ((char *)entry + 4); 951ab64890Smrg if (!--n) 961ab64890Smrg break; 971ab64890Smrg i += h; 981ab64890Smrg if (i >= VTABLESIZE) 991ab64890Smrg i -= VTABLESIZE; 1001ab64890Smrg } 1011ab64890Smrg } 1021ab64890Smrg 1031ab64890Smrg if ((keysymdb = _XInitKeysymDB())) 1041ab64890Smrg { 1051ab64890Smrg char buf[9]; 1061ab64890Smrg XrmValue resval; 1071ab64890Smrg XrmQuark empty = NULLQUARK; 1081ab64890Smrg GRNData data; 1091ab64890Smrg 110eb411b4bSmrg snprintf(buf, sizeof(buf), "%lX", ks); 1111ab64890Smrg resval.addr = (XPointer)buf; 1129c019ec5Smaya resval.size = (unsigned)strlen(buf) + 1; 1131ab64890Smrg data.name = (char *)NULL; 1141ab64890Smrg data.type = XrmPermStringToQuark("String"); 1151ab64890Smrg data.value = &resval; 1161ab64890Smrg (void)XrmEnumerateDatabase(keysymdb, &empty, &empty, XrmEnumAllLevels, 1171ab64890Smrg SameValue, (XPointer)&data); 1181ab64890Smrg if (data.name) 1191ab64890Smrg return data.name; 1201ab64890Smrg } 1211ab64890Smrg if (ks >= 0x01000100 && ks <= 0x0110ffff) { 1221ab64890Smrg KeySym val = ks & 0xffffff; 1231ab64890Smrg char *s; 1241ab64890Smrg int i; 1251ab64890Smrg if (val & 0xff0000) 1261ab64890Smrg i = 10; 1271ab64890Smrg else 1281ab64890Smrg i = 6; 1291ab64890Smrg s = Xmalloc(i); 1301ab64890Smrg if (s == NULL) 1311ab64890Smrg return s; 1321ab64890Smrg i--; 1331ab64890Smrg s[i--] = '\0'; 1341ab64890Smrg for (; i; i--){ 135eb411b4bSmrg unsigned char val1 = val & 0xf; 1361ab64890Smrg val >>= 4; 1371ab64890Smrg if (val1 < 10) 1381ab64890Smrg s[i] = '0'+ val1; 1391ab64890Smrg else 1401ab64890Smrg s[i] = 'A'+ val1 - 10; 1411ab64890Smrg } 1421ab64890Smrg s[i] = 'U'; 14361b2299dSmrg return s; 1441ab64890Smrg } 1451ab64890Smrg return ((char *) NULL); 1461ab64890Smrg} 147