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

##### Functions

    _fgets            X

##### Macros

    C                 X
    COUNT             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:         <@(#)fgets.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       r4
      18: #define         IOP     r3
      19: #define         COUNT   r2
      20: #define         P       r1
      21: #define         C       r0
      22: /*
      23:  * P & C get trounced when we call someone else ...
      24:  */
      25:
      26: /*
      27:  * char *fgets(s, n, iop);
      28:  * char *s;
      29:  * int n;
      30:  * FILE *iop;
      31:  *
      32:  * arguments: a target string, a length, and a file pointer.
      33:  * side effects: reads up to and including a newline, or up to n-1 bytes,
      34:  *	whichever is less, from the file indicated by iop into the target
      35:  *	string and null terminates.
      36:  * result: the target string if successful, 0 otherwise.
      37:  */
      38: ENTRY(fgets)
      39:         mov     r2,-(sp)                / need a few registers
      40:         mov     r3,-(sp)
      41:         mov     r4,-(sp)
      42:
      43: #	define        OLD_S   8.(sp)
      44:
      45:         mov     OLD_S,S                 / grab string pointer
      46:         mov     10.(sp),COUNT           /   string length
      47:         mov     12.(sp),IOP             /   and I/O pointer
      48:
      49:         /*
      50: 	 * Sanity check -- is the string big enough?  Has to hold at least
      51: 	 * a null ...
      52: 	 */
      53:         dec     COUNT                   / We scan at most n-1 characters
      54:         ble     Lerror
      55:
      56:         /*
      57: 	 * If no characters, call _filbuf() to get some.
      58: 	 */
      59:         tst     _CNT(IOP)
      60:         bgt     Lscan
      61:
      62: Lloop:
      63:         mov     IOP,-(sp)               / _filbuf(stdin)
      64:         jsr     pc,__filbuf
      65:         tst     (sp)+
      66:         tst     r0                      / _filbuf return EOF?
      67:         blt     Leof
      68:         movb    r0,(S)+                 / save the returned character
      69:         dec     COUNT                   / out of space?
      70:         ble     1f
      71:         cmpb    r0,$NL                  / a newline?
      72:         bne     2f
      73: 1:
      74:         clrb    (S)                     / yes, terminate the string and return
      75:         br      Lret                    /   with a pointer to it
      76: 2:
      77:         tst     _BASE(IOP)              / is input buffered?
      78:         beq     Lloop                   / no, have to do it the hard way ...
      79:         tst     _CNT(IOP)               / did __filbuf leave us anything
      80:         beq     Lloop                   /   to work with??
      81:
      82: Lscan:
      83:         /*
      84: 	 * Copy till terminating newline found or end of buffer or end of
      85: 	 * string.
      86: 	 */
      87:         mov     _PTR(IOP),P             / grab pointer into I/O buffer
      88:         mov     _CNT(IOP),C             /   and how many characters in it
      89:         sub     C,COUNT                 / more in buffer than we can take?
      90:         bge     1f
      91:         add     COUNT,C                 / only copy till end of string then
      92:         clr     COUNT
      93: 1:
      94:         movb    (P),(S)+                / copy from buffer to string
      95:         cmpb    (P)+,$NL                / was it a newline?
      96:         beq     2f
      97:         sob     C,1b                    / repeat till we run out ...
      98:         tst     COUNT                   / more room in string?
      99:         bne     Lloop                   / yes, go back for another buffer
     100: 2:
     101:         clrb    (S)                     / terminate string
     102:         sub     _PTR(IOP),P             / figure out how much we took from
     103:         add     P,_PTR(IOP)             / the buffer and update IOP
     104:         sub     P,_CNT(IOP)
     105:
     106: Lret:
     107:         mov     OLD_S,r0                / return pointer to string
     108: Lexit:
     109:         mov     (sp)+,r4                / restore registers
     110:         mov     (sp)+,r3
     111:         mov     (sp)+,r2
     112:         rts     pc                      / and return
     113:
     114:         /*
     115: 	 * End of file?  Check to see if we copied any data.
     116: 	 */
     117: Leof:
     118:         cmp     S,OLD_S                 / did we copy anything?
     119:         beq     Lerror                  / nope, return null
     120:         clrb    (S)                     / yes, terminate string
     121:         br      Lret                    /   and return a pointer to it
     122:
     123:         /*
     124: 	 * Error/eof return -- null pointer.
     125: 	 */
     126: Lerror:
     127:         clr     r0
     128:         br      Lexit

#### Defined functions

Leof defined in line 117; used 1 times

- in line 67

Lerror defined in line 126; used 2 times

- in line 54, 119

Lexit defined in line 108; used 1 times

- in line 128

Lloop defined in line 62; used 3 times

- in line 78-80(2), 99

Lret defined in line 106; used 2 times

- in line 75, 121

Lscan defined in line 82; used 1 times

- in line 60

_fgets defined in line 38; used 434 times

- in /usr/include/stdio.h line 73
- in /usr/src/bin/chpass/chpass.c line 288, 351
- in /usr/src/bin/diff/diffh.c line 52
- in /usr/src/bin/disklabel/disklabel.c line 750
- in /usr/src/bin/mail.c line 179, 341, 451, 484-487(2)
- in /usr/src/bin/passwd/passwd.c line 171
- in /usr/src/bin/rmail.c line 59, 114
- in /usr/src/games/atc/main.c line 209, 235, 269
- in /usr/src/games/battlestar/cypher.c line 256-284(8)
- in /usr/src/games/battlestar/getcom.c line 22
- in /usr/src/games/boggle/comp.c line 26
- in /usr/src/games/fortune/strfile.c line 74, 103, 149
- in /usr/src/games/hack/hack.pager.c line 30, 76
- in /usr/src/games/hack/hack.rumors.c line 26, 34
- in /usr/src/games/hangman/getword.c line 21-23(2)
- in /usr/src/games/hunt/hunt.c line 713
- in /usr/src/games/phantasia/func0.c line 400, 418
- in /usr/src/games/phantasia/func1.c line 175, 286, 303, 364, 381
- in /usr/src/games/phantasia/main.c line 327
- in /usr/src/games/rogue/curses.c line 406, 487
- in /usr/src/games/warp/init.c line 209
- in /usr/src/games/warp/intrp.c line 218
- in /usr/src/games/warp/score.c line 69-73(2), 565, 594, 648
- in /usr/src/games/warp/sm.c line 24, 55
- in /usr/src/games/warp/term.c line 314, 405
- in /usr/src/include/stdio.h line 60
- in /usr/src/lib/libc/gen/fstab.c line 64
- in /usr/src/lib/libc/gen/getgrent.c line 49
- in /usr/src/lib/libc/gen/getpwent.c line 181
- in /usr/src/lib/libc/gen/getttyent.c line 100
- in /usr/src/lib/libc/gen/getusershell.c line 107
- in /usr/src/lib/libc/net/getnent.c line 56
- in /usr/src/lib/libc/net/getpent.c line 55
- in /usr/src/lib/libc/net/getsent.c line 56
- in /usr/src/lib/libc/net/hosttable/gethostent.c line 74
- in /usr/src/lib/libc/net/named/gethnamadr.c line 310
- in /usr/src/lib/libc/net/rcmd.c line 280
- in /usr/src/lib/libc/net/res_init.c line 74
- in /usr/src/lib/libc/net/res_query.c line 230
- in /usr/src/libexec/acctd/acctd.c line 325
- in /usr/src/libexec/comsat/comsat.c line 213
- in /usr/src/libexec/fingerd/fingerd.c line 105
- in /usr/src/libexec/ftpd/ftpd.c line 371
- in /usr/src/libexec/getNAME/getNAME.c line 51, 61, 76
- in /usr/src/libexec/identd/src/crypto.c line 157
- in /usr/src/libexec/identd/src/identd.c line 434
- in /usr/src/libexec/identd/src/itest.c line 106
- in /usr/src/libexec/identd/testdir/test1.c line 110
- in /usr/src/libexec/popper/pop_dropinfo.c line 58
- in /usr/src/libexec/popper/pop_send.c line 64-67(2), 75
- in /usr/src/libexec/popper/pop_updt.c line 134
- in /usr/src/libexec/popper/pop_xmit.c line 54
- in /usr/src/libexec/popper/popper.c line 45
- in /usr/src/local/mp/main.c line 278
- in /usr/src/local/mp/print.c line 184, 235
- in /usr/src/local/mtools/expand.c line 32
- in /usr/src/local/mtools/init.c line 271
- in /usr/src/local/qterm/qterm.c line 711
- in /usr/src/local/zmodem/sz.c line 543
- in /usr/src/new/PORT/B/src/b/convert.c line 155
- in /usr/src/new/PORT/B/src/bed/comm.c line 99
- in /usr/src/new/PORT/B/src/bed/demo.c line 141
- in /usr/src/new/PORT/B/src/bed/help.c line 94
- in /usr/src/new/PORT/B/src/bed/spos.c line 45, 78
- in /usr/src/new/PORT/B/src/bed/sugg.c line 57
- in /usr/src/new/PORT/B/src/bed/unix.c line 491
- in /usr/src/new/PORT/B/src/bint/b3err.c line 88
- in /usr/src/new/PORT/hexdump/parse.c line 45
- in /usr/src/new/PORT/perl.1.0.0/str.c line 385
- in /usr/src/new/PORT/perl.1.0.0/x2p/str.c line 331
- in /usr/src/new/PORT/perl.1.0.10/str.c line 388
- in /usr/src/new/PORT/perl.1.0.10/x2p/str.c line 331
- in /usr/src/new/PORT/perl.1.0.16/str.c line 388
- in /usr/src/new/PORT/perl.1.0.16/x2p/str.c line 331
- in /usr/src/new/ansi/ansitape.c line 188
- in /usr/src/new/jove/setmaps.c line 139
- in /usr/src/new/kermit5.188/ckcmdb.c line 327
- in /usr/src/new/kermit5.188/ckuus7.c line 1313
- in /usr/src/new/nntp/common/clientlib.c line 80, 452
- in /usr/src/new/nntp/inews/inews.c line 174
- in /usr/src/new/nntp/inews/uname.c line 53, 82
- in /usr/src/new/nntp/server/access.c line 160
- in /usr/src/new/nntp/server/common.h line 97
- in /usr/src/new/nntp/server/list.c line 40
- in /usr/src/new/nntp/server/misc.c line 133, 196, 277, 338, 349, 367, 377, 409
- in /usr/src/new/nntp/server/newgroups.c line 85
- in /usr/src/new/nntp/server/newnews.c line 220, 233, 338, 417
- in /usr/src/new/nntp/server/serve.c line 198
- in /usr/src/new/nntp/server/spawn.c line 83, 188
- in /usr/src/new/nntp/server/xhdr.c line 144
- in /usr/src/new/nntp/support/mkgrdates.c line 103
- in /usr/src/new/nntp/xmit/nntpxmit.c line 578, 801, 931, 999
- in /usr/src/new/nntp/xmit/remote.c line 327
- in /usr/src/new/notes/src/bnewshead.c line 591
- in /usr/src/new/notes/src/buildnf.c line 252
- in /usr/src/new/notes/src/expand.c line 196
- in /usr/src/new/notes/src/getnet.c line 56
- in /usr/src/new/notes/src/loadem.c line 57, 136, 146, 164-173(4), 185, 299, 317-324(3), 336
- in /usr/src/new/notes/src/loadnf.c line 101, 319
- in /usr/src/new/notes/src/loadproto1.c line 24, 54
- in /usr/src/new/notes/src/mailit.c line 225
- in /usr/src/new/notes/src/newsinput.c line 308, 329, 357, 366
- in /usr/src/new/notes/src/newspath.c line 35, 56
- in /usr/src/new/notes/src/nfmail.c line 412
- in /usr/src/new/notes/src/startup.c line 156
- in /usr/src/new/pathalias/arpatxt.c line 46, 160
- in /usr/src/new/pathalias/local.c line 45, 58, 70
- in /usr/src/new/pathalias/makedb.c line 103
- in /usr/src/new/rcs/src/sccstorcs.c line 172, 193, 204, 227
- in /usr/src/new/rn/addng.c line 61, 110
- in /usr/src/new/rn/art.c line 191, 208-210(2), 652
- in /usr/src/new/rn/artio.c line 104
- in /usr/src/new/rn/artsrch.c line 277
- in /usr/src/new/rn/bits.c line 279, 365
- in /usr/src/new/rn/head.c line 166, 268, 341
- in /usr/src/new/rn/init.c line 219, 261, 334
- in /usr/src/new/rn/intrp.c line 146, 636, 997
- in /usr/src/new/rn/kfile.c line 82, 192
- in /usr/src/new/rn/kitlists.c line 34
- in /usr/src/new/rn/last.c line 25-30(3)
- in /usr/src/new/rn/ngdata.c line 162, 176
- in /usr/src/new/rn/rcstuff.c line 113
- in /usr/src/new/rn/respond.c line 344, 384
- in /usr/src/new/rn/term.c line 254
- in /usr/src/new/rn/util.c line 336
- in /usr/src/old/dump/dumpitime.c line 146
- in /usr/src/old/dump/dumpoptr.c line 33
- in /usr/src/old/uudiff/run1.c line 64
- in /usr/src/sbin/dump/dumpitime.c line 146
- in /usr/src/sbin/dump/dumpoptr.c line 37
- in /usr/src/sbin/mkpasswd/mkpasswd.c line 197
- in /usr/src/sbin/savecore/savecore.c line 176, 183, 289
- in /usr/src/share/zoneinfo/zic.c line 576
- in /usr/src/sys/autoconfig/read_dtab.c line 42, 48
- in /usr/src/ucb/Mail/def.h line 295
- in /usr/src/ucb/Mail/edit.c line 95
- in /usr/src/ucb/Mail/fio.c line 84, 170
- in /usr/src/ucb/Mail/send.c line 88, 191
- in /usr/src/ucb/PORT/pascal/utilities/pmerge.c line 113-117(2), 166
- in /usr/src/ucb/checknr.c line 243
- in /usr/src/ucb/ctags.c line 549, 638, 647, 742, 874, 962
- in /usr/src/ucb/error/errorfilter.c line 71, 83
- in /usr/src/ucb/error/errorinput.c line 49
- in /usr/src/ucb/error/errortouch.c line 525, 714
- in /usr/src/ucb/from.c line 63
- in /usr/src/ucb/ftp/cmds.c line 771, 1302
- in /usr/src/ucb/ftp/ftp.c line 223
- in /usr/src/ucb/head.c line 71
- in /usr/src/ucb/indent/args.c line 133
- in /usr/src/ucb/lock/lock.c line 120, 127, 154
- in /usr/src/ucb/logger.c line 114
- in /usr/src/ucb/msgs/msgs.c line 322, 332, 465, 592, 655, 762, 802
- in /usr/src/ucb/sccs.c line 1223, 1369
- in /usr/src/ucb/sendbug/bugfiler.c line 586, 647, 671, 711
- in /usr/src/ucb/sendbug/unixtomh.c line 178
- in /usr/src/ucb/symorder.c line 266
- in /usr/src/ucb/tset/tset.c line 1259
- in /usr/src/ucb/unexpand.c line 49
- in /usr/src/ucb/vacation.c line 174, 236
- in /usr/src/ucb/vgrind/vfontedpr.c line 284
- in /usr/src/ucb/xstr.c line 113, 195
- in /usr/src/usr.bin/at/at.c line 432
- in /usr/src/usr.bin/checkeq.c line 29
- in /usr/src/usr.bin/file.c line 55
- in /usr/src/usr.bin/find/code.c line 54
- in /usr/src/usr.bin/find/find.c line 782
- in /usr/src/usr.bin/join.c line 151
- in /usr/src/usr.bin/learn/copy.c line 239
- in /usr/src/usr.bin/learn/getlesson.c line 51
- in /usr/src/usr.bin/learn/list.c line 24
- in /usr/src/usr.bin/learn/selunit.c line 51, 63
- in /usr/src/usr.bin/mkerrlst/mkerrlst.c line 146
- in /usr/src/usr.bin/patch/inp.c line 226, 263
- in /usr/src/usr.bin/patch/pch.c line 86, 235, 399, 855
- in /usr/src/usr.bin/refer/addbib.c line 96, 106, 133, 156, 175, 260
- in /usr/src/usr.bin/refer/annobib.c line 51
- in /usr/src/usr.bin/refer/glue4.c line 68
- in /usr/src/usr.bin/refer/hunt5.c line 28
- in /usr/src/usr.bin/refer/hunt6.c line 48, 127
- in /usr/src/usr.bin/refer/inv2.c line 28
- in /usr/src/usr.bin/refer/inv6.c line 31
- in /usr/src/usr.bin/refer/lookbib.c line 52, 58
- in /usr/src/usr.bin/refer/mkey1.c line 74
- in /usr/src/usr.bin/refer/mkey2.c line 84
- in /usr/src/usr.bin/refer/mkey3.c line 33
- in /usr/src/usr.bin/refer/refer8.c line 22
- in /usr/src/usr.bin/refer/sortbib.c line 69, 144
- in /usr/src/usr.bin/refer/thash.c line 63
- in /usr/src/usr.bin/refer/what1.c line 117
- in /usr/src/usr.bin/refer/what3.c line 64
- in /usr/src/usr.bin/shar/shar.c line 237
- in /usr/src/usr.bin/sort.c line 18, 322
- in /usr/src/usr.bin/spell/spellin.c line 26
- in /usr/src/usr.bin/spell/spellout.c line 32
- in /usr/src/usr.bin/tbl/te.c line 26-31(2)
- in /usr/src/usr.bin/tip/acu.c line 91
- in /usr/src/usr.bin/tip/value.c line 44
- in /usr/src/usr.bin/uucp/acucntrl.c line 430, 457, 504, 550
- in /usr/src/usr.bin/uucp/anlwrk.c line 80
- in /usr/src/usr.bin/uucp/cfgets.c line 25-27(2)
- in /usr/src/usr.bin/uucp/condevs.c line 552
- in /usr/src/usr.bin/uucp/gnxseq.c line 53, 79
- in /usr/src/usr.bin/uucp/systat.c line 34, 104
- in /usr/src/usr.bin/uucp/uuclean.c line 175-180(2)
- in /usr/src/usr.bin/uucp/uucpname.c line 112, 201
- in /usr/src/usr.bin/uucp/uudecode.c line 44, 88, 108
- in /usr/src/usr.bin/uucp/uulog.c line 77
- in /usr/src/usr.bin/uucp/uuq.c line 265, 292
- in /usr/src/usr.bin/uucp/uusnap.c line 263
- in /usr/src/usr.bin/uucp/uuxqt.c line 206, 358, 474, 505, 533
- in /usr/src/usr.sbin/arp/arp.c line 83
- in /usr/src/usr.sbin/catman/catman.c line 190
- in /usr/src/usr.sbin/cron/crontab.c line 437
- in /usr/src/usr.sbin/cron/misc.c line 397
- in /usr/src/usr.sbin/edquota/edquota.c line 406-408(3)
- in /usr/src/usr.sbin/gettable/gettable.c line 103
- in /usr/src/usr.sbin/htable/htable.c line 367, 426-429(2)
- in /usr/src/usr.sbin/inetd/inetd.c line 895
- in /usr/src/usr.sbin/lpr/filters/necf.c line 30
- in /usr/src/usr.sbin/lpr/pac.c line 172
- in /usr/src/usr.sbin/lpr/recvjob.c line 285
- in /usr/src/usr.sbin/named/named/db_load.c line 426
- in /usr/src/usr.sbin/named/tools/nslookup/main.c line 1102
- in /usr/src/usr.sbin/sendmail.MX/aux/arpa.c line 324, 334, 342, 349, 360, 388-391(2), 400
- in /usr/src/usr.sbin/sendmail.MX/aux/bbn_daemon.c line 295
- in /usr/src/usr.sbin/sendmail.MX/aux/mconnect.c line 128
- in /usr/src/usr.sbin/sendmail.MX/aux/newaliases.c line 99, 167
- in /usr/src/usr.sbin/sendmail.MX/src/alias.c line 386, 475
- in /usr/src/usr.sbin/sendmail.MX/src/deliver.c line 1189
- in /usr/src/usr.sbin/sendmail.MX/src/main.c line 558
- in /usr/src/usr.sbin/sendmail.MX/src/queue.c line 454, 847
- in /usr/src/usr.sbin/sendmail.MX/src/readcf.c line 319
- in /usr/src/usr.sbin/sendmail.MX/src/recipient.c line 498
- in /usr/src/usr.sbin/sendmail.MX/src/savemail.c line 193, 484
- in /usr/src/usr.sbin/sendmail.MX/src/srvrsmtp.c line 583
- in /usr/src/usr.sbin/sendmail.MX/src/util.c line 635
- in /usr/src/usr.sbin/sendmail/aux/4.1a_daemon.c line 423
- in /usr/src/usr.sbin/sendmail/aux/arpa.c line 324, 334, 342, 349, 360, 388-391(2), 400
- in /usr/src/usr.sbin/sendmail/aux/bbn_daemon.c line 295
- in /usr/src/usr.sbin/sendmail/aux/mconnect.c line 142
- in /usr/src/usr.sbin/sendmail/aux/newaliases.c line 99, 167
- in /usr/src/usr.sbin/sendmail/aux/rmail.c line 73, 129
- in /usr/src/usr.sbin/sendmail/src/alias.c line 386, 477
- in /usr/src/usr.sbin/sendmail/src/deliver.c line 1134
- in /usr/src/usr.sbin/sendmail/src/main.c line 562
- in /usr/src/usr.sbin/sendmail/src/queue.c line 441, 834
- in /usr/src/usr.sbin/sendmail/src/readcf.c line 313
- in /usr/src/usr.sbin/sendmail/src/recipient.c line 506
- in /usr/src/usr.sbin/sendmail/src/savemail.c line 187, 478
- in /usr/src/usr.sbin/sendmail/src/srvrsmtp.c line 574
- in /usr/src/usr.sbin/sendmail/src/util.c line 635
- in /usr/src/usr.sbin/sysgen/sysgen.c line 44
- in /usr/src/usr.sbin/syslogd/syslogd.c line 845
- in /usr/src/usr.sbin/vipw/vipw.c line 161

#### Defined macros

C defined in line 21; used 4 times

- in line 88-91(3), 97

COUNT defined in line 19; used 7 times

- in line 46, 53, 69, 89-92(3), 98

IOP defined in line 18; used 10 times

- in line 47, 59-63(2), 77-79(2), 87-88(2), 102-104(3)

OLD_S defined in line 43; used 3 times

- in line 45, 107, 118

P defined in line 20; used 6 times

- in line 87, 94-95(2), 102-104(3)

S defined in line 17; used 7 times

- in line 45, 68, 74, 94, 101, 118-120(2)

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