UtilSDL.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  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: UtilSDL.c /main/10 1996/08/30 13:43:15 cde-hp $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: UtilSDL.c
  28. **
  29. ** Project: Cde Help System
  30. **
  31. ** Description: Utility functions for parsing an SDL volume.
  32. **
  33. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  34. **
  35. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  36. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  37. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  38. ** (c) Copyright 1993, 1994 Novell, Inc.
  39. **
  40. ****************************************************************************
  41. ************************************<+>*************************************/
  42. /*
  43. * system includes
  44. */
  45. #include <fcntl.h>
  46. #include <limits.h>
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include <unistd.h>
  51. /*
  52. * Canvas Engine includes
  53. */
  54. #include "CanvasP.h"
  55. #include "CanvasSegP.h"
  56. /*
  57. * private includes
  58. */
  59. #include "Access.h"
  60. #include "FontAttrI.h"
  61. #include "AccessSDLP.h"
  62. #include "CanvasError.h"
  63. #include "bufioI.h"
  64. #include "FormatUtilI.h"
  65. #include "SDLI.h"
  66. #include "FormatSDLI.h"
  67. #include "StringFuncsI.h"
  68. #include "UtilSDLI.h"
  69. #ifdef NLS16
  70. #endif
  71. /******** Private Function Declarations ********/
  72. /******** End Private Function Declarations ********/
  73. /******************************************************************************
  74. *
  75. * Private defines.
  76. *
  77. *****************************************************************************/
  78. #ifndef FALSE
  79. #define FALSE 0
  80. #endif
  81. #ifndef False
  82. #define False 0
  83. #endif
  84. #ifndef TRUE
  85. #define TRUE 1
  86. #endif
  87. #ifndef True
  88. #define True 1
  89. #endif
  90. #define GROW_SIZE 10
  91. #define MAX_ELEMENT_SIZE 30
  92. typedef struct _classStyleMatrix
  93. {
  94. SdlOption start;
  95. SdlOption end;
  96. enum SdlElement style;
  97. } ClassStyleMatrix;
  98. /******************************************************************************
  99. *
  100. * Private macros.
  101. *
  102. *****************************************************************************/
  103. #define IsWhiteSpace(x) \
  104. (((x) == '\n' || (x) == ' ' || (x) == '\t') ? 1 : 0)
  105. #define IsNumber(x) \
  106. (((x) >= '0' && (x) <= '9') ? 1 : 0)
  107. /******************************************************************************
  108. *
  109. * Private data.
  110. *
  111. *****************************************************************************/
  112. static ClassStyleMatrix ClassToStyle[] =
  113. {
  114. { SdlClassAcro , SdlClassUdefkey , SdlElementKeyStyle },
  115. { SdlClassLabel , SdlClassUdefhead , SdlElementHeadStyle },
  116. { SdlClassTable , SdlClassUdeffrmt , SdlElementFormStyle },
  117. { SdlClassTable , SdlClassUdeffrmt , SdlElementFrmtStyle },
  118. { SdlClassFigure, SdlClassUdefgraph, SdlElementGrphStyle },
  119. { SdlOptionBad , SdlOptionBad , SdlElementNone },
  120. };
  121. /******************************************************************************
  122. *
  123. * Private Functions
  124. *
  125. *****************************************************************************/
  126. /******************************************************************************
  127. * Function: static int SkipWhiteSpace (BufFilePtr f)
  128. *
  129. * Parameters:
  130. *
  131. * Returns 0 if successfully skipped white space.
  132. * -1 if errors.
  133. *
  134. * errno Values:
  135. *
  136. * Purpose:
  137. *
  138. *****************************************************************************/
  139. static int
  140. SkipWhiteSpace (
  141. BufFilePtr f)
  142. {
  143. char c;
  144. do {
  145. c = BufFileGet(f);
  146. if (c == BUFFILEEOF)
  147. return -1;
  148. } while (IsWhiteSpace(c));
  149. BufFilePutBack(c, f);
  150. return 0;
  151. }
  152. /******************************************************************************
  153. * Function: static int CheckSDLAttributeNameStart (char c)
  154. *
  155. * Parameters:
  156. *
  157. * Returns 0 if starts correctly,
  158. * -1 if does not start correctly for an attribute name
  159. *
  160. * errno Values:
  161. *
  162. * Purpose:
  163. *
  164. *****************************************************************************/
  165. static int
  166. CheckSDLAttributeNameStart (char c)
  167. {
  168. if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
  169. return 0;
  170. return -1;
  171. }
  172. /******************************************************************************
  173. * Function: int GetSDLElement (BufFilePtr f, char **string)
  174. *
  175. * Parameters:
  176. *
  177. * Returns 0 if got an element (subject to verification).
  178. * 1 if end of file/compressed section.
  179. * -1 if errors.
  180. *
  181. * errno Values:
  182. *
  183. * Memory owned: the returned string.
  184. *
  185. * Purpose:
  186. *
  187. *****************************************************************************/
  188. static int
  189. GetSDLElement (
  190. BufFilePtr f,
  191. int max_allowed,
  192. char *string)
  193. {
  194. _DtCvValue done = False;
  195. _DtCvValue first = True;
  196. _DtCvValue nonWhite = False;
  197. _DtCvValue startEl = False;
  198. int len = 0;
  199. char c;
  200. do {
  201. c = BufFileGet(f);
  202. /*
  203. * [chars][space] (nonWhite == True && IsWhiteSpace(c))
  204. * <element> (startEl == True && c == '>')
  205. * [chars]<element.. (first == False && c == '<')
  206. */
  207. if (c == BUFFILEEOF || (nonWhite == True && IsWhiteSpace(c))
  208. || (startEl == True && c == '>')
  209. || (first == False && c == '<'))
  210. {
  211. if (c == '>' || c == '<' || (nonWhite == True && IsWhiteSpace(c)))
  212. BufFilePutBack(c,f);
  213. done = True;
  214. }
  215. else
  216. {
  217. if (first == True && c == '<')
  218. startEl = True;
  219. first = False;
  220. if (nonWhite == False && IsWhiteSpace(c) == False)
  221. nonWhite = True;
  222. string[len++] = c;
  223. if (len >= max_allowed)
  224. done = True;
  225. }
  226. } while (!done);
  227. string[len] = '\0';
  228. if (len == 0)
  229. {
  230. if (c != BUFFILEEOF)
  231. return -1;
  232. else /* if (c == BUFFILEEOF) */
  233. return 1;
  234. }
  235. return 0;
  236. }
  237. /******************************************************************************
  238. *
  239. * Semi Public Functions
  240. *
  241. *****************************************************************************/
  242. /******************************************************************************
  243. * Function: int _DtHelpCeMatchSdlElement (BufFilePtr my_file,
  244. * const char *element_str, int sig_chars)
  245. *
  246. * Parameters:
  247. *
  248. * Returns 0 if successfully matched element_str,
  249. * 1 if did not match,
  250. * -1 if errors.
  251. *
  252. * errno Values:
  253. *
  254. * Purpose:
  255. *
  256. *****************************************************************************/
  257. int
  258. _DtHelpCeMatchSdlElement (
  259. BufFilePtr f,
  260. const char *element_str,
  261. int sig_chars)
  262. {
  263. int len;
  264. int different = False;
  265. char nextEl[MAX_ELEMENT_SIZE + 2];
  266. char *ptr;
  267. char c;
  268. /*
  269. * get the next element in the stream
  270. */
  271. do {
  272. if (GetSDLElement(f, MAX_ELEMENT_SIZE, nextEl) != 0)
  273. return -1;
  274. /*
  275. * now skip the white space
  276. */
  277. ptr = nextEl;
  278. while (IsWhiteSpace(*ptr)) ptr++;
  279. } while (*ptr == '\0');
  280. len = strlen(element_str);
  281. do {
  282. /*
  283. * get the lowered version of the character
  284. */
  285. c = _DtHelpCeToLower(*ptr);
  286. if (c != *element_str)
  287. different = True;
  288. len--;
  289. sig_chars--;
  290. element_str++;
  291. ptr++;
  292. } while (len && sig_chars && !different && *ptr != '\0');
  293. if (!different && sig_chars > 0 && len > 0)
  294. different = True;
  295. return different;
  296. }
  297. /******************************************************************************
  298. * Function: int _DtHelpCeGetSdlAttribute (BufFilePtr f,
  299. * char *attribute_name)
  300. *
  301. * Parameters:
  302. * f Specifies the buf file to read.
  303. * max_len Specifies the maximum number of characters
  304. * that can fit in 'attribute_name'. Does
  305. * *NOT* include the terminating null byte.
  306. * attribute_name Specifies the buffer in which to place
  307. * the attribute.
  308. *
  309. *
  310. * Returns 0 if successfully retrieved an attribute name.
  311. * 1 if there is no more attributes (eats the element end).
  312. * -1 if errors.
  313. *
  314. * errno Values:
  315. *
  316. * Purpose: Reads the an attribute.
  317. * Lower cases the attribute.
  318. *
  319. *****************************************************************************/
  320. int
  321. _DtHelpCeGetSdlAttribute (
  322. BufFilePtr f,
  323. int max_len,
  324. char *attribute_name)
  325. {
  326. int len = 0;
  327. char c;
  328. if (SkipWhiteSpace(f) != 0)
  329. return -1;
  330. /*
  331. * check that the attribute name starts correctly
  332. */
  333. c = BufFileGet(f);
  334. if (c == '>')
  335. return 1;
  336. if (CheckSDLAttributeNameStart(c) != 0)
  337. return -1;
  338. do {
  339. c = _DtHelpCeToLower(c);
  340. attribute_name[len++] = c;
  341. c = BufFileGet(f);
  342. } while (c != BUFFILEEOF && !IsWhiteSpace(c) && c != '=' && len < max_len);
  343. while (c != '=')
  344. {
  345. c = BufFileGet(f);
  346. if (c == BUFFILEEOF)
  347. return -1;
  348. }
  349. if (len == 0 || len >= max_len)
  350. return -1;
  351. attribute_name[len] = '\0';
  352. return 0;
  353. }
  354. /******************************************************************************
  355. * Function: int _DtHelpCeReturnSdlElement ()
  356. *
  357. * Parameters:
  358. *
  359. *
  360. * Returns 0 if matched an element in the list
  361. * 1 hit eof on the file/compressed section.
  362. * -1 if errors.
  363. *
  364. * errno Values:
  365. *
  366. * Purpose:
  367. *
  368. * Memory Owned By Caller: number_str
  369. *
  370. *****************************************************************************/
  371. int
  372. _DtHelpCeReturnSdlElement (
  373. BufFilePtr f,
  374. const SDLElementInfo *el_list,
  375. _DtCvValue cdata_flag,
  376. enum SdlElement *ret_el_define,
  377. char **ret_data,
  378. _DtCvValue *ret_end_flag)
  379. {
  380. int result;
  381. int lowerChar;
  382. _DtCvValue endFlag = False;
  383. _DtCvValue different = True;
  384. char nextEl[MAX_ELEMENT_SIZE + 2];
  385. char *ptr;
  386. *ret_el_define = SdlElementCdata;
  387. *ret_end_flag = False;
  388. if (ret_data)
  389. *ret_data = NULL;
  390. /*
  391. * get the next element
  392. */
  393. do {
  394. result = GetSDLElement(f, MAX_ELEMENT_SIZE, nextEl);
  395. if (result == 1)
  396. {
  397. *ret_el_define = SdlElementNone;
  398. return 1;
  399. }
  400. else if (result == -1)
  401. return -1;
  402. /*
  403. * lower case the element. String dup it first incase this is data
  404. * and not an element. Then skip the leading white space.
  405. */
  406. ptr = nextEl;
  407. while (IsWhiteSpace(*ptr) == True) ptr++;
  408. } while (cdata_flag == False && *ptr == '\0');
  409. /*
  410. * An element starts with a less than sign,
  411. * An end element starts with a less than sign and a forward slash.
  412. */
  413. /*
  414. * if all we've got is white space, or a non starting character,
  415. * then skip the loop
  416. */
  417. if (*ptr == '<')
  418. {
  419. /*
  420. * skip the less than sign.
  421. */
  422. ptr++;
  423. /*
  424. * is this an end element?
  425. */
  426. if (*ptr == '/')
  427. {
  428. endFlag = True;
  429. ptr++;
  430. }
  431. lowerChar = (int) _DtHelpCeToLower(*ptr);
  432. while (different && el_list->element_str != NULL)
  433. {
  434. if (endFlag == True && el_list->element_end_str != NULL &&
  435. lowerChar == ((int)(el_list->element_end_str[2])) &&
  436. _DtHelpCeStrNCaseCmpLatin1(&(el_list->element_end_str[2]),
  437. ptr, el_list->end_sig_chars - 2) == 0)
  438. {
  439. different = False;
  440. *ret_end_flag = True;
  441. }
  442. else if (endFlag == False &&
  443. lowerChar == ((int)(el_list->element_str[1])) &&
  444. _DtHelpCeStrNCaseCmpLatin1(&(el_list->element_str[1]), ptr,
  445. el_list->str_sig_chars - 1) == 0)
  446. different = False;
  447. else
  448. el_list++;
  449. }
  450. *ret_el_define = el_list->sdl_element;
  451. }
  452. if (*ret_el_define == SdlElementCdata && ret_data != NULL)
  453. *ret_data = strdup(nextEl);
  454. return 0;
  455. }
  456. /******************************************************************************
  457. * Function: int _DtHelpCeGetSdlCdata (BufFilePtr f, char **string)
  458. *
  459. * Parameters:
  460. *
  461. *
  462. * Returns 0 if successfully retrieved data.
  463. * 1 if returning because type != SdlTypeDynamic and a newline
  464. * was found.
  465. * 2 if returning because ran into a non-breaking character.
  466. * -1 if errors.
  467. *
  468. * errno Values:
  469. *
  470. * Purpose:
  471. *
  472. * Memory Owned By Caller: attribute_name
  473. *
  474. *****************************************************************************/
  475. int
  476. _DtHelpCeGetSdlCdata (
  477. BufFilePtr f,
  478. SdlOption type,
  479. int max_mb,
  480. _DtCvValue nl_to_space,
  481. _DtCvValue *cur_space,
  482. _DtCvValue *cur_nl,
  483. _DtCvValue *cur_mb,
  484. char *non_break_char,
  485. char **string,
  486. int *str_max)
  487. {
  488. _DtCvValue lastWasSpace = *cur_space;
  489. _DtCvValue lastWasNl = *cur_nl;
  490. _DtCvValue lastWasMb = *cur_mb;
  491. _DtCvValue ignore = False;
  492. _DtCvValue done = False;
  493. _DtCvValue escaped = False;
  494. int strSize = 0;
  495. int reason = 0;
  496. int len = 0;
  497. int strMB = 1;
  498. char *ptr;
  499. char buf[MB_LEN_MAX + 1];
  500. #define ESC_STR_LEN 4
  501. char escStr[ESC_STR_LEN];
  502. char c;
  503. if (string == NULL)
  504. ignore = True;
  505. else if (*string != NULL)
  506. {
  507. strSize = strlen(*string);
  508. if (*str_max < strSize)
  509. *str_max = strSize;
  510. }
  511. do {
  512. c = BufFileGet(f);
  513. buf[len++] = c;
  514. buf[len] = '\0';
  515. if (c != BUFFILEEOF && max_mb != 1)
  516. strMB = mblen(buf, max_mb);
  517. if (c == BUFFILEEOF || (escaped == False && strMB == 1 &&
  518. (c == '<' ||
  519. ((type == SdlTypeLiteral || type == SdlTypeLined) &&
  520. c == '\n'))))
  521. {
  522. if (c == '\n')
  523. reason = 1;
  524. else if (c == '<')
  525. BufFilePutBack(c,f);
  526. done = True;
  527. }
  528. else if (strMB == 1)
  529. {
  530. len = 0;
  531. if (lastWasNl == True)
  532. {
  533. ptr = " ";
  534. if (_DtHelpCeAddCharToBuf(&ptr, string, &strSize,
  535. str_max, 32) == -1)
  536. return -1;
  537. lastWasSpace = True;
  538. }
  539. lastWasMb = False;
  540. lastWasNl = False;
  541. if (escaped == True)
  542. {
  543. if (c == '#')
  544. {
  545. /*
  546. * process the SGML numeric character reference
  547. * entity. '&#d[d[d]][;]' - 'ddd' represent
  548. * characters of '0' to '9'. The semi-colon is
  549. * required iff the next character is a numeric
  550. * character of '0' to '9'. Otherwise it is
  551. * optional.
  552. */
  553. int value;
  554. len = 0; /* len should be zero here, but let's make sure */
  555. do
  556. {
  557. /*
  558. * get the next character.
  559. */
  560. c = BufFileGet(f);
  561. /*
  562. * if it is the first character of the numeric entity,
  563. * it has to be a numeric character.
  564. */
  565. if (c == BUFFILEEOF ||
  566. (len == 0 && (c < '0' || c > '9')))
  567. return -1;
  568. /*
  569. * put the character in the buffer
  570. */
  571. escStr[len++] = c;
  572. } while (len < ESC_STR_LEN && c >= '0' && c <= '9');
  573. /*
  574. * the ending character of the entity has to be a
  575. * non-numeric character.
  576. */
  577. if (c >= '0' && c <= '9')
  578. return -1;
  579. /*
  580. * if the optional semi-colon is not present, replace
  581. * the terminating character back in the input buffer
  582. * to be processed in the next pass.
  583. */
  584. else if (c != ';')
  585. BufFilePutBack(c, f);
  586. /*
  587. * get the integer value. It has to be less than 256.
  588. */
  589. value = atoi(escStr);
  590. if (value > 255)
  591. return -1;
  592. /*
  593. * transfer the value to the character variable
  594. * and zero the index for the general buffer.
  595. */
  596. c = value;
  597. len = 0;
  598. /*
  599. * set up for the return information
  600. */
  601. done = True;
  602. reason = 2;
  603. *non_break_char = c;
  604. }
  605. /*
  606. * clear the escaped flag, so that the character gets
  607. * put in the output buffer.
  608. */
  609. escaped = False;
  610. }
  611. else if (c == '\n')
  612. {
  613. if (type == SdlTypeCdata)
  614. lastWasSpace = False;
  615. else if (lastWasSpace == False)
  616. lastWasNl = True;
  617. continue;
  618. }
  619. else if (c == '&')
  620. escaped = True;
  621. if (escaped == False && ignore == False)
  622. {
  623. if (c == '\t')
  624. c = ' ';
  625. ptr = &c;
  626. if (c == '\n')
  627. {
  628. lastWasSpace = True;
  629. reason = 1;
  630. done = True;
  631. }
  632. /*
  633. * as long as we aren't processing a non break character,
  634. * add it to the buffer.
  635. */
  636. else if (2 != reason)
  637. {
  638. if (c != ' ')
  639. lastWasSpace = False;
  640. if ((lastWasSpace == False || type == SdlTypeLiteral ||
  641. type == SdlTypeUnlinedLiteral)
  642. &&
  643. _DtHelpCeAddCharToBuf(&ptr, string, &strSize,
  644. str_max, 32) == -1)
  645. return -1;
  646. if (type != SdlTypeLiteral &&
  647. type != SdlTypeUnlinedLiteral && c == ' ')
  648. lastWasSpace = True;
  649. }
  650. }
  651. }
  652. else if (strMB > 1)
  653. {
  654. if (ignore == False)
  655. {
  656. if (lastWasNl == True)
  657. {
  658. if (nl_to_space == True || lastWasMb == False)
  659. {
  660. ptr = " ";
  661. if (_DtHelpCeAddCharToBuf(&ptr, string, &strSize,
  662. str_max, 32) == -1)
  663. return -1;
  664. }
  665. }
  666. ptr = buf;
  667. if (_DtHelpCeAddStrToBuf(&ptr,string,&strSize,str_max,len,32)
  668. == -1)
  669. return -1;
  670. }
  671. lastWasMb = True;
  672. lastWasNl = False;
  673. lastWasSpace = False;
  674. escaped = False;
  675. len = 0;
  676. }
  677. else if (strMB == 0 || len > max_mb || len >= MB_LEN_MAX)
  678. return -1;
  679. } while (done == False);
  680. *cur_space = lastWasSpace;
  681. *cur_nl = lastWasNl;
  682. *cur_mb = lastWasMb;
  683. return reason;
  684. }
  685. /******************************************************************************
  686. * Function: int _DtHelpCeGetSdlAttributeCdata (BufFilePtr f, char **string);
  687. *
  688. * Parameters:
  689. *
  690. *
  691. * Returns 0 if successfully retrieved an attribute name.
  692. * -1 if errors.
  693. *
  694. * errno Values:
  695. *
  696. * Purpose: Parses the CDATA value for an element attribute. Expects the
  697. * pointer to be after the equals sign of the attribute. The
  698. * CDATA must be included in quotes (either single or double)
  699. * and can have white space (spaces, newlines or tabs) preceding
  700. * it. Any newline encountered within the CDATA value is turned
  701. * into a space. Any quote enclosed in the CDATA must not be the
  702. * same type as what is used to delimit the CDATA value. I.E.
  703. * if a single quote is used in the CDATA, the CDATA value must
  704. * be enclosed in double quotes.
  705. *
  706. * Memory Owned By Caller: attribute_name
  707. *
  708. *****************************************************************************/
  709. int
  710. _DtHelpCeGetSdlAttributeCdata (
  711. BufFilePtr f,
  712. _DtCvValue limit,
  713. char **string)
  714. {
  715. _DtCvValue ignore = False;
  716. _DtCvValue done = False;
  717. _DtCvValue firstChar = True;
  718. int strSize = 0;
  719. int strMax = 0;
  720. char *myStr = NULL;
  721. char c;
  722. char testChar;
  723. if (string == NULL)
  724. ignore = True;
  725. else if (limit == True)
  726. myStr = *string;
  727. if (SkipWhiteSpace(f) != 0)
  728. return -1;
  729. do {
  730. c = BufFileGet(f);
  731. if (c == BUFFILEEOF)
  732. {
  733. if (myStr != NULL)
  734. free(myStr);
  735. return -1;
  736. }
  737. if (firstChar)
  738. {
  739. if (c == '\'' || c == '\"')
  740. {
  741. testChar = c;
  742. firstChar = False;
  743. }
  744. else
  745. {
  746. if (myStr != NULL)
  747. free(myStr);
  748. return -1;
  749. }
  750. }
  751. else if (c == testChar)
  752. done = True;
  753. else if (ignore == False)
  754. {
  755. if (c == '\n')
  756. c = ' ';
  757. if (limit == True && strSize >= DTD_NAMELEN)
  758. {
  759. if (myStr != NULL)
  760. free(myStr);
  761. return -1;
  762. }
  763. else if (limit == False && strSize >= strMax)
  764. {
  765. strMax += 64;
  766. if (strSize == 0)
  767. myStr = (char *) malloc (sizeof(char) * 65);
  768. else
  769. myStr = (char *) realloc (myStr,(sizeof(char)*(strMax+1)));
  770. if (myStr == NULL)
  771. return -1;
  772. }
  773. myStr[strSize++] = c;
  774. }
  775. } while (done == False);
  776. if (ignore == False)
  777. {
  778. if (myStr != NULL)
  779. myStr[strSize] = '\0';
  780. if (limit == False)
  781. *string = myStr;
  782. }
  783. return 0;
  784. }
  785. /******************************************************************************
  786. * Function: int _DtHelpCeSkipCdata (BufFilePtr f, _DtCvValue Flag)
  787. *
  788. * Parameters:
  789. *
  790. *
  791. * Returns 0 if successfully retrieved an attribute name.
  792. * -1 if errors.
  793. *
  794. * errno Values:
  795. *
  796. * Purpose:
  797. *
  798. * Memory Owned By Caller: attribute_name
  799. *
  800. *****************************************************************************/
  801. int
  802. _DtHelpCeSkipCdata (
  803. BufFilePtr f,
  804. _DtCvValue flag)
  805. {
  806. _DtCvValue done = False;
  807. _DtCvValue singleQuote = False;
  808. _DtCvValue doubleQuote = False;
  809. _DtCvValue comment = False;
  810. _DtCvValue element = False;
  811. _DtCvValue bracket = False;
  812. _DtCvValue processing = True;
  813. char c;
  814. do {
  815. c = BufFileGet(f);
  816. if (c == BUFFILEEOF)
  817. return -1;
  818. if (processing)
  819. {
  820. if (c == '\'')
  821. {
  822. singleQuote = True;
  823. processing = False;
  824. }
  825. else if (c == '\"')
  826. {
  827. doubleQuote = True;
  828. processing = False;
  829. }
  830. else if (c == '-')
  831. {
  832. c = BufFileGet(f);
  833. if (c == BUFFILEEOF)
  834. return -1;
  835. if (c == '-')
  836. {
  837. comment = True;
  838. processing = False;
  839. }
  840. else
  841. BufFilePutBack(c,f);
  842. }
  843. else if (!element && c == '<')
  844. element = True;
  845. else if (c == '>')
  846. {
  847. if (element)
  848. element = False;
  849. else
  850. {
  851. BufFilePutBack(c,f);
  852. done = True;
  853. }
  854. }
  855. else if (flag && c == '[')
  856. bracket = True;
  857. else if (bracket && c == ']')
  858. {
  859. bracket = False;
  860. flag = False;
  861. }
  862. }
  863. else
  864. {
  865. if (singleQuote && c == '\'')
  866. {
  867. singleQuote = False;
  868. processing = True;
  869. }
  870. else if (doubleQuote && c == '\"')
  871. {
  872. doubleQuote = False;
  873. processing = True;
  874. }
  875. else if (comment && c == '-')
  876. {
  877. c = BufFileGet(f);
  878. if (c == BUFFILEEOF)
  879. return -1;
  880. if (c == '-')
  881. {
  882. comment = False;
  883. processing = True;
  884. }
  885. else
  886. BufFilePutBack(c,f);
  887. }
  888. }
  889. } while (done == False);
  890. if (flag)
  891. return -1;
  892. return 0;
  893. }
  894. /******************************************************************************
  895. * Function: int _DtHelpCeGetSdlId (BufFilePtr f, char **id_value)
  896. *
  897. * Parameters:
  898. *
  899. *
  900. * Returns 0 if successfully retrieved an attribute name.
  901. * -1 if errors.
  902. *
  903. * errno Values:
  904. *
  905. * Purpose:
  906. *
  907. * Memory Owned By Caller: id_value
  908. *
  909. *****************************************************************************/
  910. int
  911. _DtHelpCeGetSdlId (
  912. BufFilePtr f,
  913. char **id_value)
  914. {
  915. *id_value = NULL;
  916. if (_DtHelpCeGetSdlAttributeCdata (f, False, id_value) != 0)
  917. return -1;
  918. /*
  919. * check that the attribute name starts correctly
  920. */
  921. if (CheckSDLAttributeNameStart(**id_value) != 0)
  922. return -1;
  923. return 0;
  924. }
  925. /******************************************************************************
  926. * Function: int _DtHelpCeGetSdlNumber (BufFilePtr f, char **number_str)
  927. *
  928. * Parameters:
  929. *
  930. *
  931. * Returns 0 if successfully retrieved an attribute name.
  932. * -1 if errors.
  933. *
  934. * errno Values:
  935. *
  936. * Purpose:
  937. *
  938. * Memory Owned By Caller: number_str
  939. *
  940. *****************************************************************************/
  941. int
  942. _DtHelpCeGetSdlNumber (
  943. BufFilePtr f,
  944. char *number_str)
  945. {
  946. if (_DtHelpCeGetSdlAttributeCdata(f, True, &number_str) != 0)
  947. return -1;
  948. /*
  949. * check that the attribute name starts correctly
  950. */
  951. if (!IsNumber(*number_str))
  952. return -1;
  953. return 0;
  954. }
  955. /******************************************************************************
  956. * Function: int _DtHelpCeFindSkipSdlElementEnd (BufFilePtr f)
  957. *
  958. * Parameters:
  959. *
  960. *
  961. * Returns 0 if successfully retrieved an attribute name.
  962. * -1 if errors.
  963. *
  964. * errno Values:
  965. *
  966. * Purpose:
  967. *
  968. * Memory Owned By Caller: attribute_name
  969. *
  970. *****************************************************************************/
  971. int
  972. _DtHelpCeFindSkipSdlElementEnd (
  973. BufFilePtr f)
  974. {
  975. char c;
  976. if (SkipWhiteSpace(f) != 0)
  977. return -1;
  978. do {
  979. c = BufFileGet(f);
  980. if (c == BUFFILEEOF)
  981. return -1;
  982. } while (c != '>');
  983. return 0;
  984. }
  985. /******************************************************************************
  986. * Function: int _DtHelpCeMergeSdlAttribInfo (_DtCanvasStruct canvas,
  987. * _DtCvSegment *src_el,
  988. * _DtCvSegment *dst_el);
  989. *
  990. * Parameters:
  991. *
  992. * Returns: nothing
  993. *
  994. * Purpose: Merge the src specified attributes into the dst.
  995. * THIS WILL NOT MERGE THE SSI or RSSI values.
  996. *
  997. ******************************************************************************/
  998. void
  999. _DtHelpCeMergeSdlAttribInfo(
  1000. _DtCvSegment *src_seg,
  1001. _DtCvSegment *dst_seg,
  1002. _DtHelpFontHints *dst_fonts,
  1003. void *el_info,
  1004. unsigned long *str1_values,
  1005. unsigned long *str2_values)
  1006. {
  1007. unsigned long flag;
  1008. const SDLAttribute *pAttr;
  1009. SdlOption *dstEnum;
  1010. SdlOption *srcEnum;
  1011. SDLNumber *dstNum;
  1012. SDLNumber *srcNum;
  1013. SDLCdata *dstStr;
  1014. SDLCdata *srcStr;
  1015. SDLTossInfo *tossInfo;
  1016. char *src;
  1017. char *dst;
  1018. if (src_seg != NULL)
  1019. {
  1020. tossInfo = _SdlSegPtrToTossInfo(src_seg);
  1021. for (pAttr = _DtHelpCeGetSdlAttributeList();
  1022. pAttr->data_type != SdlAttrDataTypeInvalid; pAttr++)
  1023. {
  1024. if ((pAttr->struct_type == SdlFontSpecific ||
  1025. pAttr->struct_type == SdlContainerSpecific)
  1026. &&
  1027. SDLIsAttrSet(*tossInfo, pAttr->sdl_attr_define)
  1028. &&
  1029. !(ATTRS_EQUAL(pAttr->data_type, pAttr->sdl_attr_define,
  1030. SDL_ATTR_SSI) ||
  1031. ATTRS_EQUAL(pAttr->data_type, pAttr->sdl_attr_define,
  1032. SDL_ATTR_RSSI)))
  1033. {
  1034. if (pAttr->struct_type == SdlFontSpecific)
  1035. {
  1036. src = ((char *)(&(_SdlTossInfoPtrFontSpecs(tossInfo))));
  1037. dst = ((char *) dst_fonts);
  1038. }
  1039. else /* if (pAttr->struct_type == SdlContainerSpecific) */
  1040. {
  1041. src = ((char *)_SdlContainerPtrOfSeg(src_seg));
  1042. dst = ((char *)_SdlContainerPtrOfSeg(dst_seg));
  1043. }
  1044. switch (SDLAttrFlagType(pAttr->sdl_attr_define))
  1045. {
  1046. case ENUM_VALUE:
  1047. dstEnum = (SdlOption *)
  1048. (((char *)dst) + pAttr->field_ptr);
  1049. srcEnum = (SdlOption *)
  1050. (((char *)src) + pAttr->field_ptr);
  1051. *dstEnum = *srcEnum;
  1052. break;
  1053. case NUMBER_VALUE:
  1054. dstNum = (SDLNumber *)
  1055. (((char *)dst) + pAttr->field_ptr);
  1056. srcNum = (SDLNumber *)
  1057. (((char *)src) + pAttr->field_ptr);
  1058. *dstNum = *srcNum;
  1059. break;
  1060. case STRING1_VALUE:
  1061. case STRING2_VALUE:
  1062. dstStr = (SDLCdata *)
  1063. (((char *)dst) + pAttr->field_ptr);
  1064. srcStr = (SDLCdata *)
  1065. (((char *)src) + pAttr->field_ptr);
  1066. *dstStr = *srcStr;
  1067. break;
  1068. }
  1069. }
  1070. else if (NULL != el_info &&
  1071. pAttr->struct_type == SdlElementSpecific &&
  1072. SDLIsAttrSet(*tossInfo, pAttr->sdl_attr_define))
  1073. {
  1074. flag = pAttr->sdl_attr_define & ~(VALUE_MASK);
  1075. dstStr = (SDLCdata *)(((char *)el_info) + pAttr->field_ptr);
  1076. if (SDL_ATTR_COLW == pAttr->sdl_attr_define)
  1077. *dstStr = _SdlTossInfoPtrColW(tossInfo);
  1078. else if (SDL_ATTR_COLJ == pAttr->sdl_attr_define)
  1079. *dstStr = _SdlTossInfoPtrColJ(tossInfo);
  1080. else if (SDL_ATTR_ENTER == pAttr->sdl_attr_define)
  1081. *dstStr = _SdlTossInfoPtrEnter(tossInfo);
  1082. else if (SDL_ATTR_EXIT == pAttr->sdl_attr_define)
  1083. *dstStr = _SdlTossInfoPtrExit(tossInfo);
  1084. if (STRING1_VALUE == (pAttr->sdl_attr_define & VALUE_MASK))
  1085. *str1_values = *str1_values | flag;
  1086. else if (STRING2_VALUE == (pAttr->sdl_attr_define & VALUE_MASK))
  1087. *str2_values = *str2_values | flag;
  1088. }
  1089. }
  1090. }
  1091. }
  1092. /******************************************************************************
  1093. * Function: void _DtHelpCeAddSegToList (_DtCvSegment *seg_ptr,
  1094. * _DtCvSegment **seg_list,
  1095. * _DtCvSegment **last_seg)
  1096. *
  1097. * Parameters:
  1098. *
  1099. * Returns: 0 if successful, -1 if errors
  1100. *
  1101. * errno Values:
  1102. *
  1103. * Purpose: Allocates a memory
  1104. *
  1105. ******************************************************************************/
  1106. void
  1107. _DtHelpCeAddSegToList(
  1108. _DtCvSegment *seg_ptr,
  1109. _DtCvSegment **seg_list,
  1110. _DtCvSegment **last_seg)
  1111. {
  1112. if (*seg_list == NULL)
  1113. *seg_list = seg_ptr;
  1114. else
  1115. (*last_seg)->next_seg = seg_ptr;
  1116. while (NULL != seg_ptr->next_seg)
  1117. seg_ptr = seg_ptr->next_seg;
  1118. *last_seg = seg_ptr;
  1119. }
  1120. /******************************************************************************
  1121. * Function: int _DtHelpCeAllocSegment (
  1122. * int malloc_size,
  1123. * int *alloc_size,
  1124. * _DtCvSegment **next_seg,
  1125. * _DtCvSegment **seg_ptr);
  1126. *
  1127. * Parameters:
  1128. * malloc_size Specifies the number of blocks to
  1129. * malloc. The first one is returned in
  1130. * 'seg_ptr' with the rest in 'next_seg',
  1131. * if 'next_seg' is non-NULL.
  1132. * alloc_size Ignored if NULL. If non-NULL, indicates
  1133. * the number of blocks in 'next_seg' if
  1134. * 'next_seg' is non-NULL and the 'next_seg'
  1135. * pointer is non-NULL.
  1136. * next_seg Specifies the block of memory to take the
  1137. * next segment from.
  1138. * Returns the pointer to the next segment.
  1139. * seg_ptr Returns a pointer to the segment to use.
  1140. *
  1141. * Returns: 0 if successful, -1 if errors
  1142. *
  1143. * Purpose: Allocates a memory
  1144. *
  1145. ******************************************************************************/
  1146. int
  1147. _DtHelpCeAllocSegment(
  1148. int malloc_size,
  1149. int *alloc_size,
  1150. _DtCvSegment **next_seg,
  1151. _DtCvSegment **seg_ptr)
  1152. {
  1153. int cnt = 0;
  1154. _DtCvSegment *newSeg = NULL;
  1155. if (next_seg != NULL)
  1156. newSeg = *next_seg;
  1157. if (alloc_size != NULL && newSeg != NULL)
  1158. cnt = *alloc_size;
  1159. if (cnt < 1)
  1160. {
  1161. newSeg = _DtHelpAllocateSegments(malloc_size);
  1162. if (newSeg == NULL)
  1163. return -1;
  1164. cnt = --malloc_size;
  1165. }
  1166. else
  1167. cnt--;
  1168. *seg_ptr = newSeg++;
  1169. if (next_seg != NULL)
  1170. {
  1171. *next_seg = NULL;
  1172. if (cnt > 0)
  1173. *next_seg = newSeg;
  1174. }
  1175. if (alloc_size != NULL)
  1176. *alloc_size = cnt;
  1177. return 0;
  1178. }
  1179. /******************************************************************************
  1180. * Function: int _DtHelpCeSaveString (
  1181. * string, multi_len)
  1182. *
  1183. * Parameters:
  1184. *
  1185. * Returns: 0 if successful, -1 if errors
  1186. *
  1187. * errno Values:
  1188. *
  1189. * Purpose: Looks for the virtual page beginning.
  1190. *
  1191. ******************************************************************************/
  1192. int
  1193. _DtHelpCeSaveString(
  1194. _DtCvPointer client_data,
  1195. _DtCvSegment **seg_list,
  1196. _DtCvSegment **last_seg,
  1197. _DtCvSegment **prev_seg,
  1198. char *string,
  1199. _DtHelpFontHints *font_specs,
  1200. int link_index,
  1201. int multi_len,
  1202. int flags,
  1203. void (*load_font)(),
  1204. _SdlFontMode resolve_font,
  1205. _DtCvValue newline)
  1206. {
  1207. int len;
  1208. int size;
  1209. int numChars = 0;
  1210. int junk = 0;
  1211. char tmpChar;
  1212. char *ptr = string;
  1213. _DtCvSegment *pSeg = NULL;
  1214. _DtCvSegment *junkSeg = NULL;
  1215. _DtHelpFontHints *fontSpec = NULL;
  1216. _DtCvValue addToList = False;
  1217. _DtCvPointer useFont = (_DtCvPointer) -1;
  1218. if (*ptr == '\0')
  1219. {
  1220. if (newline == True)
  1221. {
  1222. if (_DtHelpCeAllocSegment(1, &junk, &junkSeg, &pSeg) != 0)
  1223. return -1;
  1224. addToList = True;
  1225. }
  1226. }
  1227. else
  1228. {
  1229. if (_SdlFontModeResolve == resolve_font)
  1230. (*load_font)(client_data, _DtHelpFontHintsLang(*font_specs),
  1231. _DtHelpFontHintsCharSet(*font_specs),
  1232. *font_specs, &useFont);
  1233. while (*ptr != '\0')
  1234. {
  1235. if (_DtHelpCeAllocSegment(1, &junk, &junkSeg, &pSeg) != 0)
  1236. return -1;
  1237. if (_SdlFontModeSave == resolve_font)
  1238. {
  1239. fontSpec = (_DtHelpFontHints *) malloc (sizeof(_DtHelpFontHints));
  1240. if (NULL == fontSpec)
  1241. {
  1242. free(pSeg);
  1243. return -1;
  1244. }
  1245. /*
  1246. * copy the current fonts over
  1247. */
  1248. *fontSpec = *font_specs;
  1249. useFont = (_DtCvPointer) fontSpec;
  1250. }
  1251. /*
  1252. * set the type
  1253. */
  1254. pSeg->type = _DtCvSetTypeToString(flags);
  1255. /*
  1256. * set the wide char flag if necessary.
  1257. */
  1258. len = 1;
  1259. if (multi_len != 1)
  1260. {
  1261. len = mblen (ptr, MB_CUR_MAX);
  1262. size = _DtHelpFmtFindBreak(ptr, len, &numChars);
  1263. if (1 != len)
  1264. pSeg->type = _DtCvSetTypeToWideChar(pSeg->type);
  1265. }
  1266. else
  1267. size = strlen(ptr);
  1268. /*
  1269. * set the link flag
  1270. */
  1271. if (link_index != -1)
  1272. {
  1273. pSeg->type = _DtCvSetTypeToHyperText(pSeg->type);
  1274. pSeg->link_idx = link_index;
  1275. }
  1276. tmpChar = ptr[size];
  1277. ptr[size] = '\0';
  1278. /*
  1279. * save the string appropriately.
  1280. */
  1281. if (_DtCvIsSegWideChar(pSeg))
  1282. {
  1283. wchar_t *pwcs;
  1284. size_t convSize;
  1285. /*
  1286. * include the terminating byte in the conversion.
  1287. */
  1288. numChars++;
  1289. /*
  1290. * malloc the memory
  1291. */
  1292. pwcs = (wchar_t *) malloc(sizeof(wchar_t) * numChars);
  1293. if (NULL != pwcs)
  1294. {
  1295. /* convert */
  1296. convSize = mbstowcs(pwcs, string, ((size_t) numChars));
  1297. /* check to see if it converted everything */
  1298. if (convSize + 1 == numChars)
  1299. _DtCvStringOfStringSeg(pSeg) = (void *) pwcs;
  1300. else
  1301. free(pwcs);
  1302. }
  1303. }
  1304. else
  1305. _DtCvStringOfStringSeg(pSeg) = (void *) strdup(string);
  1306. if (NULL == _DtCvStringOfStringSeg(pSeg))
  1307. return -1;
  1308. /*
  1309. * set the font
  1310. */
  1311. _DtCvFontOfStringSeg(pSeg) = useFont;
  1312. /*
  1313. * setup the list pointers
  1314. */
  1315. if (*prev_seg != NULL)
  1316. (*prev_seg)->next_disp = pSeg;
  1317. *prev_seg = pSeg;
  1318. _DtHelpCeAddSegToList(pSeg, seg_list, last_seg);
  1319. ptr[size] = tmpChar;
  1320. ptr += size;
  1321. string = ptr;
  1322. }
  1323. }
  1324. if (newline == True)
  1325. {
  1326. pSeg->type = _DtCvSetTypeToNewLine(pSeg->type);
  1327. if (addToList == True)
  1328. {
  1329. if (*prev_seg != NULL)
  1330. (*prev_seg)->next_disp = pSeg;
  1331. *prev_seg = pSeg;
  1332. _DtHelpCeAddSegToList(pSeg, seg_list, last_seg);
  1333. }
  1334. }
  1335. return 0;
  1336. }
  1337. /******************************************************************************
  1338. * Function: _DtCvSegment *_DtHelpCeMatchSemanticStyle (CESDLSegment *toss,
  1339. * enum SDLClass clan,
  1340. * char *ssi);
  1341. * Parameters:
  1342. *
  1343. * Returns: Nothing.
  1344. *
  1345. *****************************************************************************/
  1346. _DtCvSegment *
  1347. _DtHelpCeMatchSemanticStyle (
  1348. _DtCvSegment *toss,
  1349. SdlOption clan,
  1350. int level,
  1351. char *ssi)
  1352. {
  1353. _DtCvSegment *pSeg;
  1354. SDLTossInfo *pEl;
  1355. const ClassStyleMatrix *pClassStyle;
  1356. /*
  1357. * initalize the starting style.
  1358. */
  1359. pSeg = toss;
  1360. pClassStyle = ClassToStyle;
  1361. do
  1362. {
  1363. /*
  1364. * figure out which element style this class is associated with
  1365. */
  1366. while (pClassStyle->start != SdlOptionBad &&
  1367. !(pClassStyle->start <= clan && clan <= pClassStyle->end))
  1368. pClassStyle++;
  1369. if (pClassStyle->start != SdlOptionBad)
  1370. {
  1371. /*
  1372. * skip those not matching the style this class belongs to.
  1373. * But don't go past the ones after, because they might match
  1374. * too.
  1375. */
  1376. while (pSeg != NULL &&
  1377. _SdlSegPtrToTossType(pSeg) != pClassStyle->style &&
  1378. _SdlSegPtrToTossType(pSeg) != pClassStyle[1].style)
  1379. pSeg = pSeg->next_seg;
  1380. /*
  1381. * the class matches the style, look for a specific class, ssi and
  1382. * level match.
  1383. */
  1384. while (pSeg != NULL &&
  1385. _SdlSegPtrToTossType(pSeg) == pClassStyle->style)
  1386. {
  1387. pEl = _SdlSegPtrToTossInfo(pSeg);
  1388. if (_SdlTossInfoPtrClan(pEl) == clan &&
  1389. (_SdlTossInfoPtrRlevel(pEl) == -1 ||
  1390. _SdlTossInfoPtrRlevel(pEl) == level) &&
  1391. (_SdlTossInfoPtrSsi(pEl) == NULL ||
  1392. (ssi != NULL &&
  1393. _DtHelpCeStrCaseCmp(_SdlTossInfoPtrSsi(pEl), ssi) == 0)))
  1394. return pSeg;
  1395. /*
  1396. * skip to the next element
  1397. */
  1398. pSeg = pSeg->next_seg;
  1399. }
  1400. /*
  1401. * went through those styles, try more
  1402. */
  1403. pClassStyle++;
  1404. }
  1405. } while (pClassStyle->start != SdlOptionBad);
  1406. return NULL;
  1407. }
  1408. /******************************************************************************
  1409. * Function: int _DtHelpCeAllocateFontStruct (int num, _DtHelpFontHints *ret_ptr)
  1410. *
  1411. * Parameters:
  1412. *
  1413. * Returns ptr to the allocated structure.
  1414. *
  1415. * errno Values:
  1416. *
  1417. * Purpose: Allocate the number of structure specified
  1418. *
  1419. *****************************************************************************/
  1420. int
  1421. _DtHelpCeAllocateFontStruct (
  1422. int size,
  1423. _DtHelpFontHints **ret_ptr)
  1424. {
  1425. _DtHelpFontHints *font;
  1426. font = (_DtHelpFontHints *) malloc (sizeof (_DtHelpFontHints) * size);
  1427. if (NULL == font)
  1428. return -1;
  1429. *ret_ptr = font;
  1430. return 0;
  1431. }