apps/top.c
/**
 * @brief Print a single column to stdout with the appropriate formatter.
 */
@brief Print a single column to stdout with the appropriate formatter.
@brief Print a single column to stdout with the appropriate formatter .
static int print_column(struct process * proc, int column_id) {
	struct columns * column = &ColumnDescriptions[column_id];
	switch (column->formatter) {
		case FORMATTER_DECIMAL: {
			int value = *(int*)((char *)proc + column->member);
			return printf("%*d ", column->width, value);
		}
		case FORMATTER_PERCENT: {
			int value = *(int*)((char *)proc + column->member);
			if (value >= 1000) {
				return printf("%*d ", column->width, value / 10);
			} else {
				return printf("%*d.%01d ", column->width - 2, value / 10, value % 10);
			}
		}
		case FORMATTER_STRING: {
			char * value = *(char**)((char *)proc + column->member);
			return printf("%-*s ", column->width, value);
		}
		default: return 0;
	}
}
static int print_column ( struct process * proc , int column_id ) { struct columns * column = & ColumnDescriptions [ column_id ] ; switch ( column -> formatter ) { case FORMATTER_DECIMAL : { int value = * ( int * ) ( ( char * ) proc + column -> member ) ; return printf ( " " , column -> width , value ) ; } case FORMATTER_PERCENT : { int value = * ( int * ) ( ( char * ) proc + column -> member ) ; if ( value >= 1000 ) { return printf ( " " , column -> width , value / 10 ) ; } else { return printf ( " " , column -> width - 2 , value / 10 , value % 10 ) ; } } case FORMATTER_STRING : { char * value = * ( char * * ) ( ( char * ) proc + column -> member ) ; return printf ( " " , column -> width , value ) ; } default : return 0 ; } }
@brief Print a single column to stdout with the appropriate formatter.
@brief Print a single column to stdout with the appropriate formatter .