X-Git-Url: http://git.asbjorn.biz/?p=debian%2Fdhcpd-pools.git;a=blobdiff_plain;f=src%2Fsort.c;h=e436f5a08998ed9f772f0b5be30e736d8afa5786;hp=6c5ae58d86cedfde993841b081a17ab71a23f68d;hb=HEAD;hpb=74aef1c34e31699595b4b198bcde5ac1af694260 diff --git a/src/sort.c b/src/sort.c index 6c5ae58..e436f5a 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1,19 +1,18 @@ -/* -** Copyright (C) 2006- Sami Kerola -** -** This program is free software; you can redistribute it and/or modify +/* http://dhcpd-pools.sourceforge.net/ +** Copyright 2006- Sami Kerola +** +** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or +** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. -** +** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. -** +** ** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +** along with this program. If not, see . */ #ifdef HAVE_CONFIG_H @@ -23,9 +22,10 @@ #include #include #include +#include +#include #include "dhcpd-pools.h" -#include "defaults.h" /* Sort functions for range sorting */ int intcomp(const void *x, const void *y) @@ -116,9 +116,9 @@ void field_selector(char c) returner = ret_tcperc; break; default: - eprintf("field_selector: unknown sort order: %c", - config.sort[0]); - usage(EXIT_FAILURE); + warnx("field_selector: unknown sort order `%c'", c); + errx(EXIT_FAILURE, "Try `%s --help' for more information.", + program_invocation_short_name); } } @@ -135,7 +135,7 @@ int get_order(struct range_t *left, struct range_t *right) ret = strcmp(left->shared_net->name, right->shared_net->name); - if (ret > 0) { + if (0 < ret) { return (0); } else if (ret < 0) { return (1); @@ -166,11 +166,13 @@ void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp) { int left, right, i; struct range_t hold; + /* Merge sort split size */ + static const int MIN_MERGE_SIZE = 8; if (size < MIN_MERGE_SIZE) { for (left = 0; left < size; left++) { hold = *(orig + left); - for (right = left - 1; right >= 0; right--) { + for (right = left - 1; 0 <= right; right--) { if (get_order((orig + right), &hold)) { break; }