# 2.11BSD#431 - /usr/src/lib/libc/pdp/stdio/gets.s

##### Functions

    _gets             X

##### Macros

    C                 X
    IOP               X
    OLD_S             X
    P                 X
    S                 X

       1: /*
       2:  * Copyright (c) 1987 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:         <@(#)gets.s	5.6 (Berkeley) 9/2/88\0>
       9:         .even
      10: #endif LIBC_SCCS
      11:
      12: #include "DEFS.h"
      13: #include "STDIO.h"
      14:
      15: .globl  __filbuf
      16:
      17: #define         S       r3
      18: #define         IOP     r2
      19: #define         P       r1
      20: #define         C       r0
      21: /*
      22:  * P & C get trounced when we call someone else ...
      23:  */
      24:
      25: /*
      26:  * char *gets(s);
      27:  * char *s;
      28:  *
      29:  * argument: a target string
      30:  * side effects: reads bytes up to and including a newline from the
      31:  *	standard input into the target string and replaces the newline
      32:  *	with a null to null-terminate the string.
      33:  * result: the target string if successful, 0 otherwise.
      34:  */
      35: ENTRY(gets)
      36:         mov     r2,-(sp)                / need a few registers
      37:         mov     r3,-(sp)
      38:
      39: #	define        OLD_S   6.(sp)
      40:
      41:         mov     OLD_S,S                 / grab string pointer
      42:         mov     $STDIN,IOP              / in from stdin
      43:
      44:         /*
      45: 	 * If no characters, call _filbuf() to get some.
      46: 	 */
      47:         tst     _CNT(IOP)
      48:         bgt     Lscan
      49:
      50: Lloop:
      51:         mov     IOP,-(sp)               / _filbuf(stdin)
      52:         jsr     pc,__filbuf
      53:         tst     (sp)+
      54:         tst     r0                      / _filbuf return EOF?
      55:         blt     Leof
      56:         cmpb    r0,$NL                  / a newline?
      57:         bne     1f
      58:         clrb    (S)                     / yes, terminate the string and return
      59:         br      Lret                    /   with a pointer to it
      60: 1:
      61:         movb    r0,(S)+                 / save the returned character
      62:         tst     _BASE(IOP)              / is input buffered?
      63:         beq     Lloop                   / no, have to do it the hard way ...
      64:         tst     _CNT(IOP)               / did __filbuf leave us anything
      65:         beq     Lloop                   /   to work with??
      66:
      67: Lscan:
      68:         /*
      69: 	 * Copy till terminating newline found or end of buffer.
      70: 	 */
      71:         mov     _PTR(IOP),P             / grab pointer into I/O buffer
      72:         mov     _CNT(IOP),C             /   and how many characters in it
      73: 1:
      74:         movb    (P),(S)+                / copy from buffer to string
      75:         cmpb    (P)+,$NL                / was it a newline?
      76:         beq     2f
      77:         sob     C,1b                    / repeat till we hit the end of the
      78:         br      Lloop                   / buffer, and back for another
      79: 2:
      80:         clrb    -(S)                    / overwrite the newline with a null
      81:         sub     _PTR(IOP),P             / figure out how much we took from
      82:         add     P,_PTR(IOP)             / the buffer and update IOP
      83:         sub     P,_CNT(IOP)
      84:
      85: Lret:
      86:         mov     OLD_S,r0                / return pointer to string
      87: Lexit:
      88:         mov     (sp)+,r3                / restore registers
      89:         mov     (sp)+,r2
      90:         rts     pc                      / and return
      91:
      92:         /*
      93: 	 * End of file?  Check to see if we copied any data.
      94: 	 */
      95: Leof:
      96:         cmp     S,OLD_S                 / did we copy anything?
      97:         beq     Lerror                  / nope, return null
      98:         clrb    (S)                     / yes, terminate string
      99:         br      Lret                    /   and return a pointer to it
     100:
     101:         /*
     102: 	 * Error/eof return -- null pointer.
     103: 	 */
     104: Lerror:
     105:         clr     r0
     106:         br      Lexit

#### Defined functions

Leof defined in line 95; used 1 times

- in line 55

Lerror defined in line 104; used 1 times

- in line 97

Lexit defined in line 87; used 1 times

- in line 106

Lloop defined in line 50; used 3 times

- in line 63-65(2), 78

Lret defined in line 85; used 2 times

- in line 59, 99

