-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdio.chp
More file actions
60 lines (47 loc) · 1.57 KB
/
stdio.chp
File metadata and controls
60 lines (47 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* stdio.chp: standard I/O
Naturally, these should only be used for testing purposes.
Author: Marcel van der Goot
*/
/*****************************************************************************/
// Abstract type used to represent a file.
export type file = int;
export const stdin: file = 0;
export const stdout: file = 1;
export type file_err = { ok, eof, no_int };
// Open the specified file with mode. Mode is the same as for C fopen()
export
procedure fopen(res f: file; name: string; mode: string)
BUILTIN
// Close the file
export
procedure fclose(f: file)
BUILTIN
// Read a byte (character). err is assigned ok or eof. (If eof, x is 0.)
export
procedure read_byte(f: file; res x: {0..255}; res err: file_err)
BUILTIN
// Read an integer in standard CHP notation, skipping preceding white space.
// The integer may be immediately preceded by a single '-' sign.
// err is assigned ok, eof, or no_int (first char is not a digit). If not ok,
// x is 0.
export
procedure read_int(f: file; res x: int; res err: file_err)
BUILTIN
// Write a byte (character).
export
procedure write_byte(f: file; x: {0..255})
BUILTIN
// Write a string.
export
procedure write_string(f: file; x: string)
BUILTIN
// Write an integer in the specified base. Decimal integers are written
// without base, hexadecimal with 0x, all others with base#.
export
procedure write_int(f: file; x: int; base: {2..36})
BUILTIN
// Same as the builtin print() procedure (but without instance name).
export
procedure write(f: file; ...)
BUILTIN
/*****************************************************************************/