You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by dg...@locus.apache.org on 2000/04/24 06:04:14 UTC
cvs commit: apache-2.0/src/lib/apr/lib apr_strnatcmp.c
dgaudet 00/04/23 21:04:14
Added: src/lib/apr/include apr_strnatcmp.h
src/lib/apr/lib apr_strnatcmp.c
Log:
Add `IndexOptions +VersionSort', to nicely sort filenames
containing version numbers.
Submitted by: Martin Pool <mb...@linuxcare.com.au>
Revision Changes Path
1.1 apache-2.0/src/lib/apr/include/apr_strnatcmp.h
Index: apr_strnatcmp.h
===================================================================
/* -*- mode: c; c-file-style: "k&r" -*-
strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
Copyright (C) 2000 by Martin Pool <mb...@humbug.org.au>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
int strnatcmp(char const *a, char const *b);
int strnatcasecmp(char const *a, char const *b);
1.1 apache-2.0/src/lib/apr/lib/apr_strnatcmp.c
Index: apr_strnatcmp.c
===================================================================
/* -*- mode: c; c-file-style: "k&r" -*-
strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
Copyright (C) 2000 by Martin Pool <mb...@humbug.org.au>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "apr_strnatcmp.h"
#if defined(__GNUC__)
# define UNUSED __attribute__((__unused__))
#else
# define UNUSED
#endif
/* based on "strnatcmp.c,v 1.6 2000/04/20 07:30:11 mbp Exp $" */
static int
compare_right(char const *a, char const *b)
{
int bias = 0;
/* The longest run of digits wins. That aside, the greatest
value wins, but we can't know that it will until we've scanned
both numbers to know that they have the same magnitude, so we
remember it in BIAS. */
for (;; a++, b++) {
if (!isdigit(*a) && !isdigit(*b))
return bias;
else if (!isdigit(*a))
return -1;
else if (!isdigit(*b))
return +1;
else if (*a < *b) {
if (!bias)
bias = -1;
} else if (*a > *b) {
if (!bias)
bias = +1;
} else if (!*a && !*b)
return bias;
}
return 0;
}
static int
compare_left(char const *a, char const *b)
{
/* Compare two left-aligned numbers: the first to have a
different value wins. */
for (;; a++, b++) {
if (!isdigit(*a) && !isdigit(*b))
return 0;
else if (!isdigit(*a))
return -1;
else if (!isdigit(*b))
return +1;
else if (*a < *b)
return -1;
else if (*a > *b)
return +1;
}
return 0;
}
static int strnatcmp0(char const *a, char const *b, int fold_case)
{
int ai, bi;
char ca, cb;
int fractional, result;
assert(a && b);
ai = bi = 0;
while (1) {
ca = a[ai]; cb = b[bi];
/* skip over leading spaces or zeros */
while (isspace(ca))
ca = a[++ai];
while (isspace(cb))
cb = b[++bi];
/* process run of digits */
if (isdigit(ca) && isdigit(cb)) {
fractional = (ca == '0' || cb == '0');
if (fractional) {
if ((result = compare_left(a+ai, b+bi)) != 0)
return result;
} else {
if ((result = compare_right(a+ai, b+bi)) != 0)
return result;
}
}
if (!ca && !cb) {
/* The strings compare the same. Perhaps the caller
will want to call strcmp to break the tie. */
return 0;
}
if (fold_case) {
ca = toupper(ca);
cb = toupper(cb);
}
if (ca < cb)
return -1;
else if (ca > cb)
return +1;
++ai; ++bi;
}
}
int strnatcmp(char const *a, char const *b) {
return strnatcmp0(a, b, 0);
}
/* Compare, recognizing numeric string and ignoring case. */
int strnatcasecmp(char const *a, char const *b) {
return strnatcmp0(a, b, 1);
}
RE: cvs commit: apache-2.0/src/lib/apr/lib apr_strnatcmp.c
Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> From: William A. Rowe, Jr. [mailto:wrowe@lnd.com]
> Sent: Monday, April 24, 2000 9:30 AM
> I've looked at ap_hooks long enough to know
> that it should move into the apr core, since it can't be
> cleanly abstracted without more complexity, IMHO.
Huh? Need that third cup of coffee.
I ment to suggest that ap_hooks belongs in the Apache core,
since it is very Apache specific, and _not_ in the APR.
RE: cvs commit: apache-2.0/src/lib/apr/lib apr_strnatcmp.c
Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> From: dgaudet@locus.apache.org [mailto:dgaudet@locus.apache.org]
> Sent: Sunday, April 23, 2000 11:04 PM
>
> dgaudet 00/04/23 21:04:14
>
> Added: src/lib/apr/include apr_strnatcmp.h
> src/lib/apr/lib apr_strnatcmp.c
> Log:
> Add `IndexOptions +VersionSort', to nicely sort filenames
> containing version numbers.
Very nice.
Attached are the win32 updates and rename to ap_strnatcmp...
if this will live in apr.
Question... if strnatcmp belongs in apr are we also finally
ready to move the ap_sha1 and ap_base64 (headers in ap.h)
into the apr? I've looked at ap_hooks long enough to know
that it should move into the apr core, since it can't be
cleanly abstracted without more complexity, IMHO.
Apr has become what ap was to 1.3.x. With a difference,
(credits and kudos to all) in that it isn't married to the
Apache server. But can we kill ap to celebrate?