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