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

Defined functions

ENTRY defined in line 8; never used
_BASE defined in line 8; never used
_BUFSIZ defined in line 8; never used
_CNT defined in line 8; never used
_FLAG defined in line 8; never used
_PTR defined in line 8; never used
tstb defined in line 8; never used

Defined macros

COUNT defined in line 44; used 8 times
IOP defined in line 34; used 27 times
LBF defined in line 26; never used
NBF defined in line 25; used 1 times
  • in line 57
NL defined in line 28; never used
S defined in line 32; used 7 times
UNBUF defined in line 42; used 3 times
_BASE defined in line 37; used 1 times
  • in line 83
_BUFSIZ defined in line 38; used 1 times
  • in line 83
_CNT defined in line 35; never used
_FLAG defined in line 39; used 1 times
  • in line 57
_PTR defined in line 36; used 1 times
  • in line 84
Last modified: 1986-04-02
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 814
Valid CSS Valid XHTML 1.0 Strict