Exemple #1
0
//------------------------------------------------------------------------------
//!
void
BIH::create(
   const Vector<AABBoxf*>& bboxes,
   const Vector<Vec3f>&    centers,
   Vector<uint>*           ids,
   uint                    leafSize,
   uint                    maxDepth
)
{
   CHECK( bboxes.size() == centers.size() );

   DBG_BLOCK( os_bih, "Start computing BIH..." );
   DBG( Timer timer );

   // Initialization.
   DBG_MSG( os_bih, "# of elements: " << bboxes.size() << " " << centers.size() << "\n" );
   // 1. Init maximum recursion level.
   if( maxDepth == 0 )
   {
      maxDepth = (int)CGM::log2( float(centers.size()) ) * 2 + 1;
   }
   _maxDepth = CGM::min( maxDepth, (uint)100 );

   // 2. Init ids.
   if( ids == 0 )
   {
      _ids.resize( centers.size() );
      for( uint i = 0; i < _ids.size(); ++i )
      {
         _ids[i] = i;
      }
   }
   else
   {
      _ids.swap( *ids );
   }
   
   Vector<uint>  remap( centers.size() );
   for( uint i = 0; i < remap.size(); ++i )
   {
      remap[i] = i;
   }

   // 3. Init nodes and root.
   //_nodes.reserve();
   _nodes.resize(1);

   // 4. Compute bounding box.
   AABBoxf nodeBox  = AABBoxf::empty();
   for( uint i = 0; i < bboxes.size(); ++i )
   {
      nodeBox |= *bboxes[i];
   }
   AABBoxf splitBox = nodeBox;

   // 5. Stack.
   Vector<BuildStackNode> stack( maxDepth );
   uint stackID = 0;

   uint maxPrim = 0;
   uint maxD = 0;

   // Construct BIH.
   uint begin = 0;
   uint end   = uint(_ids.size());
   uint depth = 1;
   uint node  = 0;
   while( 1 )
   {
      // Do we have a root node?
      if( (end - begin <= leafSize) || depth >= maxDepth )
      {
         // Root node.
         _nodes[node]._index = (begin << 3) + 3;
         _nodes[node]._numElements = end-begin;

         maxPrim = CGM::max( maxPrim, end-begin );
         maxD = CGM::max( maxD, depth );

         // Are we done?
         if( stackID == 0 )
         {
            break;
         }
         stack[--stackID].get( node, begin, end, depth, nodeBox, splitBox );
      }
      else
      {
         // Compute split plane and axis.
         uint axis        = splitBox.longestSide();
         float splitPlane = splitBox.center( axis );

         // Partition primitives.
         AABBoxf leftNodeBox  = AABBoxf::empty();
         AABBoxf rightNodeBox = AABBoxf::empty();
         uint pivot = begin;
         for( uint i = begin; i < end; ++i )
         {
            if( centers[remap[i]](axis) < splitPlane )
            {
               leftNodeBox |= (*bboxes[remap[i]]);
               CGM::swap( remap[i], remap[pivot] );
               CGM::swap( _ids[i], _ids[pivot++] );
            }
            else
            {
               rightNodeBox |= (*bboxes[remap[i]]);
            }
         }

         // Construct node.
         ++depth;
         // No left node.
         if( pivot == begin )
         {
            uint childNode = uint(_nodes.size());

            // Current node.
            _nodes[node]._index    = (childNode << 3) + 4 + axis;
            _nodes[node]._plane[0] = rightNodeBox.min( axis );
            _nodes[node]._plane[1] = rightNodeBox.max( axis );

            // Create nodes.
            _nodes.pushBack( Node() );

            // Child node.
            node     = childNode;
            nodeBox  = rightNodeBox;
            splitBox.slab( axis )(0) = CGM::max( splitPlane, rightNodeBox.min( axis ) );
         }
         // No right node.
         else if( pivot == end )
         {
            uint childNode = uint(_nodes.size());

            // Current node.
            _nodes[node]._index    = (childNode << 3) + 4 + axis;
            _nodes[node]._plane[0] = leftNodeBox.min( axis );
            _nodes[node]._plane[1] = leftNodeBox.max( axis );

            // Create nodes.
            _nodes.pushBack( Node() );

            // Child node.
            node     = childNode;
            nodeBox  = leftNodeBox;
            splitBox.slab( axis )(1) = CGM::min( splitPlane, leftNodeBox.max( axis ) );
         }
         // Left and right node.
         else
         {
            uint leftNode = uint(_nodes.size());

            // Current node.
            _nodes[node]._index    = (leftNode << 3) + axis;
            _nodes[node]._plane[0] = leftNodeBox.max( axis );
            _nodes[node]._plane[1] = rightNodeBox.min( axis );

            // Create nodes.
            _nodes.pushBack( Node() );
            _nodes.pushBack( Node() );

            // Right node.
            AABBoxf rsplitBox( splitBox );
            rsplitBox.slab( axis )(0) = splitPlane;
            stack[stackID++].set( leftNode+1, pivot, end, depth, rightNodeBox, rsplitBox );

            // Left node.
            node     = leftNode;
            end      = pivot;
            nodeBox  = leftNodeBox;
            splitBox.slab( axis )(1) = splitPlane;
         }
      }
   }

   DBG( double time = timer.elapsed() );
   DBG_MSG( os_bih, "...finish in " << time << " sec." );
   DBG_MSG( os_bih, "# of nodes: " << _nodes.size() );
   DBG_MSG( os_bih, "# of indices: " << _ids.size() );
   DBG_MSG( os_bih, "max primitives in a leaf: " << maxPrim );
   DBG_MSG( os_bih, "max depth: " << maxD << " " << maxDepth );
}
Exemple #2
0
/*
 * Build the list with footnote text information for Word 8/9/10 files
 */
static void
vGet8FootnotesText(FILE *pFile, const pps_info_type *pPPS,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	footnote_local_type	*pCurr;
	const ULONG	*aulBlockDepot;
	UCHAR	*aucBuffer;
	ULONG	ulCharPos, ulBeginOfFootnotes, ulOffset, ulBeginFootnoteText;
	size_t	tFootnoteTextLen, tBlockDepotLen, tBlockSize;
	size_t	tIndex;

	TRACE_MSG("vGet8FootnotesText");

	ulBeginOfFootnotes = ulGetLong(0x18, aucHeader); /* fcMin */
	ulBeginOfFootnotes += ulGetLong(0x4c, aucHeader); /* ccpText */
	NO_DBG_HEX(ulBeginOfFootnotes);

	ulBeginFootnoteText = ulGetLong(0xb2, aucHeader); /* fcPlcffndTxt */
	NO_DBG_HEX(ulBeginFootnoteText);
	tFootnoteTextLen =
		(size_t)ulGetLong(0xb6, aucHeader); /* lcbPlcffndTxt */
	NO_DBG_DEC(tFootnoteTextLen);

	if (tFootnoteTextLen < 12) {
		DBG_MSG("No Footnote text in this document");
		return;
	}

	NO_DBG_DEC(pPPS->tTable.ulSB);
	NO_DBG_HEX(pPPS->tTable.ulSize);
	if (pPPS->tTable.ulSize == 0) {
		DBG_MSG("No footnote text information");
		return;
	}

	if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
	  	/* Use the Small Block Depot */
		aulBlockDepot = aulSBD;
		tBlockDepotLen = tSBDLen;
		tBlockSize = SMALL_BLOCK_SIZE;
	} else {
	  	/* Use the Big Block Depot */
		aulBlockDepot = aulBBD;
		tBlockDepotLen = tBBDLen;
		tBlockSize = BIG_BLOCK_SIZE;
	}
	aucBuffer = xmalloc(tFootnoteTextLen);
	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucBuffer, ulBeginFootnoteText, tFootnoteTextLen)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tFootnoteTextLen);

	fail(tFootnoteTextLength != 0);
	tFootnoteTextLength = tFootnoteTextLen / 4 - 2;
	fail(tFootnoteTextLength == 0);

	fail(pFootnoteText != NULL);
	pFootnoteText = xcalloc(tFootnoteTextLength,
				sizeof(footnote_local_type));

	for (tIndex = 0; tIndex < tFootnoteTextLength; tIndex++) {
		pCurr = pFootnoteText + tIndex;
		pCurr->tInfo.szText = NULL;
		ulOffset = ulGetLong(tIndex * 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfFootnotes + ulOffset;
		NO_DBG_HEX(ulCharPos);
		NO_DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosStart = ulCharPos;
		ulOffset = ulGetLong(tIndex * 4 + 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfFootnotes + ulOffset;
		NO_DBG_HEX(ulCharPos);
		NO_DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosNext = ulCharPos;
		pCurr->bUseful = pCurr->ulCharPosStart != pCurr->ulCharPosNext;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet8FootnotesText */
Exemple #3
0
/*
 * Build the list with endnote information for Word 8/9/10 files
 */
static void
vGet8EndnotesInfo(FILE *pFile, const pps_info_type *pPPS,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	const ULONG	*aulBlockDepot;
	UCHAR	*aucBuffer;
	ULONG	ulFileOffset, ulBeginOfText, ulOffset, ulBeginEndnoteInfo;
	size_t	tEndnoteInfoLen, tBlockDepotLen, tBlockSize;
	size_t	tIndex;

	TRACE_MSG("vGet8EndnotesInfo");

	ulBeginOfText = ulGetLong(0x18, aucHeader); /* fcMin */
	NO_DBG_HEX(ulBeginOfText);
	ulBeginEndnoteInfo = ulGetLong(0x20a, aucHeader); /* fcPlcfendRef */
	NO_DBG_HEX(ulBeginEndnoteInfo);
	tEndnoteInfoLen = (size_t)ulGetLong(0x20e, aucHeader); /* lcbPlcfendRef */
	NO_DBG_DEC(tEndnoteInfoLen);

	if (tEndnoteInfoLen < 10) {
		DBG_MSG("No endnotes in this document");
		return;
	}

	NO_DBG_DEC(pPPS->tTable.ulSB);
	NO_DBG_HEX(pPPS->tTable.ulSize);
	if (pPPS->tTable.ulSize == 0) {
		DBG_MSG("No endnotes information");
		return;
	}

	if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
	  	/* Use the Small Block Depot */
		aulBlockDepot = aulSBD;
		tBlockDepotLen = tSBDLen;
		tBlockSize = SMALL_BLOCK_SIZE;
	} else {
	  	/* Use the Big Block Depot */
		aulBlockDepot = aulBBD;
		tBlockDepotLen = tBBDLen;
		tBlockSize = BIG_BLOCK_SIZE;
	}
	aucBuffer = xmalloc(tEndnoteInfoLen);
	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucBuffer, ulBeginEndnoteInfo, tEndnoteInfoLen)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tEndnoteInfoLen);

	fail(tEndnoteListLength != 0);
	tEndnoteListLength = (tEndnoteInfoLen - 4) / 6;
	fail(tEndnoteListLength == 0);

	fail(aulEndnoteList != NULL);
	aulEndnoteList = xcalloc(tEndnoteListLength, sizeof(ULONG));

	for (tIndex = 0; tIndex < tEndnoteListLength; tIndex++) {
		ulOffset = ulGetLong(tIndex * 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulFileOffset = ulCharPos2FileOffset(ulBeginOfText + ulOffset);
		NO_DBG_HEX(ulFileOffset);
		aulEndnoteList[tIndex] = ulFileOffset;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet8EndnotesInfo */
Exemple #4
0
INT32 Lens_Init(LENS_INIT_STATE part)
{
    INT32 ERROR_STATUS;

    switch(part)
    {
        case LENS_INIT_ZOOM_PART1:
            //Step 1. Initiate zoom part1
            DBG_MSG("Start of LENS_INIT_ZOOM_PART1\r\n");
            //Callback function
            //TM_Begin(LENS_ZOOM_INIT);
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITZOOM1_START, NULL);
            }

            gLensCtrlObj.pLens->zoom_initPart1();

            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITZOOM1_END, NULL);
            }

            Lens_Module_SetState(LENS_STATE_INIT_PART1);
            DBG_MSG("End of LENS_STATE_INIT_PART1\r\n");    // --> LENS_STATE_INIT_PART1
            return ERR_OK;

        case LENS_INIT_ZOOM_PART2:
            //Step 2. Initiate zoom part2
            DBG_MSG("Start of LENS_INIT_ZOOM_PART2\r\n");

            //TM_Begin(LENS_ZOOM_INITWAIT);
            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITZOOM2_START, NULL);
            }

            ERROR_STATUS = gLensCtrlObj.pLens->zoom_initPart2();

            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITZOOM2_END, NULL);
            }

            //TM_End(LENS_ZOOM_INITWAIT);

            DBG_MSG("End of LENS_INIT_ZOOM_PART2\r\n");

            return ERROR_STATUS;

        case LENS_INIT_APERTURE:
            //Step 3. Initiate aperture
            DBG_MSG("Start of LENS_INIT_APERTURE\r\n");
            //TM_Begin(LENS_APER_INIT);

            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITAPERTURE_START, NULL);
            }
            gLensCtrlObj.pLens->aperture_init();
            //#NT#2010/09/23#Jeffery Chuang -begin
            //Add shutter init here until add new api

            gLensCtrlObj.pMotor->shutter_setState(MOTOR_SHUTTER_NORMAL,OPEN);
            //#NT#2010/09/23#Jeffery Chuang -end

            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITAPERTURE_END, NULL);
            }

            //TM_End(LENS_APER_INIT);

            DBG_MSG("End of LENS_INIT_APERTURE\r\n");
            return ERR_OK;

        case LENS_INIT_FOCUS:
            //TM_Begin(LENS_FOCUS_INIT);
            DBG_MSG("Start of LENS_INIT_FOCUS\r\n");

            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITFOCUS_START, NULL);
            }

            #if 1 // Could be migrated to other place in the near future.
            {
                PPSTORE_SECTION_HANDLE  pSection;
                INT16 iTmpIdx[15] = {0};
                UINT32 uiCalTblSize = Lens_Zoom_GetSection(ZOOM_MAX_SECTION)/* Table size of DemoKit is '11'. */, i;

                if(sizeof(iTmpIdx) >= uiCalTblSize)
                {
                    if ((pSection = PStore_OpenSection(PS_FOCUS_DATA, PS_RDWR)) != E_PS_SECHDLER)
                    {
                        PStore_ReadSection((UINT8 *)&iTmpIdx, 0, uiCalTblSize * sizeof(INT16), pSection);
                        PStore_CloseSection(pSection);

                        for(i = 0; i < uiCalTblSize; i++)
                        {
                            DBG_MSG("^GZoom sec_%d: peak_idx:%d\r\n", i+1, iTmpIdx[i]);
                        }
                        Lens_Focus_SetCalData(iTmpIdx, uiCalTblSize);
                    }
                    else
                        DBG_ERR("No focus calibration data!\r\n");
                }
                else
                {
                    DBG_ERR("Buf size isn't enough for AF cal data!\r\n");
                }
            }
            #endif

            gLensCtrlObj.pLens->makeAFTable();

            ERROR_STATUS = gLensCtrlObj.pLens->focus_init();

            //Callback function
            if(gLensCtrlObj.APICB!=NULL)
            {
                gLensCtrlObj.APICB(LENS_CB_INITFOCUS_END, NULL);
            }

            Lens_Module_SetState(LENS_STATE_IDLE);
            DBG_MSG("LENS_STATE_IDLE\r\n");    // --> LENS_STATE_IDLE
            DBG_MSG("End of LENS_INIT_FOCUS\r\n");
            //TM_End(LENS_FOCUS2_INIT);

            return ERROR_STATUS;


        default:
            DBG_ERR("Init wrong state\r\n");
            return ERR_OPERATION_FAIL;
    }


}
Exemple #5
0
/*
 * Fill the font information block with information
 * from a WinWord 1 file.
 */
