Cleanup of -Wpointer-compare warnings.
[oweals/cde.git] / cde / lib / DtHelp / FontAttr.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: FontAttr.c /main/8 1996/01/29 12:19:57 cde-hp $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:     Font.c
28  **
29  **   Project:     Text Graphic Display Library
30  **
31  **   Description: Semi private format utility functions that do not
32  **                require the Display Area, Motif, Xt or X11.
33  **
34  **
35  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
36  **
37  **  (c) Copyright 1993, 1994 Hewlett-Packard Company
38  **  (c) Copyright 1993, 1994 International Business Machines Corp.
39  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
40  **  (c) Copyright 1993, 1994 Novell, Inc.
41  **
42  **
43  ****************************************************************************
44  ************************************<+>*************************************/
45 /*
46  * system includes
47  */
48 #include <string.h>
49 #include <stdlib.h>
50
51 /*
52  * private includes
53  */
54 #include "FontAttrI.h"
55
56 #ifdef NLS16
57 #endif
58
59 /********    Private Function Declarations    ********/
60 /********    End Public Function Declarations    ********/
61
62 /******************************************************************************
63  *
64  * Private variables and defines.
65  *
66  *****************************************************************************/
67 #ifndef NULL
68 #define NULL    0
69 #endif
70
71 static  _DtHelpFontHints        DefaultFontAttrs =
72   {
73         "C",
74         "ISO-8859-1",
75         10, 0,                          /* pointsz, setsize */
76           NULL,                                 /* color            */
77           NULL, NULL, NULL, NULL,               /* xlfd strings     */
78           NULL, NULL, NULL, NULL,               /* MS-Win strings   */
79         _DtHelpFontStyleSanSerif,
80         _DtHelpFontSpacingProp  ,
81         _DtHelpFontWeightMedium ,
82         _DtHelpFontSlantRoman   ,
83         _DtHelpFontSpecialNone  ,
84         NULL
85   };
86
87 /******************************************************************************
88  *
89  * Private Functions
90  *
91  *****************************************************************************/
92 static int
93 HintDuplicate(char **string)
94 {
95     if (NULL != *string)
96       {
97         *string = strdup(*string);
98         if (NULL == *string)
99             return -1;
100       }
101
102     return 0;
103 }
104
105 /******************************************************************************
106  *
107  * Semi Public Functions
108  *
109  *****************************************************************************/
110 /******************************************************************************
111  * Function:    void _DtHelpCeCopyDefFontAttrList (char **font_attr)
112  *
113  * Parameters:  font_attr       Specifies the font attribute list
114  *
115  * Return Value: void
116  *
117  * Purpose:     Initialize a font attribute list to the default.
118  *              Sets '_DtMB_LEN_MAX' to the default character size.
119  *
120  *****************************************************************************/
121 void
122 _DtHelpCeCopyDefFontAttrList (_DtHelpFontHints *font_attr )
123 {
124     *font_attr = DefaultFontAttrs;
125 }
126
127 /******************************************************************************
128  * Function:    void _DtHelpFreeFontHints (
129  *
130  * Parameters:  font_hints      Specifies the font hint structure
131  *
132  * Return Value: void
133  *
134  * Purpose:     frees the strings in the font structure.
135  *
136  *****************************************************************************/
137 void
138 _DtHelpFreeFontHints (_DtHelpFontHints *font_hints )
139 {
140     /*
141      * do the language and charset
142      */
143     if (NULL != font_hints->language)
144         free(font_hints->language);
145     if (NULL != font_hints->char_set)
146         free(font_hints->char_set);
147
148     /*
149      * do the color
150      */
151     if (NULL != font_hints->color)
152         free(font_hints->color);
153
154     /*
155      * do the xlfd fonts
156      */
157     if (NULL != font_hints->xlfd)
158         free(font_hints->xlfd);
159     if (NULL != font_hints->xlfdb)
160         free(font_hints->xlfdb);
161     if (NULL != font_hints->xlfdi)
162         free(font_hints->xlfdi);
163     if (NULL != font_hints->xlfdib)
164         free(font_hints->xlfdib);
165
166     /*
167      * do the ms-windows fonts
168      */
169     if (NULL != font_hints->typenam)
170         free(font_hints->typenam);
171     if (NULL != font_hints->typenamb)
172         free(font_hints->typenamb);
173     if (NULL != font_hints->typenami)
174         free(font_hints->typenami);
175     if (NULL != font_hints->typenamib)
176         free(font_hints->typenamib);
177 }
178
179 /******************************************************************************
180  * Function:    void _DtHelpDupFontHints (
181  *
182  * Parameters:  font_hints      Specifies the font hint structure
183  *
184  * Return Value: 0 for successful, -1 if failures.
185  *
186  * Purpose:     to the dup the strings in the font hint structure.
187  *
188  *****************************************************************************/
189 int
190 _DtHelpDupFontHints (_DtHelpFontHints *font_hints )
191 {
192     int result = 0;
193
194     /*
195      * do the language and charset
196      */
197     if (-1 == HintDuplicate(&(font_hints->language)))
198         result = -1;
199     if (-1 == HintDuplicate(&(font_hints->char_set)))
200         result = -1;
201
202     /*
203      * do the color
204      */
205     if (-1 == HintDuplicate(&(font_hints->color)))
206         result = -1;
207
208     /*
209      * do the xlfd fonts
210      */
211     if (-1 == HintDuplicate(&(font_hints->xlfd)))
212         result = -1;
213     if (-1 == HintDuplicate(&(font_hints->xlfdb)))
214         result = -1;
215     if (-1 == HintDuplicate(&(font_hints->xlfdi)))
216         result = -1;
217     if (-1 == HintDuplicate(&(font_hints->xlfdib)))
218         result = -1;
219
220     /*
221      * do the ms-windows fonts
222      */
223     if (-1 == HintDuplicate(&(font_hints->typenam)))
224         result = -1;
225     if (-1 == HintDuplicate(&(font_hints->typenamb)))
226         result = -1;
227     if (-1 == HintDuplicate(&(font_hints->typenami)))
228         result = -1;
229     if (-1 == HintDuplicate(&(font_hints->typenamib)))
230         result = -1;
231
232     if (-1 == result)
233         _DtHelpFreeFontHints(font_hints);
234
235     return result;
236 }