Annotation of 43BSDTahoe/lib/libc/stdio/stdio.vax/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 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 "@(#)fputs.s     5.6 (Berkeley) 6/27/88"
        !            20: #endif /* LIBC_SCCS and not lint */
        !            21: 
        !            22: /*
        !            23:  * fputs(s, iop);
        !            24:  * char *s;
        !            25:  * FILE *iop;
        !            26:  *
        !            27:  * arguments: a source string and a file pointer.
        !            28:  * side effects: writes to the file indicated by iop using the data in
        !            29:  *     the null-terminated source string.
        !            30:  * result: technically void; for compatibility we return 0 for the null
        !            31:  *     string, non-zero otherwise.  We return zero for errors too.
        !            32:  */
        !            33: 
        !            34: #include "DEFS.h"
        !            35: 
        !            36: #define                NBF     04
        !            37: #define                LBF     0200
        !            38: 
        !            39: #define                NL      012
        !            40: 
        !            41: ENTRY(fputs, R11|R10|R9)
        !            42: 
        !            43: #define                S       r11
        !            44:        movl    4(ap),S
        !            45: #define                IOP     r10
        !            46: #define                _CNT
        !            47: #define                _PTR    4
        !            48: #define                _BASE   8
        !            49: #define                _BUFSIZ 12
        !            50: #define                _FLAG   16
        !            51:        movl    8(ap),IOP
        !            52: 
        !            53: #define                UNBUF   -4(fp)
        !            54: 
        !            55: #define                COUNT   r9
        !            56: 
        !            57:        /*
        !            58:         * For compatibility (sigh).
        !            59:         */
        !            60:        tstb    (S)
        !            61:        jeql    Lerror
        !            62: 
        !            63:        /*
        !            64:         * For unbuffered I/O, line buffer the output line.
        !            65:         * Ugly but fast -- and doesn't CURRENTLY break anything (sigh).
        !            66:         */
        !            67:        movab   -1028(sp),sp
        !            68:        bicw3   $~NBF,_FLAG(IOP),UNBUF
        !            69:        jeql    1f
        !            70: 
        !            71:        bicw2   $NBF,_FLAG(IOP)         /* Clear no-buffering flag */
        !            72:        movl    sp,_BASE(IOP)           /* Create a buffer */
        !            73:        movl    sp,_PTR(IOP)
        !            74:        cvtwl   $1024,_BUFSIZ(IOP)
        !            75:        jbr     2f
        !            76: 
        !            77: 1:
        !            78:        tstl    _CNT(IOP)               /* Has a buffer been allocated? */
        !            79:        jgtr    2f
        !            80:        pushl   IOP                     /* Get _flsbuf() to do the work */
        !            81:        pushl   $0
        !            82:        calls   $2,__flsbuf
        !            83:        tstl    r0
        !            84:        jlss    Lerror
        !            85:        incl    _CNT(IOP)               /* Unput the char we sent */
        !            86:        decl    _PTR(IOP)
        !            87: 2:
        !            88: 
        !            89:        /*
        !            90:         * Search for the terminating null.
        !            91:         * We only need to look at _BUFSIZ bytes or less on each pass.
        !            92:         */
        !            93: Lloop:
        !            94:        addl3   _BASE(IOP),_BUFSIZ(IOP),COUNT   /* How many bytes? */
        !            95:        subl2   _PTR(IOP),COUNT
        !            96:        locc    $0,COUNT,(S)            /* Look for a null */
        !            97:        jeql    Lagain
        !            98: 
        !            99:        subl2   r0,COUNT                /* Copy the data */
        !           100:        movc3   COUNT,(S),*_PTR(IOP)
        !           101:        movl    r3,_PTR(IOP)            /* Fix up IOP */
        !           102:        subl2   COUNT,_CNT(IOP)
        !           103:        bitw    $LBF,_FLAG(IOP)         /* If line buffered... */
        !           104:        jneq    1f
        !           105:        tstw    UNBUF                   /* or unbuffered... */
        !           106:        jneq    1f
        !           107:        tstl    _CNT(IOP)               /* or a full buffer... */
        !           108:        jgtr    2f
        !           109: 1:
        !           110:        pushl   IOP                     /* ... flush the buffer */
        !           111:        calls   $1,_fflush
        !           112:        tstl    r0
        !           113:        jlss    Lerror
        !           114: 2:
        !           115: 
        !           116:        /*
        !           117:         * Fix up buffering again.
        !           118:         */
        !           119: Lfixup:
        !           120:        tstw    UNBUF
        !           121:        jeql    1f
        !           122:        bisw2   $NBF,_FLAG(IOP)         /* Reset flag */
        !           123:        clrl    _BASE(IOP)              /* Clear data structure */
        !           124:        clrl    _BUFSIZ(IOP)
        !           125:        clrl    _CNT(IOP)
        !           126: 1:
        !           127:        cvtbl   $NL,r0                  /* Compatibility hack */
        !           128:        ret
        !           129: 
        !           130:        /*
        !           131:         * We didn't find the null -- loop.
        !           132:         */
        !           133: Lagain:
        !           134:        movc3   COUNT,(S),*_PTR(IOP)    /* Copy the data */
        !           135:        movl    r1,S
        !           136:        movl    r3,_PTR(IOP)            /* Fix up IOP */
        !           137:        subl2   COUNT,_CNT(IOP)
        !           138:        pushl   IOP                     /* The buffer is full -- flush it */
        !           139:        calls   $1,_fflush
        !           140:        tstl    r0
        !           141:        jlss    Lerror
        !           142:        tstb    (S)                     /* More data? */
        !           143:        jneq    Lloop
        !           144:        jbr     Lfixup
        !           145: 
        !           146:        /*
        !           147:         * Bomb out.  Return 0 (why not? that's what the old one did).
        !           148:         */
        !           149: Lerror:
        !           150:        clrl    r0
        !           151:        ret

unix.superglobalmegacorp.com

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