mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-18 00:37:01 +00:00
remove upper limit of sort order definitions
Unlikely to be needed by anyone, but because arbitrary limits are from code style point of view ugly. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
327691f34a
commit
0369340710
5 changed files with 72 additions and 59 deletions
35
src/sort.c
35
src/sort.c
|
|
@ -220,7 +220,7 @@ comparer_t field_selector(char c)
|
|||
{
|
||||
switch (c) {
|
||||
case 'n':
|
||||
break;
|
||||
return NULL;
|
||||
case 'i':
|
||||
return comp_ip;
|
||||
case 'm':
|
||||
|
|
@ -249,32 +249,23 @@ comparer_t field_selector(char c)
|
|||
*/
|
||||
static int merge(struct range_t *restrict left, struct range_t *restrict right)
|
||||
{
|
||||
int i, len, ret;
|
||||
comparer_t comparer;
|
||||
int cmp;
|
||||
struct output_sort *p;
|
||||
int ret;
|
||||
|
||||
len = strlen(config.sort);
|
||||
for (i = 0; i < len; i++) {
|
||||
/* Handling strings is case of it's own */
|
||||
if (config.sort[i] == 'n') {
|
||||
for (p = config.sorts; p; p = p->next) {
|
||||
if (p->func == NULL) {
|
||||
/* String sorting is special. */
|
||||
ret = strcmp(left->shared_net->name, right->shared_net->name);
|
||||
if (0 < ret)
|
||||
return (0);
|
||||
if (ret < 0)
|
||||
return (1);
|
||||
continue;
|
||||
} else {
|
||||
/* Range sorts are common. */
|
||||
ret = p->func(left, right);
|
||||
}
|
||||
/* Select which function is pointed by comparer */
|
||||
comparer = field_selector(config.sort[i]);
|
||||
cmp = comparer(left, right);
|
||||
/* If fields are equal use next sort method */
|
||||
if (cmp == 0)
|
||||
continue;
|
||||
if (cmp < 0)
|
||||
if (0 < ret)
|
||||
return (0);
|
||||
if (ret < 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
/* If all comparers where equal */
|
||||
/* this is reached if nothing was sorted */
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue