From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- pkg/tbtables/tbeoff.x | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pkg/tbtables/tbeoff.x (limited to 'pkg/tbtables/tbeoff.x') diff --git a/pkg/tbtables/tbeoff.x b/pkg/tbtables/tbeoff.x new file mode 100644 index 00000000..4f39a98b --- /dev/null +++ b/pkg/tbtables/tbeoff.x @@ -0,0 +1,60 @@ +include +include "tbtables.h" +include "tblerr.h" + +# tbeoff -- get offset to an element +# This function returns the offset to an element (a specific row and +# column) in a table. +# +# Phil Hodge, 14-Sep-1987 Function created. +# Phil Hodge, 28-Jul-1994 Add elnum to calling sequence. + +long procedure tbeoff (tp, cptr, rownum, elnum) + +pointer tp # i: pointer to table descriptor +pointer cptr # i: pointer to column descriptor +int rownum # i: row number +int elnum # i: element number +#-- +long offset # the offset in char +int sz_element # size of one element (if entry is an array) +int tbeszt() + +begin + if (TB_TYPE(tp) == TBL_TYPE_S_ROW) + offset = TB_BOD(tp) + (rownum-1) * TB_ROWLEN(tp) + + COL_OFFSET(cptr) + + else if (TB_TYPE(tp) == TBL_TYPE_S_COL) + offset = TB_BOD(tp) + COL_OFFSET(cptr) * TB_ALLROWS(tp) + + (rownum-1) * COL_LEN(cptr) + + else if (TB_TYPE(tp) == TBL_TYPE_TEXT) + return (0) # offset is meaningless + + else + call error (ER_TBCORRUPTED, + "tbeoff: bad table type; table or memory corrupted?") + + if (elnum > 1) { + # Not the first element. First get the size of one element. + switch (COL_DTYPE(cptr)) { + case TBL_TY_REAL: + sz_element = SZ_REAL + case TBL_TY_DOUBLE: + sz_element = SZ_DOUBLE + case TBL_TY_INT: + sz_element = SZ_INT32 + case TBL_TY_SHORT: + sz_element = SZ_SHORT + case TBL_TY_BOOL: + sz_element = SZ_BOOL + default: + sz_element = tbeszt (cptr) # character type + } + + offset = offset + (elnum-1) * sz_element + } + + return (offset) +end -- cgit