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

📄 prop2.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
					iFodo + iFodoOff + 1, aucGrpprl);			NO_DBG_DEC(pStyle->usBeforeIndent);			break;		case  22:	/* dyaAfter */			pStyle->usAfterIndent = usGetWord(					iFodo + iFodoOff + 1, aucGrpprl);			NO_DBG_DEC(pStyle->usAfterIndent);			break;		default:			break;		}		if (iInfoLen <= 0) {			iInfoLen =				iGet2InfoLength(iFodo + iFodoOff, aucGrpprl);			fail(iInfoLen <= 0);		}		iFodoOff += iInfoLen;	}} /* end of vGet2StyleInfo *//* * Build the lists with Paragraph Information for WinWord 1/2 files */voidvGet2PapInfo(FILE *pFile, const UCHAR *aucHeader){	row_block_type		tRow;	style_block_type	tStyle;	USHORT	*ausParfPage;	UCHAR	*aucBuffer;	ULONG	ulCharPos, ulCharPosFirst, ulCharPosLast;	ULONG	ulBeginParfInfo;	size_t	tParfInfoLen, tParfPageNum, tOffset, tSize, tLenOld, tLen;	int	iIndex, iIndex2, iRun, iFodo, iLen;	row_info_enum	eRowInfo;	USHORT	usParfFirstPage, usCount, usIstd;	UCHAR	ucStc;	UCHAR	aucFpage[BIG_BLOCK_SIZE];	fail(pFile == NULL || aucHeader == NULL);	ulBeginParfInfo = ulGetLong(0xa6, aucHeader); /* fcPlcfbtePapx */	NO_DBG_HEX(ulBeginParfInfo);	tParfInfoLen = (size_t)usGetWord(0xaa, aucHeader); /* cbPlcfbtePapx */	NO_DBG_DEC(tParfInfoLen);	if (tParfInfoLen < 4) {		DBG_DEC(tParfInfoLen);		return;	}	aucBuffer = xmalloc(tParfInfoLen);	if (!bReadBytes(aucBuffer, tParfInfoLen, ulBeginParfInfo, pFile)) {		aucBuffer = xfree(aucBuffer);		return;	}	NO_DBG_PRINT_BLOCK(aucBuffer, tParfInfoLen);	tLen = (tParfInfoLen - 4) / 6;	ausParfPage = xcalloc(tLen, sizeof(USHORT));	for (iIndex = 0, tOffset = (tLen + 1) * 4;	     iIndex < (int)tLen;	     iIndex++, tOffset += 2) {		ausParfPage[iIndex] = usGetWord(tOffset, aucBuffer);		NO_DBG_DEC(ausParfPage[iIndex]);	}	DBG_HEX(ulGetLong(0, aucBuffer));	aucBuffer = xfree(aucBuffer);	tParfPageNum = (size_t)usGetWord(0x144, aucHeader); /* cpnBtePap */	DBG_DEC(tParfPageNum);	if (tLen < tParfPageNum) {		/* Replace ParfPage by a longer version */		tLenOld = tLen;		usParfFirstPage = usGetWord(0x140, aucHeader); /* pnPapFirst */		DBG_DEC(usParfFirstPage);		tLen += tParfPageNum - 1;		tSize = tLen * sizeof(USHORT);		ausParfPage = xrealloc(ausParfPage, tSize);		/* Add new values */		usCount = usParfFirstPage + 1;		for (iIndex = (int)tLenOld; iIndex < (int)tLen; iIndex++) {			ausParfPage[iIndex] = usCount;			NO_DBG_DEC(ausParfPage[iIndex]);			usCount++;		}	}	(void)memset(&tRow, 0, sizeof(tRow));	ulCharPosFirst = CP_INVALID;	for (iIndex = 0; iIndex < (int)tLen; iIndex++) {		if (!bReadBytes(aucFpage, BIG_BLOCK_SIZE,				(ULONG)ausParfPage[iIndex] * BIG_BLOCK_SIZE,				pFile)) {			break;		}		NO_DBG_PRINT_BLOCK(aucFpage, BIG_BLOCK_SIZE);		iRun = (int)ucGetByte(0x1ff, aucFpage);		NO_DBG_DEC(iRun);		for (iIndex2 = 0; iIndex2 < iRun; iIndex2++) {			if ((iRun + 1) * 4 + iIndex2 * 1 >= BIG_BLOCK_SIZE) {				break;			}			NO_DBG_HEX(ulGetLong(iIndex2 * 4, aucFpage));			iFodo = 2 * (int)ucGetByte(				(iRun + 1) * 4 + iIndex2 * 1, aucFpage);			if (iFodo <= 0) {				continue;			}			iLen = 2 * (int)ucGetByte(iFodo, aucFpage);			ucStc = ucGetByte(iFodo + 1, aucFpage);			usIstd = usStc2istd(ucStc);			vFillStyleFromStylesheet(usIstd, &tStyle);			vGet2StyleInfo(iFodo, aucFpage + 8, iLen - 8, &tStyle);			ulCharPos = ulGetLong(iIndex2 * 4, aucFpage);			NO_DBG_HEX(ulCharPos);			tStyle.ulFileOffset = ulCharPos;			vAdd2StyleInfoList(&tStyle);			eRowInfo = eGet2RowInfo(iFodo,					aucFpage + 8, iLen - 8, &tRow);			switch(eRowInfo) {			case found_a_cell:				if (ulCharPosFirst != CP_INVALID) {					break;				}				ulCharPosFirst = ulGetLong(						iIndex2 * 4, aucFpage);				NO_DBG_HEX(ulCharPosFirst);				tRow.ulCharPosStart = ulCharPosFirst;				tRow.ulFileOffsetStart = ulCharPosFirst;				break;			case found_end_of_row:				ulCharPosLast = ulGetLong(						iIndex2 * 4, aucFpage);				NO_DBG_HEX(ulCharPosLast);				tRow.ulCharPosEnd = ulCharPosLast;				/* Add 1 for compatiblity with Word 6 and up */				tRow.ulFileOffsetEnd = ulCharPosLast + 1;				vAdd2RowInfoList(&tRow);				(void)memset(&tRow, 0, sizeof(tRow));				ulCharPosFirst = CP_INVALID;				break;			case found_nothing:				break;			default:				DBG_DEC(eRowInfo);				break;			}		}	}	ausParfPage = xfree(ausParfPage);} /* end of vGet2PapInfo *//* * Fill the font information block with information * from a WinWord 1 file. */voidvGet1FontInfo(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;			}		}	}} /* end of vGet1FontInfo *//* * Fill the font information block with information * from a WinWord 1/2 file. */voidvGet2FontInfo(int iFodo,	const UCHAR *aucGrpprl, size_t tBytes, font_block_type *pFont){	BOOL	bIcoChange, bFtcChange, bHpsChange, bKulChange;	USHORT	usTmp;	UCHAR	ucTmp;	UCHAR	aucChpx[18];	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(3)) {		pFont->usFontStyle ^= FONT_MARKDEL;	}	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;	}	if (usTmp & BIT(10)) {		pFont->usFontStyle ^= FONT_STRIKE;	}	ucTmp = ucGetByte(10, aucChpx);	DBG_MSG_C(ucTmp != 0 && ucTmp < 128, "Superscript");	DBG_MSG_C(ucTmp >= 128, "Subscript");	usTmp = usGetWord(2, aucChpx);	if (usTmp == 0) {		/* No changes, nothing to do */		return;	}	bIcoChange = (usTmp & BIT(0)) != 0;	bFtcChange = (usTmp & BIT(1)) != 0;	bHpsChange = (usTmp & BIT(2)) != 0;	bKulChange = (usTmp & BIT(3)) != 0;	if (bFtcChange) {		usTmp = usGetWord(4, aucChpx);		if (usTmp <= (USHORT)UCHAR_MAX) {			pFont->ucFontNumber = (UCHAR)usTmp;		} else {			pFont->ucFontNumber = 0;		}	}	if (bHpsChange) {		pFont->usFontSize = usGetWord(6, aucChpx);	}	if (bIcoChange || bKulChange) {		ucTmp = ucGetByte(9, aucChpx);		if (bIcoChange) {			pFont->ucFontColor = ucTmp & 0x1f;			if (pFont->ucFontColor > 16) {				DBG_DEC(pFont->ucFontColor);				pFont->ucFontColor = 0;			}		}		if (bKulChange) {			ucTmp = (ucTmp & 0xe0) >> 5;			DBG_DEC_C(ucTmp > 4, ucTmp);			if (ucTmp == 0) {				pFont->usFontStyle &= ~FONT_UNDERLINE;			} else {				pFont->usFontStyle |= FONT_UNDERLINE;			}		}	}} /* end of vGet2FontInfo *//* * Fill the picture information block with information from a WinWord 1 file. * Returns TRUE when successful, otherwise FALSE */static BOOLbGet1PicInfo(int iFodo,	const UCHAR *aucGrpprl, size_t tBytes, picture_block_type *pPicture){	ULONG	ulTmp;	UCHAR	aucChpx[12];	fail(iFodo < 0 || aucGrpprl == NULL || pPicture == NULL);	if (tBytes > sizeof(aucChpx)) {		NO_DBG_PRINT_BLOCK(aucGrpprl + iFodo, tBytes);		tBytes = sizeof(aucChpx);	}	/* Build the CHPX structure */	(void)memset(aucChpx, 0, sizeof(aucChpx));	(void)memcpy(aucChpx, aucGrpprl + iFodo, min(tBytes, sizeof(aucChpx)));	ulTmp = ulGetLong(8, aucChpx);	if (ulTmp != 0 && ulTmp < MAX_FILESIZE) {		pPicture->ulPictureOffset = ulTmp;		DBG_HEX(pPicture->ulPictureOffset);		return TRUE;	}	return FALSE;} /* end of bGet1PicInfo *//* * Fill the picture information block with information from a WinWord 2 file. * Returns TRUE when successful, otherwise FALSE */static BOOLbGet2PicInfo(int iFodo,	const UCHAR *aucGrpprl, size_t tBytes, picture_block_type *pPicture){	ULONG	ulTmp;	UCHAR	aucChpx[18];	fail(iFodo < 0 || aucGrpprl == NULL || pPicture == NULL);	if (tBytes > sizeof(aucChpx)) {		NO_DBG_PRINT_BLOCK(aucGrpprl + iFodo, tBytes);		tBytes = sizeof(aucChpx);	}	/* Build the CHPX structure */	(void)memset(aucChpx, 0, sizeof(aucChpx));	(void)memcpy(aucChpx, aucGrpprl + iFodo, min(tBytes, sizeof(aucChpx)));	ulTmp = ulGetLong(14, aucChpx);	if (ulTmp != 0 && ulTmp < MAX_FILESIZE) {		pPicture->ulPictureOffset = ulTmp;		DBG_HEX(pPicture->ulPictureOffset);		DBG_DEC(tBytes);		return TRUE;	}	return FALSE;} /* end of bGet2PicInfo *//* * Build the lists with Character Information for WinWord 1/2 files */voidvGet2ChrInfo(FILE *pFile, int iWordVersion, const UCHAR *aucHeader){	font_block_type		tFont;	picture_block_type	tPicture;	USHORT	*ausCharPage;	UCHAR	*aucBuffer;	ULONG	ulFileOffset, ulCharPos, ulBeginCharInfo;	size_t	tCharInfoLen, tOffset, tSize, tChrLen, tCharPageNum;	size_t	tLenOld, tLen;	int	iIndex, iIndex2, iRun, iFodo;	BOOL	bSuccess1, bSuccess2;	USHORT	usCharFirstPage, usCount, usIstd;	UCHAR	aucFpage[BIG_BLOCK_SIZE];	fail(pFile == NULL || aucHeader == NULL);	fail(iWordVersion != 1 && iWordVersion != 2);	ulBeginCharInfo = ulGetLong(0xa0, aucHeader); /* fcPlcfbteChpx */	DBG_HEX(ulBeginCharInfo);	tCharInfoLen = (size_t)usGetWord(0xa4, aucHeader); /* cbPlcfbteChpx */	DBG_DEC(tCharInfoLen);	if (tCharInfoLen < 4) {		DBG_DEC(tCharInfoLen);		return;	}	aucBuffer = xmalloc(tCharInfoLen);	if (!bReadBytes(aucBuffer, tCharInfoLen, ulBeginCharInfo, pFile)) {		aucBuffer = xfree(aucBuffer);		return;	}	NO_DBG_PRINT_BLOCK(aucBuffer, tCharInfoLen);	tLen = (tCharInfoLen - 4) / 6;	ausCharPage = xcalloc(tLen, sizeof(USHORT));	for (iIndex = 0, tOffset = (tLen + 1) * 4;	     iIndex < (int)tLen;	     iIndex++, tOffset += 2) {		ausCharPage[iIndex] = usGetWord(tOffset, aucBuffer);		NO_DBG_DEC(ausCharPage[iIndex]);	}	DBG_HEX(ulGetLong(0, aucBuffer));	aucBuffer = xfree(aucBuffer);	tCharPageNum = (size_t)usGetWord(0x142, aucHeader); /* cpnBteChp */	DBG_DEC(tCharPageNum);	if (tLen < tCharPageNum) {		/* Replace CharPage by a longer version */		tLenOld = tLen;		usCharFirstPage = usGetWord(0x13e, aucHeader); /* pnChrFirst */		NO_DBG_DEC(usCharFirstPage);		tLen += tCharPageNum - 1;		tSize = tLen * sizeof(USHORT);		ausCharPage = xrealloc(ausCharPage, tSize);		/* Add new values */		usCount = usCharFirstPage + 1;		for (iIndex = (int)tLenOld; iIndex < (int)tLen; iIndex++) {			ausCharPage[iIndex] = usCount;			NO_DBG_DEC(ausCharPage[iIndex]);			usCount++;		}	}	for (iIndex = 0; iIndex < (int)tLen; iIndex++) {		if (!bReadBytes(aucFpage, BIG_BLOCK_SIZE,				(ULONG)ausCharPage[iIndex] * BIG_BLOCK_SIZE,				pFile)) {			break;		}		NO_DBG_PRINT_BLOCK(aucFpage, BIG_BLOCK_SIZE);		iRun = (int)ucGetByte(0x1ff, aucFpage);		NO_DBG_DEC(iRun);		for (iIndex2 = 0; iIndex2 < iRun; iIndex2++) {			if ((iRun + 1) * 4 + iIndex2 >= BIG_BLOCK_SIZE) {				break;			}			ulCharPos = ulGetLong(iIndex2 * 4, aucFpage);			ulFileOffset = ulCharPos;			iFodo = 2 * (int)ucGetByte(				(iRun + 1) * 4 + iIndex2, aucFpage);			tChrLen = (size_t)ucGetByte(iFodo, aucFpage);			usIstd = usGetIstd(ulFileOffset);			vFillFontFromStylesheet(usIstd, &tFont);			if (iFodo != 0) {				if (iWordVersion == 1) {					vGet1FontInfo(iFodo,						aucFpage + 1, tChrLen, &tFont);				} else if (iWordVersion == 2) {					vGet2FontInfo(iFodo,						aucFpage + 1, tChrLen, &tFont);				}			}			tFont.ulFileOffset = ulFileOffset;			vAdd2FontInfoList(&tFont);			if (iFodo <= 0) {				continue;			}			(void)memset(&tPicture, 0, sizeof(tPicture));			bSuccess1 = iWordVersion == 1 &&					bGet1PicInfo(iFodo, aucFpage + 1,						tChrLen, &tPicture);			bSuccess2 = iWordVersion == 2 &&					bGet2PicInfo(iFodo, aucFpage + 1,						tChrLen, &tPicture);			if (bSuccess1 || bSuccess2) {				tPicture.ulFileOffset = ulFileOffset;				tPicture.ulFileOffsetPicture =						tPicture.ulPictureOffset;				vAdd2PictInfoList(&tPicture);			}		}	}	ausCharPage = xfree(ausCharPage);} /* end of vGet2ChrInfo */

⌨️ 快捷键说明

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