| 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: numbers. |
| 25 |
* |
| 26 |
* We deal in fixed format numbers and (FILE *)s here. |
| 27 |
* For pointer I/O, see pio.h. |
| 28 |
* |
| 29 |
* N.B.: These do the `wrong thing' at EOF. It is imperative |
| 30 |
* that the caller add appropriate `if (feof(fp))' statements. |
| 31 |
*/ |
| 32 |
|
| 33 |
/* |
| 34 |
* Get one unsigned byte. Note that this is a proper expression. |
| 35 |
* The reset have more limited contexts, and are therefore OddLy |
| 36 |
* CapItaliseD. |
| 37 |
*/ |
| 38 |
#define fgetbyte(fp) getc(fp) |
| 39 |
|
| 40 |
/* |
| 41 |
* Get a two-byte unsigned integer, a three-byte unsigned integer, |
| 42 |
* or a four-byte signed integer. |
| 43 |
*/ |
| 44 |
#define fGetWord(fp, r) ((r) = getc(fp) << 8, (r) |= getc(fp)) |
| 45 |
#define fGet3Byte(fp,r) ((r) = getc(fp) << 16, (r) |= getc(fp) << 8, \ |
| 46 |
(r) |= getc(fp)) |
| 47 |
#define fGetLong(fp, r) ((r) = getc(fp) << 24, (r) |= getc(fp) << 16, \ |
| 48 |
(r) |= getc(fp) << 8, (r) |= getc(fp)) |
| 49 |
|
| 50 |
/* |
| 51 |
* Fast I/O write (and regular write) macros. |
| 52 |
*/ |
| 53 |
#define putbyte(fp, r) ((void) putc((r), fp)) |
| 54 |
|
| 55 |
#define PutWord(fp, r) ((void) putc((r) >> 8, fp), \ |
| 56 |
(void) putc((r), fp)) |
| 57 |
#define Put3Byte(fp, r) ((void) putc((r) >> 16, fp), \ |
| 58 |
(void) putc((r) >> 8, fp), \ |
| 59 |
(void) putc((r), fp)) |
| 60 |
#define PutLong(fp, r) ((void) putc((r) >> 24, fp), \ |
| 61 |
(void) putc((r) >> 16, fp), \ |
| 62 |
(void) putc((r) >> 8, fp), \ |
| 63 |
(void) putc((r), fp)) |
| 64 |
|
| 65 |
/* |
| 66 |
* Function types |
| 67 |
*/ |
| 68 |
i32 GetByte(FILE *), GetWord(FILE *), Get3Byte(FILE *), GetLong(FILE *); |