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

📄 stylesheet.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
	size_t	tPos, tNameLen, tUpxLen;	int	iIndex, iBaseStyleIndex, iCounter;	USHORT	usTmp, usUpxCount, usStyleType, usBaseStyle;	USHORT	usFtcStandardChpStsh;	fail(pFile == NULL || aucHeader == NULL);	fail(ulStartBlock > MAX_BLOCKNUMBER && ulStartBlock != END_OF_CHAIN);	fail(aulBBD == NULL);	ulBeginStshInfo = ulGetLong(0x60, aucHeader); /* fcStshf */	NO_DBG_HEX(ulBeginStshInfo);	tStshInfoLen = (size_t)ulGetLong(0x64, aucHeader); /* lcbStshf */	NO_DBG_DEC(tStshInfoLen);	aucBuffer = xmalloc(tStshInfoLen);	if (!bReadBuffer(pFile, ulStartBlock,			aulBBD, tBBDLen, BIG_BLOCK_SIZE,			aucBuffer, ulBeginStshInfo, tStshInfoLen)) {		aucBuffer = xfree(aucBuffer);		return;	}	NO_DBG_PRINT_BLOCK(aucBuffer, tStshInfoLen);	tStdCount = (size_t)usGetWord(2, aucBuffer);	NO_DBG_DEC(tStdCount);	tStdBaseInFile = (size_t)usGetWord(4, aucBuffer);	usFtcStandardChpStsh = usGetWord(14, aucBuffer);	NO_DBG_DEC(usFtcStandardChpStsh);	atStyleInfo = xcalloc(tStdCount, sizeof(style_block_type));	atFontInfo = xcalloc(tStdCount, sizeof(font_block_type));	abFilled = xcalloc(tStdCount, sizeof(BOOL));	do {		iCounter = 0;		/* Read the styles one-by-one */		for (iIndex = 0, tOffset = 2 + (size_t)usGetWord(0, aucBuffer);		     iIndex < (int)tStdCount;		     iIndex++, tOffset += 2 + tStdLen) {			NO_DBG_DEC(tOffset);			tStdLen = (size_t)usGetWord(tOffset, aucBuffer);			NO_DBG_DEC(tStdLen);			if (abFilled[iIndex]) {				/* This record has already been filled */				continue;			}			pStyle = &atStyleInfo[iIndex];			pFont = &atFontInfo[iIndex];			if (tStdLen == 0) {				/* Empty record */				vGetDefaultStyle(pStyle);				vGetDefaultFont(pFont, usFtcStandardChpStsh);				abFilled[iIndex] = TRUE;				continue;			}			usTmp = usGetWord(tOffset + 4, aucBuffer);			usStyleType = usTmp % 16;			usBaseStyle = usTmp / 16;			NO_DBG_DEC(usStyleType);			NO_DBG_DEC(usBaseStyle);			if (usBaseStyle == STI_NIL || usBaseStyle == STI_USER) {				/* Based on the Nil style */				vGetDefaultStyle(pStyle);				vGetDefaultFont(pFont, usFtcStandardChpStsh);			} else {				iBaseStyleIndex = iGetStyleIndex(usBaseStyle);				NO_DBG_DEC(iBaseStyleIndex);				if (iBaseStyleIndex < 0) {					/* This base style is not known yet */					continue;				}				fail(iBaseStyleIndex >= (int)tStdCount);				fail(!abFilled[iBaseStyleIndex]);				/* Based on the specified base style */				*pStyle = atStyleInfo[iBaseStyleIndex];				pStyle->usIstd = ISTD_INVALID;				*pFont = atFontInfo[iBaseStyleIndex];			}			abFilled[iIndex] = TRUE;			iCounter++;			/* STD */			usTmp = usGetWord(tOffset + 6, aucBuffer);			usUpxCount = usTmp % 16;			pStyle->usIstdNext = usTmp / 16;;			NO_DBG_DEC(usUpxCount);			tPos = 2 + tStdBaseInFile;			NO_DBG_DEC(tPos);			tNameLen = (size_t)ucGetByte(tOffset + tPos, aucBuffer);			NO_DBG_DEC(tNameLen);			NO_DBG_STRN(aucBuffer + tOffset + tPos + 1, tNameLen);			tNameLen++;	/* Include the ASCII NULL character */			tPos += 1 + tNameLen;			if (odd(tPos)) {				tPos++;			}			NO_DBG_DEC(tPos);			if (tPos >= tStdLen) {				continue;			}			tUpxLen = (size_t)usGetWord(tOffset + tPos, aucBuffer);			NO_DBG_DEC(tUpxLen);			if (tPos + tUpxLen > tStdLen) {				/* UPX length too large to be a record */				DBG_DEC_C(tPos + tUpxLen > tStdLen,						tPos + tUpxLen);				continue;			}			if (usStyleType == SGC_PAP && usUpxCount >= 1) {				if (tUpxLen >= 2) {					NO_DBG_PRINT_BLOCK(						aucBuffer + tOffset + tPos + 2,						tUpxLen);					pStyle->usIstd = usGetWord(						tOffset + tPos + 2, aucBuffer);					NO_DBG_DEC(pStyle->usIstd);					NO_DBG_DEC(pStyle->usIstdNext);					vGet6StyleInfo(0,						aucBuffer + tOffset + tPos + 4,						tUpxLen - 2, pStyle);					NO_DBG_DEC(pStyle->sLeftIndent);					NO_DBG_DEC(pStyle->sRightIndent);					NO_DBG_HEX(pStyle->ucAlignment);				}				tPos += 2 + tUpxLen;				if (odd(tPos)) {					tPos++;				}				NO_DBG_DEC(tPos);				tUpxLen = (size_t)usGetWord(						tOffset + tPos, aucBuffer);				NO_DBG_DEC(tUpxLen);			}			if (tUpxLen == 0 || tPos + tUpxLen > tStdLen) {				/* Too small or too large to be a record */				DBG_DEC_C(tPos + tUpxLen > tStdLen,							tPos + tUpxLen);				continue;			}			if ((usStyleType == SGC_PAP && usUpxCount >= 2) ||			    (usStyleType == SGC_CHP && usUpxCount >= 1)) {				NO_DBG_PRINT_BLOCK(						aucBuffer + tOffset + tPos + 2,						tUpxLen);				vGet6FontInfo(0, ISTD_INVALID,						aucBuffer + tOffset + tPos + 2,						(int)tUpxLen, pFont);				NO_DBG_DEC(pFont->usFontSize);				NO_DBG_DEC(pFont->ucFontcolor);				NO_DBG_HEX(pFont->usFontStyle);			}		}		NO_DBG_DEC(iCounter);	} while (iCounter > 0);	/* Fill records that are still empty */	for (iIndex = 0; iIndex < (int)tStdCount; iIndex++) {		if (!abFilled[iIndex]) {			NO_DBG_DEC(iIndex);			vGetDefaultStyle(&atStyleInfo[iIndex]);			vGetDefaultFont(&atFontInfo[iIndex],					usFtcStandardChpStsh);		}	}	/* Clean up before you leave */	abFilled = xfree(abFilled);	aucBuffer = xfree(aucBuffer);} /* end of vGet6Stylesheet *//* * Build the lists with Stylesheet Information for Word 8/9/10 files */voidvGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS,	const ULONG *aulBBD, size_t tBBDLen,	const ULONG *aulSBD, size_t tSBDLen,	const UCHAR *aucHeader){	style_block_type	*pStyle;	font_block_type		*pFont;	const ULONG	*aulBlockDepot;	UCHAR	*aucBuffer;	ULONG	ulBeginStshInfo;	size_t	tStshInfoLen, tBlockDepotLen, tOffset, tStdLen, tStdBaseInFile;	size_t	tBlockSize, tPos, tNameLen, tUpxLen;	int	iIndex, iBaseStyleIndex, iCounter;	USHORT	usTmp, usUpxCount, usStyleType, usBaseStyle;	USHORT	usFtcStandardChpStsh;	fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);	fail(aulBBD == NULL || aulSBD == NULL);	ulBeginStshInfo = ulGetLong(0xa2, aucHeader); /* fcStshf */	NO_DBG_HEX(ulBeginStshInfo);	tStshInfoLen = (size_t)ulGetLong(0xa6, aucHeader); /* lcbStshf */	NO_DBG_DEC(tStshInfoLen);	NO_DBG_DEC(pPPS->tTable.ulSB);	NO_DBG_HEX(pPPS->tTable.ulSize);	if (pPPS->tTable.ulSize == 0) {		DBG_MSG("No stylesheet 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(tStshInfoLen);	if (!bReadBuffer(pFile, pPPS->tTable.ulSB,			aulBlockDepot, tBlockDepotLen, tBlockSize,			aucBuffer, ulBeginStshInfo, tStshInfoLen)) {		aucBuffer = xfree(aucBuffer);		return;	}	NO_DBG_PRINT_BLOCK(aucBuffer, tStshInfoLen);	tStdCount = (size_t)usGetWord(2, aucBuffer);	NO_DBG_DEC(tStdCount);	tStdBaseInFile = (size_t)usGetWord(4, aucBuffer);	usFtcStandardChpStsh = usGetWord(14, aucBuffer);	NO_DBG_DEC(usFtcStandardChpStsh);	atStyleInfo = xcalloc(tStdCount, sizeof(style_block_type));	atFontInfo = xcalloc(tStdCount, sizeof(font_block_type));	abFilled = xcalloc(tStdCount, sizeof(BOOL));	do {		iCounter = 0;		/* Read the styles one-by-one */		for (iIndex = 0, tOffset = 2 + (size_t)usGetWord(0, aucBuffer);		     iIndex < (int)tStdCount;		     iIndex++, tOffset += 2 + tStdLen) {			NO_DBG_DEC(tOffset);			tStdLen = (size_t)usGetWord(tOffset, aucBuffer);			NO_DBG_DEC(tStdLen);			if (abFilled[iIndex]) {				/* This record has already been filled */				continue;			}			pStyle = &atStyleInfo[iIndex];			pFont = &atFontInfo[iIndex];			if (tStdLen == 0) {				/* Empty record */				vGetDefaultStyle(pStyle);				vGetDefaultFont(pFont, usFtcStandardChpStsh);				abFilled[iIndex] = TRUE;				continue;			}			usTmp = usGetWord(tOffset + 4, aucBuffer);			usStyleType = usTmp % 16;			usBaseStyle = usTmp / 16;			NO_DBG_DEC(usStyleType);			NO_DBG_DEC(usBaseStyle);			if (usBaseStyle == STI_NIL || usBaseStyle == STI_USER) {				/* Based on the Nil style */				vGetDefaultStyle(pStyle);				vGetDefaultFont(pFont, usFtcStandardChpStsh);			} else {				iBaseStyleIndex = iGetStyleIndex(usBaseStyle);				NO_DBG_DEC(iBaseStyleIndex);				if (iBaseStyleIndex < 0) {					/* This base style is not known yet */					continue;				}				fail(iBaseStyleIndex >= (int)tStdCount);				fail(!abFilled[iBaseStyleIndex]);				/* Based on the specified base style */				*pStyle = atStyleInfo[iBaseStyleIndex];				pStyle->usIstd = ISTD_INVALID;				*pFont = atFontInfo[iBaseStyleIndex];			}			abFilled[iIndex] = TRUE;			iCounter++;			/* STD */			usTmp = usGetWord(tOffset + 6, aucBuffer);			usUpxCount = usTmp % 16;			pStyle->usIstdNext = usTmp / 16;			NO_DBG_DEC(usUpxCount);			tPos = 2 + tStdBaseInFile;			NO_DBG_DEC(tPos);			tNameLen = (size_t)usGetWord(tOffset + tPos, aucBuffer);			NO_DBG_DEC(tNameLen);			tNameLen *= 2;	/* From Unicode characters to bytes */			NO_DBG_UNICODE_N(aucBuffer + tOffset + tPos + 2,					tNameLen);			tNameLen += 2;	/* Include the Unicode NULL character */			tPos += 2 + tNameLen;			if (odd(tPos)) {				tPos++;			}			NO_DBG_DEC(tPos);			if (tPos >= tStdLen) {				continue;			}			tUpxLen = (size_t)usGetWord(tOffset + tPos, aucBuffer);			NO_DBG_DEC(tUpxLen);			if (tPos + tUpxLen > tStdLen) {				/* UPX length too large to be a record */				DBG_DEC_C(tPos + tUpxLen > tStdLen,						tPos + tUpxLen);				continue;			}			if (usStyleType == SGC_PAP && usUpxCount >= 1) {				if (tUpxLen >= 2) {					NO_DBG_PRINT_BLOCK(						aucBuffer + tOffset + tPos + 2,						tUpxLen);					pStyle->usIstd = usGetWord(						tOffset + tPos + 2, aucBuffer);					NO_DBG_DEC(pStyle->usIstd);					NO_DBG_DEC(pStyle->usIstdNext);					vGet8StyleInfo(0,						aucBuffer + tOffset + tPos + 4,						tUpxLen - 2, pStyle);					NO_DBG_DEC(pStyle->sLeftIndent);					NO_DBG_DEC(pStyle->sRightIndent);					NO_DBG_HEX(pStyle->ucAlignment);				}				tPos += 2 + tUpxLen;				if (odd(tPos)) {					tPos++;				}				NO_DBG_DEC(tPos);				tUpxLen = (size_t)usGetWord(						tOffset + tPos, aucBuffer);				NO_DBG_DEC(tUpxLen);			}			if (tUpxLen == 0 || tPos + tUpxLen > tStdLen) {				/* Too small or too large to be a record */				DBG_DEC_C(tPos + tUpxLen > tStdLen,							tPos + tUpxLen);				continue;			}			if ((usStyleType == SGC_PAP && usUpxCount >= 2) ||			    (usStyleType == SGC_CHP && usUpxCount >= 1)) {				NO_DBG_PRINT_BLOCK(						aucBuffer + tOffset + tPos + 2,						tUpxLen);				vGet8FontInfo(0, ISTD_INVALID,						aucBuffer + tOffset + tPos + 2,						(int)tUpxLen, pFont);				NO_DBG_DEC(pFont->usFontSize);				NO_DBG_DEC(pFont->ucFontcolor);				NO_DBG_HEX(pFont->usFontStyle);			}		}		NO_DBG_DEC(iCounter);	} while (iCounter > 0);	/* Fill records that are still empty */	for (iIndex = 0; iIndex < (int)tStdCount; iIndex++) {		if (!abFilled[iIndex]) {			NO_DBG_DEC(iIndex);			vGetDefaultStyle(&atStyleInfo[iIndex]);			vGetDefaultFont(&atFontInfo[iIndex],					usFtcStandardChpStsh);		}	}	/* Clean up before you leave */	abFilled = xfree(abFilled);	aucBuffer = xfree(aucBuffer);} /* end of vGet8Stylesheet *//* * vFillStyleFromStylesheet - fill a style struct with stylesheet info */voidvFillStyleFromStylesheet(USHORT usIstd, style_block_type *pStyle){	int	iIndex;	fail(pStyle == NULL);	if (usIstd != ISTD_INVALID && usIstd != STI_NIL && usIstd != STI_USER) {		for (iIndex = 0; iIndex < (int)tStdCount; iIndex++) {			if (atStyleInfo[iIndex].usIstd == usIstd) {				/* Right index found; return style */				*pStyle = atStyleInfo[iIndex];				return;			}		}	}	vGetDefaultStyle(pStyle);	pStyle->usIstd = usIstd;} /* end of vFillStyleFromStylesheet *//* * vFillFontFromStylesheet - fill a font struct with stylesheet info */voidvFillFontFromStylesheet(USHORT usIstd, font_block_type *pFont){	int	iIndex;	fail(pFont == NULL);	if (usIstd != ISTD_INVALID && usIstd != STI_NIL && usIstd != STI_USER) {		for (iIndex = 0; iIndex < (int)tStdCount; iIndex++) {			if (atStyleInfo[iIndex].usIstd == usIstd) {				/* Right index found; return font */				*pFont = atFontInfo[iIndex];				return;			}		}	}	vGetDefaultFont(pFont, 0);} /* end of vFillFontFromStylesheet */

⌨️ 快捷键说明

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