printf.txt
来自「打印语句源代码参考,在一个源代码中发现的.想研究的人可以参考一下」· 文本 代码 · 共 60 行
TXT
60 行
int printf(const char *format,...)
{
int i;
int iCnt = 0;
int iToSend = 0;
static char buf[PRINTF_BUFF_SIZE];
int ret;
UART_TYPE UartOut;
UINT8 *pBuff = (UINT8 *)buf;
UINT8 *pLastBuff = (UINT8 *)buf;
UINT8 ch = '\r';
va_list args;
va_start(args, format);
ret = vsnprintf(buf,sizeof(buf), format,args);
switch(OutputUart)
{
case 0:
return 0;
case 1:
UartOut=UART_DEBUG;
break;
case 2:
UartOut=UART_MODEM;
break;
default:
UartOut=UART_DEBUG;
break;
}
for (i=0;i<ret;i++)
{
if (pBuff[i] == '\r')
{
ret++;
UART_WriteToHost( UartOut, pLastBuff, iToSend );
iCnt += iToSend;
pLastBuff = pBuff+i+1;
iToSend = 0;
continue;
}
iToSend++;
if (pBuff[i] == '\n')
{
// ret++;
UART_WriteToHost( UartOut, pLastBuff, iToSend );
iCnt += iToSend;
UART_WriteToHost( UartOut, &ch, 1 );
// FIX BY ETAY - also put /r, so increase number of printed
// chars by 1, not by entire line (iToSend) as was before
iCnt++;
//iCnt += iToSend;
pLastBuff = pBuff+i;
iToSend = 0;
}
}
UART_WriteToHost( UartOut, pLastBuff, iToSend );
iCnt += iToSend;
return iCnt;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?