forked from kimburgess/netlinx-common-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.axi
81 lines (71 loc) · 2.11 KB
/
io.axi
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
program_name='io'
#if_not_defined __NCL_LIB_IO
#define __NCL_LIB_IO
define_variable
persistent dev io_out = 0:0:0 // output stream device
persistent integer io_out_mtu = 131 // max characters to transmit (the
// NL diagnositics console will only
// display a max of 131 characters per
// line)
persistent char io_line_seperator = $0A // seperator to insert between lines
/**
* Write a character array to the output device.
*
* If the outgoing data exceeds io_out_mtu it will be split into multiple
* packets. If a non printable char is located within the last half of the
* current packet it will split at the non printable character, otherwise all
* data up to io_out_mtu will be sent in the packet.
*
* If io_out_mtu is 0 all data will be sent in a single packet.
*
* @param buf the character array to write
* @param offset the offset to begin writing from (offset 0 == character 1)
* @param len the number of characters to write
*/
define_function write(char buf[], integer offset, integer len)
{
stack_var integer start
stack_var integer end
stack_var integer min_len
if (io_out_mtu && len > io_out_mtu) {
min_len = type_cast(io_out_mtu / 2)
start = offset + 1
while (start < offset + len) {
end = min_value(start + io_out_mtu, offset + len)
while (end > start + min_len) {
if ((buf[end] > $08 && buf[end] < $0E) ||
(buf[end] > $1B && buf[end] < $21)) {
end++
break
}
end--
}
if (end <= start + min_len) {
end = min_value(start + io_out_mtu, offset + len + 1)
}
write(buf, start - 1, end - start)
start = end
}
} else {
send_string io_out, mid_string(buf, offset + 1, len)
}
}
/**
* Print a character array to the output stream.
*
* @param x a string containing the data to output
*/
define_function print(char x[])
{
write(x, 0, length_string(x))
}
/**
* Print a line to the output stream.
*
* @param x a string containing the data to output
*/
define_function println(char x[])
{
write("x, io_line_seperator", 0, length_string(x))
}
#end_if