Format.c 35 KB

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