|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifdef LIBC_SCCS ! 8: .asciz "@(#)rindex.s 5.3 (Berkeley) 3/9/86" ! 9: #endif LIBC_SCCS ! 10: ! 11: /* ! 12: * Find the last occurence of c in the string cp. ! 13: * Return pointer to match or null pointer. ! 14: * ! 15: * char * ! 16: * rindex(cp, c) ! 17: * char *cp, c; ! 18: */ ! 19: #include "DEFS.h" ! 20: ! 21: ENTRY(rindex, 0) ! 22: movq 4(ap),r1 # r1 = cp; r2 = c ! 23: tstl r2 # check for special case c == '\0' ! 24: bneq 2f ! 25: 1: ! 26: locc $0,$65535,(r1) # just find end of string ! 27: beql 1b # still looking ! 28: movl r1,r0 # found it ! 29: ret ! 30: 2: ! 31: moval tbl,r3 # r3 = address of table ! 32: bbss $0,(r3),5f # insure not reentering ! 33: movab (r3)[r2],r5 # table entry for c ! 34: incb (r5) ! 35: clrl r4 # last found ! 36: 3: ! 37: scanc $65535,(r1),(r3),$1 # look for c or '\0' ! 38: beql 3b # keep looking ! 39: tstb (r1) # if have found '\0' ! 40: beql 4f # we are done ! 41: movl r1,r4 # save most recently found ! 42: incl r1 # skip over character ! 43: jbr 3b # keep looking ! 44: 4: ! 45: movl r4,r0 # return last found (if any) ! 46: clrb (r5) # clean up table ! 47: clrb (r3) ! 48: ret ! 49: ! 50: .data ! 51: tbl: .space 256 ! 52: .text ! 53: ! 54: /* ! 55: * Reentrant, but slower version of rindex ! 56: */ ! 57: 5: ! 58: movl r1,r3 ! 59: clrl r4 # r4 = pointer to last match ! 60: 6: ! 61: locc $0,$65535,(r3) # look for '\0' ! 62: bneq 8f ! 63: decw r0 # r0 = 65535 ! 64: 1: ! 65: locc r2,r0,(r3) # look for c ! 66: bneq 7f ! 67: movl r1,r3 # reset pointer and ... ! 68: jbr 6b # ... try again ! 69: 7: ! 70: movl r1,r4 # stash pointer ... ! 71: addl3 $1,r1,r3 # ... skip over match and ... ! 72: decl r0 # ... decrement count ! 73: jbr 6b # ... try again ! 74: 8: ! 75: subl3 r3,r1,r0 # length of short block ! 76: incl r0 # +1 for '\0' ! 77: 9: ! 78: locc r2,r0,(r3) # look for c ! 79: beql 0f ! 80: movl r1,r4 # stash pointer ... ! 81: addl3 $1,r1,r3 # ... skip over match ... ! 82: decl r0 # ... adjust count and ... ! 83: jbr 9b # ... try again ! 84: 0: ! 85: movl r4,r0 # return stashed pointer ! 86: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.