void
vGet1FontInfo(int iFodo,
	const UCHAR *aucGrpprl, size_t tBytes, font_block_type *pFont)
{
	BOOL	bIcoChange, bFtcChange, bHpsChange, bKulChange;
	USHORT	usTmp;
	UCHAR	ucTmp;
	UCHAR	aucChpx[12];

	fail(iFodo < 0 || aucGrpprl == NULL || pFont == NULL);

	if (tBytes > sizeof(aucChpx)) {
		NO_DBG_PRINT_BLOCK(aucGrpprl + iFodo, tBytes);
		return;
	}

	/* Build the CHPX structure */
	(void)memset(aucChpx, 0, sizeof(aucChpx));
	(void)memcpy(aucChpx, aucGrpprl + iFodo, min(tBytes, sizeof(aucChpx)));

	usTmp = usGetWord(0, aucChpx);
	if ((usTmp & BIT(0)) != 0) {
		pFont->usFontStyle ^= FONT_BOLD;
	}
	if ((usTmp & BIT(1)) != 0) {
		pFont->usFontStyle ^= FONT_ITALIC;
	}
	if ((usTmp & BIT(2)) != 0) {
		pFont->usFontStyle ^= FONT_STRIKE;
	}
	if ((usTmp & BIT(5)) != 0) {
		pFont->usFontStyle ^= FONT_SMALL_CAPITALS;
	}
	if ((usTmp & BIT(6)) != 0) {
		pFont->usFontStyle ^= FONT_CAPITALS;
	}
	if ((usTmp & BIT(7)) != 0) {
		pFont->usFontStyle ^= FONT_HIDDEN;
	}

	ucTmp = ucGetByte(5, aucChpx);
	if (ucTmp != 0) {
		if (ucTmp < 128) {
			pFont->usFontStyle |= FONT_SUPERSCRIPT;
			DBG_MSG("Superscript");
		} else {
			pFont->usFontStyle |= FONT_SUBSCRIPT;
			DBG_MSG("Subscript");
		}
	}

	bIcoChange = (usTmp & BIT(10)) != 0;
	bFtcChange = (usTmp & BIT(11)) != 0;
	bHpsChange = (usTmp & BIT(12)) != 0;
	bKulChange = (usTmp & BIT(13)) != 0;

	if (bFtcChange) {
		usTmp = usGetWord(2, aucChpx);
		if (usTmp <= (USHORT)UCHAR_MAX) {
			pFont->ucFontNumber = (UCHAR)usTmp;
		} else {
			pFont->ucFontNumber = 0;
		}
	}

	if (bHpsChange) {
		pFont->usFontSize = (USHORT)ucGetByte(4, aucChpx);
	}

	if (bIcoChange || bKulChange) {
		usTmp = usGetWord(6, aucChpx);
		if (bIcoChange) {
			pFont->ucFontColor = (UCHAR)((usTmp & 0x0f00) >> 8);
			if (pFont->ucFontColor <= 7) {
				/* Add 1 for compatibility with Word 2 and up */
				pFont->ucFontColor++;
			} else {
				DBG_DEC(pFont->ucFontColor);
				pFont->ucFontColor = 0;
			}
		}
		if (bKulChange) {
			usTmp = (usTmp & 0x7000) >> 12;
			DBG_DEC_C(usTmp > 4, usTmp);
			if (usTmp == 0) {
				pFont->usFontStyle &= ~FONT_UNDERLINE;
			} else {
				pFont->usFontStyle |= FONT_UNDERLINE;
			}
		}
	}
Exemple #6
0
int vout_info_add_entry(vout_t *vo)
{
	vout_info_t *p;
	int i;

	if( vo->inf == 0 )
		return 0;

#ifdef CONFIG_HW_GOVR2_DVO
	switch( vo->inf->mode ){
		case VOUT_INF_DVI:
			vo->govr = p_govrh2;
			break;
		default:
			vo->govr = p_govrh;
			break;
	}
#else
	vo->govr = ( (vo->inf->mode == VOUT_INF_DVI) && g_vpp.dual_display )? p_govrh2:p_govrh;
#endif
	for(i=0;i<VPP_VOUT_INFO_NUM;i++){
		p = &vout_info[i];
		p->num = i;
		if( p->vo_mask == 0 ){
			break;
		}
		
		if( p->vo_mask & (0x1 << vo->num) ){
			return i;
		}

		if( vo->govr ){
			if( p->govr_mod == ((vpp_mod_base_t *)(vo->govr))->mod ){
				goto add_entry_exist;
			}
		}
	}

	if( i >= VPP_VOUT_INFO_NUM ){
		DBG_ERR("full\n");
		goto add_entry_exist;
		return VPP_VOUT_INFO_NUM;
	}
	if( (g_vpp.dual_display == 0) && (i!=0) ){
		p->resx = vout_info[0].resx;
		p->resy = vout_info[0].resy;
	}
	else {
		p->resx = vo->resx;
		p->resy = vo->resy;
	}
	p->resx_virtual = vpp_calc_align(p->resx,4);
	p->resy_virtual = p->resy;
	p->fps = (int) vo->pixclk;
	p->govr_mod = (vo->govr)? ((vpp_mod_base_t *)vo->govr)->mod:VPP_MOD_MAX;
	p->govr = vo->govr;
add_entry_exist:
	p->vo_mask |= (0x1 << vo->num);	
	DBG_MSG("info %d,vo mask 0x%x,%s,%dx%d@%d\n",i,p->vo_mask,vpp_mod_str[p->govr_mod],p->resx,p->resy,p->fps);
	return i;
}
static void level1_cache_flush_all(void)
{
	DBG_MSG(4, ("meson_drm_ump_osk_msync(): Flushing the whole L1 cache\n"));
	__cpuc_flush_kern_all();
}
int ump_dmabuf_import_wrapper(u32 __user *argument,
				struct ump_session_data  *session_data)
{
	ump_session_memory_list_element *session = NULL;
	struct ump_uk_dmabuf ump_dmabuf;
	ump_dd_handle *ump_handle;
	ump_dd_physical_block *blocks;
	struct dma_buf_attachment *attach;
	struct dma_buf *dma_buf;
	struct sg_table *sgt;
	struct scatterlist *sgl;
	unsigned long block_size;
	/* FIXME */
	struct device dev;
	unsigned int i = 0, npages;
	int ret;

	/* Sanity check input parameters */
	if (!argument || !session_data) {
		MSG_ERR(("NULL parameter.\n"));
		return -EINVAL;
	}

	if (copy_from_user(&ump_dmabuf, argument,
				sizeof(struct ump_uk_dmabuf))) {
		MSG_ERR(("copy_from_user() failed.\n"));
		return -EFAULT;
	}

	dma_buf = dma_buf_get(ump_dmabuf.fd);
	if (IS_ERR(dma_buf))
		return PTR_ERR(dma_buf);

	/*
	 * check whether dma_buf imported already exists or not.
	 *
	 * TODO
	 * if already imported then dma_buf_put() should be called
	 * and then just return dma_buf imported.
	 */

	attach = dma_buf_attach(dma_buf, &dev);
	if (IS_ERR(attach)) {
		ret = PTR_ERR(attach);
		goto err_dma_buf_put;
	}

	sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
	if (IS_ERR(sgt)) {
		ret = PTR_ERR(sgt);
		goto err_dma_buf_detach;
	}

	npages = sgt->nents;

	/* really need? */
	ump_dmabuf.ctx = (void *)session_data;

	block_size = sizeof(ump_dd_physical_block) * npages;

	blocks = (ump_dd_physical_block *)_mali_osk_malloc(block_size);

	if (NULL == blocks) {
		MSG_ERR(("Failed to allocate blocks\n"));
		ret = -ENOMEM;
		goto err_dmu_buf_unmap;
	}

	sgl = sgt->sgl;

	while (i < npages) {
		blocks[i].addr = sg_phys(sgl);
		blocks[i].size = sg_dma_len(sgl);
		sgl = sg_next(sgl);
		i++;
	}

	/*
	 * Initialize the session memory list element, and add it
	 * to the session object
	 */
	session = _mali_osk_calloc(1, sizeof(*session));
	if (!session) {
		DBG_MSG(1, ("Failed to allocate session.\n"));
		ret = -EFAULT;
		goto err_free_block;
	}

	ump_handle = ump_dd_handle_create_from_phys_blocks(blocks, i);
	if (UMP_DD_HANDLE_INVALID == ump_handle) {
		DBG_MSG(1, ("Failed to create ump handle.\n"));
		ret = -EFAULT;
		goto err_free_session;
	}

	session->mem = (ump_dd_mem *)ump_handle;

	_mali_osk_lock_wait(session_data->lock, _MALI_OSK_LOCKMODE_RW);
	_mali_osk_list_add(&(session->list),
			&(session_data->list_head_session_memory_list));
	_mali_osk_lock_signal(session_data->lock, _MALI_OSK_LOCKMODE_RW);

	_mali_osk_free(blocks);

	ump_dmabuf.ump_handle = (uint32_t)ump_handle;
	ump_dmabuf.size = ump_dd_size_get(ump_handle);

	if (copy_to_user(argument, &ump_dmabuf,
				sizeof(struct ump_uk_dmabuf))) {
		MSG_ERR(("copy_to_user() failed.\n"));
		ret =  -EFAULT;
		goto err_release_ump_handle;
	}

	return 0;

err_release_ump_handle:
	ump_dd_reference_release(ump_handle);
err_free_session:
	_mali_osk_free(session);
err_free_block:
	_mali_osk_free(blocks);
err_dmu_buf_unmap:
	dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL);
err_dma_buf_detach:
	dma_buf_detach(dma_buf, attach);
err_dma_buf_put:
	dma_buf_put(dma_buf);
	return ret;
}
/*
 * IOCTL operation; Import fd to  UMP memory
 */
