WmResCvt.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Motif Release 1.2.4
  29. */
  30. /*
  31. * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
  32. /*
  33. * Included Files:
  34. */
  35. #include "WmGlobal.h"
  36. #include "WmResNames.h"
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <Xm/XmosP.h>
  41. /*
  42. * include extern functions
  43. */
  44. #include "WmResParse.h"
  45. /*
  46. * Function Declarations:
  47. */
  48. unsigned char *NextToken ();
  49. long DecStrToL ();
  50. #include "WmResCvt.h"
  51. /*************************************<->*************************************
  52. *
  53. * AddWmResourceConverters (args)
  54. *
  55. *
  56. * Description:
  57. * -----------
  58. * This function adds resource type converters for mwm specific resource
  59. * types to the X Toolkit collection.
  60. *
  61. *
  62. * Inputs:
  63. * ------
  64. * XXinput = ...
  65. *
  66. * XXinput = ...
  67. *
  68. *
  69. * Outputs:
  70. * -------
  71. * XXOutput = ...
  72. *
  73. *
  74. * Comments:
  75. * --------
  76. * XXComments ...
  77. *
  78. *************************************<->***********************************/
  79. void AddWmResourceConverters (void)
  80. {
  81. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRAbsentMapBehavior,
  82. (XtConverter)WmCvtStringToAMBehavior, NULL, 0);
  83. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRCFocusPolicy,
  84. (XtConverter)WmCvtStringToCFocus, NULL, 0);
  85. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRClientDecor,
  86. (XtConverter)WmCvtStringToCDecor, NULL, 0);
  87. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRClientFunction,
  88. (XtConverter)WmCvtStringToCFunc, NULL, 0);
  89. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRFrameStyle,
  90. (XtConverter)WmCvtStringToFrameStyle, NULL, 0);
  91. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRIconDecor,
  92. (XtConverter)WmCvtStringToIDecor, NULL, 0);
  93. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRIconPlacement,
  94. (XtConverter)WmCvtStringToIPlace, NULL, 0);
  95. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRKFocusPolicy,
  96. (XtConverter)WmCvtStringToKFocus, NULL, 0);
  97. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRSize,
  98. (XtConverter)WmCvtStringToSize, NULL, 0);
  99. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRShowFeedback,
  100. (XtConverter)WmCvtStringToShowFeedback, NULL, 0);
  101. XtAppAddConverter (wmGD.mwmAppContext, XtRString, WmRUsePPosition,
  102. (XtConverter)WmCvtStringToUsePPosition, NULL, 0);
  103. } /* END OF FUNCTION AddWmResourceConverters */
  104. /*************************************<->*************************************
  105. *
  106. * WmCvtStringToAMBehavior (args, numArgs, fromVal, toVal)
  107. *
  108. *
  109. * Description:
  110. * -----------
  111. * This function converts a string to an absent map behavior description.
  112. *
  113. *
  114. * Inputs:
  115. * ------
  116. * args = additional XrmValue arguments to the converter - NULL here
  117. *
  118. * numArgs = number of XrmValue arguments - 0 here
  119. *
  120. * fromVal = resource value to convert
  121. *
  122. *
  123. * Outputs:
  124. * -------
  125. * toVal = descriptor to use to return converted value
  126. *
  127. *************************************<->***********************************/
  128. void WmCvtStringToAMBehavior (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  129. {
  130. unsigned char *pch = (unsigned char *) (fromVal->addr);
  131. unsigned char *pchNext;
  132. int len;
  133. static int cval;
  134. Boolean fHit = False;
  135. /*
  136. * Absent map behavior policies:
  137. */
  138. #define AMAP_BEHAVIOR_ADD_STR (unsigned char *)"add"
  139. #define AMAP_BEHAVIOR_MOVE_STR (unsigned char *)"move"
  140. #define AMAP_BEHAVIOR_IGNORE_STR (unsigned char *)"ignore"
  141. /*
  142. * Convert the absent map behavior policy resource value:
  143. */
  144. if (*pch && NextToken (pch, &len, &pchNext))
  145. {
  146. if ((*pch == 'A') || (*pch == 'a'))
  147. {
  148. if (StringsAreEqual (pch, AMAP_BEHAVIOR_ADD_STR, len))
  149. {
  150. cval = AMAP_BEHAVIOR_ADD;
  151. fHit = True;
  152. }
  153. }
  154. else if ((*pch == 'M') || (*pch == 'm'))
  155. {
  156. if (StringsAreEqual (pch, AMAP_BEHAVIOR_MOVE_STR, len))
  157. {
  158. cval = AMAP_BEHAVIOR_MOVE;
  159. fHit = True;
  160. }
  161. }
  162. else if ((*pch == 'I') || (*pch == 'i'))
  163. {
  164. if (StringsAreEqual (pch, AMAP_BEHAVIOR_IGNORE_STR, len))
  165. {
  166. cval = AMAP_BEHAVIOR_IGNORE;
  167. fHit = True;
  168. }
  169. }
  170. }
  171. if (!fHit)
  172. {
  173. cval = AMAP_BEHAVIOR_ADD;
  174. }
  175. (*toVal).size = sizeof (int);
  176. (*toVal).addr = (caddr_t)&cval;
  177. } /* END OF FUNCTION WmCvtStringToAMBehavior */
  178. /*************************************<->*************************************
  179. *
  180. * WmCvtStringToCFocus (args, numArgs, fromVal, toVal)
  181. *
  182. *
  183. * Description:
  184. * -----------
  185. * This function converts a string to a colormap focus policy description.
  186. *
  187. *
  188. * Inputs:
  189. * ------
  190. * args = additional XrmValue arguments to the converter - NULL here
  191. *
  192. * numArgs = number of XrmValue arguments - 0 here
  193. *
  194. * fromVal = resource value to convert
  195. *
  196. *
  197. * Outputs:
  198. * -------
  199. * toVal = descriptor to use to return converted value
  200. *
  201. *************************************<->***********************************/
  202. void WmCvtStringToCFocus (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  203. {
  204. unsigned char *pch = (unsigned char *) (fromVal->addr);
  205. unsigned char *pchNext;
  206. int len;
  207. static int cval;
  208. Boolean fHit = False;
  209. /*
  210. * Colormap focus policies:
  211. */
  212. #define CMAP_FOCUS_EXPLICIT_STR (unsigned char *)"explicit"
  213. #define CMAP_FOCUS_KEYBOARD_STR (unsigned char *)"keyboard"
  214. #define CMAP_FOCUS_POINTER_STR (unsigned char *)"pointer"
  215. /*
  216. * Convert the colormap focus policy resource value:
  217. */
  218. if (*pch && NextToken (pch, &len, &pchNext))
  219. {
  220. if ((*pch == 'E') || (*pch == 'e'))
  221. {
  222. if (StringsAreEqual (pch, CMAP_FOCUS_EXPLICIT_STR, len))
  223. {
  224. cval = CMAP_FOCUS_EXPLICIT;
  225. fHit = True;
  226. }
  227. }
  228. else if ((*pch == 'K') || (*pch == 'k'))
  229. {
  230. if (StringsAreEqual (pch, CMAP_FOCUS_KEYBOARD_STR, len))
  231. {
  232. cval = CMAP_FOCUS_KEYBOARD;
  233. fHit = True;
  234. }
  235. }
  236. else if ((*pch == 'P') || (*pch == 'p'))
  237. {
  238. if (StringsAreEqual (pch, CMAP_FOCUS_POINTER_STR, len))
  239. {
  240. cval = CMAP_FOCUS_POINTER;
  241. fHit = True;
  242. }
  243. }
  244. }
  245. if (!fHit)
  246. {
  247. cval = CMAP_FOCUS_KEYBOARD;
  248. }
  249. (*toVal).size = sizeof (int);
  250. (*toVal).addr = (caddr_t)&cval;
  251. } /* END OF FUNCTION WmCvtStringToCFocus */
  252. /*************************************<->*************************************
  253. *
  254. * WmCvtStringToCDecor (args, numArgs, fromVal, toVal)
  255. *
  256. *
  257. * Description:
  258. * -----------
  259. * This function converts a string to a mwm client window frame decoration
  260. * description.
  261. *
  262. *
  263. * Inputs:
  264. * ------
  265. * args = NULL (don't care)
  266. *
  267. * numArgs = 0 (don't care)
  268. *
  269. * fromVal = resource value to convert
  270. *
  271. *
  272. * Outputs:
  273. * -------
  274. * toVal = descriptor to use to return converted value
  275. *
  276. *
  277. * Comments:
  278. * --------
  279. * o Accepts the following syntax:
  280. *
  281. * CDecor ::= [sign] decor_spec [decor_spec ...]
  282. *
  283. * sign ::= ['+' | '-']
  284. *
  285. * decor_spec ::= [sign] decor_name
  286. *
  287. * decor_name ::= "all" | "none" | "title" | "titlebar" |
  288. * "menu" | "minimize" | "maximize" | "resize"
  289. *
  290. *************************************<->***********************************/
  291. void WmCvtStringToCDecor (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  292. {
  293. unsigned char *pch = (unsigned char *) (fromVal->addr);
  294. unsigned char *pchNext;
  295. int len;
  296. static int cval;
  297. Boolean fHit = False;
  298. Boolean fAddNext = True;
  299. /*
  300. * Client decoration parts:
  301. */
  302. #define WM_DECOR_ALL_STR (unsigned char *)"all"
  303. #define WM_DECOR_NONE_STR (unsigned char *)"none"
  304. #define WM_DECOR_BORDER_STR (unsigned char *)"border"
  305. #define WM_DECOR_RESIZEH_STR (unsigned char *)"resizeh"
  306. #define WM_DECOR_TITLE_STR (unsigned char *)"title"
  307. #define WM_DECOR_TITLEBAR_STR (unsigned char *)"titlebar"
  308. #define WM_DECOR_MINIMIZE_STR (unsigned char *)"minimize"
  309. #define WM_DECOR_MAXIMIZE_STR (unsigned char *)"maximize"
  310. #define WM_DECOR_MENU_STR (unsigned char *)"menu"
  311. #define WM_DECOR_RESIZE_STR (unsigned char *)"resize"
  312. /*
  313. * Check first token. If '-' we subtract from all decoration.
  314. * Otherwise, we start with no decoration and add things in.
  315. */
  316. if (*pch &&
  317. (NextToken (pch, &len, &pchNext)) &&
  318. (*pch == '-'))
  319. {
  320. cval = WM_DECOR_ALL;
  321. fHit = True;
  322. }
  323. else
  324. {
  325. cval = WM_DECOR_NONE;
  326. }
  327. while (*pch && NextToken(pch, &len, &pchNext))
  328. {
  329. /*
  330. * Strip off "sign" if prepended to another token, and process
  331. * that token the next time through.
  332. */
  333. if (*pch == '+')
  334. {
  335. if (len != 1)
  336. {
  337. pchNext = pch + 1;
  338. }
  339. fAddNext = TRUE;
  340. }
  341. else if (*pch == '-')
  342. {
  343. if (len != 1)
  344. {
  345. pchNext = pch + 1;
  346. }
  347. fAddNext = FALSE;
  348. }
  349. else if ((*pch == 'A') || (*pch == 'a'))
  350. {
  351. if (StringsAreEqual(pch, WM_DECOR_ALL_STR,len))
  352. {
  353. cval = fAddNext ? (cval | WM_DECOR_ALL) :
  354. (cval & ~WM_DECOR_ALL);
  355. fHit = True;
  356. }
  357. }
  358. else if ((*pch == 'N') || (*pch == 'n'))
  359. {
  360. if (StringsAreEqual(pch, WM_DECOR_NONE_STR,len))
  361. {
  362. /* don't bother adding or subtracting nothing */
  363. fHit = True;
  364. }
  365. }
  366. else if ((*pch == 'T') || (*pch == 't'))
  367. {
  368. if (StringsAreEqual(pch, WM_DECOR_TITLE_STR,len))
  369. {
  370. cval = fAddNext ? (cval | WM_DECOR_TITLE) :
  371. (cval & ~WM_DECOR_TITLEBAR);
  372. fHit = True;
  373. }
  374. else if (StringsAreEqual(pch, WM_DECOR_TITLEBAR_STR,len))
  375. {
  376. cval = fAddNext ? (cval | WM_DECOR_TITLEBAR) :
  377. (cval & ~WM_DECOR_TITLEBAR);
  378. fHit = True;
  379. }
  380. }
  381. else if ((*pch == 'M') || (*pch == 'm'))
  382. {
  383. if (StringsAreEqual(pch, WM_DECOR_MINIMIZE_STR,len))
  384. {
  385. cval = fAddNext ? (cval | WM_DECOR_MINIMIZE) :
  386. (cval & ~MWM_DECOR_MINIMIZE);
  387. fHit = True;
  388. }
  389. else if (StringsAreEqual(pch, WM_DECOR_MAXIMIZE_STR,len))
  390. {
  391. cval = fAddNext ? (cval | WM_DECOR_MAXIMIZE) :
  392. (cval & ~MWM_DECOR_MAXIMIZE);
  393. fHit = True;
  394. }
  395. else if (StringsAreEqual(pch, WM_DECOR_MENU_STR,len))
  396. {
  397. cval = fAddNext ? (cval | WM_DECOR_SYSTEM) :
  398. (cval & ~MWM_DECOR_MENU);
  399. fHit = True;
  400. }
  401. }
  402. else if ((*pch == 'R') || (*pch == 'r'))
  403. {
  404. if (StringsAreEqual(pch, WM_DECOR_RESIZE_STR,len) ||
  405. StringsAreEqual(pch, WM_DECOR_RESIZEH_STR,len))
  406. {
  407. cval = fAddNext ? (cval | WM_DECOR_RESIZEH) :
  408. (cval & ~MWM_DECOR_RESIZEH);
  409. fHit = True;
  410. }
  411. }
  412. else if ((*pch == 'B') || (*pch == 'b'))
  413. {
  414. if (StringsAreEqual(pch, WM_DECOR_BORDER_STR,len))
  415. {
  416. cval = fAddNext ? (cval | WM_DECOR_BORDER) :
  417. (cval & ~WM_DECOR_BORDER);
  418. fHit = True;
  419. }
  420. }
  421. pch = pchNext;
  422. }
  423. if (!fHit) cval = WM_DECOR_ALL;
  424. (*toVal).size = sizeof (int);
  425. (*toVal).addr = (caddr_t) &cval;
  426. } /* END OF FUNCTION WmCvtStringToCDecor */
  427. /*************************************<->*************************************
  428. *
  429. * WmCvtStringToCFunc (args, numArgs, fromVal, toVal)
  430. *
  431. *
  432. * Description:
  433. * -----------
  434. * This function converts a string to a mwm client-applicable function
  435. * description.
  436. *
  437. *
  438. * Inputs:
  439. * ------
  440. * args = NULL (don't care)
  441. *
  442. * numArgs = 0 (don't care)
  443. *
  444. * fromVal = resource value to convert
  445. *
  446. *
  447. * Outputs:
  448. * -------
  449. * toVal = descriptor to use to return converted value
  450. *
  451. *
  452. * Comments:
  453. * --------
  454. * o Accepts the following syntax:
  455. *
  456. * CFunc ::= [sign] func_spec [func_spec ...]
  457. *
  458. * sign ::= ['+' | '-']
  459. *
  460. * func_spec ::= [sign] func_name
  461. *
  462. * func_name ::= "all" | "none" | "resize" | "move" | "minimize" |
  463. * "maximize" | "close"
  464. *
  465. *************************************<->***********************************/
  466. void WmCvtStringToCFunc (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  467. {
  468. unsigned char *pch = (unsigned char *) (fromVal->addr);
  469. unsigned char *pchNext;
  470. int len;
  471. static int cval;
  472. Boolean fHit = False;
  473. Boolean fAddNext = True;
  474. /*
  475. * Client-applicable functions:
  476. */
  477. #define WM_FUNC_ALL_STR (unsigned char *)"all"
  478. #define WM_FUNC_NONE_STR (unsigned char *)"none"
  479. #define WM_FUNC_RESIZE_STR (unsigned char *)"resize"
  480. #define WM_FUNC_MOVE_STR (unsigned char *)"move"
  481. #define WM_FUNC_MINIMIZE_STR (unsigned char *)"minimize"
  482. #define WM_FUNC_MAXIMIZE_STR (unsigned char *)"maximize"
  483. #define WM_FUNC_CLOSE_STR (unsigned char *)"close"
  484. /*
  485. * Check first token. If '-' we subtract from all functions.
  486. * Otherwise, we start with no functions and add things in.
  487. */
  488. if (*pch &&
  489. (NextToken (pch, &len, &pchNext)) &&
  490. (*pch == '-'))
  491. {
  492. cval = WM_FUNC_ALL;
  493. fHit = True;
  494. }
  495. else
  496. {
  497. cval = WM_FUNC_NONE;
  498. }
  499. while (*pch && NextToken(pch, &len, &pchNext))
  500. {
  501. /*
  502. * Strip off "sign" if prepended to another token, and process
  503. * that token the next time through.
  504. */
  505. if (*pch == '+')
  506. {
  507. if (len != 1)
  508. {
  509. pchNext = pch + 1;
  510. }
  511. fAddNext = TRUE;
  512. }
  513. else if (*pch == '-')
  514. {
  515. if (len != 1)
  516. {
  517. pchNext = pch + 1;
  518. }
  519. fAddNext = FALSE;
  520. }
  521. else if ((*pch == 'A') || (*pch == 'a'))
  522. {
  523. if (StringsAreEqual(pch, WM_FUNC_ALL_STR,len))
  524. {
  525. cval = fAddNext ? (cval | WM_FUNC_ALL) :
  526. (cval & ~WM_FUNC_ALL);
  527. fHit = True;
  528. }
  529. }
  530. else if ((*pch == 'N') || (*pch == 'n'))
  531. {
  532. if (StringsAreEqual(pch, WM_FUNC_NONE_STR,len))
  533. {
  534. /* don't bother adding or subtracting nothing */
  535. fHit = True;
  536. }
  537. }
  538. else if ((*pch == 'R') || (*pch == 'r'))
  539. {
  540. if (StringsAreEqual(pch, WM_FUNC_RESIZE_STR,len))
  541. {
  542. cval = fAddNext ? (cval | MWM_FUNC_RESIZE) :
  543. (cval & ~MWM_FUNC_RESIZE);
  544. fHit = True;
  545. }
  546. }
  547. else if ((*pch == 'M') || (*pch == 'm'))
  548. {
  549. if (StringsAreEqual(pch, WM_FUNC_MINIMIZE_STR,len))
  550. {
  551. cval = fAddNext ? (cval | MWM_FUNC_MINIMIZE) :
  552. (cval & ~MWM_FUNC_MINIMIZE);
  553. fHit = True;
  554. }
  555. else if (StringsAreEqual(pch, WM_FUNC_MAXIMIZE_STR,len))
  556. {
  557. cval = fAddNext ? (cval | MWM_FUNC_MAXIMIZE) :
  558. (cval & ~MWM_FUNC_MAXIMIZE);
  559. fHit = True;
  560. }
  561. else if (StringsAreEqual(pch, WM_FUNC_MOVE_STR,len))
  562. {
  563. cval = fAddNext ? (cval | MWM_FUNC_MOVE) :
  564. (cval & ~MWM_FUNC_MOVE);
  565. fHit = True;
  566. }
  567. }
  568. else if ((*pch == 'C') || (*pch == 'c'))
  569. {
  570. if (StringsAreEqual(pch, WM_FUNC_CLOSE_STR,len))
  571. {
  572. cval = fAddNext ? (cval | MWM_FUNC_CLOSE) :
  573. (cval & ~MWM_FUNC_CLOSE);
  574. fHit = True;
  575. }
  576. }
  577. pch = pchNext;
  578. }
  579. if (!fHit) cval = WM_FUNC_ALL;
  580. (*toVal).size = sizeof (int);
  581. (*toVal).addr = (caddr_t) &cval;
  582. } /* END OF FUNCTION WmCvtStringToCFunc */
  583. /*************************************<->*************************************
  584. *
  585. * WmCvtStringToFrameStyle (args, numArgs, fromVal, toVal)
  586. *
  587. *
  588. * Description:
  589. * -----------
  590. * This function converts a string to a frame style description.
  591. *
  592. *
  593. * Inputs:
  594. * ------
  595. * args = NULL (don't care)
  596. *
  597. * numArgs = 0 (don't care)
  598. *
  599. * fromVal = resource value to convert
  600. *
  601. *
  602. * Outputs:
  603. * -------
  604. * toVal = descriptor to use to return converted value
  605. *
  606. *************************************<->***********************************/
  607. void WmCvtStringToFrameStyle (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  608. {
  609. unsigned char *pch = (unsigned char *) (fromVal->addr);
  610. unsigned char *pchNext;
  611. int len;
  612. static FrameStyle frameStyle;
  613. Boolean fHit = False;
  614. #define FRAME_STYLE_RECESSED_STR (unsigned char *)"recessed"
  615. #define FRAME_STYLE_SLAB_STR (unsigned char *)"slab"
  616. /*
  617. * Convert the resource value:
  618. */
  619. if (*pch && NextToken (pch, &len, &pchNext))
  620. {
  621. if ((*pch == 'R') || (*pch == 'r'))
  622. {
  623. if (StringsAreEqual (pch, FRAME_STYLE_RECESSED_STR, len))
  624. {
  625. frameStyle = WmRECESSED;
  626. fHit = True;
  627. }
  628. }
  629. else if (StringsAreEqual (pch, FRAME_STYLE_SLAB_STR, len))
  630. {
  631. frameStyle = WmSLAB;
  632. fHit = True;
  633. }
  634. }
  635. if (!fHit)
  636. {
  637. frameStyle = WmRECESSED;
  638. }
  639. (*toVal).size = sizeof (FrameStyle);
  640. (*toVal).addr = (caddr_t)&frameStyle;
  641. } /* END OF FUNCTION WmCvtStringToFrameStyle */
  642. /*************************************<->*************************************
  643. *
  644. * WmCvtStringToIDecor (args, numArgs, fromVal, toVal)
  645. *
  646. *
  647. * Description:
  648. * -----------
  649. * This function converts a string to an icon decoration description.
  650. *
  651. *
  652. * Inputs:
  653. * ------
  654. * args = NULL (don't care)
  655. *
  656. * numArgs = 0 (don't care)
  657. *
  658. * fromVal = resource value to convert
  659. *
  660. *
  661. * Outputs:
  662. * -------
  663. * toVal = descriptor to use to return converted value
  664. *
  665. *************************************<->***********************************/
  666. void WmCvtStringToIDecor (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  667. {
  668. unsigned char *pch = (unsigned char *) (fromVal->addr);
  669. unsigned char *pchNext;
  670. int len;
  671. static int cval;
  672. Boolean fHit = False;
  673. /*
  674. * Icon decoration parts:
  675. */
  676. #define ICON_DECOR_IMAGE_STR (unsigned char *)"image"
  677. #define ICON_DECOR_LABEL_STR (unsigned char *)"label"
  678. #define ICON_DECOR_ACTIVE_LABEL_STR (unsigned char *)"activelabel"
  679. /*
  680. * Convert the icon decoration resource value:
  681. */
  682. cval = 0;
  683. while (*pch && NextToken (pch, &len, &pchNext))
  684. {
  685. if ((*pch == 'A') || (*pch == 'a'))
  686. {
  687. if (StringsAreEqual (pch, ICON_DECOR_ACTIVE_LABEL_STR, len))
  688. {
  689. cval |= ICON_ACTIVE_LABEL_PART;
  690. fHit = True;
  691. }
  692. }
  693. else if ((*pch == 'I') || (*pch == 'i'))
  694. {
  695. if (StringsAreEqual (pch, ICON_DECOR_IMAGE_STR, len))
  696. {
  697. cval |= ICON_IMAGE_PART;
  698. fHit = True;
  699. }
  700. }
  701. else if ((*pch == 'L') || (*pch == 'l'))
  702. {
  703. if (StringsAreEqual (pch, ICON_DECOR_LABEL_STR, len))
  704. {
  705. cval |= ICON_LABEL_PART;
  706. fHit = True;
  707. }
  708. }
  709. pch = pchNext;
  710. }
  711. /*
  712. * If we didn't match anything or only have the active label
  713. * (which is just a modifier) then give 'em the whole ball of wax.
  714. */
  715. if (!fHit || cval == ICON_ACTIVE_LABEL_PART)
  716. {
  717. cval = ICON_LABEL_PART | ICON_IMAGE_PART | ICON_ACTIVE_LABEL_PART;
  718. }
  719. (*toVal).size = sizeof (int);
  720. (*toVal).addr = (caddr_t) &cval;
  721. } /* END OF FUNCTION WmCvtStringToIDecor */
  722. /*************************************<->*************************************
  723. *
  724. * WmCvtStringToIPlace (args, numArgs, fromVal, toVal)
  725. *
  726. *
  727. * Description:
  728. * -----------
  729. * This function converts a string to an icon placement scheme description.
  730. *
  731. *
  732. * Inputs:
  733. * ------
  734. * args = NULL (don't care)
  735. *
  736. * numArgs = 0 (don't care)
  737. *
  738. * fromVal = resource value to convert
  739. *
  740. *
  741. * Outputs:
  742. * -------
  743. * toVal = descriptor to use to return converted value
  744. *
  745. *************************************<->***********************************/
  746. void WmCvtStringToIPlace (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  747. {
  748. unsigned char *pch = (unsigned char *) (fromVal->addr);
  749. unsigned char *pchNext;
  750. int len;
  751. static int cval;
  752. Boolean fPrimarySet = False;
  753. Boolean fSecondarySet = False;
  754. /*
  755. * Icon placement layout values:
  756. */
  757. #define ICON_PLACE_BOTTOM_STR (unsigned char *)"bottom"
  758. #define ICON_PLACE_LEFT_STR (unsigned char *)"left"
  759. #define ICON_PLACE_RIGHT_STR (unsigned char *)"right"
  760. #define ICON_PLACE_TOP_STR (unsigned char *)"top"
  761. #define ICON_PLACE_TIGHT_STR (unsigned char *)"tight"
  762. /*
  763. * Convert the icon placement resource value:
  764. */
  765. cval = 0;
  766. while (*pch && NextToken (pch, &len, &pchNext))
  767. {
  768. if ((*pch == 'B') || (*pch == 'b'))
  769. {
  770. if (StringsAreEqual (pch, ICON_PLACE_BOTTOM_STR, len))
  771. {
  772. if (!fPrimarySet)
  773. {
  774. cval |= ICON_PLACE_BOTTOM_PRIMARY;
  775. fPrimarySet = True;
  776. }
  777. else if (!fSecondarySet)
  778. {
  779. if (!(cval &
  780. (ICON_PLACE_BOTTOM_PRIMARY | ICON_PLACE_TOP_PRIMARY)))
  781. {
  782. cval |= ICON_PLACE_BOTTOM_SECONDARY;
  783. fSecondarySet = True;
  784. }
  785. }
  786. }
  787. }
  788. else if ((*pch == 'L') || (*pch == 'l'))
  789. {
  790. if (StringsAreEqual (pch, ICON_PLACE_LEFT_STR, len))
  791. {
  792. if (!fPrimarySet)
  793. {
  794. cval |= ICON_PLACE_LEFT_PRIMARY;
  795. fPrimarySet = True;
  796. }
  797. else if (!fSecondarySet)
  798. {
  799. if (!(cval &
  800. (ICON_PLACE_LEFT_PRIMARY | ICON_PLACE_RIGHT_PRIMARY)))
  801. {
  802. cval |= ICON_PLACE_LEFT_SECONDARY;
  803. fSecondarySet = True;
  804. }
  805. }
  806. }
  807. }
  808. else if ((*pch == 'R') || (*pch == 'r'))
  809. {
  810. if (StringsAreEqual (pch, ICON_PLACE_RIGHT_STR, len))
  811. {
  812. if (!fPrimarySet)
  813. {
  814. cval |= ICON_PLACE_RIGHT_PRIMARY;
  815. fPrimarySet = True;
  816. }
  817. else if (!fSecondarySet)
  818. {
  819. if (!(cval &
  820. (ICON_PLACE_RIGHT_PRIMARY | ICON_PLACE_LEFT_PRIMARY)))
  821. {
  822. cval |= ICON_PLACE_RIGHT_SECONDARY;
  823. fSecondarySet = True;
  824. }
  825. }
  826. }
  827. }
  828. else if ((*pch == 'T') || (*pch == 't'))
  829. {
  830. if (StringsAreEqual (pch, ICON_PLACE_TOP_STR, len))
  831. {
  832. if (!fPrimarySet)
  833. {
  834. cval |= ICON_PLACE_TOP_PRIMARY;
  835. fPrimarySet = True;
  836. }
  837. else if (!fSecondarySet)
  838. {
  839. if (!(cval &
  840. (ICON_PLACE_TOP_PRIMARY | ICON_PLACE_BOTTOM_PRIMARY)))
  841. {
  842. cval |= ICON_PLACE_TOP_SECONDARY;
  843. fSecondarySet = True;
  844. }
  845. }
  846. }
  847. else if (StringsAreEqual (pch, ICON_PLACE_TIGHT_STR, len))
  848. {
  849. cval |= ICON_PLACE_TIGHT;
  850. }
  851. }
  852. pch = pchNext;
  853. }
  854. if (!fPrimarySet)
  855. {
  856. cval = ICON_PLACE_LEFT_PRIMARY;
  857. }
  858. if (!fSecondarySet)
  859. {
  860. if (cval & (ICON_PLACE_LEFT_PRIMARY | ICON_PLACE_RIGHT_PRIMARY))
  861. {
  862. cval |= ICON_PLACE_BOTTOM_SECONDARY;
  863. }
  864. else
  865. {
  866. cval |= ICON_PLACE_LEFT_SECONDARY;
  867. }
  868. }
  869. (*toVal).size = sizeof (int);
  870. (*toVal).addr = (caddr_t) &cval;
  871. } /* END OF FUNCTION WmCvtStringToIPlace */
  872. /*************************************<->*************************************
  873. *
  874. * WmCvtStringToKFocus (args, numArgs, fromVal, toVal)
  875. *
  876. *
  877. * Description:
  878. * -----------
  879. * This function converts a string to a keyboard focus policy description.
  880. *
  881. *
  882. * Inputs:
  883. * ------
  884. * args = NULL (don't care)
  885. *
  886. * numArgs = 0 (don't care)
  887. *
  888. * fromVal = resource value to convert
  889. *
  890. *
  891. * Outputs:
  892. * -------
  893. * toVal = descriptor to use to return converted value
  894. *
  895. *************************************<->***********************************/
  896. void WmCvtStringToKFocus (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  897. {
  898. unsigned char *pch = (unsigned char *) (fromVal->addr);
  899. unsigned char *pchNext;
  900. int len;
  901. static int cval;
  902. Boolean fHit = False;
  903. /*
  904. * Keyboard focus policies:
  905. */
  906. #define KEYBOARD_FOCUS_EXPLICIT_STR (unsigned char *)"explicit"
  907. #define KEYBOARD_FOCUS_POINTER_STR (unsigned char *)"pointer"
  908. /*
  909. * Convert the keyboard focus policy resource value:
  910. */
  911. if (*pch && NextToken (pch, &len, &pchNext))
  912. {
  913. if ((*pch == 'E') || (*pch == 'e'))
  914. {
  915. if (StringsAreEqual (pch, KEYBOARD_FOCUS_EXPLICIT_STR, len))
  916. {
  917. cval = KEYBOARD_FOCUS_EXPLICIT;
  918. fHit = True;
  919. }
  920. }
  921. else if ((*pch == 'P') || (*pch == 'p'))
  922. {
  923. if (StringsAreEqual (pch, KEYBOARD_FOCUS_POINTER_STR, len))
  924. {
  925. cval = KEYBOARD_FOCUS_POINTER;
  926. fHit = True;
  927. }
  928. }
  929. }
  930. if (!fHit)
  931. {
  932. #if defined(sun)
  933. cval = KEYBOARD_FOCUS_POINTER;
  934. #else
  935. cval = KEYBOARD_FOCUS_EXPLICIT;
  936. #endif
  937. }
  938. (*toVal).size = sizeof (int);
  939. (*toVal).addr = (caddr_t)&cval;
  940. } /* END OF FUNCTION WmCvtStringToKFocus */
  941. /*************************************<->*************************************
  942. *
  943. * WmCvtStringToSize (args, numArgs, fromVal, toVal)
  944. *
  945. *
  946. * Description:
  947. * -----------
  948. * This function converts a string to a size description (<width>x<height>).
  949. *
  950. *
  951. * Inputs:
  952. * ------
  953. * args = NULL (don't care)
  954. *
  955. * numArgs = 0 (don't care)
  956. *
  957. * fromVal = resource value to convert
  958. *
  959. *
  960. * Outputs:
  961. * -------
  962. * toVal = descriptor to use to return converted value
  963. *
  964. *************************************<->***********************************/
  965. void WmCvtStringToSize (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  966. {
  967. unsigned char *pch = (unsigned char *) (fromVal->addr);
  968. unsigned char *pchNext;
  969. static WHSize cval;
  970. int len;
  971. /*
  972. * Convenience values for WmSize:
  973. */
  974. #define VERTICAL_STR (unsigned char *)"vertical"
  975. #define HORIZONTAL_STR (unsigned char *)"horizontal"
  976. /*
  977. * Convert the size resource value. The syntax is "<width>[xX]<height>"
  978. * OR it is the string 'vertical' or 'horizontal'. It's kinda neat that
  979. * BIGSIZE is a legal Dimension so that we get vertical and horizontal
  980. * for free.
  981. */
  982. cval.width = 0;
  983. cval.height = 0;
  984. if (*pch)
  985. {
  986. cval.width = (int) DecStrToL (pch, &pchNext);
  987. if (!((cval.width == 0) && (pchNext == pch)))
  988. {
  989. /*
  990. * Width was converted.
  991. * Check for a delimiter (must be 'x' or 'X'):
  992. */
  993. pch = pchNext;
  994. if (*pch && ((*pch == 'x') || (*pch == 'X')))
  995. {
  996. /*
  997. * Delimiter found now get the height:
  998. */
  999. pch++;
  1000. cval.height = (int) DecStrToL (pch, &pchNext);
  1001. }
  1002. }
  1003. else
  1004. {
  1005. if (*pch && NextToken (pch, &len, &pchNext))
  1006. {
  1007. if ((*pch == 'V') || (*pch == 'v'))
  1008. {
  1009. if (StringsAreEqual (pch, VERTICAL_STR, len))
  1010. {
  1011. cval.height = BIGSIZE;
  1012. }
  1013. }
  1014. else if ((*pch == 'H') || (*pch == 'h'))
  1015. {
  1016. if (StringsAreEqual (pch, HORIZONTAL_STR, len))
  1017. {
  1018. cval.width = BIGSIZE;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. }
  1024. /* !!! check for the maximum maximum sizes !!! */
  1025. (*toVal).size = sizeof (WHSize);
  1026. (*toVal).addr = (caddr_t)&cval;
  1027. } /* END OF FUNCTION WmCvtStringToSize */
  1028. /*************************************<->*************************************
  1029. *
  1030. * WmCvtStringToShowFeedback (args, numArgs, fromVal, toVal)
  1031. *
  1032. *
  1033. * Description:
  1034. * -----------
  1035. * This function converts a string to a value for the showFeedback flag set.
  1036. *
  1037. *
  1038. * Inputs:
  1039. * ------
  1040. * args = NULL (don't care)
  1041. *
  1042. * numArgs = 0 (don't care)
  1043. *
  1044. * fromVal = resource value to convert
  1045. *
  1046. *
  1047. * Outputs:
  1048. * -------
  1049. * toVal = descriptor to use to return converted value
  1050. *
  1051. *************************************<->***********************************/
  1052. void WmCvtStringToShowFeedback (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  1053. {
  1054. unsigned char *pch = (unsigned char *) (fromVal->addr);
  1055. unsigned char *pchNext;
  1056. int len;
  1057. static int cval;
  1058. Boolean fHit = False;
  1059. Boolean fAddNext = True;
  1060. /*
  1061. * Names of feedback options
  1062. */
  1063. #define SHOW_FB_ALL_STR (unsigned char *)"all"
  1064. #define SHOW_FB_BEHAVIOR_STR (unsigned char *)"behavior"
  1065. #define SHOW_FB_KILL_STR (unsigned char *)"kill"
  1066. #define SHOW_FB_MOVE_STR (unsigned char *)"move"
  1067. #define SHOW_FB_NONE_STR (unsigned char *)"none"
  1068. #define SHOW_FB_PLACEMENT_STR (unsigned char *)"placement"
  1069. #define SHOW_FB_QUIT_STR (unsigned char *)"quit"
  1070. #define SHOW_FB_RESIZE_STR (unsigned char *)"resize"
  1071. #define SHOW_FB_RESTART_STR (unsigned char *)"restart"
  1072. /*
  1073. * Check first token. If '-' we subtract from all functions.
  1074. * Otherwise, we start with no functions and add things in.
  1075. */
  1076. if (*pch &&
  1077. (NextToken (pch, &len, &pchNext)) &&
  1078. (*pch == '-'))
  1079. {
  1080. cval = WM_SHOW_FB_DEFAULT;
  1081. fHit = True;
  1082. }
  1083. else
  1084. {
  1085. cval = WM_SHOW_FB_NONE;
  1086. }
  1087. /*
  1088. * Convert the feedback option resource value:
  1089. */
  1090. while (*pch && NextToken (pch, &len, &pchNext))
  1091. {
  1092. /*
  1093. * Strip off "sign" if prepended to another token, and process
  1094. * that token the next time through.
  1095. */
  1096. if (*pch == '+')
  1097. {
  1098. if (len != 1)
  1099. {
  1100. pchNext = pch + 1;
  1101. }
  1102. fAddNext = TRUE;
  1103. }
  1104. else if (*pch == '-')
  1105. {
  1106. if (len != 1)
  1107. {
  1108. pchNext = pch + 1;
  1109. }
  1110. fAddNext = FALSE;
  1111. }
  1112. if ((*pch == 'A') || (*pch == 'a'))
  1113. {
  1114. if (StringsAreEqual (pch, SHOW_FB_ALL_STR, len))
  1115. {
  1116. cval = fAddNext ? (cval | WM_SHOW_FB_ALL) :
  1117. (cval & ~WM_SHOW_FB_ALL);
  1118. fHit = True;
  1119. }
  1120. }
  1121. else if ((*pch == 'B') || (*pch == 'b'))
  1122. {
  1123. if (StringsAreEqual (pch, SHOW_FB_BEHAVIOR_STR, len))
  1124. {
  1125. cval = fAddNext ? (cval | WM_SHOW_FB_BEHAVIOR) :
  1126. (cval & ~WM_SHOW_FB_BEHAVIOR);
  1127. fHit = True;
  1128. }
  1129. }
  1130. else if ((*pch == 'K') || (*pch == 'k'))
  1131. {
  1132. if (StringsAreEqual (pch, SHOW_FB_KILL_STR, len))
  1133. {
  1134. cval = fAddNext ? (cval | WM_SHOW_FB_KILL) :
  1135. (cval & ~WM_SHOW_FB_KILL);
  1136. fHit = True;
  1137. }
  1138. }
  1139. else if ((*pch == 'M') || (*pch == 'm'))
  1140. {
  1141. if (StringsAreEqual (pch, SHOW_FB_MOVE_STR, len))
  1142. {
  1143. cval = fAddNext ? (cval | WM_SHOW_FB_MOVE) :
  1144. (cval & ~WM_SHOW_FB_MOVE);
  1145. fHit = True;
  1146. }
  1147. }
  1148. else if ((*pch == 'N') || (*pch == 'n'))
  1149. {
  1150. if (StringsAreEqual (pch, SHOW_FB_NONE_STR, len))
  1151. {
  1152. /* don't bother adding or subtracting nothing */
  1153. fHit = True;
  1154. }
  1155. }
  1156. else if ((*pch == 'P') || (*pch == 'p'))
  1157. {
  1158. if (StringsAreEqual (pch, SHOW_FB_PLACEMENT_STR, len))
  1159. {
  1160. cval = fAddNext ? (cval | WM_SHOW_FB_PLACEMENT) :
  1161. (cval & ~WM_SHOW_FB_PLACEMENT);
  1162. fHit = True;
  1163. }
  1164. }
  1165. else if ((*pch == 'Q') || (*pch == 'q'))
  1166. {
  1167. if (StringsAreEqual (pch, SHOW_FB_QUIT_STR, len))
  1168. {
  1169. cval = fAddNext ? (cval | WM_SHOW_FB_QUIT) :
  1170. (cval & ~WM_SHOW_FB_QUIT);
  1171. fHit = True;
  1172. }
  1173. }
  1174. else if ((*pch == 'R') || (*pch == 'r'))
  1175. {
  1176. if (StringsAreEqual (pch, SHOW_FB_RESIZE_STR, len))
  1177. {
  1178. cval = fAddNext ? (cval | WM_SHOW_FB_RESIZE) :
  1179. (cval & ~WM_SHOW_FB_RESIZE);
  1180. fHit = True;
  1181. }
  1182. else if (StringsAreEqual (pch, SHOW_FB_RESTART_STR, len))
  1183. {
  1184. cval = fAddNext ? (cval | WM_SHOW_FB_RESTART) :
  1185. (cval & ~WM_SHOW_FB_RESTART);
  1186. fHit = True;
  1187. }
  1188. }
  1189. pch = pchNext;
  1190. }
  1191. /*
  1192. * If we didn't match anything then set to default.
  1193. */
  1194. if (!fHit)
  1195. {
  1196. cval = WM_SHOW_FB_DEFAULT;
  1197. }
  1198. (*toVal).size = sizeof (int);
  1199. (*toVal).addr = (caddr_t) &cval;
  1200. } /* END OF FUNCTION WmCvtStringToShowFeedback */
  1201. /*************************************<->*************************************
  1202. *
  1203. * WmCvtStringToUsePPosition (args, numArgs, fromVal, toVal)
  1204. *
  1205. *
  1206. * Description:
  1207. * -----------
  1208. * This function converts a string to a keyboard focus policy description.
  1209. *
  1210. *
  1211. * Inputs:
  1212. * ------
  1213. * args = NULL (don't care)
  1214. *
  1215. * numArgs = 0 (don't care)
  1216. *
  1217. * fromVal = resource value to convert
  1218. *
  1219. *
  1220. * Outputs:
  1221. * -------
  1222. * toVal = descriptor to use to return converted value
  1223. *
  1224. *************************************<->***********************************/
  1225. void WmCvtStringToUsePPosition (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  1226. {
  1227. unsigned char *pch = (unsigned char *) (fromVal->addr);
  1228. unsigned char *pchNext;
  1229. int len;
  1230. static int cval;
  1231. Boolean fHit = False;
  1232. #define USE_PPOSITION_NONZERO_STR (unsigned char *)"nonzero"
  1233. #define USE_PPOSITION_ON_STR (unsigned char *)"on"
  1234. #define USE_PPOSITION_OFF_STR (unsigned char *)"off"
  1235. /*
  1236. * Convert the use PPosition resource value:
  1237. */
  1238. if (*pch && NextToken (pch, &len, &pchNext))
  1239. {
  1240. if ((*pch == 'N') || (*pch == 'n'))
  1241. {
  1242. if (StringsAreEqual (pch, USE_PPOSITION_NONZERO_STR, len))
  1243. {
  1244. cval = USE_PPOSITION_NONZERO;
  1245. fHit = True;
  1246. }
  1247. }
  1248. else if (StringsAreEqual (pch, USE_PPOSITION_OFF_STR, len))
  1249. {
  1250. cval = USE_PPOSITION_OFF;
  1251. fHit = True;
  1252. }
  1253. else if (StringsAreEqual (pch, USE_PPOSITION_ON_STR, len))
  1254. {
  1255. cval = USE_PPOSITION_ON;
  1256. fHit = True;
  1257. }
  1258. }
  1259. if (!fHit)
  1260. {
  1261. cval = USE_PPOSITION_NONZERO;
  1262. }
  1263. (*toVal).size = sizeof (int);
  1264. (*toVal).addr = (caddr_t)&cval;
  1265. } /* END OF FUNCTION WmCvtStringToUsePPosition */
  1266. /*************************************<->*************************************
  1267. *
  1268. * NextToken (pchIn, pLen, ppchNext)
  1269. *
  1270. *
  1271. * Description:
  1272. * -----------
  1273. * XXDescription ...
  1274. *
  1275. *
  1276. * Inputs:
  1277. * ------
  1278. * pchIn = pointer to start of next token
  1279. *
  1280. *
  1281. * Outputs:
  1282. * -------
  1283. * pLen = pointer to integer containing number of characters in next token
  1284. * ppchNext = address of pointer to following token
  1285. *
  1286. * Return = next token or NULL
  1287. *
  1288. *
  1289. * Comments:
  1290. * --------
  1291. * None.
  1292. *
  1293. *************************************<->***********************************/
  1294. unsigned char *NextToken (unsigned char *pchIn, int *pLen,
  1295. unsigned char **ppchNext)
  1296. {
  1297. unsigned char *pchR = pchIn;
  1298. int i;
  1299. int chlen;
  1300. for (i = 0;
  1301. ((chlen = mblen((char *)pchIn, MB_CUR_MAX)) > 0) && (pchIn[0] != '\0');
  1302. i++)
  1303. /* find end of word: requires singlebyte whitespace terminator */
  1304. {
  1305. if ((chlen == 1) && isspace (*pchIn))
  1306. {
  1307. break;
  1308. }
  1309. pchIn += chlen;
  1310. }
  1311. /* skip to next word */
  1312. ScanWhitespace (&pchIn);
  1313. *ppchNext = pchIn;
  1314. *pLen = i;
  1315. if (i)
  1316. {
  1317. return(pchR);
  1318. }
  1319. else
  1320. {
  1321. return(NULL);
  1322. }
  1323. } /* END OF FUNCTION NextToken */
  1324. /*************************************<->*************************************
  1325. *
  1326. * StringsAreEqual (pch1, pch2, len)
  1327. *
  1328. *
  1329. * Description:
  1330. * -----------
  1331. * XXDescription ...
  1332. *
  1333. *
  1334. * Inputs:
  1335. * ------
  1336. * pch1 =
  1337. * pch2 =
  1338. * len =
  1339. *
  1340. *
  1341. * Outputs:
  1342. * -------
  1343. * Return = (Boolean) True iff strings match (case insensitive)
  1344. *
  1345. *
  1346. * Comments:
  1347. * --------
  1348. * None.
  1349. *
  1350. *************************************<->***********************************/
  1351. Boolean StringsAreEqual (unsigned char *pch1, unsigned char *pch2, int len)
  1352. {
  1353. int chlen1;
  1354. int chlen2;
  1355. wchar_t wch1;
  1356. wchar_t wch2;
  1357. while (len &&
  1358. ((chlen1 = mbtowc (&wch1, (char *) pch1, MB_CUR_MAX)) > 0) &&
  1359. ((chlen2 = mbtowc (&wch2, (char *) pch2, MB_CUR_MAX)) == chlen1) )
  1360. {
  1361. if (chlen1 == 1)
  1362. /* singlebyte characters -- make case insensitive */
  1363. {
  1364. if ((isupper (*pch1) ? tolower(*pch1) : *pch1) !=
  1365. (isupper (*pch2) ? tolower(*pch2) : *pch2))
  1366. {
  1367. break;
  1368. }
  1369. }
  1370. else
  1371. /* multibyte characters */
  1372. {
  1373. if (wch1 != wch2)
  1374. {
  1375. break;
  1376. }
  1377. }
  1378. pch1 += chlen1;
  1379. pch2 += chlen2;
  1380. len--;
  1381. }
  1382. return (len == 0);
  1383. } /* END OF StringsAreEqual */
  1384. /*************************************<->*************************************
  1385. *
  1386. * long
  1387. * DecStrToL (str, ptr)
  1388. *
  1389. *
  1390. * Description:
  1391. * -----------
  1392. * Converts a decimal string to a long.
  1393. *
  1394. *
  1395. * Inputs:
  1396. * ------
  1397. * str = character string
  1398. *
  1399. *
  1400. * Outputs:
  1401. * -------
  1402. * *ptr = pointer to character terminating str or str
  1403. * Return = long value
  1404. *
  1405. *
  1406. * Comments:
  1407. * --------
  1408. * Leading whitespace is ignored.
  1409. * Returns long value with *ptr pointing at character terminating the decimal
  1410. * string.
  1411. * Returns 0 with *ptr == str if no integer can be formed.
  1412. *
  1413. *************************************<->***********************************/
  1414. long DecStrToL (unsigned char *str, unsigned char **ptr)
  1415. {
  1416. long val = 0;
  1417. *ptr = str;
  1418. while ((mblen ((char *)str, MB_CUR_MAX) == 1) && isspace (*str))
  1419. /* Ignore leading whitespace */
  1420. {
  1421. str++;
  1422. }
  1423. /* If we can start, we will reset *ptr */
  1424. if ((mblen ((char *)str, MB_CUR_MAX) == 1) && isdigit (*str))
  1425. {
  1426. while ((mblen ((char *)str, MB_CUR_MAX) == 1) && isdigit (*str))
  1427. {
  1428. val = val * 10 + (*str - '0');
  1429. str++;
  1430. }
  1431. *ptr = str;
  1432. }
  1433. return (val);
  1434. } /* END OF FUNCTION DecStrToL */