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

unix.superglobalmegacorp.com

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