Yes, im using function pointers.
This is the function that gets called in qsort in main:
Code:
int compare(char *s1, char *s2)
{
int i, d;
char *f1, *f2;
for (i = 0; i < num_fields; i++) {
f1 = field_of(s1, fieldarray[i]);
f2 = field_of(s2, fieldarray[i]);
d = compare_field(f1, f2, flagarray[i]);
if(d != 0)
return d;
}
if (numeric)
d = numcmp(s1, s2);
else if (directory)
d = dircmp(s1, s2);
else
d = stringcmp(s1, s2);
if (reverse)
return -d;
else
return d;
}
The *field_of function returns a buffer which contains the field to compare_fields which then returns a value to int d, and if d is 0(equal) it continues to for loop the arguments.
Is this something you had in mind?
Also, it works with options like reverse and directory(if it compares only blanks/numbers).