可移植printf源码(一)

2014-11-23 22:08:39 ? 作者: ? 浏览: 12
/* tab space = 4 */
/*********************************************************************
* DISCLAIMER: *
* The software supplied by Renesas Technology America Inc. is *
* intended and supplied for use on Renesas Technology products. *
* This software is owned by Renesas Technology America, Inc. or *
* Renesas Technology Corporation and is protected under applicable *
* copyright laws. All rights are reserved. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, *
* IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO IMPLIED *
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
* APPLY TO THIS SOFTWARE. RENESAS TECHNOLOGY AMERICA, INC. AND *
* AND RENESAS TECHNOLOGY CORPORATION RESERVE THE RIGHT, WITHOUT *
* NOTICE, TO MAKE CHANGES TO THIS SOFTWARE. NEITHER RENESAS *
* TECHNOLOGY AMERICA, INC. NOR RENESAS TECHNOLOGY CORPORATION SHALL, *
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR *
* CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER ARISING OUT OF THE *
* USE OR APPLICATION OF THIS SOFTWARE. *
*********************************************************************/
/*-----------------------------------------------------------------------------
FILE NAME: simple_printf.c
-----------
DESCRIPTION: Simplified printf and sprintf. (float and signed values no supported)
-----------
DETAILS:
------------------
Revision History
------------------
1.6 April 7, 2007
Changed "..." access over to using standard "va_" macros for compatibility with other compilers.
1.5 July 16, 2006
Initialized local "s" in _print_out() in order to suppress compiler warning.
1.4 April 28, 2006
ROM/RAM reductions. Also NC30WA V.5.40 compatable.
1.3 Feb 21, 2006
Combined printf and sprintf functions
1.2 Nov 15, 2005
Fixed bug when using "%lx" or %lX
1.1 Sept 8, 2005
Fixed bug when using "%Ld"
Fixed bug for sprintf (did not add NULL at end)
1.0 , 2005
Initial Version
-----------------------------------------------------------------------------*/
#include
#include
#if defined NC308
#define FAR _far
#elif defined NC30
#define FAR _far
#else
#define FAR
#endif
enum { UI, UH, UL, SI, SH, SL };
enum { LEFT_SPACE, PREFIX, ZERO_PAD, VALUE_TXT, RIGHT_SPACE, OUT_DONE};
static const struct
{
char c[2];
char size;
} prefix[]=
{
{{0,0},0}, /* 0: default, no prefix */
{{'-',0},1}, /* 1: minus sign */
{{'+',0},1}, /* 2: plus sign */
{{' ',0},1}, /* 3: space */
{{'0','x'},2}, /* 4: hex 0x */
{{'0','X'},2}, /* 5: hex 0X */
};
/* Function Prototypes */
int _print_out(char FAR *s, const char FAR *format, va_list sp);
int sprintf(char FAR *s, const char FAR *format, ...)
{
int return_count;
va_list sp;
va_start(sp, format);
return_count = _print_out(s, format, sp);
va_end(sp);
return (return_count);
}
int printf(const char FAR *format, ...)
{
int return_count;
va_list sp;
-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: