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
82
83
84
85
86
|
include "tbtables.h"
# tbyscn -- Y set columns to null
# Write INDEF values for specified columns in a range of rows in a table.
# Note: This routine assumes that EOS = 0 (or SZB_CHAR=1) because the buffer
# for setting char values to indef is not packed.
#
# Phil Hodge, 1-Apr-1993 Include short datatype.
# Phil Hodge, 2-Jun-1997 Replace INDEFD with TBL_INDEFD.
procedure tbyscn (tp, fd, colptr, numcols, firstrow, lastrow)
pointer tp # i: pointer to table descriptor
pointer colptr[numcols] # i: array of pointers to descr of new columns
int fd # i: identifies the data file for a table
int numcols # i: the number of new columns
int firstrow # i: the first row to be set to indef
int lastrow # i: the last row to be set to indef
pointer sp
pointer charbuf # Scratch for character string column
long offset # Location (chars) for writing in table
int j, k # Loop indexes
int datatype # Data type of a column
int dlen # Number of char in an element of the table
short sbuf
bool boolbuf # Buffer for writing Boolean values
long tbyoff()
errchk seek, write
begin
do k = 1, numcols {
datatype = COL_DTYPE(colptr[k])
if (datatype < 0)
datatype = TY_CHAR
dlen = COL_LEN(colptr[k])
offset = tbyoff (tp, colptr[k], firstrow)
switch (datatype) {
case TY_REAL:
do j = 1, lastrow-firstrow+1 {
call seek (fd, offset)
call write (fd, INDEFR, dlen)
offset = offset + dlen
}
case TY_DOUBLE:
do j = 1, lastrow-firstrow+1 {
call seek (fd, offset)
call write (fd, TBL_INDEFD, dlen)
offset = offset + dlen
}
case TY_INT:
do j = 1, lastrow-firstrow+1 {
call seek (fd, offset)
call write (fd, INDEFI, dlen)
offset = offset + dlen
}
case TY_SHORT:
# We need this because INDEFS in the call to WRITE would be
# interpreted as an integer rather than as a short int.
sbuf = INDEFS
do j = 1, lastrow-firstrow+1 {
call seek (fd, offset)
call write (fd, sbuf, dlen)
offset = offset + dlen
}
case TY_BOOL:
boolbuf = false
do j = 1, lastrow-firstrow+1 {
call seek (fd, offset)
call write (fd, boolbuf, dlen)
offset = offset + dlen
}
case TY_CHAR:
call smark (sp)
call salloc (charbuf, dlen, TY_CHAR)
do j = 1, dlen
Memc[charbuf+j-1] = EOS # N.B. this assumes EOS = 0
do j = 1, lastrow-firstrow+1 {
call seek (fd, offset)
call write (fd, Memc[charbuf], dlen)
offset = offset + dlen
}
call sfree (sp)
}
}
end
|