diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
commit | d6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch) | |
tree | ece253b876159b39c620e62b6c9b1174642e070e /bin/ps/fmt.c |
initial import of NetBSD tree
Diffstat (limited to 'bin/ps/fmt.c')
-rw-r--r-- | bin/ps/fmt.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c new file mode 100644 index 00000000000..f9a2c271ab6 --- /dev/null +++ b/bin/ps/fmt.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <vis.h> + +void +fmt_puts(s, leftp) + char *s; + int *leftp; +{ + static char *v = 0, *nv; + static int maxlen = 0; + int len; + + if (*leftp == 0) + return; + len = strlen(s) * 4 + 1; + if (len > maxlen) { + if (maxlen == 0) + maxlen = getpagesize(); + while (len > maxlen) + maxlen *= 2; + nv = realloc(v, maxlen); + if (nv == 0) + return; + v = nv; + } + strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE); + if (*leftp != -1) { + len = strlen(v); + if (len > *leftp) { + v[*leftp] = '\0'; + *leftp = 0; + } else + *leftp -= len; + } + printf("%s", v); +} + +void +fmt_putc(c, leftp) + int c; + int *leftp; +{ + + if (*leftp == 0) + return; + if (*leftp != -1) + *leftp -= 1; + putchar(c); +} |