OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [nstrcmp.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
2
/* $Id: nstrcmp.c,v 1.1 2002-03-17 19:58:53 simons Exp $ */
3
#include <ctype.h>
4
#include <stdlib.h>
5
#include "util.h"
6
 
7
/* like strcmp(), but knows about numbers */
8
int nstrcmp(const char *astr, const char *b)
9
{
10
    const char *a = astr;
11
 
12
    while (*a == *b) {
13
        if (*a == '\0')
14
            return 0;
15
        a++;
16
        b++;
17
    }
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;
26
            }
27
            if (!isdigit(*b))
28
                return -1;
29
            b--;
30
        }
31
        return atoi(a) > atoi(b) ? 1 : -1;
32
    }
33
    return *a - *b;
34
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.