1: /*
   2: **  STRING COMPARE
   3: **
   4: **	The strings 'a_ptr' and 'b_ptr' are compared.  Blanks are
   5: **	ignored.  The first string may be no longer than 'a_len'
   6: **	bytes, and the second string may be no longer than 'b_len'
   7: **	bytes.  If either length is zero, it is taken to be very
   8: **	long.  A null byte also terminates the scan.
   9: **
  10: **	Compares are based on the ascii ordering.
  11: **
  12: **	Shorter strings are less than longer strings.
  13: **
  14: **	Return value is positive one for a > b, minus one for a < b,
  15: **	and zero for a == b.
  16: **
  17: **	Examples:
  18: **		"abc" > "ab"
  19: **		"  a bc  " == "ab  c"
  20: **		"abc" < "abd"
  21: */
  22: 
  23: scompare(a_ptr, a_len, b_ptr, b_len)
  24: char    *a_ptr;
  25: int a_len;
  26: char    *b_ptr;
  27: int b_len;
  28: {
  29:     char        *ap;
  30:     char        *bp;
  31:     register char   a;
  32:     char        b;
  33:     register int    al;
  34:     register int    bl;
  35: 
  36:     ap = a_ptr;
  37:     bp = b_ptr;
  38:     al = a_len;
  39:     if (al == 0)
  40:         al = 32767;
  41:     bl = b_len;
  42:     if (bl == 0)
  43:         bl = 32767;
  44: 
  45:     while (1)
  46:     {
  47: 
  48:         /* supress blanks in both strings */
  49:         while ((a = *ap) == ' ' && al > 0)
  50:         {
  51:             al--;
  52:             ap++;
  53:         }
  54:         if (al == 0)
  55:             a = 0;
  56:         while (*bp == ' ' && bl > 0)
  57:         {
  58:             bl--;
  59:             bp++;
  60:         }
  61:         if (bl == 0)
  62:             b = 0;
  63:         else
  64:             b = *bp;
  65: 
  66:         /* do inequality tests */
  67:         if (a < b)
  68:             return (-1);
  69:         if (a > b)
  70:             return (1);
  71:         if (a == 0)
  72:             return (0);
  73: 
  74:         /* go on to the next character */
  75:         ap++;
  76:         al--;
  77:         bp++;
  78:         bl--;
  79:     }
  80: }
Last modified: 1980-12-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1690
Valid CSS Valid XHTML 1.0 Strict