]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/util/fontnames.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / lib / font / util / fontnames.c
1 /* $XConsortium: fontnames.c,v 1.2 94/04/17 20:17:32 keith Exp $ */
2
3 /*
4
5 Copyright (c) 1991  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
30
31 */
32
33 /*
34  * Author:  Keith Packard, MIT X Consortium
35  *
36  *      @(#)fontnames.c 3.1     91/04/10
37  */
38
39 #include        "fontmisc.h"
40 #include        "fontstruct.h"
41
42 void
43 FreeFontNames(pFN)
44     FontNamesPtr pFN;
45 {
46     int         i;
47
48     if (!pFN)
49         return;
50     for (i = 0; i < pFN->nnames; i++) {
51         xfree(pFN->names[i]);
52     }
53     xfree(pFN->names);
54     xfree(pFN->length);
55     xfree(pFN);
56 }
57
58 FontNamesPtr
59 MakeFontNamesRecord(size)
60     unsigned    size;
61 {
62     FontNamesPtr pFN;
63
64     pFN = (FontNamesPtr) xalloc(sizeof(FontNamesRec));
65     if (pFN) {
66         pFN->nnames = 0;
67         pFN->size = size;
68         if (size)
69         {
70             pFN->length = (int *) xalloc(size * sizeof(int));
71             pFN->names = (char **) xalloc(size * sizeof(char *));
72             if (!pFN->length || !pFN->names) {
73                 xfree(pFN->length);
74                 xfree(pFN->names);
75                 xfree(pFN);
76                 pFN = (FontNamesPtr) 0;
77             }
78         }
79         else
80         {
81             pFN->length = 0;
82             pFN->names = 0;
83         }
84     }
85     return pFN;
86 }
87
88 int
89 AddFontNamesName(names, name, length)
90     FontNamesPtr names;
91     char       *name;
92     int         length;
93 {
94     int         index = names->nnames;
95     char       *nelt;
96
97     nelt = (char *) xalloc(length + 1);
98     if (!nelt)
99         return AllocError;
100     if (index >= names->size) {
101         int         size = names->size << 1;
102         int        *nlength;
103         char      **nnames;
104
105         if (size == 0)
106             size = 8;
107         nlength = (int *) xrealloc(names->length, size * sizeof(int));
108         nnames = (char **) xrealloc(names->names, size * sizeof(char *));
109         if (nlength && nnames) {
110             names->size = size;
111             names->length = nlength;
112             names->names = nnames;
113         } else {
114             xfree(nelt);
115             xfree(nlength);
116             xfree(nnames);
117             return AllocError;
118         }
119     }
120     names->length[index] = length;
121     names->names[index] = nelt;
122     strncpy(nelt, name, length);
123     nelt[length] = '\0';
124     names->nnames++;
125     return Successful;
126 }