int ump_ion_import_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
{
	_ump_uk_ion_import_s user_interaction;
	ump_dd_handle *ump_handle;
	ump_dd_physical_block * blocks;
	unsigned long num_blocks;
	struct ion_handle *ion_hnd;
	struct scatterlist *sg;
	struct scatterlist *sg_ion;
	unsigned long i = 0;

	ump_session_memory_list_element * session_memory_element = NULL;
	if (ion_client_ump==NULL)
	    ion_client_ump = ion_client_create(ion_exynos, -1, "ump");

	/* Sanity check input parameters */
	if (NULL == argument || NULL == session_data)
	{
		MSG_ERR(("NULL parameter in ump_ioctl_allocate()\n"));
		return -ENOTTY;
	}

	/* Copy the user space memory to kernel space (so we safely can read it) */
	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
	{
		MSG_ERR(("copy_from_user() in ump_ioctl_allocate()\n"));
		return -EFAULT;
	}

	user_interaction.ctx = (void *) session_data;

	/* translate fd to secure ID*/
	ion_hnd = ion_import_fd(ion_client_ump, user_interaction.ion_fd);
	sg_ion = ion_map_dma(ion_client_ump,ion_hnd);

	blocks = (ump_dd_physical_block*)_mali_osk_malloc(sizeof(ump_dd_physical_block)*1024);

	if (NULL == blocks) {
		MSG_ERR(("Failed to allocate blocks in ump_ioctl_allocate()\n"));
		return -ENOMEM;
	}

	sg = sg_ion;
	do {
		blocks[i].addr = sg_phys(sg);
		blocks[i].size = sg_dma_len(sg);
		i++;
		if (i>=1024) {
			_mali_osk_free(blocks);
			MSG_ERR(("ion_import fail() in ump_ioctl_allocate()\n"));
			return -EFAULT;
		}
		sg = sg_next(sg);
	} while(sg);

	num_blocks = i;

	/* Initialize the session_memory_element, and add it to the session object */
	session_memory_element = _mali_osk_calloc( 1, sizeof(ump_session_memory_list_element));

	if (NULL == session_memory_element)
	{
		_mali_osk_free(blocks);
		DBG_MSG(1, ("Failed to allocate ump_session_memory_list_element in ump_ioctl_allocate()\n"));
		return -EFAULT;
	}

	ump_handle = ump_dd_handle_create_from_phys_blocks(blocks, num_blocks);
	if (UMP_DD_HANDLE_INVALID == ump_handle)
	{
		_mali_osk_free(session_memory_element);
		_mali_osk_free(blocks);
		DBG_MSG(1, ("Failed to allocate ump_session_memory_list_element in ump_ioctl_allocate()\n"));
		return -EFAULT;
	}

	session_memory_element->mem = (ump_dd_mem*)ump_handle;
	_mali_osk_lock_wait(session_data->lock, _MALI_OSK_LOCKMODE_RW);
	_mali_osk_list_add(&(session_memory_element->list), &(session_data->list_head_session_memory_list));
	_mali_osk_lock_signal(session_data->lock, _MALI_OSK_LOCKMODE_RW);
	ion_unmap_dma(ion_client_ump,ion_hnd);
	ion_free(ion_client_ump, ion_hnd);

	_mali_osk_free(blocks);

	user_interaction.secure_id = ump_dd_secure_id_get(ump_handle);
	user_interaction.size = ump_dd_size_get(ump_handle);
	user_interaction.ctx = NULL;

	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
	{
		/* If the copy fails then we should release the memory. We can use the IOCTL release to accomplish this */

		MSG_ERR(("copy_to_user() failed in ump_ioctl_allocate()\n"));

		return -EFAULT;
	}
	return 0; /* success */
}
_mali_osk_errcode_t _ump_ukk_allocate( _ump_uk_allocate_s *user_interaction )
{
	ump_session_data * session_data = NULL;
	ump_dd_mem *new_allocation = NULL;
	ump_session_memory_list_element * session_memory_element = NULL;
	int map_id;

	DEBUG_ASSERT_POINTER( user_interaction );
	DEBUG_ASSERT_POINTER( user_interaction->ctx );

	session_data = (ump_session_data *) user_interaction->ctx;

	session_memory_element = _mali_osk_calloc( 1, sizeof(ump_session_memory_list_element));
	if (NULL == session_memory_element)
	{
		DBG_MSG(1, ("Failed to allocate ump_session_memory_list_element in ump_ioctl_allocate()\n"));
		return _MALI_OSK_ERR_NOMEM;
	}


	new_allocation = _mali_osk_calloc( 1, sizeof(ump_dd_mem));
	if (NULL==new_allocation)
	{
		_mali_osk_free(session_memory_element);
		DBG_MSG(1, ("Failed to allocate ump_dd_mem in _ump_ukk_allocate()\n"));
		return _MALI_OSK_ERR_NOMEM;
	}

	/* Create a secure ID for this allocation */
	_mali_osk_lock_wait(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
	map_id = ump_descriptor_mapping_allocate_mapping(device.secure_id_map, (void*)new_allocation);

	if (map_id < 0)
	{
		_mali_osk_lock_signal(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
		_mali_osk_free(session_memory_element);
		_mali_osk_free(new_allocation);
		DBG_MSG(1, ("Failed to allocate secure ID in ump_ioctl_allocate()\n"));
		return - _MALI_OSK_ERR_INVALID_FUNC;
	}

	/* Initialize the part of the new_allocation that we know so for */
	new_allocation->secure_id = (ump_secure_id)map_id;
	_mali_osk_atomic_init(&new_allocation->ref_count,1);
	if ( 0==(UMP_REF_DRV_UK_CONSTRAINT_USE_CACHE & user_interaction->constraints) )
		 new_allocation->is_cached = 0;
	else new_allocation->is_cached = 1;

	/* special case a size of 0, we should try to emulate what malloc does in this case, which is to return a valid pointer that must be freed, but can't be dereferences */
	if (0 == user_interaction->size)
	{
		user_interaction->size = 1; /* emulate by actually allocating the minimum block size */
	}

	new_allocation->size_bytes = UMP_SIZE_ALIGN(user_interaction->size); /* Page align the size */
	new_allocation->lock_usage = UMP_NOT_LOCKED;

	/* Now, ask the active memory backend to do the actual memory allocation */
	if (!device.backend->allocate( device.backend->ctx, new_allocation ) )
	{
		DBG_MSG(3, ("OOM: No more UMP memory left. Failed to allocate memory in ump_ioctl_allocate(). Size: %lu, requested size: %lu\n", new_allocation->size_bytes, (unsigned long)user_interaction->size));
		ump_descriptor_mapping_free(device.secure_id_map, map_id);
		_mali_osk_lock_signal(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
		_mali_osk_free(new_allocation);
		_mali_osk_free(session_memory_element);
		return _MALI_OSK_ERR_INVALID_FUNC;
	}
	new_allocation->hw_device = _UMP_UK_USED_BY_CPU;
	new_allocation->ctx = device.backend->ctx;
	new_allocation->release_func = device.backend->release;

	_mali_osk_lock_signal(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);

	/* Initialize the session_memory_element, and add it to the session object */
	session_memory_element->mem = new_allocation;
	_mali_osk_lock_wait(session_data->lock, _MALI_OSK_LOCKMODE_RW);
	_mali_osk_list_add(&(session_memory_element->list), &(session_data->list_head_session_memory_list));
	_mali_osk_lock_signal(session_data->lock, _MALI_OSK_LOCKMODE_RW);

	user_interaction->secure_id = new_allocation->secure_id;
	user_interaction->size = new_allocation->size_bytes;
	DBG_MSG(3, ("UMP memory allocated. ID: %u, size: %lu\n", new_allocation->secure_id, new_allocation->size_bytes));

	return _MALI_OSK_ERR_OK;
}
UMP_KERNEL_API_EXPORT ump_dd_handle ump_dd_handle_create_from_phys_blocks(ump_dd_physical_block * blocks, unsigned long num_blocks)
{
	ump_dd_mem * mem;
	unsigned long size_total = 0;
	int map_id;
	u32 i;

	/* Go through the input blocks and verify that they are sane */
	for (i=0; i < num_blocks; i++)
	{
		unsigned long addr = blocks[i].addr;
		unsigned long size = blocks[i].size;

		DBG_MSG(5, ("Adding physical memory to new handle. Address: 0x%08lx, size: %lu\n", addr, size));
		size_total += blocks[i].size;

		if (0 != UMP_ADDR_ALIGN_OFFSET(addr))
		{
			MSG_ERR(("Trying to create UMP memory from unaligned physical address. Address: 0x%08lx\n", addr));
			return UMP_DD_HANDLE_INVALID;
		}

		if (0 != UMP_ADDR_ALIGN_OFFSET(size))
		{
			MSG_ERR(("Trying to create UMP memory with unaligned size. Size: %lu\n", size));
			return UMP_DD_HANDLE_INVALID;
		}
	}

	/* Allocate the ump_dd_mem struct for this allocation */
	mem = _mali_osk_malloc(sizeof(*mem));
	if (NULL == mem)
	{
		DBG_MSG(1, ("Could not allocate ump_dd_mem in ump_dd_handle_create_from_phys_blocks()\n"));
		return UMP_DD_HANDLE_INVALID;
	}

	/* Find a secure ID for this allocation */
	_mali_osk_lock_wait(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
	map_id = ump_descriptor_mapping_allocate_mapping(device.secure_id_map, (void*) mem);

	if (map_id < 0)
	{
		_mali_osk_lock_signal(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
		_mali_osk_free(mem);
		DBG_MSG(1, ("Failed to allocate secure ID in ump_dd_handle_create_from_phys_blocks()\n"));
		return UMP_DD_HANDLE_INVALID;
	}

	/* Now, make a copy of the block information supplied by the user */
	mem->block_array = _mali_osk_malloc(sizeof(ump_dd_physical_block)* num_blocks);
	if (NULL == mem->block_array)
	{
		ump_descriptor_mapping_free(device.secure_id_map, map_id);
		_mali_osk_lock_signal(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
		_mali_osk_free(mem);
		DBG_MSG(1, ("Could not allocate a mem handle for function ump_dd_handle_create_from_phys_blocks().\n"));
		return UMP_DD_HANDLE_INVALID;
	}

	_mali_osk_memcpy(mem->block_array, blocks, sizeof(ump_dd_physical_block) * num_blocks);

	/* And setup the rest of the ump_dd_mem struct */
	_mali_osk_atomic_init(&mem->ref_count, 1);
	mem->secure_id = (ump_secure_id)map_id;
	mem->size_bytes = size_total;
	mem->nr_blocks = num_blocks;
	mem->backend_info = NULL;
	mem->ctx = NULL;
	mem->release_func = phys_blocks_release;
	/* For now UMP handles created by ump_dd_handle_create_from_phys_blocks() is forced to be Uncached */
	mem->is_cached = 0;
	mem->hw_device = _UMP_UK_USED_BY_CPU;
	mem->lock_usage = UMP_NOT_LOCKED;

	_mali_osk_lock_signal(device.secure_id_map_lock, _MALI_OSK_LOCKMODE_RW);
	DBG_MSG(3, ("UMP memory created. ID: %u, size: %lu\n", mem->secure_id, mem->size_bytes));

	return (ump_dd_handle)mem;
}
void Power_StopUSBCharge(void)
{
    //DBG_MSG("  gIsUSBInsert=%d,gIsBattInsert=%d,gIsBattDead=%d,gIsUSBAdapter=%d\r\n",gIsUSBInsert,gIsBattInsert,gIsBattDead,gIsUSBAdapter);
    if (!gIsBattInsert)
    {
        DBG_DUMP("  NO Battery, Ignore STOP\r\n");
        return;
    }
#if _MIPS_TODO
    //#NT#2010/12/10#Jeah Yen -begin
    if((USB_GetSource() == USB_SRC_USB_ADAPTER) && (Power_GetSource() != POWER_SRC_USB_ADAPTER))
    {
        //Not charge yet, just start check low-battery
        DBG_DUMP("GxPower: Start low-battery check.\r\n");
        GxPower_SetControl(GXPWR_CTRL_BATTERY_DETECT_EN, TRUE);
    }
    //#NT#2010/12/10#Jeah Yen -end

    //#NT#2011/3/30#Jeah Yen -begin
    if((USB_GetSource() == USB_SRC_NONE) && (Power_GetSource() != POWER_SRC_USB_ADAPTER))
    {
        //Cannot charge, start check low-battery
        DBG_DUMP("GxPower: Start low-battery check.\r\n");
        GxPower_SetControl(GXPWR_CTRL_BATTERY_DETECT_EN, TRUE);
    }
    //#NT#2011/3/30#Jeah Yen -end

    if((USB_GetSource() == USB_SRC_USB_ADAPTER))
    {
        //DBG_MSG("  USB Src = Adaptor\r\n");
        GxPower_SetControl(GXPWR_CTRL_BATTERY_CHARGE_CURRENT,BATT_CHARGE_CURRENT_LOW);
        DBG_MSG("  Charge Current = %d\r\n", BATT_CHARGE_CURRENT_LOW);
    }
#endif
    if((USB_GetSource() == USB_SRC_USB_PC))
    {
        //DBG_MSG("  USB Src = PC\r\n");
        GxPower_SetControl(GXPWR_CTRL_BATTERY_CHARGE_CURRENT,BATT_CHARGE_CURRENT_LOW);
        DBG_MSG("  Charge Current = %d\r\n", BATT_CHARGE_CURRENT_LOW);
    }

    if (!GxPower_GetControl(GXPWR_CTRL_BATTERY_CHARGE_EN))
    {
        DBG_DUMP("  Already NOT Charge, Ignore STOP\r\n");
        return;
    }

    //#NT#2010/12/10#Jeah Yen -begin
    DBG_DUMP("GxPower: Stop to Charge Battery\r\n");
    GxPower_SetControl(GXPWR_CTRL_BATTERY_CHARGE_EN,FALSE);
#if _MIPS_TODO
    if(!gIsUSBChargePreCheck
        && (GxSystem_GetState(SYSTEM_STATE_POWERON) != SYSTEM_POWERON_CHARGE)
        )
    {
#if (USB_CHARGE_VERIFY == ENABLE)
#else
        GxLED_SetCtrl(KEYSCAN_LED_GREEN,SET_TOGGLE_LED,FALSE);
        GxLED_SetCtrl(KEYSCAN_LED_GREEN,TURNON_LED,TRUE);
#endif
        //GxLED_SetCtrl(KEYSCAN_LED_RED,SET_TOGGLE_LED,FALSE);
        //GxLED_SetCtrl(KEYSCAN_LED_RED,TURNON_LED,FALSE);
    }
#endif
    DBG_DUMP("GxPower: Start low-battery check.\r\n");
    GxPower_SetControl(GXPWR_CTRL_BATTERY_DETECT_EN, TRUE);
    // enable flash re-charge
    SxTimer_SetFuncActive(SX_TIMER_DET_RECHARGE_ID,TRUE);
    //#NT#2010/12/10#Jeah Yen -end

}
Exemple #13
0
/*
 * pOpenFontTableFile - open the Font translation file
 * Copy the file to the proper place if necessary.
 *
 * Returns the file pointer or NULL
 */
FILE *
pOpenFontTableFile(void)
{
    FILE	*pFileR, *pFileW;
    char	*szFontNamesFile;
    size_t	tSize;
    BOOL	bFailed;
    char	acBuffer[256];

    pFileR = fopen("<AntiWord$FontNamesFile>", "r");
    if (pFileR != NULL) {
        /* The font table is already in the right directory */
        return pFileR;
    }

    szFontNamesFile = getenv("AntiWord$FontNamesSave");
    if (szFontNamesFile == NULL) {
        werr(0, "Warning: Name of the FontNames file not found");
        return NULL;
    }
    DBG_MSG(szFontNamesFile);

    pFileR = fopen("<AntiWord$Dir>.Resources.Default", "r");
    if (pFileR == NULL) {
        werr(0, "I can't find 'Resources.Default'");
        return NULL;
    }
    /* Here the default font translation table is known to exist */

    if (!bMakeDirectory(szFontNamesFile)) {
        werr(0,
             "I can't make a directory for the FontNames file");
        return NULL;
    }
    /* Here the proper directory is known to exist */

    pFileW = fopen(szFontNamesFile, "w");
    if (pFileW == NULL) {
        (void)fclose(pFileR);
        werr(0, "I can't create a default FontNames file");
        return NULL;
    }
    /* Here the proper directory is known to be writeable */

    /* Copy the default FontNames file */
    bFailed = FALSE;
    while (!feof(pFileR)) {
        tSize = fread(acBuffer, 1, sizeof(acBuffer), pFileR);
        if (ferror(pFileR)) {
            DBG_MSG("Read error");
            bFailed = TRUE;
            break;
        }
        if (fwrite(acBuffer, 1, tSize, pFileW) != tSize) {
            DBG_MSG("Write error");
            bFailed = TRUE;
            break;
        }
    }
    (void)fclose(pFileW);
    (void)fclose(pFileR);
    if (bFailed) {
        DBG_MSG("Copying the FontNames file failed");
        (void)remove(szFontNamesFile);
        return NULL;
    }
    return fopen(szFontNamesFile, "r");
} /* end of pOpenFontTableFile */
Exemple #14
0
//------------------------------------------------------------------------------
//!
bool
BIH::trace( const Rayf& ray, Hit& hit, IntersectFunc intersect, void* data ) const
{
   DBG_BLOCK( os_bih_trace, "BIH::trace(" << ray.origin() << ray.direction() << " hit: t=" << hit._t << " id=" << hit._id << ")" );
   if( _nodes.empty() )
   {
      return false;
   }

   Vec3f invDir = ray.direction().getInversed(); 

   // Compute traversal order.
   uint order[3];
   order[0] = invDir(0) >= 0.0f ? 0 : 1;
   order[1] = invDir(1) >= 0.0f ? 0 : 1;
   order[2] = invDir(2) >= 0.0f ? 0 : 1;

   float tmin  = 0.0f;
   float tmax  = hit._t;
   bool impact = false;


   // Traverse tree.
   Vector<TraversalStackNode> stack( _maxDepth );
   uint stackID = 0;
   const Node* node = &_nodes[0];

   while( 1 )
   {
      DBG_MSG( os_bih_trace, "Visiting " << *node );
      if( node->isInteriorNode() )
      {
         uint axis     = node->axis();
         float tplane0 = ( node->_plane[order[axis]] - ray.origin()(axis)) * invDir(axis);
         float tplane1 = ( node->_plane[1-order[axis]] - ray.origin()(axis)) * invDir(axis);

         // Clip node.
         if( node->isClipNode() )
         {
            // FIXME: we could probably do better (not traversing this node).
            node = &_nodes[node->index()];
            tmin = CGM::max( tmin, tplane0 );
            tmax = CGM::min( tmax, tplane1 );
            continue;
         }

         bool traverse0 = tmin < tplane0;
         bool traverse1 = tmax > tplane1;

         if( traverse0 )
         {
            if( traverse1 )
            {
               stack[stackID++].set(
                  &_nodes[node->index() + 1-order[axis]],
                  CGM::max( tmin, tplane1 ),
                  tmax
               );
            }
            node = &_nodes[node->index() + order[axis]];
            tmax = CGM::min( tmax, tplane0 );
         }
         else
         {
            if( traverse1 )
            {
               node = &_nodes[node->index() + 1-order[axis]];
               tmin = CGM::max( tmin, tplane1 );
            }
            else
            {
               // Unstack.
               do
               {
                  if( stackID == 0 )
                  {
                     return impact;
                  }
                  stack[--stackID].get( node, tmin, tmax );
                  tmax = CGM::min( tmax, hit._t );
               } while( tmin > tmax );
            }
         }

      }
      else
      {
         // We are in a leaf node.
         // Intersects all primitives in it.
         uint numElems = node->_numElements;
         uint id       = node->index();
         for( uint i = 0; i < numElems; ++i, ++id )
         {
            if( intersect( ray, _ids[id], hit._t, data ) )
            {
               impact  = true;
               hit._id = _ids[id];
            }
         }

         // Unstack.
         do
         {
            if( stackID == 0 )
            {
               return impact;
            }
            stack[--stackID].get( node, tmin, tmax );
            tmax = CGM::min( tmax, hit._t );
         } while( tmin > tmax );
      }
   }
}
Exemple #15
0
/*
 * Translate the rowinfo to a member of the row_info enumeration
 */
row_info_enum
eGet8RowInfo(int iFodo,
	const UCHAR *aucGrpprl, int iBytes, row_block_type *pRow)
{
	int	iFodoOff, iInfoLen;
	int	iIndex, iSize, iCol;
	int	iPosCurr, iPosPrev;
	USHORT	usTmp;
	BOOL	bFound2416_0, bFound2416_1, bFound2417_0, bFound2417_1;
	BOOL	bFound244b_0, bFound244b_1, bFound244c_0, bFound244c_1;
	BOOL	bFoundd608;

	fail(iFodo < 0 || aucGrpprl == NULL || pRow == NULL);

	iFodoOff = 0;
	bFound2416_0 = FALSE;
	bFound2416_1 = FALSE;
	bFound2417_0 = FALSE;
	bFound2417_1 = FALSE;
	bFound244b_0 = FALSE;
	bFound244b_1 = FALSE;
	bFound244c_0 = FALSE;
	bFound244c_1 = FALSE;
	bFoundd608 = FALSE;
	while (iBytes >= iFodoOff + 2) {
		iInfoLen = 0;
		switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
		case 0x2416:	/* fInTable */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound2416_1 = TRUE;
			} else {
				bFound2416_0 = TRUE;
			}
			break;
		case 0x2417:	/* fTtp */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound2417_1 = TRUE;
			} else {
				bFound2417_0 = TRUE;
			}
			break;
		case 0x244b:	/* sub-table fInTable */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound244b_1 = TRUE;
			} else {
				bFound244b_0 = TRUE;
			}
			break;
		case 0x244c:	/* sub-table fTtp */
			if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
				bFound244c_1 = TRUE;
			} else {
				bFound244c_0 = TRUE;
			}
			break;
		case 0x6424:	/* brcTop */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_TOP;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_TOP;
			}
			break;
		case 0x6425:	/* brcLeft */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_LEFT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_LEFT;
			}
			break;
		case 0x6426:	/* brcBottom */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_BOTTOM;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_BOTTOM;
			}
			break;
		case 0x6427:	/* brcRight */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			usTmp &= 0xff00;
			NO_DBG_DEC(usTmp >> 8);
			if (usTmp == 0) {
				pRow->ucBorderInfo &= ~TABLE_BORDER_RIGHT;
			} else {
				pRow->ucBorderInfo |= TABLE_BORDER_RIGHT;
			}
			break;
		case 0xd606:	/* cDefTable10 */
			DBG_MSG("0xd606: sprmTDefTable10");
			iSize = (int)usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			DBG_DEC(iSize);
			break;
		case 0xd608:	/* cDefTable */
			iSize = (int)usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			if (iSize < 6 || iBytes < iFodoOff + 8) {
				DBG_DEC(iSize);
				DBG_DEC(iFodoOff);
				iInfoLen = 2;
				break;
			}
			iCol = (int)ucGetByte(iFodo + iFodoOff + 4, aucGrpprl);
			if (iCol < 1 ||
			    iBytes < iFodoOff + 4 + (iCol + 1) * 2) {
				DBG_DEC(iCol);
				DBG_DEC(iFodoOff);
				iInfoLen = 2;
				break;
			}
			if (iCol >= (int)elementsof(pRow->asColumnWidth)) {
				DBG_DEC(iCol);
				werr(1, "The number of columns is corrupt");
			}
			pRow->ucNumberOfColumns = (UCHAR)iCol;
			iPosPrev = (int)(short)usGetWord(
					iFodo + iFodoOff + 5,
					aucGrpprl);
			for (iIndex = 0; iIndex < iCol; iIndex++) {
				iPosCurr = (int)(short)usGetWord(
					iFodo + iFodoOff + 7 + iIndex * 2,
					aucGrpprl);
				pRow->asColumnWidth[iIndex] =
						(short)(iPosCurr - iPosPrev);
				iPosPrev = iPosCurr;
			}
			bFoundd608 = TRUE;
			break;
		default:
			break;
		}
		if (iInfoLen <= 0) {
			iInfoLen =
				iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
			fail(iInfoLen <= 0);
		}
		iFodoOff += iInfoLen;
	}

	if (bFound2417_1 && bFoundd608) {
		return found_end_of_row;
	}
	if (bFound2417_0 && !bFoundd608) {
		return found_not_end_of_row;
	}
	if (bFound2416_1 || bFound244b_1) {
		return found_a_cell;
	}
	if (bFound2416_0 || bFound244b_0) {
		return found_not_a_cell;
	}
	return found_nothing;
} /* end of eGet8RowInfo */
Exemple #16
0
void UIDisplay_Init(UINT8 iDD, BOOL bClear, ISIZE* pDeviceSize)
{
    RESULT r;
    LAYER_INIT LayerInit;

    UINT32 uiBufAddr;
    //fixed buffer size
    UINT32 osd_w = OSD_W;
    UINT32 osd_h = OSD_H;
    //fixed buffer size
    UINT32 vdo_w = OSD_W;
    UINT32 vdo_h = OSD_H;
    //ISIZE DeviceSize;
    LAYER_INIT* pLayerInit = (LAYER_INIT*)&LayerInit; //layer init parameter
    //DeviceSize = GxVideo_GetDeviceSize(DOUT1);
    ISIZE DeviceSize = pDeviceSize[0];

    DBG_MSG("DOUT=%d\n\r",iDD>>4);
    switch(iDD & 0x0f) //check layer
    {
    case LAYER_OSD1:

        uiBufAddr = OS_GetMempoolAddr(POOL_ID_DISP_OSD1);

        pLayerInit->uiType = TYPE_FB;
        pLayerInit->uiPxlfmt = DISPLAY_OSD_FMT;
        pLayerInit->uiWidth = osd_w;
        pLayerInit->uiHeight = osd_h;
#if (OSD_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->uiBufCount = 1;
pLayerInit->uiSwapEffect = SWAPEFFECT_COPY;
#else
pLayerInit->uiBufCount = 0;
pLayerInit->uiSwapEffect = SWAPEFFECT_DISCARD;
#endif
switch(pLayerInit->uiPxlfmt)
{
case PXLFMT_INDEX1: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>3; 
break;
case PXLFMT_INDEX2: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>2; 
break;
case PXLFMT_INDEX4: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>1; 
break;
case PXLFMT_INDEX8: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>0; 
break;
}
pLayerInit->pBufAddr[0] = uiBufAddr;
#if (OSD_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->pBufAddr[1] = uiBufAddr + pLayerInit->uiBufSize;
#else
pLayerInit->pBufAddr[1] = 0;
#endif
pLayerInit->pBufAddr[2] = 0;
//dynamic window size
pLayerInit->win.x= 0;
pLayerInit->win.y = 0;
pLayerInit->win.w = DeviceSize.w;
pLayerInit->win.h = DeviceSize.h;
pLayerInit->uiWinAttr = 0;

#if (OSD_USE_ROTATE_BUFFER == ENABLE)
if(gbOsdRotate == 1)
{
DBG_MSG("^YEnable Rotate\r\n");
//prepare show DC
UINT32 buf_w = pLayerInit->uiWidth;
UINT32 buf_h = pLayerInit->uiHeight;
UINT32 win_w = pLayerInit->win.w;
UINT32 win_h = pLayerInit->win.h;
pLayerInit->uiWidth = buf_h;
pLayerInit->uiHeight = buf_w;
pLayerInit->uiBufCount = 0;
pLayerInit->uiSwapEffect = SWAPEFFECT_DISCARD;
pLayerInit->pBufAddr[0] = uiBufAddr;
pLayerInit->pBufAddr[1] = 0;
pLayerInit->pBufAddr[2] = 0;
pLayerInit->win.w = win_h;
pLayerInit->win.h = win_w;

        //prepare paint DC
        memset(pPaintDC, 0, sizeof(DC));
        GxGfx_AttachDC(pPaintDC, TYPE_FB,
                       pLayerInit->uiPxlfmt, buf_w, buf_h, buf_w,
                       (UINT8*)(uiBufAddr + pLayerInit->uiBufSize), 0, 0);
    }
    else
    {
        DBG_MSG("^YDisable Rotate\r\n");
    }
#endif

    r = GxDisplay_InitLayer(iDD, &LayerInit, bClear);
    UI_DirtyDisplaySource(iDD); //must force flush to update new swap-buffer and new swap-effect
    DBG_MSG("OSD1 buf=%08x, size=%08x\n\r",LayerInit.pBufAddr[0], LayerInit.uiBufSize);
    DBG_MSG("OSD1 buf.w=%d, buf.h=%d;\n\r",LayerInit.uiWidth, LayerInit.uiHeight);
    DBG_MSG("OSD1 win.w=%d, win.h=%d;\n\r",LayerInit.win.w, LayerInit.win.h);


    break;

case LAYER_OSD2:

    uiBufAddr = OS_GetMempoolAddr(POOL_ID_DISP_OSD2);

    pLayerInit->uiType = TYPE_FB;
    pLayerInit->uiPxlfmt = DISPLAY_OSD_FMT;
    pLayerInit->uiWidth = osd_w;
    pLayerInit->uiHeight = osd_h;
#if (OSD2_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->uiBufCount = 1;
pLayerInit->uiSwapEffect = SWAPEFFECT_COPY;
#else
pLayerInit->uiBufCount = 0;
pLayerInit->uiSwapEffect = SWAPEFFECT_DISCARD;
#endif
switch(pLayerInit->uiPxlfmt)
{
case PXLFMT_INDEX1: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>3; 
break;
case PXLFMT_INDEX2: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>2; 
break;
case PXLFMT_INDEX4: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>1; 
break;
case PXLFMT_INDEX8: 
pLayerInit->uiBufSize = (osd_w*osd_h)>>0; 
break;
}
pLayerInit->pBufAddr[0] = uiBufAddr;
#if (OSD2_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->pBufAddr[1] = uiBufAddr + pLayerInit->uiBufSize;
#else
pLayerInit->pBufAddr[1] = 0;
#endif
pLayerInit->pBufAddr[2] = 0;
//dynamic window size
pLayerInit->win.x= 0;
pLayerInit->win.y = 0;
pLayerInit->win.w = DeviceSize.w;
pLayerInit->win.h = DeviceSize.h;
pLayerInit->uiWinAttr = 0;

    r = GxDisplay_InitLayer(iDD, &LayerInit, bClear);
    DBG_MSG("OSD2 buf=%08x, size=%08x\n\r",LayerInit.pBufAddr[0], LayerInit.uiBufSize);
    DBG_MSG("OSD2 buf.w=%d, buf.h=%d;\n\r",LayerInit.uiWidth, LayerInit.uiHeight);
    DBG_MSG("OSD2 win.w=%d, win.h=%d;\n\r",LayerInit.win.w, LayerInit.win.h);

    break;

case LAYER_VDO1:

    uiBufAddr = OS_GetMempoolAddr(POOL_ID_DISP_VDO1);

    pLayerInit->uiType = TYPE_FB;
    pLayerInit->uiPxlfmt = DISPLAY_VDO_FMT;
    pLayerInit->uiWidth = vdo_w;
    pLayerInit->uiHeight = vdo_h;
#if (VDO_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->uiBufCount = 1;
pLayerInit->uiSwapEffect = SWAPEFFECT_COPY;
#else
pLayerInit->uiBufCount = 0;
pLayerInit->uiSwapEffect = SWAPEFFECT_DISCARD;
#endif
switch(pLayerInit->uiPxlfmt)
{
case PXLFMT_YUV422:
case PXLFMT_YUV422_PK:
pLayerInit->uiBufSize = (vdo_w*vdo_h)*2 + 64; 
break;
break;
default: 
DBG_ERR("Pxlfmt %d",pLayerInit->uiPxlfmt);

}
pLayerInit->pBufAddr[0] = uiBufAddr;
#if (VDO_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->pBufAddr[1] = uiBufAddr + pLayerInit->uiBufSize;
#else
pLayerInit->pBufAddr[1] = 0;
#endif
pLayerInit->pBufAddr[2] = 0;
//dynamic window size
pLayerInit->win.x= 0;
pLayerInit->win.y = 0;
pLayerInit->win.w = DeviceSize.w;
pLayerInit->win.h = DeviceSize.h;
pLayerInit->uiWinAttr = 0;

r = GxDisplay_InitLayer(iDD, &LayerInit, bClear);
DBG_MSG("VDO1 buf=%08x, size=%08x\n\r",LayerInit.pBufAddr[0], LayerInit.uiBufSize);
DBG_MSG("VDO1 buf.w=%d, buf.h=%d;\n\r",LayerInit.uiWidth, LayerInit.uiHeight);
DBG_MSG("VDO1 win.w=%d, win.h=%d;\n\r",LayerInit.win.w, LayerInit.win.h);

break;

case LAYER_VDO2:

uiBufAddr = OS_GetMempoolAddr(POOL_ID_DISP_VDO2);

pLayerInit->uiType = TYPE_FB;
pLayerInit->uiPxlfmt = DISPLAY_VDO_FMT;
pLayerInit->uiWidth = vdo_w;
pLayerInit->uiHeight = vdo_h;
#if (VDO2_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->uiBufCount = 1;
pLayerInit->uiSwapEffect = SWAPEFFECT_COPY;
#else
pLayerInit->uiBufCount = 0;
pLayerInit->uiSwapEffect = SWAPEFFECT_DISCARD;
#endif
switch(pLayerInit->uiPxlfmt)
{
case PXLFMT_YUV422:
case PXLFMT_YUV422_PK: 
pLayerInit->uiBufSize = (vdo_w*vdo_h)*2 + 64;
break;
default: 
DBG_ERR("Pxlfmt %d",pLayerInit->uiPxlfmt);
}
pLayerInit->pBufAddr[0] = uiBufAddr;
#if (VDO2_USE_DOUBLE_BUFFER == ENABLE)
pLayerInit->pBufAddr[1] = uiBufAddr + pLayerInit->uiBufSize;
#else
pLayerInit->pBufAddr[1] = 0;
#endif
pLayerInit->pBufAddr[2] = 0;
pLayerInit->win.x = 0;
pLayerInit->win.y = 0;
pLayerInit->win.w = DeviceSize.w;
pLayerInit->win.h = DeviceSize.h;
pLayerInit->uiWinAttr = 0;

r = GxDisplay_InitLayer(iDD, &LayerInit, bClear);
DBG_MSG("VDO2 buf1=%08x, size=%08x\n\r",LayerInit.pBufAddr[0], LayerInit.uiBufSize);
DBG_MSG("VDO2 buf2=%08x, size=%08x\n\r",LayerInit.pBufAddr[1], LayerInit.uiBufSize);
DBG_MSG("VDO2 buf.w=%d, buf.h=%d;\n\r",LayerInit.uiWidth, LayerInit.uiHeight);
DBG_MSG("VDO2 win.w=%d, win.h=%d;\n\r",LayerInit.win.w, LayerInit.win.h);

break;
}
}
Exemple #17
0
/*
 * Build the list with List Information for Word 8/9/10/11 files
 */
