xref: /titanic_50/usr/src/lib/libast/common/string/strvcmp.c (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
134f9b3eeSRoland Mainz /***********************************************************************
234f9b3eeSRoland Mainz *                                                                      *
334f9b3eeSRoland Mainz *               This software is part of the ast package               *
4*3e14f97fSRoger A. Faulkner *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
534f9b3eeSRoland Mainz *                      and is licensed under the                       *
634f9b3eeSRoland Mainz *                  Common Public License, Version 1.0                  *
734f9b3eeSRoland Mainz *                    by AT&T Intellectual Property                     *
834f9b3eeSRoland Mainz *                                                                      *
934f9b3eeSRoland Mainz *                A copy of the License is available at                 *
1034f9b3eeSRoland Mainz *            http://www.opensource.org/licenses/cpl1.0.txt             *
1134f9b3eeSRoland Mainz *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
1234f9b3eeSRoland Mainz *                                                                      *
1334f9b3eeSRoland Mainz *              Information and Software Systems Research               *
1434f9b3eeSRoland Mainz *                            AT&T Research                             *
1534f9b3eeSRoland Mainz *                           Florham Park NJ                            *
1634f9b3eeSRoland Mainz *                                                                      *
1734f9b3eeSRoland Mainz *                 Glenn Fowler <gsf@research.att.com>                  *
1834f9b3eeSRoland Mainz *                  David Korn <dgk@research.att.com>                   *
1934f9b3eeSRoland Mainz *                   Phong Vo <kpv@research.att.com>                    *
2034f9b3eeSRoland Mainz *                                                                      *
2134f9b3eeSRoland Mainz ***********************************************************************/
2234f9b3eeSRoland Mainz #pragma prototyped
2334f9b3eeSRoland Mainz 
2434f9b3eeSRoland Mainz #include <ast.h>
2534f9b3eeSRoland Mainz #include <ctype.h>
2634f9b3eeSRoland Mainz 
2734f9b3eeSRoland Mainz /*
2834f9b3eeSRoland Mainz  * version strcmp(3)
2934f9b3eeSRoland Mainz  */
3034f9b3eeSRoland Mainz 
3134f9b3eeSRoland Mainz int
strvcmp(register const char * a,register const char * b)3234f9b3eeSRoland Mainz strvcmp(register const char* a, register const char* b)
3334f9b3eeSRoland Mainz {
3434f9b3eeSRoland Mainz 	register unsigned long	na;
3534f9b3eeSRoland Mainz 	register unsigned long	nb;
3634f9b3eeSRoland Mainz 
3734f9b3eeSRoland Mainz 	for (;;)
3834f9b3eeSRoland Mainz 	{
3934f9b3eeSRoland Mainz 		if (isdigit(*a) && isdigit(*b))
4034f9b3eeSRoland Mainz 		{
4134f9b3eeSRoland Mainz 			na = nb = 0;
4234f9b3eeSRoland Mainz 			while (isdigit(*a))
4334f9b3eeSRoland Mainz 				na = na * 10 + *a++ - '0';
4434f9b3eeSRoland Mainz 			while (isdigit(*b))
4534f9b3eeSRoland Mainz 				nb = nb * 10 + *b++ - '0';
4634f9b3eeSRoland Mainz 			if (na < nb)
4734f9b3eeSRoland Mainz 				return -1;
4834f9b3eeSRoland Mainz 			if (na > nb)
4934f9b3eeSRoland Mainz 				return 1;
5034f9b3eeSRoland Mainz 		}
5134f9b3eeSRoland Mainz 		else if (*a != *b)
5234f9b3eeSRoland Mainz 			break;
5334f9b3eeSRoland Mainz 		else if (!*a)
5434f9b3eeSRoland Mainz 			return 0;
5534f9b3eeSRoland Mainz 		else
5634f9b3eeSRoland Mainz 		{
5734f9b3eeSRoland Mainz 			a++;
5834f9b3eeSRoland Mainz 			b++;
5934f9b3eeSRoland Mainz 		}
6034f9b3eeSRoland Mainz 	}
6134f9b3eeSRoland Mainz 	if (*a == 0)
6234f9b3eeSRoland Mainz 		return -1;
6334f9b3eeSRoland Mainz 	if (*b == 0)
6434f9b3eeSRoland Mainz 		return 1;
6534f9b3eeSRoland Mainz 	if (*a == '.')
6634f9b3eeSRoland Mainz 		return -1;
6734f9b3eeSRoland Mainz 	if (*b == '.')
6834f9b3eeSRoland Mainz 		return 1;
6934f9b3eeSRoland Mainz 	if (*a == '-')
7034f9b3eeSRoland Mainz 		return -1;
7134f9b3eeSRoland Mainz 	if (*b == '-')
7234f9b3eeSRoland Mainz 		return 1;
7334f9b3eeSRoland Mainz 	return *a < *b ? -1 : 1;
7434f9b3eeSRoland Mainz }
75