Annotation of 43BSDReno/lib/libc/vax/stdio/fputs.s, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1985 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: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #if defined(LIBC_SCCS) && !defined(lint)
        !            21:        .asciz "@(#)fputs.s     5.7 (Berkeley) 6/1/90"
        !            22: #endif /* LIBC_SCCS and not lint */
        !            23: 
        !            24: /*
        !            25:  * fputs(s, iop);
        !            26:  * char *s;
        !            27:  * FILE *iop;
        !            28:  *
        !            29:  * arguments: a source string and a file pointer.
        !            30:  * side effects: writes to the file indicated by iop using the data in
        !            31:  *     the null-terminated source string.
        !            32:  * result: technically void; for compatibility we return 0 for the null
        !            33:  *     string, non-zero otherwise.  We return zero for errors too.
        !            34:  */
        !            35: 
        !            36: #include "DEFS.h"
        !            37: 
        !            38: #define                NBF     04
        !            39: #define                LBF     0200
        !            40: 
        !            41: #define                NL      012
        !            42: 
        !            43: ENTRY(fputs, R11|R10|R9)
        !            44: 
        !            45: #define                S       r11
        !            46:        movl    4(ap),S
        !            47: #define                IOP     r10
        !            48: #define                _CNT
        !            49: #define                _PTR    4
        !            50: #define                _BASE   8
        !            51: #define                _BUFSIZ 12
        !            52: #define                _FLAG   16
        !            53:        movl    8(ap),IOP
        !            54: 
        !            55: #define                UNBUF   -4(fp)
        !            56: 
        !            57: #define                COUNT   r9
        !            58: 
        !            59:        /*
        !            60:         * For compatibility (sigh).
        !            61:         */
        !            62:        tstb    (S)
        !            63:        jeql    Lerror
        !            64: 
        !            65:        /*
        !            66:         * For unbuffered I/O, line buffer the output line.
        !            67:         * Ugly but fast -- and doesn't CURRENTLY break anything (sigh).
        !            68:         */
        !            69:        movab   -1028(sp),sp
        !            70:        bicw3   $~NBF,_FLAG(IOP),UNBUF
        !            71:        jeql    1f
        !            72: 
        !            73:        bicw2   $NBF,_FLAG(IOP)         /* Clear no-buffering flag */
        !            74:        movl    sp,_BASE(IOP)           /* Create a buffer */
        !            75:        movl    sp,_PTR(IOP)
        !            76:        cvtwl   $1024,_BUFSIZ(IOP)
        !            77:        jbr     2f
        !            78: 
        !            79: 1:
        !            80:        tstl    _CNT(IOP)               /* Has a buffer been allocated? */
        !            81:        jgtr    2f
        !            82:        pushl   IOP                     /* Get _flsbuf() to do the work */
        !            83:        pushl   $0
        !            84:        calls   $2,__flsbuf
        !            85:        tstl    r0
        !            86:        jlss    Lerror
        !            87:        incl    _CNT(IOP)               /* Unput the char we sent */
        !            88:        decl    _PTR(IOP)
        !            89: 2:
        !            90: 
        !            91:        /*
        !            92:         * Search for the terminating null.
        !            93:         * We only need to look at _BUFSIZ bytes or less on each pass.
        !            94:         */
        !            95: Lloop:
        !            96:        addl3   _BASE(IOP),_BUFSIZ(IOP),COUNT   /* How many bytes? */
        !            97:        subl2   _PTR(IOP),COUNT
        !            98:        locc    $0,COUNT,(S)            /* Look for a null */
        !            99:        jeql    Lagain
        !           100: 
        !           101:        subl2   r0,COUNT                /* Copy the data */
        !           102:        movc3   COUNT,(S),*_PTR(IOP)
        !           103:        movl    r3,_PTR(IOP)            /* Fix up IOP */
        !           104:        subl2   COUNT,_CNT(IOP)
        !           105:        bitw    $LBF,_FLAG(IOP)         /* If line buffered... */
        !           106:        jneq    1f
        !           107:        tstw    UNBUF                   /* or unbuffered... */
        !           108:        jneq    1f
        !           109:        tstl    _CNT(IOP)               /* or a full buffer... */
        !           110:        jgtr    2f
        !           111: 1:
        !           112:        pushl   IOP                     /* ... flush the buffer */
        !           113:        calls   $1,_fflush
        !           114:        tstl    r0
        !           115:        jlss    Lerror
        !           116: 2:
        !           117: 
        !           118:        /*
        !           119:         * Fix up buffering again.
        !           120:         */
        !           121: Lfixup:
        !           122:        tstw    UNBUF
        !           123:        jeql    1f
        !           124:        bisw2   $NBF,_FLAG(IOP)         /* Reset flag */
        !           125:        clrl    _BASE(IOP)              /* Clear data structure */
        !           126:        clrl    _BUFSIZ(IOP)
        !           127:        clrl    _CNT(IOP)
        !           128: 1:
        !           129:        cvtbl   $NL,r0                  /* Compatibility hack */
        !           130:        ret
        !           131: 
        !           132:        /*
        !           133:         * We didn't find the null -- loop.
        !           134:         */
        !           135: Lagain:
        !           136:        movc3   COUNT,(S),*_PTR(IOP)    /* Copy the data */
        !           137:        movl    r1,S
        !           138:        movl    r3,_PTR(IOP)            /* Fix up IOP */
        !           139:        subl2   COUNT,_CNT(IOP)
        !           140:        pushl   IOP                     /* The buffer is full -- flush it */
        !           141:        calls   $1,_fflush
        !           142:        tstl    r0
        !           143:        jlss    Lerror
        !           144:        tstb    (S)                     /* More data? */
        !           145:        jneq    Lloop
        !           146:        jbr     Lfixup
        !           147: 
        !           148:        /*
        !           149:         * Bomb out.  Return 0 (why not? that's what the old one did).
        !           150:         */
        !           151: Lerror:
        !           152:        clrl    r0
        !           153:        ret

unix.superglobalmegacorp.com

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