Programming a Tuxedo ATMI Application Using FML
|
|
This topic includes the following sections:
This section describes all FML and VIEWS functions except the run-time mapping functions described in Defining and Using Fields.
FML functions are not directly available for COBOL programs. A procedure called FINIT is available to initialize a record for receiving FML data, and the FVSTOF and FVFTOS procedures are available to convert a COBOL record into an FML buffer, and vice-versa. For detailed descriptions of these procedures, see Programming a BEA Tuxedo ATMI Application Using COBOL. The COBOL interface is not described further here.
There are two variants of FML. The original FML interface is based on 16-bit values for the length of fields and contains information identifying fields (hence FML16). FML16 is limited to 8191 unique fields, individual field lengths of up to 64K bytes, and a total fielded buffer size of 64K. The definitions, types, and function prototypes for this interface are in fml.h which must be included in an application program using the FML16 interface; and functions live in -lfml.
A second interface, FML32, uses 32-bit values for the field lengths and identifiers. It allows for about 30 million fields, and field and buffer lengths of about 2 billion bytes. The definitions, types, and function prototypes for FML32 are in fml32.h; functions reside in -lfml32. All definitions, types, and function names for FML32 have a "32" suffix (for example, MAXFBLEN32, FBFR32, FLDID32, FLDLEN32, F_OVHD32, Fchg32, and error code Ferror32). Also the environment variables are suffixed with "32" (for example, FLDTBLDIR32, FIELDTBLS32, VIEWFILES32, and VIEWDIR32). For FML32, a fielded buffer pointer is of type "FBFR32 *", a field length has the type FLDLEN32, and the number of occurrences of a field has the type FLDOCC32. The default required alignment for FML32 buffers is 4-byte alignment.
FML16 applications that are written correctly can easily be changed to use the FML32 interface. All variables used in the calls to the FML functions must use the proper typedefs (FLDID, FLDLEN, and FLDOCC). Any call to tpalloc(3c) for an FML typed buffer should use the FMLTYPE definition instead of "FML". The application source code can be changed to use the 32-bit functions simply by changing the include of fml.h to inclusion of fml32.h followed by fml1632.h. The fml1632.h contains macros that convert all of the 16-bit type definitions to 32-bit type definitions, and 16-bit functions and macros to 32-bit functions and macros.
Functions are also provided to convert an FML32 fielded buffer into an FML16 fielded buffer, and vice-versa:
#include "fml.h"
#include "fml32.h"
int
F32to16(FBFR *dest, FBFR32 *src)
int
F16to32(FBFR32 *dest, FBFR *src)
F32to16 converts a 32-bit FML buffer to a 16-bit FML buffer. It does this by converting the buffer on a field-by-field basis and then creating the index for the fielded buffer. A field is converted by generating a FLDID from a FLDID32, and copying the field value (and field length for string and carray fields).
dest and src are pointers to the destination and source fielded buffers, respectively. The source buffer is not changed.
These functions can fail for lack of space; they can be re-issued after enough additional space to complete the operation has been allocated. F16to32 converts a 16-bit FML buffer to a 32-bit FML buffer. It lives in the fml32 library or shared object and sets Ferror32 on error. F32to16 lives in the fml library or shared object and sets Ferror on error. Note that both fml.h and fml32.h must be included to use these functions; fml1632.h may not be included in the same file.
The field types for embedded buffers (FLD_PTR, FLD_FML32, and FLD_VIEW32) are supported only for FML32. Buffers containing FLD_PTR, FLD_FML32, FLD_MBSTRING, or FLD_VIEW32 fields cause F32to16 to fail with an FBADFLD error. There is no impact when F16to32 is called for these functions.
Note: For the remainder of this section, we describe only the 16-bit functions, without specifying the equivalent FML32 and VIEW32 functions.
To simplify the specification of parameters for FML functions, a convention has been adopted for the sequence of those parameters. FML parameters appear in the following sequence.
FBFR), this parameter is first. If a function takes two-fielded buffer pointers (such as the transfer functions), the destination buffer comes first, followed by the source buffer. A fielded buffer pointer must point to an area that is aligned on a short boundary (or an error is returned with Ferror set to FALIGNERR) and the area must be a fielded buffer (or an error is returned with Ferror set to FNOTFLD).FLDID) appears next (in the case of Fnext, it is a pointer to a field identifier).FLDOCC), this parameter comes next. (For Fnext, it is a pointer to an occurrence number.)carray, mbstring) field, you must specify its length as the next parameter (type FLDLEN). For functions that retrieve a field value, a pointer to the length of the retrieval buffer must be passed to the function and this length parameter is set to the length of the value retrieved.
Several functions allow a programmer to query field tables or field identifiers for information about fields during program execution.
Fldid returns the field identifier for a given valid field name and loads the field name/field ID mapping tables from the field table files, if they do not already exist.
FLDID
Fldid(char *name)
Here name is a valid field name.
The space used by the mapping tables in memory can be freed using the Fnmid_unload, Fnmid_unload32(3fml) function. Note that these tables are separate from the tables loaded and used by the Fname function.
For more information, refer to Fldid, Fldid32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fname returns the field name for a given valid field identifier and loads the field ID/name mapping tables from the field table files, if they do not already exist.
char *
Fname(FLDIDfieldid)
Here fieldid is a valid field identifier.
The space used by the mapping tables in memory can be freed using the Fnmid_unload, Fnmid_unload32(3fml) function. Note that these tables are separate from the tables loaded and used by the Fldid function. (Refer to the BEA Tuxedo ATMI FML Function Reference for more information.)
For more information, refer to Fname, Fname32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fldno extracts the field number from a given field identifier.
FLDOCC
Fldno(FLDIDfieldid)
Here fieldid is a valid field identifier.
For more information, refer to Fldno, Fldno32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fldtype extracts the field type (an integer, as defined in fml.h) from a given field identifier.
int
Fldtype(FLDIDfieldid)
Here fieldid is a valid field identifier.
The following table shows the possible values returned by Fldtype and their meanings.
For more information, refer to Fldtype, Fldtype32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Ftype returns a pointer to a string containing the name of the type of a field given a field identifier.
char *
Ftype(FLDIDfieldid)
Here fieldid is a valid field identifier. For example, the following code returns a pointer to one of the following strings: short, long, char, float, double, string, carray, mbstring, FLD_PTR, FLD_FML32, or FLD_VIEW32.
char *typename
. . .
typename = Ftype(fieldid);
For more information, refer to Ftype, Ftype32(3fml) in BEA Tuxedo ATMI FML Function Reference.
As part of an application generator, or to reconstruct a field identifier, it might be useful to make a field identifier from a type specification and an available field number. Fmkfldid provides this functionality.
FLDID
Fmkfldid(inttype, FLDIDnum)
type is a valid type. (Specifically, it is an integer; see Fldtype for details.)num is a field number. (It should be an unused field number to avoid confusion with existing fields.)For more information, refer to Fmkfldid, Fmkfldid32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The functions described in this section are provided for writing stand-alone FML programs. If you are using the BEA Tuxedo ATMI functions, keep in mind that for tasks such as allocating and freeing message buffers, you must call ATMI functions such as tpalloc(3c), tprealloc(3c), and tpfree(3c), instead of FML functions such as Falloc, Falloc32(3fml), Frealloc, Frealloc32(3fml), and Ffree, Ffree32(3fml).
Most FML functions require a pointer to a fielded buffer as an argument. The typedef FBFR is available for declaring such pointers, as shown in the following example:
FBFR *fbfr;
In this section, the variable fbfr refers to a pointer to a fielded buffer. Never attempt to declare fielded buffers themselves; declare only pointers to fielded buffers.
When a server receives a request that contains an FML buffer, it allocates space for that FML buffer and for any embedded views or buffers referenced by FLD_PTR fields. A pointer to the new FML buffer is passed to the user-written code. Once the server processing is complete, all buffers allocated when the message was received must be destroyed. The BEA Tuxedo system checks the FML buffer and all subsidiary buffers, and deletes any buffers to which it finds references. As a programmer writing server code, you should be aware of the following situations:
tpreturn() is freed, but any buffers referenced by FLD_PTR or FLD_VIEW32 fields are not freed.The functions used to reserve space for fielded buffers are explained in the following text, but first we describe a function that can be used to determine whether a given buffer is, in fact, a fielded buffer.
Fielded (or Fielded32) is used to test whether the specified buffer is fielded.
int
Fielded(FBFR *fbfr)
Fielded32 is used with 32-bit FML.
Fielded returns true (1) if the buffer is fielded. It returns false (0) if the buffer is not fielded but does not set Ferror.
For more information, refer to Fielded, Fielded32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The amount of memory to allocate for a fielded buffer depends on the maximum number of fields the buffer will contain and the total amount of space needed for all the field values. The function Fneeded can be used to determine the amount of space (in bytes) needed for a fielded buffer; it takes the number of fields and the space needed for all field values (in bytes) as arguments.
long
Fneeded(FLDOCCF, FLDLENV)
The space needed for field values is computed by estimating the amount of space that is required by each field value if stored in standard structures (for example, a long is stored as a long and needs four bytes). For variable length fields, estimate the average amount of space needed for the field. The space calculated by Fneeded includes a fixed overhead for each field; it adds that to the space needed for the field values.
Once you obtain the estimate of space from Fneeded, you can allocate the desired number of bytes using malloc(3) and set up a pointer to the allocated memory space. For example, the following code allocates space for a fielded buffer large enough to contain 25 fields and 300 bytes of values.
#define NF 25
#define NV 300
extern char *malloc;
. . .
if((fbfr = (FBFR *)malloc(Fneeded(NF, NV))) == NULL)
F_error("pgm_name"); /* no space to allocate buffer */
However, this allocated memory space is not yet a fielded buffer. Finit must be used to initialize it.
For more information, refer to Fneeded, Fneeded32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The Fvneeded function determines the amount of space (in bytes) needed for a VIEW buffer. The function takes a pointer to the name of the VIEW as an argument.
long
Fvneeded(char *subtype)
The Fvneeded function returns the size of the VIEW in number of bytes.
For more information, refer to Fvneeded, Fvneeded32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The Finit function initializes an allocated memory space as a fielded buffer.
int
Finit(FBFR *fbfr, FLDLENbuflen)
A call to Finit to initialize the memory space allocated in the previous example looks like the following code:
Finit(fbfr, Fneeded(NF, NV));
Now fbfr points to an initialized, empty fielded buffer. Up to Fneeded(NF, NV) bytes minus a small amount (F_OVHD as defined in fml.h) are available in the buffer to hold fields.
Note: The numbers used in the malloc(3) call (as described in the previous section) and Finit call must be the same.
For more information, refer to Finit, Finit32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Calls to Fneeded, malloc(3) and Finit may be replaced by a single call to Falloc, which allocates the desired amount of space and initializes the buffer.
FBFR *
Falloc(FLDOCCF, FLDLENV)
A call to Falloc that provides the same functionality created by the calls to Fneeded, malloc(), and Finit described in the previous three sections, must be written as follows:
extern FBFR *Falloc;
. . .
if((fbfr = Falloc(NF, NV)) == NULL)
F_error("pgm_name"); /* couldn't allocate buffer */
Storage allocated with Falloc (or Fneeded, malloc(3), and Finit) should be freed with Ffree. (See Ffree, Ffree32(3fml) in the BEA Tuxedo ATMI FML Function Reference.)
For more information, refer to Falloc, Falloc32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Ffree is used to free memory space allocated as a fielded buffer. Ffree32 does not free the memory area referenced by a pointer in a FLD_PTR field.
int
Ffree(FBFR *fbfr)
Here fbfr is a pointer to a fielded buffer. Consider the following example:
#include <fml.h>
. . .
if(Ffree(fbfr) < 0)
F_error("pgm_name"); /* not fielded buffer */
Ffree is preferable to free(3), because Ffree invalidates a fielded buffer, whereas free(3) does not. It is necessary to invalidate fielded buffers because malloc(3) re-uses memory that has been freed without clearing it. Thus, if free(3) is used, malloc can return a piece of memory that looks like a valid fielded buffer, but is not.
Space for a fielded buffer may also be reserved directly. The buffer must begin on a short boundary. You must allocate at least F_OVHD bytes (defined in fml.h) for the buffer; if you do not, Finit returns an error.
The following code is analogous to the preceding example but Fneeded cannot be used to size the static buffer because it is not a macro:
/* the first line aligns the buffer */
static short buffer[500/sizeof(short)];
FBFR *fbfr=(FBFR *)buffer;
. . .
Finit(fbfr, 500);
Be careful not to enter code such as the following:
FBFR badfbfr;
. . .
Finit(&badfbfr, Fneeded(NF, NV));
This code is wrong: the structure for FBFR is not defined in the user header files. As a result, a compilation error will be produced.
For more information, refer to Ffree, Ffree32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fsizeof returns the size of a fielded buffer in bytes.
long
Fsizeof(FBFR *fbfr)
Here fbfr is a pointer to a fielded buffer. In the following code, for example, Fsizeof returns the same number that Fneeded returned when the fielded buffer was originally allocated:
long bytes;
. . .
bytes = Fsizeof(fbfr);
For more information, refer to Fsizeof, Fsizeof32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Funused may be used to determine how much space is available in a fielded buffer for additional data.
long
Funused(FBFR *fbfr)
Here fbfr is a pointer to a fielded buffer. Consider the following example:
long unused;
. . .
unused = Funused(fbfr);
Note that Funused does not indicate the location, in the buffer, of the unused bytes; only the number of unused bytes is specified.
For more information, refer to Funused, Funused32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fused may be used to determine how much space is used in a fielded buffer for data and overhead.
long
Fused(FBFR *fbfr)
Here fbfr is a pointer to a fielded buffer. Consider the following example:
long used;
. . .
used = Fused(fbfr);
Note that Fused does not indicate the location, in the buffer, of the used bytes; only the number of used bytes is specified.
For more information, refer to Fused, Fused32(3fml) in BEA Tuxedo ATMI FML Function Reference.
This function enables you to change the size of a buffer for which you have allocated space by calling Falloc.
If you have allocated space with tpalloc(3c), you must call tprealloc(3c) to reallocate that space. Being able to resize the buffer can be useful if, for example, a buffer runs out of space while a new field value is being added. Simply by calling Frealloc you can increase the size of the buffer. In other situations you may want to call Frealloc to decrease the size of the buffer.
FBFR *
Frealloc(FBFR *fbfr, FLDOCCnf, FLDLENnv)
fbfr is a pointer to a fielded buffer.nf is the new number of fields or 0.nv is the new space for field values, in bytes.Consider the following example:
FBFR *newfbfr;
. . .
if((newfbfr = Frealloc(fbfr, NF+5, NV+300)) == NULL)
F_error("pgm_name"); /* couldn't re-allocate space */
else
fbfr = newfbfr; /* assign new pointer to old */
In this case, the application needed to remember the number of fields and the number of value space bytes previously allocated. Note that the arguments to Frealloc (as with its counterpart realloc(3)) are absolute values, not increments. This example does not work if it is necessary to re-allocate space several times.
The following example shows a second way of incrementing the allocated space:
/* define the increment size when buffer out of space */
#define INCR 400
FBFR *newfbfr;
. . .
if((newfbfr = Frealloc(fbfr, 0, Fsizeof(fbfr)+INCR)) == NULL)
F_error("pgm_name"); /* couldn't re-allocate space */
else
fbfr = newfbfr; /* assign new pointer to old */
You do not need to know the number of fields or the value space size with which the buffer was last initialized. Thus, the easiest way to increase the size is to use the current size plus the increment as the value space. The previous example can be executed as many times as needed without remembering past executions or values. You do not need to call Finit after calling Frealloc.
If the amount of additional space requested in the call to Frealloc is contiguous to the old buffer, newfbfr and fbfr in the previous examples are the same. However, defensive programming dictates that you should declare newfbfr as a safeguard in case either a new value or NULL is returned. If Frealloc fails, do not use fbfr again.
Note: The buffer size can be decreased only to the number of bytes currently being used in the buffer.
For more information, refer to Frealloc, Frealloc32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The only restriction on the location of fielded buffers is that they must be aligned on a short boundary. Otherwise, fielded buffers are position-independent and may be moved around freely in memory.
If src points to a fielded buffer and dest points to an area of storage big enough to hold it, then the following code might be used to move the fielded buffer:
FBFR *src;
char *dest;
. . .
memcpy(dest, src, Fsizeof(src));
The function memcpy, one of the C run-time memory management functions, moves the number of bytes indicated by its third argument from the area pointed to by its second argument to the area pointed to by its first argument.
While memcpy may be used to copy a fielded buffer, the destination copy of the buffer looks just like the source copy. In particular, for example, the destination copy has the same number of unused bytes as the source buffer.
Fmove acts like memcpy, but does not need an explicit length (which is computed).
int
Fmove(char *dest, FBFR *src)
In the following code, for example, Fmove checks that the source buffer is indeed a fielded buffer, but does not modify the source buffer in any way.
FBFR *src;
char *dest;
. . .
if(Fmove(dest,src) < 0)
F_error("pgm_name");
The destination buffer need not be a fielded buffer (that is, it need not have been allocated using Falloc), but it must be aligned on a short boundary (4-byte alignment for FML32). Thus, Fmove provides an alternative to Fcpy when you want to copy a fielded buffer to a non-fielded buffer. Fmove does not, however, check to make sure there is enough room in the destination buffer to receive the source buffer.
For values of type FLD_PTR, Fmove32 transfers the buffer pointer. The application programmer must manage the reallocation and freeing of buffers when the associated pointer is moved. The buffer pointed to by a FLD_PTR field must be allocated using the tpalloc(3c) call.
For more information, refer to Fmove, Fmove32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fcpy is used to overwrite one fielded buffer with another.
int
Fcpy(FBFR *dest, FBFR *src)
Fcpy preserves the overall buffer length of the overwritten fielded buffer and therefore is useful for expanding or reducing the size of a fielded buffer. Consider the following example:
FBFR *src, *dest;
. . .
if(Fcpy(dest, src) < 0)
F_error("pgm_name");
Unlike Fmove, where dest could point to an uninitialized area, Fcpy expects dest to point to an initialized fielded buffer (allocated using Falloc). Fcpy also verifies that dest is big enough to accommodate the data from the source buffer.
Note: You cannot reduce the size of a fielded buffer below the amount of space needed for currently held data.
As with Fmove, the source buffer is not modified by Fcpy.
For values of type FLD_PTR, Fcpy32 copies the buffer pointer. The application programmer must manage the reallocation and freeing of buffers when the associated pointer is copied. The buffer pointed to by a FLD_PTR field must be allocated using the tpalloc(3c) call.
For more information, refer to Fcpy, Fcpy32(3fml) in BEA Tuxedo ATMI FML Function Reference.
This section discusses how to update and access fielded buffers using the field types of the fields without doing any conversions. For a list of the functions that allow you to convert data from one type to another upon transfer to or from a fielded buffer, see Conversion Functions.
The Fadd function adds a new field value to the fielded buffer.
int
Fadd(FBFR *fbfr, FLDIDfieldid, char *value, FLDLENlen)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.value is a pointer to a new value. Its type is shown as char*, but when it is used, its type must be the same type as the value to be added (see below).len is the length of the value if its type is FLD_CARRAY or FLD_MBSTRING.If no occurrence of the field exists in the buffer, then the field is added. If one or more occurrences of the field already exist, then the value is added as a new occurrence of the field, and is assigned an occurrence number 1 greater than the current highest occurrence. (To add a specific occurrence, Fchg must be used.)
Fadd, like all other functions that take or return a field value, expects a pointer to a field value, never the value itself.
If the field type is such that the field length is fixed (short, long, char, float, or double) or can be determined (string), the field length need not be given (it is ignored). If the field type is a character array (FLD_CARRAY or FLD_MBSTRING), the length must be specified; the length is defined as type FLDLEN. The following code, for example, gets the field identifier for the desired field and adds the field value to the buffer.
FLDID fieldid, Fldid;
FBFR *fbfr;
. . .
fieldid = Fldid("fieldname");
if(Fadd(fbfr, fieldid, "new value", (FLDLEN)9) < 0)
F_error("pgm_name");
It is assumed (by default) that the native type of the field is a character array so that the length of the value must be passed to the function. If the value being added is not a character array, the type of value must reflect the type of the value to which it points. The following code, for example, adds a long field value.
long lval;
. . .
lval = 123456789;
if(Fadd(fbfr, fieldid, &lval, (FLDLEN)0) < 0)
F_error("pgm_name");
For character array fields, null fields may be indicated by a length of 0. For string fields, the null string may be stored since the NULL terminating byte is actually stored as part of the field value: a string consisting of only the NULL terminating byte is considered to have a length of 1. For all other types (fixed length types), you may choose some special value that is interpreted by the application as a NULL, but the size of the value is taken from its field type (for example, a length of 4 for a long), regardless of what value is actually passed. Passing a NULL value address results in an error (FEINVAL).
For pointer fields, Fadd32 stores the pointer value. The buffer pointed to by a FLD_PTR field must be allocated using the tpalloc(3c) call. For embedded FML32 buffers, Fadd32 stores the entire FLD_FML32 field value, except for the index.
For embedded VIEW32 buffers, Fadd32 stores a pointer to a structure of type FVIEWFLD, which contains vflags (a flags field, currently unused and set to 0), vname (a character array containing the view name), and data (a pointer to the view data stored as a C structure). The application provides the vname and data to Fadd32. The FVIEWFLD structure is as follows:
typedef struct {
TM32U vflags; /* flags - currently unused */
char vname[FVIEWNAMESIZE+1]; /* name of view */
char *data; /* pointer to view structure */
} FVIEWFLD;
For more information, refer to Fadd, Fadd32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The Fappend function appends a new field value to the fielded buffer.
int
Fappend(FBFR *fbfr, FLDIDfieldid, char *value, FLDLENlen)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.value is a pointer to a new value. Its type is shown as char *, but when it is used, its type must be the same type as the value to be appended (see below).len is the length of the value if its type is FLD_CARRAY or FLD_MBSTRING.Fappend appends a new occurrence of the field fieldid with a value located at value to the fielded buffer and puts the buffer into append mode. Append mode provides optimized buffer construction for large buffers constructed of many rows of a common set of fields.
A buffer that is in append mode is restricted as to what operations may be performed on the buffer. Only calls to the following FML routines are allowed in append mode: Fappend, Findex, Funindex, Ffree, Fused, Funused and Fsizeof. Calls to Findex or Funindex end append mode.
The following example shows the construction, using Fappend, of a 500-row buffer with 5 fields per row:
for (i=0; i 500 ;i++) {
if ((Fappend(fbfr, LONGFLD1, &lval1[i], (FLDLEN)0) < 0) ||
(Fappend(fbfr, LONGFLD2, &lval2[i], (FLDLEN)0) < 0) ||
(Fappend(fbfr, STRFLD1, &str1[i], (FLDLEN)0) < 0) ||
(Fappend(fbfr, STRFLD2, &str2[i], (FLDLEN)0) < 0) ||
(Fappend(fbfr, LONGFLD3, &lval3[i], (FLDLEN)0) < 0)) {
F_error("pgm_name");
break;
}
}
Findex(fbfr, 0);
Fappend, like all other functions that take or return a field value, expects a pointer to a field value, never the value itself.
If the field type is such that the field length is fixed (short, long, char, float, or double) or can be determined (string), the field length need not be given (it is ignored). If the field type is a character array (FLD_CARRAY or FLD_MBSTRING), the length must be specified; the length is defined as type FLDLEN.
It is assumed (by default) that the native type of the field is a character array so that the length of the value must be passed to the function. If the value being appended is not a character array, the type of value must reflect the type of the value it points to.
For character array fields, null fields may be indicated by a length of 0. For string fields, the null string may be stored since the NULL terminating byte is actually stored as part of the field value: a string consisting of only the NULL terminating byte is considered to have a length of 1. For all other types (fixed-length types), you may choose some special value that is interpreted by the application as a NULL, but the size of the value is taken from its field type (for example, the length of 4 for a long), regardless of what value is actually passed. Passing a NULL value address results in an error (FEINVAL).
For more information, refer to Fappend, Fappend32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fchg changes the value of a field in the buffer.
int
Fchg(FBFR *fbfr, FLDIDfieldid, FLDOCCoc, char *value, FLDLENlen)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.oc is the occurrence number of the field.value is a pointer to a new value. Its type is shown as char *, but when it is used, its type must be the same type as the value to be added (see Fadd).len is the length of the value if its type is FLD_CARRAY or FLD_MBSTRING.For example, the following code changes a field of type carray to a new value stored in value:
FBFR *fbfr;
FLDID fieldid;
FLDOCC oc;
FLDLEN len;
char value[50];
. . .
strcpy(value, "new value");
flen = strlen(value);
if(Fchg(fbfr, fieldid, oc, value, len) < 0)
F_error("pgm_name");
If oc is -1, then the field value is added as a new occurrence to the buffer. If oc is 0 or greater and the field is found, then the field value is modified to the new value specified. If oc is 0 or greater and the field is not found, then NULL occurrences are added to the buffer until the value can be added as the specified occurrence. For example, changing field occurrence 3 for a field that does not exist on a buffer causes three NULL occurrences to be added (occurrences 0, 1 and 2), followed by occurrence 3 with the specified field value. Null values consist of the NULL string "\0" (1 byte in length) for string and character values, 0 for long and short fields, 0.0 for float and double values, and a zero-length string for a character array.
The new or modified value is contained in value. If it is a character array (FLD_CARRAY or FLD_MBSTRING), its length is given in len (len is ignored for other field types). If the value pointer is NULL and the field is found, then the field is deleted. If the field occurrence to be deleted is not found, it is considered an error (FNOTPRES).
For pointer fields, Fchg32 stores the pointer value. The buffer pointed to by a FLD_PTR field must be allocated using the tpalloc(3c) call. For embedded FML32 buffers, Fchg32 stores the entire FLD_FML32 field value, except the index.
For embedded VIEW32 buffers, Fchg32 stores a pointer to a structure of type FVIEWFLD, which contains vflags (a flags field, currently unused and set to 0), vname (a character array containing the view name), and data (a pointer to the view data stored as a C structure). The application provides the vname and data to Fchg32. The FVIEWFLD structure is as follows:
typedef struct {
TM32U vflags; /* flags - currently unused */
char vname[FVIEWNAMESIZE+1]; /* name of view */
char *data; /* pointer to view structure */
} FVIEWFLD;
The buffer must have enough room to contain the modified or added field value, or an error is returned (FNOSPACE).
For more information, refer to Fchg, Fchg32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fcmp compares the field identifiers and field values of two fielded buffers.
int
Fcmp(FBFR *fbfr1, FBFR *fbfr2)
Here fbfr1 and fbfr2 are pointers to fielded buffers.
The function returns a 0 if the buffers are identical; it returns a -1 on any of the following conditions:
fieldid of a fbfr1 field is less than the field ID of the corresponding field of fbfr2.fbfr1 field is less than the value of the corresponding field of fbfr2.fbfr1 is shorter than fbfr2.The following criteria are used to determine whether pointers and embedded buffers are equal:
Fcmp returns a 1 if the opposite of any of these conditions is true. For example, Fcmp returns 1 if the field ID of a fbfr2 field is less than the field ID of the corresponding field of fbfr1.
For more information, refer to Fcmp, Fcmp32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The Fdel function deletes the specified field occurrence.
int
Fdel(FBFR *fbfr, FLDIDfieldid, FLDOCCoc)
For example, the following code deletes the first occurrence of the field indicated by the specified field identifier:
FLDOCC occurrence;
. . .
occurrence=0;
if(Fdel(fbfr, fieldid, occurrence) < 0)
F_error("pgm_name");
If the specified field does not exist, the function returns -1 and Ferror is set to FNOTPRES.
For pointer fields, Fdel32 deletes the FLD_PTR field occurrence without changing the referenced buffer or freeing the pointer. The data buffer is treated as an opaque pointer.
For more information, refer to Fdel, Fdel32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fdelall deletes all occurrences of the specified field from the buffer.
int
Fdelall(FBFR *fbfr, FLDIDfieldid)
Consider the following example:
if(Fdelall(fbfr, fieldid) < 0)
F_error("pgm_name"); /* field not present */
If the field is not found, the function returns -1 and Ferror is set to FNOTPRES.
For pointer fields, Fdelall32 deletes the FLD_PTR field occurrence without changing the referenced buffer or freeing the pointer. The data buffer is treated as an opaque pointer.
For more information, refer to Fdelall, Fdelall32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fdelete deletes all occurrences of all fields listed in the array of field identifiers, fieldid[].
int
Fdelete(FBFR *fbfr, FLDID *fieldid)
fbfr is a pointer to a fielded buffer.fieldid is a pointer to the list of field identifiers to be deleted.The update is done directly to the fielded buffer. The array of field identifiers does not need to be in any specific order, but the last entry in the array must be field identifier 0 (BADFLDID). Consider the following example:
#include "fldtbl.h"
FBFR *dest;
FLDID fieldid[20];
. . .
fieldid[0] = A; /* field id for field A */
fieldid[1] = D; /* field id for field D */
fieldid[2] = BADFLDID; /* sentinel value */
if(Fdelete(dest, fieldid) < 0)
F_error("pgm_name");
If the destination buffer has fields A, B, C, and D, this example results in a buffer that contains only occurrences of fields B and C.
Fdelete provides a more efficient way of deleting several fields from a buffer than using several Fdelall calls.
For pointer fields, Fdelete deletes the FLD_PTR field occurrence without changing the referenced buffer or freeing the pointer. The data buffer is treated as an opaque pointer.
For more information, refer to Fdelete, Fdelete32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Ffind finds the value of the specified field occurrence in the buffer.
char *
Ffind(FBFR *fbfr, FLDIDfieldid, FLDOCCoc, FLDLEN *len)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.oc is the occurrence number.len is the length of the value found.In the previous declaration the return value to Ffind is shown as a character pointer data type (char* in C). The actual type of the pointer returned is the same as the type of the value to which it points.
The following code provides an example of how this function is used:
#include "fldtbl.h"
FBFR *fbfr;
FLDLEN len;
char* Ffind, *value;
. . .
if((value=Ffind(fbfr,ZIP,0, &len)) == NULL)
F_error("pgm_name");
If the field is found, its length is returned in len (if len is NULL, the length is not returned), and its location is returned as the value of the function. If the field is not found, NULL is returned, and Ferror is set to FNOTPRES.
Ffind is useful for gaining "read-only" access to a field. The value returned by Ffind should not be used to modify the buffer. Field values should be modified only by the Fadd or Fchg function. This function does not check for occurrences of the specified field in embedded buffers.
The value returned by Ffind is valid only so long as the buffer remains unmodified. The value is guaranteed to be aligned on a short boundary but may not be aligned on a long or double boundary, even if the field is of that type. (See the conversion functions described later in this document for aligned values.) On processors that require proper alignment of variables, referencing the value when not aligned properly causes a system error, as shown in the following example:
long *l1,l2;
FLDLEN length;
char *Ffind;
. . .
if((l1=(long *)Ffind(fbfr, ZIP, 0, &length)) == NULL)
F_error("pgm_name");
else
l2 = *l1;
This code should be re-written as follows:
if((l1==(long *)Ffind(fbfr, ZIP, 0, &length)) == NULL)
F_error("pgm_name");
else
memcpy(&l2,l1,sizeof(long));
For more information, refer to Ffind, Ffind32(3fml) in BEA Tuxedo ATMI FML Function Reference.
This function finds the last occurrence of a field in a fielded buffer and returns a pointer to the field, as well as the occurrence number and length of the field occurrence.
char *
Ffindlast(FBFR *fbfr, FLDIDfieldid, FLDOCC *oc, FLDLEN *len)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.oc is a pointer to the occurrence number of the last field occurrence found.len is a pointer to the length of the value found.In the previous declaration the return value to Ffindlast is shown as a character pointer data type (char* in C). The actual type of the pointer returned is the same as the type of the value to which it points.
Ffindlast acts like Ffind, except that you do not specify a field occurrence. Instead, both the occurrence number and the value of the last field occurrence are returned. However, if you specify NULL as the value of the occurrence when calling the function, the occurrence number is not returned. This function does not check for occurrences of the specified field in embedded buffers.
The value returned by Ffindlast is valid only as long as the buffer remains unchanged.
For more information, refer to Ffindlast, Ffindlast32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Ffindocc looks at occurrences of the specified field on the buffer and returns the occurrence number of the first field occurrence that matches the user-specified field value.
FLDOCC
Ffindocc(FBFR *fbfr,FLDIDfieldid, char *value, FLDLENlen;)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.value is a pointer to a new value. Its type is shown as char*, but when it is used, its type must be the same type as the value to be added (see Fadd).len is the length of the value if its type is FLD_CARRAY or FLD_MBSTRING.For example, the following code sets oc to the occurrence for the specified zip code:
#include "fldtbl.h"
FBFR *fbfr;
FLDOCC oc;
long zipvalue;
. . .
zipvalue = 123456;
if((oc=Ffindocc(fbfr,ZIP,&zipvalue, 0)) < 0)
F_error("pgm_name");
Regular expressions are supported for string fields. For example, the following code sets oc to the occurrence of NAME that starts with "J":
#include "fldtbl.h"
FBFR *fbfr;
FLDOCC oc;
char *name;
. . .
name = "J.*"
if ((oc = Ffindocc(fbfr, NAME, name, 1)) < 0)
F_error("pgm_name");
Note: To enable pattern matching on strings, the fourth argument to Ffindocc must be non-zero. If it is zero, a simple string compare is performed. If the field value is not found, -1 is returned.
For upward compatibility, a circumflex (^) prefix and dollar sign ($) suffix are implicitly added to the regular expression. Thus the previous example is actually interpreted as "^(J.*)$". The regular expression must match the entire string value in the field.
For more information, refer to Ffindocc, Ffindocc32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Use Fget to retrieve a field from a fielded buffer when the value is to be modified.
int
Fget(FBFR *fbfr, FLDIDfieldid, FLDOCCoc, char *loc, FLDLEN *maxlen)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.oc is the occurrence number.loc is a pointer to a buffer to copy the field value into.maxlen is a pointer to the length of the source buffer on calling the function, and a pointer to the length of the field on return.The caller provides Fget with a pointer to a private buffer, as well as the length of the buffer. If maxlen is specified as NULL, then it is assumed that the destination buffer is large enough to accommodate the field value, and its length is not returned.
Fget returns an error if the desired field is not in the buffer (FNOTPRES), or if the destination buffer is too small (FNOSPACE). For example, the following code gets the zip code, assuming it is stored as a character array or string:
FLDLEN len;
char value[100];
. . .
len=sizeof(value);
if(Fget(fbfr, ZIP, 0, value, &len) < 0)
F_error("pgm_name");
If the zip code is stored as a long, it can be retrieved by the following code:
FLDLEN len;
long value;
. . .
len = sizeof(value);
if(Fget(fbfr, ZIP, 0, value, &len) < 0)
F_error("pgm_name");
For more information, refer to Fget, Fget32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Like Fget, Fgetalloc finds and makes a copy of a buffer field, but it acquires space for the field via a call to malloc(3).
char *
Fgetalloc(FBFR *fbfr, FLDIDfieldid, FLDOCCoc, FLDLEN *extralen)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.oc is the occurrence number.extralen is a pointer to the additional length to be acquired on calling the function, and a pointer to the actual length acquired on return.In the declaration above the return value to Fgetalloc is shown as a character pointer data type (char* in C). The actual type of the pointer returned is the same as the type of the value to which it points.
On success, Fgetalloc returns a valid pointer to the copy of the properly aligned buffer field; on error it returns NULL. If malloc(3) fails, Fgetalloc returns an error and Ferror is set to FMALLOC.
The last parameter to Fgetalloc specifies an extra amount of space to be acquired if, for instance, the value obtained is to be expanded before re-insertion into the fielded buffer. On success, the length of the allocated buffer is returned in extralen. Consider the following example:
FLDLEN extralen;
FBFR *fieldbfr
char *Fgetalloc;
. . .
extralen = 0;
if (fieldbfr = (FBFR *)Fgetalloc(fbfr, ZIP, 0, &extralen) == NULL)
F_error("pgm_name");
It is the responsibility of the caller to free space acquired by Fgetalloc.
For more information, refer to Fgetalloc, Fgetalloc32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fgetlast is used to retrieve the last occurrence of a field from a fielded buffer when the value is to be modified.
int
Fgetlast(FBFR *fbfr, FLDIDfieldid, FLDOCC *oc, char *loc, FLDLEN *maxlen)
fbfr is a pointer to a fielded buffer.fieldid is a field identifier.oc is a pointer to the occurrence number of the last field occurrence.loc is a pointer to a buffer to copy the field value into.maxlen is a pointer to the length of the source buffer on calling the function, and a pointer to the length of the field on return.The caller provides Fgetlast with a pointer to a private buffer, as well as the length of the buffer. Fgetlast acts like Fget, except that you do not specify a field occurrence. Instead, both the occurrence number and the value of the last field occurrence are returned. However, if you specify NULL for occ on calling the function, the occurrence number is not returned.
For more information, refer to Fgetlast, Fgetlast32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fnext finds the next field in the buffer after the specified field occurrence.
int
Fnext(FBFR *fbfr, FLDID *fieldid, FLDOCC *oc, char *value, FLDLEN *len)
fbfr is a pointer to a fielded buffer.fieldid is a pointer to a field identifier.oc is a pointer to the occurrence number.value is a pointer of the same type as the value contained in the next field.len is a pointer to the length of *value.A fieldid of FIRSTFLDID should be specified to get the first field in a buffer; the field identifier and occurrence number of the first field occurrence are returned in the corresponding parameters. If the field is not NULL, its value is copied into the memory location addressed by the value pointer.
The len parameter is used to determine whether value has enough space allocated to contain the field value. If the amount of space is insufficient, Ferror is set to FNOSPACE. The length of the value is returned in the len parameter. If the value of the field is non-null, then the len parameter is also assumed to contain the length of the currently allocated space for value.
When the field to be retrieved is an embedded VIEW32 buffer, the value parameter points to an FVIEWFLD structure. The Fnext function populates the vname and data fields in the structure. The FVIEWFLD structure is as follows:
typedef struct {
TM32U vflags; /* flags - currently unused */
char vname[FVIEWNAMESIZE+1]; /* name of view */
char *data; /* pointer to view structure */
} FVIEWFLD;
If the field value is NULL, then the value and length parameters are not changed.
If no more fields are found, Fnext returns 0 (end of buffer) and fieldid, occurrence, and value are left unchanged.
If the value parameter is not NULL, the length parameter is also assumed to be non-NULL.
The following example reads all field occurrences in the buffer:
FLDID fieldid;
FLDOCC occurrence;
char *value[100];
FLDLEN len;
. . .
for(fieldid=FIRSTFLDID,len=sizeof(value);
Fnext(fbfr,&fieldid,&occurrence,value,&len) > 0;
len=sizeof(value)) {
/* code for each field occurrence */
}
For more information, refer to Fnext, Fnext32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fnum returns the number of fields contained in the specified buffer, or -1 on error.
FLDOCC
Fnum(FBFR *fbfr)
Here fbfr is a pointer to a fielded buffer. The following code, for example, prints the number of fields in the specified buffer:
if((cnt=Fnum(fbfr)) < 0)
F_error("pgm_name");
else
fprintf(stdout,"%d fields in buffer\n",cnt);
Each FLD_FML32 and FLD_VIEW32 field is counted as a single field, regardless of the number of fields it contains.
For more information, refer to Fnum, Fnum32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Foccur returns the number of occurrences for the specified field in the buffer:
FLDOCC
Foccur(FBFR *fbfr, FLDIDfieldid)
Occurrences of a field within an embedded FML32 buffer are not counted.
Zero is returned if the field does not occur in the buffer and -1 is returned on error. For example, the following code prints the number of occurrences of the field ZIP in the specified buffer:
FLDOCC cnt;
. . .
if((cnt=Foccur(fbfr,ZIP)) < 0)
F_error("pgm_name");
else
fprintf(stdout,"Field ZIP occurs %d times in buffer\n",cnt);
For more information, refer to Foccur, Foccur32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fpres returns true (1) if the specified field occurrence exists. Otherwise, it returns false (0).
int
Fpres(FBFR *fbfr, FLDIDfieldid, FLDOCCoc)
For example, the following code returns true if the field ZIP exists in the fielded buffer referenced by fbfr:
Fpres(fbfr,ZIP,0)
Fpres does not check for occurrences of the specified field within an embedded buffer.
For more information, refer to Fpres, Fpres32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fvals works like Ffind for string values but guarantees that a pointer to a value is returned. Fvall works like Ffind for long and short values, but returns the actual value of the field as a long, instead of as a pointer to the value.
char*Fvals(FBFR *fbfr,FLDIDfieldid,FLDOCCoc)
char*Fvall(FBFR *fbfr,FLDIDfieldid,FLDOCCoc)
For Fvals, if the specified field occurrence is not found, the NULL string, \0, is returned. This function is useful for passing the value of a field to another function without checking the return value. This function is valid only for fields of type string; the NULL string is automatically returned for other field types (that is, no conversion is done).
For Fvall, if the specified field occurrence is not found, then 0 is returned. This function is useful for passing the value of a field to another function without checking the return value. This function is valid only for fields of type long and short; 0 is automatically returned for other field types (that is, no conversion is done).
For more information, refer to Fvals, Fvals32(3fml) and Fvall, Fvall32(3fml) in BEA Tuxedo ATMI FML Function Reference.
The functions listed in this section access and update entire fielded buffers, rather than individual fields in the buffers. These functions use, at most, three parameters:
dest is a pointer to a destination fielded buffer.src is a pointer to a source fielded buffer.fieldid is a field identifier or an array of field identifiers.Fconcat adds fields from the source buffer to the fields that already exist in the destination buffer.
int
Fconcat(FBFR *dest, FBFR *src)
Occurrences in the destination buffer are maintained (that is, they are retained and not modified) and new occurrences from the source buffer are added with greater occurrence numbers than any existing occurrences for each field. The fields are maintained in field identifier order.
Consider the following example:
FBFR *src, *dest;
. . .
if(Fconcat(dest,src) < 0)
F_error("pgm_name");
If dest has fields A, B, and two occurrences of C, and src has fields A, C, and D, the resulting dest has two occurrences of field A (destination field A and source field A), field B, three occurrences of field C (two from dest and the third from src), and field D.
This operation fails if there is not enough space for the new fields (FNOSPACE); in this case, the destination buffer remains unchanged.
For more information, refer to Fconcat, Fconcat32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fjoin is used to join two fielded buffers based on matching field ID/occurrence.
int
Fjoin(FBFR *dest, FBFR *src)
For fields that match on field ID/occurrence, the field value is updated in the destination buffer with the value from the source buffer. Fields in the destination buffer that have no corresponding field ID/occurrence in the source buffer are deleted. Fields in the source buffer that have no corresponding field ID/occurrence in the destination buffer are not added to the destination buffer. Thus
if(Fjoin(dest,src) < 0)
F_error("pgm_name");
Using the input buffers in the previous example results in a destination buffer that has source field value A and source field value C. This function may fail due to lack of space if the new values are larger than the old (FNOSPACE); in this case, the destination buffer will have been modified. However, if this happens, the destination buffer may be reallocated using Frealloc and the Fjoin function repeated (even if the destination buffer has been partially updated, repeating the function gives the correct results).
If joining buffers results in the removal of a pointer field (FLD_PTR), the memory area referenced by the pointer is not modified or freed.
For more information, refer to Fjoin, Fjoin32(3fml) in BEA Tuxedo ATMI FML Function Reference.
Fojoin is similar to Fjoin, but it does not delete fields from the destination buffer that have no corresponding field ID/occurrence in the source buffer.
int
Fojoin(FBFR *dest, FBFR *src)
Note that fields in the source buffer for which there are no corresponding field ID/occurrence pairs in the destination buffer are not added to the destination buffer. Consider the following example: