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 librararies 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: CCDFUtil.c /main/7 1996/11/01 10:10:08 drk $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 ** Project: Un*x Desktop Help
32 ** Description: Semi private format utility functions for
36 ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
38 ** (c) Copyright 1993, 1994 Hewlett-Packard Company
39 ** (c) Copyright 1993, 1994 International Business Machines Corp.
40 ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
41 ** (c) Copyright 1993, 1994 Novell, Inc.
44 ****************************************************************************
45 ************************************<+>*************************************/
63 * Canvas Engine includes
71 #include "CanvasError.h"
72 #include "CCDFUtilI.h"
73 #include "FontAttrI.h"
74 #include "CvStringI.h"
75 #include "FormatUtilI.h"
76 #include "StringFuncsI.h"
81 /******** Private Function Declarations ********/
82 static int GetCmdData(
93 /******** End Private Function Declarations ********/
95 /******************************************************************************
97 * Private variables and defines.
99 *****************************************************************************/
101 #define REALLOC_INCR 10
102 #define CMD_NOT_ALLOWED -1000
110 static const FormatCmds CcdfFormatCmds[] =
112 { "abbrev" , CCDF_ABBREV_CMD , 2 },
113 { "angle" , CCDF_FONT_CMD , 2 },
114 { "characterset", CCDF_FONT_CMD , 1 },
115 { "figure" , CCDF_FIGURE_CMD , 1 },
116 { "graphic" , CCDF_GRAPHIC_CMD , 1 },
117 { "id" , CCDF_ID_CMD , 1 },
118 { "label" , CCDF_LABEL_CMD , 2 },
119 { "link" , CCDF_LINK_CMD , 2 },
120 { "newline" , CCDF_NEWLINE_CMD , 1 },
121 { "paragraph" , CCDF_PARAGRAPH_CMD, 1 },
122 { "size" , CCDF_FONT_CMD , 2 },
123 { "spacing" , CCDF_FONT_CMD , 2 },
124 { "title" , CCDF_TITLE_CMD , 2 },
125 { "topic" , CCDF_TOPIC_CMD , 2 },
126 { "type" , CCDF_FONT_CMD , 2 },
127 { "weight" , CCDF_FONT_CMD , 1 },
128 { "0x" , CCDF_OCTAL_CMD , 2 },
129 /* always leave this one as the last entry */
130 { "/" , CCDF_FORMAT_END , 1 }
133 /******************************************************************************
135 * Semi Public variables.
137 *****************************************************************************/
138 /******************************************************************************
142 *****************************************************************************/
143 /******************************************************************************
144 * Function: static int GetCmdData (FILE *in_file, char *in_buf, int in_size,
145 * char **in_ptr, int allowed, int strip,
146 * int *ret_size, int *ret_max, char **ret_string)
149 * in_file Specifies a stream to read from.
150 * in_buf Specifies the buffer where new information
152 * in_size Specifies the maximum size of 'in_buf'.
153 * in_ptr Specifies the pointer into 'in_buf' to
155 * Returns the new location in 'in_buf' to
156 * continue processing.
157 * allowed Specifies the formatting commands allowed
159 * strip Specifies the formatting commands to strip.
161 * ret_size Specifies the current size of
163 * Returns the new size of 'ret_string'.
164 * ret_max Specifies the current maximum size of
166 * Returns the new size of 'ret_string'.
167 * ret_string Returns the data found.
170 * Returns: 0 if successful, -1 if errors.
173 * read (2) Errors set via a read call.
180 * Purpose: Gets a string containing font change tags
182 * "data with font change tags </>"
184 *****************************************************************************/
202 char *myBufPtr = *in_ptr;
204 int skipString = False;
214 charSize = mblen(myBufPtr, cur_mb_len);
219 * Do we need to read more information?
221 if (((int) strlen (myBufPtr)) < 3 &&
222 _DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1)
229 * Go to the next character.
238 if (*myBufPtr == '/')
241 return _DtHelpCeGetCcdfEndMark (in_file, in_buf,
242 in_ptr, in_size,cur_mb_len);
245 fontType = _DtHelpCeGetCcdfFontType (myBufPtr);
248 switch (_DtCvToLower (*myBufPtr))
255 _DtHelpCeAddOctalToBuf (
257 ret_string, ret_size,
260 _DtHelpCeGetCcdfEndMark (in_file, in_buf,
261 &myBufPtr,in_size,cur_mb_len) == -1)
272 if (_DtCvToLower (*myBufPtr) == 'b')
274 if (CCDF_NOT_ALLOW_CMD (allowed,
277 errno = CMD_NOT_ALLOWED;
280 else if (CCDF_NOT_ALLOW_CMD (strip,
286 errno = CEErrorFormattingCmd;
297 if (CCDF_NOT_ALLOW_CMD (allowed,
300 errno = CMD_NOT_ALLOWED;
303 else if (CCDF_NOT_ALLOW_CMD (strip,
313 if (CCDF_NOT_ALLOW_CMD (allowed,
316 errno = CMD_NOT_ALLOWED;
320 if (_DtHelpCeGetCcdfEndMark (in_file, in_buf,
321 &myBufPtr,in_size,cur_mb_len) == -1)
331 if (CCDF_NOT_ALLOW_CMD (allowed,
334 errno = CMD_NOT_ALLOWED;
337 else if (CCDF_NOT_ALLOW_CMD (strip,
348 if (_DtCvToLower (*myBufPtr) == 'a')
350 if (CCDF_NOT_ALLOW_CMD (allowed,
353 errno = CMD_NOT_ALLOWED;
356 else if (CCDF_NOT_ALLOW_CMD (strip,
360 else if (_DtCvToLower (*myBufPtr) == 'i')
362 if (CCDF_NOT_ALLOW_CMD (allowed,
365 errno = CMD_NOT_ALLOWED;
368 else if (CCDF_NOT_ALLOW_CMD (strip,
374 errno = CEErrorFormattingCmd;
384 if (CCDF_NOT_ALLOW_CMD (allowed,
387 errno = CMD_NOT_ALLOWED;
391 if (_DtHelpCeGetCcdfEndMark (in_file, in_buf,
392 &myBufPtr,in_size,cur_mb_len) == -1)
402 if (CCDF_NOT_ALLOW_CMD (allowed,
405 errno = CMD_NOT_ALLOWED;
408 else if (CCDF_NOT_ALLOW_CMD (strip,
419 if (_DtCvToLower (*myBufPtr) == 'o')
421 if (CCDF_NOT_ALLOW_CMD (allowed,
424 errno = CMD_NOT_ALLOWED;
427 else if (CCDF_NOT_ALLOW_CMD (strip,
431 else if (_DtCvToLower (*myBufPtr) == 'i')
433 if (CCDF_NOT_ALLOW_CMD (allowed,
436 errno = CMD_NOT_ALLOWED;
439 else if (CCDF_NOT_ALLOW_CMD (strip,
445 errno = CEErrorFormattingCmd;
452 errno = CEErrorFormattingCmd;
456 else if (CCDF_NOT_ALLOW_CMD (allowed, CCDF_FONT_CMD))
458 errno = CMD_NOT_ALLOWED;
461 else if (CCDF_NOT_ALLOW_CMD (strip, CCDF_FONT_CMD))
467 * This is a <token>....</token> construct.
468 * pass over the <token> part.
470 if (_DtHelpCeGetCcdfEndMark (in_file, in_buf,
471 &myBufPtr, in_size,cur_mb_len) == -1 ||
472 GetCmdData (in_file, in_buf, in_size,
473 &myBufPtr, cur_mb_len, allowed, strip,
474 ret_size, ret_max, ret_string) == -1)
482 * Put a space in the segment
487 result = _DtHelpCeAddCharToBuf (&tmpPtr,
488 ret_string, ret_size, ret_max, MIN_GROW);
497 * Save the escaped character
500 result = _DtHelpCeAddCharToBuf (&myBufPtr,
501 ret_string, ret_size, ret_max, MIN_GROW);
508 * Put the information in the buffer
510 result = _DtHelpCeStrcspn (myBufPtr, "<\\\n ",
513 * If _DtHelpCeStrcspn found an invalid character
514 * we don't want to quit yet. Allow another pass
515 * to try to read another buffer of information.
519 if (!skipString && size)
520 result = _DtHelpCeAddStrToBuf (&myBufPtr,
521 ret_string, ret_size, ret_max, size, 0);
526 else if (charSize > 1)
528 result = _DtHelpCeStrcspn (myBufPtr, "<\\\n ", cur_mb_len, &size);
531 * If _DtHelpCeStrcspn found an invalid character
532 * we don't want to quit yet. Allow another pass
533 * to try to read another buffer of information.
537 if (!skipString && size)
538 result = _DtHelpCeAddStrToBuf (&myBufPtr,
539 ret_string, ret_size, ret_max, size, 0);
543 else /* if (charSize < 1) */
545 if (*myBufPtr == '\0' || ((int) strlen (in_buf)) < cur_mb_len)
546 result = _DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size);
549 errno = CEErrorIllegalInfo;
557 /******************************************************************************
558 * Function: int GetTitleCmd (FILE *in_file, char in_buf, int in_size,
559 * char **in_ptr, char **ret_string)
562 * in_file Specifies a stream to read from.
563 * in_buf Specifies the buffer where new information
565 * in_size Specifies the maximum size of 'in_buf'.
566 * in_ptr Specifies the pointer into 'in_buf' to
568 * Returns the new location in 'in_buf' to
569 * continue processing.
570 * ret_string Returns the data found.
572 * Returns: 0 if successful, -1 if errors
575 * read (2) Errors set via a read call.
580 * Purpose: Determine if the next formatting command is
582 * Returns the data found between <ABBREV> and its ending </>.
584 * Note: The only formatting command allowed between <ABBREV> and
585 * its </> is the <NEWLINE> command. And it is stripped.
587 *****************************************************************************/
602 * null the return string
608 * check for the token
610 result = _DtHelpCeCheckNextCcdfCmd ("ti", in_file, in_buf, in_size, cur_mb_len, in_ptr);
614 errno = CEErrorMissingTitleCmd;
618 if (_DtHelpCeGetCcdfEndMark(in_file,in_buf,in_ptr,in_size,cur_mb_len) != 0)
621 result = GetCmdData (in_file, in_buf, in_size, in_ptr, cur_mb_len,
622 (CCDF_NEWLINE_CMD | CCDF_GRAPHIC_CMD |
623 CCDF_LINK_CMD | CCDF_FONT_CMD | CCDF_ID_CMD),
624 (CCDF_NEWLINE_CMD | CCDF_GRAPHIC_CMD |
625 CCDF_LINK_CMD | CCDF_FONT_CMD | CCDF_ID_CMD),
626 &junkSize, &junkMax, ret_string);
628 if (result == -1 && errno == CMD_NOT_ALLOWED)
629 errno = CEErrorTitleSyntax;
634 /******************************************************************************
636 * Semi Public Functions
638 *****************************************************************************/
639 /******************************************************************************
640 * Function: int _DtHelpCeGetCcdfEndMark (FILE *file, char *buffer,
641 * char **buf_ptr, int buf_size, int flag)
644 * file Specifies a stream to read from.
645 * buffer Specifies the buffer where new information
647 * buf_ptr Specifies the pointer into 'buffer' to
649 * Returns the new location in 'buffer' to
650 * continue processing.
651 * buf_size Specifies the maximum size of 'buffer'.
654 * Return Value: 0 if successful, -1 if a failure occurs
657 * read (2) Errors set via a read call.
662 * Purpose: Find the end of tag marker '>'.
664 ******************************************************************************/
666 _DtHelpCeGetCcdfEndMark (
682 * Find the end of marker or end of topic
684 result = _DtHelpCeStrcspn (ptr, "\\>", cur_mb_len, &len);
690 * found either a backslash or the end marker,
691 * update the pointer and if it was the '>'
700 else /* result == -1 || result == 1 */
703 * nothing here - get the next buffer and keep looking
704 * unless getting the next buffer has problems/eof
706 if (((int) strlen(ptr)) >= cur_mb_len)
708 errno = CEErrorIllegalInfo;
712 if (_DtHelpCeGetNxtBuf (file, buffer, &ptr, buf_size) == -1)
721 /******************************************************************************
722 * Function: int _DtHelpCeGetCcdfStrParam (FILE *in_file, char *in_buf,
723 * int in_size, char **in_ptr, int flag,
724 * int eat_escape, Boolean ignore_quotes,
725 * int less_test, char **ret_string)
728 * in_file Specifies a stream to read from.
729 * in_buf Specifies the buffer where new information
731 * in_size Specifies the maximum size of 'in_buf'.
732 * in_ptr Specifies the pointer into 'in_buf' to
734 * Returns the new location in 'in_buf' to
735 * continue processing.
736 * flag Specifies whether the routine returns
737 * a -1 if '>' is the next token.
738 * eat_secape Specifies whether the backslash is not
739 * placed in the returned string.
740 * True - it is skipped.
741 * False - it is saved in 'ret_string'.
742 * ignore_quotes Specifies whether quotes are to be included
743 * in the returned string.
744 * less_test Specifies whether the routine should
745 * stop when it finds a '<' character.
746 * ret_string If NULL, throws the information away.
747 * Otherwise, returns the string found.
749 * Returns: 0 if successful, -1 if errors, 1 if 'flag' is false and
750 * the next token is '>'.
753 * read (2) Errors set via a read call.
759 * Purpose: Skip the rest of the current token.
760 * Get the next token. A token is defined as being one or
761 * more strings between single or double quotes,
762 * or a string bounded by spaces or ended by the
765 *****************************************************************************/
767 _DtHelpCeGetCcdfStrParam(
774 _DtCvValue eat_escape,
775 _DtCvValue ignore_quotes,
776 _DtCvValue less_test,
784 char *stringPtr = NULL;
788 int singleQuotes = False;
789 int doubleQuotes = False;
790 int skipString = False;
797 * do we want to skip the string or read it.
803 * skip to the next parameter or > character. If flag is true,
804 * we want another parameter, so error if the > character is found.
806 if (_DtHelpCeSkipToNextCcdfToken (in_file, in_buf, in_size, cur_mb_len, in_ptr, flag) != 0)
812 * see if there is another parameter
814 if (_DtCvFALSE == flag && *myBufPtr == '>')
818 * Initialize the global buffer.
820 if (_DtCvFALSE == ignore_quotes &&
821 (!testMB || mblen (myBufPtr, cur_mb_len) == 1))
823 if (*myBufPtr == '\"')
828 else if (*myBufPtr == '\'')
837 spnResult = _DtHelpCeStrcspn (myBufPtr, " <>\'\"\\\n",
838 cur_mb_len, ©Size);
840 * Either skip the string or place it in storage
843 myBufPtr += copySize;
844 else if (_DtHelpCeAddStrToBuf (&myBufPtr, &stringPtr, &stringSize,
845 &stringMax, copySize, 0) == -1)
849 * If spnResult is non-zero, read the next buffer of information
853 if (spnResult == -1 && ((int)strlen(myBufPtr)) >= cur_mb_len)
855 errno = CEErrorIllegalInfo;
859 if (_DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1)
864 * Otherwise _DtHelpCeStrcspn stopped at a character we want
871 if (_DtCvTRUE == eat_escape || skipString)
873 else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
874 &stringSize, &stringMax, MIN_GROW) == -1)
877 if (*myBufPtr == '\0' && _DtHelpCeGetNxtBuf(in_file,
878 in_buf,&myBufPtr,in_size) == -1)
883 else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
884 &stringSize, &stringMax, MIN_GROW) == -1)
889 if (!doubleQuotes && !singleQuotes)
896 if (_DtHelpCeAddCharToBuf (&mySpace, &stringPtr,
897 &stringSize, &stringMax, MIN_GROW) == -1)
903 if (_DtCvTRUE == less_test)
907 else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
908 &stringSize, &stringMax, MIN_GROW) == -1)
914 if (!doubleQuotes && !singleQuotes)
918 else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
919 &stringSize, &stringMax, MIN_GROW) == -1)
924 if (_DtCvFALSE == ignore_quotes && singleQuotes)
928 else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
929 &stringSize, &stringMax, MIN_GROW) == -1)
934 if (_DtCvFALSE == ignore_quotes && doubleQuotes)
938 else if (_DtHelpCeAddCharToBuf (&myBufPtr, &stringPtr,
939 &stringSize, &stringMax, MIN_GROW) == -1)
953 *ret_string = stringPtr;
958 } /* End _DtHelpCeGetCcdfStrParam */
960 /******************************************************************************
961 * Function: int _DtHelpCeGetCcdfValueParam (FILE *in_file, char *in_buf,
962 * int in_size, char **in_ptr,
963 * int flag, int *ret_value)
966 * in_file Specifies a stream to read from.
967 * in_buf Specifies the buffer where new information
969 * in_size Specifies the maximum size of 'in_buf'.
970 * in_ptr Specifies the pointer into 'in_buf' to
972 * Returns the new location in 'in_buf' to
973 * continue processing.
974 * flag Specifies whether the routine returns
975 * a -2 if '>' is the next token.
976 * ret_value Returns the atoi conversion
977 * of the string found.
979 * Returns: 0 if successful, -1 if errors, -2 if 'flag' is True and
980 * the next token is '>'.
983 * read (2) Errors set via a read call.
987 * CEErrorFormattingValue
990 * Purpose: Get then next numeric parameter.
992 *****************************************************************************/
994 _DtHelpCeGetCcdfValueParam(
1005 char *stringPtr = NULL;
1012 if (_DtHelpCeSkipToNextCcdfToken (in_file, in_buf, in_size,
1013 cur_mb_len, in_ptr, _DtCvTRUE) != 0)
1020 spnResult = _DtHelpCeStrcspn (myBufPtr, " >\n", cur_mb_len, ©Size);
1021 if (_DtHelpCeAddStrToBuf (&myBufPtr, &stringPtr, &stringSize,
1022 &stringMax, copySize, 0) == -1)
1026 * _DtHelpCeStrcspn stopped at a character we want
1030 else if (((int)strlen(myBufPtr)) >= cur_mb_len)
1032 errno = CEErrorIllegalInfo;
1035 else if (_DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1)
1039 if (stringPtr != NULL && *stringPtr != '\0')
1041 *ret_value = atoi(stringPtr);
1046 errno = CEErrorFormattingValue;
1052 if (result != -1 && _DtCvTRUE == flag && *myBufPtr == '>')
1058 /******************************************************************************
1059 * Function: int _DtHelpCeSkipToNextCcdfToken (FILE *read_file, char *read_buf,
1060 * int read_size, char **src_ptr, int flag)
1063 * read_file Specifies a stream to read from.
1064 * read_buf Specifies the buffer where new information
1066 * read_size Specifies the maximum size of 'read_buf'.
1067 * src_ptr Specifies the pointer into 'read_buf' to
1069 * Returns the new location in 'read_buf' to
1070 * continue processing.
1071 * flag Specifies whether the routine returns
1072 * a 1 if '>' is the next token.
1074 * -1 If problems encountered finding the next token.
1075 * 0 If no problems encountered finding the next token.
1076 * 1 If flag is true and the next token is a > character.
1079 * read (2) Errors set via a read call.
1082 * CEErrorIllegalInfo
1084 * Purpose: Move 'src_ptr' to the next occurrance of a > character
1085 * or the first character after the next space.
1087 *****************************************************************************/
1089 _DtHelpCeSkipToNextCcdfToken (
1090 BufFilePtr read_file,
1099 char *srcPtr = *src_ptr;
1102 * Skip the rest of the alphanumeric string.
1107 * _DtHelpCeStrcspn returns 0 for 'found a character'
1109 result = _DtHelpCeStrcspn (srcPtr, " >\n", cur_mb_len, &len);
1110 srcPtr = srcPtr + len;
1114 if (result == -1 && ((int)strlen(srcPtr)) >= cur_mb_len)
1116 errno = CEErrorIllegalInfo;
1119 if (_DtHelpCeGetNxtBuf(read_file, read_buf,&srcPtr,read_size) == -1)
1125 * Now skip the blanks and end of lines
1130 * _DtHelpCeStrspn returns 0 for 'found a character'
1132 result = _DtHelpCeStrspn (srcPtr, " \n", cur_mb_len, &len);
1133 srcPtr = srcPtr + len;
1136 if (result == -1 && ((int)strlen(srcPtr)) >= cur_mb_len)
1138 errno = CEErrorIllegalInfo;
1141 if (_DtHelpCeGetNxtBuf(read_file,read_buf,&srcPtr,read_size) == -1)
1148 if (_DtCvTRUE == flag && *srcPtr == '>')
1150 errno = CEErrorFormattingOption;
1156 /******************************************************************************
1157 * Function: int _DtHelpCeGetCcdfTopicCmd (void *dpy, FILE *in_file, char *in_buf,
1158 * char **in_ptr, int in_size,
1159 * char **ret_charSet)
1162 * in_file Specifies a stream to read from.
1163 * in_buf Specifies the buffer where new information
1165 * in_ptr Specifies the pointer into 'in_buf' to
1167 * Returns the new location in 'in_buf' to
1168 * continue processing.
1169 * in_size Specifies the maximum size of 'in_buf'.
1170 * ret_charSet Returns the characters set if specified.
1172 * Returns: 0 if successful, -1 if errors.
1175 * read (2) Errors set via a read call.
1178 * CEErrorIllegalInfo
1182 * Purpose: Checks for the <TOPIC> command and returns the charset
1185 *****************************************************************************/
1187 _DtHelpCeGetCcdfTopicCmd (
1194 char **ret_charSet )
1196 char *mycharSet = NULL;
1199 * null the return values
1202 *ret_charSet = NULL;
1205 * check for <TOPIC charset string>
1207 if (_DtHelpCeCheckNextCcdfCmd ("to",in_file,in_buf,in_size,cur_mb_len,in_ptr) == 0)
1210 * The <TOPIC> command and it's attributes must be in 1-byte charset.
1212 if (_DtHelpCeSkipToNextCcdfToken(in_file, in_buf, in_size, 1,
1213 in_ptr, _DtCvFALSE) == -1)
1219 if (_DtCvToLower (**in_ptr) == 'c')
1221 if (_DtHelpCeGetCcdfStrParam (in_file, in_buf, in_size,
1222 1, in_ptr, True, False, False, False, &mycharSet) == -1)
1225 if (_DtHelpCeGetCcdfEndMark(in_file,in_buf,in_ptr,in_size,1) == -1)
1233 else if (**in_ptr != '>')
1235 errno = CEErrorTopicSyntax;
1241 * skip the end token
1243 *in_ptr = *in_ptr + 1;
1248 errno = CEErrorMissingTopicCmd;
1253 *ret_charSet = mycharSet;
1260 /******************************************************************************
1261 * Function: int _DtHelpCeCheckNextCcdfCmd (char *token, FILE *in_file, char in_buf,
1262 * int in_size, char **in_ptr)
1265 * token Specifies the syntax to look for.
1266 * <token ....> data </>
1267 * in_file Specifies a stream to read from.
1268 * in_buf Specifies the buffer where new information
1270 * in_size Specifies the maximum size of 'in_buf'.
1271 * in_ptr Specifies the pointer into 'in_buf' to
1273 * Returns the new location in 'in_buf' to
1274 * continue processing.
1276 * Returns: 0 if successful, -1 if errors, -2 if token not found.
1279 * read (2) Errors set via a read call.
1281 * CEErrorIllegalInfo
1284 * Purpose: Determine if the next formatting command is
1287 * Note: 'token' must be a lower case string.
1289 *****************************************************************************/
1291 _DtHelpCeCheckNextCcdfCmd(
1300 int len = strlen (token);
1304 * check for the token
1306 while (len > 0 && result > -1)
1308 if (**in_ptr == '\0' &&
1309 _DtHelpCeGetNxtBuf(in_file, in_buf, in_ptr, in_size) == -1)
1312 if (cur_mb_len == 1 || mblen (*in_ptr, cur_mb_len) == 1)
1314 if ((isspace (**in_ptr) || **in_ptr == '\n'))
1315 *in_ptr = *in_ptr + 1;
1316 else if (**in_ptr == '<')
1318 if (((int)strlen(*in_ptr)) < (len + 1) &&
1319 _DtHelpCeGetNxtBuf (in_file, in_buf,
1320 in_ptr, in_size) == -1)
1323 for (str = *in_ptr + 1; len > 0; len--, str++, token++)
1325 if (_DtCvToLower (*str) != *token)
1340 /*****************************************************************************
1341 * Function: int _DtHelpCeGetCcdfTopicAbbrev (void *dpy, FILE *file, char *buffer,
1342 * char **buf_ptr, int buf_size, int strip,
1343 * char **ret_title, char **ret_charSet,
1344 * char **ret_abbrev)
1347 * dpy Specifies the display connection as a void.
1348 * Do it this way to prevent the terminal
1349 * functions from having to know about Xlib.
1350 * Terminal/Access Functions should pass NULL
1352 * file Specifies the stream of the open file.
1353 * buffer The buffer holding the current information.
1354 * buf_ptr Specifies the pointer into 'buffer' to
1356 * Returns the new location in 'buffer' to
1357 * continue processing.
1358 * buf_size The size of buffer.
1359 * ret_title Returns a null terminated string
1360 * containing the title if found.
1361 * ret_charSet Returns a null terminated string
1362 * containing the character set if found.
1363 * ret_abbrev Returns a null terminated string
1364 * containing the abbreviated title if found.
1366 * Memory own by caller:
1371 * Returns: 0 if successful, -2 if <TOPIC> not found, otherwise -1.
1374 * read (2) Errors set via a read call.
1377 * CEErrorIllegalInfo
1380 * Purpose: Find the title and abbreviated title of a topic.
1382 *****************************************************************************/
1384 _DtHelpCeGetCcdfTopicAbbrev (
1404 * check for <TOPIC charset string>
1406 if (_DtHelpCeGetCcdfTopicCmd (dpy,
1414 /* Must have a <TITLE> token*/
1415 GetTitleCmd(file, buffer, buf_size, cur_mb_len,buf_ptr,ret_title) == -1
1417 /* check for the <ABBREV> token */
1418 _DtHelpCeGetCcdfAbbrevCmd (file, buffer, buf_size, cur_mb_len,buf_ptr, ret_abbrev) == -1)
1425 /*****************************************************************************
1426 * Function: int _DtHelpCeSkipCcdfAbbrev (FILE *file, char *buffer, int buf_size,
1430 * file Specifies the stream of the open file.
1431 * buffer The buffer holding the current information.
1432 * buf_size The size of buffer.
1433 * buf_ptr Specifies the pointer into 'buffer' to
1435 * Returns the new location in 'buffer' to
1436 * continue processing.
1438 * Returns: 0 if successful, otherwise -1.
1441 * read (2) Errors set via a read call.
1444 * CEErrorIllegalInfo
1447 * Purpose: Skip the <ABBREV> command
1449 *****************************************************************************/
1451 _DtHelpCeSkipCcdfAbbrev (
1459 * check for the <ABBREV> token and skip its data.
1461 return _DtHelpCeGetCcdfAbbrevCmd(file, buffer, buf_size, cur_mb_len,buf_ptr, NULL);
1464 /******************************************************************************
1465 * Function: int _DtHelpCeGetCcdfAbbrevCmd (FILE *in_file, char *in_buf, int in_size,
1466 * char **in_ptr, char **ret_string)
1469 * in_file Specifies a stream to read from.
1470 * in_buf Specifies the buffer where new information
1472 * in_size Specifies the maximum size of 'in_buf'.
1473 * in_ptr Specifies the pointer into 'in_buf' to
1475 * Returns the new location in 'in_buf' to
1476 * continue processing.
1477 * ret_string Returns the data found.
1479 * Returns: 0 if successful, -1 if errors
1482 * read (2) Errors set via a read call.
1484 * CEErrorIllegalInfo
1487 * Purpose: Determine if the next formatting command is
1489 * Returns the data found between <ABBREV> and its ending </>.
1491 * Note: The only formatting command allowed between <ABBREV> and
1492 * its </> is the <NEWLINE> command. And it is stripped.
1494 *****************************************************************************/
1496 _DtHelpCeGetCcdfAbbrevCmd(
1509 * null the return string
1515 * check for the token
1517 result = _DtHelpCeCheckNextCcdfCmd ("ab", in_file, in_buf, in_size, cur_mb_len, in_ptr);
1520 else if (result == 0 &&
1521 _DtHelpCeGetCcdfEndMark(in_file,in_buf,in_ptr,in_size,cur_mb_len) != -1)
1523 result = GetCmdData (in_file, in_buf, in_size, in_ptr, cur_mb_len,
1524 CCDF_NEWLINE_CMD, CCDF_NEWLINE_CMD,
1525 &junkSize, &junkMax, ret_string);
1526 if (result == -1 && errno == CMD_NOT_ALLOWED)
1527 errno = CEErrorAbbrevSyntax;
1535 /******************************************************************************
1536 * Function: int _DtHelpCeGetCcdfCmd (int current, char *buffer,
1537 * char **buf_ptr, FILE *my_file,
1538 * int size, int allowed, int flag )
1540 * Parameters: current Specifies the current formatting command.
1541 * buffer Specifies the buffer to use for input.
1542 * buf_ptr Specifies the current position into 'buffer'.
1543 * my_file Specifies the file stream to read from.
1544 * size Specifies the maximum size of the input buffer.
1545 * allowed Specifies the commands allowed at this time.
1546 * flag Specifies the flag to use for
1547 * _DtHelpCeGetNxtBuf. No longer used.
1550 * -1 If errors reading the file or the command is not
1552 * > 0 The formmatting command.
1556 * Purpose: Determine if the string pointed to by 'ptr' is a formatting
1559 *****************************************************************************/
1561 _DtHelpCeGetCcdfCmd (
1577 * always allow the end of formatting command
1579 allowed = allowed | CCDF_FORMAT_END;
1582 * set the pointer to the current position in the input buffer
1585 if (*myPtr == '\0' &&
1586 _DtHelpCeGetNxtBuf(my_file, buffer, &myPtr, size) == -1)
1589 firstChar = _DtCvToLower (*myPtr);
1592 different = firstChar - CcdfFormatCmds[i].cmd[0];
1594 if (!different && CcdfFormatCmds[i].significant > 1)
1596 if (((int)strlen(myPtr)) < CcdfFormatCmds[i].significant &&
1597 _DtHelpCeGetNxtBuf (my_file, buffer, &myPtr, size) == -1)
1602 different = _DtCvToLower(myPtr[j]) - CcdfFormatCmds[i].cmd[j];
1604 } while (!different && j < CcdfFormatCmds[i].significant);
1607 } while (different && CcdfFormatCmds[i].type != CCDF_FORMAT_END);
1610 * update the passed in pointer
1615 * check to see if the formatting command is valid
1618 errno = CEErrorFormattingCmd;
1620 else if (!different && CCDF_NOT_ALLOW_CMD (allowed, CcdfFormatCmds[i].type))
1625 case CCDF_ABBREV_CMD:
1626 errno = CEErrorAbbrevSyntax;
1628 case CCDF_FIGURE_CMD:
1629 errno = CEErrorFigureSyntax;
1632 errno = CEErrorFontSyntax;
1634 case CCDF_GRAPHIC_CMD:
1635 errno = CEErrorGraphicSyntax;
1638 errno = CEErrorIdSyntax;
1640 case CCDF_LABEL_CMD:
1641 errno = CEErrorLabelSyntax;
1644 errno = CEErrorLinkSyntax;
1646 case CCDF_NEWLINE_CMD:
1647 errno = CEErrorNewLineSyntax;
1649 case CCDF_OCTAL_CMD:
1650 errno = CEErrorOctalSyntax;
1652 case CCDF_PARAGRAPH_CMD:
1653 errno = CEErrorParagraphSyntax;
1655 case CCDF_TITLE_CMD:
1656 errno = CEErrorTitleSyntax;
1658 case CCDF_TOPIC_CMD:
1659 errno = CEErrorTopicSyntax;
1663 if (different || my_error)
1666 return CcdfFormatCmds[i].type;
1669 /******************************************************************************
1670 * Function: int _DtHelpCeGetCcdfFontType (char *code)
1672 * Parameters: code Specifies the character set to initialize
1673 * data and flags. The caller must ensure that
1674 * there is enough of the code string available
1675 * to make the determination.
1677 * Return Value: int Returns the font resource to change.
1678 * -1 if unknown font change type.
1680 * Purpose: Determines if the code is a font change specification.
1682 *****************************************************************************/
1684 _DtHelpCeGetCcdfFontType (char *code)
1687 char myChar = _DtCvToLower (*code);
1690 my2Char = _DtCvToLower (*code);
1698 return _CEFONT_ANGLE;
1703 case 'c': return _CEFONT_CHAR_SET;
1710 return _CEFONT_TYPE;
1716 case 'w': return _CEFONT_WEIGHT;
1724 return _CEFONT_SIZE;
1727 return _CEFONT_SPACING;