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

📄 zprintf.c

📁 打印解析处理函数, 含有浮点数处理, 无需浮点协处理器
💻 C
📖 第 1 页 / 共 5 页
字号:
		dwPrnCount += PutString(
			pbOutLoc + dwPrnCount, wBufLen, pbPromtStr, wPromtLen);
		wBufLen -= (WORD)dwPrnCount;
	}

	if (ptFmt->bRight)													/* 2*/
	{
		dwPrnCount += PutChar(
			pbOutLoc + dwPrnCount, wBufLen, ptFmt->bPreChar, wWidthPad);
		wBufLen -= (WORD)dwPrnCount;
	}

	if (ptFmt->bRight && !ptFmt->bAlter)								/* 3*/
	{
		dwPrnCount += PutString(
			pbOutLoc + dwPrnCount, wBufLen, pbPromtStr, wPromtLen);
		wBufLen -= (WORD)dwPrnCount;
	}

	dwPrnCount += PutChar(												/* 4*/
		pbOutLoc + dwPrnCount, wBufLen, '0', wPrecPad);
	wBufLen -= (WORD)dwPrnCount;

	dwPrnCount += PutString(											/* 5*/
		pbOutLoc + dwPrnCount, wBufLen, pbOutBeg, (WORD)(pbOutEnd - pbOutBeg));
	wBufLen -= (WORD)dwPrnCount;

	if (!ptFmt->bRight)													/* 6*/
	{
		dwPrnCount += PutChar(
			pbOutLoc + dwPrnCount, wBufLen, ptFmt->bPreChar, wWidthPad);
	}

	return dwPrnCount;
}

/*--------------------------------------------------------------------------*/
/* Function name : OutPutDecimal()											*/
/* Description   : 按照打印格式符从相应的地址中取出数据并打印				*/
/* Input         : pbOutLoc		- 打印字符输出地址							*/
/*				 : wBufLen		- 打印缓存长度								*/
/*				 : pbFmt		- 打印格式控制结构							*/
/*				 : ppbDataAddr	- 可供取数的内存地址指针					*/
/*				 : wDataLen		- 数据长度									*/
/* Output		 : none		 												*/
/* Return        : 打印的字符个数											*/
/* Global Var    : 无														*/
/* Author/Date   : R.Z.Tian/2003-5-21 9:24									*/
/* Note          :                                                          */
/*--------------------------------------------------------------------------*/
static ULONG OutPutDecimal(BYTE *pbOutLoc,
	WORD wBufLen, PrnFormatGlb_T *ptFmt, BYTE **ppbDataAddr, WORD wDataLen)
{
	BYTE		sTempOutBuf[MaxDecDigitLen_M], sPromtStr[2] = "+";
	BYTE		*pbOutBeg = &sTempOutBuf[MaxDecDigitLen_M - 1];
	BYTE		*pbOutEnd = &sTempOutBuf[MaxDecDigitLen_M - 1];
	DWORD		dwAbsVal = 0, dwTempVal = 0;

	*ppbDataAddr = TakeDataByFormat(ptFmt, *ppbDataAddr, wDataLen);

	/*----------------------------------------------------------------------*/
	/*	按照格式符调整取得的数据											*/
	/*----------------------------------------------------------------------*/
	if (ptFmt->bType == 'u' && ptFmt->bMod == 'h')
	{
		dwAbsVal = (WORD)ptFmt->dwReadVal;
	}
	else if (ptFmt->bType == 'u' /* && ptFmt->bMod != 'h' */)
	{
		dwAbsVal = ptFmt->dwReadVal;
	}
	else if (/* ptFmt->bType == 'd,i' && */ ptFmt->bMod == 'h')
	{
		if ((SHORT)ptFmt->dwReadVal < 0)
		{
			dwAbsVal = -((SHORT)ptFmt->dwReadVal);
			ptFmt->bPlus = 1, sPromtStr[0] = '-';
		}
		else
		{
			dwAbsVal = (SHORT)ptFmt->dwReadVal;
		}
	}
	else /* if (ptFmt->bType == 'd,i' && ptFmt->bMod != 'h') */
	{
		if ((LONG)ptFmt->dwReadVal < 0)
		{
			dwAbsVal = -((LONG)ptFmt->dwReadVal);
			ptFmt->bPlus = 1, sPromtStr[0] = '-';
		}
		else
		{
			dwAbsVal = (LONG)ptFmt->dwReadVal;
		}
	}

	sPromtStr[0] = (ptFmt->bPlus == 2) ? ' ' : sPromtStr[0];

	/*----------------------------------------------------------------------*/
	/*	求得目标字符本体, 对没有32位除法指令的机器来说,下面的代码可能有问题*/
	/*----------------------------------------------------------------------*/
	if (dwAbsVal == 0)
	{
		*(--pbOutBeg) = '0';
	}
	else for (dwTempVal = dwAbsVal; dwTempVal > 0; /* none */)
	{
		*(--pbOutBeg) = (BYTE)(dwTempVal % 10 + '0'), dwTempVal /= 10;
	}

	/*----------------------------------------------------------------------*/
	/*	检验输出字符宽度并进行输出											*/
	/*----------------------------------------------------------------------*/
	dwTempVal = OutPutWidthCheck(
		pbOutLoc, wBufLen, pbOutBeg, pbOutEnd, ptFmt, sPromtStr, 1);

	return dwTempVal;
}

