Subscribe
int record_sort(const void *a, const void *b)
{
_record *c1 = (_record *)a;
_record *c2 = (_record *)b;
if (c1->a==c2->a)
if (c1->b==c2->b)
if (c1->c==c2->c)
if (c1->d==c2->d)
if (c1->e==c2->e)
if (strncmp(c1->f, c2->f, SIZE_RULE)==0)
if (c1->g==c2->g)
if (c1->h==c2->h)
if (c1->i==c2->i)
return(1);
else
return(c1->i>c2->i);
else
return(c1->h>c2->h);
else
return(c1->g>c2->g);
else
return(strncmp(c1->f, c2->f, SIZE_RULE));
else
return(c1->e>c2->e);
else
return(c1->d>c2->d);
else
return(c1->c>c2->c);
else
return(c1->b>c2->b);
else
return(c1->a>c2->a);
}
int c;
return
(c1->a != c2->a ? c1->a > c2->a :
(c1->b != c2->b ? c1->b > c2->b :
(c1->c != c2->c ? c1->c > c2->c :
(c1->d != c2->d ? c1->d > c2->d :
(c1->e != c2->e ? c1->e > c2->e :
(0==c=strncmp(c1->f, c2->f, SIZE_RULE) ? c :
(c1->g != c2->g ? c1->g > c2->g :
(c1->h != c2->h ? c1->h > c2->h :
(c1->i != c2->i ? c1->i > c2->i : 1 )))))))));
define expansion.)
#define cmpit(a,b, nxt) \
a!=b ? a > b : (nxt)
#define cmpit_str(a,b, nxt) \
0==c=strncmp((a), (b), SIZE_RULE) ? c : (nxt)
...
int c;
return cmpit(c1->a, c2->a,
cmpit(c1->b, c2->b,
cmpit(c1->c, c2->c,
...
cmpit_str(c1->f, c2->f,
cmpit(c1->g, c2->g,
cmpit(c1->h, c2->h,
cmpit(c1->i, c2->i, 1)))))))));
#define cmpit(a,b, nxt) \
(a) != (b) ? (a) > (b) : (nxt)
#define CMP(a, b) ((a) < (b) ? -1 : 1)
#define TEST(x) if (c1->x != c2->x) return CMP(c1->x, c2->x)
TEST(a);
TEST(b);
TEST(c);
TEST(d);
TEST(e);
if (strncmp(c1->f, c2->f, SIZE_RULE) != 0)
return strncmp(c1->f, c2->f, SIZE_RULE);
TEST(g);
TEST(h);
return 0;
return(c1->e>c2->e)) if they're not.an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.Note that this does not require that the returned value be exactly -1, 0 or 1, though these are naturally acceptable. For integer comparisons, just return the result of a subtraction.
int compare_records (const void *a, const void *b)
{
_record *ra = (_record *) a;
_record *rb = (_record *) b;
int d;
double s;
d = ra->a - rb->a; if (d) return d;
d = ra->b - rb->b; if (d) return d;
d = ra->c - rb->c; if (d) return d;
s = ra->d - rb->d; d = (s>0) - (s<0); if (d) return d;
d = ra->e - rb->e; if (d) return d;
d = strncmp(ra->f, rb->f, SIZE_RULE); if (d) return d;
d = ra->g - rb->g; if (d) return d;
d = ra->h - rb->h; if (d) return d;
d = ra->i - rb->i; if (d) return d;
return 0;
}
return(c1->e>c2->e)) if they're not."
short morse_lookup[] = {
MORSE DI DAH _ _ _ _ _ _ 'a',
MORSE DA DI DI DIT _ _ _ _ 'b',
MORSE DA DI DA DIT _ _ _ _ 'c',
MORSE DA DI DIT _ _ _ _ _ 'd',
MORSE DIT _ _ _ _ _ _ _ 'e',
MORSE DI DI DA DIT _ _ _ _ 'f',
...
MORSE DA DA DA DA DAH _ _ _ '0',
MORSE DI DA DI DA DI DAH _ _ '.',
MORSE DA DA DI DI DA DAH _ _ ',',
MORSE DI DI DA DA DI DIT _ _ '?',
}
#define numcmp(x, y) ( (x) < (y) ? -1 : (x) > (y) )
int foocmp(const void *pa, const void *pb)
{
foo *a = (foo *) pa;
foo *b = (foo *) pb;
int d;
d = numcmp(a->a, b->a); if (d) return d;
d = numcmp(a->b, b->b); if (d) return d;
d = numcmp(a->c, b->c); if (d) return d;
d = numcmp(a->d, b->d); if (d) return d;
d = numcmp(a->e, b->e); if (d) return d;
d = strncmp(a->f, b->f, SIZE_RULE); if (d) return d;
d = numcmp(a->g, b->g); if (d) return d;
d = numcmp(a->h, b->h); if (d) return d;
d = numcmp(a->i, b->i); if (d) return d;
return 0;
}
posted by Psychnic at 1:06 PM on September 28, 2006