Commit | Line | Data |
---|---|---|
878b8aef KT |
1 | .th GETC III 4/30/72 |
2 | .sh NAME | |
3 | getc, getw, fopen \*- buffered input | |
4 | .sh SYNOPSIS | |
5 | .ft B | |
6 | mov $filename,r0 | |
7 | .br | |
8 | jsr r5,fopen; iobuf | |
9 | .s3 | |
10 | fopen(filename, iobuf) | |
11 | .br | |
12 | char *filename; | |
13 | .br | |
14 | struct buf *iobuf; | |
15 | .s3 | |
16 | jsr r5,getc; iobuf | |
17 | .br | |
18 | .ft R | |
19 | (character in r0) | |
20 | .s3 | |
21 | .ft B | |
22 | getc(iobuf) | |
23 | .br | |
24 | struct buf *iobuf; | |
25 | .s3 | |
26 | jsr r5,getw; iobuf | |
27 | .br | |
28 | .ft R | |
29 | (word in r0) | |
30 | .s3 | |
31 | .ft B | |
32 | getw(iobuf) | |
33 | .br | |
34 | struct buf *iobuf; | |
35 | .ft R | |
36 | .sh DESCRIPTION | |
37 | These routines provide a buffered input | |
38 | facility. | |
39 | .it Iobuf | |
40 | is the address of a 518(10) byte buffer area whose | |
41 | contents are maintained by these routines. | |
42 | Its structure is | |
43 | .s3 | |
44 | .nf | |
45 | .ft B | |
46 | struct buf { | |
47 | int fildes; /* File descriptor */ | |
48 | int nleft; /* Chars left in buffer */ | |
49 | char *nextp; /* Ptr to next character */ | |
50 | char buff[512]; /* The buffer */ | |
51 | }; | |
52 | .ft R | |
53 | .s3 | |
54 | .fi | |
55 | .it Fopen | |
56 | may be called initially to open the file. On return, | |
57 | the error bit (c-bit) is set if the open failed. | |
58 | If \fIfopen\fR is never called, \fIget\fR will | |
59 | read from the standard | |
60 | input file. | |
61 | From C, the value is negative if the open failed. | |
62 | .s3 | |
63 | .it Getc | |
64 | returns the next byte from the file in r0. | |
65 | The error bit is set on end of file or a read error. | |
66 | From C, the character is returned as an integer, without sign extension; | |
67 | it is \*-1 on end-of-file or error. | |
68 | .s3 | |
69 | \fIGetw\fR returns the next word in r0. | |
70 | .it Getc | |
71 | and | |
72 | \fIgetw\fR | |
73 | may be used alternately; there are no odd/even | |
74 | problems. | |
75 | \fIGetw\fR is may be called from C; | |
76 | \*-1 is returned on end-of-file or error, | |
77 | but of course | |
78 | is also a legitimate value. | |
79 | .s3 | |
80 | .it Iobuf | |
81 | must be provided by the user; it must be on a word boundary. | |
82 | .s3 | |
83 | To reuse the same buffer for another file, it is sufficient | |
84 | to close the original file and call \fIfopen\fR again. | |
85 | .sh "SEE ALSO" | |
86 | open (II), read (II), getchar (III), putc (III) | |
87 | .sh DIAGNOSTICS | |
88 | c-bit set on EOF or error; | |
89 | from C, negative return indicates error or EOF. | |
90 | Moreover, | |
91 | .it errno | |
92 | is set by this routine just as it is for a system call | |
93 | (see introduction (II)). | |
94 | .sh BUGS |