1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
23
24 #include <ast.h>
25 #include <ctype.h>
26
27 /*
28 * version strcmp(3)
29 */
30
31 int
strvcmp(register const char * a,register const char * b)32 strvcmp(register const char* a, register const char* b)
33 {
34 register unsigned long na;
35 register unsigned long nb;
36
37 for (;;)
38 {
39 if (isdigit(*a) && isdigit(*b))
40 {
41 na = nb = 0;
42 while (isdigit(*a))
43 na = na * 10 + *a++ - '0';
44 while (isdigit(*b))
45 nb = nb * 10 + *b++ - '0';
46 if (na < nb)
47 return -1;
48 if (na > nb)
49 return 1;
50 }
51 else if (*a != *b)
52 break;
53 else if (!*a)
54 return 0;
55 else
56 {
57 a++;
58 b++;
59 }
60 }
61 if (*a == 0)
62 return -1;
63 if (*b == 0)
64 return 1;
65 if (*a == '.')
66 return -1;
67 if (*b == '.')
68 return 1;
69 if (*a == '-')
70 return -1;
71 if (*b == '-')
72 return 1;
73 return *a < *b ? -1 : 1;
74 }
75