/*--------------------------------------------------------------------------*/
/* Function name : OutPutHex()												*/
/* Description   : 按照打印格式符从相应的地址中取出数据并打印				*/
/* Input         : pbOutLoc		- 打印字符输出地址							*/
/*				 : wBufLen		- 打印缓存长度								*/
/*				 : pbFmt		- 打印格式控制结构							*/
/*				 : ppbDataAddr	- 可供取数的内存地址指针					*/
/*				 : wDataLen		- 数据长度									*/
/* Output		 : none		 												*/
/* Return        : 打印的字符个数											*/
/* Global Var    : 无														*/
/* Author/Date   : R.Z.Tian/2003-5-21 16:57									*/
/* Note          :                                                          */
/*--------------------------------------------------------------------------*/
static ULONG OutPutHex(BYTE *pbOutLoc,
	WORD wBufLen, PrnFormatGlb_T *ptFmt, BYTE **ppbDataAddr, WORD wDataLen)
{
	BYTE		sTemp[MaxHexDigitLen_M], sPromtStr[4] = "0x ", baHexTbl[16];
	BYTE		*pbOutBeg = &sTemp[MaxHexDigitLen_M - 1];
	BYTE		*pbOutEnd = &sTemp[MaxHexDigitLen_M - 1];
	DWORD		dwAbsVal = 0, dwTempVal = 0;
	BYTE		bChar = '0';

	*ppbDataAddr = TakeDataByFormat(ptFmt, *ppbDataAddr, wDataLen);

	for (dwTempVal = 0; dwTempVal < 9; dwTempVal++)
	{
		baHexTbl[dwTempVal] = bChar++;
	}

	if (ptFmt->bType == 'x')
	{
		bChar = 'a';
	}
	else
	{
		bChar = 'A', sPromtStr[1] = 'X';
	}

	for (dwTempVal = 10; dwTempVal < 16; dwTempVal++)
	{
		baHexTbl[dwTempVal] = bChar++;
	}

	/*----------------------------------------------------------------------*/
	/*	按照格式符调整取得的数据											*/
	/*----------------------------------------------------------------------*/
	if (ptFmt->bMod == 'h')
	{
		dwAbsVal = (WORD)ptFmt->dwReadVal;
	}
	else /* if (ptFmt->bMod != 'h') */
	{
		dwAbsVal = ptFmt->dwReadVal;
	}

	/*----------------------------------------------------------------------*/
	/*	求得目标字符本体													*/
	/*----------------------------------------------------------------------*/
	if (dwAbsVal == 0)
	{
		*(--pbOutBeg) = '0';
	}
	else for (dwTempVal = dwAbsVal; dwTempVal > 0; /* none */)
	{
		*(--pbOutBeg) = baHexTbl[dwTempVal & 0xf], dwTempVal >>= 4;
	}

	/*----------------------------------------------------------------------*/
	/*	检验输出字符宽度并进行输出											*/
	/*----------------------------------------------------------------------*/
	dwTempVal = OutPutWidthCheck(
		pbOutLoc, wBufLen, pbOutBeg, pbOutEnd, ptFmt, sPromtStr, 3);

	return dwTempVal;
}

