Annotation of 43BSDTahoe/lib/libc/compat-sys5/compat-sys5.vax/strrchr.s, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  */
        !            17: 
        !            18: #if defined(LIBC_SCCS) && !defined(lint)
        !            19:        .asciz "@(#)strrchr.s   5.2 (Berkeley) 6/27/88"
        !            20: #endif /* LIBC_SCCS and not lint */
        !            21: 
        !            22: #ifdef notdef
        !            23: _sccsid:.asciz "@(#)rindex.s   5.4 (Berkeley) 5/25/88"
        !            24: #endif
        !            25: 
        !            26: /*
        !            27:  * Find the last occurence of c in the string cp.
        !            28:  * Return pointer to match or null pointer.
        !            29:  *
        !            30:  * char *
        !            31:  * rindex(cp, c)
        !            32:  *     char *cp, c;
        !            33:  */
        !            34: #include "DEFS.h"
        !            35: 
        !            36: ENTRY(strrchr, 0)
        !            37:        movq    4(ap),r1        # r1 = cp; r2 = c
        !            38:        tstl    r2              # check for special case c == '\0'
        !            39:        bneq    2f
        !            40: 1:
        !            41:        locc    $0,$65535,(r1)  # just find end of string
        !            42:        beql    1b              # still looking
        !            43:        movl    r1,r0           # found it
        !            44:        ret
        !            45: 2:
        !            46:        moval   tbl,r3          # r3 = address of table
        !            47:        bbss    $0,(r3),5f      # insure not reentering
        !            48:        movab   (r3)[r2],r5     # table entry for c
        !            49:        incb    (r5)
        !            50:        clrl    r4              # last found
        !            51: 3:
        !            52:        scanc   $65535,(r1),(r3),$1     # look for c or '\0'
        !            53:        beql    3b              # keep looking
        !            54:        tstb    (r1)            # if have found '\0'
        !            55:        beql    4f              #    we are done
        !            56:        movl    r1,r4           # save most recently found
        !            57:        incl    r1              # skip over character
        !            58:        jbr     3b              # keep looking
        !            59: 4:
        !            60:        movl    r4,r0           # return last found (if any)
        !            61:        clrb    (r5)            # clean up table
        !            62:        clrb    (r3)
        !            63:        ret
        !            64: 
        !            65:        .data
        !            66: tbl:   .space  256
        !            67:        .text
        !            68: 
        !            69: /*
        !            70:  * Reentrant, but slower version of rindex
        !            71:  */
        !            72: 5:
        !            73:        movl    r1,r3
        !            74:        clrl    r4              # r4 = pointer to last match
        !            75: 6:
        !            76:        locc    $0,$65535,(r3)  # look for '\0'
        !            77:        bneq    8f
        !            78:        decw    r0              # r0 = 65535
        !            79: 1:
        !            80:        locc    r2,r0,(r3)      # look for c
        !            81:        bneq    7f
        !            82:        movl    r1,r3           # reset pointer and ...
        !            83:        jbr     6b              # ... try again
        !            84: 7:
        !            85:        movl    r1,r4           # stash pointer ...
        !            86:        addl3   $1,r1,r3        # ... skip over match and ...
        !            87:        decl    r0              # ... decrement count
        !            88:        jbr     6b              # ... try again
        !            89: 8:
        !            90:        subl3   r3,r1,r0        # length of short block
        !            91:        incl    r0              # +1 for '\0'
        !            92: 9:
        !            93:        locc    r2,r0,(r3)      # look for c
        !            94:        beql    0f
        !            95:        movl    r1,r4           # stash pointer ...
        !            96:        addl3   $1,r1,r3        # ... skip over match ...
        !            97:        decl    r0              # ... adjust count and ...
        !            98:        jbr     9b              # ... try again
        !            99: 0:
        !           100:        movl    r4,r0           # return stashed pointer
        !           101:        ret

unix.superglobalmegacorp.com

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