/****************************************************************************** * Function: int _DtHelpCeGetNxtBuf (FILE *file, char *dst, char **src, * int max_size) * * Parameters: * file Specifies a stream to read from. * dst Specifies the buffer where new information * is placed. * src Specifies a pointer into 'dst'. If there * is information left over, it * is moved to the begining of 'dst'. * Returns 'src' pointing to 'dst'. * max_size Specifies the maximum size of 'dst'. * * Returns: 0 if this is the last buffer that can be read for the topic. * -1 if errors. * >0 if more to be read. * * errno Values: * read (2) Errors set via a read call. * EINVAL * CEErrorReadEmpty * * Purpose: Reads the next buffer of information. * *****************************************************************************/ int _DtHelpCeGetNxtBuf( BufFilePtr file, char *dst, char **src, int max_size) { int leftOver; int result; if (file == NULL) { errno = EINVAL; return -1; } (void ) strcpy (dst, (*src)); leftOver = strlen (dst); result = _DtHelpCeReadBuf (file, &(dst[leftOver]), (max_size - leftOver)); /* * check to see if we ran into trouble reading this buffer * of information. If not reset the pointer to the beginning * of the buffer. */ if (result != -1) *src = dst; return result; }
/***************************************************************************** * 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 */