/*--------------------------------------------------------------------------*/
/* Function name : OutPutOctet()											*/
/* Description   : 按照打印格式符从相应的地址中取出数据并打印				*/
/* Input         : pbOutLoc		- 打印字符输出地址							*/
/*				 : wBufLen		- 打印缓存长度								*/
/*				 : pbFmt		- 打印格式控制结构							*/
/*				 : ppbDataAddr	- 可供取数的内存地址指针					*/
/*				 : wDataLen		- 数据长度									*/
/* Output		 : none		 												*/
/* Return        : 打印的字符个数											*/
/* Global Var    : 无														*/
/* Author/Date   : R.Z.Tian/2003-5-21 16:57									*/
/* Note          :                                                          */
/*--------------------------------------------------------------------------*/
static ULONG OutPutOctet(BYTE *pbOutLoc,
	WORD wBufLen, PrnFormatGlb_T *ptFmt, BYTE **ppbDataAddr, WORD wDataLen)
{
	BYTE		sTempOutBuf[MaxOctDigitLen_M], sPromtStr[3] = "O ";
	BYTE		*pbOutBeg = &sTempOutBuf[MaxOctDigitLen_M - 1];
	BYTE		*pbOutEnd = &sTempOutBuf[MaxOctDigitLen_M - 1];
	DWORD		dwAbsVal = 0, dwTempVal = 0;

	*ppbDataAddr = TakeDataByFormat(ptFmt, *ppbDataAddr, wDataLen);

	/*----------------------------------------------------------------------*/
	/*	按照格式符调整取得的数据											*/
	/*----------------------------------------------------------------------*/
	if (ptFmt->bMod == 'h')
	{
		dwAbsVal = (WORD)ptFmt->dwReadVal;
	}
	else /* if (ptFmt->bMod != 'h') */
	{
		dwAbsVal = ptFmt->dwReadVal;
	}

	/*----------------------------------------------------------------------*/
	/*	求得目标字符本体													*/
	/*----------------------------------------------------------------------*/
	if (dwAbsVal == 0)
	{
		*(--pbOutBeg) = '0';
	}
	else for (dwTempVal = dwAbsVal; dwTempVal > 0; /* none */)
	{
		*(--pbOutBeg) = (BYTE)((dwTempVal & 7) + '0'), dwTempVal >>= 3;
	}

	/*----------------------------------------------------------------------*/
	/*	检验输出字符宽度并进行输出											*/
	/*----------------------------------------------------------------------*/
	dwTempVal = OutPutWidthCheck(
		pbOutLoc, wBufLen, pbOutBeg, pbOutEnd, ptFmt, sPromtStr, 2);

	return dwTempVal;
}

