aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbcnum.x
blob: 1bf6b90c1f3b1b96a3055b6dd75af0fbc9a60d25 (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
include "tbtables.h"

# tbcnum -- get column pointer from number
# This function returns the column pointer corresponding to a given
# column number, or NULL if the column number is out of range.
#
# Phil Hodge,  2-Mar-1998  Map selected column descriptor to actual descriptor.

pointer procedure tbcnum (tp, colnum)

pointer tp			# i: pointer to table descriptor
int	colnum			# i: column number (not pointer)
#--
pointer cp
pointer tcs_column()

begin
	# Value to be returned if column number is out of range.
	cp = NULL

	if (colnum < 1)
	    return (cp)

	if (TB_COLUMN_SELECT(tp) == YES) {	# column selector was used
	    if (colnum <= TB_NSEL_COLS(tp)) {
		cp = tcs_column (TB_SELCOL(tp,colnum))
	    }
	} else {				# column selector not used
	    if (colnum <= TB_NCOLS(tp)) {
		cp = TB_COLINFO(tp,colnum)
	    }
	}

	return (cp)
end