Define From Source File

As an alternative to building a string variable containing the DEFSTRUCT and all the dependent definitions needed for your dynstruct, you can also extract it from a standard program source file. This might not help in situations where the structure information does not become available until runtime, but it is extremely useful in situations where you are using the dynstruct mechanism to work on a range of data layouts whose structures already exist. For example, a generic file viewer, or report generator for a particular application with a large, but finite set of file layouts. Note that the source file does not have to be limited to containing just the DEFSTRUCTs of interest; it can be an entire program, with many nested ++INCLUDEs, somewhere among which the target DEFSTRUCT is buried. Here we define a dynstruct corresponding to the DEFSTRUCT named ST_FLDDEF which is found in the file dynstruct.def, which is included by fndynst.bsi, which is included by fndynst.bp.

map1 dsname$,T_DYN_NAME     ! name of the Dynstruct/DEFSTRUCT

map1 dsdef$,s,0             ! @name of source file containing struct definition

map1 fields,i,2             ! # fields (signed to allow error codes)

map1 stsize,b,4             ! size of the structure

map1 errmsg$,s,100          ! error messages

 

dsname$ = "ST_FLDDEF"       ! name of DEFSTRUCT to create dynstruct from

dsdef$ = "@soslib:fndynst.bp[907,11]   ! note @ prefix signals file name

fields = Fn'Dynst'Define(dsdef$,stsize,dsname$,errmsg$)

? "fields: ";fields; ifelse$(fields >= 0, " [ok]"," Error: "+errmsg$)