Format.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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: Format.c /main/18 1996/11/22 12:23:59 cde-hp $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Format.c
  28. **
  29. ** Project: Text Graphic Display Library
  30. **
  31. ** Description: This body of formats the input into a form understood by
  32. ** a Display Area.
  33. **
  34. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  35. **
  36. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  37. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  38. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  39. ** (c) Copyright 1993, 1994 Novell, Inc.
  40. **
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. /*
  45. * system includes
  46. */
  47. #include <stdio.h>
  48. #include <errno.h>
  49. #include <fcntl.h>
  50. #include <locale.h>
  51. #include <stdlib.h>
  52. #include <unistd.h>
  53. #include <X11/Xlib.h>
  54. #include <X11/Xresource.h>
  55. #include <Xm/Xm.h>
  56. #ifdef X_NOT_STDC_ENV
  57. extern int errno;
  58. #endif
  59. /*
  60. * Core Engine includes
  61. */
  62. #include "CanvasP.h"
  63. #include "CanvasSegP.h"
  64. /*
  65. * private includes
  66. */
  67. #include "bufioI.h"
  68. #include "CvtToArrayP.h"
  69. #include "DisplayAreaP.h"
  70. #include "FontAttrI.h"
  71. #include "FontI.h"
  72. #include "HelpXlate.h"
  73. #include "XInterfaceI.h"
  74. #include "Lock.h"
  75. /*
  76. * private core engine
  77. */
  78. #include "Access.h"
  79. #include "AccessP.h"
  80. #include "AccessI.h"
  81. #include "AccessCCDFI.h"
  82. #include "SDLI.h"
  83. #include "FormatUtilI.h"
  84. #include "FormatCCDFI.h"
  85. #include "FormatSDLI.h"
  86. #include "StringFuncsI.h"
  87. #ifdef NLS16
  88. #endif
  89. /******** Private Function Declarations ********/
  90. /******** End Public Function Declarations ********/
  91. /******************************************************************************
  92. *
  93. * Private variables and defines.
  94. *
  95. *****************************************************************************/
  96. #define BUFF_SIZE 1024
  97. static char *ScanString = "\n\t";
  98. static const _FrmtUiInfo defUiInfo = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 1, False };
  99. /******************************************************************************
  100. *
  101. * Private Functions
  102. *
  103. *****************************************************************************/
  104. /******************************************************************************
  105. * Function: int FormatChunksToXmString ()
  106. *
  107. * Parameters:
  108. * *ret_list may be NULL when called
  109. *
  110. * Returns: 0 if successful, -1 if errors
  111. *
  112. * errno Values:
  113. *
  114. * Purpose: Take some rich text chunks and turn it into an XmString.
  115. *
  116. ******************************************************************************/
  117. static int
  118. FormatChunksToXmString(
  119. DtHelpDispAreaStruct *pDAS,
  120. Boolean free_flag,
  121. void **title_chunks,
  122. XmString *ret_title,
  123. XmFontList *ret_list,
  124. Boolean *ret_mod )
  125. {
  126. int result = 0;
  127. int i;
  128. long j;
  129. int quarkCount;
  130. long chunkType;
  131. long myIdx;
  132. _DtCvPointer fontPtr;
  133. char *charSet;
  134. const char *strChunk;
  135. char buffer[16];
  136. _DtHelpFontHints fontSpecs;
  137. XmFontContext fontContext;
  138. XmString partTitle;
  139. XmString newTitle;
  140. XrmQuark charSetQuark;
  141. XrmName myCharSetQuarks[20];
  142. XrmName xrmName[_CEFontAttrNumber];
  143. Boolean myMore;
  144. /*
  145. * Initialize the pointers.
  146. */
  147. *ret_title = NULL;
  148. *ret_mod = False;
  149. if (title_chunks == NULL)
  150. return -1;
  151. /*
  152. * initialize the font context
  153. */
  154. _DtHelpCeCopyDefFontAttrList(&fontSpecs);
  155. if ( NULL != *ret_list )
  156. {
  157. if (XmFontListInitFontContext (&fontContext, *ret_list) == False)
  158. result = -1;
  159. else
  160. {
  161. XFontStruct *myFontStruct;
  162. /*
  163. * quarkize all the character sets found.
  164. */
  165. quarkCount = 0;
  166. do
  167. {
  168. myMore = XmFontListGetNextFont (fontContext, &charSet,
  169. &myFontStruct);
  170. if (myMore)
  171. {
  172. myCharSetQuarks[quarkCount++] =
  173. XrmStringToQuark (charSet);
  174. XtFree (charSet);
  175. }
  176. } while (myMore);
  177. XmFontListFreeFontContext (fontContext);
  178. }
  179. } /* if NULL != *ret_list */
  180. else
  181. { /* if NULL == *ret_list */
  182. quarkCount = 0;
  183. myCharSetQuarks[0] = 0;
  184. }
  185. /*
  186. * Build the XrmString based on the segments.
  187. * The format of the returned information is
  188. * 'DT_HELP_CE_CHARSET locale string'
  189. * 'DT_HELP_CE_FONT_PTR fontptr string'
  190. * 'DT_HELP_CE_SPC spc'
  191. * 'DT_HELP_CE_STRING string' - uses last specified
  192. * charset/font_ptr.
  193. *
  194. * The order and manner in which the title_chunks are processed
  195. * is known and depended upon in several locations.
  196. * Do not change this without changing the other locations.
  197. * See the _DtHelpFormatxxx() routines and the ones that
  198. * create the title_chunk arrays in FormatSDL.c and FormatCCDF.c
  199. */
  200. myIdx = __DtHelpDefaultFontIndexGet(pDAS);
  201. _DtHelpCopyDefaultList(xrmName);
  202. for (i = 0; result == 0 && title_chunks[i] != DT_HELP_CE_END; i++)
  203. {
  204. /*
  205. * create a string for the char set and a quark for it.
  206. */
  207. chunkType = (long) title_chunks[i++];
  208. /*
  209. * i now points to the first value after the type
  210. */
  211. if (chunkType & DT_HELP_CE_CHARSET)
  212. {
  213. char *charSet;
  214. char *lang = (char *) title_chunks[i];
  215. /*
  216. * test to see if the locale is in a lang.codeset form
  217. */
  218. if (_DtHelpCeStrchr(lang, ".", 1, &charSet) == 0)
  219. {
  220. *charSet = '\0';
  221. charSet++;
  222. }
  223. else
  224. {
  225. charSet = lang;
  226. lang = NULL;
  227. }
  228. /*
  229. * resolve/load the font for the default fonts
  230. */
  231. _DtHelpDAResolveFont(pDAS, lang, charSet, fontSpecs, &fontPtr);
  232. myIdx = (long) fontPtr;
  233. if (lang != NULL)
  234. {
  235. charSet--;
  236. *charSet = '.';
  237. }
  238. if (free_flag)
  239. free(title_chunks[i]);
  240. /*
  241. * move the i to point to the string.
  242. */
  243. i++;
  244. }
  245. else if (chunkType & DT_HELP_CE_FONT_PTR)
  246. {
  247. /*
  248. * get the default font for the language and code set.
  249. */
  250. (void) __DtHelpFontCharSetQuarkGet(pDAS, (long)title_chunks[i],
  251. &xrmName[_DT_HELP_FONT_CHAR_SET]);
  252. (void) __DtHelpFontLangQuarkGet(pDAS, (long)title_chunks[i],
  253. &xrmName[_DT_HELP_FONT_LANG_TER]);
  254. (void) __DtHelpFontIndexGet(pDAS, xrmName, &myIdx);
  255. /*
  256. * move the i to point to the string.
  257. */
  258. i++;
  259. }
  260. /*
  261. * the i point spc or string.
  262. */
  263. if (chunkType & DT_HELP_CE_SPC)
  264. {
  265. j = (long) title_chunks[i];
  266. strChunk = _DtHelpDAGetSpcString(pDAS->spc_chars[j].spc_idx);
  267. fontPtr = pDAS->spc_chars[j].font_ptr;
  268. /*
  269. * get the default font for the language and code set.
  270. */
  271. (void) __DtHelpFontCharSetQuarkGet(pDAS, (long)fontPtr,
  272. &xrmName[_DT_HELP_FONT_CHAR_SET]);
  273. (void) __DtHelpFontLangQuarkGet(pDAS, (long)fontPtr,
  274. &xrmName[_DT_HELP_FONT_LANG_TER]);
  275. (void) __DtHelpFontIndexGet(pDAS, xrmName, &myIdx);
  276. }
  277. else /* if (chunkType & _DT_HELP_CE_STRING) */
  278. strChunk = (char *) title_chunks[i];
  279. sprintf(buffer, "%ld", myIdx);
  280. charSetQuark = XrmStringToQuark(buffer);
  281. j = 0;
  282. while (j < quarkCount && myCharSetQuarks[j] != charSetQuark)
  283. j++;
  284. /*
  285. * If we didn't find a matching character set,
  286. * add it to the list.
  287. */
  288. if (j >= quarkCount)
  289. {
  290. /* Copy the input list so XmFontListAppendEntry can mangle it. */
  291. /* But only do it once! */
  292. if (False == *ret_mod)
  293. *ret_list = XmFontListCopy(*ret_list);
  294. if (myIdx < 0)
  295. {
  296. XFontSet fontSet = __DtHelpFontSetGet(pDAS->font_info, myIdx);
  297. XmFontListEntry fontEntry;
  298. fontEntry = XmFontListEntryCreate (buffer,
  299. XmFONT_IS_FONTSET,
  300. (XtPointer) fontSet);
  301. *ret_list = XmFontListAppendEntry (*ret_list, fontEntry);
  302. XmFontListEntryFree (&fontEntry);
  303. }
  304. else
  305. {
  306. XFontStruct *fontStruct =
  307. __DtHelpFontStructGet(pDAS->font_info, myIdx);
  308. XmFontListEntry fontEntry;
  309. fontEntry = XmFontListEntryCreate (buffer,
  310. XmFONT_IS_FONT,
  311. (XtPointer) fontStruct);
  312. *ret_list = XmFontListAppendEntry (*ret_list, fontEntry);
  313. XmFontListEntryFree (&fontEntry);
  314. }
  315. *ret_mod = True;
  316. if (*ret_list == NULL)
  317. result = -1;
  318. myCharSetQuarks[quarkCount++] = charSetQuark;
  319. }
  320. /*
  321. * add this segment to the XmString.
  322. */
  323. if (result == 0)
  324. {
  325. if (*ret_title == NULL)
  326. *ret_title = XmStringGenerate ((char *) strChunk, buffer,
  327. XmCHARSET_TEXT, NULL);
  328. else
  329. {
  330. partTitle = XmStringGenerate ((char *) strChunk, buffer,
  331. XmCHARSET_TEXT, NULL);
  332. newTitle = XmStringConcat (*ret_title, partTitle);
  333. XmStringFree (*ret_title);
  334. XmStringFree (partTitle);
  335. *ret_title = newTitle;
  336. }
  337. /*
  338. * if a newline was specified,
  339. * replace it with a blank.
  340. */
  341. if (*ret_title != NULL && (chunkType & DT_HELP_CE_NEWLINE))
  342. {
  343. partTitle = XmStringGenerate (" ", buffer, XmCHARSET_TEXT, NULL);
  344. newTitle = XmStringConcat (*ret_title, partTitle);
  345. XmStringFree (*ret_title);
  346. XmStringFree (partTitle);
  347. *ret_title = newTitle;
  348. }
  349. if (*ret_title == NULL)
  350. result = -1;
  351. }
  352. if (free_flag && (chunkType & DT_HELP_CE_STRING))
  353. free(title_chunks[i]);
  354. }
  355. /*
  356. * deallocate the memory.
  357. */
  358. if (free_flag) free(title_chunks);
  359. return result;
  360. }
  361. /******************************************************************************
  362. *
  363. * Semi-Public Functions
  364. *
  365. *****************************************************************************/
  366. /*****************************************************************************
  367. * Function: int _DtHelpFormatAsciiFile (char *filename,
  368. * CEParagraph **ret_para, int *ret_num)
  369. *
  370. * Parameters:
  371. * filename Specifies the ascii file to read.
  372. * ret_para Returns a pointer to a list of CEParagraph
  373. * structures.
  374. * ret_num Returns the number of structures in 'ret_para'.
  375. *
  376. * Returns: 0 if successful, -1 if errors
  377. *
  378. * errno Values:
  379. * EINVAL
  380. *
  381. * Purpose: _DtHelpFormatAsciiFile formats Ascii Files into a list of
  382. * CEParagraph structures.
  383. *
  384. *****************************************************************************/
  385. int
  386. _DtHelpFormatAsciiFile(
  387. XtPointer client_data,
  388. char *filename,
  389. XtPointer *ret_handle)
  390. {
  391. int myFile;
  392. int result = -1;
  393. _DtHelpFontHints fontAttrs;
  394. char buffer [BUFF_SIZE];
  395. BufFilePtr rawInput;
  396. XtPointer varHandle;
  397. _DtCvTopicPtr topic = NULL;
  398. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  399. _FrmtUiInfo myUiInfo = defUiInfo;
  400. /*
  401. * check the parameters
  402. */
  403. if (filename == NULL || ret_handle == NULL)
  404. {
  405. errno = EINVAL;
  406. return -1;
  407. }
  408. /*
  409. * Initialize the pointers, buffers and counters
  410. */
  411. *ret_handle = NULL;
  412. /*
  413. * open the file.
  414. */
  415. myFile = open (filename, O_RDONLY);
  416. if (myFile != -1)
  417. {
  418. /*
  419. * set the information
  420. */
  421. rawInput = _DtHelpCeBufFileRdWithFd(myFile);
  422. if (rawInput == 0)
  423. {
  424. close (myFile);
  425. return -1;
  426. }
  427. result = _DtHelpCeReadBuf (rawInput, buffer, BUFF_SIZE);
  428. if (result != -1)
  429. {
  430. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  431. fontAttrs.spacing = _DtHelpFontSpacingMono;
  432. _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,
  433. setlocale(LC_CTYPE,NULL), NULL,
  434. &(fontAttrs.language), &(fontAttrs.char_set));
  435. /*
  436. * fill out the ui information
  437. */
  438. myUiInfo.load_font = _DtHelpDAResolveFont;
  439. myUiInfo.client_data = (_DtCvPointer) pDAS;
  440. myUiInfo.line_width = pDAS->lineThickness;
  441. myUiInfo.line_height = pDAS->lineHeight;
  442. myUiInfo.leading = pDAS->leading;
  443. myUiInfo.avg_char = (int)(pDAS->charWidth / 10 +
  444. ((pDAS->charWidth % 10) ? 1 : 0));
  445. myUiInfo.nl_to_space = pDAS->nl_to_space;
  446. /*
  447. * get the formatting structure.
  448. */
  449. varHandle = __DtHelpCeSetUpVars(fontAttrs.language,
  450. fontAttrs.char_set, &myUiInfo);
  451. if (varHandle == NULL)
  452. {
  453. free(fontAttrs.language);
  454. free(fontAttrs.char_set);
  455. return -1;
  456. }
  457. result = __DtHelpCeProcessString (varHandle, rawInput,
  458. _DtCvLITERAL,
  459. ScanString, buffer, BUFF_SIZE,
  460. 0, False, &fontAttrs);
  461. if (result != -1)
  462. result = __DtHelpCeGetParagraphList (varHandle, True,
  463. _DtCvLITERAL,
  464. &topic);
  465. free(fontAttrs.language);
  466. free(fontAttrs.char_set);
  467. free(varHandle);
  468. }
  469. _DtHelpCeBufFileClose(rawInput, True);
  470. }
  471. *ret_handle = (XtPointer) topic;
  472. return result;
  473. } /* End _DtHelpFormatAsciiFile */
  474. /*****************************************************************************
  475. * Function: int _DtHelpFormatAsciiString (char *input_string,
  476. * CEParagraph **ret_para, int *ret_num)
  477. *
  478. * Parameters:
  479. * input_string Specifies the ascii string to format.
  480. * ret_para Returns a pointer to a list of CEParagraph
  481. * structures.
  482. * ret_num Returns the number of structures in 'ret_para'.
  483. *
  484. * Returns: 0 if successful, -1 if errors
  485. *
  486. * errno Values:
  487. *
  488. * Purpose: _DtHelpFormatAsciiString formats a string as if it were a
  489. * static string - watching for newlines and using them
  490. * to force a break in the line.
  491. *
  492. *****************************************************************************/
  493. int
  494. _DtHelpFormatAsciiString(
  495. XtPointer client_data,
  496. char *input_string,
  497. XtPointer *ret_handle)
  498. {
  499. int result = -1;
  500. _DtHelpFontHints fontAttrs;
  501. XtPointer varHandle;
  502. _DtCvTopicPtr topic = NULL;
  503. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  504. _FrmtUiInfo myUiInfo = defUiInfo;
  505. /*
  506. * check the parameters.
  507. */
  508. if (input_string == NULL || ret_handle == NULL)
  509. {
  510. errno = EINVAL;
  511. return -1;
  512. }
  513. /*
  514. * fill out the ui information
  515. */
  516. myUiInfo.load_font = _DtHelpDAResolveFont;
  517. myUiInfo.client_data = (_DtCvPointer) pDAS;
  518. myUiInfo.line_width = pDAS->lineThickness;
  519. myUiInfo.line_height = pDAS->lineHeight;
  520. myUiInfo.leading = pDAS->leading;
  521. myUiInfo.avg_char = (int)(pDAS->charWidth / 10 +
  522. ((pDAS->charWidth % 10) ? 1 : 0));
  523. myUiInfo.nl_to_space = pDAS->nl_to_space;
  524. /*
  525. * Get the initialized variables
  526. */
  527. *ret_handle = NULL;
  528. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  529. _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,setlocale(LC_CTYPE,NULL),
  530. NULL, &(fontAttrs.language),
  531. &(fontAttrs.char_set));
  532. varHandle = __DtHelpCeSetUpVars(fontAttrs.language, fontAttrs.char_set,
  533. &myUiInfo);
  534. if (varHandle == NULL)
  535. {
  536. free(fontAttrs.language);
  537. free(fontAttrs.char_set);
  538. return -1;
  539. }
  540. result = __DtHelpCeProcessString (varHandle, NULL,
  541. _DtCvLITERAL,
  542. ScanString, input_string,
  543. strlen(input_string),
  544. 0, False,
  545. &fontAttrs);
  546. if (result != -1)
  547. result = __DtHelpCeGetParagraphList (varHandle, True, _DtCvLITERAL,
  548. &topic);
  549. *ret_handle = (XtPointer) topic;
  550. free(fontAttrs.language);
  551. free(fontAttrs.char_set);
  552. free(varHandle);
  553. return result;
  554. } /* End _DtHelpFormatAsciiString */
  555. /*****************************************************************************
  556. * Function: int _DtHelpFormatAsciiStringDynamic (char *input_string,
  557. * CEParagraph **ret_para, int *ret_num)
  558. *
  559. * Parameters:
  560. * input_string Specifies the ascii string to format.
  561. * ret_para Returns a pointer to a list of CEParagraph
  562. * structures.
  563. * ret_num Returns the number of structures in 'ret_para'.
  564. *
  565. * Returns: 0 if successful, -1 if errors
  566. *
  567. * errno Values:
  568. *
  569. * Purpose: _DtHelpFormatAsciiStringDynamic formats a string as if it were
  570. * a dynamic string - it uses newline characters to terminate
  571. * the current paragraph, not a line.
  572. *
  573. *****************************************************************************/
  574. int
  575. _DtHelpFormatAsciiStringDynamic(
  576. XtPointer client_data,
  577. char *input_string,
  578. XtPointer *ret_handle)
  579. {
  580. int result = -1;
  581. _DtHelpFontHints fontAttrs;
  582. XtPointer varHandle;
  583. _DtCvTopicPtr topic = NULL;
  584. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  585. _FrmtUiInfo myUiInfo = defUiInfo;
  586. /*
  587. * check the parameters.
  588. */
  589. if (input_string == NULL || ret_handle == NULL)
  590. {
  591. errno = EINVAL;
  592. return -1;
  593. }
  594. /*
  595. * fill out the ui information
  596. */
  597. myUiInfo.load_font = _DtHelpDAResolveFont;
  598. myUiInfo.client_data = (_DtCvPointer) pDAS;
  599. myUiInfo.line_width = pDAS->lineThickness;
  600. myUiInfo.line_height = pDAS->lineHeight;
  601. myUiInfo.leading = pDAS->leading;
  602. myUiInfo.avg_char = (int)(pDAS->charWidth / 10 +
  603. ((pDAS->charWidth % 10) ? 1 : 0));
  604. myUiInfo.nl_to_space = pDAS->nl_to_space;
  605. /*
  606. * Fake the flag and give the string as the input buffer.
  607. */
  608. *ret_handle = NULL;
  609. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  610. _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,setlocale(LC_CTYPE,NULL),
  611. NULL, &(fontAttrs.language),
  612. &(fontAttrs.char_set));
  613. varHandle = __DtHelpCeSetUpVars(fontAttrs.language, fontAttrs.char_set,
  614. &myUiInfo);
  615. if (varHandle == NULL)
  616. {
  617. free(fontAttrs.language);
  618. free(fontAttrs.char_set);
  619. return -1;
  620. }
  621. result = __DtHelpCeProcessString (varHandle, NULL,
  622. _DtCvDYNAMIC,
  623. ScanString, input_string,
  624. strlen(input_string),
  625. 0, True,
  626. &fontAttrs);
  627. if (result != -1)
  628. result = __DtHelpCeGetParagraphList (varHandle, False, _DtCvDYNAMIC,
  629. &topic);
  630. *ret_handle = (XtPointer) topic;
  631. free(fontAttrs.language);
  632. free(fontAttrs.char_set);
  633. free(varHandle);
  634. return result;
  635. } /* End _DtHelpFormatAsciiStringDynamic */
  636. /******************************************************************************
  637. * Function: int _DtHelpFormatTopicTitle (Display *dpy, _XvhVolume volume,
  638. * char *filename, int offset,
  639. * XmString *ret_title, XmFontList *ret_list,
  640. * Boolean *ret_mod)
  641. *
  642. * Parameters:
  643. * dpy Specifies the connection to the server.
  644. * volume Specifies the Help Volume the information
  645. * is associated with.
  646. * filename Specifies the file containing the Help Topic
  647. * desired.
  648. * offset Specifies the offset into 'filename' to
  649. * the Help Topic desired.
  650. * ret_title Returns XmString containing the title.
  651. * ret_list Specifies the current font list being used.
  652. * Returns a new font list if new character
  653. * sets are added to it.
  654. * ret_mod Returns True if fonts were added to the
  655. * font list.
  656. *
  657. * Returns: 0 if successful, -1 if errors
  658. *
  659. * errno Values:
  660. *
  661. * Purpose: _DtHelpFormatTopicTitle formats a topic title and associates
  662. * the correct font with it.
  663. *
  664. ******************************************************************************/
  665. int
  666. _DtHelpFormatTopicTitle(
  667. XtPointer client_data,
  668. _DtHelpVolumeHdl volume_handle,
  669. char *location_id,
  670. XmString *ret_title,
  671. XmFontList *ret_list,
  672. Boolean *ret_mod )
  673. {
  674. int result = -1;
  675. void **titleChunks = NULL;
  676. _FrmtUiInfo myUiInfo = defUiInfo;
  677. _DtHelpCeLockInfo lockInfo;
  678. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  679. /*
  680. * Check the parameters
  681. */
  682. if (ret_title == NULL || ret_list == NULL || ret_mod == NULL)
  683. {
  684. errno = EINVAL;
  685. return -1;
  686. }
  687. /*
  688. * lock the volume
  689. */
  690. if (_DtHelpCeLockVolume(volume_handle, &lockInfo) != 0)
  691. return -1;
  692. /*
  693. * set up my UI information
  694. */
  695. myUiInfo.load_graphic = _DtHelpDALoadGraphic;
  696. myUiInfo.resolve_spc = _DtHelpDAResolveSpc;
  697. myUiInfo.load_font = _DtHelpDAResolveFont;
  698. myUiInfo.exec_filter = pDAS->exec_filter;
  699. myUiInfo.destroy_region = _DtHelpDADestroyRegion;
  700. myUiInfo.client_data = (_DtCvPointer) pDAS;
  701. /* since we're going for chunks, set avg_char width to 1 */
  702. myUiInfo.line_width = 0;
  703. myUiInfo.line_height = 0;
  704. myUiInfo.leading = 0;
  705. myUiInfo.avg_char = 1;
  706. myUiInfo.nl_to_space = pDAS->nl_to_space;
  707. /*
  708. * Get the title and charsets associated with the title segments.
  709. * The format of the returned information is
  710. * [type,charset/fontptr,]type,string/spc
  711. */
  712. result = _DtHelpCeGetVolumeFlag(volume_handle);
  713. _DtHelpProcessLock();
  714. if (result == 1)
  715. result = _DtHelpCeGetSdlTitleChunks(volume_handle, location_id,
  716. &myUiInfo, &titleChunks);
  717. else if (result == 0)
  718. result = _DtHelpCeGetCcdfTitleChunks( volume_handle, location_id,
  719. &myUiInfo, &titleChunks);
  720. _DtHelpProcessUnlock();
  721. if (result != -1)
  722. result = FormatChunksToXmString(pDAS, True, titleChunks,
  723. ret_title, ret_list, ret_mod);
  724. _DtHelpCeUnlockVolume(lockInfo);
  725. return result;
  726. } /* End _DtHelpFormatTopicTitle */
  727. /******************************************************************************
  728. * Function: int _DtHelpFormatVolumeTitle (DtHelpDispAreaStruct *pDAS,
  729. * _XvhVolume volume,
  730. * XmString *ret_title, XmFontList *ret_list,
  731. * Boolean *ret_mod)
  732. *
  733. * Parameters:
  734. * volume Specifies the Help Volume the information
  735. * is associated with.
  736. * ret_title Returns XmString containing the title.
  737. * ret_list Specifies the current font list being used.
  738. * Returns a new font list if new character
  739. * sets are added to it.
  740. * ret_mod Returns True if fonts were added to the
  741. * font list.
  742. *
  743. * Returns: 0 if successful, -1 if errors
  744. *
  745. * errno Values:
  746. *
  747. * Purpose: _DtHelpFormatVolumeTitle formats a volume title and associates
  748. * the correct font with it.
  749. *
  750. ******************************************************************************/
  751. int
  752. _DtHelpFormatVolumeTitle(
  753. XtPointer client_data,
  754. _DtHelpVolumeHdl volume_handle,
  755. XmString *ret_title,
  756. XmFontList *ret_list,
  757. Boolean *ret_mod )
  758. {
  759. int result = -1;
  760. void **titleChunks = NULL;
  761. _FrmtUiInfo myUiInfo = defUiInfo;
  762. _DtHelpCeLockInfo lockInfo;
  763. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  764. /*
  765. * Check the parameters
  766. */
  767. if (ret_title == NULL || ret_list == NULL || ret_mod == NULL)
  768. {
  769. errno = EINVAL;
  770. return -1;
  771. }
  772. /*
  773. * lock the volume
  774. */
  775. *ret_title = NULL;
  776. if (_DtHelpCeLockVolume(volume_handle, &lockInfo) != 0)
  777. return -1;
  778. /*
  779. * set up my UI information
  780. */
  781. myUiInfo.load_graphic = _DtHelpDALoadGraphic;
  782. myUiInfo.resolve_spc = _DtHelpDAResolveSpc;
  783. myUiInfo.load_font = _DtHelpDAResolveFont;
  784. myUiInfo.exec_filter = pDAS->exec_filter;
  785. myUiInfo.destroy_region = _DtHelpDADestroyRegion;
  786. myUiInfo.client_data = (_DtCvPointer) pDAS;
  787. /* since we're going for chunks, set avg_char width to 1 */
  788. myUiInfo.line_width = 0;
  789. myUiInfo.line_height = 0;
  790. myUiInfo.leading = 0;
  791. myUiInfo.avg_char = 1;
  792. myUiInfo.nl_to_space = pDAS->nl_to_space;
  793. /*
  794. * Get the title and charsets associated with the volume title.
  795. * The format of the returned information is
  796. * [type,charset/fontptr,]type,string/spc
  797. */
  798. result = _DtHelpCeGetVolumeFlag(volume_handle);
  799. _DtHelpProcessLock();
  800. if (result == 1)
  801. result = _DtHelpCeGetSdlVolTitleChunks(volume_handle, &myUiInfo,
  802. &titleChunks);
  803. else if (result == 0)
  804. result = _DtHelpCeGetCcdfVolTitleChunks(
  805. (_DtHelpVolume) volume_handle,
  806. &myUiInfo,
  807. &titleChunks);
  808. _DtHelpProcessUnlock();
  809. if (result != -1)
  810. result = FormatChunksToXmString(pDAS, True, titleChunks,
  811. ret_title, ret_list, ret_mod);
  812. _DtHelpCeUnlockVolume(lockInfo);
  813. return result;
  814. } /* End _DtHelpFormatVolumeTitle */
  815. /******************************************************************************
  816. * Function: int _DtHelpFormatIndexEntries (DtHelpDispAreaStruct *pDAS,
  817. * _XvhVolume volume,
  818. * XmString *ret_title, XmFontList *ret_list,
  819. * Boolean *ret_mod)
  820. *
  821. * Parameters:
  822. * volume Specifies the Help Volume the information
  823. * is associated with.
  824. * ret_cnt number of valid entries in the array
  825. * ret_words Returns NULL-termintaed array of
  826. * XmStrings containing the words.
  827. * ret_list Specifies the current font list being used.
  828. * Returns a new font list if new character
  829. * sets are added to it.
  830. * ret_mod Returns True if fonts were added to the
  831. * font list.
  832. *
  833. * Returns: 0 if successful, -1 if errors
  834. *
  835. * errno Values:
  836. *
  837. * Purpose: _DtHelpFormatIndexEntries formats index entries and associates
  838. * the correct font with it.
  839. *
  840. ******************************************************************************/
  841. int
  842. _DtHelpFormatIndexEntries(
  843. XtPointer client_data,
  844. _DtHelpVolumeHdl volume_handle,
  845. int *ret_cnt,
  846. XmString **ret_words,
  847. XmFontList *ret_list,
  848. Boolean *ret_mod )
  849. {
  850. int i;
  851. int result = -1;
  852. void *titleChunks[4];
  853. char *charSet;
  854. char **keyWords;
  855. Boolean myMod = False;
  856. XmFontList oldList;
  857. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  858. /*
  859. * Check the parameters
  860. */
  861. if (ret_words == NULL || ret_list == NULL || ret_mod == NULL)
  862. {
  863. errno = EINVAL;
  864. return -1;
  865. }
  866. *ret_mod = False;
  867. charSet = _DtHelpGetVolumeLocale(volume_handle);
  868. if (charSet != NULL)
  869. {
  870. *ret_cnt = _DtHelpCeGetKeywordList(volume_handle, &keyWords);
  871. if (*ret_cnt > 0)
  872. {
  873. *ret_words = (XmString *) malloc (sizeof(XmString) * (*ret_cnt+1));
  874. if (*ret_words == NULL)
  875. return -1;
  876. /* the order of the string ptr and charset ptr in the titleChunks
  877. is determined by the order of the if(..) tests on the
  878. flags and subsequent processing in FormatChunksToXmString() */
  879. titleChunks[0] = (void *) (DT_HELP_CE_STRING | DT_HELP_CE_CHARSET);
  880. titleChunks[1] = (void *) charSet;
  881. titleChunks[3] = (void *) DT_HELP_CE_END;
  882. for (i = 0, result = 0; result == 0 && i < *ret_cnt; i++)
  883. {
  884. oldList = *ret_list;
  885. titleChunks[2] = (void *) keyWords[i];
  886. result = FormatChunksToXmString(pDAS, False, titleChunks,
  887. &(*ret_words)[i], ret_list, &myMod);
  888. if (myMod == True)
  889. {
  890. /*
  891. * if the list has been modified before,
  892. * free the previously modified list.
  893. */
  894. if (True == *ret_mod)
  895. XmFontListFree(oldList);
  896. *ret_mod = True;
  897. }
  898. }
  899. (*ret_words)[i] = NULL;
  900. }
  901. free(charSet);
  902. }
  903. return result;
  904. } /* End _DtHelpFormatIndexEntries */
  905. /******************************************************************************
  906. * Function: int _DtHelpFormatTopic (
  907. * DtHelpDispAreaStruct *pDAS,
  908. * _DtHelpVolumeHdl volume,
  909. * char *id_string,
  910. * Boolean look_at_id,
  911. * XtPointer *ret_handle)
  912. *
  913. * Parameters:
  914. * pDAS Specifies the display area to use.
  915. * volume Specifies the Help Volume the information
  916. * is associated with.
  917. * id_string Specifies the location id for the topic.
  918. * This location id can be contained in a
  919. * topic.
  920. * look_at_id Specifies whether or not to start the
  921. * display of the topic at the location id.
  922. * ret_handle Returns a handle to the topic information
  923. * including the number of paragraphs and the
  924. * id match segment.
  925. *
  926. * Returns: 0 if successful.
  927. * -1 if errors.
  928. * -2 if the id was not found.
  929. * -3 if unable to format the topic.
  930. *
  931. * errno Values:
  932. *
  933. * Purpose: _DtHelpParseTopic accesses and parses Help topics.
  934. *
  935. ******************************************************************************/
  936. int
  937. _DtHelpFormatTopic(
  938. XtPointer client_data,
  939. _DtHelpVolumeHdl volume,
  940. char *id_string,
  941. Boolean look_at_id,
  942. XtPointer *ret_handle )
  943. {
  944. char *filename = NULL;
  945. int offset;
  946. int result = -2;
  947. _DtHelpCeLockInfo lockInfo;
  948. _FrmtUiInfo myUiInfo = defUiInfo;
  949. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  950. _DtCvTopicInfo *topic;
  951. if (_DtHelpCeLockVolume(volume, &lockInfo) != 0)
  952. return -1;
  953. if (_DtHelpCeFindId(volume,id_string,lockInfo.fd,&filename,&offset)==True)
  954. {
  955. if (look_at_id == False)
  956. id_string = NULL;
  957. myUiInfo.load_graphic = _DtHelpDALoadGraphic;
  958. myUiInfo.resolve_spc = _DtHelpDAResolveSpc;
  959. myUiInfo.load_font = _DtHelpDAResolveFont;
  960. myUiInfo.exec_filter = pDAS->exec_filter;
  961. myUiInfo.destroy_region = _DtHelpDADestroyRegion;
  962. myUiInfo.client_data = (_DtCvPointer) pDAS;
  963. myUiInfo.line_width = pDAS->lineThickness;
  964. myUiInfo.line_height = pDAS->lineHeight;
  965. myUiInfo.leading = pDAS->leading;
  966. myUiInfo.avg_char = (int)(pDAS->charWidth / 10 +
  967. ((pDAS->charWidth % 10) ? 1 : 0));
  968. myUiInfo.nl_to_space = pDAS->nl_to_space;
  969. result = _DtHelpCeGetVolumeFlag(volume);
  970. _DtHelpProcessLock();
  971. if (result == 1)
  972. result = _DtHelpCeParseSdlTopic(volume,
  973. &myUiInfo,
  974. lockInfo.fd, offset,
  975. id_string, True, &topic);
  976. else if (result == 0)
  977. result = _DtHelpCeFrmtCcdfTopic((_DtHelpVolume) volume,
  978. filename, offset,
  979. id_string,
  980. &myUiInfo, &topic);
  981. _DtHelpProcessUnlock();
  982. *ret_handle = (XtPointer) topic;
  983. if (result != 0)
  984. result = -3;
  985. if (filename != NULL)
  986. free(filename);
  987. }
  988. _DtHelpCeUnlockVolume(lockInfo);
  989. return result;
  990. } /* End _DtHelpFormatTopic */
  991. /******************************************************************************
  992. * Function: int _DtHelpGetAsciiVolumeTitle (
  993. *
  994. * Parameters: vol Specifies the loaded volume.
  995. * retTitle Returns the title of the volume. This string is
  996. * owned by the caller and must be freed.
  997. *
  998. * Return Value: 0 if successful, -1 if a failure occurs
  999. *
  1000. * errno Values: CEErrorMalloc
  1001. * EINVAL 'vol' or 'retTitle' is NULL.
  1002. * CEErrorMissingTitleRes
  1003. * 'vol' does not contain the resource
  1004. * 'Title' or 'title' or the resource
  1005. * is zero length.
  1006. *
  1007. * Purpose: Get the title of a volume.
  1008. *
  1009. ******************************************************************************/
  1010. int
  1011. _DtHelpGetAsciiVolumeTitle (
  1012. XtPointer client_data,
  1013. _DtHelpVolumeHdl volume,
  1014. char **ret_title)
  1015. {
  1016. int result;
  1017. _FrmtUiInfo myUiInfo = defUiInfo;
  1018. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  1019. /*
  1020. * What type of volume is it?
  1021. */
  1022. result = _DtHelpCeGetVolumeFlag(volume);
  1023. if (1 == result)
  1024. {
  1025. /*
  1026. * set up my UI information
  1027. */
  1028. myUiInfo.load_graphic = _DtHelpDALoadGraphic;
  1029. myUiInfo.resolve_spc = _DtHelpDAResolveSpc;
  1030. myUiInfo.load_font = _DtHelpDAResolveFont;
  1031. myUiInfo.exec_filter = pDAS->exec_filter;
  1032. myUiInfo.destroy_region = _DtHelpDADestroyRegion;
  1033. myUiInfo.client_data = (_DtCvPointer) pDAS;
  1034. /* since we're going for a string, set avg_char width to 1 */
  1035. myUiInfo.line_width = 0;
  1036. myUiInfo.line_height = 0;
  1037. myUiInfo.leading = 0;
  1038. myUiInfo.avg_char = 1;
  1039. myUiInfo.nl_to_space = pDAS->nl_to_space;
  1040. _DtHelpProcessLock();
  1041. result = _DtHelpCeFrmtSDLVolTitleToAscii(volume, &myUiInfo, ret_title);
  1042. }
  1043. else if (0 == result)
  1044. {
  1045. _DtHelpProcessLock();
  1046. result = _DtHelpCeGetCcdfVolumeTitle(volume, ret_title);
  1047. }
  1048. _DtHelpProcessUnlock();
  1049. return result;
  1050. }
  1051. /*****************************************************************************
  1052. * Function: int _DtHelpFormatToc (
  1053. * _DtHelpVolumeHdl volume, id);
  1054. *
  1055. * Parameters:
  1056. * canvas Specifies the handle for the canvas.
  1057. *
  1058. * Returns: -1 if errors.
  1059. * 0 if no errors.
  1060. * 1 if empty path.
  1061. *
  1062. * Purpose:
  1063. *
  1064. *****************************************************************************/
  1065. int
  1066. _DtHelpFormatToc (
  1067. DtHelpDispAreaStruct *pDAS,
  1068. _DtHelpVolumeHdl volume,
  1069. char *id,
  1070. char **ret_id,
  1071. XtPointer *ret_handle)
  1072. {
  1073. int result = 0;
  1074. _DtCvTopicPtr topic;
  1075. _DtHelpCeLockInfo lockInfo;
  1076. if (volume == NULL || id == NULL)
  1077. return -1;
  1078. /*
  1079. * This becomes my volume; want to ensure that it doesn't
  1080. * get closed out from under me, so tell the system that
  1081. * i'm using it.
  1082. */
  1083. if (_DtHelpCeLockVolume(volume, &lockInfo) != 0)
  1084. return -1;
  1085. result = _DtHelpCeMapTargetToId(volume, id, ret_id);
  1086. if (result == 0)
  1087. {
  1088. _FrmtUiInfo myUiInfo = defUiInfo;
  1089. myUiInfo.client_data = (XtPointer) pDAS;
  1090. myUiInfo.load_graphic = _DtHelpDALoadGraphic;
  1091. myUiInfo.resolve_spc = _DtHelpDAResolveSpc;
  1092. myUiInfo.load_font = _DtHelpDAResolveFont;
  1093. myUiInfo.exec_filter = pDAS->exec_filter;
  1094. myUiInfo.destroy_region = _DtHelpDADestroyRegion;
  1095. myUiInfo.client_data = (_DtCvPointer) pDAS;
  1096. myUiInfo.line_width = pDAS->lineThickness;
  1097. myUiInfo.line_height = pDAS->lineHeight;
  1098. myUiInfo.leading = pDAS->leading;
  1099. myUiInfo.avg_char = (int)(pDAS->charWidth / 10 +
  1100. ((pDAS->charWidth % 10) ? 1 : 0));
  1101. myUiInfo.nl_to_space = pDAS->nl_to_space;
  1102. result = _DtHelpCeGetVolumeFlag(volume);
  1103. _DtHelpProcessLock();
  1104. if (result == 1)
  1105. result = _DtHelpCeFrmtSdlPathAndChildren(volume,
  1106. &myUiInfo,
  1107. lockInfo.fd,
  1108. *ret_id, &topic);
  1109. else if (result == 0)
  1110. result = _DtHelpCeFrmtCcdfPathAndChildren(volume,
  1111. *ret_id,
  1112. &myUiInfo, &topic);
  1113. _DtHelpProcessUnlock();
  1114. *ret_handle = (XtPointer) topic;
  1115. }
  1116. /*
  1117. * didn't successfully format a path, so close my copy
  1118. * of the volume.
  1119. */
  1120. else
  1121. _DtHelpCloseVolume (volume);
  1122. _DtHelpCeUnlockVolume(lockInfo);
  1123. return result;
  1124. } /* End _DtHelpFormatToc */