/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these libraries and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* $XConsortium: CCDFUtil.c /main/7 1996/11/01 10:10:08 drk $ */ /************************************<+>************************************* **************************************************************************** ** ** File: CCDFUtil.c ** ** Project: Un*x Desktop Help ** ** ** Description: Semi private format utility functions for ** formatting CCDF ** ** ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company ** ** (c) Copyright 1993, 1994 Hewlett-Packard Company ** (c) Copyright 1993, 1994 International Business Machines Corp. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc. ** (c) Copyright 1993, 1994 Novell, Inc. ** ** **************************************************************************** ************************************<+>*************************************/ /* * system includes */ #include #include #include #include #include #include #include #ifdef X_NOT_STDC_ENV extern int errno; #endif /* * Canvas Engine includes */ #include "CanvasP.h" /* * private includes */ #include "bufioI.h" #include "CanvasError.h" #include "CCDFUtilI.h" #include "FontAttrI.h" #include "CvStringI.h" #include "FormatUtilI.h" #include "StringFuncsI.h" #ifdef NLS16 #endif /******** Private Function Declarations ********/ static int GetCmdData( BufFilePtr in_file, char *in_buf, int in_size, char **in_ptr, int cur_mb_len, int allowed, int strip, int *ret_size, int *ret_max, char **ret_string ); /******** End Private Function Declarations ********/ /****************************************************************************** * * Private variables and defines. * *****************************************************************************/ #define MIN_GROW 16 #define REALLOC_INCR 10 #define CMD_NOT_ALLOWED -1000 typedef struct { char *cmd; int type; int significant; } FormatCmds; static const FormatCmds CcdfFormatCmds[] = { { "abbrev" , CCDF_ABBREV_CMD , 2 }, { "angle" , CCDF_FONT_CMD , 2 }, { "characterset", CCDF_FONT_CMD , 1 }, { "figure" , CCDF_FIGURE_CMD , 1 }, { "graphic" , CCDF_GRAPHIC_CMD , 1 }, { "id" , CCDF_ID_CMD , 1 }, { "label" , CCDF_LABEL_CMD , 2 }, { "link" , CCDF_LINK_CMD , 2 }, { "newline" , CCDF_NEWLINE_CMD , 1 }, { "paragraph" , CCDF_PARAGRAPH_CMD, 1 }, { "size" , CCDF_FONT_CMD , 2 }, { "spacing" , CCDF_FONT_CMD , 2 }, { "title" , CCDF_TITLE_CMD , 2 }, { "topic" , CCDF_TOPIC_CMD , 2 }, { "type" , CCDF_FONT_CMD , 2 }, { "weight" , CCDF_FONT_CMD , 1 }, { "0x" , CCDF_OCTAL_CMD , 2 }, /* always leave this one as the last entry */ { "/" , CCDF_FORMAT_END , 1 } }; /****************************************************************************** * * Semi Public variables. * *****************************************************************************/ /****************************************************************************** * * Private Functions * *****************************************************************************/ /****************************************************************************** * Function: static int GetCmdData (FILE *in_file, char *in_buf, int in_size, * char **in_ptr, int allowed, int strip, * int *ret_size, int *ret_max, char **ret_string) * * Parameters: * in_file Specifies a stream to read from. * in_buf Specifies the buffer where new information * is placed. * in_size Specifies the maximum size of 'in_buf'. * in_ptr Specifies the pointer into 'in_buf' to * start processing. * Returns the new location in 'in_buf' to * continue processing. * allowed Specifies the formatting commands allowed * in the data. * strip Specifies the formatting commands to strip. * from the data. * ret_size Specifies the current size of * 'ret_string'. * Returns the new size of 'ret_string'. * ret_max Specifies the current maximum size of * 'ret_string' * Returns the new size of 'ret_string'. * ret_string Returns the data found. * * * Returns: 0 if successful, -1 if errors. * * errno Values: * read (2) Errors set via a read call. * EINVAL * CEErrorMalloc * CEErrorIllegalInfo * CEErrorReadEmpty * * * Purpose: Gets a string containing font change tags * Incoming source: * "data with font change tags " * *****************************************************************************/ static int GetCmdData( BufFilePtr in_file, char *in_buf, int in_size, char **in_ptr, int cur_mb_len, int allowed, int strip, int *ret_size, int *ret_max, char **ret_string ) { int size; int fontType; int charSize = 1; int result = 0; char *myBufPtr = *in_ptr; char *tmpPtr; int skipString = False; int endToken; int stripCmd; if (!ret_string) skipString = True; while (!result) { if (cur_mb_len != 1) charSize = mblen(myBufPtr, cur_mb_len); if (charSize == 1) { /* * Do we need to read more information? */ if (((int) strlen (myBufPtr)) < 3 && _DtHelpCeGetNxtBuf(in_file,in_buf,&myBufPtr,in_size) == -1) return -1; switch (*myBufPtr) { case '<': /* * Go to the next character. */ myBufPtr++; endToken = True; stripCmd = False; /* * end token */ if (*myBufPtr == '/') { *in_ptr = myBufPtr; return _DtHelpCeGetCcdfEndMark (in_file, in_buf, in_ptr, in_size,cur_mb_len); } fontType = _DtHelpCeGetCcdfFontType (myBufPtr); if (fontType == -1) { switch (_DtCvToLower (*myBufPtr)) { /* * <0xff> */ case '0': if ((!skipString && _DtHelpCeAddOctalToBuf ( myBufPtr, ret_string, ret_size, ret_max, 0) == -1) || _DtHelpCeGetCcdfEndMark (in_file, in_buf, &myBufPtr,in_size,cur_mb_len) == -1) return -1; endToken = False; break; /* * */ case 'a': myBufPtr++; if (_DtCvToLower (*myBufPtr) == 'b') { if (CCDF_NOT_ALLOW_CMD (allowed, CCDF_ABBREV_CMD)) { errno = CMD_NOT_ALLOWED; return -1; } else if (CCDF_NOT_ALLOW_CMD (strip, CCDF_ABBREV_CMD)) stripCmd = True; } else { errno = CEErrorFormattingCmd; return -1; } break; /* *
*/ case 'f': if (CCDF_NOT_ALLOW_CMD (allowed, CCDF_FIGURE_CMD)) { errno = CMD_NOT_ALLOWED; return -1; } else if (CCDF_NOT_ALLOW_CMD (strip, CCDF_FIGURE_CMD)) stripCmd = True; break; /* * */ case 'g': if (CCDF_NOT_ALLOW_CMD (allowed, CCDF_GRAPHIC_CMD)) { errno = CMD_NOT_ALLOWED; return -1; } if (_DtHelpCeGetCcdfEndMark (in_file, in_buf, &myBufPtr,in_size,cur_mb_len) == -1) return -1; endToken = False; break; /* * */ case 'i': if (CCDF_NOT_ALLOW_CMD (allowed, CCDF_ID_CMD)) { errno = CMD_NOT_ALLOWED; return -1; } else if (CCDF_NOT_ALLOW_CMD (strip, CCDF_ID_CMD)) stripCmd = True; break; /* *