Beispiel #1
0
/*****************************************************************************
 * Function:	int _DtHelpFormatAsciiStringDynamic (char *input_string,
 *					CEParagraph **ret_para, int *ret_num)
 *
 * Parameters:
 *		input_string	Specifies the ascii string to format.
 *		ret_para	Returns a pointer to a list of CEParagraph
 *				structures.
 *		ret_num		Returns the number of structures in 'ret_para'.
 *
 * Returns:	0 if successful, -1 if errors
 *
 * errno Values:
 *
 * Purpose:	_DtHelpFormatAsciiStringDynamic formats a string as if it were
 *		a dynamic string - it uses newline characters to terminate
 *		the current paragraph, not a line.
 *
 *****************************************************************************/
int
_DtHelpFormatAsciiStringDynamic(
	XtPointer	  client_data,
	char		 *input_string,
	XtPointer	 *ret_handle)
{
    int      result = -1;
    _DtHelpFontHints fontAttrs;
    XtPointer varHandle;
    _DtCvTopicPtr	  topic    = NULL;
    DtHelpDispAreaStruct *pDAS     = (DtHelpDispAreaStruct *) client_data;
    _FrmtUiInfo           myUiInfo = defUiInfo;

    /*
     * check the parameters.
     */
    if (input_string == NULL || ret_handle == NULL)
      {
	errno = EINVAL;
	return -1;
      }

    /*
     * fill out the ui information
     */
    myUiInfo.load_font    = _DtHelpDAResolveFont;
    myUiInfo.client_data  = (_DtCvPointer) pDAS;
    myUiInfo.line_width   = pDAS->lineThickness;
    myUiInfo.line_height  = pDAS->lineHeight;
    myUiInfo.leading      = pDAS->leading;
    myUiInfo.avg_char     = (int)(pDAS->charWidth / 10 +
				    ((pDAS->charWidth % 10) ? 1 : 0));
    myUiInfo.nl_to_space  = pDAS->nl_to_space;

    /*
     * Fake the flag and give the string as the input buffer.
     */
    *ret_handle  = NULL;

    _DtHelpCeCopyDefFontAttrList (&fontAttrs);
    _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,setlocale(LC_CTYPE,NULL),
				NULL, &(fontAttrs.language),
				&(fontAttrs.char_set));

    varHandle = __DtHelpCeSetUpVars(fontAttrs.language, fontAttrs.char_set,
						&myUiInfo);
    if (varHandle == NULL)
      {
        free(fontAttrs.language);
        free(fontAttrs.char_set);
	return -1;
      }

    result = __DtHelpCeProcessString (varHandle, NULL,
				_DtCvDYNAMIC,
				ScanString, input_string,
				strlen(input_string),
				0, True,
				&fontAttrs);

    if (result != -1)
	result = __DtHelpCeGetParagraphList (varHandle, False, _DtCvDYNAMIC,
								&topic);
    *ret_handle = (XtPointer) topic;

    free(fontAttrs.language);
    free(fontAttrs.char_set);
    free(varHandle);

    return result;

}  /* End _DtHelpFormatAsciiStringDynamic */
Beispiel #2
0
/******************************************************************************
 * Function:	int FormatChunksToXmString ()
 *
 * Parameters:
 *               *ret_list may be NULL when called
 *
 * Returns:	0 if successful, -1 if errors
 *
 * errno Values:
 *
 * Purpose:	Take some rich text chunks and turn it into an XmString.
 *
 ******************************************************************************/
