Home | History | Annotate | Line # | Download | only in ps
fmt.c revision 1.12
      1 /*	$NetBSD: fmt.c,v 1.12 1998/01/09 07:00:57 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/resource.h>
      9 #include "ps.h"
     10 #include "extern.h"
     11 
     12 void
     13 fmt_puts(s, leftp)
     14 	char *s;
     15 	int *leftp;
     16 {
     17 	static char *v = 0, *nv;
     18 	static int maxlen = 0;
     19 	int len;
     20 
     21 	if (*leftp == 0)
     22 		return;
     23 	len = strlen(s) * 4 + 1;
     24 	if (len > maxlen) {
     25 		if (maxlen == 0)
     26 			maxlen = getpagesize();
     27 		while (len > maxlen)
     28 			maxlen *= 2;
     29 		nv = realloc(v, maxlen);
     30 		if (nv == 0)
     31 			return;
     32 		v = nv;
     33 	}
     34 	strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);
     35 	if (*leftp != -1) {
     36 		len = strlen(v);
     37 		if (len > *leftp) {
     38 			v[*leftp] = '\0';
     39 			*leftp = 0;
     40 		} else
     41 			*leftp -= len;
     42 	}
     43 	printf("%s", v);
     44 }
     45 
     46 void
     47 fmt_putc(c, leftp)
     48 	int c;
     49 	int *leftp;
     50 {
     51 
     52 	if (*leftp == 0)
     53 		return;
     54 	if (*leftp != -1)
     55 		*leftp -= 1;
     56 	putchar(c);
     57 }
     58