Commit | Line | Data |
---|---|---|
586c39b1 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
493b70ca KB |
3 | * All rights reserved. |
4 | * | |
019bea33 | 5 | * %sccs.include.redist.c% |
586c39b1 DF |
6 | */ |
7 | ||
f4f66d2c | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
019bea33 | 9 | .asciz "@(#)index.s 5.6 (Berkeley) %G%" |
f4f66d2c | 10 | #endif /* LIBC_SCCS and not lint */ |
a7452cdf SL |
11 | |
12 | /* | |
13 | * Find the first occurence of c in the string cp. | |
14 | * Return pointer to match or null pointer. | |
15 | * | |
16 | * char * | |
17 | * index(cp, c) | |
18 | * char *cp, c; | |
19 | */ | |
dadab5a2 | 20 | #include "DEFS.h" |
a7452cdf | 21 | |
dadab5a2 | 22 | ENTRY(index, 0) |
a7452cdf SL |
23 | movq 4(ap),r1 # r1 = cp; r2 = c |
24 | tstl r2 # check for special case c == '\0' | |
25 | bneq 2f | |
26 | 1: | |
27 | locc $0,$65535,(r1) # just find end of string | |
28 | beql 1b # still looking | |
29 | movl r1,r0 # found it | |
30 | ret | |
31 | 2: | |
8f899db2 KM |
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 | |
a7452cdf SL |
35 | incb (r5) |
36 | movzwl $65535,r4 # fast access | |
37 | 3: | |
8f899db2 | 38 | scanc r4,(r1),(r3),$1 # look for c or '\0' |
a7452cdf SL |
39 | beql 3b # still looking |
40 | movl r1,r0 # return pointer to char | |
41 | tstb (r0) # if have found '\0' | |
42 | bneq 4f | |
43 | clrl r0 # else return 0 | |
44 | 4: | |
45 | clrb (r5) # clean up table | |
8f899db2 | 46 | clrb (r3) |
a7452cdf SL |
47 | ret |
48 | ||
49 | .data | |
8f899db2 | 50 | tbl: .space 256 |
a7452cdf | 51 | .text |
8f899db2 KM |
52 | |
53 | /* | |
54 | * Reentrant, but slower version of index | |
55 | */ | |
56 | 5: | |
57 | movl r1,r3 | |
58 | 6: | |
59 | locc $0,$65535,(r3) # look for '\0' | |
60 | bneq 7f | |
61 | locc r2,$65535,(r3) # look for c | |
62 | bneq 8f | |
63 | movl r1,r3 # reset pointer and ... | |
64 | jbr 6b # ... try again | |
65 | 7: | |
66 | subl3 r3,r1,r4 # length of short block | |
67 | incl r4 # +1 for '\0' | |
68 | locc r2,r4,(r3) # look for c | |
69 | bneq 8f | |
70 | ret | |
71 | 8: | |
72 | movl r1,r0 # return pointer to char | |
73 | ret |