BSD 4 release
[unix-history] / usr / src / cmd / px / 30read.s
CommitLineData
b202b2da 1#\f
31cef89c
BJ
2# Copyright (c) 1979 Regents of the University of California
3#
4# char sccsid[] = "@(#)30read.s 4.2 10/29/80";
b202b2da
CH
5#
6# READ OPERATIONS
7#
8_GET:
9 incl r10
10 calls $0,_iosync #insure that something is in the window
31cef89c 11 jbs $fEOF,FUNIT(r7),eeof
b202b2da
CH
12 bisw2 $SYNC,FUNIT(r7) #throw it away
13 jmp (r8)
31cef89c
BJ
14eeof:
15 movw $EPASTEOF,_perrno
16 jbr error
b202b2da
CH
17_FNIL:
18 incl r10
19 movl (sp),r0
31cef89c
BJ
20 jbs $fWRITE,FUNIT(r0),l3002 #ignore sync of output files
21 movl r7,r6
b202b2da
CH
22 calls $0,_unit #do not discard arguement to unit on return
23 calls $0,_iosync
31cef89c
BJ
24 jbs $fEOF,FUNIT(r7),eeof
25 movl r6,r7
26 movl PFNAME(r7),_file
b202b2da
CH
27l3002:
28 jmp (r8)
29_READ4:
30 incl r10
31 calls $0,_unsync #prepare input stream
32 pushl $0 #space for answer
33 pushl sp #ptr to answer space
34 pushal rd4 #ptr to input format
35 pushl FBUF(r7) #stream
36 calls $3,_fscanf
37 cmpl $1,r0
38 bneq eiread
39 bisw2 $SYNC,FUNIT(r7)
40 jmp (r8)
41eiread:
42 movw $EBADINUM,_perrno
43 jbr error
44_READ8:
45 incl r10
46 calls $0,_unsync #prepare input stream
47 clrd -(sp) #space for answer
48 pushl sp #ptr to answer space
49 pushal rd8 #ptr to input format
50 pushl FBUF(r7) #stream
51 calls $3,_fscanf
52 cmpl $1,r0
53 bneq efread
54 bisw2 $SYNC,FUNIT(r7)
55 jmp (r8)
56efread:
57 movw $EBADFNUM,_perrno
58 jbr error
59_READLN:
60 incl r10
61 calls $0,_iosync
31cef89c
BJ
62 jbs $fEOLN,FUNIT(r7),l3005 #check for already at end of line
63 movab -1024(sp),sp #temp space
64 pushl FBUF(r7) #file
65 pushl $1024 #buffer
66 pushal 8(sp) #ptr to buffer
67 calls $3,_fgets
68 movab 1024(sp),sp #pop temp space
b202b2da 69l3005:
31cef89c 70 jbs $fEOF,FUNIT(r7),eeof
b202b2da
CH
71 bisw2 $SYNC,FUNIT(r7)
72 jmp (r8)
73_READC:
74 incl r10
75 calls $0,_iosync
76 cvtbw (r7),-(sp)
31cef89c 77 jbs $fEOF,FUNIT(r7),eeof
b202b2da
CH
78 bisw2 $SYNC,FUNIT(r7)
79 jmp (r8)
31cef89c
BJ
80_READE:
81 incl r10
82 calls $0,_unsync #push back char if present
83 subl2 $bufsze,sp #allocate space for name
84 pushl sp #ptr to buffer
85 pushal rden #format string
86 pushl FBUF(r7) #FILE ptr
87 calls $3,_fscanf #read name
88 cmpl r0,$1 #check for valid input
89 bneq entfd
90 locc $0,$bufsze,(sp) #find size of input
91 subl3 r0,$bufsze+1,r6 #r6 has length of input
92 addl3 (r10),ap,r5 #r5 points to candidate data
93 cvtwl (r5)+,r4 #r4 has number of candidates
94 movaw 2(r5)[r4],r1 #r1 has addr of candidate name list
95l3006:
96 subw3 (r5)+,(r5),r0 #r0 has candidate length
97 cmpw r0,r6 #check for correct length
98 bneq l3007
99 cmpc3 r0,(r1),(sp) #check for actual match
100 beql l3008
101l3007:
102 addl2 r0,r1 #update ptr to next candidate
103 sobgtr r4,l3006
104entfd:
105 addl2 $bufsze,sp #deallocate buffer
106 addl2 $4,r10
107 movw $ENUMNTFD,_perrno
108 jbr error
109l3008:
110 addl2 $bufsze,sp #deallocate buffer
111 addl3 (r10)+,ap,r0 #r0 has number of cases
112 subw3 r4,(r0),-(sp) #push internal value
113 jmp (r8)
b202b2da 114
31cef89c
BJ
115 .set bufsze,84
116rd4: .asciz "%ld"
117rd8: .asciz "%lf"
118rden: .asciz "%*[ \t\n]%80[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]",