From f383bda56a5f0847dc98d6e09fdabae66a416913 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 23 May 2006 20:30:48 +0000 Subject: 2006-05-23 Jeff Johnston * libc/misc/dprintf.c: Removed. * libc/misc/__dprintf.c: Renamed from dprintf.c. * libc/misc/Makefile.am: Changed appropriately for rename. * libc/misc/Makefile.in: Regenerated. --- newlib/libc/misc/Makefile.am | 2 +- newlib/libc/misc/Makefile.in | 14 +-- newlib/libc/misc/__dprintf.c | 271 +++++++++++++++++++++++++++++++++++++++++++ newlib/libc/misc/dprintf.c | 271 ------------------------------------------- 4 files changed, 279 insertions(+), 279 deletions(-) create mode 100644 newlib/libc/misc/__dprintf.c delete mode 100644 newlib/libc/misc/dprintf.c (limited to 'newlib/libc') diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am index a24333dd8..56eeeee0e 100644 --- a/newlib/libc/misc/Makefile.am +++ b/newlib/libc/misc/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -LIB_SOURCES = dprintf.c unctrl.c ffs.c init.c +LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c libmisc_la_LDFLAGS = -Xcompiler -nostdlib diff --git a/newlib/libc/misc/Makefile.in b/newlib/libc/misc/Makefile.in index 95919367b..95269af5a 100644 --- a/newlib/libc/misc/Makefile.in +++ b/newlib/libc/misc/Makefile.in @@ -54,13 +54,13 @@ LIBRARIES = $(noinst_LIBRARIES) ARFLAGS = cru lib_a_AR = $(AR) $(ARFLAGS) lib_a_LIBADD = -am__objects_1 = lib_a-dprintf.$(OBJEXT) lib_a-unctrl.$(OBJEXT) \ +am__objects_1 = lib_a-__dprintf.$(OBJEXT) lib_a-unctrl.$(OBJEXT) \ lib_a-ffs.$(OBJEXT) lib_a-init.$(OBJEXT) @USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) lib_a_OBJECTS = $(am_lib_a_OBJECTS) LTLIBRARIES = $(noinst_LTLIBRARIES) libmisc_la_LIBADD = -am__objects_2 = dprintf.lo unctrl.lo ffs.lo init.lo +am__objects_2 = __dprintf.lo unctrl.lo ffs.lo init.lo @USE_LIBTOOL_TRUE@am_libmisc_la_OBJECTS = $(am__objects_2) libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS) @USE_LIBTOOL_TRUE@am_libmisc_la_rpath = @@ -219,7 +219,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -LIB_SOURCES = dprintf.c unctrl.c ffs.c init.c +LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c libmisc_la_LDFLAGS = -Xcompiler -nostdlib @USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libmisc.la @USE_LIBTOOL_TRUE@libmisc_la_SOURCES = $(LIB_SOURCES) @@ -300,11 +300,11 @@ distclean-compile: .c.lo: $(LTCOMPILE) -c -o $@ $< -lib_a-dprintf.o: dprintf.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-dprintf.o `test -f 'dprintf.c' || echo '$(srcdir)/'`dprintf.c +lib_a-__dprintf.o: __dprintf.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-__dprintf.o `test -f '__dprintf.c' || echo '$(srcdir)/'`__dprintf.c -lib_a-dprintf.obj: dprintf.c - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-dprintf.obj `if test -f 'dprintf.c'; then $(CYGPATH_W) 'dprintf.c'; else $(CYGPATH_W) '$(srcdir)/dprintf.c'; fi` +lib_a-__dprintf.obj: __dprintf.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-__dprintf.obj `if test -f '__dprintf.c'; then $(CYGPATH_W) '__dprintf.c'; else $(CYGPATH_W) '$(srcdir)/__dprintf.c'; fi` lib_a-unctrl.o: unctrl.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-unctrl.o `test -f 'unctrl.c' || echo '$(srcdir)/'`unctrl.c diff --git a/newlib/libc/misc/__dprintf.c b/newlib/libc/misc/__dprintf.c new file mode 100644 index 000000000..0b780f59b --- /dev/null +++ b/newlib/libc/misc/__dprintf.c @@ -0,0 +1,271 @@ +/* Debugging printf, for debugging the library itself. + + We don't assume stdio is working. + We do assume _write_r is working. +*/ + +#include "ctype.h" +#include "reent.h" +#include "string.h" +#include "unctrl.h" + +#ifdef __STDC__ +#include "stdarg.h" +#else +#include "varargs.h" +#endif + +#if 0 +static char *parse_number (); +#endif + +static long get_number (); +static void print_number (); +static void write_char (); +static void write_string (); + +/* Non-zero for big-endian systems. */ +static int big_endian_p; + +/* For now hardcode 2 (stderr) as the console file descriptor. + May wish to let the caller pass in a file descriptor or some such but + this is only for debugging purposes anyway. */ +#define CONSOLE_FD 2 + +/* Standalone printf routine. + + The format string has been enhanced so that multiple values can be dumped + without having to have a %-field for each one (say if you want to dump + 20 words at a certain address). A modifier of `N' says the next argument + is a count, and the one after that is a pointer. + + Example: __dprintf (stderr, "%Nx\n", 20, p); /-* print 20 ints at `p' *-/ + + Supported formats are: c d u x s p. + + All ints are retrieved a byte at a time so alignment issues are not + a problem. + + This routine is used in situations where the only debugging capability + is console output and was written to aid debugging newlib itself. We don't + use printf ourselves as we may be debugging it. We do assume _write_r is + working. +*/ + +void +#ifdef __STDC__ +__dprintf (char *fmt, ...) +#else +__dprintf (fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + va_list args; + + /* Which endian are we? */ + { + short tmp = 1; + big_endian_p = *(char *) &tmp == 0; + } + +#ifdef __STDC__ + va_start (args, fmt); +#else + va_start (args); +#endif + + while (*fmt) + { + char c, *p; + int count; + long l; + + if (*fmt != '%' || *++fmt == '%') + { + write_char (*fmt++); + continue; + } + + if (*fmt == 'N') + { + count = va_arg (args, int); + p = va_arg (args, char *); + ++fmt; + c = *fmt++; + + while (--count >= 0) + { + switch (c) + { + case 'c' : + write_string (unctrl (*p++)); + break; + case 'p' : + print_number (16, 1, get_number (p, sizeof (char *), 1)); + p += sizeof (char *); + break; + case 'd' : + case 'u' : + case 'x' : + print_number (c == 'x' ? 16 : 10, c != 'd', + get_number (p, sizeof (int), c != 'd')); + p += sizeof (int); + break; + case 's' : + write_string (*(char **) p); + p += sizeof (char *); + break; + } + if (count > 0) + write_char (' '); + } + } + else + { + switch (c = *fmt++) + { + case 'c' : + c = va_arg (args, int); + write_string (unctrl (c)); + break; + case 'p' : + l = (_POINTER_INT) va_arg (args, char *); + print_number (16, 1, l); + break; + case 'd' : + case 'u' : + case 'x' : + l = va_arg (args, int); + print_number (c == 'x' ? 16 : 10, c != 'd', l); + break; + case 's' : + p = va_arg (args, char *); + write_string (p); + break; + } + } + } + + va_end (args); +} + +#if 0 +/* Parse a positive decimal integer at S. + FIXME: Was used in earlier version, but not currently used. + Keep for now. */ + +static char * +parse_number (s, p) + char *s; + long *p; +{ + long x = 0; + + while (isdigit (*s)) + { + x = (x * 10) + (*s - '0'); + ++s; + } + + *p = x; + return s; +} +#endif + +/* Fetch the number at S of SIZE bytes. */ + +static long +get_number (s, size, unsigned_p) + char *s; + long size; + int unsigned_p; +{ + long x; + unsigned char *p = (unsigned char *) s; + + switch (size) + { + case 1 : + x = *p; + if (!unsigned_p) + x = (x ^ 0x80) - 0x80; + return x; + case 2 : + if (big_endian_p) + x = (p[0] << 8) | p[1]; + else + x = (p[1] << 8) | p[0]; + if (!unsigned_p) + x = (x ^ 0x8000) - 0x8000; + return x; + case 4 : + if (big_endian_p) + x = ((long)p[0] << 24) | ((long)p[1] << 16) | (p[2] << 8) | p[3]; + else + x = ((long)p[3] << 24) | ((long)p[2] << 16) | (p[1] << 8) | p[0]; + if (!unsigned_p) + x = (x ^ 0x80000000L) - 0x80000000L; + return x; +#if 0 /* FIXME: Is there a standard mechanism for knowing if + long longs exist? */ + case 8 : +#endif + default : + return 0; + } +} + +/* Print X in base BASE. */ + +static void +print_number (base, unsigned_p, n) + int base; + int unsigned_p; + long n; +{ + static char chars[16] = "0123456789abcdef"; + char *p, buf[32]; + unsigned long x; + + if (!unsigned_p && n < 0) + { + write_char ('-'); + x = -n; + } + else + x = n; + + p = buf + sizeof (buf); + *--p = '\0'; + do + { + *--p = chars[x % base]; + x /= base; + } + while (x != 0); + + write_string (p); +} + +/* Write C to the console. + We go through the file descriptor directly because we can't assume + stdio is working. */ + +static void +write_char (c) + char c; +{ + _write_r (_REENT, CONSOLE_FD, &c, 1); +} + +/* Write S to the console. + We go through the file descriptor directly because we can't assume + stdio is working. */ + +static void +write_string (s) + char *s; +{ + _write_r (_REENT, CONSOLE_FD, s, strlen (s)); +} diff --git a/newlib/libc/misc/dprintf.c b/newlib/libc/misc/dprintf.c deleted file mode 100644 index 0b780f59b..000000000 --- a/newlib/libc/misc/dprintf.c +++ /dev/null @@ -1,271 +0,0 @@ -/* Debugging printf, for debugging the library itself. - - We don't assume stdio is working. - We do assume _write_r is working. -*/ - -#include "ctype.h" -#include "reent.h" -#include "string.h" -#include "unctrl.h" - -#ifdef __STDC__ -#include "stdarg.h" -#else -#include "varargs.h" -#endif - -#if 0 -static char *parse_number (); -#endif - -static long get_number (); -static void print_number (); -static void write_char (); -static void write_string (); - -/* Non-zero for big-endian systems. */ -static int big_endian_p; - -/* For now hardcode 2 (stderr) as the console file descriptor. - May wish to let the caller pass in a file descriptor or some such but - this is only for debugging purposes anyway. */ -#define CONSOLE_FD 2 - -/* Standalone printf routine. - - The format string has been enhanced so that multiple values can be dumped - without having to have a %-field for each one (say if you want to dump - 20 words at a certain address). A modifier of `N' says the next argument - is a count, and the one after that is a pointer. - - Example: __dprintf (stderr, "%Nx\n", 20, p); /-* print 20 ints at `p' *-/ - - Supported formats are: c d u x s p. - - All ints are retrieved a byte at a time so alignment issues are not - a problem. - - This routine is used in situations where the only debugging capability - is console output and was written to aid debugging newlib itself. We don't - use printf ourselves as we may be debugging it. We do assume _write_r is - working. -*/ - -void -#ifdef __STDC__ -__dprintf (char *fmt, ...) -#else -__dprintf (fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list args; - - /* Which endian are we? */ - { - short tmp = 1; - big_endian_p = *(char *) &tmp == 0; - } - -#ifdef __STDC__ - va_start (args, fmt); -#else - va_start (args); -#endif - - while (*fmt) - { - char c, *p; - int count; - long l; - - if (*fmt != '%' || *++fmt == '%') - { - write_char (*fmt++); - continue; - } - - if (*fmt == 'N') - { - count = va_arg (args, int); - p = va_arg (args, char *); - ++fmt; - c = *fmt++; - - while (--count >= 0) - { - switch (c) - { - case 'c' : - write_string (unctrl (*p++)); - break; - case 'p' : - print_number (16, 1, get_number (p, sizeof (char *), 1)); - p += sizeof (char *); - break; - case 'd' : - case 'u' : - case 'x' : - print_number (c == 'x' ? 16 : 10, c != 'd', - get_number (p, sizeof (int), c != 'd')); - p += sizeof (int); - break; - case 's' : - write_string (*(char **) p); - p += sizeof (char *); - break; - } - if (count > 0) - write_char (' '); - } - } - else - { - switch (c = *fmt++) - { - case 'c' : - c = va_arg (args, int); - write_string (unctrl (c)); - break; - case 'p' : - l = (_POINTER_INT) va_arg (args, char *); - print_number (16, 1, l); - break; - case 'd' : - case 'u' : - case 'x' : - l = va_arg (args, int); - print_number (c == 'x' ? 16 : 10, c != 'd', l); - break; - case 's' : - p = va_arg (args, char *); - write_string (p); - break; - } - } - } - - va_end (args); -} - -#if 0 -/* Parse a positive decimal integer at S. - FIXME: Was used in earlier version, but not currently used. - Keep for now. */ - -static char * -parse_number (s, p) - char *s; - long *p; -{ - long x = 0; - - while (isdigit (*s)) - { - x = (x * 10) + (*s - '0'); - ++s; - } - - *p = x; - return s; -} -#endif - -/* Fetch the number at S of SIZE bytes. */ - -static long -get_number (s, size, unsigned_p) - char *s; - long size; - int unsigned_p; -{ - long x; - unsigned char *p = (unsigned char *) s; - - switch (size) - { - case 1 : - x = *p; - if (!unsigned_p) - x = (x ^ 0x80) - 0x80; - return x; - case 2 : - if (big_endian_p) - x = (p[0] << 8) | p[1]; - else - x = (p[1] << 8) | p[0]; - if (!unsigned_p) - x = (x ^ 0x8000) - 0x8000; - return x; - case 4 : - if (big_endian_p) - x = ((long)p[0] << 24) | ((long)p[1] << 16) | (p[2] << 8) | p[3]; - else - x = ((long)p[3] << 24) | ((long)p[2] << 16) | (p[1] << 8) | p[0]; - if (!unsigned_p) - x = (x ^ 0x80000000L) - 0x80000000L; - return x; -#if 0 /* FIXME: Is there a standard mechanism for knowing if - long longs exist? */ - case 8 : -#endif - default : - return 0; - } -} - -/* Print X in base BASE. */ - -static void -print_number (base, unsigned_p, n) - int base; - int unsigned_p; - long n; -{ - static char chars[16] = "0123456789abcdef"; - char *p, buf[32]; - unsigned long x; - - if (!unsigned_p && n < 0) - { - write_char ('-'); - x = -n; - } - else - x = n; - - p = buf + sizeof (buf); - *--p = '\0'; - do - { - *--p = chars[x % base]; - x /= base; - } - while (x != 0); - - write_string (p); -} - -/* Write C to the console. - We go through the file descriptor directly because we can't assume - stdio is working. */ - -static void -write_char (c) - char c; -{ - _write_r (_REENT, CONSOLE_FD, &c, 1); -} - -/* Write S to the console. - We go through the file descriptor directly because we can't assume - stdio is working. */ - -static void -write_string (s) - char *s; -{ - _write_r (_REENT, CONSOLE_FD, s, strlen (s)); -} -- cgit v1.2.3