void
vGet8LstInfo(FILE *pFile, const pps_info_type *pPPS,
	const ULONG *aulBBD, size_t tBBDLen,
	const ULONG *aulSBD, size_t tSBDLen,
	const UCHAR *aucHeader)
{
	list_block_type	tList;
	const ULONG	*aulBlockDepot;
	UCHAR	*aucLfoInfo, *aucLstfInfo, *aucPapx, *aucXString;
	ULONG	ulBeginLfoInfo, ulBeginLstfInfo, ulBeginLvlfInfo;
	ULONG	ulListID, ulStart;
	size_t	tBlockDepotLen, tBlockSize;
	size_t	tLfoInfoLen, tLstfInfoLen, tPapxLen, tXstLen, tOff;
	size_t	tLstfRecords, tStart, tIndex;
	int	iNums;
	USHORT	usIstd;
	UCHAR	ucTmp, ucListLevel, ucMaxLevel, ucChpxLen;
	UCHAR	aucLvlfInfo[28], aucXst[2];

	fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
	fail(aulBBD == NULL || aulSBD == NULL);

	NO_DBG_DEC(pPPS->tTable.ulSB);
	NO_DBG_HEX(pPPS->tTable.ulSize);
	if (pPPS->tTable.ulSize == 0) {
		DBG_MSG("No list information");
		return;
	}

	if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
		/* Use the Small Block Depot */
		aulBlockDepot = aulSBD;
		tBlockDepotLen = tSBDLen;
		tBlockSize = SMALL_BLOCK_SIZE;
	} else {
		/* Use the Big Block Depot */
		aulBlockDepot = aulBBD;
		tBlockDepotLen = tBBDLen;
		tBlockSize = BIG_BLOCK_SIZE;
	}

	/* LFO (List Format Override) */
	ulBeginLfoInfo = ulGetLong(0x2ea, aucHeader); /* fcPlfLfo */
	DBG_HEX(ulBeginLfoInfo);
	tLfoInfoLen = (size_t)ulGetLong(0x2ee, aucHeader); /* lcbPlfLfo */
	DBG_DEC(tLfoInfoLen);
	if (tLfoInfoLen == 0) {
		DBG_MSG("No lists in this document");
		return;
	}

	aucLfoInfo = xmalloc(tLfoInfoLen);
	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucLfoInfo, ulBeginLfoInfo, tLfoInfoLen)) {
		aucLfoInfo = xfree(aucLfoInfo);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucLfoInfo, tLfoInfoLen);
	vBuildLfoList(aucLfoInfo, tLfoInfoLen);
	aucLfoInfo = xfree(aucLfoInfo);

	/* LSTF (LiST data on File) */
	ulBeginLstfInfo = ulGetLong(0x2e2, aucHeader); /* fcPlcfLst */
	DBG_HEX(ulBeginLstfInfo);
	tLstfInfoLen = (size_t)ulGetLong(0x2e6, aucHeader); /* lcbPlcfLst */
	DBG_DEC(tLstfInfoLen);
	if (tLstfInfoLen == 0) {
		DBG_MSG("No list data on file");
		return;
	}

	aucLstfInfo = xmalloc(tLstfInfoLen);
	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
			aulBlockDepot, tBlockDepotLen, tBlockSize,
			aucLstfInfo, ulBeginLstfInfo, tLstfInfoLen)) {
		aucLstfInfo = xfree(aucLstfInfo);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucLstfInfo, tLstfInfoLen);

	tLstfRecords = (size_t)usGetWord(0, aucLstfInfo);
	if (2 + tLstfRecords * 28 < tLstfInfoLen) {
		DBG_DEC(2 + tLstfRecords * 28);
		DBG_DEC(tLstfInfoLen);
		aucLstfInfo = xfree(aucLstfInfo);
		return;
	}

	/* LVLF (List leVeL on File) */
	ulBeginLvlfInfo = ulBeginLstfInfo + tLstfInfoLen;
	DBG_HEX(ulBeginLvlfInfo);

	aucXString = NULL;
	ulStart = ulBeginLvlfInfo;

	for (tIndex = 0, tStart = 2;
	     tIndex < tLstfRecords;
	     tIndex++, tStart += 28) {
		ulListID = ulGetLong(tStart, aucLstfInfo);
		NO_DBG_HEX(ulListID);
		ucTmp = ucGetByte(tStart + 26, aucLstfInfo);
		ucMaxLevel = odd(ucTmp) ? 1 : 9;
		for (ucListLevel = 0; ucListLevel < ucMaxLevel; ucListLevel++) {
			fail(aucXString != NULL);
			usIstd = usGetWord(
					tStart + 8 + 2 * (size_t)ucListLevel,
					aucLstfInfo);
			DBG_DEC_C(usIstd != STI_NIL, usIstd);
			NO_DBG_HEX(ulStart);
			(void)memset(&tList, 0, sizeof(tList));
			/* Read the lvlf (List leVeL on File) */
			if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
					aulBlockDepot, tBlockDepotLen,
					tBlockSize, aucLvlfInfo,
					ulStart, sizeof(aucLvlfInfo))) {
				aucLstfInfo = xfree(aucLstfInfo);
				return;
			}
			NO_DBG_PRINT_BLOCK(aucLvlfInfo, sizeof(aucLvlfInfo));
			if (bAllZero(aucLvlfInfo, sizeof(aucLvlfInfo))) {
				tList.ulStartAt = 1;
				tList.ucNFC = 0x00;
				tList.bNoRestart = FALSE;
			} else {
				tList.ulStartAt = ulGetLong(0, aucLvlfInfo);
				tList.ucNFC = ucGetByte(4, aucLvlfInfo);
				ucTmp = ucGetByte(5, aucLvlfInfo);
				tList.bNoRestart = (ucTmp & BIT(3)) != 0;
				DBG_MSG_C((ucTmp & BIT(4)) != 0 &&
					(ucTmp & BIT(6)) != 0, "Found one");
			}
			ulStart += sizeof(aucLvlfInfo);
			tPapxLen = (size_t)ucGetByte(25, aucLvlfInfo);
			if (tPapxLen != 0) {
				aucPapx = xmalloc(tPapxLen);
				/* Read the Papx */
				if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
						aulBlockDepot, tBlockDepotLen,
						tBlockSize, aucPapx,
						ulStart, tPapxLen)) {
					aucPapx = xfree(aucPapx);
					aucLstfInfo = xfree(aucLstfInfo);
					return;
				}
				NO_DBG_PRINT_BLOCK(aucPapx, tPapxLen);
				tList.sLeftIndent =
					sGetLeftIndent(aucPapx, tPapxLen);
				aucPapx = xfree(aucPapx);
			}
			ulStart += tPapxLen;
			ucChpxLen = ucGetByte(24, aucLvlfInfo);
			ulStart += (ULONG)ucChpxLen;
			/* Read the length of the XString */
			if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
					aulBlockDepot, tBlockDepotLen,
					tBlockSize, aucXst,
					ulStart, sizeof(aucXst))) {
				aucLstfInfo = xfree(aucLstfInfo);
				return;
			}
			NO_DBG_PRINT_BLOCK(aucXst, sizeof(aucXst));
			tXstLen = (size_t)usGetWord(0, aucXst);
			ulStart += sizeof(aucXst);
			if (tXstLen == 0) {
				tList.usListChar = DEFAULT_LISTCHAR;
				vAdd2ListInfoList(ulListID,
						usIstd,
						ucListLevel,
						&tList);
				continue;
			}
			tXstLen *= 2;	/* Length in chars to length in bytes */
			aucXString = xmalloc(tXstLen);
			/* Read the XString */
			if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
					aulBlockDepot, tBlockDepotLen,
					tBlockSize, aucXString,
					ulStart, tXstLen)) {
				aucXString = xfree(aucXString);
				aucLstfInfo = xfree(aucLstfInfo);
				return;
			}
			NO_DBG_PRINT_BLOCK(aucXString, tXstLen);
			tOff = 0;
			for (iNums = 6; iNums < 15; iNums++) {
				ucTmp = ucGetByte(iNums, aucLvlfInfo);
				if (ucTmp == 0) {
					break;
				}
				tOff = (size_t)ucTmp;
			}
			tOff *= 2;	/* Offset in chars to offset in bytes */
			NO_DBG_DEC(tOff);
			if (tList.ucNFC == LIST_SPECIAL ||
			    tList.ucNFC == LIST_SPECIAL2 ||
			    tList.ucNFC == LIST_BULLETS) {
				tList.usListChar = usGetWord(0, aucXString);
			} else if (tOff != 0 && tOff < tXstLen) {
				tList.usListChar = usGetWord(tOff, aucXString);
			} else {
				tList.usListChar = DEFAULT_LISTCHAR;
			}
			vAdd2ListInfoList(ulListID,
					usIstd,
					ucListLevel,
					&tList);
			ulStart += tXstLen;
			aucXString = xfree(aucXString);
		}
	}
	aucLstfInfo = xfree(aucLstfInfo);
} /* end of vGet8LstInfo */
Exemple #18
0
void System_OnStrgInit_FWS(void)
{
    BOOL bLZC = FALSE;
    ER er;
    UINT32 m_LdLoadedOffest;
    DX_HANDLE pStrgDev = 0;

    DBG_MSG("Init!\r\n");
    DBG_IND("^M LD_BLOCK=%d\r\n", gBinInfo.ld.LdBlockCount);
    DBG_IND("^M FW_MAX_SIZE=%08X\r\n", gBinInfo.ld.FWResvSize);
    DBG_IND("^MFW_validate-update:");
    //ValidateUpdateFW
    {
        UINT32 bUpdate = ((gBinInfo.ld.LdCtrl2 & LDCF_UPDATE_FW)!=0);
        UINT32 uiUpdateResult = ((gBinInfo.ld.LdCtrl2 & LDCF_UPDATE_FW_DONE)!=0);
        if(bUpdate)
        {
            DBG_IND("\r\n^MFW is just updated.\r\n");
            if(!uiUpdateResult)
            {
                DBG_FATAL("\r\nFW updated: fail!\r\n");
            }
        }
    }
    DBG_IND("^M ok\r\n");


    pStrgDev = Dx_GetObject(DX_CLASS_STORAGE_EXT|DX_TYPE_NAND0);

    #if (_INTERSTORAGE_==_INTERSTORAGE_SPI_)
    bLZC = TRUE;
    #else
    bLZC = FALSE;
    #endif

    if(bLZC)
    {
        gPL_Init.PlInit.DataType = PARTLOAD_DATA_TYPE_COMPRESS_LZ;
        gPL_BufAddr = OS_GetMempoolAddr(POOL_ID_APP);
        gPL_BufSize = POOL_SIZE_APP;
    }
    else
    {
        gPL_Init.PlInit.DataType = PARTLOAD_DATA_TYPE_UNCOMPRESS;
        gPL_BufAddr = OS_GetMempoolAddr(POOL_ID_FWS_BUFFER);
        gPL_BufSize = POOL_SIZE_FWS_BUFFER;
    }

    m_LdLoadedOffest = gBinInfo.ld.LdLoadSize; //Get Ld loaded size

    gPL_Init.uiApiVer = FWSRV_API_VERSION;
    gPL_Init.TaskID = 0;
    gPL_Init.SemID = 0;
    gPL_Init.FlagID = 0;
    gPL_Init.PlInit.uiApiVer = PARTLOAD_API_VERSION;
    gPL_Init.PlInit.hStrg = pStrgDev;
    gPL_Init.PlInit.uiAddrBegin = OS_GetMemAddr(MEM_CODE)+m_LdLoadedOffest; //Must be block boundary align
    gPL_Init.PlInit.uiWorkingAddr = gPL_BufAddr;
    gPL_Init.PlInit.uiWorkingSize = gPL_BufSize;
    er = FwSrv_Init(&gPL_Init);
    if(er != FWSRV_ER_OK)
    {
        DBG_ERR("Init failed!\r\n");
    }
    er = FwSrv_Open();
    if(er != FWSRV_ER_OK)
    {
        DBG_ERR("Open failed!\r\n");
    }
}
Exemple #19
0
vpp_timing_t *vout_find_video_mode(int no,vout_info_t *info)
{
	vout_t *vo;
	char *edid = 0;
	unsigned int vo_option;
	vpp_timing_t *p_timing = 0;
	unsigned int opt = 0;
	int index = 0;
	vpp_timing_t *edid_timing = 0;

	if( (vo = vout_get_entry(no)) == 0 )
		return 0;

//	if( vo->num != VPP_VOUT_NUM_HDMI )	// wm3445 simulate dual display
	{
	if( info->fixed_timing ){
		p_timing = info->fixed_timing;
		DBG_MSG("%d(fixed timer)\n",no);
		goto find_video_mode;
	}
	}

	vo_option = vo->option[1];
	DBG_MSG("(%d,%dx%d@%d,%d),%s\n",no,info->resx,info->resy,info->pixclk,info->fps,(vo_option & VOUT_OPT_INTERLACE)?"i":"p");
	if( vo->status & VPP_VOUT_STS_PLUGIN ){
		if( (edid = vout_get_edid(no)) ){
			if( edid_parse(edid,&vo->edid_info) == 0 ){
				edid = 0;
			}
			else {
				opt = info->fps | ((vo_option & VOUT_OPT_INTERLACE)? EDID_TMR_INTERLACE:0);
				if( edid_find_support(&vo->edid_info,info->resx,info->resy,opt,&edid_timing) ){
					if( edid_timing ){
						p_timing = edid_timing;
						DBG_MSG("Use EDID detail timing\n");
						goto find_video_mode;
					}
				}
			}
		}
	}

	do {
		p_timing = vpp_get_video_mode(info->resx,info->resy,info->pixclk,&index);
		DBG_MSG("find(%dx%d@%d) -> %dx%d\n",info->resx,info->resy,info->pixclk,p_timing->hpixel,p_timing->vpixel);
		info->resx = p_timing->hpixel;
		info->resy = p_timing->vpixel;
		if( p_timing->option & VPP_OPT_INTERLACE ){
			info->resy *= 2;
		}
		info->fps = VPP_GET_OPT_FPS(p_timing->option);
		opt = info->fps | ((vo_option & VOUT_OPT_INTERLACE)? EDID_TMR_INTERLACE:0);
		if( edid == 0 )
			break;

		DBG_MSG("find edid %dx%d@%d%s\n",info->resx,info->resy,info->fps,(opt & EDID_TMR_INTERLACE)?"i":"p");
		if( edid_find_support(&vo->edid_info,info->resx,info->resy,opt,&edid_timing) ){
			break;
		}

		opt = info->fps | ((vo_option & VOUT_OPT_INTERLACE)? 0:EDID_TMR_INTERLACE);
		DBG_MSG("find edid %dx%d@%d%s\n",info->resx,info->resy,info->fps,(opt & EDID_TMR_INTERLACE)?"i":"p");
		if( edid_find_support(&vo->edid_info,info->resx,info->resy,opt,&edid_timing) ){
			break;
		}

		if( (info->resx <= vpp_video_mode_table[0].hpixel) || (index <=1) ){
			info->resx = vpp_video_mode_table[0].hpixel;
			info->resy = vpp_video_mode_table[0].vpixel;
			break;
		}
		
		do {
			index--;
			p_timing = (vpp_timing_t *) &vpp_video_mode_table[index];
			if( info->resx == p_timing->hpixel ){
				int vpixel;

				vpixel = p_timing->vpixel;
				if( p_timing->option & VPP_OPT_INTERLACE ){
					vpixel *= 2;
					index--;
				}
				if( info->resy == vpixel ){
					continue;
				}
			}
			break;
		} while(1);
		info->resx = vpp_video_mode_table[index].hpixel;
		info->resy = vpp_video_mode_table[index].vpixel;
		if(vpp_video_mode_table[index].option & VPP_OPT_INTERLACE){
			info->resy *= 2;
		}
	} while(1);

	if( edid_timing ){
		p_timing = edid_timing;
		DBG_MSG("Use EDID detail timing\n");
	}
	else {
		if( opt & EDID_TMR_INTERLACE )
			vo_option |= VOUT_OPT_INTERLACE;
		else 
			vo_option &= ~VOUT_OPT_INTERLACE;
		
		p_timing = vpp_get_video_mode_ext(info->resx,info->resy,info->fps,vo_option);
	}
find_video_mode:
	{
		int hpixel,vpixel;
		
		info->resx = p_timing->hpixel;
		info->resy = p_timing->vpixel;
		hpixel = p_timing->hpixel + p_timing->hsync + p_timing->hfp + p_timing->hbp;
		vpixel = p_timing->vpixel + p_timing->vsync + p_timing->vfp + p_timing->vbp;
		if( p_timing->option & VPP_OPT_INTERLACE ) {
			info->resy *= 2;
//			vpixel *= 2;
		}
		info->pixclk = p_timing->pixel_clock;
		info->fps = info->pixclk / (hpixel * vpixel);
		info->resx_virtual = vpp_calc_fb_width(g_vpp.mb_colfmt,info->resx);
		info->resy_virtual = info->resy;
	}
	DBG_MSG("Leave (%dx%d@%d,%d)\n",p_timing->hpixel,p_timing->vpixel,p_timing->pixel_clock,info->fps);
	return p_timing;
}
Exemple #20
0
void System_OnStrg_DownloadFW(UINT32* SecOrderTable, void (*LoadCallback)(const UINT32 Idx))
{
    BOOL bEnablePartload = FALSE;
    int nSect = 0;
    DBG_MSG("Init!\r\n");

    DBG_DUMP("^G[LOAD-FW]\r\n");
    nSect = OS_GetMemSectionCount(MEM_CODE);  //How to get last section ZI
    DBG_DUMP("^GTotal Sections = %d\r\n", nSect);
    if(LoadCallback)
        LoadCallback(CODE_SECTION_01);
    DBG_IND("^M P1_LOAD_SIZE=%08X, TIME=%d\r\n", gBinInfo.ld.LdLoadSize, gBinInfo.ld.LdLoadTime);

    DBG_IND("^MPL_check_Ld:\r\n");
    DBG_IND("^M PL_EN=%08X\r\n", gBinInfo.ld.LdCtrl & LDCF_PARTLOAD_EN);
    DBG_IND("^M LZ_EN=%08X\r\n", gBinInfo.head.BinCtrl & HDCF_LZCOMPRESS_EN);
    bEnablePartload = ((gBinInfo.ld.LdCtrl & LDCF_PARTLOAD_EN)!=0);

    if(!bEnablePartload)
        return;

    DBG_IND("^MPL_validate-p1-range:");
    //ValidatePartOne
    {
        // Make Sure: Partloader start (PART-2 start) <= Loader loaded end
        int i;
        UINT32 FwSize = 0;
        UINT32 uiDestAddress = OS_GetMemAddr(MEM_CODE)+gBinInfo.ld.LdLoadSize;
        if((uiDestAddress != 0) && (uiDestAddress < OS_GetMemAddr(1)))
        {
            DBG_FATAL("PART_TWO start (%08x) > PART_ONE loaded end (%08x)!\r\n",
                OS_GetMemAddr(1), uiDestAddress );
        }

        // Make Sure: Partloader end (PART-last end) <= MEM_CODE end
        for(i=0;i<nSect;i++)
        {
            DBG_IND("Sect%d: Addr:%08X, Size:%08X\r\n",i,OS_GetMemAddr(i),OS_GetMemSize(i));
            FwSize += OS_GetMemSize(i);
        }
        if (OS_GetMemAddr(0)+FwSize > OS_GetMemAddr(MEM_CODE)+OS_GetMemSize(MEM_CODE))
        {
            DBG_FATAL("PART_LAST end (%08x) > MEM_CODE end (%08x)!\r\n",
                OS_GetMemAddr(0)+FwSize, OS_GetMemAddr(MEM_CODE)+OS_GetMemSize(MEM_CODE));
        }
    }
    DBG_IND("^M ok\r\n");

    DBG_DUMP("^MPL_begin\r\n");
    {
        ER er;
        gPL_In.puiIdxSequence = SecOrderTable;
        gPL_In.fpLoadedCb = LoadCallback;
        gPL_Cmd.Idx = FWSRV_CMD_IDX_PL_LOAD_BURST; //continue load
        gPL_Cmd.In.pData = &gPL_In;
        gPL_Cmd.In.uiNumByte = sizeof(gPL_In);
        gPL_Cmd.Prop.bExitCmdFinish = TRUE;
        er = FwSrv_Cmd(&gPL_Cmd);
        if(er != FWSRV_ER_OK)
        {
            DBG_ERR("Process failed!\r\n");
        }
    }
    DBG_DUMP("^MPL_end\r\n");
}
/* This is a copy of _ump_osk_msync from drivers/amlogic/gpu/ump/linux/ump_osk_low_level_mem.c
 * with adapted parameters */
