⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blocklist.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
			if (pCurr->pNext != NULL &&			    pCurr->tInfo.ulLength % BIG_BLOCK_SIZE != 0) {				DBG_DEC(tIndex);				DBG_HEX(pCurr->tInfo.ulFileOffset);				DBG_HEX(pCurr->tInfo.ulCharPos);				DBG_DEC(pCurr->tInfo.ulLength);				pCurr->tInfo.ulLength /= BIG_BLOCK_SIZE;				pCurr->tInfo.ulLength++;				pCurr->tInfo.ulLength *= BIG_BLOCK_SIZE;				DBG_DEC(pCurr->tInfo.ulLength);			}		}	}} /* end of vSplitBlockList */#if defined(__riscos)/* * ulGetDocumentLength - get the total character length of the printable lists * * returns: The total number of characters */ULONGulGetDocumentLength(void){	long		ulTotal;	DBG_MSG("ulGetDocumentLength");	ulTotal = ulComputeListLength(pTextAnchor);	ulTotal += ulComputeListLength(pFootnoteAnchor);	ulTotal += ulComputeListLength(pEndnoteAnchor);	ulTotal += ulComputeListLength(pTextBoxAnchor);	ulTotal += ulComputeListLength(pHdrTextBoxAnchor);	DBG_DEC(ulTotal);	return ulTotal;} /* end of ulGetDocumentLength */#endif /* __riscos */#if 0/* * bExistsHdrFtr - are there headers and/or footers? */BOOLbExistsHdrFtr(void){	return pHdrFtrAnchor != NULL &&		pHdrFtrAnchor->tInfo.ulLength != 0;} /* end of bExistsHdrFtr */#endif/* * bExistsTextBox - is there a text box? */BOOLbExistsTextBox(void){	return pTextBoxAnchor != NULL &&		pTextBoxAnchor->tInfo.ulLength != 0;} /* end of bExistsTextBox *//* * bExistsHdrTextBox - is there a header text box? */BOOLbExistsHdrTextBox(void){	return pHdrTextBoxAnchor != NULL &&		pHdrTextBoxAnchor->tInfo.ulLength != 0;} /* end of bExistsHdrTextBox *//* * usGetNextByte - get the next byte from the specified block list */static USHORTusGetNextByte(FILE *pFile, readinfo_type *pInfoCurrent, list_mem_type *pAnchor,	ULONG *pulFileOffset, ULONG *pulCharPos, USHORT *pusPropMod){	ULONG	ulReadOff;	size_t	tReadLen;	fail(pInfoCurrent == NULL);	if (pInfoCurrent->pBlockCurrent == NULL ||	    pInfoCurrent->tByteNext >= sizeof(pInfoCurrent->aucBlock) ||	    pInfoCurrent->ulBlockOffset + pInfoCurrent->tByteNext >=				pInfoCurrent->pBlockCurrent->tInfo.ulLength) {		if (pInfoCurrent->pBlockCurrent == NULL) {			/* First block, first part */			pInfoCurrent->pBlockCurrent = pAnchor;			pInfoCurrent->ulBlockOffset = 0;		} else if (pInfoCurrent->ulBlockOffset +				sizeof(pInfoCurrent->aucBlock) <				pInfoCurrent->pBlockCurrent->tInfo.ulLength) {			/* Same block, next part */			pInfoCurrent->ulBlockOffset +=					sizeof(pInfoCurrent->aucBlock);		} else {			/* Next block, first part */			pInfoCurrent->pBlockCurrent =					pInfoCurrent->pBlockCurrent->pNext;			pInfoCurrent->ulBlockOffset = 0;		}		if (pInfoCurrent->pBlockCurrent == NULL) {			/* Past the last part of the last block */			return (USHORT)EOF;		}		tReadLen = (size_t)			(pInfoCurrent->pBlockCurrent->tInfo.ulLength -			 pInfoCurrent->ulBlockOffset);		if (tReadLen > sizeof(pInfoCurrent->aucBlock)) {			tReadLen = sizeof(pInfoCurrent->aucBlock);		}		ulReadOff = pInfoCurrent->pBlockCurrent->tInfo.ulFileOffset +				pInfoCurrent->ulBlockOffset;		if (!bReadBytes(pInfoCurrent->aucBlock,						tReadLen, ulReadOff, pFile)) {			/* Don't read from this list any longer */			pInfoCurrent->pBlockCurrent = NULL;			return (USHORT)EOF;		}		pInfoCurrent->tByteNext = 0;	}	if (pulFileOffset != NULL) {		*pulFileOffset =			pInfoCurrent->pBlockCurrent->tInfo.ulFileOffset +			pInfoCurrent->ulBlockOffset +			pInfoCurrent->tByteNext;	}	if (pulCharPos != NULL) {		*pulCharPos =			pInfoCurrent->pBlockCurrent->tInfo.ulCharPos +			pInfoCurrent->ulBlockOffset +			pInfoCurrent->tByteNext;	}	if (pusPropMod != NULL) {		*pusPropMod = pInfoCurrent->pBlockCurrent->tInfo.usPropMod;	}	return (USHORT)pInfoCurrent->aucBlock[pInfoCurrent->tByteNext++];} /* end of usGetNextByte *//* * usGetNextChar - get the next character from the specified block list */static USHORTusGetNextChar(FILE *pFile, list_id_enum eListID,	ULONG *pulFileOffset, ULONG *pulCharPos, USHORT *pusPropMod){	readinfo_type	*pReadinfo;	list_mem_type	*pAnchor;	USHORT	usLSB, usMSB;	switch (eListID) {	case text_list:		pReadinfo = &tOthers;		pAnchor = pTextAnchor;		break;	case footnote_list:		pReadinfo = &tFootnote;		pAnchor = pFootnoteAnchor;		break;	case hdrftr_list:		pReadinfo = &tHdrFtr;		pAnchor = pHdrFtrAnchor;		break;	case endnote_list:		pReadinfo = &tOthers;		pAnchor = pEndnoteAnchor;		break;	case textbox_list:		pReadinfo = &tOthers;		pAnchor = pTextBoxAnchor;		break;	case hdrtextbox_list:		pReadinfo = &tOthers;		pAnchor = pHdrTextBoxAnchor;		break;	default:		DBG_DEC(eListID);		return (USHORT)EOF;	}	usLSB = usGetNextByte(pFile, pReadinfo, pAnchor,				pulFileOffset, pulCharPos, pusPropMod);	if (usLSB == (USHORT)EOF) {		return (USHORT)EOF;	}	fail(pReadinfo->pBlockCurrent == NULL);	if (pReadinfo->pBlockCurrent->tInfo.bUsesUnicode) {		usMSB = usGetNextByte(pFile,				pReadinfo, pAnchor, NULL, NULL, NULL);	} else {		usMSB = 0x00;	}	if (usMSB == (USHORT)EOF) {		DBG_MSG("usGetNextChar: Unexpected EOF");		DBG_HEX_C(pulFileOffset != NULL, *pulFileOffset);		DBG_HEX_C(pulCharPos != NULL, *pulCharPos);		return (USHORT)EOF;	}	return (usMSB << 8) | usLSB;} /* end of usGetNextChar *//* * usNextChar - get the next character from the given block list */USHORTusNextChar(FILE *pFile, list_id_enum eListID,	ULONG *pulFileOffset, ULONG *pulCharPos, USHORT *pusPropMod){	USHORT	usRetVal;	fail(pFile == NULL);	usRetVal = usGetNextChar(pFile, eListID,				pulFileOffset, pulCharPos, pusPropMod);	if (usRetVal == (USHORT)EOF) {		if (pulFileOffset != NULL) {			*pulFileOffset = FC_INVALID;		}		if (pulCharPos != NULL) {			*pulCharPos = CP_INVALID;		}		if (pusPropMod != NULL) {			*pusPropMod = IGNORE_PROPMOD;		}	}	return usRetVal;} /* end of usNextChar *//* * usToHdrFtrPosition - Go to a character position in header/foorter list * * Returns the character found on the specified character position */USHORTusToHdrFtrPosition(FILE *pFile, ULONG ulCharPos){	ULONG	ulCharPosCurr;	USHORT	usChar;	tHdrFtr.pBlockCurrent = NULL;	/* To reset the header/footer list */	do {		usChar = usNextChar(pFile,				hdrftr_list, NULL, &ulCharPosCurr, NULL);	} while (usChar != (USHORT)EOF && ulCharPosCurr != ulCharPos);	return usChar;} /* end of usToHdrFtrPosition *//* * usToFootnotePosition - Go to a character position in footnote list * * Returns the character found on the specified character position */USHORTusToFootnotePosition(FILE *pFile, ULONG ulCharPos){	ULONG	ulCharPosCurr;	USHORT	usChar;	tFootnote.pBlockCurrent = NULL;	/* To reset the footnote list */	do {		usChar = usNextChar(pFile,				footnote_list, NULL, &ulCharPosCurr, NULL);	} while (usChar != (USHORT)EOF && ulCharPosCurr != ulCharPos);	return usChar;} /* end of usToFootnotePosition *//* * Convert a character position to an offset in the file. * Logical to physical offset. * * Returns:	FC_INVALID: in case of error *		otherwise: the computed file offset */ULONGulCharPos2FileOffsetX(ULONG ulCharPos, list_id_enum *peListID){	static list_id_enum	eListIDs[8] = {		text_list,	footnote_list,		hdrftr_list,		macro_list,	annotation_list,	endnote_list,		textbox_list,	hdrtextbox_list,	};	list_mem_type	*apAnchors[8];	list_mem_type	*pCurr;	list_id_enum	eListGuess;	ULONG		ulBestGuess;	size_t		tIndex;	fail(peListID == NULL);	if (ulCharPos == CP_INVALID) {		*peListID = no_list;		return FC_INVALID;	}	apAnchors[0] = pTextAnchor;	apAnchors[1] = pFootnoteAnchor;	apAnchors[2] = pHdrFtrAnchor;	apAnchors[3] = pMacroAnchor;	apAnchors[4] = pAnnotationAnchor;	apAnchors[5] = pEndnoteAnchor;	apAnchors[6] = pTextBoxAnchor;	apAnchors[7] = pHdrTextBoxAnchor;	eListGuess = no_list;	  /* Best guess is no list */	ulBestGuess = FC_INVALID; /* Best guess is "file offset not found" */	for (tIndex = 0; tIndex < elementsof(apAnchors); tIndex++) {		for (pCurr = apAnchors[tIndex];		     pCurr != NULL;		     pCurr = pCurr->pNext) {			if (ulCharPos == pCurr->tInfo.ulCharPos +			     pCurr->tInfo.ulLength &&			    pCurr->pNext != NULL) {				/*				 * The character position is one beyond this				 * block, so we guess it's the first byte of				 * the next block (if there is a next block)				 */				eListGuess= eListIDs[tIndex];				ulBestGuess = pCurr->pNext->tInfo.ulFileOffset;			}			if (ulCharPos < pCurr->tInfo.ulCharPos ||			    ulCharPos >= pCurr->tInfo.ulCharPos +			     pCurr->tInfo.ulLength) {				/* Character position is not in this block */				continue;			}			/* The character position is in the current block */			*peListID = eListIDs[tIndex];			return pCurr->tInfo.ulFileOffset +				ulCharPos - pCurr->tInfo.ulCharPos;		}	}	/* Passed beyond the end of the last list */	NO_DBG_HEX(ulCharPos);	NO_DBG_HEX(ulBestGuess);	*peListID = eListGuess;	return ulBestGuess;} /* end of ulCharPos2FileOffsetX *//* * Convert a character position to an offset in the file. * Logical to physical offset. * * Returns:	FC_INVALID: in case of error *		otherwise: the computed file offset */ULONGulCharPos2FileOffset(ULONG ulCharPos){	list_id_enum	eListID;	return ulCharPos2FileOffsetX(ulCharPos, &eListID);} /* end of ulCharPos2FileOffset *//* * Convert an offset in the header/footer list to a character position. * * Returns:	CP_INVALID: in case of error *		otherwise: the computed character position */ULONGulHdrFtrOffset2CharPos(ULONG ulHdrFtrOffset){	list_mem_type	*pCurr;	ULONG		ulOffset;	ulOffset = ulHdrFtrOffset;	for (pCurr = pHdrFtrAnchor; pCurr != NULL; pCurr = pCurr->pNext) {		if (ulOffset >= pCurr->tInfo.ulLength) {			/* The offset is not in this block */			ulOffset -= pCurr->tInfo.ulLength;			continue;		}		return pCurr->tInfo.ulCharPos + ulOffset;	}	return CP_INVALID;} /* end of ulHdrFtrOffset2CharPos *//* * Get the sequence number beloning to the given file offset * * Returns the sequence number */ULONGulGetSeqNumber(ULONG ulFileOffset){	list_mem_type	*pCurr;	ULONG		ulSeq;	if (ulFileOffset == FC_INVALID) {		return FC_INVALID;	}	ulSeq = 0;	for (pCurr = pTextAnchor; pCurr != NULL; pCurr = pCurr->pNext) {		if (ulFileOffset >= pCurr->tInfo.ulFileOffset &&		    ulFileOffset < pCurr->tInfo.ulFileOffset +		     pCurr->tInfo.ulLength) {			/* The file offset is within the current textblock */			return ulSeq + ulFileOffset - pCurr->tInfo.ulFileOffset;		}		ulSeq += pCurr->tInfo.ulLength;	}	return FC_INVALID;} /* end of ulGetSeqNumber */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -