aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbxag.x
blob: e6a57043cc2cacadf47016ed01138df64b91679a (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
include <mach.h>		# for MAX_INT, MAX_SHORT, and MAX_REAL
include <tbset.h>
include "tbtables.h"

# This file contains tbxag[tbirds] as well as tbxgpt for getting an
# array of elements from a row ordered table.
#
# Phil Hodge, 12-Sep-1994  Subroutines created.
# Phil Hodge,  2-Jun-1997  Replace IS_INDEFD with TBL_IS_INDEFD.
# Phil Hodge,  5-Aug-1999  Use COL_NELEM instead of tbalen to get array length.

int procedure tbxagd (tp, cp, row, buffer, first, nelem)

pointer tp		# i: pointer to table struct
pointer cp		# i: pointer to column struct
int	row		# i: row number
double	buffer[ARB]	# o: values read from table
int	first		# i: number of first array element to read
int	nelem		# i: maximum number of elements to read
#--
pointer sp
pointer buf		# scratch for local string buffer
real	rbuf
int	ibuf
short	sbuf
bool	bbuf
long	offset		# offset of first element in entry
int	dtype		# data type of column
int	ntotal		# total number of elements in array
int	nret		# actual number of elements to read
int	nchar		# number of char to read
int	i		# loop index
int	read(), nscan()
long	tbeoff()
string	CANNOTREAD	"tbagtd:  unexpected end of file"
errchk	seek, read, tbxgpt

begin
	dtype = COL_DTYPE(cp)
	ntotal = COL_NELEM(cp)
	nret = min (nelem, ntotal-first+1)
	offset = tbeoff (tp, cp, row, first)
	call seek (TB_FILE(tp), offset)

	if (dtype == TBL_TY_DOUBLE) {

	    nchar = nret * SZ_DOUBLE
	    if (read (TB_FILE(tp), buffer, nchar) < nchar)
		call error (1, CANNOTREAD)
	    do i = 1, nret {
		if (TBL_IS_INDEFD (buffer[i]))
		    buffer[i] = INDEFD
	    }

	} else {

	    switch (dtype) {
	    case TBL_TY_REAL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), rbuf, SZ_REAL) < SZ_REAL)
			call error (1, CANNOTREAD)
		    if (IS_INDEFR(rbuf))
			buffer[i] = INDEFD
		    else
			buffer[i] = rbuf
		}
	    case TBL_TY_INT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), ibuf, SZ_INT32) < SZ_INT32)
			call error (1, CANNOTREAD)
		    if (SZ_INT != SZ_INT32)
			call iupk32 (ibuf, ibuf, 1)
		    if (IS_INDEFI(ibuf))
			buffer[i] = INDEFD
		    else
			buffer[i] = ibuf
		}
	    case TBL_TY_SHORT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), sbuf, SZ_SHORT) < SZ_SHORT)
			call error (1, CANNOTREAD)
		    if (IS_INDEFS(sbuf))
			buffer[i] = INDEFD
		    else
			buffer[i] = sbuf
		}
	    case TBL_TY_BOOL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), bbuf, SZ_BOOL) < SZ_BOOL)
			call error (1, CANNOTREAD)
		    if (bbuf)
			buffer[i] = double(YES)
		    else
			buffer[i] = double(NO)
		}
	    default:
		if (dtype > 0 && dtype != TBL_TY_CHAR)
		    call error (1, "tbagtd:  bad data type")
		call smark (sp)
		call salloc (buf, SZ_LINE, TY_CHAR)
		do i = 1, nret {
		    offset = tbeoff (tp, cp, row, first+i-1)
		    call tbxgpt (tp, cp, offset, Memc[buf], SZ_LINE, 1)
		    call sscan (Memc[buf])
			call gargd (buffer[i])
		    if (nscan() < 1)
			buffer[i] = INDEFD
		}
		call sfree (sp)
	    }
	}

	return (nret)
end

int procedure tbxagr (tp, cp, row, buffer, first, nelem)

pointer tp		# i: pointer to table struct
pointer cp		# i: pointer to column struct
int	row		# i: row number
real	buffer[ARB]	# o: values read from table
int	first		# i: number of first array element to read
int	nelem		# i: maximum number of elements to read
#--
pointer sp
pointer buf		# scratch for local string buffer
double	dbuf
int	ibuf
short	sbuf
bool	bbuf
long	offset		# offset of first element in entry
int	dtype		# data type of column
int	ntotal		# total number of elements in array
int	nret		# actual number of elements to read
int	nchar		# number of char to read
int	i		# loop index
int	read(), nscan()
long	tbeoff()
string	CANNOTREAD	"tbagtr:  unexpected end of file"
errchk	seek, read, tbxgpt

