2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: UtilSDL.c /main/10 1996/08/30 13:43:15 cde-hp $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 ** Project: Cde Help System
31 ** Description: Utility functions for parsing an SDL volume.
33 ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
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.
40 ****************************************************************************
41 ************************************<+>*************************************/
54 * Canvas Engine includes
57 #include "CanvasSegP.h"
63 #include "FontAttrI.h"
64 #include "AccessSDLP.h"
65 #include "CanvasError.h"
67 #include "FormatUtilI.h"
69 #include "FormatSDLI.h"
70 #include "StringFuncsI.h"
76 /******** Private Function Declarations ********/
77 /******** End Private Function Declarations ********/
79 /******************************************************************************
83 *****************************************************************************/
101 #define MAX_ELEMENT_SIZE 30
103 typedef struct _classStyleMatrix
107 enum SdlElement style;
110 /******************************************************************************
114 *****************************************************************************/
115 #define IsWhiteSpace(x) \
116 (((x) == '\n' || (x) == ' ' || (x) == '\t') ? 1 : 0)
118 #define IsNumber(x) \
119 (((x) >= '0' && (x) <= '9') ? 1 : 0)
121 /******************************************************************************
125 *****************************************************************************/
126 static ClassStyleMatrix ClassToStyle[] =
128 { SdlClassAcro , SdlClassUdefkey , SdlElementKeyStyle },
129 { SdlClassLabel , SdlClassUdefhead , SdlElementHeadStyle },
130 { SdlClassTable , SdlClassUdeffrmt , SdlElementFormStyle },
131 { SdlClassTable , SdlClassUdeffrmt , SdlElementFrmtStyle },
132 { SdlClassFigure, SdlClassUdefgraph, SdlElementGrphStyle },
133 { SdlOptionBad , SdlOptionBad , SdlElementNone },
136 /******************************************************************************
140 *****************************************************************************/
141 /******************************************************************************
142 * Function: static int SkipWhiteSpace (BufFilePtr f)
146 * Returns 0 if successfully skipped white space.
153 *****************************************************************************/
165 } while (IsWhiteSpace(c));
167 BufFilePutBack(c, f);
173 /******************************************************************************
174 * Function: static int CheckSDLAttributeNameStart (char c)
178 * Returns 0 if starts correctly,
179 * -1 if does not start correctly for an attribute name
185 *****************************************************************************/
187 CheckSDLAttributeNameStart (char c)
189 if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
195 /******************************************************************************
196 * Function: int GetSDLElement (BufFilePtr f, char **string)
200 * Returns 0 if got an element (subject to verification).
201 * 1 if end of file/compressed section.
206 * Memory owned: the returned string.
210 *****************************************************************************/
217 _DtCvValue done = False;
218 _DtCvValue first = True;
219 _DtCvValue nonWhite = False;
220 _DtCvValue startEl = False;
228 * [chars][space] (nonWhite == True && IsWhiteSpace(c))
229 * <element> (startEl == True && c == '>')
230 * [chars]<element.. (first == False && c == '<')
232 if (c == BUFFILEEOF || (nonWhite == True && IsWhiteSpace(c))
233 || (startEl == True && c == '>')
234 || (first == False && c == '<'))
236 if (c == '>' || c == '<' || (nonWhite == True && IsWhiteSpace(c)))
242 if (first == True && c == '<')
246 if (nonWhite == False && IsWhiteSpace(c) == False)
251 if (len >= max_allowed)
263 else /* if (c == BUFFILEEOF) */
270 /******************************************************************************
272 * Semi Public Functions
274 *****************************************************************************/
275 /******************************************************************************
276 * Function: int _DtHelpCeMatchSdlElement (BufFilePtr my_file,
277 * const char *element_str, int sig_chars)
281 * Returns 0 if successfully matched element_str,
282 * 1 if did not match,
289 *****************************************************************************/
291 _DtHelpCeMatchSdlElement (
293 const char *element_str,
297 int different = False;
298 char nextEl[MAX_ELEMENT_SIZE + 2];
303 * get the next element in the stream
306 if (GetSDLElement(f, MAX_ELEMENT_SIZE, nextEl) != 0)
310 * now skip the white space
313 while (IsWhiteSpace(*ptr)) ptr++;
315 } while (*ptr == '\0');
317 len = strlen(element_str);
321 * get the lowered version of the character
323 c = _DtHelpCeToLower(*ptr);
324 if (c != *element_str)
332 } while (len && sig_chars && !different && *ptr != '\0');
334 if (!different && sig_chars > 0 && len > 0)
340 /******************************************************************************
341 * Function: int _DtHelpCeGetSdlAttribute (BufFilePtr f,
342 * char *attribute_name)
345 * f Specifies the buf file to read.
346 * max_len Specifies the maximum number of characters
347 * that can fit in 'attribute_name'. Does
348 * *NOT* include the terminating null byte.
349 * attribute_name Specifies the buffer in which to place
353 * Returns 0 if successfully retrieved an attribute name.
354 * 1 if there is no more attributes (eats the element end).
359 * Purpose: Reads the an attribute.
360 * Lower cases the attribute.
362 *****************************************************************************/
364 _DtHelpCeGetSdlAttribute (
367 char *attribute_name)
372 if (SkipWhiteSpace(f) != 0)
376 * check that the attribute name starts correctly
382 if (CheckSDLAttributeNameStart(c) != 0)
386 c = _DtHelpCeToLower(c);
388 attribute_name[len++] = c;
392 } while (c != BUFFILEEOF && !IsWhiteSpace(c) && c != '=' && len < max_len);
401 if (len == 0 || len >= max_len)
404 attribute_name[len] = '\0';
409 /******************************************************************************
410 * Function: int _DtHelpCeReturnSdlElement ()
415 * Returns 0 if matched an element in the list
416 * 1 hit eof on the file/compressed section.
423 * Memory Owned By Caller: number_str
425 *****************************************************************************/
427 _DtHelpCeReturnSdlElement (
429 const SDLElementInfo *el_list,
430 _DtCvValue cdata_flag,
431 enum SdlElement *ret_el_define,
433 _DtCvValue *ret_end_flag)
437 _DtCvValue endFlag = False;
438 _DtCvValue different = True;
439 char nextEl[MAX_ELEMENT_SIZE + 2];
442 *ret_el_define = SdlElementCdata;
443 *ret_end_flag = False;
448 * get the next element
451 result = GetSDLElement(f, MAX_ELEMENT_SIZE, nextEl);
454 *ret_el_define = SdlElementNone;
457 else if (result == -1)
461 * lower case the element. String dup it first incase this is data
462 * and not an element. Then skip the leading white space.
465 while (IsWhiteSpace(*ptr) == True) ptr++;
466 } while (cdata_flag == False && *ptr == '\0');
469 * An element starts with a less than sign,
470 * An end element starts with a less than sign and a forward slash.
474 * if all we've got is white space, or a non starting character,
480 * skip the less than sign.
485 * is this an end element?
493 lowerChar = (int) _DtHelpCeToLower(*ptr);
495 while (different && el_list->element_str != NULL)
497 if (endFlag == True && el_list->element_end_str != NULL &&
498 lowerChar == ((int)(el_list->element_end_str[2])) &&
499 _DtHelpCeStrNCaseCmpLatin1(&(el_list->element_end_str[2]),
500 ptr, el_list->end_sig_chars - 2) == 0)
503 *ret_end_flag = True;
505 else if (endFlag == False &&
506 lowerChar == ((int)(el_list->element_str[1])) &&
507 _DtHelpCeStrNCaseCmpLatin1(&(el_list->element_str[1]), ptr,
508 el_list->str_sig_chars - 1) == 0)
513 *ret_el_define = el_list->sdl_element;
516 if (*ret_el_define == SdlElementCdata && ret_data != NULL)
517 *ret_data = strdup(nextEl);
522 /******************************************************************************
523 * Function: int _DtHelpCeGetSdlCdata (BufFilePtr f, char **string)
528 * Returns 0 if successfully retrieved data.
529 * 1 if returning because type != SdlTypeDynamic and a newline
531 * 2 if returning because ran into a non-breaking character.
538 * Memory Owned By Caller: attribute_name
540 *****************************************************************************/
542 _DtHelpCeGetSdlCdata (
546 _DtCvValue nl_to_space,
547 _DtCvValue *cur_space,
550 char *non_break_char,
554 _DtCvValue lastWasSpace = *cur_space;
555 _DtCvValue lastWasNl = *cur_nl;
556 _DtCvValue lastWasMb = *cur_mb;
557 _DtCvValue ignore = False;
558 _DtCvValue done = False;
559 _DtCvValue escaped = False;
565 char buf[MB_LEN_MAX + 1];
566 #define ESC_STR_LEN 4
567 char escStr[ESC_STR_LEN];
572 else if (*string != NULL)
574 strSize = strlen(*string);
575 if (*str_max < strSize)
585 if (c != BUFFILEEOF && max_mb != 1)
586 strMB = mblen(buf, max_mb);
588 if (c == BUFFILEEOF || (escaped == False && strMB == 1 &&
590 ((type == SdlTypeLiteral || type == SdlTypeLined) &&
604 if (lastWasNl == True)
607 if (_DtHelpCeAddCharToBuf(&ptr, string, &strSize,
621 * process the SGML numeric character reference
622 * entity. '&#d[d[d]][;]' - 'ddd' represent
623 * characters of '0' to '9'. The semi-colon is
624 * required iff the next character is a numeric
625 * character of '0' to '9'. Otherwise it is
630 len = 0; /* len should be zero here, but let's make sure */
634 * get the next character.
639 * if it is the first character of the numeric entity,
640 * it has to be a numeric character.
642 if (c == BUFFILEEOF ||
643 (len == 0 && (c < '0' || c > '9')))
647 * put the character in the buffer
651 } while (len < ESC_STR_LEN && c >= '0' && c <= '9');
654 * the ending character of the entity has to be a
655 * non-numeric character.
657 if (c >= '0' && c <= '9')
660 * if the optional semi-colon is not present, replace
661 * the terminating character back in the input buffer
662 * to be processed in the next pass.
665 BufFilePutBack(c, f);
668 * get the integer value. It has to be less than 256.
670 value = atoi(escStr);
675 * transfer the value to the character variable
676 * and zero the index for the general buffer.
682 * set up for the return information
690 * clear the escaped flag, so that the character gets
691 * put in the output buffer.
697 if (type == SdlTypeCdata)
698 lastWasSpace = False;
699 else if (lastWasSpace == False)
706 if (escaped == False && ignore == False)
719 * as long as we aren't processing a non break character,
720 * add it to the buffer.
722 else if (2 != reason)
725 lastWasSpace = False;
727 if ((lastWasSpace == False || type == SdlTypeLiteral ||
728 type == SdlTypeUnlinedLiteral)
730 _DtHelpCeAddCharToBuf(&ptr, string, &strSize,
734 if (type != SdlTypeLiteral &&
735 type != SdlTypeUnlinedLiteral && c == ' ')
744 if (lastWasNl == True)
746 if (nl_to_space == True || lastWasMb == False)
749 if (_DtHelpCeAddCharToBuf(&ptr, string, &strSize,
756 if (_DtHelpCeAddStrToBuf(&ptr,string,&strSize,str_max,len,32)
762 lastWasSpace = False;
766 else if (strMB == 0 || len > max_mb || len >= MB_LEN_MAX)
769 } while (done == False);
771 *cur_space = lastWasSpace;
777 /******************************************************************************
778 * Function: int _DtHelpCeGetSdlAttributeCdata (BufFilePtr f, char **string);
783 * Returns 0 if successfully retrieved an attribute name.
788 * Purpose: Parses the CDATA value for an element attribute. Expects the
789 * pointer to be after the equals sign of the attribute. The
790 * CDATA must be included in quotes (either single or double)
791 * and can have white space (spaces, newlines or tabs) preceding
792 * it. Any newline encountered within the CDATA value is turned
793 * into a space. Any quote enclosed in the CDATA must not be the
794 * same type as what is used to delimit the CDATA value. I.E.
795 * if a single quote is used in the CDATA, the CDATA value must
796 * be enclosed in double quotes.
798 * Memory Owned By Caller: attribute_name
800 *****************************************************************************/
802 _DtHelpCeGetSdlAttributeCdata (
807 _DtCvValue ignore = False;
808 _DtCvValue done = False;
809 _DtCvValue firstChar = True;
818 else if (limit == True)
821 if (SkipWhiteSpace(f) != 0)
835 if (c == '\'' || c == '\"')
847 else if (c == testChar)
849 else if (ignore == False)
854 if (limit == True && strSize >= DTD_NAMELEN)
860 else if (limit == False && strSize >= strMax)
864 myStr = (char *) malloc (sizeof(char) * 65);
866 myStr = (char *) realloc (myStr,(sizeof(char)*(strMax+1)));
872 myStr[strSize++] = c;
874 } while (done == False);
879 myStr[strSize] = '\0';
887 /******************************************************************************
888 * Function: int _DtHelpCeSkipCdata (BufFilePtr f, _DtCvValue Flag)
893 * Returns 0 if successfully retrieved an attribute name.
900 * Memory Owned By Caller: attribute_name
902 *****************************************************************************/
908 _DtCvValue done = False;
909 _DtCvValue singleQuote = False;
910 _DtCvValue doubleQuote = False;
911 _DtCvValue comment = False;
912 _DtCvValue element = False;
913 _DtCvValue bracket = False;
914 _DtCvValue processing = True;
948 else if (!element && c == '<')
961 else if (flag && c == '[')
964 else if (bracket && c == ']')
972 if (singleQuote && c == '\'')
977 else if (doubleQuote && c == '\"')
982 else if (comment && c == '-')
997 } while (done == False);
1005 /******************************************************************************
1006 * Function: int _DtHelpCeGetSdlId (BufFilePtr f, char **id_value)
1011 * Returns 0 if successfully retrieved an attribute name.
1018 * Memory Owned By Caller: id_value
1020 *****************************************************************************/
1028 if (_DtHelpCeGetSdlAttributeCdata (f, False, id_value) != 0)
1032 * check that the attribute name starts correctly
1034 if (CheckSDLAttributeNameStart(**id_value) != 0)
1040 /******************************************************************************
1041 * Function: int _DtHelpCeGetSdlNumber (BufFilePtr f, char **number_str)
1046 * Returns 0 if successfully retrieved an attribute name.
1053 * Memory Owned By Caller: number_str
1055 *****************************************************************************/
1057 _DtHelpCeGetSdlNumber (
1061 if (_DtHelpCeGetSdlAttributeCdata(f, True, &number_str) != 0)
1065 * check that the attribute name starts correctly
1067 if (!IsNumber(*number_str))
1073 /******************************************************************************
1074 * Function: int _DtHelpCeFindSkipSdlElementEnd (BufFilePtr f)
1079 * Returns 0 if successfully retrieved an attribute name.
1086 * Memory Owned By Caller: attribute_name
1088 *****************************************************************************/
1090 _DtHelpCeFindSkipSdlElementEnd (
1095 if (SkipWhiteSpace(f) != 0)
1100 if (c == BUFFILEEOF)
1108 /******************************************************************************
1109 * Function: int _DtHelpCeMergeSdlAttribInfo (_DtCanvasStruct canvas,
1110 * _DtCvSegment *src_el,
1111 * _DtCvSegment *dst_el);
1117 * Purpose: Merge the src specified attributes into the dst.
1118 * THIS WILL NOT MERGE THE SSI or RSSI values.
1120 ******************************************************************************/
1122 _DtHelpCeMergeSdlAttribInfo(
1123 _DtCvSegment *src_seg,
1124 _DtCvSegment *dst_seg,
1125 _DtHelpFontHints *dst_fonts,
1127 unsigned long *str1_values,
1128 unsigned long *str2_values)
1131 const SDLAttribute *pAttr;
1138 SDLTossInfo *tossInfo;
1142 if (src_seg != NULL)
1144 tossInfo = _SdlSegPtrToTossInfo(src_seg);
1145 for (pAttr = _DtHelpCeGetSdlAttributeList();
1146 pAttr->data_type != SdlAttrDataTypeInvalid; pAttr++)
1148 if ((pAttr->struct_type == SdlFontSpecific ||
1149 pAttr->struct_type == SdlContainerSpecific)
1151 SDLIsAttrSet(*tossInfo, pAttr->sdl_attr_define)
1153 !(ATTRS_EQUAL(pAttr->data_type, pAttr->sdl_attr_define,
1155 ATTRS_EQUAL(pAttr->data_type, pAttr->sdl_attr_define,
1158 if (pAttr->struct_type == SdlFontSpecific)
1160 src = ((char *)(&(_SdlTossInfoPtrFontSpecs(tossInfo))));
1161 dst = ((char *) dst_fonts);
1163 else /* if (pAttr->struct_type == SdlContainerSpecific) */
1165 src = ((char *)_SdlContainerPtrOfSeg(src_seg));
1166 dst = ((char *)_SdlContainerPtrOfSeg(dst_seg));
1169 switch (SDLAttrFlagType(pAttr->sdl_attr_define))
1172 dstEnum = (SdlOption *)
1173 (((char *)dst) + pAttr->field_ptr);
1174 srcEnum = (SdlOption *)
1175 (((char *)src) + pAttr->field_ptr);
1176 *dstEnum = *srcEnum;
1180 dstNum = (SDLNumber *)
1181 (((char *)dst) + pAttr->field_ptr);
1182 srcNum = (SDLNumber *)
1183 (((char *)src) + pAttr->field_ptr);
1189 dstStr = (SDLCdata *)
1190 (((char *)dst) + pAttr->field_ptr);
1191 srcStr = (SDLCdata *)
1192 (((char *)src) + pAttr->field_ptr);
1198 else if (NULL != el_info &&
1199 pAttr->struct_type == SdlElementSpecific &&
1200 SDLIsAttrSet(*tossInfo, pAttr->sdl_attr_define))
1202 flag = pAttr->sdl_attr_define & ~(VALUE_MASK);
1204 dstStr = (SDLCdata *)(((char *)el_info) + pAttr->field_ptr);
1205 if (SDL_ATTR_COLW == pAttr->sdl_attr_define)
1206 *dstStr = _SdlTossInfoPtrColW(tossInfo);
1207 else if (SDL_ATTR_COLJ == pAttr->sdl_attr_define)
1208 *dstStr = _SdlTossInfoPtrColJ(tossInfo);
1209 else if (SDL_ATTR_ENTER == pAttr->sdl_attr_define)
1210 *dstStr = _SdlTossInfoPtrEnter(tossInfo);
1211 else if (SDL_ATTR_EXIT == pAttr->sdl_attr_define)
1212 *dstStr = _SdlTossInfoPtrExit(tossInfo);
1214 if (STRING1_VALUE == (pAttr->sdl_attr_define & VALUE_MASK))
1215 *str1_values = *str1_values | flag;
1216 else if (STRING2_VALUE == (pAttr->sdl_attr_define & VALUE_MASK))
1217 *str2_values = *str2_values | flag;
1223 /******************************************************************************
1224 * Function: void _DtHelpCeAddSegToList (_DtCvSegment *seg_ptr,
1225 * _DtCvSegment **seg_list,
1226 * _DtCvSegment **last_seg)
1230 * Returns: 0 if successful, -1 if errors
1234 * Purpose: Allocates a memory
1236 ******************************************************************************/
1238 _DtHelpCeAddSegToList(
1239 _DtCvSegment *seg_ptr,
1240 _DtCvSegment **seg_list,
1241 _DtCvSegment **last_seg)
1243 if (*seg_list == NULL)
1244 *seg_list = seg_ptr;
1246 (*last_seg)->next_seg = seg_ptr;
1248 while (NULL != seg_ptr->next_seg)
1249 seg_ptr = seg_ptr->next_seg;
1251 *last_seg = seg_ptr;
1254 /******************************************************************************
1255 * Function: int _DtHelpCeAllocSegment (
1258 * _DtCvSegment **next_seg,
1259 * _DtCvSegment **seg_ptr);
1262 * malloc_size Specifies the number of blocks to
1263 * malloc. The first one is returned in
1264 * 'seg_ptr' with the rest in 'next_seg',
1265 * if 'next_seg' is non-NULL.
1266 * alloc_size Ignored if NULL. If non-NULL, indicates
1267 * the number of blocks in 'next_seg' if
1268 * 'next_seg' is non-NULL and the 'next_seg'
1269 * pointer is non-NULL.
1270 * next_seg Specifies the block of memory to take the
1271 * next segment from.
1272 * Returns the pointer to the next segment.
1273 * seg_ptr Returns a pointer to the segment to use.
1275 * Returns: 0 if successful, -1 if errors
1277 * Purpose: Allocates a memory
1279 ******************************************************************************/
1281 _DtHelpCeAllocSegment(
1284 _DtCvSegment **next_seg,
1285 _DtCvSegment **seg_ptr)
1288 _DtCvSegment *newSeg = NULL;
1290 if (next_seg != NULL)
1293 if (alloc_size != NULL && newSeg != NULL)
1298 newSeg = _DtHelpAllocateSegments(malloc_size);
1302 cnt = --malloc_size;
1307 *seg_ptr = newSeg++;
1308 if (next_seg != NULL)
1314 if (alloc_size != NULL)
1320 /******************************************************************************
1321 * Function: int _DtHelpCeSaveString (
1322 * string, multi_len)
1326 * Returns: 0 if successful, -1 if errors
1330 * Purpose: Looks for the virtual page beginning.
1332 ******************************************************************************/
1334 _DtHelpCeSaveString(
1335 _DtCvPointer client_data,
1336 _DtCvSegment **seg_list,
1337 _DtCvSegment **last_seg,
1338 _DtCvSegment **prev_seg,
1340 _DtHelpFontHints *font_specs,
1344 void (*load_font)(),
1345 _SdlFontMode resolve_font,
1355 _DtCvSegment *pSeg = NULL;
1356 _DtCvSegment *junkSeg = NULL;
1357 _DtHelpFontHints *fontSpec = NULL;
1358 _DtCvValue addToList = False;
1359 _DtCvPointer useFont = (_DtCvPointer) -1;
1363 if (newline == True)
1365 if (_DtHelpCeAllocSegment(1, &junk, &junkSeg, &pSeg) != 0)
1372 if (_SdlFontModeResolve == resolve_font)
1373 (*load_font)(client_data, _DtHelpFontHintsLang(*font_specs),
1374 _DtHelpFontHintsCharSet(*font_specs),
1375 *font_specs, &useFont);
1377 while (*ptr != '\0')
1379 if (_DtHelpCeAllocSegment(1, &junk, &junkSeg, &pSeg) != 0)
1382 if (_SdlFontModeSave == resolve_font)
1384 fontSpec = (_DtHelpFontHints *) malloc (sizeof(_DtHelpFontHints));
1385 if (NULL == fontSpec)
1392 * copy the current fonts over
1394 *fontSpec = *font_specs;
1395 useFont = (_DtCvPointer) fontSpec;
1401 pSeg->type = _DtCvSetTypeToString(flags);
1404 * set the wide char flag if necessary.
1409 len = mblen (ptr, MB_CUR_MAX);
1410 size = _DtHelpFmtFindBreak(ptr, len, &numChars);
1412 pSeg->type = _DtCvSetTypeToWideChar(pSeg->type);
1420 if (link_index != -1)
1422 pSeg->type = _DtCvSetTypeToHyperText(pSeg->type);
1423 pSeg->link_idx = link_index;
1426 tmpChar = ptr[size];
1430 * save the string appropriately.
1432 if (_DtCvIsSegWideChar(pSeg))
1438 * include the terminating byte in the conversion.
1445 pwcs = (wchar_t *) malloc(sizeof(wchar_t) * numChars);
1449 convSize = mbstowcs(pwcs, string, ((size_t) numChars));
1451 /* check to see if it converted everything */
1452 if (convSize + 1 == numChars)
1453 _DtCvStringOfStringSeg(pSeg) = (void *) pwcs;
1459 _DtCvStringOfStringSeg(pSeg) = (void *) strdup(string);
1461 if (NULL == _DtCvStringOfStringSeg(pSeg))
1467 _DtCvFontOfStringSeg(pSeg) = useFont;
1470 * setup the list pointers
1472 if (*prev_seg != NULL)
1473 (*prev_seg)->next_disp = pSeg;
1477 _DtHelpCeAddSegToList(pSeg, seg_list, last_seg);
1479 ptr[size] = tmpChar;
1485 if (newline == True)
1487 pSeg->type = _DtCvSetTypeToNewLine(pSeg->type);
1489 if (addToList == True)
1491 if (*prev_seg != NULL)
1492 (*prev_seg)->next_disp = pSeg;
1494 _DtHelpCeAddSegToList(pSeg, seg_list, last_seg);
1501 /******************************************************************************
1502 * Function: _DtCvSegment *_DtHelpCeMatchSemanticStyle (CESDLSegment *toss,
1503 * enum SDLClass clan,
1509 *****************************************************************************/
1511 _DtHelpCeMatchSemanticStyle (
1519 const ClassStyleMatrix *pClassStyle;
1522 * initalize the starting style.
1525 pClassStyle = ClassToStyle;
1530 * figure out which element style this class is associated with
1532 while (pClassStyle->start != SdlOptionBad &&
1533 !(pClassStyle->start <= clan && clan <= pClassStyle->end))
1536 if (pClassStyle->start != SdlOptionBad)
1539 * skip those not matching the style this class belongs to.
1540 * But don't go past the ones after, because they might match
1543 while (pSeg != NULL &&
1544 _SdlSegPtrToTossType(pSeg) != pClassStyle->style &&
1545 _SdlSegPtrToTossType(pSeg) != pClassStyle[1].style)
1546 pSeg = pSeg->next_seg;
1549 * the class matches the style, look for a specific class, ssi and
1552 while (pSeg != NULL &&
1553 _SdlSegPtrToTossType(pSeg) == pClassStyle->style)
1555 pEl = _SdlSegPtrToTossInfo(pSeg);
1556 if (_SdlTossInfoPtrClan(pEl) == clan &&
1557 (_SdlTossInfoPtrRlevel(pEl) == -1 ||
1558 _SdlTossInfoPtrRlevel(pEl) == level) &&
1559 (_SdlTossInfoPtrSsi(pEl) == NULL ||
1561 _DtHelpCeStrCaseCmp(_SdlTossInfoPtrSsi(pEl), ssi) == 0)))
1565 * skip to the next element
1567 pSeg = pSeg->next_seg;
1571 * went through those styles, try more
1575 } while (pClassStyle->start != SdlOptionBad);
1580 /******************************************************************************
1581 * Function: int _DtHelpCeAllocateFontStruct (int num, _DtHelpFontHints *ret_ptr)
1585 * Returns ptr to the allocated structure.
1589 * Purpose: Allocate the number of structure specified
1591 *****************************************************************************/
1593 _DtHelpCeAllocateFontStruct (
1595 _DtHelpFontHints **ret_ptr)
1597 _DtHelpFontHints *font;
1599 font = (_DtHelpFontHints *) malloc (sizeof (_DtHelpFontHints) * size);