printfold.c

来自「A MP3 Player Source Code, Enjoy it!」· C语言 代码 · 共 126 行

C
126
字号
/*-----------------------------------------------------------------    printfl.c - source file for reduced version of printf    Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)    This program is free software; you can redistribute it and/or modify it    under the terms of the GNU General Public License as published by the    Free Software Foundation; either version 2, or (at your option) any    later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    In other words, you are welcome to use, share and improve this program.    You are forbidden to forbid anyone else to use, share and improve    what you give them.   Help stamp out software-hoarding!-------------------------------------------------------------------------*//* following formats are supported :-   format     output type       argument-type     %d        decimal             int     %ld       decimal             long     %hd       decimal             short/char     %x        hexadecimal         int     %lx       hexadecimal         long     %hx       hexadecimal         short/char     %c        character           char/short     %s        character           _generic pointer*/#include <stdarg.h>#include <reg51.h>#include "paulmon2.h"#include "printf.h"extern void putchar(char );static data volatile char ch;static data char radix ;static bit  long_flag = 0;static bit  string_flag =0;static bit  short_flag = 0;static bit sign;static char * data str ;static long val;void printf (code char * fmt, ... ) reentrant{	va_list ap ;	va_start(ap,fmt);	for (; *fmt ; fmt++ ) {		if (*fmt == '%') {			long_flag = string_flag = short_flag = 0;			fmt++ ;			switch (*fmt) {			case 'l':				long_flag = 1;				fmt++;				break;			case 'h':				short_flag = 1;				fmt++;			}			switch (*fmt) {			case 's':				string_flag = 1;				break;			case 'd':				radix = 10;				break;			case 'x':				radix = 16;				break;			case 'c':				radix = 0;				break;			}			if (string_flag) {				str = va_arg(ap,char _generic *);				while (*str) putchar(*str++);				continue ;			}			if (long_flag)				val = va_arg(ap,long);			else			if (short_flag)				val = va_arg(ap,short);			else				val = va_arg(ap,int);			switch (radix) {			case 10:				pm2_pint16u((int)(val & 0xFFFF));				//pvaldec(val) ;				break;			case 16:				pm2_phex16((int)(val & 0xFFFF));				//pvalhex (val);				break;			case 0:				putchar((char)val);				break;			}		} else {			putchar(*fmt);		}	}}

⌨️ 快捷键说明

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