begin
	dtype = COL_DTYPE(cp)
	ntotal = COL_NELEM(cp)
	nret = min (nelem, ntotal-first+1)
	offset = tbeoff (tp, cp, row, first)
	call seek (TB_FILE(tp), offset)

	if (dtype == TBL_TY_REAL) {

	    nchar = nret * SZ_REAL
	    if (read (TB_FILE(tp), buffer, nchar) < nchar)
		call error (1, CANNOTREAD)

	} else {

	    switch (dtype) {
	    case TBL_TY_DOUBLE:
		do i = 1, nret {
		    if (read (TB_FILE(tp), dbuf, SZ_DOUBLE) < SZ_DOUBLE)
			call error (1, CANNOTREAD)
		    if (TBL_IS_INDEFD (dbuf))
			buffer[i] = INDEFR
		    else
			buffer[i] = dbuf
		}
	    case TBL_TY_INT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), ibuf, SZ_INT32) < SZ_INT32)
			call error (1, CANNOTREAD)
                    if (SZ_INT != SZ_INT32)
                        call iupk32 (ibuf, ibuf, 1)
		    if (IS_INDEFI(ibuf))
			buffer[i] = INDEFR
		    else
			buffer[i] = ibuf
		}
	    case TBL_TY_SHORT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), sbuf, SZ_SHORT) < SZ_SHORT)
			call error (1, CANNOTREAD)
		    if (IS_INDEFS(sbuf))
			buffer[i] = INDEFR
		    else
			buffer[i] = sbuf
		}
	    case TBL_TY_BOOL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), bbuf, SZ_BOOL) < SZ_BOOL)
			call error (1, CANNOTREAD)
		    if (bbuf)
			buffer[i] = real(YES)
		    else
			buffer[i] = real(NO)
		}
	    default:
		if (dtype > 0 && dtype != TBL_TY_CHAR)
		    call error (1, "tbagtr:  bad data type")
		call smark (sp)
		call salloc (buf, SZ_LINE, TY_CHAR)
		do i = 1, nret {
		    offset = tbeoff (tp, cp, row, first+i-1)
		    call tbxgpt (tp, cp, offset, Memc[buf], SZ_LINE, 1)
		    call sscan (Memc[buf])
			call gargd (dbuf)
		    if (nscan() < 1)
			buffer[i] = INDEFR
		    else if (abs (dbuf) > MAX_REAL)
			buffer[i] = INDEFR
		    else
			buffer[i] = dbuf
		}
		call sfree (sp)
	    }
	}

	return (nret)
end

int procedure tbxagi (tp, cp, row, buffer, first, nelem)

pointer tp		# i: pointer to table struct
pointer cp		# i: pointer to column struct
int	row		# i: row number
int	buffer[ARB]	# o: values read from table
int	first		# i: number of first array element to read
int	nelem		# i: maximum number of elements to read
#--
pointer sp
pointer buf		# scratch for local string buffer
double	dbuf
real	rbuf
short	sbuf
bool	bbuf
long	offset		# offset of first element in entry
int	dtype		# data type of column
int	ntotal		# total number of elements in array
int	nret		# actual number of elements to read
int	nchar		# number of char to read
int	i		# loop index
int	read(), nscan()
long	tbeoff()
string	CANNOTREAD	"tbagti:  unexpected end of file"
errchk	seek, read, tbxgpt

begin
	dtype = COL_DTYPE(cp)
	ntotal = COL_NELEM(cp)
	nret = min (nelem, ntotal-first+1)
	offset = tbeoff (tp, cp, row, first)
	call seek (TB_FILE(tp), offset)

	if (dtype == TBL_TY_INT) {

	    nchar = nret * SZ_INT32
	    if (read (TB_FILE(tp), buffer, nchar) < nchar)
		call error (1, CANNOTREAD)

	} else {

	    switch (dtype) {
	    case TBL_TY_DOUBLE:
		do i = 1, nret {
		    if (read (TB_FILE(tp), dbuf, SZ_DOUBLE) < SZ_DOUBLE)
			call error (1, CANNOTREAD)
		    if (TBL_IS_INDEFD (dbuf) || abs (dbuf) > MAX_INT)
			buffer[i] = INDEFI
		    else
			buffer[i] = nint (dbuf)
		}
	    case TBL_TY_REAL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), rbuf, SZ_REAL) < SZ_REAL)
			call error (1, CANNOTREAD)
		    if (IS_INDEFR(rbuf) || abs (rbuf) > MAX_INT)
			buffer[i] = INDEFI
		    else
			buffer[i] = nint (rbuf)
		}
	    case TBL_TY_SHORT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), sbuf, SZ_SHORT) < SZ_SHORT)
			call error (1, CANNOTREAD)
		    if (IS_INDEFS(sbuf))
			buffer[i] = INDEFI
		    else
			buffer[i] = sbuf
		}
	    case TBL_TY_BOOL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), bbuf, SZ_BOOL) < SZ_BOOL)
			call error (1, CANNOTREAD)
		    if (bbuf)
			buffer[i] = YES
		    else
			buffer[i] = NO
		}
	    default:
		if (dtype > 0 && dtype != TBL_TY_CHAR)
		    call error (1, "tbagti:  bad data type")
		call smark (sp)
		call salloc (buf, SZ_LINE, TY_CHAR)
		do i = 1, nret {
		    offset = tbeoff (tp, cp, row, first+i-1)
		    call tbxgpt (tp, cp, offset, Memc[buf], SZ_LINE, 1)
		    call sscan (Memc[buf])
			call gargd (dbuf)
		    if (nscan() < 1 || abs (dbuf) > MAX_INT)
			buffer[i] = INDEFI
		    else
			buffer[i] = nint (dbuf)
		}
		call sfree (sp)
	    }
	}

	return (nret)
end

int procedure tbxags (tp, cp, row, buffer, first, nelem)

pointer tp		# i: pointer to table struct
pointer cp		# i: pointer to column struct
int	row		# i: row number
short	buffer[ARB]	# o: values read from table
int	first		# i: number of first array element to read
int	nelem		# i: maximum number of elements to read
#--
pointer sp
pointer buf		# scratch for local string buffer
double	dbuf
real	rbuf
int	ibuf
bool	bbuf
long	offset		# offset of first element in entry
int	dtype		# data type of column
int	ntotal		# total number of elements in array
int	nret		# actual number of elements to read
int	nchar		# number of char to read
int	i		# loop index
int	read(), nscan()
long	tbeoff()
string	CANNOTREAD	"tbagts:  unexpected end of file"
errchk	seek, read, tbxgpt

begin
	dtype = COL_DTYPE(cp)
	ntotal = COL_NELEM(cp)
	nret = min (nelem, ntotal-first+1)
	offset = tbeoff (tp, cp, row, first)
	call seek (TB_FILE(tp), offset)

	if (dtype == TBL_TY_SHORT) {

	    nchar = nret * SZ_SHORT
	    if (read (TB_FILE(tp), buffer, nchar) < nchar)
		call error (1, CANNOTREAD)

	} else {

	    switch (dtype) {
	    case TBL_TY_DOUBLE:
		do i = 1, nret {
		    if (read (TB_FILE(tp), dbuf, SZ_DOUBLE) < SZ_DOUBLE)
			call error (1, CANNOTREAD)
		    if (TBL_IS_INDEFD (dbuf) || abs (dbuf) > MAX_SHORT)
			buffer[i] = INDEFS
		    else
			buffer[i] = nint (dbuf)
		}
	    case TBL_TY_REAL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), rbuf, SZ_REAL) < SZ_REAL)
			call error (1, CANNOTREAD)
		    if (IS_INDEFR(rbuf) || abs (rbuf) > MAX_SHORT)
			buffer[i] = INDEFS
		    else
			buffer[i] = nint (rbuf)
		}
	    case TBL_TY_INT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), ibuf, SZ_INT32) < SZ_INT32)
			call error (1, CANNOTREAD)
                    if (SZ_INT != SZ_INT32)
                        call iupk32 (ibuf, ibuf, 1)
		    if (IS_INDEFI(ibuf) || abs (ibuf) > MAX_SHORT)
			buffer[i] = INDEFS
		    else
			buffer[i] = ibuf
		}
	    case TBL_TY_BOOL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), bbuf, SZ_BOOL) < SZ_BOOL)
			call error (1, CANNOTREAD)
		    if (bbuf)
			buffer[i] = YES
		    else
			buffer[i] = NO
		}
	    default:
		if (dtype > 0 && dtype != TBL_TY_CHAR)
		    call error (1, "tbagts:  bad data type")
		call smark (sp)
		call salloc (buf, SZ_LINE, TY_CHAR)
		do i = 1, nret {
		    offset = tbeoff (tp, cp, row, first+i-1)
		    call tbxgpt (tp, cp, offset, Memc[buf], SZ_LINE, 1)
		    call sscan (Memc[buf])
			call gargd (dbuf)
		    if (nscan() < 1 || abs (dbuf) > MAX_SHORT)
			buffer[i] = INDEFS
		    else
			buffer[i] = nint (dbuf)
		}
		call sfree (sp)
	    }
	}

	return (nret)
end

int procedure tbxagb (tp, cp, row, buffer, first, nelem)

pointer tp		# i: pointer to table struct
pointer cp		# i: pointer to column struct
int	row		# i: row number
bool	buffer[ARB]	# o: values read from table
int	first		# i: number of first array element to read
int	nelem		# i: maximum number of elements to read
#--
pointer sp
pointer buf		# scratch for local string buffer
double	dbuf
real	rbuf
int	ibuf
short	sbuf
long	offset		# offset of first element in entry
int	dtype		# data type of column
int	ntotal		# total number of elements in array
int	nret		# actual number of elements to read
int	nchar		# number of char to read
int	i		# loop index
int	read(), nscan()
long	tbeoff()
string	CANNOTREAD	"tbagtb:  unexpected end of file"
errchk	seek, read, tbxgpt

begin
	dtype = COL_DTYPE(cp)
	ntotal = COL_NELEM(cp)
	nret = min (nelem, ntotal-first+1)
	offset = tbeoff (tp, cp, row, first)
	call seek (TB_FILE(tp), offset)

	if (dtype == TBL_TY_BOOL) {

	    nchar = nret * SZ_BOOL
	    if (read (TB_FILE(tp), buffer, nchar) < nchar)
		call error (1, CANNOTREAD)

	} else {

	    switch (dtype) {
	    case TBL_TY_DOUBLE:
		do i = 1, nret {
		    if (read (TB_FILE(tp), dbuf, SZ_DOUBLE) < SZ_DOUBLE)
			call error (1, CANNOTREAD)
		    if (TBL_IS_INDEFD (dbuf))
			buffer[i] = false
		    else
			buffer[i] = (dbuf != double(NO))
		}
	    case TBL_TY_REAL:
		do i = 1, nret {
		    if (read (TB_FILE(tp), rbuf, SZ_REAL) < SZ_REAL)
			call error (1, CANNOTREAD)
		    if (IS_INDEFR(rbuf))
			buffer[i] = false
		    else
			buffer[i] = (rbuf != real(NO))
		}
	    case TBL_TY_INT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), ibuf, SZ_INT32) < SZ_INT32)
			call error (1, CANNOTREAD)
                    if (SZ_INT != SZ_INT32)
                        call iupk32 (ibuf, ibuf, 1)
		    if (IS_INDEFI(ibuf))
			buffer[i] = false
		    else
			buffer[i] = (ibuf != NO)
		}
	    case TBL_TY_SHORT:
		do i = 1, nret {
		    if (read (TB_FILE(tp), sbuf, SZ_SHORT) < SZ_SHORT)
			call error (1, CANNOTREAD)
		    if (IS_INDEFS(sbuf))
			buffer[i] = false
		    else
			buffer[i] = (sbuf != NO)
		}
	    default:
		if (dtype > 0 && dtype != TBL_TY_CHAR)
		    call error (1, "tbagtb:  bad data type")
		call smark (sp)
		call salloc (buf, SZ_LINE, TY_CHAR)
		do i = 1, nret {
		    offset = tbeoff (tp, cp, row, first+i-1)
		    call tbxgpt (tp, cp, offset, Memc[buf], SZ_LINE, 1)
		    call sscan (Memc[buf])
			call gargb (buffer[i])
		    if (nscan() < 1)
			buffer[i] = false
		}
		call sfree (sp)
	    }
	}

	return (nret)
end

int procedure tbxagt (tp, cp, row, cbuf, maxch, first, nelem)