Lscan defined in line 67; used 1 times

- in line 48

_gets defined in line 35; used 120 times

- in /usr/include/stdio.h line 74
- in /usr/src/games/banner.c line 1045
- in /usr/src/games/btlgammon/btlgammon.c line 63, 70, 78-83(2), 110, 331
- in /usr/src/games/mille/varpush.c line 39
- in /usr/src/games/sail/externs.h line 283
- in /usr/src/games/sail/pl_main.c line 174
- in /usr/src/games/warp/intrp.c line 458
- in /usr/src/include/stdio.h line 61
- in /usr/src/local/cxref/cxrfilt.c line 101, 251, 285
- in /usr/src/local/cxref/fmtxref.c line 51, 74, 88
- in /usr/src/local/mtools/mdel.c line 100
- in /usr/src/local/mtools/mlabel.c line 101, 112
- in /usr/src/local/mtools/mread.c line 211
- in /usr/src/local/mtools/mren.c line 69
- in /usr/src/local/mtools/mwrite.c line 178
- in /usr/src/new/nntp/inews/inews.c line 103
- in /usr/src/new/nntp/server/common.h line 97
- in /usr/src/new/notes/src/nfmail.c line 174
- in /usr/src/new/pathalias/arpatxt.c line 46, 135
- in /usr/src/new/rcs/src/rcsrev.c line 670, 676-680(3)
- in /usr/src/new/rn/art.c line 716
- in /usr/src/new/rn/bits.c line 386, 580
- in /usr/src/new/rn/cheat.c line 67
- in /usr/src/new/rn/head.c line 334
- in /usr/src/new/rn/intrp.c line 494
- in /usr/src/new/vmsbackup/vmsbackup.c line 304
- in /usr/src/old/512restor.c line 303, 345, 431, 438
- in /usr/src/sbin/icheck/icheck.c line 108
- in /usr/src/sbin/mkfs/mkfs.c line 135, 187, 196-200(2), 206
- in /usr/src/sbin/restor/restor.c line 191, 235, 321, 328
- in /usr/src/sys/autoconfig/do_config.c line 297
- in /usr/src/ucb/Mail/def.h line 288
- in /usr/src/ucb/ftp/cmds.c line 78, 310, 324, 369, 516, 530, 659, 970, 1026, 1052, 1097, 1111, 1167, 1175, 1283, 1348, 1375, 1404, 1439, 1471, 1564, 1665, 1798, 2052, 2115, 2139
- in /usr/src/ucb/ftp/domacro.c line 45
- in /usr/src/ucb/ftp/main.c line 218
- in /usr/src/ucb/man/apropos.c line 107
- in /usr/src/ucb/msgs/msgs.c line 682
- in /usr/src/ucb/telnet.c line 1928, 2024, 2275
- in /usr/src/ucb/tftp/main.c line 161, 276, 367, 447, 473, 538
- in /usr/src/ucb/tn3270/tn3270.c line 227, 689, 1055
- in /usr/src/usr.bin/find/bigram.c line 23
- in /usr/src/usr.bin/find/code.c line 57
- in /usr/src/usr.bin/learn/dounit.c line 51
- in /usr/src/usr.bin/learn/selsub.c line 76, 82, 97
- in /usr/src/usr.bin/learn/selunit.c line 33
- in /usr/src/usr.bin/refer/deliv1.c line 18
- in /usr/src/usr.bin/refer/kaiser.c line 20
- in /usr/src/usr.lib/libF77/mkvers.c line 57
- in /usr/src/usr.lib/libI77/mkvers.c line 57
- in /usr/src/usr.lib/libU77/mkvers.c line 57
- in /usr/src/usr.sbin/lpr/lpc.c line 99
- in /usr/src/usr.sbin/named/tools/nstest.c line 102, 226-230(2), 240, 250, 259, 290
- in /usr/src/usr.sbin/timed/timedc.c line 101

#### Defined macros

C defined in line 20; used 2 times

- in line 72-77(2)

IOP defined in line 18; used 10 times

- in line 42-51(3), 62-64(2), 71-72(2), 81-83(3)

OLD_S defined in line 39; used 3 times

- in line 41, 86, 96

P defined in line 19; used 6 times

- in line 71-75(3), 81-83(3)

S defined in line 17; used 7 times

- in line 41, 58-61(2), 74, 80, 96-98(2)

Last modified: 1988-12-26 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 847 |