static void meson_drm_ump_osk_msync(struct drm_gem_cma_object *cma_obj, void *virt, u32 offset, size_t size, enum drm_meson_msync_op op, struct meson_drm_session_data *session_data)
{
	struct drm_gem_object *gem_obj;
	u32 start_p, end_p;

	/* Flush L1 using virtual address, the entire range in one go.
	 * Only flush if user space process has a valid write mapping on given address. */
	if ((cma_obj) && (virt != NULL) && (access_ok(VERIFY_WRITE, virt, size))) {
		__cpuc_flush_dcache_area(virt, size);
		DBG_MSG(3, ("meson_drm_ump_osk_msync(): Flushing CPU L1 Cache. CPU address: %x, size: %x\n", virt, size));
	} else {
		if (session_data) {
			if (op == DRM_MESON_MSYNC_FLUSH_L1) {
				DBG_MSG(4, ("meson_drm_ump_osk_msync(): Pending %d L1 cache flushes\n", session_data->has_pending_level1_cache_flush));
				session_data->has_pending_level1_cache_flush = 0;
				level1_cache_flush_all();
				return;
			} else {
				if (session_data->cache_operations_ongoing) { /* This is set in cache_operations_control(start) */
					session_data->has_pending_level1_cache_flush++;
					DBG_MSG(4, ("meson_drm_ump_osk_msync(): Defering L1 cache flush (%d pending)\n" session_data->has_pending_level1_cache_flush));
				} else {
					/* Flushing the L1 cache for each switch_user() if ump_cache_operations_control(START) is not called */
					level1_cache_flush_all();
				}
			}
		} else {
			DBG_MSG(4, ("Unkown state %s %d\n", __FUNCTION__, __LINE__));
			level1_cache_flush_all();
		}
	}

	if (!cma_obj)
		return;
	gem_obj = &cma_obj->base;

	DBG_MSG(3, ("meson_drm_ump_osk_msync(): Flushing CPU L2 Cache\n"));

	/* Flush L2 using physical addresses
	 * Our allocations are always contiguous (GEM CMA), so we have only one mem block */

	if (offset >= gem_obj->size) {
		offset -= gem_obj->size;
		return;
	}

	if (offset) {
		start_p = (u32)cma_obj->paddr + offset;
		/* We'll zero the offset later, after using it to calculate end_p. */
	} else {
		start_p = (u32)cma_obj->paddr;
	}

	if (size < gem_obj->size - offset) {
		end_p = start_p + size;
		size = 0;
	} else {
		if (offset) {
			end_p = start_p + (gem_obj->size - offset);
			size -= gem_obj->size - offset;
			offset = 0;
		} else {
			end_p = start_p + gem_obj->size;
			size -= gem_obj->size;
		}
	}

	switch (op) {
	case DRM_MESON_MSYNC_CLEAN:
		outer_clean_range(start_p, end_p);
		break;
	case DRM_MESON_MSYNC_CLEAN_AND_INVALIDATE:
		outer_flush_range(start_p, end_p);
		break;
	case DRM_MESON_MSYNC_INVALIDATE:
		outer_inv_range(start_p, end_p);
		break;
	default:
		break;
	}

	return;
}
static int block_allocator_allocate(void* ctx, ump_dd_mem * mem)
{
	block_allocator * allocator;
	u32 left;
	block_info * last_allocated = NULL;
	int i = 0;

	BUG_ON(!ctx);
	BUG_ON(!mem);

	allocator = (block_allocator*)ctx;
	left = mem->size_bytes;

	BUG_ON(!left);
	BUG_ON(!&allocator->mutex);

	mem->nr_blocks = ((left + UMP_BLOCK_SIZE - 1) & ~(UMP_BLOCK_SIZE - 1)) / UMP_BLOCK_SIZE;
	mem->block_array = (ump_dd_physical_block*)vmalloc(sizeof(ump_dd_physical_block) * mem->nr_blocks);
	if (NULL == mem->block_array) {
		MSG_ERR(("Failed to allocate block array\n"));
		return 0;
	}

	if (down_interruptible(&allocator->mutex)) {
		MSG_ERR(("Could not get mutex to do block_allocate\n"));
		return 0;
	}

	mem->size_bytes = 0;

	while ((left > 0) && (allocator->first_free)) {
		block_info * block;

		block = allocator->first_free;
		allocator->first_free = allocator->first_free->next;
		block->next = last_allocated;
		last_allocated = block;
		allocator->num_free--;

		mem->block_array[i].addr = get_phys(allocator, block);
		mem->block_array[i].size = UMP_BLOCK_SIZE;
		mem->size_bytes += UMP_BLOCK_SIZE;

		i++;

		if (left < UMP_BLOCK_SIZE) left = 0;
		else left -= UMP_BLOCK_SIZE;
	}

	if (left) {
		block_info * block;
		/* release all memory back to the pool */
		while (last_allocated) {
			block = last_allocated->next;
			last_allocated->next = allocator->first_free;
			allocator->first_free = last_allocated;
			last_allocated = block;
			allocator->num_free++;
		}

		vfree(mem->block_array);
		mem->backend_info = NULL;
		mem->block_array = NULL;

		DBG_MSG(4, ("Could not find a mem-block for the allocation.\n"));
		up(&allocator->mutex);

		return 0;
	}

	mem->backend_info = last_allocated;

	up(&allocator->mutex);
	mem->is_cached=0;

	return 1;
}
Exemple #23
0
void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t Device_Error) 
{
    DBG_MSG("Error: %d", Device_Error);
}
Exemple #24
0
void ICACHE_FLASH_ATTR config_set(serverConnData *conn, uint8_t argc, char *argv[]){
    bool err = false;
    cJSON * config = NULL;
    cJSON * lastchild = NULL;
    char *stmp = NULL;

    DBG_MSG("config_set argc: %d\r\n", argc);
    if (argc == 0)
        espbuffsentprintf(conn, "Usage: set <key> [value]\r\nUse help for more details\r\n");
    else if (argc == 1) {
        // Delete config
        DBG_MSG("Delete config %s\r\n", argv[1]);
        config = get_parent_by_key(jconfig_root, argv[1], &stmp);
        if (config != NULL) lastchild = cJSON_GetObjectItem(config, stmp);
        DBG_MSG("config: %p, stmp: %p\r\n", config, stmp);
        if (config == NULL) {
            espbuffsentprintf(conn, "Could not found parent config with key [%s].\r\n", argv[1]);
        }else if(lastchild == NULL) {
            espbuffsentprintf(conn, "Could not found lastchild config with key [%s].\r\n", argv[1]);
        } else {
            char *tmp;
            DBG_MSG("Delete %s from %s.\r\n", lastchild->string, config->string);
            cJSON_DeleteItemFromObject(config, lastchild->string);
            tmp = cJSON_PrintUnformatted(config);
            espbuffsentstring(conn, "Deleted. Now content is:\r\n");
            espbuffsentstring(conn, tmp);
            os_free(tmp);
        }
    } else {
        // Update config value
        char value[255];
        uint8_t i;
        uint32_t idx = 0;

        os_bzero(value, sizeof(value));
        for (i=2; i<=argc; ++i) {
            DBG_MSG("argv[%d] = %s.\r\n", i, argv[i]);
            os_sprintf(value + idx, "%s ", argv[i]);
            idx += os_strlen(argv[i]) + 1;
        }
        value[idx - 1] = 0;
        DBG_MSG("Update config %s to %s.\r\n", argv[1], value);
        config = get_parent_by_key(jconfig_root, argv[1], &stmp);
        DBG_MSG("config: %p, stmp: %p\r\n", config, stmp);
        if (config == NULL) {
            espbuffsentprintf(conn, "Could not found parent config with key [%s].\r\n", argv[1]);
        }else if (stmp == NULL) {
            espbuffsentprintf(conn, "Could not found last config with key [%s].\r\n", argv[1]);
        } else {
            char *tmp;
            int i;
            cJSON *newchild = NULL;

            DBG_MSG("stmp: %s, valuetype: %c.\r\n", stmp, value[0]);
            lastchild = cJSON_GetObjectItem(config, stmp);
            DBG_MSG("lastchild: %p.\r\n", lastchild);
            switch (value[0]) {
                case 'i':
                if (os_strlen(value) < 2) {
                    espbuffsentstring(conn, "value is invalid format: i10\r\n");
                    break;
                }
                i = atoi(&value[1]);
                newchild = cJSON_CreateNumber(i);
                break;
                case 's':
                if (os_strlen(value) < 2) {
                    espbuffsentstring(conn, "value is invalid format: slamp\r\n");
                    break;
                }
                newchild = cJSON_CreateString(&value[1]);
                DBG_MSG("Create item: %s -> %p.\r\n", &value[1], newchild);
                break;
                default:
                    espbuffsentstring(conn, "value is invalid format\r\n");
                    newchild = NULL;
                break;
            }

            if (newchild != NULL) {
                if (lastchild != NULL) {
                    cJSON_ReplaceItemInObject(config, lastchild->string, newchild);
                } else {
                    DBG_MSG("Add config %s to %s.\r\n", stmp, config->string);
                    cJSON_AddItemToObject(config, stmp, newchild);
                }
                tmp = cJSON_PrintUnformatted(config);
                espbuffsentstring(conn, "Updated. Now content is:\r\n");
                espbuffsentstring(conn, tmp);
                os_free(tmp);
            }
        }
    }
    if (err)
        espbuffsentstring(conn, MSG_ERROR);
    else
        espbuffsentstring(conn, MSG_OK);
}
Exemple #25
0
/*
 * Build the list with footnote text information for Word 6/7 files
 */