static int
FormatChunksToXmString(
    DtHelpDispAreaStruct *pDAS,
    Boolean		  free_flag,
    void		**title_chunks,
    XmString		 *ret_title,
    XmFontList		 *ret_list,
    Boolean		 *ret_mod )
{
    int			 result = 0;
    int			 i;
    long		 j;
    int			 quarkCount;
    long		 chunkType;
    long		 myIdx;
    _DtCvPointer	 fontPtr;
    char		*charSet;
    const char		*strChunk;
    char		 buffer[16];
    _DtHelpFontHints		 fontSpecs;
    XmFontContext	 fontContext;
    XmString		 partTitle;
    XmString		 newTitle;
    XrmQuark		 charSetQuark;
    XrmName		 myCharSetQuarks[20];
    XrmName		 xrmName[_CEFontAttrNumber];
    Boolean		 myMore;

    /*
     * Initialize the pointers.
     */
    *ret_title = NULL;
    *ret_mod   = False;

    if (title_chunks == NULL)
	return -1;

    /*
     * initialize the font context
     */
    _DtHelpCeCopyDefFontAttrList(&fontSpecs);
    if ( NULL != *ret_list )
      {
        if (XmFontListInitFontContext (&fontContext, *ret_list) == False)
            result = -1;
        else 
          {
            XFontStruct *myFontStruct;
            /*
             * quarkize all the character sets found.
             */
            quarkCount = 0;
            do
              {
                myMore = XmFontListGetNextFont (fontContext, &charSet,
                                                                &myFontStruct);
                if (myMore)
                  {
                    myCharSetQuarks[quarkCount++] = 
                                                XrmStringToQuark (charSet);
                    XtFree (charSet);
                  }
              } while (myMore);
    
            XmFontListFreeFontContext (fontContext);
          }
      } /* if NULL != *ret_list */
    else
      { /* if NULL == *ret_list */
         quarkCount = 0;
         myCharSetQuarks[0] = 0;
      }

    /*
     * Build the XrmString based on the segments.
     * The format of the returned information is
     *		'DT_HELP_CE_CHARSET  locale  string'
     *		'DT_HELP_CE_FONT_PTR fontptr string'
     *		'DT_HELP_CE_SPC      spc'
     *		'DT_HELP_CE_STRING   string' - uses last specified
     *                                         charset/font_ptr.
     *
     * The order and manner in which the title_chunks are processed
     * is known and depended upon in several locations.
     * Do not change this without changing the other locations.
     * See the _DtHelpFormatxxx() routines and the ones that
     * create the title_chunk arrays in FormatSDL.c and FormatCCDF.c
     */
    myIdx = __DtHelpDefaultFontIndexGet(pDAS);
    _DtHelpCopyDefaultList(xrmName);
    for (i = 0; result == 0 && title_chunks[i] != DT_HELP_CE_END; i++)
      {
        /*
         * create a string for the char set and a quark for it.
         */
	chunkType = (long) title_chunks[i++];

        /*
	 * i now points to the first value after the type
	 */
	if (chunkType & DT_HELP_CE_CHARSET)
	  {
	    char *charSet;
	    char *lang = (char *) title_chunks[i];

	    /*
	     * test to see if the locale is in a lang.codeset form
	     */
	    if (_DtHelpCeStrchr(lang, ".", 1, &charSet) == 0)
	      {
		*charSet = '\0';
		charSet++;
	      }
	    else
	      {
		charSet = lang;
		lang    = NULL;
	      }

	    /*
	     * resolve/load the font for the default fonts
	     */
	    _DtHelpDAResolveFont(pDAS, lang, charSet, fontSpecs, &fontPtr);
	    myIdx = (long) fontPtr;
	    if (lang != NULL)
	      {
		charSet--;
		*charSet = '.';
	      }

	    if (free_flag)
	        free(title_chunks[i]);

	    /*
	     * move the i to point to the string.
	     */
	    i++;
	  }
	else if (chunkType & DT_HELP_CE_FONT_PTR)
	  {
	    /*
	     * get the default font for the language and code set.
	     */
	    (void) __DtHelpFontCharSetQuarkGet(pDAS, (long)title_chunks[i],
					&xrmName[_DT_HELP_FONT_CHAR_SET]);
	    (void) __DtHelpFontLangQuarkGet(pDAS, (long)title_chunks[i],
					&xrmName[_DT_HELP_FONT_LANG_TER]);
	    (void) __DtHelpFontIndexGet(pDAS, xrmName, &myIdx);

	    /*
	     * move the i to point to the string.
	     */
	    i++;
	  }

        /*
	 * the i point spc or string.
	 */
	if (chunkType & DT_HELP_CE_SPC)
	  {
	    j        = (long) title_chunks[i];
	    strChunk = _DtHelpDAGetSpcString(pDAS->spc_chars[j].spc_idx);
	    fontPtr  = pDAS->spc_chars[j].font_ptr;

	    /*
	     * get the default font for the language and code set.
	     */
	    (void) __DtHelpFontCharSetQuarkGet(pDAS, (long)fontPtr,
					&xrmName[_DT_HELP_FONT_CHAR_SET]);
	    (void) __DtHelpFontLangQuarkGet(pDAS, (long)fontPtr,
					&xrmName[_DT_HELP_FONT_LANG_TER]);
	    (void) __DtHelpFontIndexGet(pDAS, xrmName, &myIdx);
	  }
	else /* if (chunkType & _DT_HELP_CE_STRING) */
	    strChunk = (char *) title_chunks[i];

	sprintf(buffer, "%ld", myIdx);
	charSetQuark = XrmStringToQuark(buffer);

        j = 0;
        while (j < quarkCount && myCharSetQuarks[j] != charSetQuark)
            j++;

        /*
         * If we didn't find a matching character set,
         * add it to the list.
         */
        if (j >= quarkCount)
          {
	    /* Copy the input list so XmFontListAppendEntry can mangle it. */
	    /* But only do it once! */
	    if (False == *ret_mod)
	       *ret_list = XmFontListCopy(*ret_list);

	    if (myIdx < 0)
	      {
		XFontSet fontSet = __DtHelpFontSetGet(pDAS->font_info, myIdx);
                XmFontListEntry fontEntry;

		fontEntry = XmFontListEntryCreate (buffer,
						XmFONT_IS_FONTSET,
						(XtPointer) fontSet);
		*ret_list = XmFontListAppendEntry (*ret_list, fontEntry);
		XmFontListEntryFree (&fontEntry);
	      }
	    else
	      {
		XFontStruct *fontStruct =
				__DtHelpFontStructGet(pDAS->font_info, myIdx);
                XmFontListEntry fontEntry;

		fontEntry = XmFontListEntryCreate (buffer,
						XmFONT_IS_FONT,
						(XtPointer) fontStruct);
		*ret_list = XmFontListAppendEntry (*ret_list, fontEntry);
		XmFontListEntryFree (&fontEntry);
	      }

           *ret_mod = True;
            if (*ret_list == NULL)
                result = -1;

            myCharSetQuarks[quarkCount++] = charSetQuark;
          }

        /*
         * add this segment to the XmString.
         */
        if (result == 0)
          {
            if (*ret_title == NULL)
                *ret_title = XmStringGenerate ((char *) strChunk, buffer, 
					       XmCHARSET_TEXT, NULL);
            else
              {
                partTitle = XmStringGenerate ((char *) strChunk, buffer,
					      XmCHARSET_TEXT, NULL);

                newTitle = XmStringConcat (*ret_title, partTitle);

                XmStringFree (*ret_title);
                XmStringFree (partTitle);
                *ret_title = newTitle;
              }

            /*
             * if a newline was specified,
             * replace it with a blank.
             */
            if (*ret_title != NULL && (chunkType & DT_HELP_CE_NEWLINE))
              {
                partTitle = XmStringGenerate (" ", buffer, XmCHARSET_TEXT, NULL);
                newTitle = XmStringConcat (*ret_title, partTitle);
                XmStringFree (*ret_title);
                XmStringFree (partTitle);
                *ret_title = newTitle;
              }

            if (*ret_title == NULL)
                result = -1;
          }

	if (free_flag && (chunkType & DT_HELP_CE_STRING))
	    free(title_chunks[i]);
      }
    /*
     * deallocate the memory.
     */
    if (free_flag) free(title_chunks);
    return result;
}
Beispiel #3
0
/*****************************************************************************
 * Function:	int _DtHelpFormatAsciiFile (char *filename,
 *					CEParagraph **ret_para, int *ret_num)
 *
 * Parameters:
 *		filename	Specifies the ascii file to read.
 *		ret_para	Returns a pointer to a list of CEParagraph
 *				structures.
 *		ret_num		Returns the number of structures in 'ret_para'.
 *
 * Returns:	0 if successful, -1 if errors
 *
 * errno Values:
 *		EINVAL
 *
 * Purpose:	_DtHelpFormatAsciiFile formats Ascii Files into a list of
 *		CEParagraph structures.
 *
 *****************************************************************************/
int
_DtHelpFormatAsciiFile(
	XtPointer	  client_data,
	char		 *filename,
	XtPointer	 *ret_handle)
{
    int	       myFile;
    int	       result = -1;
    _DtHelpFontHints fontAttrs;
    char       buffer [BUFF_SIZE];
    BufFilePtr rawInput;
    XtPointer   varHandle;
    _DtCvTopicPtr	  topic    = NULL;
    DtHelpDispAreaStruct *pDAS     = (DtHelpDispAreaStruct *) client_data;
    _FrmtUiInfo           myUiInfo = defUiInfo;

    /*
     * check the parameters
     */
    if (filename == NULL || ret_handle == NULL)
      {
	errno = EINVAL;
	return -1;
      }

    /*
     * Initialize the pointers, buffers and counters
     */
    *ret_handle  = NULL;

    /*
     * open the file.
     */
    myFile = open (filename, O_RDONLY);
    if (myFile != -1)
      {
	/*
	 * set the information
	 */
	rawInput = _DtHelpCeBufFileRdWithFd(myFile);
	if (rawInput == 0)
	  {
	    close (myFile);
	    return -1;
	  }

        result = _DtHelpCeReadBuf (rawInput, buffer, BUFF_SIZE);

	if (result != -1)
	  {
	    _DtHelpCeCopyDefFontAttrList (&fontAttrs);
	    fontAttrs.spacing = _DtHelpFontSpacingMono;
	    _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,
				setlocale(LC_CTYPE,NULL), NULL,
				&(fontAttrs.language), &(fontAttrs.char_set));

	    /*
	     * fill out the ui information
	     */
	    myUiInfo.load_font    = _DtHelpDAResolveFont;
	    myUiInfo.client_data  = (_DtCvPointer) pDAS;
	    myUiInfo.line_width   = pDAS->lineThickness;
	    myUiInfo.line_height  = pDAS->lineHeight;
	    myUiInfo.leading      = pDAS->leading;
	    myUiInfo.avg_char     = (int)(pDAS->charWidth / 10 +
					((pDAS->charWidth % 10) ? 1 : 0));
	    myUiInfo.nl_to_space  = pDAS->nl_to_space;

	    /*
	     * get the formatting structure.
	     */
	    varHandle = __DtHelpCeSetUpVars(fontAttrs.language,
						fontAttrs.char_set, &myUiInfo);
	    if (varHandle == NULL)
	      {
	        free(fontAttrs.language);
	        free(fontAttrs.char_set);
		return -1;
	      }

	    result = __DtHelpCeProcessString (varHandle, rawInput,
				_DtCvLITERAL,
				ScanString, buffer, BUFF_SIZE,
				0, False, &fontAttrs);

	    if (result != -1)
		result = __DtHelpCeGetParagraphList (varHandle, True,
						_DtCvLITERAL,
						&topic);

	    free(fontAttrs.language);
	    free(fontAttrs.char_set);
	    free(varHandle);
	  }

	_DtHelpCeBufFileClose(rawInput, True);
      }

    *ret_handle = (XtPointer) topic;
    return result;

}  /* End _DtHelpFormatAsciiFile */
Beispiel #4
0
/*********************************************************************
 * Function: _DtHelpFormatManPage
 *
 *    _DtHelpFormatManPage formats a man page
 *	into a form understood by a display area.
 *
 *********************************************************************/
