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