fontnames.c revision a96d7823
1/* 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 <X11/fonts/fontmisc.h> 39#include <X11/fonts/fontstruct.h> 40 41void 42xfont2_free_font_names(FontNamesPtr pFN) 43{ 44 int i; 45 46 if (!pFN) 47 return; 48 for (i = 0; i < pFN->nnames; i++) { 49 free(pFN->names[i]); 50 } 51 free(pFN->names); 52 free(pFN->length); 53 free(pFN); 54} 55 56FontNamesPtr 57xfont2_make_font_names_record(unsigned size) 58{ 59 FontNamesPtr pFN; 60 61 pFN = malloc(sizeof(FontNamesRec)); 62 if (pFN) { 63 pFN->nnames = 0; 64 pFN->size = size; 65 if (size) 66 { 67 pFN->length = malloc(size * sizeof(int)); 68 pFN->names = malloc(size * sizeof(char *)); 69 if (!pFN->length || !pFN->names) { 70 free(pFN->length); 71 free(pFN->names); 72 free(pFN); 73 pFN = (FontNamesPtr) 0; 74 } 75 } 76 else 77 { 78 pFN->length = 0; 79 pFN->names = 0; 80 } 81 } 82 return pFN; 83} 84 85int 86xfont2_add_font_names_name(FontNamesPtr names, 87 char *name, 88 int length) 89{ 90 int index = names->nnames; 91 char *nelt; 92 93 nelt = malloc(length + 1); 94 if (!nelt) 95 return AllocError; 96 if (index >= names->size) { 97 int size = names->size << 1; 98 int *nlength; 99 char **nnames; 100 101 if (size == 0) 102 size = 8; 103 nlength = realloc(names->length, size * sizeof(int)); 104 nnames = realloc(names->names, size * sizeof(char *)); 105 if (nlength && nnames) { 106 names->size = size; 107 names->length = nlength; 108 names->names = nnames; 109 } else { 110 free(nelt); 111 free(nlength); 112 free(nnames); 113 return AllocError; 114 } 115 } 116 names->length[index] = length; 117 names->names[index] = nelt; 118 strncpy(nelt, name, length); 119 nelt[length] = '\0'; 120 names->nnames++; 121 return Successful; 122} 123