Debian Codegraph @

texk/seetexk/fio.c

raw
1 /* Copyright (c) 1987, 1989, 2012 University of Maryland Department of
2 Computer Science.
3
4 Permission is hereby granted, free of charge, to any person obtaining
5 a copy of this software and associated documentation files (the
6 "Software"), to deal in the Software without restriction, including
7 without limitation, the rights to use, copy, modify, merge, publish,
8 distribute, sublicense, and/or sell copies of the Software, and to
9 permit persons to whom the Software is furnished to do so, subject to
10 the following conditions: The above copyright notice, this permission
11 notice and the disclaimer statement shall be included in all copies
12 or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 /*
24 * File I/O subroutines for getting bytes, words, 3bytes, and longwords.
25 * N.B.: these believe they are working on a DVI file.
26 */
27
28 #include "types.h"
29 #include "error.h"
30 #include "fio.h"
31 #include <stdio.h>
32
33 static char eofmsg[] = "unexpected EOF, help";
34
35 /* for symmetry: */
36 #define fGetByte(fp, r) ((r) = getc(fp))
37 #define Sign32(i) (i)
38
39 #define make(name, func, signextend) \
40 i32 \
41 name(FILE *fp) \
42 { \
43 register i32 n; \
44 \
45 func(fp, n); \
46 if (feof(fp)) \
47 error(1, 0, eofmsg); \
48 return (signextend(n)); \
49 }
50
51 make(GetByte, fGetByte, Sign8)
52 make(GetWord, fGetWord, Sign16)
53 make(Get3Byte, fGet3Byte, Sign24)
54 make(GetLong, fGetLong, Sign32)