1 /* $NetBSD: fmt.c,v 1.13 1998/02/03 03:16:01 perry Exp $ */ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <unistd.h> 7 #include <vis.h> 8 #include <sys/time.h> 9 #include <sys/resource.h> 10 #include "ps.h" 11 #include "extern.h" 12 13 void 14 fmt_puts(s, leftp) 15 char *s; 16 int *leftp; 17 { 18 static char *v = 0, *nv; 19 static int maxlen = 0; 20 int len; 21 22 if (*leftp == 0) 23 return; 24 len = strlen(s) * 4 + 1; 25 if (len > maxlen) { 26 if (maxlen == 0) 27 maxlen = getpagesize(); 28 while (len > maxlen) 29 maxlen *= 2; 30 nv = realloc(v, maxlen); 31 if (nv == 0) 32 return; 33 v = nv; 34 } 35 strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE); 36 if (*leftp != -1) { 37 len = strlen(v); 38 if (len > *leftp) { 39 v[*leftp] = '\0'; 40 *leftp = 0; 41 } else 42 *leftp -= len; 43 } 44 printf("%s", v); 45 } 46 47 void 48 fmt_putc(c, leftp) 49 int c; 50 int *leftp; 51 { 52 53 if (*leftp == 0) 54 return; 55 if (*leftp != -1) 56 *leftp -= 1; 57 putchar(c); 58 } 59