include define USRERR 1 # GETTABDAT -- Read an element from a table into a string # # B.Simon 17-Aug-87 First Code procedure gettabdat (hd, colname, rownum, maxch, value, undef, eltype) pointer hd # i: Table descriptor char colname[ARB] # i: Table column name int rownum # i: Table row number int maxch # i: Maximum length of element value char value[ARB] # o: Table element value bool undef # o: Is table element undefined? int eltype # o: Type of table element bool nullbuf[1] int lendata, ip pointer colptr[1] pointer sp, errtxt, valbuf string badnamerr "Column name not found in table (%s)" int tbcigi() begin # Allocate dynamic memory to hold strings call smark (sp) call salloc (errtxt, SZ_LINE, TY_CHAR) call salloc (valbuf, maxch, TY_CHAR) # Get the column pointer from the column name call tbcfnd (hd, colname, colptr, 1) # If the pointer is NULL, the column was not found if (colptr[1] == NULL) { call sprintf (Memc[errtxt], SZ_LINE, badnamerr) call pargstr (colname) call error (USRERR, Memc[errtxt]) } # Get the column data type. Store in eltype eltype = tbcigi (colptr[1], TBL_COL_DATATYPE) if (eltype < 0) { lendata = - eltype eltype = TY_CHAR } # Get the table element as a text string call tbrgtt (hd, colptr, Memc[valbuf], nullbuf, maxch, 1, rownum) if (eltype == TY_CHAR) { # Just do a straight copy if the element is a string call strcpy (Memc[valbuf], value, maxch) } else{ # Otherwise, strip whitespace from element value ip = 1 call ctowrd (Memc[valbuf], ip, value, maxch) } undef = nullbuf[1] call sfree (sp) return end