Exemplo n.º 1
0
static int cmp_rows(const void *f1, const void *f2)
{
	static const signed char sort_order[] =
		{ COL_NAME, COL_TIME, COL_SIZE, -1 };
	int *r1, *r2;
	char *s1, *s2;
	int d, c, bits, lvl;

	r1 = mdt->fcols + *(int *)f1 * COL_MAX;
	r2 = mdt->fcols + *(int *)f2 * COL_MAX;

	/* "/ .." Directory always goes first, other dirs next, files last;
	 * and their type IDs are ordered to reflect that */
	s1 = RELREF(r1[COL_NAME]);
	s2 = RELREF(r2[COL_NAME]);
	if ((d = s1[0] - s2[0])) return (d);

	bits = lvl = 0;
	c = abs(mdt->fsort) - 1 + COL_NAME;

	while (c >= 0)
	{
		if (bits & (1 << c))
		{
			c = sort_order[lvl++];
			continue;
		}
		bits |= 1 << c;
		s1 = RELREF(r1[c]);
		s2 = RELREF(r2[c]);
		switch (c)
		{
		case COL_TYPE:
			if ((d = strcollcmp(s1, s2))) break;
			continue;
		case COL_SIZE:
			if ((d = strcmp(s1, s2))) break;
			continue;
		case COL_TIME:
			if ((d = strcmp(s2, s1))) break; // Newest first
			continue;
		default:
		case COL_NAME:
			c = case_insensitive ? COL_NOCASE : COL_CASE;
			continue;
		case COL_NOCASE:
		case COL_CASE:
			if ((d = strkeycmp(s1, s2))) break;
			c = COL_CASE;
			continue;
		}
		break;
	}
	return (mdt->fsort < 0 ? -d : d);
}
Exemplo n.º 2
0
static int pstrcollcmp(const void *a, const void *b)	/* UseCollate */
{
    return strcollcmp (*(char **)a, *(char**)b);
}