Changes to the file include several modifications to make it compile, changes to implement snprintf / vsnprintf, and of course, the changes to implement the Formatter::format() callback hook.
Wherever possible, the original implementation has been retained to simplify merging in future changes from the FreeBSD camp, using the __FORMATTER__ macro to distinguish the adaptations.
Definition in file vfprintf.c.
#include <stdarg.h>
#include <memory.h>
#include "config.h"
#include "compat/fpclassify.h"
#include <sys/cdefs.h>
#include <sys/types.h>
#include <ctype.h>
#include <limits.h>
#include <locale.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <float.h>
#include <math.h>
#include "floatio.h"
#include "gdtoa.h"
Go to the source code of this file.
Classes | |
struct | __siov |
struct | __suio |
union | arg |
Defines | |
#define | __FORMATTER__ |
#define | __FBSDID(x) |
#define | INTMAX_MAX INT_MAX |
#define | reallocf realloc |
#define | to_digit(c) ((c) - '0') |
#define | is_digit(c) ((unsigned)to_digit(c) <= 9) |
#define | to_char(n) ((n) + '0') |
#define | DEFPREC 6 |
#define | BUF 100 |
#define | STATIC_ARG_TBL_SIZE 8 |
#define | ALT 0x001 |
#define | LADJUST 0x004 |
#define | LONGDBL 0x008 |
#define | LONGINT 0x010 |
#define | LLONGINT 0x020 |
#define | SHORTINT 0x040 |
#define | ZEROPAD 0x080 |
#define | FPT 0x100 |
#define | GROUPING 0x200 |
#define | SIZET 0x400 |
#define | PTRDIFFT 0x800 |
#define | INTMAXT 0x1000 |
#define | CHARINT 0x2000 |
#define | PADSIZE 16 |
#define | PRINT(ptr, len) |
#define | PAD(howmany, with) |
#define | PRINTANDPAD(p, ep, len, with) |
#define | FLUSH() {} |
#define | GETARG(type) |
#define | SARG() |
#define | UARG() |
#define | INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT) |
#define | SJARG() |
#define | UJARG() |
#define | GETASTER(val) |
#define | ADDTYPE(type) |
#define | ADDSARG() |
#define | ADDUARG() |
#define | ADDASTER() |
Enumerations | |
enum | typeid { T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT, T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG, T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET, T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR, T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR } |
Functions | |
__FBSDID ("$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.69 2005/04/16 22:36:51 das Exp $") | |
size_t | formatter_format (void *fmtobj, char *str, size_t strsz) |
static char * | __ujtoa (uintmax_t, char *, int, int, const char *, int, char, const char *) |
static char * | __ultoa (u_long, char *, int, int, const char *, int, char, const char *) |
static char * | __wcsconv (wchar_t *, int) |
static void | __find_arguments (const char *, va_list, union arg **) |
static void | __grow_type_table (int, enum typeid **, int *) |
static int | exponent (char *, int, int) |
int | vsnprintf (char *str, size_t strsz, const char *fmt0, va_list ap) |
int | snprintf (char *str, size_t strsz, const char *fmt,...) |
#define __FBSDID | ( | x | ) |
Definition at line 85 of file vfprintf.c.
#define __FORMATTER__ |
Definition at line 16 of file vfprintf.c.
#define ADDASTER | ( | ) |
#define ADDSARG | ( | ) |
#define ADDTYPE | ( | type | ) |
Value:
((nextarg >= tablesize) ? \ __grow_type_table(nextarg, &typetable, &tablesize) : (void)0, \ (nextarg > tablemax) ? tablemax = nextarg : 0, \ typetable[nextarg++] = type)
Referenced by __find_arguments().
#define ADDUARG | ( | ) |
#define ALT 0x001 |
#define BUF 100 |
#define CHARINT 0x2000 |
#define DEFPREC 6 |
#define FLUSH | ( | ) | {} |
Referenced by vsnprintf().
#define FPT 0x100 |
#define GETARG | ( | type | ) |
Value:
((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \ (nextarg++, va_arg(ap, type)))
Referenced by vsnprintf().
#define GETASTER | ( | val | ) |
Value:
n2 = 0; \ cp = fmt; \ while (is_digit(*cp)) { \ n2 = 10 * n2 + to_digit(*cp); \ cp++; \ } \ if (*cp == '$') { \ int hold = nextarg; \ if (argtable == NULL) { \ argtable = statargtable; \ __find_arguments (fmt0, orgap, &argtable); \ } \ nextarg = n2; \ val = GETARG (int); \ nextarg = hold; \ fmt = ++cp; \ } else { \ val = GETARG (int); \ }
Referenced by vsnprintf().
#define GROUPING 0x200 |
#define INTMAX_MAX INT_MAX |
#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT) |
Referenced by vsnprintf().
#define INTMAXT 0x1000 |
#define is_digit | ( | c | ) | ((unsigned)to_digit(c) <= 9) |
#define LADJUST 0x004 |
#define LLONGINT 0x020 |
#define LONGDBL 0x008 |
#define LONGINT 0x010 |
#define PAD | ( | howmany, | |||
with | ) |
Value:
{ \ if ((n = (howmany)) > 0) { \ while (n > PADSIZE) { \ PRINT(with, PADSIZE); \ n -= PADSIZE; \ } \ PRINT(with, n); \ } \ }
Referenced by vsnprintf().
#define PADSIZE 16 |
Referenced by vsnprintf().
#define PRINT | ( | ptr, | |||
len | ) |
Value:
{ \ sz = (((size_t)len) <= strsz) ? len : strsz; \ memcpy(str, ptr, sz); \ str += sz; \ strsz -= sz; \ }
Referenced by vsnprintf().
#define PRINTANDPAD | ( | p, | |||
ep, | |||||
len, | |||||
with | ) |
Value:
do { \ n2 = (ep) - (p); \ if (n2 > (len)) \ n2 = (len); \ if (n2 > 0) \ PRINT((p), n2); \ PAD((len) - (n2 > 0 ? n2 : 0), (with)); \ } while(0)
Referenced by vsnprintf().
#define PTRDIFFT 0x800 |
#define reallocf realloc |
#define SARG | ( | ) |
Value:
(flags&LONGINT ? GETARG(long) : \ flags&SHORTINT ? (long)(short)GETARG(int) : \ flags&CHARINT ? (long)(signed char)GETARG(int) : \ (long)GETARG(int))
Referenced by vsnprintf().
#define SHORTINT 0x040 |
#define SIZET 0x400 |
#define SJARG | ( | ) |
Value:
(flags&INTMAXT ? GETARG(intmax_t) : \ flags&SIZET ? (intmax_t)GETARG(size_t) : \ flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \ (intmax_t)GETARG(long long))
Referenced by vsnprintf().
#define STATIC_ARG_TBL_SIZE 8 |
Definition at line 557 of file vfprintf.c.
Referenced by __find_arguments(), __grow_type_table(), and vsnprintf().
#define to_char | ( | n | ) | ((n) + '0') |
Definition at line 274 of file vfprintf.c.
Referenced by __ujtoa(), __ultoa(), exponent(), and oasys::fast_ultoa().
#define to_digit | ( | c | ) | ((c) - '0') |
#define UARG | ( | ) |
Value:
(flags&LONGINT ? GETARG(u_long) : \ flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \ flags&CHARINT ? (u_long)(u_char)GETARG(int) : \ (u_long)GETARG(u_int))
Referenced by vsnprintf().
#define UJARG | ( | ) |
Value:
(flags&INTMAXT ? GETARG(uintmax_t) : \ flags&SIZET ? (uintmax_t)GETARG(size_t) : \ flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \ (uintmax_t)GETARG(unsigned long long))
Referenced by vsnprintf().
#define ZEROPAD 0x080 |
enum typeid |
Definition at line 193 of file vfprintf.c.
__FBSDID | ( | "$FreeBSD: src/lib/libc/stdio/vfprintf. | c, | |
v 1.69 2005/04/16 22:36:51 das Exp $" | ||||
) |
static void __find_arguments | ( | const char * | , | |
va_list | , | |||
union arg ** | ||||
) | [static] |
Definition at line 1478 of file vfprintf.c.
References ADDASTER, ADDSARG, ADDTYPE, ADDUARG, CHARINT, arg::intarg, INTMAXT, is_digit, LLONGINT, LONGDBL, LONGINT, PTRDIFFT, SHORTINT, SIZET, STATIC_ARG_TBL_SIZE, T_DOUBLE, T_INT, T_INTMAXT, T_LLONG, T_LONG, T_LONG_DOUBLE, T_PTRDIFFT, T_SIZET, T_U_INT, T_U_LLONG, T_U_LONG, T_UINTMAXT, T_UNUSED, T_WINT, to_digit, TP_CHAR, TP_INT, TP_INTMAXT, TP_LLONG, TP_LONG, TP_PTRDIFFT, TP_SCHAR, TP_SHORT, TP_SIZET, TP_VOID, and TP_WCHAR.
Referenced by vsnprintf().
static void __grow_type_table | ( | int | , | |
enum typeid ** | , | |||
int * | ||||
) | [static] |
static char * __ujtoa | ( | uintmax_t | , | |
char * | , | |||
int | , | |||
int | , | |||
const char * | , | |||
int | , | |||
char | , | |||
const char * | ||||
) | [static] |
Definition at line 360 of file vfprintf.c.
References __ultoa(), INTMAX_MAX, and to_char.
Referenced by vsnprintf().
static char * __ultoa | ( | u_long | , | |
char * | , | |||
int | , | |||
int | , | |||
const char * | , | |||
int | , | |||
char | , | |||
const char * | ||||
) | [static] |
Definition at line 283 of file vfprintf.c.
References to_char.
Referenced by __ujtoa(), and vsnprintf().
static char * __wcsconv | ( | wchar_t * | , | |
int | ||||
) | [static] |
static int exponent | ( | char * | , | |
int | , | |||
int | ||||
) | [static] |
Definition at line 1833 of file vfprintf.c.
References MAXEXPDIG, and to_char.
Referenced by vsnprintf().
size_t formatter_format | ( | void * | fmtobj, | |
char * | str, | |||
size_t | strsz | |||
) |
Referenced by vsnprintf().
int snprintf | ( | char * | str, | |
size_t | strsz, | |||
const char * | fmt, | |||
... | ||||
) |
Definition at line 1459 of file vfprintf.c.
References vsnprintf().
Referenced by oasys::Bluetooth::_batostr(), dtn_strerror(), oasys::ByteBufShim::format(), oasys::NullStringShim::format(), oasys::StringShim::format(), oasys::UIntShim::format(), oasys::IntShim::format(), dtn::RouteEntry::format(), oasys::RefCountedObject::format(), dtn::Link::format(), dtn::Contact::format(), dtn::Bundle::format(), oasys::Log::gen_prefix(), dtn::FragmentManager::get_hash_key(), dtn::APIClient::handle_recv(), oasys::FatalSignals::handler(), oasys::Log::log_multiline(), main(), dtn::ContactManager::new_opportunistic_link(), oasys::Log::parse_debug_file(), oasys::KeyMarshal::process_int(), oasys::KeyMarshal::process_int64(), dtn::CustodySignal::reason_to_str(), oasys::FileSystemStore::tidy_database(), dtn::DTNServer::tidy_dir(), oasys::Getopt::usage(), and oasys::Log::vlogf().
int vsnprintf | ( | char * | str, | |
size_t | strsz, | |||
const char * | fmt0, | |||
va_list | ap | |||
) |
Definition at line 582 of file vfprintf.c.
References __find_arguments(), __hdtoa(), __hldtoa(), __ldtoa(), __ujtoa(), __ultoa(), __wcsconv(), ALT, BUF, CHARINT, DEFPREC, exponent(), FLUSH, formatter_format(), FPT, GETARG, GETASTER, GROUPING, INTMAX_SIZE, INTMAXT, is_digit, LADJUST, LLONGINT, LONGDBL, LONGINT, MAXEXPDIG, PAD, PADSIZE, PRINT, PRINTANDPAD, PTRDIFFT, SARG, SHORTINT, SIZET, SJARG, STATIC_ARG_TBL_SIZE, to_digit, UARG, __suio::uio_iov, __suio::uio_iovcnt, __suio::uio_resid, UJARG, and ZEROPAD.
Referenced by oasys::Logger::Logger(), oasys::Logger::logpath_appendf(), oasys::Logger::logpathf(), snprintf(), oasys::StringBuffer::vappendf(), oasys::StringAppender::vappendf(), oasys::BufferedOutput::vformat_buf(), and oasys::Log::vlogf().