pointer tp		# i: pointer to table struct
pointer cp		# i: pointer to column struct
int	row		# i: row number
char	cbuf[maxch,ARB]	# o: values read from table
int	maxch		# i: size of first dimension of cbuf
int	first		# i: number of first array element to read
int	nelem		# i: maximum number of elements to read
#--
pointer sp
pointer buf		# scratch for local string buffer
double	dbuf
real	rbuf
int	ibuf
short	sbuf
bool	bbuf
char	pformat[SZ_COLFMT]	# print format for column
long	offset		# offset of first element in entry
int	dtype		# data type of column
int	ntotal		# total number of elements in array
int	nret		# actual number of elements to read
int	i		# loop index
int	read()
long	tbeoff()
string	CANNOTREAD	"tbagtt:  unexpected end of file"
errchk	seek, read, tbxgpt

begin
	dtype = COL_DTYPE(cp)
	ntotal = COL_NELEM(cp)
	nret = min (nelem, ntotal-first+1)
	offset = tbeoff (tp, cp, row, first)

	if (dtype < 0 || dtype == TBL_TY_CHAR) {

	    call tbxgpt (tp, cp, offset, cbuf[1,1], maxch, nret)

	} else {

	    call smark (sp)
	    call salloc (buf, SZ_LINE+maxch, TY_CHAR)
	    call tbcigt (cp, TBL_COL_FMT, pformat, SZ_COLFMT)

	    call seek (TB_FILE(tp), offset)

	    do i = 1, nret {

		switch (dtype) {
		case TBL_TY_REAL:
		    if (read (TB_FILE(tp), rbuf, SZ_REAL) < SZ_REAL)
			call error (1, CANNOTREAD)
		    call sprintf (Memc[buf], SZ_LINE+maxch, pformat)
			call pargr (rbuf)
		case TBL_TY_DOUBLE:
		    if (read (TB_FILE(tp), dbuf, SZ_DOUBLE) < SZ_DOUBLE)
			call error (1, CANNOTREAD)
		    if (TBL_IS_INDEFD (dbuf)) {
			call strcpy ("INDEF", Memc[buf], SZ_LINE)
		    } else {
			call sprintf (Memc[buf], SZ_LINE+maxch, pformat)
			    call pargd (dbuf)
		    }
		case TBL_TY_INT:
		    if (read (TB_FILE(tp), ibuf, SZ_INT32) < SZ_INT32)
			call error (1, CANNOTREAD)
                    if (SZ_INT != SZ_INT32)
                        call iupk32 (ibuf, ibuf, 1)
		    call sprintf (Memc[buf], SZ_LINE+maxch, pformat)
			call pargi (ibuf)
		case TBL_TY_SHORT:
		    if (read (TB_FILE(tp), sbuf, SZ_SHORT) < SZ_SHORT)
			call error (1, CANNOTREAD)
		    call sprintf (Memc[buf], SZ_LINE+maxch, pformat)
			call pargs (sbuf)
		case TBL_TY_BOOL:
		    if (read (TB_FILE(tp), bbuf, SZ_BOOL) < SZ_BOOL)
			call error (1, CANNOTREAD)
		    call sprintf (Memc[buf], SZ_LINE+maxch, pformat)
			call pargb (bbuf)
		default:
		    call error (1, "tbagtt:  bad data type")
		}

		call strcpy (Memc[buf], cbuf[1,i], maxch)
	    }

	    call sfree (sp)
	}

	return (nret)
end

# tbxgpt -- array get primitive text

procedure tbxgpt (tp, cp, offset, cbuf, maxch, nelem)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
long	offset			# i: offset in char to first location
char	cbuf[maxch,nelem]	# o: buffer to receive values
int	maxch			# i: size of each element of array
int	nelem			# i: number of elements to get
#--
char	buffer[SZ_LINE]		# buffer for reading from table
long	eoffset			# offset to location for reading
int	nchar			# size of each element in table
int	i
int	read(), tbeszt()
errchk	seek, read

begin
	nchar = min (tbeszt (cp), SZ_LINE)	# size of each element
	eoffset = offset			# an initial value

	do i = 1, nelem {			# do for each element

	    call seek (TB_FILE(tp), eoffset)
	    if (read (TB_FILE(tp), buffer, nchar) < nchar)
		call error (1, "tbxgpt:  unexpected end of file")

	    # It may be that no EOS was read from the element in the table.
	    buffer[nchar+1] = EOS
	    call strupk (buffer, cbuf[1,i], maxch)

	    eoffset = eoffset + nchar
	}
end