home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / XKBGAlloc.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  38KB  |  1,447 lines

  1. /* $XConsortium: XKBGAlloc.c /main/7 1996/02/02 14:38:24 kaleb $ */
  2. /* $XFree86: xc/lib/X11/XKBGAlloc.c,v 3.2 1996/10/13 11:17:25 dawes Exp $ */
  3. /************************************************************
  4. Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  5.  
  6. Permission to use, copy, modify, and distribute this
  7. software and its documentation for any purpose and without
  8. fee is hereby granted, provided that the above copyright
  9. notice appear in all copies and that both that copyright
  10. notice and this permission notice appear in supporting
  11. documentation, and that the name of Silicon Graphics not be 
  12. used in advertising or publicity pertaining to distribution 
  13. of the software without specific prior written permission.
  14. Silicon Graphics makes no representation about the suitability 
  15. of this software for any purpose. It is provided "as is"
  16. without any express or implied warranty.
  17.  
  18. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
  19. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
  20. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  21. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  22. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
  23. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
  24. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  25. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  
  27. ********************************************************/
  28.  
  29. #define    NEED_EVENTS
  30. #define    NEED_REPLIES
  31.  
  32. #ifndef XKB_IN_SERVER
  33.  
  34. #include <stdio.h>
  35. #include "Xlib_private.h"
  36. #include "XKBlibint.h"
  37. #include <X11/extensions/XKBgeom.h>
  38. #include <X11/extensions/XKBproto.h>
  39.  
  40. #else 
  41.  
  42. #include <stdio.h>
  43. #include "X.h"
  44. #include "Xproto.h"
  45. #include "misc.h"
  46. #include "inputstr.h"
  47. #include "XKBsrv.h"
  48. #include "XKBgeom.h"
  49.  
  50. #endif /* XKB_IN_SERVER */
  51.  
  52. #ifdef X_NOT_POSIX
  53. #define Size_t unsigned int
  54. #else
  55. #define Size_t size_t
  56. #endif
  57.  
  58. /***====================================================================***/
  59.  
  60. static void 
  61. #if NeedFunctionPrototypes
  62. _XkbFreeGeomLeafElems(    Bool            freeAll,
  63.             int            first,
  64.             int             count,
  65.             unsigned short *    num_inout,
  66.             unsigned short *    sz_inout,
  67.             char **            elems,
  68.             unsigned int        elem_sz)
  69. #else
  70. _XkbFreeGeomLeafElems(freeAll,first,count,num_inout,sz_inout,elems,elem_sz)
  71.     Bool        freeAll;
  72.     int            first;
  73.     int            count;
  74.     unsigned short *    num_inout;
  75.     unsigned short *    sz_inout;
  76.     char **        elems;
  77.     unsigned int    elem_sz;
  78. #endif
  79. {
  80.     DBUG_ENTER("_XkbFreeGeomLeafElems")
  81.     if ((freeAll)||(*elems==NULL)) {
  82.     *num_inout= *sz_inout= 0;
  83.     if (*elems!=NULL) {
  84.         _XkbFree(*elems);
  85.         *elems= NULL;
  86.     }    
  87.     DBUG_VOID_RETURN;
  88.     }
  89.  
  90.     if ((first>=(*num_inout))||(first<0)||(count<1))
  91.     DBUG_VOID_RETURN;
  92.  
  93.     if (first+count>=(*num_inout)) { 
  94.     /* truncating the array is easy */
  95.     (*num_inout)= first;
  96.     }
  97.     else {
  98.     char *    ptr;
  99.     int     extra;
  100.     ptr= *elems;
  101.     extra= ((*num_inout)-(first+count))*elem_sz;
  102.     if (extra>0)
  103.         memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra);
  104.     (*num_inout)-= count;
  105.     }
  106.     DBUG_VOID_RETURN;
  107. }
  108.  
  109. typedef void (*ContentsClearFunc)(
  110. #if NeedFunctionPrototypes
  111.         char *        /* priv */
  112. #endif
  113. );
  114.  
  115. static void 
  116. #if NeedFunctionPrototypes
  117. _XkbFreeGeomNonLeafElems(    Bool            freeAll,
  118.                 int            first,
  119.                 int             count,
  120.                 unsigned short *    num_inout,
  121.                 unsigned short *    sz_inout,
  122.                 char **            elems,
  123.                 unsigned int        elem_sz,
  124.                 ContentsClearFunc    freeFunc)
  125. #else
  126. _XkbFreeGeomNonLeafElems(freeAll,first,count,num_inout,sz_inout,elems,elem_sz,
  127.                                  freeFunc)
  128.     Bool        freeAll;
  129.     int            first;
  130.     int            count;
  131.     unsigned short *    num_inout;
  132.     unsigned short *    sz_inout;
  133.     char **        elems;
  134.     unsigned int    elem_sz;
  135.     ContentsClearFunc    freeFunc;
  136. #endif
  137. {
  138.     DBUG_ENTER("_XkbFreeGeomNonLeafElems")
  139.     register int i;
  140.     register char *ptr;
  141.  
  142.     if (freeAll) {
  143.     first= 0;
  144.     count= (*num_inout);
  145.     }
  146.     else if ((first>=(*num_inout))||(first<0)||(count<1)) {
  147.     DBUG_VOID_RETURN;
  148.     } else if (first+count>(*num_inout))
  149.     count= (*num_inout)-first;
  150.     if (*elems==NULL)
  151.     DBUG_VOID_RETURN;
  152.  
  153.     if (freeFunc) {
  154.     ptr= *elems;
  155.     ptr+= first*elem_sz;
  156.     for (i=0;i<count;i++) {
  157.         (*freeFunc)(ptr);
  158.         ptr+= elem_sz;
  159.     }
  160.     }
  161.     if (freeAll) {
  162.     (*num_inout)= (*sz_inout)= 0;
  163.     if (*elems) {
  164.         _XkbFree(*elems);
  165.         *elems= NULL;
  166.     }
  167.     }
  168.     else if (first+count>=(*num_inout))
  169.     *num_inout= first;
  170.     else {
  171.     i= ((*num_inout)-(first+count))*elem_sz;
  172.     ptr= *elems;
  173.     memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i);
  174.     (*num_inout)-= count;
  175.     }
  176.     DBUG_VOID_RETURN;
  177. }
  178.  
  179. /***====================================================================***/
  180.  
  181. static void
  182. #if NeedFunctionPrototypes
  183. _XkbClearProperty(char *prop_in)
  184. #else
  185. _XkbClearProperty(prop_in)
  186.     char *    prop_in;
  187. #endif
  188. {
  189.     DBUG_ENTER("_XkbClearProperty")
  190.     XkbPropertyPtr    prop= (XkbPropertyPtr)prop_in;
  191.  
  192.     if (prop->name) {
  193.     _XkbFree(prop->name);
  194.     prop->name= NULL;
  195.     }
  196.     if (prop->value) {
  197.     _XkbFree(prop->value);
  198.     prop->value= NULL;
  199.     }
  200.     DBUG_VOID_RETURN;
  201. }
  202.  
  203. void
  204. #if NeedFunctionPrototypes
  205. XkbFreeGeomProperties(    XkbGeometryPtr    geom,
  206.             int        first,
  207.             int        count,
  208.             Bool        freeAll)
  209. #else
  210. XkbFreeGeomProperties(geom,first,count,freeAll)
  211.     XkbGeometryPtr    geom;
  212.     int            first;
  213.     int            count;
  214.     Bool        freeAll;
  215. #endif
  216. {
  217.     DBUG_ENTER("XkbFreeGeomProperties")
  218.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  219.                 &geom->num_properties,&geom->sz_properties,
  220.                 (char **)&geom->properties,
  221.                 sizeof(XkbPropertyRec),_XkbClearProperty);
  222.     DBUG_VOID_RETURN;
  223. }
  224.  
  225. /***====================================================================***/
  226.  
  227. void
  228. #if NeedFunctionPrototypes
  229. XkbFreeGeomKeyAliases(    XkbGeometryPtr    geom,
  230.             int        first,
  231.             int        count,
  232.             Bool        freeAll)
  233. #else
  234. XkbFreeGeomKeyAliases(geom,first,count,freeAll)
  235.     XkbGeometryPtr    geom;
  236.     int            first;
  237.     int            count;
  238.     Bool        freeAll;
  239. #endif
  240. {    
  241.     DBUG_ENTER("XkbFreeGeomKeyAliases")
  242.     _XkbFreeGeomLeafElems(freeAll,first,count,
  243.                 &geom->num_key_aliases,&geom->sz_key_aliases,
  244.                 (char **)&geom->key_aliases,
  245.                 sizeof(XkbKeyAliasRec));
  246.     DBUG_VOID_RETURN;
  247. }
  248.  
  249. /***====================================================================***/
  250.  
  251. static void
  252. #if NeedFunctionPrototypes
  253. _XkbClearColor(char *color_in)
  254. #else
  255. _XkbClearColor(color_in)
  256.     char *    color_in;
  257. #endif
  258. {
  259.     DBUG_ENTER("_XkbClearColor")
  260.     XkbColorPtr    color= (XkbColorPtr)color_in;
  261.  
  262.     if (color->spec)
  263.     _XkbFree(color->spec);
  264.     DBUG_VOID_RETURN;
  265. }
  266.  
  267. void
  268. #if NeedFunctionPrototypes
  269. XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll)
  270. #else
  271. XkbFreeGeomColors(geom,first,count,freeAll)
  272.     XkbGeometryPtr    geom;
  273.     int            first;
  274.     int            count;
  275.     Bool        freeAll;
  276. #endif
  277. {
  278.     DBUG_ENTER("XkbFreeGeomColors")
  279.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  280.                 &geom->num_colors,&geom->sz_colors,
  281.                 (char **)&geom->colors,
  282.                 sizeof(XkbColorRec),_XkbClearColor);
  283.     DBUG_VOID_RETURN;
  284. }
  285.  
  286. /***====================================================================***/
  287.  
  288. void
  289. #if NeedFunctionPrototypes
  290. XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
  291. #else
  292. XkbFreeGeomPoints(outline,first,count,freeAll)
  293.     XkbOutlinePtr    outline;
  294.     int            first;
  295.     int            count;
  296.     Bool        freeAll;
  297. #endif
  298. {
  299.     DBUG_ENTER("XkbFreeGeomPoints")
  300.     _XkbFreeGeomLeafElems(freeAll,first,count,
  301.                 &outline->num_points,&outline->sz_points,
  302.                 (char **)&outline->points,
  303.                 sizeof(XkbPointRec));
  304.     DBUG_VOID_RETURN;
  305. }
  306.  
  307. /***====================================================================***/
  308.  
  309. static void
  310. #if NeedFunctionPrototypes
  311. _XkbClearOutline(char *outline_in)
  312. #else
  313. _XkbClearOutline(outline_in)
  314.     char *    outline_in;
  315. #endif
  316. {
  317.     DBUG_ENTER("_XkbClearOutline")
  318.     XkbOutlinePtr    outline= (XkbOutlinePtr)outline_in;
  319.  
  320.     if (outline->points!=NULL)
  321.     XkbFreeGeomPoints(outline,0,outline->num_points,True);
  322.     DBUG_VOID_RETURN;
  323. }
  324.  
  325. void
  326. #if NeedFunctionPrototypes
  327. XkbFreeGeomOutlines(XkbShapePtr    shape,int first,int count,Bool freeAll)
  328. #else
  329. XkbFreeGeomOutlines(shape,first,count,freeAll)
  330.     XkbShapePtr        shape;
  331.     int            first;
  332.     int            count;
  333.     Bool        freeAll;
  334. #endif
  335. {
  336.     DBUG_ENTER("XkbFreeGeomOutlines")
  337.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  338.                 &shape->num_outlines,&shape->sz_outlines,
  339.                 (char **)&shape->outlines,
  340.                 sizeof(XkbOutlineRec),_XkbClearOutline);
  341.     
  342.     DBUG_VOID_RETURN;
  343. }
  344.  
  345. /***====================================================================***/
  346.  
  347. static void
  348. #if NeedFunctionPrototypes
  349. _XkbClearShape(char *shape_in)
  350. #else
  351. _XkbClearShape(shape_in)
  352.     char *    shape_in;
  353. #endif
  354. {
  355.     DBUG_ENTER("_XkbClearShape")
  356.     XkbShapePtr    shape= (XkbShapePtr)shape_in;
  357.  
  358.     if (shape->outlines)
  359.     XkbFreeGeomOutlines(shape,0,shape->num_outlines,True);
  360.     DBUG_VOID_RETURN;
  361. }
  362.  
  363. void
  364. #if NeedFunctionPrototypes
  365. XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll)
  366. #else
  367. XkbFreeGeomShapes(geom,first,count,freeAll)
  368.     XkbGeometryPtr    geom;
  369.     int            first;
  370.     int            count;
  371.     Bool        freeAll;
  372. #endif
  373. {
  374.     DBUG_ENTER("XkbFreeGeomShapes")
  375.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  376.                 &geom->num_shapes,&geom->sz_shapes,
  377.                 (char **)&geom->shapes,
  378.                 sizeof(XkbShapeRec),_XkbClearShape);
  379.     DBUG_VOID_RETURN;
  380. }
  381.  
  382. /***====================================================================***/
  383.  
  384. void 
  385. #if NeedFunctionPrototypes
  386. XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll)
  387. #else
  388. XkbFreeGeomOverlayKeys(row,first,count,freeAll)
  389.     XkbOverlayRowPtr    row;
  390.     int            first;
  391.     int            count;
  392.     Bool        freeAll;
  393. #endif
  394. {
  395.     DBUG_ENTER("XkbFreeGeomOverlayKeys")
  396.     _XkbFreeGeomLeafElems(freeAll,first,count,
  397.                 &row->num_keys,&row->sz_keys,
  398.                 (char **)&row->keys,
  399.                 sizeof(XkbOverlayKeyRec));
  400.     DBUG_VOID_RETURN;
  401. }
  402.  
  403. /***====================================================================***/
  404.  
  405. static void
  406. #if NeedFunctionPrototypes
  407. _XkbClearOverlayRow(char *row_in)
  408. #else
  409. _XkbClearOverlayRow(row_in)
  410.     char *    row_in;
  411. #endif
  412. {
  413.     DBUG_ENTER("_XkbClearOverlayRow")
  414.     XkbOverlayRowPtr    row= (XkbOverlayRowPtr)row_in;
  415.  
  416.     if (row->keys!=NULL)
  417.     XkbFreeGeomOverlayKeys(row,0,row->num_keys,True);
  418.     DBUG_VOID_RETURN;
  419. }
  420.  
  421. void
  422. #if NeedFunctionPrototypes
  423. XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll)
  424. #else
  425. XkbFreeGeomOverlayRows(overlay,first,count,freeAll)
  426.     XkbOverlayPtr    overlay;
  427.     int            first;
  428.     int            count;
  429.     Bool        freeAll;
  430. #endif
  431. {
  432.     DBUG_ENTER("XkbFreeGeomOverlayRows")
  433.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  434.                 &overlay->num_rows,&overlay->sz_rows,
  435.                 (char **)&overlay->rows,
  436.                 sizeof(XkbOverlayRowRec),_XkbClearOverlayRow);
  437.     DBUG_VOID_RETURN;
  438. }
  439.  
  440. /***====================================================================***/
  441.  
  442. static void
  443. #if NeedFunctionPrototypes
  444. _XkbClearOverlay(char *overlay_in)
  445. #else
  446. _XkbClearOverlay(overlay_in)
  447.     char *    overlay_in;
  448. #endif
  449. {
  450.     DBUG_ENTER("_XkbClearOverlay")
  451.     XkbOverlayPtr    overlay= (XkbOverlayPtr)overlay_in;
  452.  
  453.     if (overlay->rows!=NULL)
  454.     XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True);
  455.     DBUG_VOID_RETURN;
  456. }
  457.  
  458. void
  459. #if NeedFunctionPrototypes
  460. XkbFreeGeomOverlays(XkbSectionPtr section,int first,int    count,Bool freeAll)
  461. #else
  462. XkbFreeGeomOverlays(section,first,count,freeAll)
  463.     XkbSectionPtr    section;
  464.     int            first;
  465.     int            count;
  466.     Bool        freeAll;
  467. #endif
  468. {
  469.     DBUG_ENTER("XkbFreeGeomOverlays")
  470.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  471.                 §ion->num_overlays,§ion->sz_overlays,
  472.                 (char **)§ion->overlays,
  473.                 sizeof(XkbOverlayRec),_XkbClearOverlay);
  474.     DBUG_VOID_RETURN;
  475. }
  476.  
  477. /***====================================================================***/
  478.  
  479. void
  480. #if NeedFunctionPrototypes
  481. XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
  482. #else
  483. XkbFreeGeomKeys(row,first,count,freeAll)
  484.     XkbRowPtr        row;
  485.     int            first;
  486.     int            count;
  487.     Bool        freeAll;
  488. #endif
  489. {
  490.     DBUG_ENTER("XkbFreeGeomKeys")
  491.     _XkbFreeGeomLeafElems(freeAll,first,count,
  492.                 &row->num_keys,&row->sz_keys,
  493.                 (char **)&row->keys,
  494.                 sizeof(XkbKeyRec));
  495.     DBUG_VOID_RETURN;
  496. }
  497.  
  498. /***====================================================================***/
  499.  
  500. static void
  501. #if NeedFunctionPrototypes
  502. _XkbClearRow(char *row_in)
  503. #else
  504. _XkbClearRow(row_in)
  505.     char *    row_in;
  506. #endif
  507. {
  508.     DBUG_ENTER("_XkbClearRow")
  509.     XkbRowPtr    row= (XkbRowPtr)row_in;
  510.  
  511.     if (row->keys!=NULL)
  512.     XkbFreeGeomKeys(row,0,row->num_keys,True);
  513.     DBUG_VOID_RETURN;
  514. }
  515.  
  516. void
  517. #if NeedFunctionPrototypes
  518. XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
  519. #else
  520. XkbFreeGeomRows(section,first,count,freeAll)
  521.     XkbSectionPtr    section;
  522.     int            first;
  523.     int            count;
  524.     Bool        freeAll;
  525. #endif
  526. {
  527.     DBUG_ENTER("XkbFreeGeomRows")
  528.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  529.                 §ion->num_rows,§ion->sz_rows,
  530.                 (char **)§ion->rows,
  531.                 sizeof(XkbRowRec),_XkbClearRow);
  532.     DBUG_VOID_RETURN;
  533. }
  534.  
  535. /***====================================================================***/
  536.  
  537. static void
  538. #if NeedFunctionPrototypes
  539. _XkbClearSection(char *section_in)
  540. #else
  541. _XkbClearSection(section_in)
  542.     char *    section_in;
  543. #endif
  544. {
  545.     DBUG_ENTER("_XkbClearSection")
  546.     XkbSectionPtr    section= (XkbSectionPtr)section_in;
  547.  
  548.     if (section->rows!=NULL)
  549.     XkbFreeGeomRows(section,0,section->num_rows,True);
  550.     if (section->doodads!=NULL) {
  551.     XkbFreeGeomDoodads(section->doodads,section->num_doodads,True);
  552.     section->doodads= NULL;
  553.     }
  554.     DBUG_VOID_RETURN;
  555. }
  556.  
  557. void
  558. #if NeedFunctionPrototypes
  559. XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
  560. #else
  561. XkbFreeGeomSections(geom,first,count,freeAll)
  562.     XkbGeometryPtr    geom;
  563.     int            first;
  564.     int            count;
  565.     Bool        freeAll;
  566. #endif
  567. {
  568.     DBUG_ENTER("XkbFreeGeomSections")
  569.     _XkbFreeGeomNonLeafElems(freeAll,first,count,
  570.                 &geom->num_sections,&geom->sz_sections,
  571.                 (char **)&geom->sections,
  572.                 sizeof(XkbSectionRec),_XkbClearSection);
  573.     DBUG_VOID_RETURN;
  574. }
  575.  
  576. /***====================================================================***/
  577.  
  578. static void
  579. #if NeedFunctionPrototypes
  580. _XkbClearDoodad(char *doodad_in)
  581. #else
  582. _XkbClearDoodad(doodad_in)
  583.     char *    doodad_in;
  584. #endif
  585. {
  586.     DBUG_ENTER("_XkbClearDoodad")
  587.     XkbDoodadPtr    doodad= (XkbDoodadPtr)doodad_in;
  588.  
  589.     switch (doodad->any.type) {
  590.        case XkbTextDoodad: 
  591.         {
  592.         if (doodad->text.text!=NULL) {
  593.             _XkbFree(doodad->text.text);
  594.             doodad->text.text= NULL;
  595.         }
  596.         if (doodad->text.font!=NULL) {
  597.             _XkbFree(doodad->text.font);
  598.             doodad->text.font= NULL;
  599.         }
  600.         }
  601.         break;
  602.        case XkbLogoDoodad: 
  603.         {
  604.         if (doodad->logo.logo_name!=NULL) {
  605.             _XkbFree(doodad->logo.logo_name);
  606.             doodad->logo.logo_name= NULL;
  607.         }
  608.         }
  609.         break;
  610.     }
  611.     DBUG_VOID_RETURN;
  612. }
  613.  
  614. void
  615. #if NeedFunctionPrototypes
  616. XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll)
  617. #else
  618. XkbFreeGeomDoodads(doodads,nDoodads,freeAll)
  619.     XkbDoodadPtr    doodads;
  620.     int            nDoodads;
  621.     Bool        freeAll;
  622. #endif
  623. {
  624.     DBUG_ENTER("XkbFreeGeomDoodads")
  625.     register int         i;
  626.     register XkbDoodadPtr    doodad;
  627.  
  628.     if (doodads) {
  629.     for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) {
  630.         _XkbClearDoodad((char *)doodad);
  631.     }
  632.     if (freeAll)
  633.         _XkbFree(doodads);
  634.     }
  635.     DBUG_VOID_RETURN;
  636. }
  637.  
  638. void
  639. #if NeedFunctionPrototypes
  640. XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
  641. #else
  642. XkbFreeGeometry(geom,which,freeMap)
  643.     XkbGeometryPtr    geom;
  644.     unsigned        which;
  645.     Bool        freeMap;
  646. #endif
  647. {
  648.     DBUG_ENTER("XkbFreeGeometry")
  649.     if (geom==NULL)
  650.     DBUG_VOID_RETURN;
  651.     if (freeMap)
  652.     which= XkbGeomAllMask;
  653.     if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL))
  654.     XkbFreeGeomProperties(geom,0,geom->num_properties,True);
  655.     if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL))
  656.     XkbFreeGeomColors(geom,0,geom->num_colors,True);
  657.     if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL))
  658.     XkbFreeGeomShapes(geom,0,geom->num_shapes,True);
  659.     if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL))
  660.     XkbFreeGeomSections(geom,0,geom->num_sections,True);
  661.     if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) {
  662.     XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True);
  663.     geom->doodads= NULL;
  664.     geom->num_doodads= geom->sz_doodads= 0;
  665.     }
  666.     if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
  667.     XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True);
  668.     if (freeMap) {
  669.     if (geom->label_font!=NULL) {
  670.         _XkbFree(geom->label_font);
  671.         geom->label_font= NULL;
  672.     }
  673.     _XkbFree(geom);
  674.     }
  675.     DBUG_VOID_RETURN;
  676. }
  677.  
  678. /***====================================================================***/
  679.  
  680. static Status
  681. #if NeedFunctionPrototypes
  682. _XkbGeomAlloc(    XPointer *        old,
  683.         unsigned short *    num,
  684.         unsigned short *    total,
  685.         int            num_new,
  686.         Size_t            sz_elem)
  687. #else
  688. _XkbGeomAlloc(old,num,total,num_new,sz_elem)
  689.     XPointer *        old;
  690.     unsigned short *    num;
  691.     unsigned short *    total;
  692.     int            num_new;
  693.     Size_t        sz_elem;
  694. #endif
  695. {
  696.     DBUG_ENTER("_XkbGeomAlloc")
  697.     if (num_new<1)
  698.     DBUG_RETURN(Success);
  699.     if ((*old)==NULL)
  700.     *num= *total= 0;
  701.  
  702.     if ((*num)+num_new<=(*total))
  703.     DBUG_RETURN(Success);
  704.  
  705.     *total= (*num)+num_new;
  706.     if ((*old)!=NULL)
  707.      (*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem);
  708.     else (*old)= (XPointer)_XkbCalloc((*total),sz_elem);
  709.     if ((*old)==NULL) {
  710.     *total= *num= 0;
  711.     DBUG_RETURN(BadAlloc);
  712.     }
  713.  
  714.     if (*num>0) {
  715.     char *tmp= (char *)(*old);
  716.     bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem));
  717.     }
  718.     DBUG_RETURN(Success);
  719. }
  720.  
  721. #define    _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\
  722.                 &(g)->num_properties,&(g)->sz_properties,\
  723.                 (n),sizeof(XkbPropertyRec))
  724. #define    _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\
  725.                 &(g)->num_colors,&(g)->sz_colors,\
  726.                 (n),sizeof(XkbColorRec))
  727. #define    _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\
  728.                 &(g)->num_shapes,&(g)->sz_shapes,\
  729.                 (n),sizeof(XkbShapeRec))
  730. #define    _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\
  731.                 &(g)->num_sections,&(g)->sz_sections,\
  732.                 (n),sizeof(XkbSectionRec))
  733. #define    _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\
  734.                 &(g)->num_doodads,&(g)->sz_doodads,\
  735.                 (n),sizeof(XkbDoodadRec))
  736. #define    _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\
  737.                 &(g)->num_key_aliases,&(g)->sz_key_aliases,\
  738.                 (n),sizeof(XkbKeyAliasRec))
  739.  
  740. #define    _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\
  741.                 &(s)->num_outlines,&(s)->sz_outlines,\
  742.                 (n),sizeof(XkbOutlineRec))
  743. #define    _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\
  744.                 &(s)->num_rows,&(s)->sz_rows,\
  745.                 (n),sizeof(XkbRowRec))
  746. #define    _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\
  747.                 &(o)->num_points,&(o)->sz_points,\
  748.                 (n),sizeof(XkbPointRec))
  749. #define    _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
  750.                 &(r)->num_keys,&(r)->sz_keys,\
  751.                 (n),sizeof(XkbKeyRec))
  752. #define    _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\
  753.                 &(s)->num_overlays,&(s)->sz_overlays,\
  754.                 (n),sizeof(XkbOverlayRec))
  755. #define    _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\
  756.                 &(o)->num_rows,&(o)->sz_rows,\
  757.                 (n),sizeof(XkbOverlayRowRec))
  758. #define    _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
  759.                 &(r)->num_keys,&(r)->sz_keys,\
  760.                 (n),sizeof(XkbOverlayKeyRec))
  761.     
  762. Status
  763. #if NeedFunctionPrototypes
  764. XkbAllocGeomProps(XkbGeometryPtr geom,int nProps)
  765. #else
  766. XkbAllocGeomProps(geom,nProps)
  767.     XkbGeometryPtr    geom;
  768.     int            nProps;
  769. #endif
  770. {
  771.     DBUG_ENTER("XkbAllocGeomProps")
  772.     Status result = _XkbAllocProps(geom,nProps);
  773.     DBUG_RETURN(result);
  774. }
  775.  
  776. Status
  777. #if NeedFunctionPrototypes
  778. XkbAllocGeomColors(XkbGeometryPtr geom,int nColors)
  779. #else
  780. XkbAllocGeomColors(geom,nColors)
  781.     XkbGeometryPtr    geom;
  782.     int            nColors;
  783. #endif
  784. {
  785.     DBUG_ENTER("XkbAllocGeomColors")
  786.     Status result = _XkbAllocColors(geom,nColors);
  787.     DBUG_RETURN(result);
  788. }
  789.  
  790. Status
  791. #if NeedFunctionPrototypes
  792. XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases)
  793. #else
  794. XkbAllocGeomKeyAliases(geom,nKeyAliases)
  795.     XkbGeometryPtr    geom;
  796.     int            nKeyAliases;
  797. #endif
  798. {
  799.     DBUG_ENTER("XkbAllocGeomKeyAliases")
  800.     Status result = _XkbAllocKeyAliases(geom,nKeyAliases);
  801.     DBUG_RETURN(result);
  802. }
  803.  
  804. Status
  805. #if NeedFunctionPrototypes
  806. XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes)
  807. #else
  808. XkbAllocGeomShapes(geom,nShapes)
  809.     XkbGeometryPtr    geom;
  810.     int            nShapes;
  811. #endif
  812. {
  813.     DBUG_ENTER("XkbAllocGeomShapes")
  814.     Status result = _XkbAllocShapes(geom,nShapes);
  815.     DBUG_RETURN(result);
  816. }
  817.  
  818. Status
  819. #if NeedFunctionPrototypes
  820. XkbAllocGeomSections(XkbGeometryPtr geom,int nSections)
  821. #else
  822. XkbAllocGeomSections(geom,nSections)
  823.     XkbGeometryPtr    geom;
  824.     int            nSections;
  825. #endif
  826. {
  827.     DBUG_ENTER("XkbAllocGeomSections")
  828.     Status result = _XkbAllocSections(geom,nSections);
  829.     DBUG_RETURN(result);
  830. }
  831.  
  832. Status
  833. #if NeedFunctionPrototypes
  834. XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays)
  835. #else
  836. XkbAllocGeomOverlays(section,nOverlays)
  837.     XkbSectionPtr    section;
  838.     int            nOverlays;
  839. #endif
  840. {
  841.     DBUG_ENTER("XkbAllocGeomOverlays")
  842.     Status result = _XkbAllocOverlays(section,nOverlays);
  843.     DBUG_RETURN(result);
  844. }
  845.  
  846. Status
  847. #if NeedFunctionPrototypes
  848. XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows)
  849. #else
  850. XkbAllocGeomOverlayRows(overlay,nRows)
  851.     XkbOverlayPtr    overlay;
  852.     int            nRows;
  853. #endif
  854. {
  855.     DBUG_ENTER("XkbAllocGeomOverlayRows")
  856.     Status result = _XkbAllocOverlayRows(overlay,nRows);
  857.     DBUG_RETURN(result);
  858. }
  859.  
  860. Status
  861. #if NeedFunctionPrototypes
  862. XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys)
  863. #else
  864. XkbAllocGeomOverlayKeys(row,nKeys)
  865.     XkbOverlayRowPtr    row;
  866.     int            nKeys;
  867. #endif
  868. {
  869.     DBUG_ENTER("XkbAllocGeomOverlayKeys")
  870.     Status result = _XkbAllocOverlayKeys(row,nKeys);
  871.     DBUG_RETURN(result);
  872. }
  873.  
  874. Status
  875. #if NeedFunctionPrototypes
  876. XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads)
  877. #else
  878. XkbAllocGeomDoodads(geom,nDoodads)
  879.     XkbGeometryPtr    geom;
  880.     int            nDoodads;
  881. #endif
  882. {
  883.     DBUG_ENTER("XkbAllocGeomDoodads")
  884.     Status result = _XkbAllocDoodads(geom,nDoodads);
  885.     DBUG_RETURN(result);
  886. }
  887.  
  888. Status
  889. #if NeedFunctionPrototypes
  890. XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads)
  891. #else
  892. XkbAllocGeomSectionDoodads(section,nDoodads)
  893.     XkbSectionPtr    section;
  894.     int            nDoodads;
  895. #endif
  896. {
  897.     DBUG_ENTER("XkbAllocGeomSectionDoodads")
  898.     Status result = _XkbAllocDoodads(section,nDoodads);
  899.     DBUG_RETURN(result);
  900. }
  901.  
  902. Status
  903. #if NeedFunctionPrototypes
  904. XkbAllocGeomOutlines(XkbShapePtr shape,int nOL)
  905. #else
  906. XkbAllocGeomOutlines(shape,nOL)
  907.     XkbShapePtr        shape;
  908.     int            nOL;
  909. #endif
  910. {
  911.     DBUG_ENTER("XkbAllocGeomOutlines")
  912.     Status result = _XkbAllocOutlines(shape,nOL);
  913.     DBUG_RETURN(result);
  914. }
  915.  
  916. Status
  917. #if NeedFunctionPrototypes
  918. XkbAllocGeomRows(XkbSectionPtr section,int nRows)
  919. #else
  920. XkbAllocGeomRows(section,nRows)
  921.     XkbSectionPtr    section;
  922.     int            nRows;
  923. #endif
  924. {
  925.     DBUG_ENTER("XkbAllocGeomRows")
  926.     Status result = _XkbAllocRows(section,nRows);
  927.     DBUG_RETURN(result);
  928. }
  929.  
  930. Status
  931. #if NeedFunctionPrototypes
  932. XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts)
  933. #else
  934. XkbAllocGeomPoints(ol,nPts)
  935.     XkbOutlinePtr    ol;
  936.     int            nPts;
  937. #endif
  938. {
  939.     DBUG_ENTER("XkbAllocGeomPoints")
  940.     Status result = _XkbAllocPoints(ol,nPts);
  941.     DBUG_RETURN(result);
  942. }
  943.  
  944. Status
  945. #if NeedFunctionPrototypes
  946. XkbAllocGeomKeys(XkbRowPtr row,int nKeys)
  947. #else
  948. XkbAllocGeomKeys(row,nKeys)
  949.     XkbRowPtr        row;
  950.     int            nKeys;
  951. #endif
  952. {
  953.     DBUG_ENTER("XkbAllocGeomKeys")
  954.     Status result = _XkbAllocKeys(row,nKeys);
  955.     DBUG_RETURN(result);
  956. }
  957.  
  958. Status
  959. #if NeedFunctionPrototypes
  960. XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes)
  961. #else
  962. XkbAllocGeometry(xkb,sizes)
  963.     XkbDescPtr        xkb;
  964.     XkbGeometrySizesPtr    sizes;
  965. #endif
  966. {
  967.     DBUG_ENTER("XkbAllocGeometry")
  968.     XkbGeometryPtr    geom;
  969.     Status        rtrn;
  970.  
  971.     if (xkb->geom==NULL) {
  972.     xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec);
  973.     if (!xkb->geom)
  974.         DBUG_RETURN(BadAlloc);
  975.     }
  976.     geom= xkb->geom;
  977.     if ((sizes->which&XkbGeomPropertiesMask)&&
  978.     ((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) {
  979.     goto BAIL;
  980.     }
  981.     if ((sizes->which&XkbGeomColorsMask)&&
  982.     ((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) {
  983.     goto BAIL;
  984.     }
  985.     if ((sizes->which&XkbGeomShapesMask)&&
  986.     ((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) {
  987.     goto BAIL;
  988.     }
  989.     if ((sizes->which&XkbGeomSectionsMask)&&
  990.     ((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) {
  991.     goto BAIL;
  992.     }
  993.     if ((sizes->which&XkbGeomDoodadsMask)&&
  994.     ((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) {
  995.     goto BAIL;
  996.     }
  997.     if ((sizes->which&XkbGeomKeyAliasesMask)&&
  998.     ((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) {
  999.     goto BAIL;
  1000.     }
  1001.     DBUG_RETURN(Success);
  1002. BAIL:
  1003.     XkbFreeGeometry(geom,XkbGeomAllMask,True);
  1004.     xkb->geom= NULL;
  1005.     DBUG_RETURN(rtrn);
  1006. }
  1007.  
  1008. /***====================================================================***/
  1009.  
  1010. XkbPropertyPtr
  1011. #if NeedFunctionPrototypes
  1012. XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value)
  1013. #else
  1014. XkbAddGeomProperty(geom,name,value)
  1015.     XkbGeometryPtr    geom;
  1016.     char *        name;
  1017.     char *        value;
  1018. #endif
  1019. {
  1020.     DBUG_ENTER("XkbAddGeomProperty")
  1021.     register int i;
  1022.     register XkbPropertyPtr prop;
  1023.  
  1024.     if ((!geom)||(!name)||(!value))
  1025.     DBUG_RETURN(NULL);
  1026.     for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
  1027.     if ((prop->name)&&(strcmp(name,prop->name)==0)) {
  1028.         if (prop->value)
  1029.         _XkbFree(prop->value);
  1030.         prop->value= (char *)_XkbAlloc(strlen(value)+1);
  1031.         if (prop->value)
  1032.         strcpy(prop->value,value);
  1033.         DBUG_RETURN(prop);
  1034.     }    
  1035.     }
  1036.     if ((geom->num_properties>=geom->sz_properties)&&
  1037.                     (_XkbAllocProps(geom,1)!=Success)) {
  1038.     DBUG_RETURN(NULL);
  1039.     }
  1040.     prop= &geom->properties[geom->num_properties];
  1041.     prop->name= (char *)_XkbAlloc(strlen(name)+1);
  1042.     if (!name)
  1043.     DBUG_RETURN(NULL);
  1044.     strcpy(prop->name,name);
  1045.     prop->value= (char *)_XkbAlloc(strlen(value)+1);
  1046.     if (!value) {
  1047.     _XkbFree(prop->name);
  1048.     prop->name= NULL;
  1049.     DBUG_RETURN(NULL);
  1050.     }
  1051.     strcpy(prop->value,value);
  1052.     geom->num_properties++;
  1053.     DBUG_RETURN(prop);
  1054. }
  1055.  
  1056. XkbKeyAliasPtr
  1057. #if NeedFunctionPrototypes
  1058. XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr)
  1059. #else
  1060. XkbAddGeomKeyAlias(geom,aliasStr,realStr)
  1061.     XkbGeometryPtr    geom;
  1062.     char *        aliasStr;
  1063.     char *        realStr;
  1064. #endif
  1065. {
  1066.     DBUG_ENTER("XkbAddGeomKeyAlias")
  1067.     register int i;
  1068.     register XkbKeyAliasPtr alias;
  1069.  
  1070.     if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0]))
  1071.     DBUG_RETURN(NULL);
  1072.     for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
  1073.     if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
  1074.         bzero(alias->real,XkbKeyNameLength);
  1075.         strncpy(alias->real,realStr,XkbKeyNameLength);
  1076.         DBUG_RETURN(alias);
  1077.     }
  1078.     }
  1079.     if ((geom->num_key_aliases>=geom->sz_key_aliases)&&
  1080.                 (_XkbAllocKeyAliases(geom,1)!=Success)) {
  1081.     DBUG_RETURN(NULL);
  1082.     }
  1083.     alias= &geom->key_aliases[geom->num_key_aliases];
  1084.     bzero(alias,sizeof(XkbKeyAliasRec));
  1085.     strncpy(alias->alias,aliasStr,XkbKeyNameLength);
  1086.     strncpy(alias->real,realStr,XkbKeyNameLength);
  1087.     geom->num_key_aliases++;
  1088.     DBUG_RETURN(alias);
  1089. }
  1090.  
  1091. XkbColorPtr
  1092. #if NeedFunctionPrototypes
  1093. XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel)
  1094. #else
  1095. XkbAddGeomColor(geom,spec,pixel)
  1096.     XkbGeometryPtr    geom;
  1097.     char *        spec;
  1098.     unsigned int    pixel;
  1099. #endif
  1100. {
  1101.     DBUG_ENTER("XkbAddGeomColor")
  1102.     register int i;
  1103.     register XkbColorPtr color;
  1104.  
  1105.     if ((!geom)||(!spec))
  1106.     DBUG_RETURN(NULL);
  1107.     for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
  1108.     if ((color->spec)&&(strcmp(color->spec,spec)==0)) {
  1109.         color->pixel= pixel;
  1110.         DBUG_RETURN(color);
  1111.     }
  1112.     }
  1113.     if ((geom->num_colors>=geom->sz_colors)&&
  1114.                     (_XkbAllocColors(geom,1)!=Success)) {
  1115.     DBUG_RETURN(NULL);
  1116.     }
  1117.     color= &geom->colors[geom->num_colors];
  1118.     color->pixel= pixel;
  1119.     color->spec= (char *)_XkbAlloc(strlen(spec)+1);
  1120.     if (!color->spec)
  1121.     DBUG_RETURN(NULL);
  1122.     strcpy(color->spec,spec);
  1123.     geom->num_colors++;
  1124.     DBUG_RETURN(color);
  1125. }
  1126.  
  1127. XkbOutlinePtr
  1128. #if NeedFunctionPrototypes
  1129. XkbAddGeomOutline(XkbShapePtr shape,int sz_points)
  1130. #else
  1131. XkbAddGeomOutline(shape,sz_points)
  1132.     XkbShapePtr        shape;
  1133.     int            sz_points;
  1134. #endif
  1135. {
  1136.     DBUG_ENTER("XkbAddGeomOutline")
  1137.     XkbOutlinePtr    outline;
  1138.  
  1139.     if ((!shape)||(sz_points<0))
  1140.     DBUG_RETURN(NULL);
  1141.     if ((shape->num_outlines>=shape->sz_outlines)&&
  1142.                     (_XkbAllocOutlines(shape,1)!=Success)) {
  1143.     DBUG_RETURN(NULL);
  1144.     }
  1145.     outline= &shape->outlines[shape->num_outlines];
  1146.     bzero(outline,sizeof(XkbOutlineRec));
  1147.     if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success))
  1148.     DBUG_RETURN(NULL);
  1149.     shape->num_outlines++;
  1150.     DBUG_RETURN(outline);
  1151. }
  1152.  
  1153. XkbShapePtr
  1154. #if NeedFunctionPrototypes
  1155. XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines)
  1156. #else
  1157. XkbAddGeomShape(geom,name,sz_outlines)
  1158.     XkbGeometryPtr    geom;
  1159.     Atom        name;
  1160.     int            sz_outlines;
  1161. #endif
  1162. {
  1163.     DBUG_ENTER("XkbAddGeomShape")
  1164.     XkbShapePtr    shape;
  1165.     register int    i;
  1166.  
  1167.     if ((!geom)||(!name)||(sz_outlines<0))
  1168.     DBUG_RETURN(NULL);
  1169.     if (geom->num_shapes>0) {
  1170.     for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) {
  1171.         if (name==shape->name)
  1172.         DBUG_RETURN(shape);
  1173.     }
  1174.     }
  1175.     if ((geom->num_shapes>=geom->sz_shapes)&&
  1176.                     (_XkbAllocShapes(geom,1)!=Success))
  1177.     DBUG_RETURN(NULL);
  1178.     shape= &geom->shapes[geom->num_shapes];
  1179.     bzero(shape,sizeof(XkbShapeRec));
  1180.     if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success))
  1181.     DBUG_RETURN(NULL);
  1182.     shape->name= name;
  1183.     shape->primary= shape->approx= NULL;
  1184.     geom->num_shapes++;
  1185.     DBUG_RETURN(shape);
  1186. }
  1187.  
  1188. XkbKeyPtr
  1189. #if NeedFunctionPrototypes
  1190. XkbAddGeomKey(XkbRowPtr row)
  1191. #else
  1192. XkbAddGeomKey(row)
  1193.     XkbRowPtr        row;
  1194. #endif
  1195. {
  1196.     DBUG_ENTER("XkbAddGeomKey")
  1197.     XkbKeyPtr    key;
  1198.     if (!row)
  1199.     DBUG_RETURN(NULL);
  1200.     if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success))
  1201.     DBUG_RETURN(NULL);
  1202.     key= &row->keys[row->num_keys++];
  1203.     bzero(key,sizeof(XkbKeyRec));
  1204.     DBUG_RETURN(key);
  1205. }
  1206.  
  1207. XkbRowPtr
  1208. #if NeedFunctionPrototypes
  1209. XkbAddGeomRow(XkbSectionPtr section,int sz_keys)
  1210. #else
  1211. XkbAddGeomRow(section,sz_keys)
  1212.     XkbSectionPtr    section;
  1213.     int            sz_keys;
  1214. #endif
  1215. {
  1216.     DBUG_ENTER("XkbAddGeomRow")
  1217.     XkbRowPtr    row;
  1218.  
  1219.     if ((!section)||(sz_keys<0))
  1220.     DBUG_RETURN(NULL);
  1221.     if ((section->num_rows>=section->sz_rows)&&
  1222.                         (_XkbAllocRows(section,1)!=Success))
  1223.     DBUG_RETURN(NULL);
  1224.     row= §ion->rows[section->num_rows];
  1225.     bzero(row,sizeof(XkbRowRec));
  1226.     if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success))
  1227.     DBUG_RETURN(NULL);
  1228.     section->num_rows++;
  1229.     DBUG_RETURN(row);
  1230. }
  1231.  
  1232. XkbSectionPtr
  1233. #if NeedFunctionPrototypes
  1234. XkbAddGeomSection(    XkbGeometryPtr    geom,
  1235.             Atom        name,
  1236.             int        sz_rows,
  1237.             int        sz_doodads,
  1238.             int        sz_over)
  1239. #else
  1240. XkbAddGeomSection(geom,name,sz_rows,sz_doodads,sz_over)
  1241.     XkbGeometryPtr    geom;
  1242.     Atom        name;
  1243.     int            sz_rows;
  1244.     int            sz_doodads;
  1245.     int            sz_over;
  1246. #endif
  1247. {
  1248.     DBUG_ENTER("XkbAddGeomSection")
  1249.     register int    i;
  1250.     XkbSectionPtr    section;
  1251.  
  1252.     if ((!geom)||(name==None)||(sz_rows<0))
  1253.     DBUG_RETURN(NULL);
  1254.     for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
  1255.     if (section->name!=name)
  1256.         continue;
  1257.     if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))||
  1258.         ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))||
  1259.         ((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success)))
  1260.         DBUG_RETURN(NULL);
  1261.     DBUG_RETURN(section);
  1262.     }
  1263.     if ((geom->num_sections>=geom->sz_sections)&&
  1264.                     (_XkbAllocSections(geom,1)!=Success))
  1265.     DBUG_RETURN(NULL);
  1266.     section= &geom->sections[geom->num_sections];
  1267.     if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))
  1268.     DBUG_RETURN(NULL);
  1269.     if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) {
  1270.     if (section->rows) {
  1271.         _XkbFree(section->rows);
  1272.         section->rows= NULL;
  1273.         section->sz_rows= section->num_rows= 0;
  1274.     }
  1275.     DBUG_RETURN(NULL);
  1276.     }
  1277.     section->name= name;
  1278.     geom->num_sections++;
  1279.     DBUG_RETURN(section);
  1280. }
  1281.  
  1282. XkbDoodadPtr
  1283. #if NeedFunctionPrototypes
  1284. XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name)
  1285. #else
  1286. XkbAddGeomDoodad(geom,section,name)
  1287.     XkbGeometryPtr    geom;
  1288.     XkbSectionPtr    section;
  1289.     Atom        name;
  1290. #endif
  1291. {
  1292.     DBUG_ENTER("XkbAddGeomDoodad")
  1293.     XkbDoodadPtr    old,doodad;
  1294.     register int    i,nDoodads;
  1295.  
  1296.     if ((!geom)||(name==None))
  1297.     DBUG_RETURN(NULL);
  1298.     if ((section!=NULL)&&(section->num_doodads>0)) {
  1299.     old= section->doodads;
  1300.     nDoodads= section->num_doodads;
  1301.     }
  1302.     else {
  1303.     old= geom->doodads;
  1304.     nDoodads= geom->num_doodads;
  1305.     }
  1306.     for (i=0,doodad=old;i<nDoodads;i++,doodad++) {
  1307.     if (doodad->any.name==name)
  1308.         DBUG_RETURN(doodad);
  1309.     }
  1310.     if (section) {
  1311.     if ((section->num_doodads>=geom->sz_doodads)&&
  1312.         (_XkbAllocDoodads(section,1)!=Success)) {
  1313.         DBUG_RETURN(NULL);
  1314.     }
  1315.     doodad= §ion->doodads[section->num_doodads++];
  1316.     }
  1317.     else {
  1318.     if ((geom->num_doodads>=geom->sz_doodads)&&
  1319.                     (_XkbAllocDoodads(geom,1)!=Success))
  1320.         DBUG_RETURN(NULL);
  1321.     doodad= &geom->doodads[geom->num_doodads++];
  1322.     }
  1323.     bzero(doodad,sizeof(XkbDoodadRec));
  1324.     doodad->any.name= name;
  1325.     DBUG_RETURN(doodad);
  1326. }
  1327.  
  1328. XkbOverlayKeyPtr
  1329. #if NeedFunctionPrototypes
  1330. XkbAddGeomOverlayKey(    XkbOverlayPtr        overlay,
  1331.             XkbOverlayRowPtr     row,
  1332.             char *            over,
  1333.             char *            under)
  1334. #else
  1335. XkbAddGeomOverlayKey(overlay,row,over,under)
  1336.     XkbOverlayPtr    overlay;
  1337.     XkbOverlayRowPtr    row;
  1338.     char *        over;
  1339.     char *        under;
  1340. #endif
  1341. {
  1342.     DBUG_ENTER("XkbAddGeomOverlayKey")
  1343.     register int    i;
  1344.     XkbOverlayKeyPtr key;
  1345.     XkbSectionPtr    section;
  1346.     XkbRowPtr    row_under;
  1347.     Bool        found;
  1348.  
  1349.     if ((!overlay)||(!row)||(!over)||(!under))
  1350.     DBUG_RETURN(NULL);
  1351.     section= overlay->section_under;
  1352.     if (row->row_under>=section->num_rows)
  1353.     DBUG_RETURN(NULL);
  1354.     row_under= §ion->rows[row->row_under];
  1355.     for (i=0,found=False;i<row_under->num_keys;i++) {
  1356.     if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) {
  1357.         found= True;
  1358.         break;
  1359.     }
  1360.     }
  1361.     if (!found)
  1362.        DBUG_RETURN(NULL); 
  1363.     if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success))
  1364.     DBUG_RETURN(NULL);
  1365.     key= &row->keys[row->num_keys];
  1366.     strncpy(key->under.name,under,XkbKeyNameLength);
  1367.     strncpy(key->over.name,over,XkbKeyNameLength);
  1368.     row->num_keys++;
  1369.     DBUG_RETURN(key);
  1370. }
  1371.  
  1372. XkbOverlayRowPtr
  1373. #if NeedFunctionPrototypes
  1374. XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys)
  1375. #else
  1376. XkbAddGeomOverlayRow(overlay,row_under,sz_keys)
  1377.     XkbOverlayPtr    overlay;
  1378.     int         row_under;
  1379.     int            sz_keys;
  1380. #endif
  1381. {
  1382.     DBUG_ENTER("XkbAddGeomOverlayRow")
  1383.     register int        i;
  1384.     XkbOverlayRowPtr    row;
  1385.  
  1386.     if ((!overlay)||(sz_keys<0))
  1387.     DBUG_RETURN(NULL);
  1388.     if (row_under>=overlay->section_under->num_rows)
  1389.     DBUG_RETURN(NULL);
  1390.     for (i=0;i<overlay->num_rows;i++) {
  1391.     if (overlay->rows[i].row_under==row_under) {
  1392.         row= &overlay->rows[i];
  1393.         if ((row->sz_keys<sz_keys)&&
  1394.                 (_XkbAllocOverlayKeys(row,sz_keys)!=Success)) {
  1395.         DBUG_RETURN(NULL);
  1396.         }
  1397.         DBUG_RETURN(&overlay->rows[i]);
  1398.     }
  1399.     }
  1400.     if ((overlay->num_rows>=overlay->sz_rows)&&
  1401.                 (_XkbAllocOverlayRows(overlay,1)!=Success))
  1402.     DBUG_RETURN(NULL);
  1403.     row= &overlay->rows[overlay->num_rows];
  1404.     bzero(row,sizeof(XkbOverlayRowRec));
  1405.     if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success))
  1406.     DBUG_RETURN(NULL);
  1407.     row->row_under= row_under;
  1408.     overlay->num_rows++;
  1409.     DBUG_RETURN(row);
  1410. }
  1411.  
  1412. XkbOverlayPtr
  1413. #if NeedFunctionPrototypes
  1414. XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows)
  1415. #else
  1416. XkbAddGeomOverlay(section,name,sz_rows)
  1417.     XkbSectionPtr    section;
  1418.     Atom        name;
  1419.     int            sz_rows;
  1420. #endif
  1421. {
  1422.     DBUG_ENTER("XkbAddGeomOverlay")
  1423.     register int    i;
  1424.     XkbOverlayPtr    overlay;
  1425.  
  1426.     if ((!section)||(name==None)||(sz_rows==0))
  1427.     DBUG_RETURN(NULL);
  1428.  
  1429.     for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) {
  1430.     if (overlay->name==name) {
  1431.         if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
  1432.         DBUG_RETURN(NULL);
  1433.         DBUG_RETURN(overlay);
  1434.     }
  1435.     }
  1436.     if ((section->num_overlays>=section->sz_overlays)&&
  1437.                 (_XkbAllocOverlays(section,1)!=Success))
  1438.     DBUG_RETURN(NULL);
  1439.     overlay= §ion->overlays[section->num_overlays];
  1440.     if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
  1441.     DBUG_RETURN(NULL);
  1442.     overlay->name= name;
  1443.     overlay->section_under= section;
  1444.     section->num_overlays++;
  1445.     DBUG_RETURN(overlay);
  1446. }
  1447.