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
|
include "../lib/mctable.h"
$for (csilrdxp)
# MCT_PUT - Put value randomly (generic)
procedure mct_put$t (table, row, col, value)
pointer table # table descriptor
int row # row number
int col # column number
PIXEL value # data value
int offset
pointer base
errchk mct_indef()
begin
# Check pointer and magic number.
if (table == NULL)
call error (0, "mct_put: Null table pointer")
if (MCT_MAGIC (table) != MAGIC)
call error (0, "mct_put: Bad magic number")
# Check the table type.
if (MCT_TYPE (table) != TY_PIXEL)
call error (0, "mct_put: Wrong table type")
# Test row and column values.
if (row < 1)
call error (0, "mct_put: Row number less than one")
if (col < 1 || col > MCT_MAXCOL (table))
call error (0, "mct_put: Column out of range")
# Reallocate space if necessary.
if (row > MCT_MAXROW (table)) {
# Compute offset of new area.
offset = MCT_MAXROW (table) * MCT_MAXCOL (table)
# Recompute new number of rows and reallocate buffer.
MCT_MAXROW (table) = MCT_MAXROW (table) + MCT_INCROWS (table)
call realloc (MCT_DATA (table),
MCT_MAXROW (table) * MCT_MAXCOL (table), TY_PIXEL)
# Compute base address of new area and clear it with INDEF.
base = MCT_DATA (table) + offset
call mct_indef (table, base,
MCT_INCROWS (table) * MCT_MAXCOL (table))
}
# Update row and column counter, only if the new entries are beyond
# the old limits.
if (row > MCT_NPROWS (table)) {
MCT_NPROWS (table) = row
MCT_NPCOLS (table) = col
} else if (col > MCT_NPCOLS (table))
MCT_NPCOLS (table) = col
# Enter variable.
base = MCT_DATA (table) + (row - 1) * MCT_MAXCOL (table)
$if (datatype == p)
MEMP[base + col - 1] = value
$else
Mem$t[base + col - 1] = value
$endif
end
$endfor
|