FormatTerm.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  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. /* $TOG: FormatTerm.c /main/14 1997/08/07 10:52:34 samborn $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: FormatTerm.c
  28. **
  29. ** Project: CDE Help System
  30. **
  31. ** Description: This code uses the core engine functionality of the
  32. ** the help system to get topics into a form understood
  33. ** by ASCII based applications.
  34. **
  35. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  36. **
  37. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  38. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  39. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  40. ** (c) Copyright 1993, 1994 Novell, Inc.
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. /*
  45. * system includes
  46. */
  47. #include <stdio.h>
  48. #include <errno.h>
  49. #include <limits.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <unistd.h>
  53. #include <sys/param.h>
  54. #include <sys/stat.h>
  55. #include <X11/Xos.h>
  56. #ifdef X_NOT_STDC_ENV
  57. extern int errno;
  58. #endif
  59. /*
  60. * Canvas Engine includes
  61. */
  62. #include "CanvasP.h"
  63. #include "CanvasSegP.h"
  64. #include "LinkMgrP.h"
  65. /*
  66. * private includes
  67. */
  68. #include "LinkMgrI.h"
  69. #include "HelpTermP.h"
  70. #include "HelpP.h"
  71. #include "HelpI.h"
  72. #include "bufioI.h"
  73. #include "AsciiSpcI.h"
  74. #include "Access.h"
  75. #include "AccessI.h"
  76. #include "CanvasI.h"
  77. #include "CleanUpI.h"
  78. #include "HelpErrorP.h"
  79. #include "FileUtilsI.h"
  80. #include "FontAttrI.h"
  81. #include "StringFuncsI.h"
  82. #include "SDLI.h"
  83. #include "FormatUtilI.h"
  84. #include "FormatSDLI.h"
  85. #include "FormatCCDFI.h"
  86. #include "Lock.h"
  87. #ifdef NLS16
  88. #endif
  89. /******** Private Function Declarations ********/
  90. static void TermMetrics(
  91. _DtCvPointer client_data,
  92. _DtCvElemType elem_type,
  93. _DtCvPointer ret_metrics);
  94. static _DtCvUnit TermStrWidth(
  95. _DtCvPointer client_data,
  96. _DtCvElemType elem_type,
  97. _DtCvPointer data);
  98. static void TermStrDraw(
  99. _DtCvPointer client_data,
  100. _DtCvUnit x,
  101. _DtCvUnit y,
  102. const void *string,
  103. int byte_len,
  104. int wc,
  105. _DtCvPointer font_ptr,
  106. _DtCvUnit box_x,
  107. _DtCvUnit box_y,
  108. _DtCvUnit box_height,
  109. int link_type,
  110. _DtCvFlags old_flags,
  111. _DtCvFlags new_flags );
  112. #ifdef XTAG
  113. static _DtCvStatus TermFindGraphic(
  114. _DtCvPointer client_data,
  115. char *vol_xid,
  116. char *topic_xid,
  117. char *file_xid,
  118. char *format,
  119. char *method,
  120. _DtCvUnit *ret_width,
  121. _DtCvUnit *ret_height,
  122. _DtCvPointer *ret_graphic);
  123. #endif
  124. static void TermGetFont(
  125. _DtCvPointer client_data,
  126. char *lang,
  127. char *charset,
  128. _DtHelpFontHints font_attr,
  129. _DtCvPointer *ret_font );
  130. static void TermFontMetrics(
  131. _DtCvPointer client_data,
  132. _DtCvPointer font_ptr,
  133. _DtCvUnit *ret_ascent,
  134. _DtCvUnit *ret_descent,
  135. _DtCvUnit *char_width,
  136. _DtCvUnit *ret_super,
  137. _DtCvUnit *ret_sub);
  138. static _DtCvStatus TermResolveSpc(
  139. _DtCvPointer client_data,
  140. char *lang,
  141. char *charset,
  142. _DtHelpFontHints font_attr,
  143. char *spc_symbol,
  144. _DtCvPointer *ret_handle,
  145. _DtCvUnit *ret_width,
  146. _DtCvUnit *ret_height,
  147. _DtCvUnit *ret_ascent);
  148. static void TermRenderElem(
  149. _DtCvPointer client_data,
  150. _DtCvElemType elem_type,
  151. _DtCvUnit x,
  152. _DtCvUnit y,
  153. int link_type,
  154. _DtCvFlags old_flags,
  155. _DtCvFlags new_flags,
  156. _DtCvElemType trav_type,
  157. _DtCvPointer trav_data,
  158. _DtCvPointer data );
  159. /******** End Public Function Declarations ********/
  160. /******************************************************************************
  161. *
  162. * Private variables and defines.
  163. *
  164. *****************************************************************************/
  165. #define GROW_SIZE 10
  166. #define EOS '\0'
  167. /*
  168. * My private values
  169. */
  170. static _DtHelpVolumeHdl MyVolume = NULL;
  171. static int HyperErr = 0;
  172. static wchar_t WcSpace = 0;
  173. /*
  174. * These values change as the information is processed.
  175. */
  176. typedef struct {
  177. wchar_t **lines;
  178. size_t *wc_num;
  179. int max_lines;
  180. _DtCvUnit max_columns;
  181. _DtCvUnit max_rows;
  182. short nl_to_space;
  183. wchar_t *cant_begin_chars;
  184. wchar_t *cant_end_chars;
  185. } TerminalInfo;
  186. /* default values */
  187. static TerminalInfo DfltTermInfo = {NULL, NULL, 0, 1, 100000, 1, NULL, NULL};
  188. static _DtCvVirtualInfo TermVirtInfo =
  189. {
  190. TermMetrics, /* void (*_DtCvGetMetrics)(); */
  191. TermRenderElem, /* void (*_DtCvRenderElem)(); */
  192. TermStrWidth, /* _DtCvUnit (*_DtCvGetElemWidth)(); */
  193. TermFontMetrics, /* void (*_DtCvGetFontMetrics)(); */
  194. NULL, /* _DtCvStatus (*_DtCvBuildSelection)(); */
  195. NULL, /* _DtCvStatus (*_DtCvFilterExecCmd)(); */
  196. };
  197. static TerminalInfo MyInfo = {NULL, NULL, 0, 1, 100000, 1, NULL, NULL};
  198. static _DtCvHandle MyCanvas = NULL;
  199. #ifdef XTAG
  200. int missingGraphics = 0; /* Counter used by cdewalk */
  201. #endif /* XTAG */
  202. /******************************************************************************
  203. *
  204. * Private functions
  205. *
  206. ******************************************************************************/
  207. /******************************************************************************
  208. * Canvas functions
  209. ******************************************************************************/
  210. #ifdef XTAG
  211. /*****************************************************************************
  212. * Function: _DtCvStatus TermFindGraphic ();
  213. *
  214. * Parameters:
  215. *
  216. * Returns:
  217. *
  218. * Purpose:
  219. *
  220. *****************************************************************************/
  221. static _DtCvStatus
  222. TermFindGraphic (
  223. _DtCvPointer client_data,
  224. char *vol_xid,
  225. char *topic_xid,
  226. char *file_xid,
  227. char *format,
  228. char *method,
  229. _DtCvUnit *ret_width,
  230. _DtCvUnit *ret_height,
  231. _DtCvPointer *ret_graphic )
  232. {
  233. char *ptr;
  234. char *fileName = file_xid;
  235. if (fileName != NULL && *fileName != '/')
  236. {
  237. fileName = (char *) malloc (strlen(vol_xid) + strlen (file_xid) + 2);
  238. if (fileName == NULL)
  239. return -1;
  240. strcpy(fileName, vol_xid);
  241. if (_DtHelpCeStrrchr(fileName, "/", MB_CUR_MAX, &ptr) != -1)
  242. *ptr = '\0';
  243. strcat(fileName, "/");
  244. strcat(fileName, file_xid);
  245. }
  246. if (access(fileName, R_OK) != 0)
  247. {
  248. missingGraphics++;
  249. fprintf (stdout, "\tGRAPHICS LINK ***UNRESOLVED***\n");
  250. fprintf (stdout, "\tUnable to find graphic file: %s\n\n", fileName);
  251. }
  252. if (fileName != file_xid)
  253. free (fileName);
  254. *ret_width = 0;
  255. *ret_height = 0;
  256. *ret_graphic = 0;
  257. return 0;
  258. }
  259. #endif /* XTAG */
  260. /*****************************************************************************
  261. * Function: void TermStrDraw ();
  262. *
  263. * Parameters:
  264. *
  265. * Returns:
  266. *
  267. * Purpose:
  268. *
  269. *****************************************************************************/
  270. static void
  271. TermStrDraw (
  272. _DtCvPointer client_data,
  273. _DtCvUnit x,
  274. _DtCvUnit y,
  275. const void *string,
  276. int byte_len,
  277. int wc,
  278. _DtCvPointer font_ptr,
  279. _DtCvUnit box_x,
  280. _DtCvUnit box_y,
  281. _DtCvUnit box_height,
  282. int link_type,
  283. _DtCvFlags old_flags,
  284. _DtCvFlags new_flags )
  285. {
  286. TerminalInfo *pTerm = (TerminalInfo *) client_data;
  287. wchar_t *wcStr = pTerm->lines[y];
  288. size_t length = 1;
  289. length = x + byte_len;
  290. if (wcStr == NULL)
  291. {
  292. pTerm->lines[y] = (wchar_t *) malloc (sizeof(wchar_t) * (length + 1));
  293. if (pTerm->lines[y] != NULL)
  294. {
  295. int i;
  296. wcStr = pTerm->lines[y];
  297. _DtHelpProcessLock();
  298. for (i = 0; i < x; i++)
  299. wcStr[i] = WcSpace;
  300. _DtHelpProcessUnlock();
  301. /*
  302. * this will leave a hole that will be plugged by the next
  303. * mbstowc call.
  304. */
  305. wcStr[length] = 0;
  306. pTerm->wc_num[y] = length;
  307. }
  308. }
  309. else
  310. {
  311. if (length > pTerm->wc_num[y])
  312. {
  313. pTerm->lines[y] = (wchar_t *) realloc (wcStr,
  314. (sizeof(wchar_t) * (length + 1)));
  315. if (pTerm->lines[y] != NULL)
  316. {
  317. int i;
  318. wcStr = pTerm->lines[y];
  319. _DtHelpProcessLock();
  320. for (i = pTerm->wc_num[y]; i < x; i++)
  321. wcStr[i] = WcSpace;
  322. _DtHelpProcessUnlock();
  323. wcStr[length] = 0;
  324. pTerm->wc_num[y] = length;
  325. }
  326. }
  327. }
  328. if (0 == wc)
  329. mbstowcs(&wcStr[x], string, byte_len);
  330. else
  331. {
  332. wchar_t *wcp = (wchar_t *) string;
  333. while (0 < byte_len)
  334. {
  335. wcStr[x++] = *wcp++;
  336. byte_len--;
  337. }
  338. }
  339. }
  340. /*****************************************************************************
  341. * Function: void TermRenderElem ();
  342. *
  343. * Parameters:
  344. *
  345. * Returns:
  346. *
  347. * Purpose:
  348. *
  349. *****************************************************************************/
  350. static void
  351. TermRenderElem (
  352. _DtCvPointer client_data,
  353. _DtCvElemType elem_type,
  354. _DtCvUnit x,
  355. _DtCvUnit y,
  356. int link_type,
  357. _DtCvFlags old_flags,
  358. _DtCvFlags new_flags,
  359. _DtCvElemType trav_type,
  360. _DtCvPointer trav_data,
  361. _DtCvPointer data)
  362. {
  363. _DtCvStringInfo *strInfo;
  364. _DtCvRenderInfo *posInfo = (_DtCvRenderInfo *) data;
  365. if (_DtCvSTRING_TYPE == elem_type)
  366. {
  367. strInfo = (_DtCvStringInfo *) posInfo->info;
  368. TermStrDraw (client_data, x, y, strInfo->string, strInfo->byte_len,
  369. strInfo->wc , strInfo->font_ptr,
  370. posInfo->box_x , posInfo->box_y ,
  371. posInfo->box_height, link_type,
  372. old_flags , new_flags);
  373. }
  374. else if (_DtCvREGION_TYPE == elem_type)
  375. {
  376. const char *spcStr = (const char*) posInfo->info;
  377. int len = spcStr ? strlen(spcStr) : 0;
  378. TermStrDraw (client_data, x, y, spcStr, len, 0, 0,
  379. posInfo->box_x , posInfo->box_y,
  380. posInfo->box_height, link_type,
  381. old_flags , new_flags);
  382. }
  383. }
  384. /*****************************************************************************
  385. * Function: void TermMetrics ();
  386. *
  387. * Parameters:
  388. *
  389. * Returns:
  390. *
  391. * Purpose:
  392. *
  393. *****************************************************************************/
  394. static _DtCvSpaceMetrics defLinkMetrics = { 0, 0, 0, 0 };
  395. static void
  396. TermMetrics (
  397. _DtCvPointer client_data,
  398. _DtCvElemType elem_type,
  399. _DtCvPointer ret_metrics)
  400. {
  401. TerminalInfo *pTerm = (TerminalInfo *) client_data;
  402. _DtCvSpaceMetrics *retSpace = (_DtCvSpaceMetrics *) ret_metrics;
  403. if (_DtCvCANVAS_TYPE == elem_type)
  404. {
  405. _DtCvMetrics *retCanvas = (_DtCvMetrics *) ret_metrics;
  406. retCanvas->width = pTerm->max_columns;
  407. retCanvas->height = 50;
  408. retCanvas->top_margin = 0;
  409. retCanvas->side_margin = 0;
  410. retCanvas->line_height = 1;
  411. retCanvas->horiz_pad_hint = 1;
  412. }
  413. else if (_DtCvLOCALE_TYPE == elem_type)
  414. {
  415. _DtCvLocale *retLocale = (_DtCvLocale *) ret_metrics;
  416. retLocale->line_wrap_mode = _DtCvModeWrapNone;
  417. retLocale->cant_begin_chars = pTerm->cant_begin_chars;
  418. retLocale->cant_end_chars = pTerm->cant_end_chars;
  419. }
  420. else if (_DtCvLINK_TYPE == elem_type || _DtCvTRAVERSAL_TYPE == elem_type)
  421. *retSpace = defLinkMetrics;
  422. }
  423. /*****************************************************************************
  424. * Function: void TermGetFont ();
  425. *
  426. * Parameters:
  427. *
  428. * Returns:
  429. *
  430. * Purpose:
  431. *
  432. *****************************************************************************/
  433. static void
  434. TermGetFont (
  435. _DtCvPointer client_data,
  436. char *lang,
  437. char *charset,
  438. _DtHelpFontHints font_attr,
  439. _DtCvPointer *ret_font )
  440. {
  441. *ret_font = (_DtCvPointer) 0;
  442. }
  443. /*****************************************************************************
  444. * Function: _DtCvStatus TermResolveSpc ();
  445. *
  446. * Parameters:
  447. *
  448. * Returns:
  449. *
  450. * Purpose:
  451. *
  452. *****************************************************************************/
  453. static _DtCvStatus
  454. TermResolveSpc (
  455. _DtCvPointer client_data,
  456. char *lang,
  457. char *charset,
  458. _DtHelpFontHints font_attr,
  459. char *spc_symbol,
  460. _DtCvPointer *ret_handle,
  461. _DtCvUnit *ret_width,
  462. _DtCvUnit *ret_height,
  463. _DtCvUnit *ret_ascent)
  464. {
  465. const char* spcStr;
  466. /*
  467. * initialize the returned information to nothing.
  468. */
  469. *ret_handle = NULL;
  470. *ret_height = 0;
  471. *ret_width = 0;
  472. *ret_ascent = 0;
  473. spcStr = _DtHelpCeResolveSpcToAscii (spc_symbol);
  474. if (spcStr != NULL)
  475. {
  476. *ret_handle = ((_DtCvPointer)(spcStr));
  477. *ret_height = 1;
  478. *ret_width = strlen(spcStr);
  479. }
  480. return 0;
  481. }
  482. /*****************************************************************************
  483. * Function: void TermFontMetrics ();
  484. *
  485. * Parameters:
  486. *
  487. * Returns:
  488. *
  489. * Purpose:
  490. *
  491. *****************************************************************************/
  492. static void
  493. TermFontMetrics (
  494. _DtCvPointer client_data,
  495. _DtCvPointer font_ptr,
  496. _DtCvUnit *ret_ascent,
  497. _DtCvUnit *ret_descent,
  498. _DtCvUnit *char_width,
  499. _DtCvUnit *ret_super,
  500. _DtCvUnit *ret_sub)
  501. {
  502. if (ret_ascent)
  503. *ret_ascent = 0;
  504. if (ret_descent)
  505. *ret_descent = 0;
  506. if (char_width)
  507. *char_width = 0;
  508. if (ret_super)
  509. *ret_super = 0;
  510. if (ret_sub)
  511. *ret_sub = 0;
  512. return;
  513. }
  514. /*****************************************************************************
  515. * Function: _DtCvUnit TermStrWidth ();
  516. *
  517. * Parameters:
  518. *
  519. * Returns:
  520. *
  521. * Purpose:
  522. *
  523. *****************************************************************************/
  524. static _DtCvUnit
  525. TermStrWidth (
  526. _DtCvPointer client_data,
  527. _DtCvElemType elem_type,
  528. _DtCvPointer data)
  529. {
  530. _DtCvStringInfo *strInfo = (_DtCvStringInfo *) data;
  531. if (elem_type != _DtCvSTRING_TYPE)
  532. return 0;
  533. return ((_DtCvUnit)(strInfo->byte_len));
  534. }
  535. /******************************************************************************
  536. * End Canvas functions
  537. * Begin other private functions
  538. ******************************************************************************/
  539. /******************************************************************************
  540. * Function: DtHelpHyperLines *AddHyperToArray (DtHelpHyperLines *array_ptr,
  541. * int value, char *link_spec, char *title)
  542. *
  543. * Parameters:
  544. * array_ptr Specifies a NULL terminated list of
  545. * DtHelpHyperLines or NULL.
  546. * value Specifies the link type.
  547. * link_spec Specifies the link specification.
  548. * title Specifies the title of the link.
  549. *
  550. * Returns: A ptr to the new DtHelpHyperLines if successful,
  551. * NULL if errors.
  552. *
  553. * errno Values:
  554. * DtErrorMalloc
  555. *
  556. * Purpose: Add a hypertext link to an array of DtHelpHyperLines.
  557. *
  558. *****************************************************************************/
  559. static DtHelpHyperLines *
  560. AddHyperToArray(
  561. DtHelpHyperLines *array_ptr,
  562. int value,
  563. int win_hint,
  564. char *link_spec,
  565. char *title )
  566. {
  567. DtHelpHyperLines *next;
  568. int num = 0;
  569. if (array_ptr)
  570. {
  571. for (next = array_ptr; next->specification != NULL; next++)
  572. num++;
  573. if (((num + 1) % GROW_SIZE) == 0)
  574. array_ptr = (DtHelpHyperLines *) realloc ((void *) array_ptr,
  575. (sizeof (DtHelpHyperLines) * (num + 1 + GROW_SIZE)));
  576. }
  577. else
  578. array_ptr = (DtHelpHyperLines *) malloc (
  579. sizeof (DtHelpHyperLines) * GROW_SIZE);
  580. if (array_ptr == NULL)
  581. errno = DtErrorMalloc;
  582. else
  583. {
  584. next = array_ptr + num;
  585. next->hyper_type = value;
  586. next->win_hint = win_hint;
  587. next->specification = strdup(link_spec);
  588. next->title = title;
  589. next++;
  590. next->specification = NULL;
  591. next->title = NULL;
  592. }
  593. return array_ptr;
  594. }
  595. /******************************************************************************
  596. * Function: void DeallocateHyperArray (DtHelpHyperLines *array_ptr)
  597. *
  598. * Parameters:
  599. * array_ptr Specifies a NULL terminated array of
  600. * DtHelpHyperLines.
  601. *
  602. * Returns: Nothing
  603. *
  604. * errno Values:
  605. *
  606. * Purpose: De-allocate an array of DtHelpHyperLines structures.
  607. *
  608. *****************************************************************************/
  609. static void
  610. DeallocateHyperArray(
  611. DtHelpHyperLines *array_ptr )
  612. {
  613. DtHelpHyperLines *next = array_ptr;
  614. if (array_ptr)
  615. {
  616. while (next->title && next->specification)
  617. {
  618. free (next->title);
  619. free (next->specification);
  620. next++;
  621. }
  622. free (array_ptr);
  623. }
  624. }
  625. /******************************************************************************
  626. * Function: int AddHyperToList(
  627. *
  628. * Parameters:
  629. *
  630. * Returns: 0 if successful.
  631. * -1 if unrecoverable errors.
  632. * -2 if could not resolve the hypertext link.
  633. *
  634. * errno Values:
  635. * DtErrorMalloc
  636. * DtErrorFormattingLabel
  637. * A label has illegal syntax.
  638. * DtErrorHyperType
  639. * Invalid (negative) hypertype.
  640. * DtErrorFormattingLink
  641. * Invalid <LINK>.
  642. * DtErrorHyperSpec
  643. * Invalid 'hyper_specification' in the
  644. * the <LINK>.
  645. * DtErrorFormattingId
  646. * Invalid <ID> syntax.
  647. *
  648. * Purpose: Process the result of a hypertext link, filling out
  649. * a hypertext structure element with the information.
  650. *
  651. *****************************************************************************/
  652. static int
  653. AddHyperToList(
  654. _DtHelpVolumeHdl volume,
  655. _DtCvHandle canvas,
  656. int i,
  657. DtHelpHyperLines **ret_list)
  658. {
  659. _DtCanvasStruct *myCanvas = (_DtCanvasStruct *)canvas;
  660. _DtCvLinkInfo hyperInfo;
  661. _DtHelpVolumeHdl newVol = NULL;
  662. _DtHelpVolumeHdl useVol = volume;
  663. char *volName = NULL;
  664. char *title = NULL;
  665. char *allocName = NULL;
  666. char *spec = NULL;
  667. char *id;
  668. int result = -3;
  669. if (_DtLinkDbGetLinkInfo(myCanvas->link_data, i,
  670. myCanvas->virt_functions.exec_cmd_filter,
  671. myCanvas->client_data, &hyperInfo) == 0)
  672. {
  673. result = 0;
  674. if (hyperInfo.description == NULL)
  675. {
  676. id = hyperInfo.specification;
  677. switch (hyperInfo.hyper_type)
  678. {
  679. case _DtCvLinkType_CrossLink:
  680. spec = strdup (id);
  681. if (spec != NULL)
  682. {
  683. volName = spec;
  684. id = NULL;
  685. _DtHelpCeStrchr (spec," ",MB_CUR_MAX,&id);
  686. if (id != NULL)
  687. {
  688. *id = '\0';
  689. id++;
  690. /* find the volume (volName is malloc'd) */
  691. allocName = _DtHelpFileLocate(DtHelpVOLUME_TYPE, volName,
  692. _DtHelpFileSuffixList,False,R_OK);
  693. if (allocName == NULL)
  694. result = -2;
  695. if (_DtHelpOpenVolume(allocName, &newVol)==0)
  696. useVol = newVol;
  697. else
  698. result = -2;
  699. }
  700. else
  701. id = spec;
  702. }
  703. else
  704. result = -1;
  705. /* fall thru */
  706. case _DtCvLinkType_SameVolume:
  707. if (result == 0)
  708. {
  709. result = _DtHelpGetTopicTitle(useVol, id, &title);
  710. if (result == -2)
  711. HyperErr = DtErrorLocIdNotFound;
  712. }
  713. if (newVol != NULL)
  714. _DtHelpCloseVolume(newVol);
  715. if (spec != NULL)
  716. free(spec);
  717. if (allocName != NULL)
  718. free(allocName);
  719. break;
  720. case _DtCvLinkType_Execute:
  721. title = (char *) malloc(strlen(id) + 11);
  722. sprintf(title, "Execute \"%s\"", id);
  723. break;
  724. case _DtCvLinkType_ManPage:
  725. title = (char *) malloc(strlen(id) + 13);
  726. sprintf(title, "Man Page \"%s\"", id);
  727. break;
  728. case _DtCvLinkType_AppDefine:
  729. title = (char *) malloc(strlen(id) + 26);
  730. sprintf(title, "Application Link Type \"%s\"", id);
  731. break;
  732. case _DtCvLinkType_TextFile:
  733. title = (char *) malloc(strlen(id) + 12);
  734. sprintf(title, "Text File \"%s\"", id);
  735. break;
  736. default:
  737. title = strdup ("Unkown link type");
  738. break;
  739. }
  740. }
  741. else
  742. {
  743. title = strdup (hyperInfo.description);
  744. }
  745. }
  746. if (result == -2)
  747. *ret_list = AddHyperToArray (*ret_list, -(hyperInfo.hyper_type + 1),
  748. hyperInfo.win_hint,
  749. hyperInfo.specification,
  750. strdup("Invalid Link"));
  751. else if (result >= 0)
  752. *ret_list = AddHyperToArray (*ret_list, hyperInfo.hyper_type,
  753. hyperInfo.win_hint,
  754. hyperInfo.specification,
  755. title);
  756. /*
  757. * report unable to resolve the hypertext link
  758. */
  759. if (result == -2)
  760. return -2;
  761. if (result == -1 || *ret_list == NULL)
  762. return -1;
  763. return (0);
  764. } /* End AddHyperToList */
  765. /******************************************************************************
  766. * Function: TerminalInfo * GetTermInfo(canvasHandle)
  767. *
  768. * Parameters:
  769. * canvasHandle Canvas whose client_data is a TerminalInfo *
  770. *
  771. * Returns: 0 for success, -1 for failure.
  772. *
  773. ******************************************************************************/
  774. static TerminalInfo *
  775. GetTermInfo(
  776. _DtCvHandle canvasHandle)
  777. {
  778. _DtCanvasStruct * canvas = (_DtCanvasStruct *) canvasHandle;
  779. return (TerminalInfo *) canvas->client_data;
  780. }
  781. /******************************************************************************
  782. *
  783. * Public functions
  784. *
  785. ******************************************************************************/
  786. /******************************************************************************
  787. * Function: int _DtHelpTermCreateCanvas (int maxColumns,_DtCvHandle * ret_canvas)
  788. *
  789. * Parameters:
  790. * maxColumns Specifies the column width of the window
  791. * for which to format the information.
  792. * ret_canvas handle to the canvas that was created
  793. *
  794. * Returns: 0 for success, -1 for failure.
  795. *
  796. * errno Values:
  797. * EINVAL 'ret_canvas' was NULL or 'maxColumns'
  798. * was less than one.
  799. * ENOMEM unable to allocate necessary memory
  800. * DtErrorMalloc
  801. *
  802. * Purpose: _DtHelpTermCreateCanvas creates a canvas that use
  803. * text-only content processing routines
  804. *
  805. *****************************************************************************/
  806. int
  807. _DtHelpTermCreateCanvas (
  808. int maxColumns,
  809. _DtCvHandle * ret_canvas)
  810. {
  811. TerminalInfo * termInfo;
  812. /*
  813. * check the parameters
  814. */
  815. if (maxColumns < 1 || ret_canvas == NULL)
  816. {
  817. errno = EINVAL;
  818. return -1;
  819. }
  820. termInfo = (TerminalInfo *) malloc(sizeof(TerminalInfo));
  821. if (termInfo == NULL)
  822. {
  823. errno = ENOMEM;
  824. return -1;
  825. }
  826. /* init info and create a canvas */
  827. *termInfo = DfltTermInfo;
  828. termInfo->max_columns = maxColumns;
  829. if (1 < MB_CUR_MAX)
  830. _DtHelpLoadMultiInfo(&(termInfo->cant_begin_chars),
  831. &(termInfo->cant_begin_chars),
  832. &(termInfo->nl_to_space));
  833. *ret_canvas = _DtCanvasCreate (TermVirtInfo, (_DtCvPointer) termInfo);
  834. if (*ret_canvas == NULL)
  835. return -1;
  836. return 0;
  837. }
  838. /******************************************************************************
  839. * Function: int _DtHelpTermGetTopicData(canvasHandle,volHandle,
  840. * locationId,helpList,hyperList)
  841. *
  842. * Parameters:
  843. * canvasHandle Canvas used to retrieve the info; MUST
  844. * be a Terminal canvas Since it isn't easy
  845. * to verify this, we don't try. So if the
  846. * Canvas ISN'T a Terminal Canvas, we'll
  847. * crash.
  848. * volHandle Help volume to use
  849. * locationId Specifies the locationId of the desired topic.
  850. * helpList Returns a NULL terminated array of
  851. * strings.
  852. * hyperList Returns a NULL terminated array of
  853. * DtHelpHyperLines containing the hyperlinks
  854. * found in the topic.
  855. *
  856. * Returns: 0 for success, -1 for failure.
  857. *
  858. * errno Values:
  859. * EINVAL 'helpVolume', 'locationId', 'helpList',
  860. * or 'hyperList' were NULL. 'maxColumns'
  861. * was less than one.
  862. * open(2) errno set via an open call on
  863. * the file for 'locationId'.
  864. * DtErrorMalloc
  865. * DtErrorExceedMaxSize
  866. * When following symbolic links, the
  867. * new path will exceed the system
  868. * maximum file path length.
  869. * DtErrorIllegalPath
  870. * When following symbolic links, the
  871. * new path would change to a parent
  872. * directory beyond the beginning
  873. * of the base path.
  874. * DtErrorIllegalDatabaseFile
  875. * Specifies that 'helpVolume' is
  876. * an illegal database file.
  877. * DtErrorMissingFilenameRes
  878. * Specifies that the 'Filename/filename'
  879. * resource for the topic does not exist.
  880. * DtErrorMissingFileposRes
  881. * Specifies that the 'Filepos/filepos'
  882. * resource for the topic does not exist.
  883. * DtErrorLocIdNotFound
  884. * Specifies that 'locationId' was not found.
  885. * DtErrorFormattingLabel
  886. * A label has illegal syntax.
  887. * DtErrorHyperType
  888. * Invalid (negative) hypertype.
  889. * DtErrorFormattingLink
  890. * Invalid <LINK>.
  891. * DtErrorHyperSpec
  892. * Invalid 'hyper_specification' in the
  893. * the <LINK>.
  894. * DtErrorFormattingId
  895. * Invalid <ID> syntax.
  896. * DtErrorFormattingTitle
  897. * Invalid <TITLE> syntax.
  898. *
  899. * Purpose: _DtHelpTermGetTopicData retrieves Help Files content with
  900. * in a form understood by a terminal
  901. *
  902. *****************************************************************************/
  903. int
  904. _DtHelpTermGetTopicData(
  905. _DtCvHandle canvasHandle,
  906. _DtHelpVolumeHdl volHandle,
  907. char * locationId,
  908. char * * * helpList,
  909. DtHelpHyperLines ** hyperList)
  910. {
  911. int result = -1;
  912. int offset;
  913. _DtCvUnit maxRows;
  914. _DtCvUnit maxWidth;
  915. char * * strList;
  916. char* fileName = NULL;
  917. _DtHelpCeLockInfo lockInfo;
  918. _DtCvTopicPtr topic = NULL;
  919. TerminalInfo * termInfo;
  920. _FrmtUiInfo myUiInfo;
  921. termInfo = GetTermInfo(canvasHandle);
  922. _DtHelpProcessLock();
  923. if (WcSpace == 0)
  924. mbtowc (&WcSpace, " ", 1);
  925. _DtHelpProcessUnlock();
  926. /*
  927. * find the filename and the Id string.
  928. */
  929. if (_DtHelpCeLockVolume(volHandle, &lockInfo) != 0)
  930. {
  931. return -1;
  932. }
  933. if (_DtHelpCeFindId(volHandle,locationId,lockInfo.fd,&fileName,&offset)==0)
  934. {
  935. _DtHelpCeUnlockVolume(lockInfo);
  936. return -1;
  937. }
  938. /*
  939. * create the ui structure for the parsing.
  940. */
  941. #ifdef XTAG
  942. myUiInfo.load_graphic = TermFindGraphic;
  943. #else
  944. myUiInfo.load_graphic = NULL;
  945. #endif /* XTAG */
  946. myUiInfo.resolve_spc = TermResolveSpc;
  947. myUiInfo.load_font = TermGetFont;
  948. myUiInfo.destroy_region = NULL;
  949. myUiInfo.exec_filter = NULL;
  950. myUiInfo.client_data = (_DtCvPointer) termInfo;
  951. myUiInfo.line_width = 0;
  952. myUiInfo.line_height = 1;
  953. myUiInfo.leading = 0;
  954. myUiInfo.avg_char = 1;
  955. myUiInfo.nl_to_space = termInfo->nl_to_space;
  956. /*
  957. * Format the topic.
  958. */
  959. result = _DtHelpCeGetVolumeFlag(volHandle);
  960. _DtHelpProcessLock();
  961. if (result == 1)
  962. result = _DtHelpCeParseSdlTopic(volHandle,
  963. &myUiInfo,
  964. lockInfo.fd,
  965. offset, NULL, True, &topic);
  966. else if (result == 0)
  967. result = _DtHelpCeFrmtCcdfTopic(volHandle, fileName,
  968. offset, NULL, &myUiInfo,
  969. &topic);
  970. _DtHelpProcessUnlock();
  971. /* if successfully formatted topic */
  972. if (result != -1)
  973. {
  974. int i;
  975. int len;
  976. wchar_t **wcList;
  977. _DtCanvasStruct *myCStruct = (_DtCanvasStruct *)canvasHandle;
  978. /* build the help text list, if requested */
  979. if (NULL != helpList)
  980. {
  981. _DtCanvasSetTopic(canvasHandle, topic, _DtCvIGNORE_BOUNDARY,
  982. &maxWidth, &maxRows, NULL);
  983. /*
  984. * The 'maxRows' variable is really misnamed; it's really the
  985. * 'maxY', and is 0-based. Thus, the 'lines' and 'wc_num'
  986. * arrays need to be 'maxRows+1', in order to hold all the
  987. * entries. Likewise, 'strList' must be 'maxRows+2', because
  988. * it also needs to be NULL terminated.
  989. */
  990. termInfo->lines = (wchar_t **)malloc(sizeof(wchar_t *) *(maxRows+1));
  991. termInfo->wc_num = (size_t *)malloc(sizeof(size_t) * (maxRows+1));
  992. strList = (char **) malloc(sizeof(char *) * (maxRows+2));
  993. if (termInfo->lines == NULL || termInfo->wc_num == NULL ||
  994. strList == NULL)
  995. {
  996. free(fileName);
  997. if (termInfo->lines != NULL)
  998. free(termInfo->lines);
  999. if (termInfo->wc_num != NULL)
  1000. free(termInfo->wc_num);
  1001. if (strList != NULL)
  1002. free(strList);
  1003. _DtHelpCeUnlockVolume(lockInfo);
  1004. return -1;
  1005. }
  1006. for (i = 0; i <= maxRows; i++)
  1007. {
  1008. termInfo->lines[i] = NULL;
  1009. termInfo->wc_num[i] = 0;
  1010. }
  1011. _DtCanvasRender(canvasHandle, 0, 0, maxWidth, maxRows,
  1012. _DtCvRENDER_PARTIAL, _DtCvFALSE, NULL, NULL);
  1013. *helpList = strList;
  1014. wcList = termInfo->lines;
  1015. for (i = 0; i <= maxRows; i++, wcList++, strList++)
  1016. {
  1017. if (*wcList == NULL)
  1018. {
  1019. *strList = (char *) malloc (1);
  1020. **strList = '\0';
  1021. }
  1022. else
  1023. {
  1024. len = (termInfo->wc_num[i] + 1) * MB_CUR_MAX;
  1025. *strList = (char *) malloc (sizeof (char) * len);
  1026. if (*strList != NULL)
  1027. wcstombs(*strList, *wcList, len);
  1028. }
  1029. }
  1030. *strList = NULL;
  1031. /*
  1032. * free the allocated memory
  1033. */
  1034. for (i = 0, wcList = termInfo->lines; i <= maxRows; i++, wcList++)
  1035. if (*wcList != NULL)
  1036. free(*wcList);
  1037. free(termInfo->lines);
  1038. free(termInfo->wc_num);
  1039. } /* if requested help text */
  1040. /*
  1041. * build the hyperlinks list, if requested
  1042. */
  1043. if ( NULL != hyperList )
  1044. {
  1045. *hyperList = NULL;
  1046. for (i = 0; result != -1 && i < myCStruct->link_data->max; i++)
  1047. result = AddHyperToList(volHandle, canvasHandle, i, hyperList);
  1048. }
  1049. } /* if successfully formatted topic */
  1050. _DtCanvasClean(canvasHandle);
  1051. _DtHelpDestroyTopicData(topic, NULL, NULL);
  1052. free(fileName);
  1053. _DtHelpCeUnlockVolume(lockInfo);
  1054. return result;
  1055. } /* End _DtHelpTermGetTopicData */
  1056. /******************************************************************************
  1057. * Function: int _DtHelpGetTopicDataHandles(ret_canvasHandle,ret_volHandle)
  1058. *
  1059. * Parameters:
  1060. * ret_canvasHandle Canvas used to retrieve the info
  1061. * ret_volHandle Help volume in use
  1062. *
  1063. * Returns:
  1064. * 0: canvas handle & volHandle are not NULL
  1065. * -1: canvas handle & volHandle are NULL
  1066. ******************************************************************************/
  1067. int
  1068. _DtHelpGetTopicDataHandles(
  1069. _DtCvHandle * ret_canvasHandle,
  1070. _DtHelpVolumeHdl * ret_volHandle)
  1071. {
  1072. _DtHelpProcessLock();
  1073. *ret_canvasHandle = MyCanvas;
  1074. *ret_volHandle = MyVolume;
  1075. if (MyCanvas != NULL && MyVolume != NULL)
  1076. {
  1077. _DtHelpProcessUnlock();
  1078. return 0;
  1079. }
  1080. else
  1081. {
  1082. _DtHelpProcessUnlock();
  1083. return -1;
  1084. }
  1085. }
  1086. /******************************************************************************
  1087. * Function: int _DtHelpGetTopicData (char *helpVolume, char *locationId,
  1088. * int maxColumns, char ***helpList, DtHelpHyperLines **hyperList)
  1089. *
  1090. * Parameters:
  1091. * helpVolume Specifies a file path to the volume.
  1092. * locationId Specifies the locationId of the desired topic.
  1093. * maxColumns Specifies the column width of the window
  1094. * for which to format the information.
  1095. * helpList Returns a NULL terminated array of
  1096. * strings.
  1097. * hyperList Returns a NULL terminated array of
  1098. * DtHelpHyperLines containing the hyperlinks
  1099. * found in the topic.
  1100. *
  1101. * Returns: 0 for success, -1 for failure.
  1102. *
  1103. * errno Values:
  1104. * EINVAL 'helpVolume', 'locationId', 'helpList',
  1105. * or 'hyperList' were NULL. 'maxColumns'
  1106. * was less than one.
  1107. * getcwd(2) errno set via a getcwd call.
  1108. * readlink(2) errno set via a readlink call.
  1109. * open(2) errno set via an open call on
  1110. * the file for 'locationId'.
  1111. * DtErrorMalloc
  1112. * DtErrorExceedMaxSize
  1113. * When following symbolic links, the
  1114. * new path will exceed the system
  1115. * maximum file path length.
  1116. * DtErrorIllegalPath
  1117. * When following symbolic links, the
  1118. * new path would change to a parent
  1119. * directory beyond the beginning
  1120. * of the base path.
  1121. * DtErrorIllegalDatabaseFile
  1122. * Specifies that 'helpVolume' is
  1123. * an illegal database file.
  1124. * DtErrorMissingFilenameRes
  1125. * Specifies that the 'Filename/filename'
  1126. * resource for the topic does not exist.
  1127. * DtErrorMissingFileposRes
  1128. * Specifies that the 'Filepos/filepos'
  1129. * resource for the topic does not exist.
  1130. * DtErrorLocIdNotFound
  1131. * Specifies that 'locationId' was not found.
  1132. * DtErrorFormattingLabel
  1133. * A label has illegal syntax.
  1134. * DtErrorHyperType
  1135. * Invalid (negative) hypertype.
  1136. * DtErrorFormattingLink
  1137. * Invalid <LINK>.
  1138. * DtErrorHyperSpec
  1139. * Invalid 'hyper_specification' in the
  1140. * the <LINK>.
  1141. * DtErrorFormattingId
  1142. * Invalid <ID> syntax.
  1143. * DtErrorFormattingTitle
  1144. * Invalid <TITLE> syntax.
  1145. *
  1146. * Purpose: _DtHelpGetTopicData formats Help Files with
  1147. * formatting information
  1148. * into a form understood by a terminal
  1149. *
  1150. *****************************************************************************/
  1151. int
  1152. _DtHelpGetTopicData (
  1153. char * helpVolume,
  1154. char * locationId,
  1155. int maxColumns,
  1156. char * * * helpList,
  1157. DtHelpHyperLines * * hyperList )
  1158. {
  1159. int result = -1;
  1160. _DtHelpVolumeHdl volume = NULL;
  1161. char * path = NULL;
  1162. /* find the volume (path is malloc'd) */
  1163. path = _DtHelpFileLocate(DtHelpVOLUME_TYPE, helpVolume,
  1164. _DtHelpFileSuffixList,False,R_OK);
  1165. if (path == NULL) { errno = EINVAL; return -1; } /* RETURN */
  1166. /* open new canvas or reuse old one with new size */
  1167. _DtHelpProcessLock();
  1168. if (MyCanvas == NULL)
  1169. {
  1170. _DtHelpTermCreateCanvas(maxColumns,&MyCanvas);
  1171. if (MyCanvas == NULL)
  1172. {
  1173. free(path);
  1174. _DtHelpProcessUnlock();
  1175. return -1; /* RETURN: errno=from CreateCanvas */
  1176. }
  1177. }
  1178. else
  1179. {
  1180. MyInfo.max_columns = maxColumns;
  1181. _DtCanvasResize (MyCanvas, _DtCvFALSE, NULL, NULL);
  1182. }
  1183. if (_DtHelpOpenVolume (helpVolume, &volume) == -1)
  1184. {
  1185. free(path);
  1186. _DtHelpProcessUnlock();
  1187. return -1; /* RETURN: errno=from OpenVolume */
  1188. }
  1189. /* release any previously opened volume */
  1190. if (MyVolume)
  1191. _DtHelpCloseVolume (MyVolume);
  1192. /* assign the new volume */
  1193. MyVolume = volume;
  1194. /* get the terminal info */
  1195. result = _DtHelpTermGetTopicData(MyCanvas,MyVolume,locationId,helpList,hyperList);
  1196. _DtHelpProcessUnlock();
  1197. free(path);
  1198. return result;
  1199. }
  1200. /*****************************************************************************
  1201. * Function: int _DtHelpProcessLinkData (char * ref_volume,DtHelpHyperLines *hyperLine,
  1202. * char **ret_helpVolume, char **ret_locationId)
  1203. *
  1204. * Parameters:
  1205. * hyperLine Specifies the hypertext line that
  1206. * the caller wishes to be resolved.
  1207. * helpVolume Returns the help volume specified by
  1208. * 'hyperLine'.
  1209. * locationId Returns the location Id specified by
  1210. * 'hyperLine'.
  1211. *
  1212. * Returns: 0 if successful, -1 if errors.
  1213. *
  1214. * errno Values:
  1215. * EINVAL 'hyperLines', 'helpVolume', or 'locationId'
  1216. * is NULL.
  1217. * DtErrorMalloc
  1218. * DtErrorHyperType
  1219. * The hyper type is not _DtJUMP_REUSE,
  1220. * _DtJUMP_NEW, or _DtDEFINITION.
  1221. * DtErrorHyperSpec
  1222. * Invalid hyper specification.
  1223. * DtErrorIllegalPath
  1224. * The volume used by the link spec (either
  1225. * embedded or the ref_volume) could not be
  1226. * located.
  1227. *
  1228. * Purpose: _DtHelpProcessLinkData resolves a hypertext specification
  1229. * into a pathname to a help volume and a location Id within
  1230. * the help volume.
  1231. *
  1232. *****************************************************************************/
  1233. int
  1234. _DtHelpProcessLinkData (
  1235. char * ref_volume,
  1236. DtHelpHyperLines * hyperLine,
  1237. char * * ret_helpVolume,
  1238. char * * ret_locationId )
  1239. {
  1240. char * linkSpec = NULL;
  1241. char * volumeName = NULL;
  1242. char * idToken = NULL;
  1243. /* check params */
  1244. if (ref_volume == NULL || hyperLine == NULL ||
  1245. ret_helpVolume == NULL || ret_locationId == NULL)
  1246. {
  1247. errno = EINVAL;
  1248. return -1;
  1249. }
  1250. /* only process SameVolume or CrossVolume links */
  1251. switch (hyperLine->hyper_type)
  1252. {
  1253. case _DtCvLinkType_SameVolume:
  1254. case _DtCvLinkType_CrossLink:
  1255. break;
  1256. default:
  1257. errno = DtErrorHyperType;
  1258. return -1; /* RETURN */
  1259. }
  1260. /* Initialize the pointers. */
  1261. *ret_helpVolume = NULL;
  1262. *ret_locationId = NULL;
  1263. /* get working copy of spec */
  1264. linkSpec = strdup (hyperLine->specification);
  1265. if (linkSpec == NULL)
  1266. {
  1267. errno = DtErrorMalloc;
  1268. return -1;
  1269. }
  1270. /* parse the link spec. Syntax is: "[volume] locationId" */
  1271. if (linkSpec == NULL || *linkSpec == EOS)
  1272. {
  1273. errno = DtErrorHyperSpec; /* no spec */
  1274. }
  1275. else /* at least one token exists */
  1276. {
  1277. volumeName = linkSpec; /* posit that first token is the volume */
  1278. /* look for another possible token */
  1279. idToken = NULL;
  1280. _DtHelpCeStrchr (linkSpec," ",MB_CUR_MAX,&idToken);
  1281. /* second token? */
  1282. if (idToken) /* second token */
  1283. {
  1284. /* separate the tokens and advance idToken to first valid char */
  1285. *idToken = EOS; idToken++;
  1286. /* find the fully qualified volume (volName is malloc'd) */
  1287. volumeName = _DtHelpFileLocate(DtHelpVOLUME_TYPE, volumeName,
  1288. _DtHelpFileSuffixList,False,R_OK);
  1289. if (volumeName == NULL)
  1290. errno = DtErrorIllegalPath;
  1291. }
  1292. else /* no second token */
  1293. {
  1294. idToken = volumeName;
  1295. /* find the fully qualified volume (volName is malloc'd) */
  1296. volumeName = _DtHelpFileLocate(DtHelpVOLUME_TYPE, ref_volume,
  1297. _DtHelpFileSuffixList,False,R_OK);
  1298. if (volumeName == NULL)
  1299. errno = DtErrorIllegalPath;
  1300. }
  1301. if (idToken && volumeName)
  1302. {
  1303. *ret_helpVolume = volumeName; /* already allocd by _DtHelpFileLocate */
  1304. *ret_locationId = strdup (idToken);
  1305. if (*ret_locationId == NULL)
  1306. errno = DtErrorMalloc;
  1307. }
  1308. } /* if at least one token exists */
  1309. free (linkSpec);
  1310. return ( (*ret_helpVolume && *ret_locationId) ? 0 : -1 );
  1311. } /* End _DtHelpProcessLinkData */
  1312. /*****************************************************************************
  1313. * Function: void _DtHelpFreeTopicData (char **helpList,
  1314. * DtHelpHyperLines *hyperList)
  1315. *
  1316. * Parameters:
  1317. * helpList Specifies a pointer to a NULL terminated
  1318. * array of strings.
  1319. * hyperList Specifies a pointer to a NULL terminated
  1320. * list of DtHelpHyperLines.
  1321. *
  1322. * Returns: Nothing
  1323. *
  1324. * Purpose: _DtHelpFreeTopicData frees the data associated with a topic.
  1325. *
  1326. *****************************************************************************/
  1327. void
  1328. _DtHelpFreeTopicData (
  1329. char **helpList,
  1330. DtHelpHyperLines *hyperList)
  1331. {
  1332. if (helpList != NULL)
  1333. _DtHelpCeFreeStringArray (helpList);
  1334. if (hyperList != NULL)
  1335. DeallocateHyperArray (hyperList);
  1336. } /* End _DtHelpFreeTopicData */
  1337. /******************************************************************************
  1338. * Function: int _DtHelpGetTopicChildren (char *helpVolume, char *topic_id,
  1339. * char ***ret_children)
  1340. *
  1341. * Parameters:
  1342. * helpVolume Specifies a file path to the volume.
  1343. * topic_id Specifies the id of the desired topic.
  1344. * ret_children Returns a NULL terminated array of
  1345. * strings. The memory for these strings
  1346. * *IS OWNED* by the caller and must be freed
  1347. * after use.
  1348. *
  1349. * Returns: > 0 for success, -1 for failure.
  1350. *
  1351. * errno Values:
  1352. *
  1353. * Purpose: _DtHelpGetTopicChildren returns the topic ids of the children
  1354. * for a given topic id.
  1355. *
  1356. *****************************************************************************/
  1357. int
  1358. _DtHelpGetTopicChildren (
  1359. char *helpVolume,
  1360. char *topic_id,
  1361. char ***ret_children)
  1362. {
  1363. int result = -1;
  1364. _DtHelpVolumeHdl volume = NULL;
  1365. char * path;
  1366. /* Initialize the pointer */
  1367. *ret_children = NULL;
  1368. /* find the volume (path is malloc'd) */
  1369. path = _DtHelpFileLocate(DtHelpVOLUME_TYPE, helpVolume,
  1370. _DtHelpFileSuffixList,False,R_OK);
  1371. if (path == NULL) { errno = EINVAL; return -1; } /* RETURN */
  1372. /* open new canvas or reuse old one with new size */
  1373. _DtHelpProcessLock();
  1374. if (MyCanvas == NULL)
  1375. {
  1376. _DtHelpTermCreateCanvas(72,&MyCanvas); /* 72: arbitary value for max columns */
  1377. if (MyCanvas == NULL)
  1378. {
  1379. free(path);
  1380. _DtHelpProcessUnlock();
  1381. return -1; /* RETURN: errno=??? */
  1382. }
  1383. }
  1384. if (_DtHelpOpenVolume (helpVolume, &volume) == -1)
  1385. {
  1386. free(path);
  1387. _DtHelpProcessUnlock();
  1388. return -1; /* RETURN: errno=??? */
  1389. }
  1390. /* release any previously opened volume */
  1391. if (MyVolume)
  1392. _DtHelpCloseVolume (MyVolume);
  1393. /* assign the new volume */
  1394. MyVolume = volume;
  1395. /* Get the children */
  1396. result = _DtHelpCeGetTopicChildren(MyVolume, topic_id, ret_children);
  1397. _DtHelpProcessUnlock();
  1398. free(path);
  1399. return result;
  1400. }