1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8#if defined(LIBC_SCCS) && !defined(lint) 9 .asciz "@(#)rindex.s 8.1 (Berkeley) 06/04/93" 10#endif /* LIBC_SCCS and not lint */ 11 12/* 13 * Find the last occurence of c in the string cp. 14 * Return pointer to match or null pointer. 15 * 16 * char * 17 * rindex(cp, c) 18 * char *cp, c; 19 */ 20#include "DEFS.h" 21 22ENTRY(rindex, 0) 23 movq 4(ap),r1 # r1 = cp; r2 = c 24 tstl r2 # check for special case c == '\0' 25 bneq 2f 261: 27 locc $0,$65535,(r1) # just find end of string 28 beql 1b # still looking 29 movl r1,r0 # found it 30 ret 312: 32 moval tbl,r3 # r3 = address of table 33 bbss $0,(r3),5f # insure not reentering 34 movab (r3)[r2],r5 # table entry for c 35 incb (r5) 36 clrl r4 # last found 373: 38 scanc $65535,(r1),(r3),$1 # look for c or '\0' 39 beql 3b # keep looking 40 tstb (r1) # if have found '\0' 41 beql 4f # we are done 42 movl r1,r4 # save most recently found 43 incl r1 # skip over character 44 jbr 3b # keep looking 454: 46 movl r4,r0 # return last found (if any) 47 clrb (r5) # clean up table 48 clrb (r3) 49 ret 50 51 .data 52tbl: .space 256 53 .text 54 55/* 56 * Reentrant, but slower version of rindex 57 */ 585: 59 movl r1,r3 60 clrl r4 # r4 = pointer to last match 616: 62 locc $0,$65535,(r3) # look for '\0' 63 bneq 8f 64 decw r0 # r0 = 65535 651: 66 locc r2,r0,(r3) # look for c 67 bneq 7f 68 movl r1,r3 # reset pointer and ... 69 jbr 6b # ... try again 707: 71 movl r1,r4 # stash pointer ... 72 addl3 $1,r1,r3 # ... skip over match and ... 73 decl r0 # ... decrement count 74 jbr 6b # ... try again 758: 76 subl3 r3,r1,r0 # length of short block 77 incl r0 # +1 for '\0' 789: 79 locc r2,r0,(r3) # look for c 80 beql 0f 81 movl r1,r4 # stash pointer ... 82 addl3 $1,r1,r3 # ... skip over match ... 83 decl r0 # ... adjust count and ... 84 jbr 9b # ... try again 850: 86 movl r4,r0 # return stashed pointer 87 ret 88