fcobjs.c revision 6fc018e4
1c9710b42Smrg/* 2c9710b42Smrg * fontconfig/src/fclist.c 3c9710b42Smrg * 4c9710b42Smrg * Copyright © 2000 Keith Packard 5c9710b42Smrg * 6c9710b42Smrg * Permission to use, copy, modify, distribute, and sell this software and its 7c9710b42Smrg * documentation for any purpose is hereby granted without fee, provided that 8c9710b42Smrg * the above copyright notice appear in all copies and that both that 9c9710b42Smrg * copyright notice and this permission notice appear in supporting 10c9710b42Smrg * documentation, and that the name of the author(s) not be used in 11c9710b42Smrg * advertising or publicity pertaining to distribution of the software without 12c9710b42Smrg * specific, written prior permission. The authors make no 13c9710b42Smrg * representations about the suitability of this software for any purpose. It 14c9710b42Smrg * is provided "as is" without express or implied warranty. 15c9710b42Smrg * 16c9710b42Smrg * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 17c9710b42Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 18c9710b42Smrg * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR 19c9710b42Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 20c9710b42Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 21c9710b42Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 22c9710b42Smrg * PERFORMANCE OF THIS SOFTWARE. 23c9710b42Smrg */ 24c9710b42Smrg 25c9710b42Smrg#include "fcint.h" 26c9710b42Smrg 27c9710b42Smrgstatic unsigned int 28c9710b42SmrgFcObjectTypeHash (register const char *str, register unsigned int len); 29c9710b42Smrg 30c9710b42Smrgstatic const struct FcObjectTypeInfo * 31c9710b42SmrgFcObjectTypeLookup (register const char *str, register unsigned int len); 32c9710b42Smrg 33c9710b42Smrg#include "fcobjshash.h" 34c9710b42Smrg 35c9710b42Smrg#include <string.h> 36c9710b42Smrg 37c9710b42Smrg/* The 1000 is to leave some room for future added internal objects, such 38c9710b42Smrg * that caches from newer fontconfig can still be used with older fontconfig 39c9710b42Smrg * without getting confused. */ 406fc018e4Smrgstatic fc_atomic_int_t next_id = FC_MAX_BASE_OBJECT + FC_EXT_OBJ_INDEX; 41c9710b42Smrgstruct FcObjectOtherTypeInfo { 42c9710b42Smrg struct FcObjectOtherTypeInfo *next; 43c9710b42Smrg FcObjectType object; 44c9710b42Smrg FcObject id; 45c9710b42Smrg} *other_types; 46c9710b42Smrg 47c9710b42Smrgstatic FcObjectType * 48c9710b42Smrg_FcObjectLookupOtherTypeByName (const char *str, FcObject *id) 49c9710b42Smrg{ 50c9710b42Smrg struct FcObjectOtherTypeInfo *ots, *ot; 51c9710b42Smrg 52c9710b42Smrgretry: 53c9710b42Smrg ots = fc_atomic_ptr_get (&other_types); 54c9710b42Smrg 55c9710b42Smrg for (ot = ots; ot; ot = ot->next) 56c9710b42Smrg if (0 == strcmp (ot->object.object, str)) 57c9710b42Smrg break; 58c9710b42Smrg 59c9710b42Smrg if (!ot) 60c9710b42Smrg { 61c9710b42Smrg ot = malloc (sizeof (*ot)); 62c9710b42Smrg if (!ot) 63c9710b42Smrg return NULL; 64c9710b42Smrg 65c9710b42Smrg ot->object.object = (const char *) FcStrdup (str); 666fc018e4Smrg ot->object.type = FcTypeUnknown; 67c9710b42Smrg ot->id = fc_atomic_int_add (next_id, +1); 68c9710b42Smrg ot->next = ots; 69c9710b42Smrg 70c9710b42Smrg if (!fc_atomic_ptr_cmpexch (&other_types, ots, ot)) { 71c9710b42Smrg free (ot); 72c9710b42Smrg goto retry; 73c9710b42Smrg } 74c9710b42Smrg } 75c9710b42Smrg 76c9710b42Smrg if (id) 77c9710b42Smrg *id = ot->id; 78c9710b42Smrg 79c9710b42Smrg return &ot->object; 80c9710b42Smrg} 81c9710b42Smrg 82c9710b42SmrgFcObject 83c9710b42SmrgFcObjectLookupBuiltinIdByName (const char *str) 84c9710b42Smrg{ 85c9710b42Smrg const struct FcObjectTypeInfo *o = FcObjectTypeLookup (str, strlen (str)); 86c9710b42Smrg 87c9710b42Smrg if (o) 88c9710b42Smrg return o->id; 89c9710b42Smrg 90c9710b42Smrg return 0; 91c9710b42Smrg} 92c9710b42Smrg 93c9710b42SmrgFcObject 94c9710b42SmrgFcObjectLookupIdByName (const char *str) 95c9710b42Smrg{ 96c9710b42Smrg const struct FcObjectTypeInfo *o = FcObjectTypeLookup (str, strlen (str)); 97c9710b42Smrg FcObject id; 98c9710b42Smrg if (o) 99c9710b42Smrg return o->id; 100c9710b42Smrg 101c9710b42Smrg if (_FcObjectLookupOtherTypeByName (str, &id)) 102c9710b42Smrg return id; 103c9710b42Smrg 104c9710b42Smrg return 0; 105c9710b42Smrg} 106c9710b42Smrg 107c9710b42Smrgconst char * 108c9710b42SmrgFcObjectLookupOtherNameById (FcObject id) 109c9710b42Smrg{ 110c9710b42Smrg struct FcObjectOtherTypeInfo *ot; 111c9710b42Smrg 112c9710b42Smrg for (ot = fc_atomic_ptr_get (&other_types); ot; ot = ot->next) 113c9710b42Smrg if (ot->id == id) 114c9710b42Smrg return ot->object.object; 115c9710b42Smrg 116c9710b42Smrg return NULL; 117c9710b42Smrg} 118c9710b42Smrg 119c9710b42Smrgconst FcObjectType * 120c9710b42SmrgFcObjectLookupOtherTypeByName (const char *str) 121c9710b42Smrg{ 122c9710b42Smrg return _FcObjectLookupOtherTypeByName (str, NULL); 123c9710b42Smrg} 124c9710b42Smrg 125c9710b42SmrgFcPrivate const FcObjectType * 126c9710b42SmrgFcObjectLookupOtherTypeById (FcObject id) 127c9710b42Smrg{ 128c9710b42Smrg struct FcObjectOtherTypeInfo *ot; 129c9710b42Smrg 130c9710b42Smrg for (ot = fc_atomic_ptr_get (&other_types); ot; ot = ot->next) 131c9710b42Smrg if (ot->id == id) 132c9710b42Smrg return &ot->object; 133c9710b42Smrg 134c9710b42Smrg return NULL; 135c9710b42Smrg} 136c9710b42Smrg 137c9710b42Smrg 138c9710b42Smrg#include "fcaliastail.h" 139c9710b42Smrg#undef __fcobjs__ 140