int
_DtHelpFormatManPage(
	XtPointer	 client_data,
	char		*man_spec,
	XtPointer	*ret_handle)
{
    int      result = -1;
    FILE    *myFile;
    int      writeBufSize = 0;
    int      writeBufMax  = 0;
    char    *ptr;
    char    *writeBuf = NULL;
    char     readBuf[BUFSIZ];
    _DtHelpFontHints    fontAttr;
    VarHandle  myVars;
    _DtCvTopicInfo *topicStruct;
    BufFilePtr myBufFile;
    static char manString[]     = "man ";
    static char devNullString[] = " 2>/dev/null";
    _DtCvTopicPtr topic = NULL;
    DtHelpDispAreaStruct *pDAS     = (DtHelpDispAreaStruct *) client_data;
    _FrmtUiInfo		  myUiInfo = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 1, False };

    /*
     * fill out the ui information
     */
    myUiInfo.load_font    = _DtHelpDAResolveFont;
    myUiInfo.client_data  = (_DtCvPointer) pDAS;
    myUiInfo.avg_char     = (int)(pDAS->charWidth / 10 +
					((pDAS->charWidth % 10) ? 1 : 0));
    myUiInfo.nl_to_space  = pDAS->nl_to_space;

    /*
     * pre-append the man command to man specification
     */
    ptr = (char *) malloc(sizeof(manString) + strlen(man_spec) +
						   sizeof(devNullString) - 1);
    if (!ptr)
	return -1;
    strcpy (ptr, manString);
    strcat (ptr, man_spec);
    strcat (ptr, devNullString);

    myFile = popen(ptr, "r");

    /*
     * free the man command
     */
    free (ptr);

    /*
     * check for problems
     */
    if (!myFile) /* couldn't create man(1) process */
	return -1;

    /*
     * make sure we don't try to read compressed.
     */
    myBufFile = _DtHelpCeCreatePipeBufFile(myFile);
    if (myBufFile == NULL)
      {
	(void) pclose(myFile); /* don't check for error, it was popen'd */
	return -1;
      }

    /*
     * get the font quark list - but force to mono-space
     */
    _DtHelpCeCopyDefFontAttrList (&fontAttr);
    fontAttr.spacing  = _DtHelpFontSpacingMono;
    _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,setlocale(LC_CTYPE,NULL),
			NULL, &(fontAttr.language), &(fontAttr.char_set));

    myVars = __DtHelpCeSetUpVars(fontAttr.language, fontAttr.char_set, &myUiInfo);
    if (myVars == NULL)
      {
	free(fontAttr.language);
	free(fontAttr.char_set);
	_DtHelpCeBufFileClose (myBufFile, True);
	return -1;
      }

    readBuf[0] = '\0';
    ptr        = readBuf;

    result = _DtHelpCeGetNxtBuf (myBufFile, readBuf, &ptr, BUFSIZ);
    if (result > 0)
	 result = FormatManPage (myVars, myBufFile,
				     readBuf,
				     BUFSIZ,
				     &fontAttr,
				     &writeBuf,
				     &writeBufSize,
				     &writeBufMax );

    if ((result != -1) && writeBufSize)
	result = __DtHelpCeProcessString(myVars, NULL, _DtCvLITERAL,
			ScanString, writeBuf, writeBufSize,
			0, False, &fontAttr);

    /*
     * free the buffer
     */
    if (writeBuf)
        free (writeBuf);

    /*
     * close the pipe
     */
    _DtHelpCeBufFileClose (myBufFile, True);

    /*
     * clean up the last segment.
     */
    if (result != -1)
	__DtHelpCeGetParagraphList (myVars, True, _DtCvLITERAL, &topic);

    topicStruct = (_DtCvTopicInfo *) (topic);

   /*
    * did we have any paragraphs to format?
    */
   if (topic != NULL && NULL == topicStruct->seg_list
		|| NULL == _DtCvContainerListOfSeg(topicStruct->seg_list))
      {
	_DtHelpFreeSegments(topicStruct->seg_list, _DtCvFALSE,
						NULL, (_DtCvPointer) pDAS);
	free ((char *) topicStruct);
	topic = NULL;
	errno = ENOENT; /* we'll just assume no man page existed */
	result = -1;
      }

    free(fontAttr.language);
    free(fontAttr.char_set);
    free(myVars);

    *ret_handle = (_DtCvPointer) topic;

    return (result);

}  /* End _DtHelpFormatManPage */