simple patch from Ajax <ajax@firest0rm.org> (corrected) to print DDP
[oss-qm-packages.git] / lib / nstrcmp.c
blob8b1ff30258130b0209800131c5c3da7e30c18672
1 /* Copyright 1998 by Andi Kleen. Subject to the GPL. */
2 /* $Id: nstrcmp.c,v 1.2 1998/11/15 20:11:38 freitag Exp $ */
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include "util.h"
7 /* like strcmp(), but knows about numbers */
8 int nstrcmp(const char *astr, const char *b)
10 const char *a = astr;
12 while (*a == *b) {
13 if (*a == '\0')
14 return 0;
15 a++;
16 b++;
18 if (isdigit(*a)) {
19 if (!isdigit(*b))
20 return -1;
21 while (a > astr) {
22 a--;
23 if (!isdigit(*a)) {
24 a++;
25 break;
27 if (!isdigit(*b))
28 return -1;
29 b--;
31 return atoi(a) > atoi(b) ? 1 : -1;
33 return *a - *b;