dtcalc: change from obsoleted MAXFLOAT to FLT_MAX from std C
[oweals/cde.git] / cde / lib / DtHelp / GenUtils.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 librararies 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: GenUtils.c /main/10 1996/05/09 03:42:28 drk $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:        GenUtils.c
28  **
29  **   Project:     CDEnext Info Access.
30  **
31  **   Description: This module contains non public routines used only by
32  **                CDE 1.0 dthelpgen.  If any of these routines are
33  **                renamed or modified to remove or add parameters, the
34  **                original routine should be moved to Obsolete.c, a new
35  **                routine created (and named differently), and the old
36  **                routine should call the new routine.
37  **
38  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
39  **
40  **  (c) Copyright 1993, 1994 Hewlett-Packard Company
41  **  (c) Copyright 1993, 1994 International Business Machines Corp.
42  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
43  **  (c) Copyright 1993, 1994 Novell, Inc.
44  **
45  **
46  ****************************************************************************
47  ************************************<+>*************************************/
48
49 /*
50  * system includes
51  */
52 #include <stdio.h>
53 #include <X11/Xlib.h>
54 #include <X11/Xresource.h>
55
56 /*
57  * Canvas Engine includes
58  */
59 #include "CanvasP.h"
60 #include "CanvasSegP.h"
61
62 /*
63  * private includes
64  */
65 #include "bufioI.h"     /* for FormatUtilI.h */
66 #include "GenUtilsP.h"
67 #include "FontAttrI.h"
68 #include "Access.h"
69 #include "AccessI.h"
70 #include "AccessP.h"
71 #include "AccessSDLP.h"
72 #include "AccessSDLI.h"
73 #include "AccessCCDFP.h"
74 #include "AccessCCDFI.h"
75 #include "SDLI.h"
76 #include "FormatUtilI.h"
77 #include "FormatSDLI.h"
78 #include "Lock.h"
79
80 #ifdef NLS16
81 #endif
82
83 /********    Private Defines      ********/
84 /********    Private Function Declarations    ********/
85 static  void            DefCvsMetrics(
86                                 _DtCvPointer             client_data,
87                                 _DtCvElemType   elem_type,
88                                 _DtCvPointer    ret_metrics);
89 /********    Private Macro Declarations        ********/
90
91 /******************************************************************************
92 *
93 * Private variables used within this file.
94 *
95 *******************************************************************************/
96 static _DtCvVirtualInfo MyVirtInfo =
97   {
98         DefCvsMetrics,  /* void            (*_CEGet_DtCvMetrics)(); */
99         NULL,           /* void            (*_DtCvRenderElem)(); */
100         NULL, /* DefCvsStrWidth, _DtCvUnit (*_DtCvGetElemWidth)(); */
101         NULL, /* DefCvsFontMetrics, void   (*_DtCvGetFontMetrics)(); */
102         NULL,           /* VStatus         (*_DtCvBuildSelection)(); */
103   };
104
105 static  const _DtCvSpaceMetrics defLinkMetrics = { 0, 0, 0, 0 };
106
107 /******************************************************************************
108  *
109  * Private functions
110  *
111  ******************************************************************************/
112 /*****************************************************************************
113  * Function:    void DefCvsMetrics ();
114  *
115  * Parameters:
116  *
117  * Returns:
118  *
119  * Purpose:
120  *
121  *****************************************************************************/
122 static  void
123 DefCvsMetrics (
124     _DtCvPointer                 client_data,
125     _DtCvElemType       elem_type,
126     _DtCvPointer        ret_metrics)
127 {
128     _DtCvSpaceMetrics *retLink = (_DtCvSpaceMetrics *) ret_metrics;
129
130     if (_DtCvCANVAS_TYPE == elem_type)
131       {
132         _DtCvMetrics *retCanvas = (_DtCvMetrics *) ret_metrics;
133
134         retCanvas->width          = 1;
135         retCanvas->height         = 1;
136         retCanvas->top_margin     = 0;
137         retCanvas->side_margin    = 0;
138         retCanvas->line_height    = 1;
139         retCanvas->horiz_pad_hint = 1;
140       }
141     else if (_DtCvLINK_TYPE == elem_type || _DtCvTRAVERSAL_TYPE == elem_type)
142         *retLink = defLinkMetrics;
143 }
144
145 /******************************************************************************
146  *                          Semi-Public Functions
147  ******************************************************************************/
148 /******************************************************************************
149  * Function:    int _DtHelpCeGetVolumeTitle(_DtHelpVolume vol, char **retTitle);
150  *
151  * Parameters:  vol             Specifies the loaded volume.
152  *              retTitle        Returns the title of the volume. This string is
153  *                              owned by the caller and must be freed.
154  *
155  * Return Value: 0 if successful, -1 if a failure occurs
156  *
157  * Purpose:     Get the title of a volume.
158  *
159  * Used by:     dthelpgen 1.0
160  *
161  ******************************************************************************/
162 int 
163 _DtHelpCeGetVolumeTitle (
164     CanvasHandle          canvas,
165     VolumeHandle          volume,
166     char                **ret_title)
167 {
168     _FrmtUiInfo myUiInfo;
169     _DtHelpVolume vol = (_DtHelpVolume)volume;
170     int result;
171
172     /*
173      * set up my UI information
174      */
175     myUiInfo.load_graphic = NULL;
176     myUiInfo.resolve_spc  = NULL;
177     myUiInfo.load_font    = NULL;
178     myUiInfo.destroy_region = NULL;
179     myUiInfo.exec_filter  = NULL;
180     myUiInfo.client_data  = NULL;
181     /* since we're going for a string, set avg_char width to 1 */
182     myUiInfo.line_width   = 0;
183     myUiInfo.line_height  = 0;
184     myUiInfo.leading      = 0;
185     myUiInfo.avg_char     = 1;
186     myUiInfo.nl_to_space  = 0;
187
188     /*
189      * What type of volume is it?
190      */
191     _DtHelpProcessLock();
192     if (0 == _DtHelpCeGetVolumeFlag(volume))
193       {
194         result = _DtHelpCeGetCcdfVolumeTitle(vol, ret_title);
195       }
196     else
197       {
198         result = _DtHelpCeFrmtSDLVolTitleToAscii(volume, &myUiInfo, ret_title);
199       }
200     _DtHelpProcessUnlock();
201     return result;
202 }
203 /******************************************************************************
204  * Function:    int _DtHelpCeGetAsciiVolumeAbstract (_DtHelpVolume vol, char **a
205 bstract);
206  *
207  * Parameters:  vol     Specifies the loaded volume.
208  *              abstract Returns the abstract of the volume.  This string
209  *                       is owned by the caller and should be freed.
210  *
211  * Return Value: 0 if successful, -1 if a failure occurs
212  *
213  * Purpose:     Get the abstract of a volume.
214  *
215  * Used by:     dthelpgen 1.0
216  *
217  ******************************************************************************/
218 int
219 _DtHelpCeGetAsciiVolumeAbstract (
220     CanvasHandle          canvas,
221     VolumeHandle          volume,
222     char                **retAbs)
223 {
224     _DtHelpVolume vol = (_DtHelpVolume)volume;
225     int result;
226
227     /*
228      * What type of volume is it?
229      */
230     _DtHelpProcessLock();
231     if (0 == _DtHelpCeGetVolumeFlag(volume))
232       {
233         result = _DtHelpCeGetCcdfVolumeAbstract(vol, retAbs);
234         _DtHelpProcessUnlock();
235         return result;
236       }
237
238     *retAbs = _DtHelpCeGetSdlVolumeAsciiAbstract(volume);
239     if (*retAbs == NULL)
240       {
241         _DtHelpProcessUnlock();
242         return (-1);
243       }
244
245     _DtHelpProcessUnlock();
246     return (0);
247 }
248
249 /*****************************************************************************
250  * Function:    CanvasHandle _DtHelpCeCreateDefCanvas (void);
251  *
252  * Parameters:
253  *
254  * Returns:     A handle to the canvas or NULL if an error occurs.
255  *
256  * Purpose:     Create a canvas and attach the appropriate virtual functions
257  *              to the canvas.
258  *****************************************************************************/
259 CanvasHandle
260 _DtHelpCeCreateDefCanvas (void)
261 {
262     return (_DtCanvasCreate(MyVirtInfo, NULL));
263
264 } /* End _DtHelpCeCreateDefCanvas */
265
266 /******************************************************************************
267  * Function:    char *_DtHelpCeGetNxtToken (char *str, char **retToken)
268  *
269  * Parameters:
270  * Return Value:        Returns the pointer to the next unparsed character in
271  *                      the input string. A NULL value indicates an error.
272  *
273  * errno Values:
274  *              EINVAL
275  *              CEErrorMalloc
276  *
277  * Purpose:     Parse tokens in resource string values.
278  *
279  *****************************************************************************/
280 char *
281 _DtHelpCeGetNxtToken (
282     char        *str,
283     char        **retToken)
284 {
285    return (_DtHelpGetNxtToken(str, retToken));
286 }