diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-05-14 16:12:34 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-05-14 16:12:34 +0000 |
commit | 35b5cf41ece181531dfe61c047144502b2323573 (patch) | |
tree | 8fee2d27305ae926be331ef2177f247b4f2d6891 /sys/ddb/db_output.c | |
parent | a4cfbd718676369b886f401ff8cd7d67f0155a8a (diff) |
db_printf has three non-standard formats that are not supported by
printf. Since we want to be able to have some ddb functions use db_printf
or normal printf, provide a new way to acheive the same kind of formatting.
The new function is called db_format and can emulate all variations of
how the nonstandard db_printf formats are used.
Note that this doesn't (yet?) mean that we want to convert all the
non-standard formats, we just want to have that option.
miod@ ok.
Diffstat (limited to 'sys/ddb/db_output.c')
-rw-r--r-- | sys/ddb/db_output.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sys/ddb/db_output.c b/sys/ddb/db_output.c index 76e46f2dae5..bc55e0f9723 100644 --- a/sys/ddb/db_output.c +++ b/sys/ddb/db_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_output.c,v 1.17 2002/03/14 01:26:51 millert Exp $ */ +/* $OpenBSD: db_output.c,v 1.18 2002/05/14 16:12:33 art Exp $ */ /* $NetBSD: db_output.c,v 1.13 1996/04/01 17:27:14 christos Exp $ */ /* @@ -217,3 +217,26 @@ db_end_line(space) if (db_output_position >= db_max_width - space) db_printf("\n"); } + +char * +db_format(char *buf, size_t bufsize, long val, int format, int alt, int width) +{ + const char *fmt; + + if (format == DB_FORMAT_Z || db_radix == 16) + fmt = alt ? "-%#*lx" : "-%*lx"; + else if (db_radix == 8) + fmt = alt ? "-%#*lo" : "-%*lo"; + else + fmt = alt ? "-%#*lu" : "-%*lu"; + + /* The leading '-' is a nasty (and beautiful) idea from NetBSD */ + if (val < 0 && format != DB_FORMAT_N) + val = -val; + else + fmt++; + + snprintf(buf, bufsize, fmt, width, val); + + return (buf); +} |