|
|
1.1 ! root 1: #include "../h/rt.h" ! 2: ! 3: /* ! 4: * lexcmp - lexically compare two strings. ! 5: */ ! 6: ! 7: lexcmp(d1, d2) ! 8: struct descrip *d1, *d2; ! 9: { ! 10: register char *s1, *s2; ! 11: register int minlen; ! 12: int l1, l2; ! 13: ! 14: /* ! 15: * Get length and starting address of both strings. ! 16: */ ! 17: l1 = STRLEN(*d1); ! 18: s1 = STRLOC(*d1); ! 19: l2 = STRLEN(*d2); ! 20: s2 = STRLOC(*d2); ! 21: ! 22: /* ! 23: * Set minlen to length of the shorter string. ! 24: */ ! 25: minlen = (l1 <= l2) ? l1 : l2; ! 26: ! 27: /* ! 28: * Compare as many bytes as are in the smaller string. If an ! 29: * inequality is found, return the difference of the differing ! 30: * bytes. ! 31: */ ! 32: while (minlen--) ! 33: if (*s1++ != *s2++) ! 34: return ((*--s1 & 0377) - (*--s2 & 0377)); ! 35: ! 36: /* ! 37: * The strings compared equal for the length of the shorter. Return ! 38: * the difference in their lengths. (Thus, the strings must be of ! 39: * the same length to be equal.) ! 40: */ ! 41: return (l1 - l2); ! 42: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.