GenUtils.c 8.5 KB

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