// Emacs style mode select   -*- C++ -*- 
//-----------------------------------------------------------------------------
//
// $Id: strcmp.c,v 1.2 2003/08/18 18:26:06 hurdler Exp $
//
// Copyright (C) 1998-2000 by DooM Legacy Team.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
//
// $Log: strcmp.c,v $
// Revision 1.2  2003/08/18 18:26:06  hurdler
// stable 1.41
//
// Revision 1.2  2000/02/27 00:42:12  hurdler
// fix CR+LF problem
//
// Revision 1.1.1.1  2000/02/22 20:32:33  hurdler
// Initial import into CVS (v1.29 pr3)
//
//
// DESCRIPTION:
//      
//
//-----------------------------------------------------------------------------

#include <ctype.h>
#include "strcmp.h"

int strcasecmp(const char *a, const char *b)
{
    const char *p;
    const char *q;

    for (p = a, q = b; *p && *q; p++, q++)
    {
        int diff = tolower(*p) - tolower(*q);
        if (diff)
            return diff;
    }
    if (*p)
        return 1;       /* p was longer than q */
    if (*q)
        return -1;      /* p was shorter than q */
    return 0;   /* Exact match */
}

int strncasecmp(const char *a, const char *b, int n)
{
    const char *p;
    const char *q;

    for (p = a, q = b; /*NOTHING*/; p++, q++)
    {
        int diff;
        if (p == a + n)
            return 0;   /*   Match up to n characters */
        if (!(*p && *q))
            return *p - *q;
        diff = tolower(*p) - tolower(*q);
        if (diff)
            return diff;
    }
 /*NOTREACHED*/}
