fontnames.c revision c7b4381a
1249c3046Smrg/* 2 3Copyright 1991, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included 12in all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall 23not be used in advertising or otherwise to promote the sale, use or 24other dealings in this Software without prior written authorization 25from The Open Group. 26 27*/ 28 29/* 30 * Author: Keith Packard, MIT X Consortium 31 * 32 */ 33 34#ifdef HAVE_CONFIG_H 35#include <config.h> 36#endif 37#include "libxfontint.h" 38#include "src/util/replace.h" 39#include <X11/fonts/fontmisc.h> 40#include <X11/fonts/fontstruct.h> 41 42void 43xfont2_free_font_names(FontNamesPtr pFN) 44{ 45 int i; 46 47 if (!pFN) 48 return; 49 for (i = 0; i < pFN->nnames; i++) { 50 free(pFN->names[i]); 51 } 52 free(pFN->names); 53 free(pFN->length); 54 free(pFN); 55} 56 57FontNamesPtr 58xfont2_make_font_names_record(unsigned size) 59{ 60 FontNamesPtr pFN; 61 62 pFN = malloc(sizeof(FontNamesRec)); 63 if (pFN) { 64 pFN->nnames = 0; 65 pFN->size = size; 66 if (size) 67 { 68 pFN->length = mallocarray(size, sizeof(int)); 69 pFN->names = mallocarray(size, sizeof(char *)); 70 if (!pFN->length || !pFN->names) { 71 free(pFN->length); 72 free(pFN->names); 73 free(pFN); 74 pFN = (FontNamesPtr) 0; 75 } 76 } 77 else 78 { 79 pFN->length = 0; 80 pFN->names = 0; 81 } 82 } 83 return pFN; 84} 85 86int 87xfont2_add_font_names_name(FontNamesPtr names, 88 char *name, 89 int length) 90{ 91 int index = names->nnames; 92 char *nelt; 93 94 nelt = malloc(length + 1); 95 if (!nelt) 96 return AllocError; 97 if (index >= names->size) { 98 int size = names->size << 1; 99 int *nlength; 100 char **nnames; 101 102 if (size == 0) 103 size = 8; 104 nlength = reallocarray(names->length, size, sizeof(int)); 105 nnames = reallocarray(names->names, size, sizeof(char *)); 106 if (nlength && nnames) { 107 names->size = size; 108 names->length = nlength; 109 names->names = nnames; 110 } else { 111 free(nelt); 112 free(nlength); 113 free(nnames); 114 return AllocError; 115 } 116 } 117 names->length[index] = length; 118 names->names[index] = nelt; 119 strncpy(nelt, name, length); 120 nelt[length] = '\0'; 121 names->nnames++; 122 return Successful; 123} 124