apps/top.c
/**
 * @brief Sort an array of process struct pointers using the
 *        currently selected sort column.
 */
@brief Sort an array of process struct pointers using the
currently selected sort column.
@brief Sort an array of process struct pointers using the currently selected sort column .
static int sort_processes(const void * a, const void * b) {
	struct process * left  = *(struct process **)a;
	struct process * right = *(struct process **)b;
	struct columns * column = &ColumnDescriptions[sort_column];
	if (sort_column == COLUMN_NONE) {
		return strcmp(left->command_line, right->command_line);
	}
	switch (column->formatter) {
		case FORMATTER_DECIMAL:
		case FORMATTER_PERCENT: {
			int a = *(int*)((char *)left + column->member);
			int b = *(int*)((char *)right + column->member);
			return (column->sort_order == SORT_ASC) ? (a - b) : (b - a);
		}
		case FORMATTER_STRING: {
			char * a = *(char **)((char *)left + column->member);
			char * b = *(char **)((char *)right + column->member);
			return (column->sort_order == SORT_ASC) ? strcmp(a,b) : strcmp(b,a);
		}
		default: return 0;
	}
}
static int sort_processes ( const void * a , const void * b ) { struct process * left = * ( struct process * * ) a ; struct process * right = * ( struct process * * ) b ; struct columns * column = & ColumnDescriptions [ sort_column ] ; if ( sort_column == COLUMN_NONE ) { return strcmp ( left -> command_line , right -> command_line ) ; } switch ( column -> formatter ) { case FORMATTER_DECIMAL : case FORMATTER_PERCENT : { int a = * ( int * ) ( ( char * ) left + column -> member ) ; int b = * ( int * ) ( ( char * ) right + column -> member ) ; return ( column -> sort_order == SORT_ASC ) ? ( a - b ) : ( b - a ) ; } case FORMATTER_STRING : { char * a = * ( char * * ) ( ( char * ) left + column -> member ) ; char * b = * ( char * * ) ( ( char * ) right + column -> member ) ; return ( column -> sort_order == SORT_ASC ) ? strcmp ( a , b ) : strcmp ( b , a ) ; } default : return 0 ; } }
@brief Sort an array of process struct pointers using the
        currently selected sort column.
@brief Sort an array of process struct pointers using the currently selected sort column .