Annotation of 42BSD/ingres/source/gutil/scompare.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.