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 | |
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')
-rw-r--r-- | sys/ddb/db_output.c | 25 | ||||
-rw-r--r-- | sys/ddb/db_output.h | 20 |
2 files changed, 43 insertions, 2 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); +} diff --git a/sys/ddb/db_output.h b/sys/ddb/db_output.h index 545cb09fade..e2dbc4c2bf4 100644 --- a/sys/ddb/db_output.h +++ b/sys/ddb/db_output.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_output.h,v 1.10 2002/03/14 01:26:51 millert Exp $ */ +/* $OpenBSD: db_output.h,v 1.11 2002/05/14 16:12:33 art Exp $ */ /* $NetBSD: db_output.h,v 1.9 1996/04/04 05:13:50 cgd Exp $ */ /* @@ -39,3 +39,21 @@ int db_print_position(void); int db_printf(const char *, ...) __kprintf_attribute__((__format__(__kprintf__,1,2))); void db_end_line(int); + +/* + * This is a replacement for the non-standard %z, %n and %r printf formats + * in db_printf. + * + * db_format(buf, bufsize, val, format, alt, width) + * + * val is the value we want printed. + * format is one of DB_FORMAT_[ZRN] + * alt specifies if we should provide an "alternate" format (# in the printf + * format). + * width is the field width. 0 is the same as no width specifier. + */ +#define DB_FORMAT_Z 1 +#define DB_FORMAT_R 2 +#define DB_FORMAT_N 3 +#define DB_FORMAT_BUF_SIZE 64 /* should be plenty for all formats */ +char *db_format(char *, size_t, long, int, int, int); |