static void
vGet6FootnotesText(FILE *pFile, ULONG ulStartBlock,
	const ULONG *aulBBD, size_t tBBDLen,
	const UCHAR *aucHeader)
{
	footnote_local_type	*pCurr;
	UCHAR	*aucBuffer;
	ULONG	ulCharPos, ulBeginOfFootnotes, ulOffset, ulBeginFootnoteText;
	size_t	tFootnoteTextLen;
	size_t	tIndex;

	TRACE_MSG("vGet6FootnotesText");

	fail(pFile == NULL || aucHeader == NULL);
	fail(ulStartBlock > MAX_BLOCKNUMBER && ulStartBlock != END_OF_CHAIN);
	fail(aulBBD == NULL);

	ulBeginOfFootnotes = ulGetLong(0x18, aucHeader); /* fcMin */
	ulBeginOfFootnotes += ulGetLong(0x34, aucHeader); /* ccpText */
	NO_DBG_HEX(ulBeginOfFootnotes);

	ulBeginFootnoteText = ulGetLong(0x70, aucHeader); /* fcPlcffndTxt */
	NO_DBG_HEX(ulBeginFootnoteText);
	tFootnoteTextLen =
		(size_t)ulGetLong(0x74, aucHeader); /* lcbPlcffndTxt */
	NO_DBG_DEC(tFootnoteTextLen);

	if (tFootnoteTextLen < 12) {
		DBG_MSG("No Footnote text in this document");
		return;
	}

	aucBuffer = xmalloc(tFootnoteTextLen);
	if (!bReadBuffer(pFile, ulStartBlock,
			aulBBD, tBBDLen, BIG_BLOCK_SIZE,
			aucBuffer, ulBeginFootnoteText, tFootnoteTextLen)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	NO_DBG_PRINT_BLOCK(aucBuffer, tFootnoteTextLen);

	fail(tFootnoteTextLength != 0);
	tFootnoteTextLength = tFootnoteTextLen / 4 - 2;
	fail(tFootnoteTextLength == 0);

	fail(pFootnoteText != NULL);
	pFootnoteText = xcalloc(tFootnoteTextLength,
				sizeof(footnote_local_type));

	for (tIndex = 0; tIndex < tFootnoteTextLength; tIndex++) {
		pCurr = pFootnoteText + tIndex;
		pCurr->tInfo.szText = NULL;
		ulOffset = ulGetLong(tIndex * 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfFootnotes + ulOffset;
		NO_DBG_HEX(ulCharPos);
		NO_DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosStart = ulCharPos;
		ulOffset = ulGetLong(tIndex * 4 + 4, aucBuffer);
		NO_DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfFootnotes + ulOffset;
		NO_DBG_HEX(ulCharPos);
		NO_DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosNext = ulCharPos;
		pCurr->bUseful = pCurr->ulCharPosStart != pCurr->ulCharPosNext;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet6FootnotesText */
Exemple #26
0
void ICACHE_FLASH_ATTR ota_upgrade(serverConnData *conn, uint8_t argc, char *argv[]) {
    espbuffsentprintf(conn, "START OTA UPGRADE...CUR ROM: %d.\r\n", ROMNUM);

    if (argc == 0)
        espbuffsentstring(conn, "OTA <SRV IP> <PORT> <FOLDER PATH>\r\n");
    else if (argc != 3)
        espbuffsentstring(conn, MSG_ERROR);
    else {
        uint16_t port = atoi(argv[2]);
        uint8_t iparr[4];
        uint8_t i;
        char tmp[4];
        char* pCurIp = argv[1];
        char * ch;

        DBG_MSG("OTA UPGRADE with IP:%s, port:%d, path:%s.\r\n", argv[1], argv[2], argv[3]);
        for (i=0; i<protocol_idx; ++i) {
            DBG_MSG("protocol_disconnect res: %d, index: %d\r\n", protocol_disconnect(&protocol_list[i]), i);
        }
        ch = strchr(pCurIp, '.');

        DBG_MSG("First: %s\r\n", pCurIp);
        DBG_MSG("After: %s\r\n", ch);

        for (i = 0; i < 4; ++i) {
            if (i < (ch - pCurIp + 1)) {
                tmp[i] = pCurIp[i];
            } else {
                tmp[i] = 0;
            }
        }
        iparr[0] = atoi(tmp);
        pCurIp = ch + 1;

        ch = strchr(pCurIp, '.');
        DBG_MSG("First: %s\r\n", pCurIp);
        DBG_MSG("After: %s\r\n", ch);
        for (i = 0; i < 4; ++i) {
            if (i < (ch - pCurIp + 1)) {
                tmp[i] = pCurIp[i];
            } else {
                tmp[i] = 0;
            }
        }
        iparr[1] = atoi(tmp);
        pCurIp = ch + 1;

        ch = strchr(pCurIp, '.');
        DBG_MSG("First: %s\r\n", pCurIp);
        DBG_MSG("After: %s\r\n", ch);
        for (i = 0; i < 4; ++i) {
            if (i < (ch - pCurIp + 1)) {
                tmp[i] = pCurIp[i];
            } else {
                tmp[i] = 0;
            }
        }
        iparr[2] = atoi(tmp);
        pCurIp = ch + 1;

        ch = strchr(pCurIp, '.');
        DBG_MSG("First: %s\r\n", pCurIp);
        DBG_MSG("After: %s\r\n", ch);
        for (i = 0; i < 4; ++i) {
            if (i < (argv[1] + strlen(argv[1]) - pCurIp + 1)) {
                tmp[i] = pCurIp[i];
            } else {
                tmp[i] = 0;
            }
        }
        iparr[3] = atoi(tmp);

        DBG_MSG("=> IP: %d %d %d %d\r\n", iparr[0], iparr[1], iparr[2], iparr[3]);

        if ((port == 0)||(port>65535)) {
             espbuffsentstring(conn, MSG_ERROR);
        } else {
            espbuffsentstring(conn, MSG_OK);
            handleUpgrade(2, iparr, port, argv[3]);
        }
    }
}
Exemple #27
0
/*
 * Build the list with footnote information for Word for DOS files
 */
static void
vGet0FootnotesInfoAndText(FILE *pFile, const UCHAR *aucHeader)
{
	footnote_local_type	*pCurr;
	UCHAR	*aucBuffer;
	ULONG	ulFileOffset, ulBeginOfText, ulOffset, ulBeginFootnoteInfo;
	ULONG	ulCharPos, ulBeginNextBlock;
	size_t	tFootnotes, tFootnoteInfoLen;
	size_t	tIndex;
	UCHAR   aucTmp[2];

	TRACE_MSG("vGet0FootnotesInfoAndText");

	fail(pFile == NULL || aucHeader == NULL);

	ulBeginOfText = 128;
	NO_DBG_HEX(ulBeginOfText);
	ulBeginFootnoteInfo =  128 * (ULONG)usGetWord(0x14, aucHeader);
	DBG_HEX(ulBeginFootnoteInfo);
	ulBeginNextBlock = 128 * (ULONG)usGetWord(0x16, aucHeader);
	DBG_HEX(ulBeginNextBlock);

	if (ulBeginFootnoteInfo == ulBeginNextBlock) {
		DBG_MSG("No Footnotes in this document");
		return;
	}

	/* Read the the number of footnotes + 1 */
	if (!bReadBytes(aucTmp, 2, ulBeginFootnoteInfo, pFile)) {
		return;
	}
	tFootnotes = (size_t)usGetWord(0, aucTmp);
	if (tFootnotes < 2) {
		DBG_MSG("No Footnotes in this document (2)");
	}
	DBG_DEC(tFootnotes);
	tFootnoteInfoLen =  8 * tFootnotes;

	aucBuffer = xmalloc(tFootnoteInfoLen);
	if (!bReadBytes(aucBuffer,
			tFootnoteInfoLen, ulBeginFootnoteInfo + 4, pFile)) {
		aucBuffer = xfree(aucBuffer);
		return;
	}
	DBG_PRINT_BLOCK(aucBuffer, tFootnoteInfoLen);

	/* Get footnote information */
	fail(tFootnoteListLength != 0);
	tFootnoteListLength = tFootnotes - 1;
	fail(tFootnoteListLength == 0);

	fail(aulFootnoteList != NULL);
	aulFootnoteList = xcalloc(tFootnoteListLength, sizeof(ULONG));

	for (tIndex = 0; tIndex < tFootnoteListLength; tIndex++) {
		ulOffset = ulGetLong(tIndex * 8, aucBuffer);
		DBG_HEX(ulOffset);
		ulFileOffset = ulCharPos2FileOffset(ulBeginOfText + ulOffset);
		DBG_HEX(ulFileOffset);
		aulFootnoteList[tIndex] = ulFileOffset;
	}

	/* Get footnote text */
	fail(tFootnoteTextLength != 0);
	tFootnoteTextLength = tFootnotes - 1;
	fail(tFootnoteTextLength == 0);

	fail(pFootnoteText != NULL);
	pFootnoteText = xcalloc(tFootnoteTextLength,
				sizeof(footnote_local_type));

	for (tIndex = 0; tIndex < tFootnoteTextLength; tIndex++) {
		pCurr = pFootnoteText + tIndex;
		pCurr->tInfo.szText = NULL;
		ulOffset = ulGetLong(tIndex * 8 + 4, aucBuffer);
		DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfText + ulOffset;
		DBG_HEX(ulCharPos);
		DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosStart = ulCharPos;
		ulOffset = ulGetLong((tIndex + 1) * 8 + 4, aucBuffer);
		DBG_HEX(ulOffset);
		ulCharPos = ulBeginOfText + ulOffset;
		DBG_HEX(ulCharPos);
		DBG_HEX(ulCharPos2FileOffset(ulCharPos));
		pCurr->ulCharPosNext = ulCharPos;
		pCurr->bUseful = pCurr->ulCharPosStart != pCurr->ulCharPosNext;
	}
	aucBuffer = xfree(aucBuffer);
} /* end of vGet0FootnotesInfoAndText */
Exemple #28
0
/*
 * Fill the font information block with information
 * from a Word 8/9/10/11 file.
 */
void
vGet8FontInfo(int iFodo, USHORT usIstd,
	const UCHAR *aucGrpprl, int iBytes, font_block_type *pFont)
{
	long	lTmp;
	int	iFodoOff, iInfoLen;
	USHORT	usFtc0, usFtc1, usFtc2, usTmp;
	UCHAR	ucTmp;

	fail(iFodo < 0 || aucGrpprl == NULL || pFont == NULL);

	usFtc0 = USHRT_MAX;
	usFtc1 = USHRT_MAX;
	usFtc2 = USHRT_MAX;

	iFodoOff = 0;
	while (iBytes >= iFodoOff + 2) {
		switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
		case 0x0800:	/* fRMarkDel */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			if (ucTmp == 0) {
				pFont->usFontStyle &= ~FONT_MARKDEL;
			} else {
				pFont->usFontStyle |= FONT_MARKDEL;
			}
			break;
		case 0x0835:	/* fBold */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			switch (ucTmp) {
			case   0:	/* Unset */
				pFont->usFontStyle &= ~FONT_BOLD;
				break;
			case   1:	/* Set */
				pFont->usFontStyle |= FONT_BOLD;
				break;
			case 128:	/* Unchanged */
				break;
			case 129:	/* Negation */
				pFont->usFontStyle ^= FONT_BOLD;
				break;
			default:
				DBG_DEC(ucTmp);
				DBG_FIXME();
				break;
			}
			break;
		case 0x0836:	/* fItalic */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			switch (ucTmp) {
			case   0:	/* Unset */
				pFont->usFontStyle &= ~FONT_ITALIC;
				break;
			case   1:	/* Set */
				pFont->usFontStyle |= FONT_ITALIC;
				break;
			case 128:	/* Unchanged */
				break;
			case 129:	/* Negation */
				pFont->usFontStyle ^= FONT_ITALIC;
				break;
			default:
				DBG_DEC(ucTmp);
				DBG_FIXME();
				break;
			}
			break;
		case 0x0837:	/* fStrike */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			switch (ucTmp) {
			case   0:	/* Unset */
				pFont->usFontStyle &= ~FONT_STRIKE;
				break;
			case   1:	/* Set */
				pFont->usFontStyle |= FONT_STRIKE;
				break;
			case 128:	/* Unchanged */
				break;
			case 129:	/* Negation */
				pFont->usFontStyle ^= FONT_STRIKE;
				break;
			default:
				DBG_DEC(ucTmp);
				DBG_FIXME();
				break;
			}
			break;
		case 0x083a:	/* fSmallCaps */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			switch (ucTmp) {
			case   0:	/* Unset */
				pFont->usFontStyle &= ~FONT_SMALL_CAPITALS;
				break;
			case   1:	/* Set */
				pFont->usFontStyle |= FONT_SMALL_CAPITALS;
				break;
			case 128:	/* Unchanged */
				break;
			case 129:	/* Negation */
				pFont->usFontStyle ^= FONT_SMALL_CAPITALS;
				break;
			default:
				DBG_DEC(ucTmp);
				DBG_FIXME();
				break;
			}
			break;
		case 0x083b:	/* fCaps */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			switch (ucTmp) {
			case   0:	/* Unset */
				pFont->usFontStyle &= ~FONT_CAPITALS;
				break;
			case   1:	/* Set */
				pFont->usFontStyle |= FONT_CAPITALS;
				break;
			case 128:	/* Unchanged */
				break;
			case 129:	/* Negation */
				pFont->usFontStyle ^= FONT_CAPITALS;
				break;
			default:
				DBG_DEC(ucTmp);
				DBG_FIXME();
				break;
			}
			break;
		case 0x083c:	/* fVanish */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			switch (ucTmp) {
			case   0:	/* Unset */
				pFont->usFontStyle &= ~FONT_HIDDEN;
				break;
			case   1:	/* Set */
				pFont->usFontStyle |= FONT_HIDDEN;
				break;
			case 128:	/* Unchanged */
				break;
			case 129:	/* Negation */
				pFont->usFontStyle ^= FONT_HIDDEN;
				break;
			default:
				DBG_DEC(ucTmp);
				DBG_FIXME();
				break;
			}
			break;
		case 0x2a32:	/* cDefault */
			pFont->usFontStyle &= FONT_HIDDEN;
			pFont->ucFontColor = FONT_COLOR_DEFAULT;
			break;
		case 0x2a33:	/* cPlain */
			DBG_MSG("2a33: cPlain");
			vFillFontFromStylesheet(usIstd, pFont);
			break;
		case 0x2a3e:	/* cKul */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			if (ucTmp == 0 || ucTmp == 5) {
				pFont->usFontStyle &= ~FONT_UNDERLINE;
			} else {
				NO_DBG_MSG("Underline text");
				pFont->usFontStyle |= FONT_UNDERLINE;
				if (ucTmp == 6) {
					DBG_MSG("Bold text");
					pFont->usFontStyle |= FONT_BOLD;
				}
			}
			break;
		case 0x2a42:	/* cIco */
			pFont->ucFontColor =
				ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pFont->ucFontColor);
			break;
		case 0x2a44:	/* cHpsInc */
			DBG_MSG("0x2a44: sprmCHpsInc");
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			DBG_DEC(ucTmp);
			break;
		case 0x2a48:	/* cIss */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			ucTmp &= 0x07;
			if (ucTmp == 1) {
				pFont->usFontStyle |= FONT_SUPERSCRIPT;
				NO_DBG_MSG("Superscript");
			} else if (ucTmp == 2) {
				pFont->usFontStyle |= FONT_SUBSCRIPT;
				NO_DBG_MSG("Subscript");
			}
			break;
		case 0x4a30:	/* cIstd */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(usTmp);
			break;
		case 0x4a43:	/* cHps */
			pFont->usFontSize =
				usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			NO_DBG_DEC(pFont->usFontSize);
			break;
		case 0x4a4d:	/* cHpsMul */
			DBG_MSG("0x4a4d: sprmCHpsMul");
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			DBG_DEC(usTmp);
			break;
		case 0x4a4f:	/* cFtc0 */
			usFtc0 = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			break;
		case 0x4a50:	/* cFtc1 */
			usFtc1 = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			break;
		case 0x4a51:	/* cFtc2 */
			usFtc2 = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			break;
		case 0xca47:	/* cMajority */
			DBG_MSG("0xca47: sprmCMajority");
			break;
		case 0xca4a:	/* cHpsInc1 */
			usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
			lTmp = (long)pFont->usFontSize + (long)usTmp;
			if (lTmp < 8) {
				pFont->usFontSize = 8;
			} else if (lTmp > 32766) {
				pFont->usFontSize = 32766;
			} else {
				pFont->usFontSize = (USHORT)lTmp;
			}
			break;
		case 0xca4c:	/* cMajority50 */
			DBG_MSG("0xca4c: sprmCMajority50");
			break;
		case 0xea3f:	/* cHps, cHpsPos */
			ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
			DBG_DEC(ucTmp);
			if (ucTmp != 0) {
				pFont->usFontSize = (USHORT)ucTmp;
			}
			ucTmp = ucGetByte(iFodo + iFodoOff + 3, aucGrpprl);
			DBG_DEC(ucTmp);
			break;
		default:
			break;
		}
		iInfoLen = iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
		fail(iInfoLen <= 0);
		iFodoOff += iInfoLen;
	}

	/* Combine the Ftc's to a FontNumber */
	NO_DBG_DEC_C(usFtc0 != USHRT_MAX, usFtc0);
	NO_DBG_DEC_C(usFtc2 != USHRT_MAX, usFtc2);
	NO_DBG_DEC_C(usFtc1 != USHRT_MAX, usFtc1);
	if (usFtc0 <= 0x7fff) {
		if (usFtc0 <= (USHORT)UCHAR_MAX) {
			pFont->ucFontNumber = (UCHAR)usFtc0;
		} else {
			DBG_DEC(usFtc0);
			DBG_FIXME();
			pFont->ucFontNumber = 0;
		}
	} else if (usFtc2 <= 0x7fff) {
		if (usFtc2 <= (USHORT)UCHAR_MAX) {
			pFont->ucFontNumber = (UCHAR)usFtc2;
		} else {
			DBG_DEC(usFtc2);
			DBG_FIXME();
			pFont->ucFontNumber = 0;
		}
	} else if (usFtc1 <= 0x7fff) {
		if (usFtc1 <= (USHORT)UCHAR_MAX) {
			pFont->ucFontNumber = (UCHAR)usFtc1;
		} else {
			DBG_DEC(usFtc1);
			DBG_FIXME();
			pFont->ucFontNumber = 0;
		}
	}
} /* end of vGet8FontInfo */
static UINT32 DrvPower_GetBatteryLevel(void)
{
    static UINT32   uiPreBatteryLvl    = DRVPWR_BATTERY_LVL_UNKNOWN;
    static UINT32   uiPreBatteryADC    = 0;
    static UINT32   uiRetBatteryLvl;
    static UINT32   uiEmptycount =0;
    static UINT32   uiCount = 0;
    UINT32          uiCurBatteryADC, uiCurBatteryLvl,i;
    BOOL            isMatch = FALSE;

    uiCurBatteryLvl = 0;
    if(uiPreBatteryLvl== DRVPWR_BATTERY_LVL_UNKNOWN)
    {
        uiCurBatteryADC = DrvPower_GetBatteryADC();
        uiPreBatteryADC = DrvPower_GetBatteryADC()-1;
        for (i = 0; i<BATT_SLIDE_WINDOW_COUNT; i++)
        {
            uiBattADCSlideWin[i] = uiCurBatteryADC;
            DBG_MSG("AVG=%d\r\n",uiCurBatteryADC);
        }
    }
    else
    {

        uiCurSlideWinCnt = BATT_SLIDE_WINDOW_COUNT;
        uiBattADCSlideWin[uiBattSlideIdx++] = DrvPower_GetBatteryADC();
        if (uiBattSlideIdx >= uiCurSlideWinCnt)
        {
            uiBattSlideIdx = 0;
        }
        uiCurBatteryADC = 0;
        for (i = 0; i<uiCurSlideWinCnt; i++)
        {
            uiCurBatteryADC+=uiBattADCSlideWin[i];
            DBG_MSG("A[%d]=%d,",i,uiBattADCSlideWin[i]);
        }
        uiCurBatteryADC/=uiCurSlideWinCnt;
        DBG_MSG("AVG=%d",uiCurBatteryADC);
        DBG_MSG(", V=%d",uiCurBatteryADC*42/9100);
        DBG_MSG(".%02d\r\n",(uiCurBatteryADC*42/91)%100);
    }

    //DBG_IND("%d,%d,%d\r\n",VOLDET_BATTERY_ADC_LVL0,VOLDET_BATTERY_ADC_LVL1,VOLDET_BATTERY_ADC_LVL2);
    // Rising
    if (uiCurBatteryADC > uiPreBatteryADC)
    {
        for (i=BATT_LEVEL_COUNT; i>0; i--)
        {
            if (uiCurBatteryADC > pBattAdcLevelValue[i-1])
            {
                uiCurBatteryLvl = i;
                isMatch = TRUE;
                break;
            }
        }
        if (isMatch != TRUE)
        {
            uiCurBatteryLvl = 0;
        }
    }
    // Falling
    else
    {
        for (i=BATT_LEVEL_COUNT; i>0; i--)
        {
            if (uiCurBatteryADC > pBattAdcLevelValue[i-1])
            {
                uiCurBatteryLvl = i;
                isMatch = TRUE;
                break;
            }
        }
        if (isMatch != TRUE)
        {
            uiCurBatteryLvl = 0;
        }
    }
    // Debounce
    if ((uiCurBatteryLvl == uiPreBatteryLvl) ||
            (uiPreBatteryLvl == DRVPWR_BATTERY_LVL_UNKNOWN))
    {
        uiRetBatteryLvl = uiCurBatteryLvl;
    }
    uiPreBatteryLvl = uiCurBatteryLvl;
    uiPreBatteryADC = uiCurBatteryADC;

    if(uiCount % 2 == 0)
    {
        uiRetBatteryLvl = uiPreBatteryLvl;
    }
    uiCount++;
    //
    if(uiEmptycount|| uiRetBatteryLvl == DRVPWR_BATTERY_LVL_0)
    {
        uiEmptycount++;
        if (uiEmptycount >= 15)
        {
            return DRVPWR_BATTERY_LVL_EMPTY;
        }
    }

    return uiRetBatteryLvl;
}
Exemple #30
0
int
main(int argc, char **argv)
{
	options_type	tOptions;
	const char	*szWordfile;
	int	iFirst, iIndex, iGoodCount;
	BOOL	bUsage, bMultiple, bUseTXT, bUseXML;

	if (argc <= 0) {
		return EXIT_FAILURE;
	}

	szTask = szBasename(argv[0]);

	if (argc <= 1) {
		iFirst = 1;
		bUsage = TRUE;
	} else {
		iFirst = iReadOptions(argc, argv);
		bUsage = iFirst <= 0;
	}
	if (bUsage) {
		vUsage();
		return iFirst < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

#if defined(N_PLAT_NLM) && !defined(_VA_LIST)
	nwinit();
#endif /* N_PLAT_NLM && !_VA_LIST */

	vGetOptions(&tOptions);

#if !defined(__dos)
	if (is_locale_utf8()) {
#if defined(__STDC_ISO_10646__)
		/*
		 * If the user wants UTF-8 and the envirionment variables
		 * support UTF-8, than set the locale accordingly
		 */
		if (tOptions.eEncoding == encoding_utf_8) {
			if (setlocale(LC_CTYPE, "") == NULL) {
				werr(1, "Can't set the UTF-8 locale! "
					"Check LANG, LC_CTYPE, LC_ALL.");
			}
			DBG_MSG("The UTF-8 locale has been set");
		} else {
			(void)setlocale(LC_CTYPE, "C");
		}
#endif /* __STDC_ISO_10646__ */
	} else {
		if (setlocale(LC_CTYPE, "") == NULL) {
			werr(0, "Can't set the locale! Will use defaults");
			(void)setlocale(LC_CTYPE, "C");
		}
		DBG_MSG("The locale has been set");
	}
#endif /* !__dos */

	bMultiple = argc - iFirst > 1;
	bUseTXT = tOptions.eConversionType == conversion_text ||
		tOptions.eConversionType == conversion_fmt_text;
	bUseXML = tOptions.eConversionType == conversion_xml;
	iGoodCount = 0;

#if defined(__dos)
	if (tOptions.eConversionType == conversion_pdf) {
		/* PDF must be written as a binary stream */
		setmode(fileno(stdout), O_BINARY);
	}
#endif /* __dos */

	if (bUseXML) {
		fprintf(stdout,
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
	"<!DOCTYPE %s PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\"\n"
	"\t\"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n",
		bMultiple ? "set" : "book");
		if (bMultiple) {
			fprintf(stdout, "<set>\n");
		}
	}

	for (iIndex = iFirst; iIndex < argc; iIndex++) {
		if (bMultiple && bUseTXT) {
			szWordfile = szBasename(argv[iIndex]);
			fprintf(stdout, "::::::::::::::\n");
			fprintf(stdout, "%s\n", szWordfile);
			fprintf(stdout, "::::::::::::::\n");
		}
		if (bProcessFile(argv[iIndex])) {
			iGoodCount++;
		}
	}

	if (bMultiple && bUseXML) {
		fprintf(stdout, "</set>\n");
	}

	DBG_DEC(iGoodCount);
	return iGoodCount <= 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} /* end of main */