xkbtext.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. /************************************************************
  2. Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
  3. Permission to use, copy, modify, and distribute this
  4. software and its documentation for any purpose and without
  5. fee is hereby granted, provided that the above copyright
  6. notice appear in all copies and that both that copyright
  7. notice and this permission notice appear in supporting
  8. documentation, and that the name of Silicon Graphics not be
  9. used in advertising or publicity pertaining to distribution
  10. of the software without specific prior written permission.
  11. Silicon Graphics makes no representation about the suitability
  12. of this software for any purpose. It is provided "as is"
  13. without any express or implied warranty.
  14. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  15. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  16. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  18. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  21. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ********************************************************/
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <stdio.h>
  27. #include <ctype.h>
  28. #include <stdlib.h>
  29. #include <X11/Xos.h>
  30. #include <X11/X.h>
  31. #include <X11/Xproto.h>
  32. #include <X11/extensions/XKMformat.h>
  33. #include "misc.h"
  34. #include "inputstr.h"
  35. #include "dix.h"
  36. #include "xkbstr.h"
  37. #define XKBSRV_NEED_FILE_FUNCS 1
  38. #include <xkbsrv.h>
  39. #include "xkbgeom.h"
  40. /***====================================================================***/
  41. #define BUFFER_SIZE 512
  42. static char textBuffer[BUFFER_SIZE];
  43. static int tbNext = 0;
  44. static char *
  45. tbGetBuffer(unsigned size)
  46. {
  47. char *rtrn;
  48. if (size >= BUFFER_SIZE)
  49. return NULL;
  50. if ((BUFFER_SIZE - tbNext) <= size)
  51. tbNext = 0;
  52. rtrn = &textBuffer[tbNext];
  53. tbNext += size;
  54. return rtrn;
  55. }
  56. /***====================================================================***/
  57. char *
  58. XkbAtomText(Atom atm, unsigned format)
  59. {
  60. const char *atmstr;
  61. char *rtrn, *tmp;
  62. atmstr = NameForAtom(atm);
  63. if (atmstr != NULL) {
  64. int len;
  65. len = strlen(atmstr) + 1;
  66. if (len > BUFFER_SIZE)
  67. len = BUFFER_SIZE - 2;
  68. rtrn = tbGetBuffer(len);
  69. strlcpy(rtrn, atmstr, len);
  70. }
  71. else {
  72. rtrn = tbGetBuffer(1);
  73. rtrn[0] = '\0';
  74. }
  75. if (format == XkbCFile) {
  76. for (tmp = rtrn; *tmp != '\0'; tmp++) {
  77. if ((tmp == rtrn) && (!isalpha(*tmp)))
  78. *tmp = '_';
  79. else if (!isalnum(*tmp))
  80. *tmp = '_';
  81. }
  82. }
  83. return XkbStringText(rtrn, format);
  84. }
  85. /***====================================================================***/
  86. char *
  87. XkbVModIndexText(XkbDescPtr xkb, unsigned ndx, unsigned format)
  88. {
  89. register int len;
  90. register Atom *vmodNames;
  91. char *rtrn;
  92. const char *tmp;
  93. char numBuf[20];
  94. if (xkb && xkb->names)
  95. vmodNames = xkb->names->vmods;
  96. else
  97. vmodNames = NULL;
  98. tmp = NULL;
  99. if (ndx >= XkbNumVirtualMods)
  100. tmp = "illegal";
  101. else if (vmodNames && (vmodNames[ndx] != None))
  102. tmp = NameForAtom(vmodNames[ndx]);
  103. if (tmp == NULL) {
  104. snprintf(numBuf, sizeof(numBuf), "%d", ndx);
  105. tmp = numBuf;
  106. }
  107. len = strlen(tmp) + 1;
  108. if (format == XkbCFile)
  109. len += 4;
  110. if (len >= BUFFER_SIZE)
  111. len = BUFFER_SIZE - 1;
  112. rtrn = tbGetBuffer(len);
  113. if (format == XkbCFile) {
  114. strcpy(rtrn, "vmod_");
  115. strncpy(&rtrn[5], tmp, len - 4);
  116. }
  117. else
  118. strncpy(rtrn, tmp, len);
  119. return rtrn;
  120. }
  121. char *
  122. XkbVModMaskText(XkbDescPtr xkb,
  123. unsigned modMask, unsigned mask, unsigned format)
  124. {
  125. register int i, bit;
  126. int len;
  127. char *mm, *rtrn;
  128. char *str, buf[BUFFER_SIZE];
  129. if ((modMask == 0) && (mask == 0)) {
  130. rtrn = tbGetBuffer(5);
  131. if (format == XkbCFile)
  132. snprintf(rtrn, 5, "0");
  133. else
  134. snprintf(rtrn, 5, "none");
  135. return rtrn;
  136. }
  137. if (modMask != 0)
  138. mm = XkbModMaskText(modMask, format);
  139. else
  140. mm = NULL;
  141. str = buf;
  142. buf[0] = '\0';
  143. if (mask) {
  144. char *tmp;
  145. for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
  146. if (mask & bit) {
  147. tmp = XkbVModIndexText(xkb, i, format);
  148. len = strlen(tmp) + 1 + (str == buf ? 0 : 1);
  149. if (format == XkbCFile)
  150. len += 4;
  151. if ((str - (buf + len)) <= BUFFER_SIZE) {
  152. if (str != buf) {
  153. if (format == XkbCFile)
  154. *str++ = '|';
  155. else
  156. *str++ = '+';
  157. len--;
  158. }
  159. }
  160. if (format == XkbCFile)
  161. snprintf(str, BUFFER_SIZE - len, "%sMask", tmp);
  162. else
  163. strcpy(str, tmp);
  164. str = &str[len - 1];
  165. }
  166. }
  167. str = buf;
  168. }
  169. else
  170. str = NULL;
  171. if (mm)
  172. len = strlen(mm);
  173. else
  174. len = 0;
  175. if (str)
  176. len += strlen(str) + (mm == NULL ? 0 : 1);
  177. if (len >= BUFFER_SIZE)
  178. len = BUFFER_SIZE - 1;
  179. rtrn = tbGetBuffer(len + 1);
  180. rtrn[0] = '\0';
  181. if (mm != NULL) {
  182. i = strlen(mm);
  183. if (i > len)
  184. i = len;
  185. strcpy(rtrn, mm);
  186. }
  187. else {
  188. i = 0;
  189. }
  190. if (str != NULL) {
  191. if (mm != NULL) {
  192. if (format == XkbCFile)
  193. strcat(rtrn, "|");
  194. else
  195. strcat(rtrn, "+");
  196. }
  197. strncat(rtrn, str, len - i);
  198. }
  199. rtrn[len] = '\0';
  200. return rtrn;
  201. }
  202. static const char *modNames[XkbNumModifiers] = {
  203. "Shift", "Lock", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5"
  204. };
  205. char *
  206. XkbModIndexText(unsigned ndx, unsigned format)
  207. {
  208. char *rtrn;
  209. char buf[100];
  210. if (format == XkbCFile) {
  211. if (ndx < XkbNumModifiers)
  212. snprintf(buf, sizeof(buf), "%sMapIndex", modNames[ndx]);
  213. else if (ndx == XkbNoModifier)
  214. snprintf(buf, sizeof(buf), "XkbNoModifier");
  215. else
  216. snprintf(buf, sizeof(buf), "0x%02x", ndx);
  217. }
  218. else {
  219. if (ndx < XkbNumModifiers)
  220. strcpy(buf, modNames[ndx]);
  221. else if (ndx == XkbNoModifier)
  222. strcpy(buf, "none");
  223. else
  224. snprintf(buf, sizeof(buf), "ILLEGAL_%02x", ndx);
  225. }
  226. rtrn = tbGetBuffer(strlen(buf) + 1);
  227. strcpy(rtrn, buf);
  228. return rtrn;
  229. }
  230. char *
  231. XkbModMaskText(unsigned mask, unsigned format)
  232. {
  233. register int i, bit;
  234. char buf[64], *rtrn;
  235. if ((mask & 0xff) == 0xff) {
  236. if (format == XkbCFile)
  237. strcpy(buf, "0xff");
  238. else
  239. strcpy(buf, "all");
  240. }
  241. else if ((mask & 0xff) == 0) {
  242. if (format == XkbCFile)
  243. strcpy(buf, "0");
  244. else
  245. strcpy(buf, "none");
  246. }
  247. else {
  248. char *str = buf;
  249. buf[0] = '\0';
  250. for (i = 0, bit = 1; i < XkbNumModifiers; i++, bit <<= 1) {
  251. if (mask & bit) {
  252. if (str != buf) {
  253. if (format == XkbCFile)
  254. *str++ = '|';
  255. else
  256. *str++ = '+';
  257. }
  258. strcpy(str, modNames[i]);
  259. str = &str[strlen(str)];
  260. if (format == XkbCFile) {
  261. strcpy(str, "Mask");
  262. str += 4;
  263. }
  264. }
  265. }
  266. }
  267. rtrn = tbGetBuffer(strlen(buf) + 1);
  268. strcpy(rtrn, buf);
  269. return rtrn;
  270. }
  271. /***====================================================================***/
  272. /*ARGSUSED*/ char *
  273. XkbConfigText(unsigned config, unsigned format)
  274. {
  275. static char *buf;
  276. buf = tbGetBuffer(32);
  277. switch (config) {
  278. case XkmSemanticsFile:
  279. strcpy(buf, "Semantics");
  280. break;
  281. case XkmLayoutFile:
  282. strcpy(buf, "Layout");
  283. break;
  284. case XkmKeymapFile:
  285. strcpy(buf, "Keymap");
  286. break;
  287. case XkmGeometryFile:
  288. case XkmGeometryIndex:
  289. strcpy(buf, "Geometry");
  290. break;
  291. case XkmTypesIndex:
  292. strcpy(buf, "Types");
  293. break;
  294. case XkmCompatMapIndex:
  295. strcpy(buf, "CompatMap");
  296. break;
  297. case XkmSymbolsIndex:
  298. strcpy(buf, "Symbols");
  299. break;
  300. case XkmIndicatorsIndex:
  301. strcpy(buf, "Indicators");
  302. break;
  303. case XkmKeyNamesIndex:
  304. strcpy(buf, "KeyNames");
  305. break;
  306. case XkmVirtualModsIndex:
  307. strcpy(buf, "VirtualMods");
  308. break;
  309. default:
  310. sprintf(buf, "unknown(%d)", config);
  311. break;
  312. }
  313. return buf;
  314. }
  315. /***====================================================================***/
  316. char *
  317. XkbKeysymText(KeySym sym, unsigned format)
  318. {
  319. static char buf[32];
  320. if (sym == NoSymbol)
  321. strcpy(buf, "NoSymbol");
  322. else
  323. snprintf(buf, sizeof(buf), "0x%lx", (long) sym);
  324. return buf;
  325. }
  326. char *
  327. XkbKeyNameText(char *name, unsigned format)
  328. {
  329. char *buf;
  330. if (format == XkbCFile) {
  331. buf = tbGetBuffer(5);
  332. memcpy(buf, name, 4);
  333. buf[4] = '\0';
  334. }
  335. else {
  336. int len;
  337. buf = tbGetBuffer(7);
  338. buf[0] = '<';
  339. memcpy(&buf[1], name, 4);
  340. buf[5] = '\0';
  341. len = strlen(buf);
  342. buf[len++] = '>';
  343. buf[len] = '\0';
  344. }
  345. return buf;
  346. }
  347. /***====================================================================***/
  348. static const char *siMatchText[5] = {
  349. "NoneOf", "AnyOfOrNone", "AnyOf", "AllOf", "Exactly"
  350. };
  351. const char *
  352. XkbSIMatchText(unsigned type, unsigned format)
  353. {
  354. static char buf[40];
  355. const char *rtrn;
  356. switch (type & XkbSI_OpMask) {
  357. case XkbSI_NoneOf:
  358. rtrn = siMatchText[0];
  359. break;
  360. case XkbSI_AnyOfOrNone:
  361. rtrn = siMatchText[1];
  362. break;
  363. case XkbSI_AnyOf:
  364. rtrn = siMatchText[2];
  365. break;
  366. case XkbSI_AllOf:
  367. rtrn = siMatchText[3];
  368. break;
  369. case XkbSI_Exactly:
  370. rtrn = siMatchText[4];
  371. break;
  372. default:
  373. snprintf(buf, sizeof(buf), "0x%x", type & XkbSI_OpMask);
  374. return buf;
  375. }
  376. if (format == XkbCFile) {
  377. if (type & XkbSI_LevelOneOnly)
  378. snprintf(buf, sizeof(buf), "XkbSI_LevelOneOnly|XkbSI_%s", rtrn);
  379. else
  380. snprintf(buf, sizeof(buf), "XkbSI_%s", rtrn);
  381. rtrn = buf;
  382. }
  383. return rtrn;
  384. }
  385. /***====================================================================***/
  386. static const char *imWhichNames[] = {
  387. "base",
  388. "latched",
  389. "locked",
  390. "effective",
  391. "compat"
  392. };
  393. char *
  394. XkbIMWhichStateMaskText(unsigned use_which, unsigned format)
  395. {
  396. int len;
  397. unsigned i, bit, tmp;
  398. char *buf;
  399. if (use_which == 0) {
  400. buf = tbGetBuffer(2);
  401. strcpy(buf, "0");
  402. return buf;
  403. }
  404. tmp = use_which & XkbIM_UseAnyMods;
  405. for (len = i = 0, bit = 1; tmp != 0; i++, bit <<= 1) {
  406. if (tmp & bit) {
  407. tmp &= ~bit;
  408. len += strlen(imWhichNames[i]) + 1;
  409. if (format == XkbCFile)
  410. len += 9;
  411. }
  412. }
  413. buf = tbGetBuffer(len + 1);
  414. tmp = use_which & XkbIM_UseAnyMods;
  415. for (len = i = 0, bit = 1; tmp != 0; i++, bit <<= 1) {
  416. if (tmp & bit) {
  417. tmp &= ~bit;
  418. if (format == XkbCFile) {
  419. if (len != 0)
  420. buf[len++] = '|';
  421. sprintf(&buf[len], "XkbIM_Use%s", imWhichNames[i]);
  422. buf[len + 9] = toupper(buf[len + 9]);
  423. }
  424. else {
  425. if (len != 0)
  426. buf[len++] = '+';
  427. sprintf(&buf[len], "%s", imWhichNames[i]);
  428. }
  429. len += strlen(&buf[len]);
  430. }
  431. }
  432. return buf;
  433. }
  434. static const char *ctrlNames[] = {
  435. "repeatKeys",
  436. "slowKeys",
  437. "bounceKeys",
  438. "stickyKeys",
  439. "mouseKeys",
  440. "mouseKeysAccel",
  441. "accessXKeys",
  442. "accessXTimeout",
  443. "accessXFeedback",
  444. "audibleBell",
  445. "overlay1",
  446. "overlay2",
  447. "ignoreGroupLock"
  448. };
  449. char *
  450. XkbControlsMaskText(unsigned ctrls, unsigned format)
  451. {
  452. int len;
  453. unsigned i, bit, tmp;
  454. char *buf;
  455. if (ctrls == 0) {
  456. buf = tbGetBuffer(5);
  457. if (format == XkbCFile)
  458. strcpy(buf, "0");
  459. else
  460. strcpy(buf, "none");
  461. return buf;
  462. }
  463. tmp = ctrls & XkbAllBooleanCtrlsMask;
  464. for (len = i = 0, bit = 1; tmp != 0; i++, bit <<= 1) {
  465. if (tmp & bit) {
  466. tmp &= ~bit;
  467. len += strlen(ctrlNames[i]) + 1;
  468. if (format == XkbCFile)
  469. len += 7;
  470. }
  471. }
  472. buf = tbGetBuffer(len + 1);
  473. tmp = ctrls & XkbAllBooleanCtrlsMask;
  474. for (len = i = 0, bit = 1; tmp != 0; i++, bit <<= 1) {
  475. if (tmp & bit) {
  476. tmp &= ~bit;
  477. if (format == XkbCFile) {
  478. if (len != 0)
  479. buf[len++] = '|';
  480. sprintf(&buf[len], "Xkb%sMask", ctrlNames[i]);
  481. buf[len + 3] = toupper(buf[len + 3]);
  482. }
  483. else {
  484. if (len != 0)
  485. buf[len++] = '+';
  486. sprintf(&buf[len], "%s", ctrlNames[i]);
  487. }
  488. len += strlen(&buf[len]);
  489. }
  490. }
  491. return buf;
  492. }
  493. /***====================================================================***/
  494. char *
  495. XkbStringText(char *str, unsigned format)
  496. {
  497. char *buf;
  498. register char *in, *out;
  499. int len;
  500. Bool ok;
  501. if (str == NULL) {
  502. buf = tbGetBuffer(2);
  503. buf[0] = '\0';
  504. return buf;
  505. }
  506. else if (format == XkbXKMFile)
  507. return str;
  508. for (ok = TRUE, len = 0, in = str; *in != '\0'; in++, len++) {
  509. if (!isprint(*in)) {
  510. ok = FALSE;
  511. switch (*in) {
  512. case '\n':
  513. case '\t':
  514. case '\v':
  515. case '\b':
  516. case '\r':
  517. case '\f':
  518. len++;
  519. break;
  520. default:
  521. len += 4;
  522. break;
  523. }
  524. }
  525. }
  526. if (ok)
  527. return str;
  528. buf = tbGetBuffer(len + 1);
  529. for (in = str, out = buf; *in != '\0'; in++) {
  530. if (isprint(*in))
  531. *out++ = *in;
  532. else {
  533. *out++ = '\\';
  534. if (*in == '\n')
  535. *out++ = 'n';
  536. else if (*in == '\t')
  537. *out++ = 't';
  538. else if (*in == '\v')
  539. *out++ = 'v';
  540. else if (*in == '\b')
  541. *out++ = 'b';
  542. else if (*in == '\r')
  543. *out++ = 'r';
  544. else if (*in == '\f')
  545. *out++ = 'f';
  546. else if ((*in == '\033') && (format == XkbXKMFile)) {
  547. *out++ = 'e';
  548. }
  549. else {
  550. *out++ = '0';
  551. sprintf(out, "%o", *in);
  552. while (*out != '\0')
  553. out++;
  554. }
  555. }
  556. }
  557. *out++ = '\0';
  558. return buf;
  559. }
  560. /***====================================================================***/
  561. char *
  562. XkbGeomFPText(int val, unsigned format)
  563. {
  564. int whole, frac;
  565. char *buf;
  566. buf = tbGetBuffer(12);
  567. if (format == XkbCFile) {
  568. sprintf(buf, "%d", val);
  569. }
  570. else {
  571. whole = val / XkbGeomPtsPerMM;
  572. frac = val % XkbGeomPtsPerMM;
  573. if (frac != 0)
  574. sprintf(buf, "%d.%d", whole, frac);
  575. else
  576. sprintf(buf, "%d", whole);
  577. }
  578. return buf;
  579. }
  580. char *
  581. XkbDoodadTypeText(unsigned type, unsigned format)
  582. {
  583. char *buf;
  584. if (format == XkbCFile) {
  585. buf = tbGetBuffer(24);
  586. if (type == XkbOutlineDoodad)
  587. strcpy(buf, "XkbOutlineDoodad");
  588. else if (type == XkbSolidDoodad)
  589. strcpy(buf, "XkbSolidDoodad");
  590. else if (type == XkbTextDoodad)
  591. strcpy(buf, "XkbTextDoodad");
  592. else if (type == XkbIndicatorDoodad)
  593. strcpy(buf, "XkbIndicatorDoodad");
  594. else if (type == XkbLogoDoodad)
  595. strcpy(buf, "XkbLogoDoodad");
  596. else
  597. sprintf(buf, "UnknownDoodad%d", type);
  598. }
  599. else {
  600. buf = tbGetBuffer(12);
  601. if (type == XkbOutlineDoodad)
  602. strcpy(buf, "outline");
  603. else if (type == XkbSolidDoodad)
  604. strcpy(buf, "solid");
  605. else if (type == XkbTextDoodad)
  606. strcpy(buf, "text");
  607. else if (type == XkbIndicatorDoodad)
  608. strcpy(buf, "indicator");
  609. else if (type == XkbLogoDoodad)
  610. strcpy(buf, "logo");
  611. else
  612. sprintf(buf, "unknown%d", type);
  613. }
  614. return buf;
  615. }
  616. static const char *actionTypeNames[XkbSA_NumActions] = {
  617. "NoAction",
  618. "SetMods", "LatchMods", "LockMods",
  619. "SetGroup", "LatchGroup", "LockGroup",
  620. "MovePtr",
  621. "PtrBtn", "LockPtrBtn",
  622. "SetPtrDflt",
  623. "ISOLock",
  624. "Terminate", "SwitchScreen",
  625. "SetControls", "LockControls",
  626. "ActionMessage",
  627. "RedirectKey",
  628. "DeviceBtn", "LockDeviceBtn"
  629. };
  630. const char *
  631. XkbActionTypeText(unsigned type, unsigned format)
  632. {
  633. static char buf[32];
  634. const char *rtrn;
  635. if (type <= XkbSA_LastAction) {
  636. rtrn = actionTypeNames[type];
  637. if (format == XkbCFile) {
  638. snprintf(buf, sizeof(buf), "XkbSA_%s", rtrn);
  639. return buf;
  640. }
  641. return rtrn;
  642. }
  643. snprintf(buf, sizeof(buf), "Private");
  644. return buf;
  645. }
  646. /***====================================================================***/
  647. static int
  648. TryCopyStr(char *to, const char *from, int *pLeft)
  649. {
  650. register int len;
  651. if (*pLeft > 0) {
  652. len = strlen(from);
  653. if (len < ((*pLeft) - 3)) {
  654. strcat(to, from);
  655. *pLeft -= len;
  656. return TRUE;
  657. }
  658. }
  659. *pLeft = -1;
  660. return FALSE;
  661. }
  662. /*ARGSUSED*/ static Bool
  663. CopyNoActionArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  664. {
  665. return TRUE;
  666. }
  667. static Bool
  668. CopyModActionArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  669. {
  670. XkbModAction *act;
  671. unsigned tmp;
  672. act = &action->mods;
  673. tmp = XkbModActionVMods(act);
  674. TryCopyStr(buf, "modifiers=", sz);
  675. if (act->flags & XkbSA_UseModMapMods)
  676. TryCopyStr(buf, "modMapMods", sz);
  677. else if (act->real_mods || tmp) {
  678. TryCopyStr(buf,
  679. XkbVModMaskText(xkb, act->real_mods, tmp, XkbXKBFile), sz);
  680. }
  681. else
  682. TryCopyStr(buf, "none", sz);
  683. if (act->type == XkbSA_LockMods)
  684. return TRUE;
  685. if (act->flags & XkbSA_ClearLocks)
  686. TryCopyStr(buf, ",clearLocks", sz);
  687. if (act->flags & XkbSA_LatchToLock)
  688. TryCopyStr(buf, ",latchToLock", sz);
  689. return TRUE;
  690. }
  691. /*ARGSUSED*/ static Bool
  692. CopyGroupActionArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  693. {
  694. XkbGroupAction *act;
  695. char tbuf[32];
  696. act = &action->group;
  697. TryCopyStr(buf, "group=", sz);
  698. if (act->flags & XkbSA_GroupAbsolute)
  699. snprintf(tbuf, sizeof(tbuf), "%d", XkbSAGroup(act) + 1);
  700. else if (XkbSAGroup(act) < 0)
  701. snprintf(tbuf, sizeof(tbuf), "%d", XkbSAGroup(act));
  702. else
  703. snprintf(tbuf, sizeof(tbuf), "+%d", XkbSAGroup(act));
  704. TryCopyStr(buf, tbuf, sz);
  705. if (act->type == XkbSA_LockGroup)
  706. return TRUE;
  707. if (act->flags & XkbSA_ClearLocks)
  708. TryCopyStr(buf, ",clearLocks", sz);
  709. if (act->flags & XkbSA_LatchToLock)
  710. TryCopyStr(buf, ",latchToLock", sz);
  711. return TRUE;
  712. }
  713. /*ARGSUSED*/ static Bool
  714. CopyMovePtrArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  715. {
  716. XkbPtrAction *act;
  717. int x, y;
  718. char tbuf[32];
  719. act = &action->ptr;
  720. x = XkbPtrActionX(act);
  721. y = XkbPtrActionY(act);
  722. if ((act->flags & XkbSA_MoveAbsoluteX) || (x < 0))
  723. snprintf(tbuf, sizeof(tbuf), "x=%d", x);
  724. else
  725. snprintf(tbuf, sizeof(tbuf), "x=+%d", x);
  726. TryCopyStr(buf, tbuf, sz);
  727. if ((act->flags & XkbSA_MoveAbsoluteY) || (y < 0))
  728. snprintf(tbuf, sizeof(tbuf), ",y=%d", y);
  729. else
  730. snprintf(tbuf, sizeof(tbuf), ",y=+%d", y);
  731. TryCopyStr(buf, tbuf, sz);
  732. if (act->flags & XkbSA_NoAcceleration)
  733. TryCopyStr(buf, ",!accel", sz);
  734. return TRUE;
  735. }
  736. /*ARGSUSED*/ static Bool
  737. CopyPtrBtnArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  738. {
  739. XkbPtrBtnAction *act;
  740. char tbuf[32];
  741. act = &action->btn;
  742. TryCopyStr(buf, "button=", sz);
  743. if ((act->button > 0) && (act->button < 6)) {
  744. snprintf(tbuf, sizeof(tbuf), "%d", act->button);
  745. TryCopyStr(buf, tbuf, sz);
  746. }
  747. else
  748. TryCopyStr(buf, "default", sz);
  749. if (act->count > 0) {
  750. snprintf(tbuf, sizeof(tbuf), ",count=%d", act->count);
  751. TryCopyStr(buf, tbuf, sz);
  752. }
  753. if (action->type == XkbSA_LockPtrBtn) {
  754. switch (act->flags & (XkbSA_LockNoUnlock | XkbSA_LockNoLock)) {
  755. case XkbSA_LockNoLock:
  756. TryCopyStr(buf, ",affect=unlock", sz);
  757. break;
  758. case XkbSA_LockNoUnlock:
  759. TryCopyStr(buf, ",affect=lock", sz);
  760. break;
  761. case XkbSA_LockNoUnlock | XkbSA_LockNoLock:
  762. TryCopyStr(buf, ",affect=neither", sz);
  763. break;
  764. default:
  765. TryCopyStr(buf, ",affect=both", sz);
  766. break;
  767. }
  768. }
  769. return TRUE;
  770. }
  771. /*ARGSUSED*/ static Bool
  772. CopySetPtrDfltArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  773. {
  774. XkbPtrDfltAction *act;
  775. char tbuf[32];
  776. act = &action->dflt;
  777. if (act->affect == XkbSA_AffectDfltBtn) {
  778. TryCopyStr(buf, "affect=button,button=", sz);
  779. if ((act->flags & XkbSA_DfltBtnAbsolute) ||
  780. (XkbSAPtrDfltValue(act) < 0))
  781. snprintf(tbuf, sizeof(tbuf), "%d", XkbSAPtrDfltValue(act));
  782. else
  783. snprintf(tbuf, sizeof(tbuf), "+%d", XkbSAPtrDfltValue(act));
  784. TryCopyStr(buf, tbuf, sz);
  785. }
  786. return TRUE;
  787. }
  788. static Bool
  789. CopyISOLockArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  790. {
  791. XkbISOAction *act;
  792. char tbuf[64];
  793. act = &action->iso;
  794. if (act->flags & XkbSA_ISODfltIsGroup) {
  795. TryCopyStr(tbuf, "group=", sz);
  796. if (act->flags & XkbSA_GroupAbsolute)
  797. snprintf(tbuf, sizeof(tbuf), "%d", XkbSAGroup(act) + 1);
  798. else if (XkbSAGroup(act) < 0)
  799. snprintf(tbuf, sizeof(tbuf), "%d", XkbSAGroup(act));
  800. else
  801. snprintf(tbuf, sizeof(tbuf), "+%d", XkbSAGroup(act));
  802. TryCopyStr(buf, tbuf, sz);
  803. }
  804. else {
  805. unsigned tmp;
  806. tmp = XkbModActionVMods(act);
  807. TryCopyStr(buf, "modifiers=", sz);
  808. if (act->flags & XkbSA_UseModMapMods)
  809. TryCopyStr(buf, "modMapMods", sz);
  810. else if (act->real_mods || tmp) {
  811. if (act->real_mods) {
  812. TryCopyStr(buf, XkbModMaskText(act->real_mods, XkbXKBFile), sz);
  813. if (tmp)
  814. TryCopyStr(buf, "+", sz);
  815. }
  816. if (tmp)
  817. TryCopyStr(buf, XkbVModMaskText(xkb, 0, tmp, XkbXKBFile), sz);
  818. }
  819. else
  820. TryCopyStr(buf, "none", sz);
  821. }
  822. TryCopyStr(buf, ",affect=", sz);
  823. if ((act->affect & XkbSA_ISOAffectMask) == 0)
  824. TryCopyStr(buf, "all", sz);
  825. else {
  826. int nOut = 0;
  827. if ((act->affect & XkbSA_ISONoAffectMods) == 0) {
  828. TryCopyStr(buf, "mods", sz);
  829. nOut++;
  830. }
  831. if ((act->affect & XkbSA_ISONoAffectGroup) == 0) {
  832. snprintf(tbuf, sizeof(tbuf), "%sgroups", (nOut > 0 ? "+" : ""));
  833. TryCopyStr(buf, tbuf, sz);
  834. nOut++;
  835. }
  836. if ((act->affect & XkbSA_ISONoAffectPtr) == 0) {
  837. snprintf(tbuf, sizeof(tbuf), "%spointer", (nOut > 0 ? "+" : ""));
  838. TryCopyStr(buf, tbuf, sz);
  839. nOut++;
  840. }
  841. if ((act->affect & XkbSA_ISONoAffectCtrls) == 0) {
  842. snprintf(tbuf, sizeof(tbuf), "%scontrols", (nOut > 0 ? "+" : ""));
  843. TryCopyStr(buf, tbuf, sz);
  844. nOut++;
  845. }
  846. }
  847. return TRUE;
  848. }
  849. /*ARGSUSED*/ static Bool
  850. CopySwitchScreenArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  851. {
  852. XkbSwitchScreenAction *act;
  853. char tbuf[32];
  854. act = &action->screen;
  855. if ((act->flags & XkbSA_SwitchAbsolute) || (XkbSAScreen(act) < 0))
  856. snprintf(tbuf, sizeof(tbuf), "screen=%d", XkbSAScreen(act));
  857. else
  858. snprintf(tbuf, sizeof(tbuf), "screen=+%d", XkbSAScreen(act));
  859. TryCopyStr(buf, tbuf, sz);
  860. if (act->flags & XkbSA_SwitchApplication)
  861. TryCopyStr(buf, ",!same", sz);
  862. else
  863. TryCopyStr(buf, ",same", sz);
  864. return TRUE;
  865. }
  866. /*ARGSUSED*/ static Bool
  867. CopySetLockControlsArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  868. {
  869. XkbCtrlsAction *act;
  870. unsigned tmp;
  871. char tbuf[32];
  872. act = &action->ctrls;
  873. tmp = XkbActionCtrls(act);
  874. TryCopyStr(buf, "controls=", sz);
  875. if (tmp == 0)
  876. TryCopyStr(buf, "none", sz);
  877. else if ((tmp & XkbAllBooleanCtrlsMask) == XkbAllBooleanCtrlsMask)
  878. TryCopyStr(buf, "all", sz);
  879. else {
  880. int nOut = 0;
  881. if (tmp & XkbRepeatKeysMask) {
  882. snprintf(tbuf, sizeof(tbuf), "%sRepeatKeys", (nOut > 0 ? "+" : ""));
  883. TryCopyStr(buf, tbuf, sz);
  884. nOut++;
  885. }
  886. if (tmp & XkbSlowKeysMask) {
  887. snprintf(tbuf, sizeof(tbuf), "%sSlowKeys", (nOut > 0 ? "+" : ""));
  888. TryCopyStr(buf, tbuf, sz);
  889. nOut++;
  890. }
  891. if (tmp & XkbBounceKeysMask) {
  892. snprintf(tbuf, sizeof(tbuf), "%sBounceKeys", (nOut > 0 ? "+" : ""));
  893. TryCopyStr(buf, tbuf, sz);
  894. nOut++;
  895. }
  896. if (tmp & XkbStickyKeysMask) {
  897. snprintf(tbuf, sizeof(tbuf), "%sStickyKeys", (nOut > 0 ? "+" : ""));
  898. TryCopyStr(buf, tbuf, sz);
  899. nOut++;
  900. }
  901. if (tmp & XkbMouseKeysMask) {
  902. snprintf(tbuf, sizeof(tbuf), "%sMouseKeys", (nOut > 0 ? "+" : ""));
  903. TryCopyStr(buf, tbuf, sz);
  904. nOut++;
  905. }
  906. if (tmp & XkbMouseKeysAccelMask) {
  907. snprintf(tbuf, sizeof(tbuf), "%sMouseKeysAccel",
  908. (nOut > 0 ? "+" : ""));
  909. TryCopyStr(buf, tbuf, sz);
  910. nOut++;
  911. }
  912. if (tmp & XkbAccessXKeysMask) {
  913. snprintf(tbuf, sizeof(tbuf), "%sAccessXKeys",
  914. (nOut > 0 ? "+" : ""));
  915. TryCopyStr(buf, tbuf, sz);
  916. nOut++;
  917. }
  918. if (tmp & XkbAccessXTimeoutMask) {
  919. snprintf(tbuf, sizeof(tbuf), "%sAccessXTimeout",
  920. (nOut > 0 ? "+" : ""));
  921. TryCopyStr(buf, tbuf, sz);
  922. nOut++;
  923. }
  924. if (tmp & XkbAccessXFeedbackMask) {
  925. snprintf(tbuf, sizeof(tbuf), "%sAccessXFeedback",
  926. (nOut > 0 ? "+" : ""));
  927. TryCopyStr(buf, tbuf, sz);
  928. nOut++;
  929. }
  930. if (tmp & XkbAudibleBellMask) {
  931. snprintf(tbuf, sizeof(tbuf), "%sAudibleBell",
  932. (nOut > 0 ? "+" : ""));
  933. TryCopyStr(buf, tbuf, sz);
  934. nOut++;
  935. }
  936. if (tmp & XkbOverlay1Mask) {
  937. snprintf(tbuf, sizeof(tbuf), "%sOverlay1", (nOut > 0 ? "+" : ""));
  938. TryCopyStr(buf, tbuf, sz);
  939. nOut++;
  940. }
  941. if (tmp & XkbOverlay2Mask) {
  942. snprintf(tbuf, sizeof(tbuf), "%sOverlay2", (nOut > 0 ? "+" : ""));
  943. TryCopyStr(buf, tbuf, sz);
  944. nOut++;
  945. }
  946. if (tmp & XkbIgnoreGroupLockMask) {
  947. snprintf(tbuf, sizeof(tbuf), "%sIgnoreGroupLock",
  948. (nOut > 0 ? "+" : ""));
  949. TryCopyStr(buf, tbuf, sz);
  950. nOut++;
  951. }
  952. }
  953. return TRUE;
  954. }
  955. /*ARGSUSED*/ static Bool
  956. CopyActionMessageArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  957. {
  958. XkbMessageAction *act;
  959. unsigned all;
  960. char tbuf[32];
  961. act = &action->msg;
  962. all = XkbSA_MessageOnPress | XkbSA_MessageOnRelease;
  963. TryCopyStr(buf, "report=", sz);
  964. if ((act->flags & all) == 0)
  965. TryCopyStr(buf, "none", sz);
  966. else if ((act->flags & all) == all)
  967. TryCopyStr(buf, "all", sz);
  968. else if (act->flags & XkbSA_MessageOnPress)
  969. TryCopyStr(buf, "KeyPress", sz);
  970. else
  971. TryCopyStr(buf, "KeyRelease", sz);
  972. snprintf(tbuf, sizeof(tbuf), ",data[0]=0x%02x", act->message[0]);
  973. TryCopyStr(buf, tbuf, sz);
  974. snprintf(tbuf, sizeof(tbuf), ",data[1]=0x%02x", act->message[1]);
  975. TryCopyStr(buf, tbuf, sz);
  976. snprintf(tbuf, sizeof(tbuf), ",data[2]=0x%02x", act->message[2]);
  977. TryCopyStr(buf, tbuf, sz);
  978. snprintf(tbuf, sizeof(tbuf), ",data[3]=0x%02x", act->message[3]);
  979. TryCopyStr(buf, tbuf, sz);
  980. snprintf(tbuf, sizeof(tbuf), ",data[4]=0x%02x", act->message[4]);
  981. TryCopyStr(buf, tbuf, sz);
  982. snprintf(tbuf, sizeof(tbuf), ",data[5]=0x%02x", act->message[5]);
  983. TryCopyStr(buf, tbuf, sz);
  984. return TRUE;
  985. }
  986. static Bool
  987. CopyRedirectKeyArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  988. {
  989. XkbRedirectKeyAction *act;
  990. char tbuf[32], *tmp;
  991. unsigned kc;
  992. unsigned vmods, vmods_mask;
  993. act = &action->redirect;
  994. kc = act->new_key;
  995. vmods = XkbSARedirectVMods(act);
  996. vmods_mask = XkbSARedirectVModsMask(act);
  997. if (xkb && xkb->names && xkb->names->keys && (kc <= xkb->max_key_code) &&
  998. (xkb->names->keys[kc].name[0] != '\0')) {
  999. char *kn;
  1000. kn = XkbKeyNameText(xkb->names->keys[kc].name, XkbXKBFile);
  1001. snprintf(tbuf, sizeof(tbuf), "key=%s", kn);
  1002. }
  1003. else
  1004. snprintf(tbuf, sizeof(tbuf), "key=%d", kc);
  1005. TryCopyStr(buf, tbuf, sz);
  1006. if ((act->mods_mask == 0) && (vmods_mask == 0))
  1007. return TRUE;
  1008. if ((act->mods_mask == XkbAllModifiersMask) &&
  1009. (vmods_mask == XkbAllVirtualModsMask)) {
  1010. tmp = XkbVModMaskText(xkb, act->mods, vmods, XkbXKBFile);
  1011. TryCopyStr(buf, ",mods=", sz);
  1012. TryCopyStr(buf, tmp, sz);
  1013. }
  1014. else {
  1015. if ((act->mods_mask & act->mods) || (vmods_mask & vmods)) {
  1016. tmp = XkbVModMaskText(xkb, act->mods_mask & act->mods,
  1017. vmods_mask & vmods, XkbXKBFile);
  1018. TryCopyStr(buf, ",mods= ", sz);
  1019. TryCopyStr(buf, tmp, sz);
  1020. }
  1021. if ((act->mods_mask & (~act->mods)) || (vmods_mask & (~vmods))) {
  1022. tmp = XkbVModMaskText(xkb, act->mods_mask & (~act->mods),
  1023. vmods_mask & (~vmods), XkbXKBFile);
  1024. TryCopyStr(buf, ",clearMods= ", sz);
  1025. TryCopyStr(buf, tmp, sz);
  1026. }
  1027. }
  1028. return TRUE;
  1029. }
  1030. /*ARGSUSED*/ static Bool
  1031. CopyDeviceBtnArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  1032. {
  1033. XkbDeviceBtnAction *act;
  1034. char tbuf[32];
  1035. act = &action->devbtn;
  1036. snprintf(tbuf, sizeof(tbuf), "device= %d", act->device);
  1037. TryCopyStr(buf, tbuf, sz);
  1038. TryCopyStr(buf, ",button=", sz);
  1039. snprintf(tbuf, sizeof(tbuf), "%d", act->button);
  1040. TryCopyStr(buf, tbuf, sz);
  1041. if (act->count > 0) {
  1042. snprintf(tbuf, sizeof(tbuf), ",count=%d", act->count);
  1043. TryCopyStr(buf, tbuf, sz);
  1044. }
  1045. if (action->type == XkbSA_LockDeviceBtn) {
  1046. switch (act->flags & (XkbSA_LockNoUnlock | XkbSA_LockNoLock)) {
  1047. case XkbSA_LockNoLock:
  1048. TryCopyStr(buf, ",affect=unlock", sz);
  1049. break;
  1050. case XkbSA_LockNoUnlock:
  1051. TryCopyStr(buf, ",affect=lock", sz);
  1052. break;
  1053. case XkbSA_LockNoUnlock | XkbSA_LockNoLock:
  1054. TryCopyStr(buf, ",affect=neither", sz);
  1055. break;
  1056. default:
  1057. TryCopyStr(buf, ",affect=both", sz);
  1058. break;
  1059. }
  1060. }
  1061. return TRUE;
  1062. }
  1063. /*ARGSUSED*/ static Bool
  1064. CopyOtherArgs(XkbDescPtr xkb, XkbAction *action, char *buf, int *sz)
  1065. {
  1066. XkbAnyAction *act;
  1067. char tbuf[32];
  1068. act = &action->any;
  1069. snprintf(tbuf, sizeof(tbuf), "type=0x%02x", act->type);
  1070. TryCopyStr(buf, tbuf, sz);
  1071. snprintf(tbuf, sizeof(tbuf), ",data[0]=0x%02x", act->data[0]);
  1072. TryCopyStr(buf, tbuf, sz);
  1073. snprintf(tbuf, sizeof(tbuf), ",data[1]=0x%02x", act->data[1]);
  1074. TryCopyStr(buf, tbuf, sz);
  1075. snprintf(tbuf, sizeof(tbuf), ",data[2]=0x%02x", act->data[2]);
  1076. TryCopyStr(buf, tbuf, sz);
  1077. snprintf(tbuf, sizeof(tbuf), ",data[3]=0x%02x", act->data[3]);
  1078. TryCopyStr(buf, tbuf, sz);
  1079. snprintf(tbuf, sizeof(tbuf), ",data[4]=0x%02x", act->data[4]);
  1080. TryCopyStr(buf, tbuf, sz);
  1081. snprintf(tbuf, sizeof(tbuf), ",data[5]=0x%02x", act->data[5]);
  1082. TryCopyStr(buf, tbuf, sz);
  1083. snprintf(tbuf, sizeof(tbuf), ",data[6]=0x%02x", act->data[6]);
  1084. TryCopyStr(buf, tbuf, sz);
  1085. return TRUE;
  1086. }
  1087. typedef Bool (*actionCopy) (XkbDescPtr /* xkb */ ,
  1088. XkbAction * /* action */ ,
  1089. char * /* buf */ ,
  1090. int * /* sz */
  1091. );
  1092. static actionCopy copyActionArgs[XkbSA_NumActions] = {
  1093. CopyNoActionArgs /* NoAction */ ,
  1094. CopyModActionArgs /* SetMods */ ,
  1095. CopyModActionArgs /* LatchMods */ ,
  1096. CopyModActionArgs /* LockMods */ ,
  1097. CopyGroupActionArgs /* SetGroup */ ,
  1098. CopyGroupActionArgs /* LatchGroup */ ,
  1099. CopyGroupActionArgs /* LockGroup */ ,
  1100. CopyMovePtrArgs /* MovePtr */ ,
  1101. CopyPtrBtnArgs /* PtrBtn */ ,
  1102. CopyPtrBtnArgs /* LockPtrBtn */ ,
  1103. CopySetPtrDfltArgs /* SetPtrDflt */ ,
  1104. CopyISOLockArgs /* ISOLock */ ,
  1105. CopyNoActionArgs /* Terminate */ ,
  1106. CopySwitchScreenArgs /* SwitchScreen */ ,
  1107. CopySetLockControlsArgs /* SetControls */ ,
  1108. CopySetLockControlsArgs /* LockControls */ ,
  1109. CopyActionMessageArgs /* ActionMessage */ ,
  1110. CopyRedirectKeyArgs /* RedirectKey */ ,
  1111. CopyDeviceBtnArgs /* DeviceBtn */ ,
  1112. CopyDeviceBtnArgs /* LockDeviceBtn */
  1113. };
  1114. #define ACTION_SZ 256
  1115. char *
  1116. XkbActionText(XkbDescPtr xkb, XkbAction *action, unsigned format)
  1117. {
  1118. char buf[ACTION_SZ], *tmp;
  1119. int sz;
  1120. if (format == XkbCFile) {
  1121. snprintf(buf, sizeof(buf),
  1122. "{ %20s, { 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x } }",
  1123. XkbActionTypeText(action->type, XkbCFile),
  1124. action->any.data[0], action->any.data[1], action->any.data[2],
  1125. action->any.data[3], action->any.data[4], action->any.data[5],
  1126. action->any.data[6]);
  1127. }
  1128. else {
  1129. snprintf(buf, sizeof(buf), "%s(",
  1130. XkbActionTypeText(action->type, XkbXKBFile));
  1131. sz = ACTION_SZ - strlen(buf) + 2; /* room for close paren and NULL */
  1132. if (action->type < (unsigned) XkbSA_NumActions)
  1133. (*copyActionArgs[action->type]) (xkb, action, buf, &sz);
  1134. else
  1135. CopyOtherArgs(xkb, action, buf, &sz);
  1136. TryCopyStr(buf, ")", &sz);
  1137. }
  1138. tmp = tbGetBuffer(strlen(buf) + 1);
  1139. if (tmp != NULL)
  1140. strcpy(tmp, buf);
  1141. return tmp;
  1142. }
  1143. char *
  1144. XkbBehaviorText(XkbDescPtr xkb, XkbBehavior * behavior, unsigned format)
  1145. {
  1146. char buf[256], *tmp;
  1147. if (format == XkbCFile) {
  1148. if (behavior->type == XkbKB_Default)
  1149. snprintf(buf, sizeof(buf), "{ 0, 0 }");
  1150. else
  1151. snprintf(buf, sizeof(buf), "{ %3d, 0x%02x }", behavior->type,
  1152. behavior->data);
  1153. }
  1154. else {
  1155. unsigned type, permanent;
  1156. type = behavior->type & XkbKB_OpMask;
  1157. permanent = ((behavior->type & XkbKB_Permanent) != 0);
  1158. if (type == XkbKB_Lock) {
  1159. snprintf(buf, sizeof(buf), "lock= %s",
  1160. (permanent ? "Permanent" : "TRUE"));
  1161. }
  1162. else if (type == XkbKB_RadioGroup) {
  1163. int g;
  1164. g = ((behavior->data) & (~XkbKB_RGAllowNone)) + 1;
  1165. if (XkbKB_RGAllowNone & behavior->data) {
  1166. snprintf(buf, sizeof(buf), "allowNone,");
  1167. tmp = &buf[strlen(buf)];
  1168. }
  1169. else
  1170. tmp = buf;
  1171. if (permanent)
  1172. sprintf(tmp, "permanentRadioGroup= %d", g);
  1173. else
  1174. sprintf(tmp, "radioGroup= %d", g);
  1175. }
  1176. else if ((type == XkbKB_Overlay1) || (type == XkbKB_Overlay2)) {
  1177. int ndx, kc;
  1178. char *kn;
  1179. ndx = ((type == XkbKB_Overlay1) ? 1 : 2);
  1180. kc = behavior->data;
  1181. if ((xkb) && (xkb->names) && (xkb->names->keys))
  1182. kn = XkbKeyNameText(xkb->names->keys[kc].name, XkbXKBFile);
  1183. else {
  1184. static char tbuf[8];
  1185. snprintf(tbuf, sizeof(tbuf), "%d", kc);
  1186. kn = tbuf;
  1187. }
  1188. if (permanent)
  1189. snprintf(buf, sizeof(buf), "permanentOverlay%d= %s", ndx, kn);
  1190. else
  1191. snprintf(buf, sizeof(buf), "overlay%d= %s", ndx, kn);
  1192. }
  1193. }
  1194. tmp = tbGetBuffer(strlen(buf) + 1);
  1195. if (tmp != NULL)
  1196. strcpy(tmp, buf);
  1197. return tmp;
  1198. }
  1199. /***====================================================================***/
  1200. char *
  1201. XkbIndentText(unsigned size)
  1202. {
  1203. static char buf[32];
  1204. register int i;
  1205. if (size > 31)
  1206. size = 31;
  1207. for (i = 0; i < size; i++) {
  1208. buf[i] = ' ';
  1209. }
  1210. buf[size] = '\0';
  1211. return buf;
  1212. }