1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2011 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Eclipse Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.eclipse.org/org/documents/epl-v10.html *
11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
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