2002-02-14 09:54:41 +03:00
|
|
|
/* $NetBSD: fmt.c,v 1.17 2002/02/14 06:54:41 enami Exp $ */
|
1998-01-09 10:00:57 +03:00
|
|
|
|
1999-12-03 05:26:36 +03:00
|
|
|
#include <kvm.h>
|
1995-05-21 17:38:25 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <vis.h>
|
1998-02-03 06:16:01 +03:00
|
|
|
#include <sys/time.h>
|
1997-07-21 00:37:53 +04:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include "ps.h"
|
1995-05-21 17:38:25 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
fmt_puts(s, leftp)
|
|
|
|
char *s;
|
|
|
|
int *leftp;
|
|
|
|
{
|
2002-02-14 09:54:41 +03:00
|
|
|
static char *v = 0;
|
1995-05-21 17:38:25 +04:00
|
|
|
static int maxlen = 0;
|
2002-02-14 09:54:41 +03:00
|
|
|
char *nv;
|
2001-03-20 22:05:11 +03:00
|
|
|
int len, nlen;
|
1995-05-21 17:38:25 +04:00
|
|
|
|
|
|
|
if (*leftp == 0)
|
|
|
|
return;
|
|
|
|
len = strlen(s) * 4 + 1;
|
|
|
|
if (len > maxlen) {
|
|
|
|
if (maxlen == 0)
|
2001-03-20 22:05:11 +03:00
|
|
|
nlen = getpagesize();
|
2001-03-23 04:06:02 +03:00
|
|
|
else
|
|
|
|
nlen = maxlen;
|
2001-03-20 22:05:11 +03:00
|
|
|
while (len > nlen)
|
|
|
|
nlen *= 2;
|
|
|
|
nv = realloc(v, nlen);
|
1995-05-21 17:38:25 +04:00
|
|
|
if (nv == 0)
|
|
|
|
return;
|
|
|
|
v = nv;
|
2001-03-20 22:05:11 +03:00
|
|
|
maxlen = nlen;
|
1995-05-21 17:38:25 +04:00
|
|
|
}
|
|
|
|
strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);
|
|
|
|
if (*leftp != -1) {
|
|
|
|
len = strlen(v);
|
|
|
|
if (len > *leftp) {
|
1995-05-25 07:14:37 +04:00
|
|
|
v[*leftp] = '\0';
|
1995-05-21 17:38:25 +04:00
|
|
|
*leftp = 0;
|
1995-05-25 07:14:37 +04:00
|
|
|
} else
|
1995-05-21 17:38:25 +04:00
|
|
|
*leftp -= len;
|
1995-05-25 07:14:37 +04:00
|
|
|
}
|
|
|
|
printf("%s", v);
|
1995-05-21 17:38:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fmt_putc(c, leftp)
|
|
|
|
int c;
|
|
|
|
int *leftp;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (*leftp == 0)
|
|
|
|
return;
|
|
|
|
if (*leftp != -1)
|
|
|
|
*leftp -= 1;
|
|
|
|
putchar(c);
|
|
|
|
}
|