diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2006-03-20 20:27:46 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2006-03-20 20:27:46 +0000 |
commit | 59c4ef87b769c1a36b20f45eab3060bb9dbc0d22 (patch) | |
tree | 6d9a63d7a5d65c7f2ca064e8561040d20885aaab /usr.bin/m4/gnum4.c | |
parent | 0f5ef76916936b0c2154ed95cdab6cfd11c8f6a2 (diff) |
add limited support for format builtin in gnu-m4 mode, because I'm fed
up of patching it away in various autoconf derivatives.
okay miod@
Diffstat (limited to 'usr.bin/m4/gnum4.c')
-rw-r--r-- | usr.bin/m4/gnum4.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c index 0b71338263f..973df3b030c 100644 --- a/usr.bin/m4/gnum4.c +++ b/usr.bin/m4/gnum4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gnum4.c,v 1.32 2006/03/20 10:55:19 espie Exp $ */ +/* $OpenBSD: gnum4.c,v 1.33 2006/03/20 20:27:45 espie Exp $ */ /* * Copyright (c) 1999 Marc Espie @@ -503,6 +503,52 @@ doregexp(const char *argv[], int argc) } void +doformat(const char *argv[], int argc) +{ + const char *format = argv[2]; + int pos = 3; + while (*format != 0) { + if (*format != '%') { + addchar(*format++); + } else { + format++; + if (*format == '%' || *format == 0) { + addchar('%'); + if (*format == '%') + format++; + } else { + int left_padded = 0; + unsigned long width; + size_t l; + + if (*format == '-') { + left_padded = 1; + format++; + } + width = strtoul(format, &format, 10); + if (*format != 's') { + m4errx(1, "Unsupported format specification: %s.", argv[2]); + } + format++; + if (pos >= argc) + m4errx(1, "Format with too many values."); + l = strlen(argv[pos]); + if (!left_padded) { + while (l < width--) + addchar(' '); + } + addchars(argv[pos++], l); + if (left_padded) { + while (l < width--) + addchar(' '); + } + } + } + } + pbstr(getstring()); +} + +void doesyscmd(const char *cmd) { int p[2]; |