/*--------------------------------------------------------------------------*/
/* Function name : OutPutBinary()											*/
/* Description   : 按照打印格式符从相应的地址中取出数据并打印				*/
/* Input         : pbOutLoc		- 打印字符输出地址							*/
/*				 : wBufLen		- 打印缓存长度								*/
/*				 : pbFmt		- 打印格式控制结构							*/
/*				 : ppbDataAddr	- 可供取数的内存地址指针					*/
/*				 : wDataLen		- 数据长度									*/
/* Output		 : none		 												*/
/* Return        : 打印的字符个数											*/
/* Global Var    : 无														*/
/* Author/Date   : R.Z.Tian/2003-5-21 17:31									*/
/* Note          :                                                          */
/*--------------------------------------------------------------------------*/
static ULONG OutPutBinary(BYTE *pbOutLoc,
	WORD wBufLen, PrnFormatGlb_T *ptFmt, BYTE **ppbDataAddr, WORD wDataLen)
{
	BYTE		sTempOutBuf[MaxBinDigitLen_M], sPromtStr[3] = "b ";
	BYTE		*pbOutBeg = &sTempOutBuf[MaxBinDigitLen_M - 1];
	BYTE		*pbOutEnd = &sTempOutBuf[MaxBinDigitLen_M - 1];
	DWORD		dwAbsVal = 0, dwTempVal = 0;

	*ppbDataAddr = TakeDataByFormat(ptFmt, *ppbDataAddr, wDataLen);

	/*----------------------------------------------------------------------*/
	/*	按照格式符调整取得的数据											*/
	/*----------------------------------------------------------------------*/
	if (ptFmt->bMod == 'h')
	{
		dwAbsVal = (WORD)ptFmt->dwReadVal;
	}
	else /* if (ptFmt->bMod != 'h') */
	{
		dwAbsVal = ptFmt->dwReadVal;
	}

	/*----------------------------------------------------------------------*/
	/*	求得目标字符本体													*/
	/*----------------------------------------------------------------------*/
	if (dwAbsVal == 0)
	{
		*(--pbOutBeg) = '0';
	}
	else for (dwTempVal = dwAbsVal; dwTempVal > 0; /* none */)
	{
		*(--pbOutBeg) = (BYTE)((dwTempVal & 1) + '0'), dwTempVal >>= 1;
	}

	/*----------------------------------------------------------------------*/
	/*	检验输出字符宽度并进行输出											*/
	/*----------------------------------------------------------------------*/
	dwTempVal = OutPutWidthCheck(
		pbOutLoc, wBufLen, pbOutBeg, pbOutEnd, ptFmt, sPromtStr, 2);

	return dwTempVal;
}

/*--------------------------------------------------------------------------*/
/* Function name : OutPutChar()												*/
/* Description   : 按照打印格式符从相应的地址中取出字符并打印				*/
/* Input         : pbOutLoc		- 打印字符输出地址							*/
/*				 : wBufLen		- 打印缓存长度								*/
/*				 : pbFmt		- 打印格式控制结构							*/
/*				 : ppbDataAddr	- 可供取数的内存地址指针					*/
/*				 : wDataLen		- 数据长度									*/
/* Output		 : none		 												*/
/* Return        : 打印的字符个数											*/
/* Global Var    : 无														*/
/* Author/Date   : R.Z.Tian/2003-5-21 17:31									*/
/* Note          :                                                          */
/*--------------------------------------------------------------------------*/
static ULONG OutPutChar(BYTE *pbOutLoc,
	WORD wBufLen, PrnFormatGlb_T *ptFmt, BYTE **ppbDataAddr, WORD wDataLen)
{
	BYTE		sTempOutBuf[MaxCharDigitLen_M], sPromtStr[1] = "";
	BYTE		*pbOutBeg = &sTempOutBuf[MaxCharDigitLen_M - 1];
	BYTE		*pbOutEnd = &sTempOutBuf[MaxCharDigitLen_M - 1];
	DWORD		dwTempVal;

	/*----------------------------------------------------------------------*/
	/*	按照格式符调整取得的数据,并检验取数据默认值						*/
	/*----------------------------------------------------------------------*/
	if (!ptFmt->bTakeDataDecl)
	{
		ptFmt->wTakeBytes = PrnTakeCharBytesDft_M;
	}
	ptFmt->lPrecision = 0;

	*ppbDataAddr = TakeDataByFormat(ptFmt, *ppbDataAddr, wDataLen);

	*(--pbOutBeg) = (char)ptFmt->dwReadVal;

	/*----------------------------------------------------------------------*/
	/*	检验输出字符宽度并进行输出											*/
	/*----------------------------------------------------------------------*/
	dwTempVal = OutPutWidthCheck(
		pbOutLoc, wBufLen, pbOutBeg, pbOutEnd, ptFmt, sPromtStr, 0);

	return dwTempVal;
}

/*--------------------------------------------------------------------------*/
/* Function name : OutPutString()											*/

⌨️ 快捷键说明

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