FreeBSD/bin/ps/print.c
/*
 * Generic output routines.  Print fields from various prototype
 * structures.
 */
Generic output routines.  Print fields from various prototype
structures.
Generic output routines . Print fields from various prototype structures .
static char *
printval(void *bp, VAR *v)
{
	static char ofmt[32] = "%";
	const char *fcp;
	char *cp, *str;
	cp = ofmt + 1;
	fcp = v->fmt;
	while ((*cp++ = *fcp++));
#define	CHKINF127(n)	(((n) > 127) && (v->flag & INF127) ? 127 : (n))
	switch (v->type) {
	case CHAR:
		(void)asprintf(&str, ofmt, *(char *)bp);
		break;
	case UCHAR:
		(void)asprintf(&str, ofmt, *(u_char *)bp);
		break;
	case SHORT:
		(void)asprintf(&str, ofmt, *(short *)bp);
		break;
	case USHORT:
		(void)asprintf(&str, ofmt, *(u_short *)bp);
		break;
	case INT:
		(void)asprintf(&str, ofmt, *(int *)bp);
		break;
	case UINT:
		(void)asprintf(&str, ofmt, CHKINF127(*(u_int *)bp));
		break;
	case LONG:
		(void)asprintf(&str, ofmt, *(long *)bp);
		break;
	case ULONG:
		(void)asprintf(&str, ofmt, *(u_long *)bp);
		break;
	case KPTR:
		(void)asprintf(&str, ofmt, *(u_long *)bp);
		break;
	case PGTOK:
		(void)asprintf(&str, ofmt, ps_pgtok(*(u_long *)bp));
		break;
	default:
		xo_errx(1, "unknown type %d", v->type);
	}
	return (str);
}
static char * printval ( void * bp , VAR * v ) { static char ofmt [ 32 ] = " " ; const char * fcp ; char * cp , * str ; cp = ofmt + 1 ; fcp = v -> fmt ; while ( ( * cp ++ = * fcp ++ ) ) ; #define CHKINF127 ( n ) 	(((n) > 127) && (v->flag & INF127) ? 127 : (n)) switch ( v -> type ) { case CHAR : ( void ) asprintf ( & str , ofmt , * ( char * ) bp ) ; break ; case UCHAR : ( void ) asprintf ( & str , ofmt , * ( u_char * ) bp ) ; break ; case SHORT : ( void ) asprintf ( & str , ofmt , * ( short * ) bp ) ; break ; case USHORT : ( void ) asprintf ( & str , ofmt , * ( u_short * ) bp ) ; break ; case INT : ( void ) asprintf ( & str , ofmt , * ( int * ) bp ) ; break ; case UINT : ( void ) asprintf ( & str , ofmt , CHKINF127 ( * ( u_int * ) bp ) ) ; break ; case LONG : ( void ) asprintf ( & str , ofmt , * ( long * ) bp ) ; break ; case ULONG : ( void ) asprintf ( & str , ofmt , * ( u_long * ) bp ) ; break ; case KPTR : ( void ) asprintf ( & str , ofmt , * ( u_long * ) bp ) ; break ; case PGTOK : ( void ) asprintf ( & str , ofmt , ps_pgtok ( * ( u_long * ) bp ) ) ; break ; default : xo_errx ( 1 , " " , v -> type ) ; } return ( str ) ; }
Generic output routines.
Generic output routines .