From: Dan Nicholson Date: Sat, 28 Mar 2009 19:39:21 +0000 (-0700) Subject: Copy XkbAddGeom* functions from XKBlib X-Git-Tag: xkbcommon-0.2.0~962 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46e5e164d6611c88e422dcb9f3bae0b0d926a08c;p=platform%2Fupstream%2Flibxkbcommon.git Copy XkbAddGeom* functions from XKBlib These are needed by the geometry compiler in xkbcomp. --- diff --git a/include/X11/extensions/XKBcommon.h b/include/X11/extensions/XKBcommon.h index 502ede0..5e37ea4 100644 --- a/include/X11/extensions/XKBcommon.h +++ b/include/X11/extensions/XKBcommon.h @@ -191,6 +191,44 @@ XkbcAllocGeomKeys(XkbRowPtr row, int nKeys); extern int XkbcAllocGeometry(XkbcDescPtr xkb, XkbGeometrySizesPtr sizes); +extern XkbPropertyPtr +XkbcAddGeomProperty(XkbGeometryPtr geom, char *name, char *value); + +extern XkbKeyAliasPtr +XkbcAddGeomKeyAlias(XkbGeometryPtr geom, char *aliasStr, char *realStr); + +extern XkbColorPtr +XkbcAddGeomColor(XkbGeometryPtr geom, char *spec, unsigned int pixel); + +extern XkbOutlinePtr +XkbcAddGeomOutline(XkbShapePtr shape, int sz_points); + +extern XkbShapePtr +XkbcAddGeomShape(XkbGeometryPtr geom, Atom name, int sz_outlines); + +extern XkbKeyPtr +XkbcAddGeomKey(XkbRowPtr row); + +extern XkbRowPtr +XkbcAddGeomRow(XkbSectionPtr section, int sz_keys); + +extern XkbSectionPtr +XkbcAddGeomSection(XkbGeometryPtr geom, Atom name, + int sz_rows, int sz_doodads, int sz_over); + +extern XkbDoodadPtr +XkbcAddGeomDoodad(XkbGeometryPtr geom, XkbSectionPtr section, Atom name); + +extern XkbOverlayKeyPtr +XkbcAddGeomOverlayKey(XkbOverlayPtr overlay, XkbOverlayRowPtr row, + char *over, char *under); + +extern XkbOverlayRowPtr +XkbcAddGeomOverlayRow(XkbOverlayPtr overlay, int row_under, int sz_keys); + +extern XkbOverlayPtr +XkbcAddGeomOverlay(XkbSectionPtr section, Atom name, int sz_rows); + extern void XkbcInitAtoms(void); diff --git a/src/galloc.c b/src/galloc.c index ad8946d..49af81b 100644 --- a/src/galloc.c +++ b/src/galloc.c @@ -603,3 +603,346 @@ bail: xkb->geom = NULL; return rtrn; } + +XkbPropertyPtr +XkbcAddGeomProperty(XkbGeometryPtr geom,char *name,char *value) +{ +register int i; +register XkbPropertyPtr prop; + + if ((!geom)||(!name)||(!value)) + return NULL; + for (i=0,prop=geom->properties;inum_properties;i++,prop++) { + if ((prop->name)&&(strcmp(name,prop->name)==0)) { + if (prop->value) + _XkbFree(prop->value); + prop->value= (char *)_XkbAlloc(strlen(value)+1); + if (prop->value) + strcpy(prop->value,value); + return prop; + } + } + if ((geom->num_properties>=geom->sz_properties)&& + (_XkbAllocProps(geom,1)!=Success)) { + return NULL; + } + prop= &geom->properties[geom->num_properties]; + prop->name= (char *)_XkbAlloc(strlen(name)+1); + if (!name) + return NULL; + strcpy(prop->name,name); + prop->value= (char *)_XkbAlloc(strlen(value)+1); + if (!value) { + _XkbFree(prop->name); + prop->name= NULL; + return NULL; + } + strcpy(prop->value,value); + geom->num_properties++; + return prop; +} + +XkbKeyAliasPtr +XkbcAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr) +{ +register int i; +register XkbKeyAliasPtr alias; + + if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0])) + return NULL; + for (i=0,alias=geom->key_aliases;inum_key_aliases;i++,alias++) { + if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) { + bzero(alias->real,XkbKeyNameLength); + strncpy(alias->real,realStr,XkbKeyNameLength); + return alias; + } + } + if ((geom->num_key_aliases>=geom->sz_key_aliases)&& + (_XkbAllocKeyAliases(geom,1)!=Success)) { + return NULL; + } + alias= &geom->key_aliases[geom->num_key_aliases]; + bzero(alias,sizeof(XkbKeyAliasRec)); + strncpy(alias->alias,aliasStr,XkbKeyNameLength); + strncpy(alias->real,realStr,XkbKeyNameLength); + geom->num_key_aliases++; + return alias; +} + +XkbColorPtr +XkbcAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel) +{ +register int i; +register XkbColorPtr color; + + if ((!geom)||(!spec)) + return NULL; + for (i=0,color=geom->colors;inum_colors;i++,color++) { + if ((color->spec)&&(strcmp(color->spec,spec)==0)) { + color->pixel= pixel; + return color; + } + } + if ((geom->num_colors>=geom->sz_colors)&& + (_XkbAllocColors(geom,1)!=Success)) { + return NULL; + } + color= &geom->colors[geom->num_colors]; + color->pixel= pixel; + color->spec= (char *)_XkbAlloc(strlen(spec)+1); + if (!color->spec) + return NULL; + strcpy(color->spec,spec); + geom->num_colors++; + return color; +} + +XkbOutlinePtr +XkbcAddGeomOutline(XkbShapePtr shape,int sz_points) +{ +XkbOutlinePtr outline; + + if ((!shape)||(sz_points<0)) + return NULL; + if ((shape->num_outlines>=shape->sz_outlines)&& + (_XkbAllocOutlines(shape,1)!=Success)) { + return NULL; + } + outline= &shape->outlines[shape->num_outlines]; + bzero(outline,sizeof(XkbOutlineRec)); + if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success)) + return NULL; + shape->num_outlines++; + return outline; +} + +XkbShapePtr +XkbcAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines) +{ +XkbShapePtr shape; +register int i; + + if ((!geom)||(!name)||(sz_outlines<0)) + return NULL; + if (geom->num_shapes>0) { + for (shape=geom->shapes,i=0;inum_shapes;i++,shape++) { + if (name==shape->name) + return shape; + } + } + if ((geom->num_shapes>=geom->sz_shapes)&& + (_XkbAllocShapes(geom,1)!=Success)) + return NULL; + shape= &geom->shapes[geom->num_shapes]; + bzero(shape,sizeof(XkbShapeRec)); + if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success)) + return NULL; + shape->name= name; + shape->primary= shape->approx= NULL; + geom->num_shapes++; + return shape; +} + +XkbKeyPtr +XkbcAddGeomKey(XkbRowPtr row) +{ +XkbKeyPtr key; + if (!row) + return NULL; + if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success)) + return NULL; + key= &row->keys[row->num_keys++]; + bzero(key,sizeof(XkbKeyRec)); + return key; +} + +XkbRowPtr +XkbcAddGeomRow(XkbSectionPtr section,int sz_keys) +{ +XkbRowPtr row; + + if ((!section)||(sz_keys<0)) + return NULL; + if ((section->num_rows>=section->sz_rows)&& + (_XkbAllocRows(section,1)!=Success)) + return NULL; + row= §ion->rows[section->num_rows]; + bzero(row,sizeof(XkbRowRec)); + if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success)) + return NULL; + section->num_rows++; + return row; +} + +XkbSectionPtr +XkbcAddGeomSection( XkbGeometryPtr geom, + Atom name, + int sz_rows, + int sz_doodads, + int sz_over) +{ +register int i; +XkbSectionPtr section; + + if ((!geom)||(name==None)||(sz_rows<0)) + return NULL; + for (i=0,section=geom->sections;inum_sections;i++,section++) { + if (section->name!=name) + continue; + if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))|| + ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))|| + ((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success))) + return NULL; + return section; + } + if ((geom->num_sections>=geom->sz_sections)&& + (_XkbAllocSections(geom,1)!=Success)) + return NULL; + section= &geom->sections[geom->num_sections]; + if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success)) + return NULL; + if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) { + if (section->rows) { + _XkbFree(section->rows); + section->rows= NULL; + section->sz_rows= section->num_rows= 0; + } + return NULL; + } + section->name= name; + geom->num_sections++; + return section; +} + +XkbDoodadPtr +XkbcAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name) +{ +XkbDoodadPtr old,doodad; +register int i,nDoodads; + + if ((!geom)||(name==None)) + return NULL; + if ((section!=NULL)&&(section->num_doodads>0)) { + old= section->doodads; + nDoodads= section->num_doodads; + } + else { + old= geom->doodads; + nDoodads= geom->num_doodads; + } + for (i=0,doodad=old;iany.name==name) + return doodad; + } + if (section) { + if ((section->num_doodads>=geom->sz_doodads)&& + (_XkbAllocDoodads(section,1)!=Success)) { + return NULL; + } + doodad= §ion->doodads[section->num_doodads++]; + } + else { + if ((geom->num_doodads>=geom->sz_doodads)&& + (_XkbAllocDoodads(geom,1)!=Success)) + return NULL; + doodad= &geom->doodads[geom->num_doodads++]; + } + bzero(doodad,sizeof(XkbDoodadRec)); + doodad->any.name= name; + return doodad; +} + +XkbOverlayKeyPtr +XkbcAddGeomOverlayKey( XkbOverlayPtr overlay, + XkbOverlayRowPtr row, + char * over, + char * under) +{ +register int i; +XkbOverlayKeyPtr key; +XkbSectionPtr section; +XkbRowPtr row_under; +Bool found; + + if ((!overlay)||(!row)||(!over)||(!under)) + return NULL; + section= overlay->section_under; + if (row->row_under>=section->num_rows) + return NULL; + row_under= §ion->rows[row->row_under]; + for (i=0,found=False;inum_keys;i++) { + if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) { + found= True; + break; + } + } + if (!found) + return NULL; + if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success)) + return NULL; + key= &row->keys[row->num_keys]; + strncpy(key->under.name,under,XkbKeyNameLength); + strncpy(key->over.name,over,XkbKeyNameLength); + row->num_keys++; + return key; +} + +XkbOverlayRowPtr +XkbcAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys) +{ +register int i; +XkbOverlayRowPtr row; + + if ((!overlay)||(sz_keys<0)) + return NULL; + if (row_under>=overlay->section_under->num_rows) + return NULL; + for (i=0;inum_rows;i++) { + if (overlay->rows[i].row_under==row_under) { + row= &overlay->rows[i]; + if ((row->sz_keysrows[i]; + } + } + if ((overlay->num_rows>=overlay->sz_rows)&& + (_XkbAllocOverlayRows(overlay,1)!=Success)) + return NULL; + row= &overlay->rows[overlay->num_rows]; + bzero(row,sizeof(XkbOverlayRowRec)); + if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success)) + return NULL; + row->row_under= row_under; + overlay->num_rows++; + return row; +} + +XkbOverlayPtr +XkbcAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows) +{ +register int i; +XkbOverlayPtr overlay; + + if ((!section)||(name==None)||(sz_rows==0)) + return NULL; + + for (i=0,overlay=section->overlays;inum_overlays;i++,overlay++) { + if (overlay->name==name) { + if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success)) + return NULL; + return overlay; + } + } + if ((section->num_overlays>=section->sz_overlays)&& + (_XkbAllocOverlays(section,1)!=Success)) + return NULL; + overlay= §ion->overlays[section->num_overlays]; + if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success)) + return NULL; + overlay->name= name; + overlay->section_under= section; + section->num_overlays++; + return overlay; +} diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c index 298872a..c73e580 100644 --- a/src/xkbcomp/geometry.c +++ b/src/xkbcomp/geometry.c @@ -2887,7 +2887,7 @@ CopyShapeDef(XkbGeometryPtr geom, ShapeInfo * si) si->index = geom->num_shapes; name = XkbcInternAtom(XkbcAtomGetString(si->name), False); - shape = XkbAddGeomShape(geom, name, si->nOutlines); + shape = XkbcAddGeomShape(geom, name, si->nOutlines); if (!shape) { WSGO("Couldn't allocate shape in geometry\n"); @@ -2897,7 +2897,7 @@ CopyShapeDef(XkbGeometryPtr geom, ShapeInfo * si) old_outline = si->outlines; for (i = 0; i < si->nOutlines; i++, old_outline++) { - outline = XkbAddGeomOutline(shape, old_outline->num_points); + outline = XkbcAddGeomOutline(shape, old_outline->num_points); if (!outline) { WSGO("Couldn't allocate outline in shape\n"); @@ -3260,7 +3260,7 @@ CopyDoodadDef(XkbGeometryPtr geom, if (!VerifyDoodadInfo(di, info)) return False; name = XkbcInternAtom(XkbcAtomGetString(di->name), False); - doodad = XkbAddGeomDoodad(geom, section, name); + doodad = XkbcAddGeomDoodad(geom, section, name); if (!doodad) { WSGO1("Couldn't allocate doodad in %s\n", @@ -3281,7 +3281,7 @@ CopyDoodadDef(XkbGeometryPtr geom, return False; doodad->shape.angle = di->angle; color = - XkbAddGeomColor(geom, XkbcAtomGetString(di->color), + XkbcAddGeomColor(geom, XkbcAtomGetString(di->color), geom->num_colors); shape = &geom->shapes[si->index]; XkbSetShapeDoodadColor(geom, &doodad->shape, color); @@ -3301,7 +3301,7 @@ CopyDoodadDef(XkbGeometryPtr geom, doodad->text.font = XkbcAtomGetString(di->fontSpec); doodad->text.text = XkbcAtomGetString(di->text); color = - XkbAddGeomColor(geom, XkbcAtomGetString(di->color), + XkbcAddGeomColor(geom, XkbcAtomGetString(di->color), geom->num_colors); XkbSetTextDoodadColor(geom, &doodad->text, color); break; @@ -3311,12 +3311,12 @@ CopyDoodadDef(XkbGeometryPtr geom, return False; shape = &geom->shapes[si->index]; color = - XkbAddGeomColor(geom, XkbcAtomGetString(di->color), + XkbcAddGeomColor(geom, XkbcAtomGetString(di->color), geom->num_colors); XkbSetIndicatorDoodadShape(geom, &doodad->indicator, shape); XkbSetIndicatorDoodadOnColor(geom, &doodad->indicator, color); color = - XkbAddGeomColor(geom, XkbcAtomGetString(di->offColor), + XkbcAddGeomColor(geom, XkbcAtomGetString(di->offColor), geom->num_colors); XkbSetIndicatorDoodadOffColor(geom, &doodad->indicator, color); break; @@ -3326,7 +3326,7 @@ CopyDoodadDef(XkbGeometryPtr geom, return False; doodad->logo.angle = di->angle; color = - XkbAddGeomColor(geom, XkbcAtomGetString(di->color), + XkbcAddGeomColor(geom, XkbcAtomGetString(di->color), geom->num_colors); shape = &geom->shapes[si->index]; XkbSetLogoDoodadColor(geom, &doodad->logo, color); @@ -3452,7 +3452,7 @@ CopyOverlayDef(XkbGeometryPtr geom, if (!VerifyOverlayInfo(geom, section, oi, info, rowMap, rowSize)) return False; name = XkbcInternAtom(XkbcAtomGetString(oi->name), False); - ol = XkbAddGeomOverlay(section, name, oi->nRows); + ol = XkbcAddGeomOverlay(section, name, oi->nRows); if (!ol) { WSGO2("Couldn't add overlay \"%s\" to section \"%s\"\n", @@ -3468,7 +3468,7 @@ CopyOverlayDef(XkbGeometryPtr geom, if (rowMap[tmp] == i) row_under = tmp; } - if (!XkbAddGeomOverlayRow(ol, row_under, rowSize[i])) + if (!XkbcAddGeomOverlayRow(ol, row_under, rowSize[i])) { WSGO3 ("Can't add row %d to overlay \"%s\" of section \"%s\"\n", @@ -3501,7 +3501,7 @@ CopySectionDef(XkbGeometryPtr geom, SectionInfo * si, GeometryInfo * info) name = XkbcInternAtom(XkbcAtomGetString(si->name), False); section = - XkbAddGeomSection(geom, name, si->nRows, si->nDoodads, si->nOverlays); + XkbcAddGeomSection(geom, name, si->nRows, si->nDoodads, si->nOverlays); if (section == NULL) { WSGO("Couldn't allocate section in geometry\n"); @@ -3516,7 +3516,7 @@ CopySectionDef(XkbGeometryPtr geom, SectionInfo * si, GeometryInfo * info) section->priority = si->priority; for (ri = si->rows; ri != NULL; ri = (RowInfo *) ri->defs.next) { - row = XkbAddGeomRow(section, ri->nKeys); + row = XkbcAddGeomRow(section, ri->nKeys); if (row == NULL) { WSGO("Couldn't allocate row in section\n"); @@ -3536,7 +3536,7 @@ CopySectionDef(XkbGeometryPtr geom, SectionInfo * si, GeometryInfo * info) ACTION1("Section %s ignored\n", scText(si)); return False; } - key = XkbAddGeomKey(row); + key = XkbcAddGeomKey(row); if (key == NULL) { WSGO("Couldn't allocate key in row\n"); @@ -3557,11 +3557,11 @@ CopySectionDef(XkbGeometryPtr geom, SectionInfo * si, GeometryInfo * info) } if (ki->color != None) color = - XkbAddGeomColor(geom, + XkbcAddGeomColor(geom, XkbcAtomGetString(ki->color), geom->num_colors); else - color = XkbAddGeomColor(geom, "white", geom->num_colors); + color = XkbcAddGeomColor(geom, "white", geom->num_colors); XkbSetKeyColor(geom, key, color); } } @@ -3640,18 +3640,18 @@ CompileGeometry(XkbFile *file, XkbcDescPtr xkb, unsigned merge) info.fontVariant, info.fontSize, info.fontEncoding); - XkbAddGeomColor(geom, "black", geom->num_colors); - XkbAddGeomColor(geom, "white", geom->num_colors); + XkbcAddGeomColor(geom, "black", geom->num_colors); + XkbcAddGeomColor(geom, "white", geom->num_colors); if (info.baseColor == None) info.baseColor = XkbcInternAtom("white", False); if (info.labelColor == None) info.labelColor = XkbcInternAtom("black", False); geom->base_color = - XkbAddGeomColor(geom, XkbcAtomGetString(info.baseColor), + XkbcAddGeomColor(geom, XkbcAtomGetString(info.baseColor), geom->num_colors); geom->label_color = - XkbAddGeomColor(geom, XkbcAtomGetString(info.labelColor), + XkbcAddGeomColor(geom, XkbcAtomGetString(info.labelColor), geom->num_colors); if (info.props) @@ -3660,7 +3660,7 @@ CompileGeometry(XkbFile *file, XkbcDescPtr xkb, unsigned merge) for (pi = info.props; pi != NULL; pi = (PropertyInfo *) pi->defs.next) { - if (!XkbAddGeomProperty(geom, pi->name, pi->value)) + if (!XkbcAddGeomProperty(geom, pi->name, pi->value)) return False; } }