/* lwrcmpn.c */

/* Copyright 1997 by Eberhard Mattes <mattes@azu.informatik.uni-stuttgart.de>
   Donated to the public domain.  No warranty.

   1997-09-06 Initial version
   1997-09-09 Renamed from lwr_cmp() to lwr_cmpn() */

#include <stdlib.h>
#include "libemfw.h"

/* Compare N characters at S1 to N characters at S2, ignoring case.
   The null character is not treated specially in any way!  Return a
   positive value (S1 compares greater than S2), zero (S1 compares
   equal to S2), or a negative value (S1 compares less than S2).
   Characters are converted to lower case for comparison. */

int lower_cmpn (const char *s1, const char *s2, size_t n)
{
  DEBUG_ASSERT (s1 != NULL);
  DEBUG_ASSERT (s2 != NULL);
  while (n != 0 && (lower_table[(unsigned char)*s1]
		    == lower_table[(unsigned char)*s2]))
    {
      ++s1; ++s2; --n;
    }
  if (n == 0)
    return 0;
  else if (lower_table[(unsigned char)*s1] > lower_table[(unsigned char)*s2])
    return 1;
  else
    return -1;
}
