Add GNU LGPL headers to all .c .C and .h files
[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 "AccessP.h"
70 #include "AccessSDLP.h"
71 #include "AccessSDLI.h"
72 #include "AccessCCDFP.h"
73 #include "AccessCCDFI.h"
74 #include "SDLI.h"
75 #include "FormatUtilI.h"
76 #include "FormatSDLI.h"
77 #include "Lock.h"
78
79 #ifdef NLS16
80 #endif
81
82 /********    Private Defines      ********/
83 /********    Private Function Declarations    ********/
84 static  void            DefCvsMetrics(
85                                 _DtCvPointer             client_data,
86                                 _DtCvElemType   elem_type,
87                                 _DtCvPointer    ret_metrics);
88 /********    Private Macro Declarations        ********/
89
90 /******************************************************************************
91 *
92 * Private variables used within this file.
93 *
94 *******************************************************************************/
95 static _DtCvVirtualInfo MyVirtInfo =
96   {
97         DefCvsMetrics,  /* void            (*_CEGet_DtCvMetrics)(); */
98         NULL,           /* void            (*_DtCvRenderElem)(); */
99         NULL, /* DefCvsStrWidth, _DtCvUnit (*_DtCvGetElemWidth)(); */
100         NULL, /* DefCvsFontMetrics, void   (*_DtCvGetFontMetrics)(); */
101         NULL,           /* VStatus         (*_DtCvBuildSelection)(); */
102   };
103
104 static  const _DtCvSpaceMetrics defLinkMetrics = { 0, 0, 0, 0 };
105
106 /******************************************************************************
107  *
108  * Private functions
109  *
110  ******************************************************************************/
111 /*****************************************************************************
112  * Function:    void DefCvsMetrics ();
113  *
114  * Parameters:
115  *
116  * Returns:
117  *
118  * Purpose:
119  *
120  *****************************************************************************/
121 static  void
122 DefCvsMetrics (
123     _DtCvPointer                 client_data,
124     _DtCvElemType       elem_type,
125     _DtCvPointer        ret_metrics)
126 {
127     _DtCvSpaceMetrics *retLink = (_DtCvSpaceMetrics *) ret_metrics;
128
129     if (_DtCvCANVAS_TYPE == elem_type)
130       {
131         _DtCvMetrics *retCanvas = (_DtCvMetrics *) ret_metrics;
132
133         retCanvas->width          = 1;
134         retCanvas->height         = 1;
135         retCanvas->top_margin     = 0;
136         retCanvas->side_margin    = 0;
137         retCanvas->line_height    = 1;
138         retCanvas->horiz_pad_hint = 1;
139       }
140     else if (_DtCvLINK_TYPE == elem_type || _DtCvTRAVERSAL_TYPE == elem_type)
141         *retLink = defLinkMetrics;
142 }
143
144 /******************************************************************************
145  *                          Semi-Public Functions
146  ******************************************************************************/
147 /******************************************************************************
148  * Function:    int _DtHelpCeGetVolumeTitle(_DtHelpVolume vol, char **retTitle);
149  *
150  * Parameters:  vol             Specifies the loaded volume.
151  *              retTitle        Returns the title of the volume. This string is
152  *                              owned by the caller and must be freed.
153  *
154  * Return Value: 0 if successful, -1 if a failure occurs
155  *
156  * Purpose:     Get the title of a volume.
157  *
158  * Used by:     dthelpgen 1.0
159  *
160  ******************************************************************************/
161 int 
162 _DtHelpCeGetVolumeTitle (
163     CanvasHandle          canvas,
164     VolumeHandle          volume,
165     char                **ret_title)
166 {
167     _FrmtUiInfo myUiInfo;
168     _DtHelpVolume vol = (_DtHelpVolume)volume;
169     int result;
170
171     /*
172      * set up my UI information
173      */
174     myUiInfo.load_graphic = NULL;
175     myUiInfo.resolve_spc  = NULL;
176     myUiInfo.load_font    = NULL;
177     myUiInfo.destroy_region = NULL;
178     myUiInfo.exec_filter  = NULL;
179     myUiInfo.client_data  = NULL;
180     /* since we're going for a string, set avg_char width to 1 */
181     myUiInfo.line_width   = 0;
182     myUiInfo.line_height  = 0;
183     myUiInfo.leading      = 0;
184     myUiInfo.avg_char     = 1;
185     myUiInfo.nl_to_space  = 0;
186
187     /*
188      * What type of volume is it?
189      */
190     _DtHelpProcessLock();
191     if (0 == _DtHelpCeGetVolumeFlag(volume))
192       {
193         result = _DtHelpCeGetCcdfVolumeTitle(vol, ret_title);
194       }
195     else
196       {
197         result = _DtHelpCeFrmtSDLVolTitleToAscii(volume, &myUiInfo, ret_title);
198       }
199     _DtHelpProcessUnlock();
200     return result;
201 }
202 /******************************************************************************
203  * Function:    int _DtHelpCeGetAsciiVolumeAbstract (_DtHelpVolume vol, char **a
204 bstract);
205  *
206  * Parameters:  vol     Specifies the loaded volume.
207  *              abstract Returns the abstract of the volume.  This string
208  *                       is owned by the caller and should be freed.
209  *
210  * Return Value: 0 if successful, -1 if a failure occurs
211  *
212  * Purpose:     Get the abstract of a volume.
213  *
214  * Used by:     dthelpgen 1.0
215  *
216  ******************************************************************************/
217 int
218 _DtHelpCeGetAsciiVolumeAbstract (
219     CanvasHandle          canvas,
220     VolumeHandle          volume,
221     char                **retAbs)
222 {
223     _DtHelpVolume vol = (_DtHelpVolume)volume;
224     int result;
225
226     /*
227      * What type of volume is it?
228      */
229     _DtHelpProcessLock();
230     if (0 == _DtHelpCeGetVolumeFlag(volume))
231       {
232         result = _DtHelpCeGetCcdfVolumeAbstract(vol, retAbs);
233         _DtHelpProcessUnlock();
234         return result;
235       }
236
237     *retAbs = _DtHelpCeGetSdlVolumeAsciiAbstract(volume);
238     if (*retAbs == NULL)
239       {
240         _DtHelpProcessUnlock();
241         return (-1);
242       }
243
244     _DtHelpProcessUnlock();
245     return (0);
246 }
247
248 /*****************************************************************************
249  * Function:    CanvasHandle _DtHelpCeCreateDefCanvas (void);
250  *
251  * Parameters:
252  *
253  * Returns:     A handle to the canvas or NULL if an error occurs.
254  *
255  * Purpose:     Create a canvas and attach the appropriate virtual functions
256  *              to the canvas.
257  *****************************************************************************/
258 CanvasHandle
259 _DtHelpCeCreateDefCanvas (void)
260 {
261     return (_DtCanvasCreate(MyVirtInfo, NULL));
262
263 } /* End _DtHelpCeCreateDefCanvas */
264
265 /******************************************************************************
266  * Function:    char *_DtHelpCeGetNxtToken (char *str, char **retToken)
267  *
268  * Parameters:
269  * Return Value:        Returns the pointer to the next unparsed character in
270  *                      the input string. A NULL value indicates an error.
271  *
272  * errno Values:
273  *              EINVAL
274  *              CEErrorMalloc
275  *
276  * Purpose:     Parse tokens in resource string values.
277  *
278  *****************************************************************************/
279 char *
280 _DtHelpCeGetNxtToken (
281     char        *str,
282     char        **retToken)
283 {
284    return (_DtHelpGetNxtToken(str, retToken));
285 }