BEA Logo BEA Tuxedo Release 7.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   Tuxedo Doc Home   |   Programming   |   Topic List   |   Previous   |   Next   |   Contents

   Programming a BEA Tuxedo Application Using FML

Converting Strings

The following set of functions is provided to handle the case of conversion to and from a user type of FLD_STRING:

These functions call their non-string-function counterparts, providing a type of FLD_STRING, and a len of 0. Note that the duration of the validity of the pointer returned by Ffinds is the same as that described for CFfind.

For descriptions of these functions, see the BEA Tuxedo FML Function Reference.

Ftypcvt

The functions CFadd, CFchg, CFget, CFgetalloc, and CFfind use the function Ftypcvt to perform the appropriate data conversion. The Ftypcvt32 function fails for the FLD_PTR, FLD_FML32, and FLD_VIEW32 field types. The synopsis of Ftypcvt usage is as follows (it does not follow the parameter order conventions).

char *
Ftypcvt(FLDLEN *tolen, int totype, char *fromval, int fromtype, FLDLEN fromlen)

Here:

Ftypcvt converts from the value *fromval, which has type fromtype, and length fromlen if fromtype is type FLD_CARRAY (otherwise fromlen is inferred from fromtype), to a value of type totype. Ftypcvt returns a pointer to the converted value, and sets *tolen to the converted length, upon success. Upon failure, Ftypcvt returns NULL. Consider the following example, in which the CFchg function is used.

CFchg(fbfr,fieldid,oc,value,len,type)
FBFR *fbfr; /* fielded buffer */
FLDID fieldid; /* field to be changed */
FLDOCC oc; /* occurrence of field to be changed */
char *value; /* location of new value */
FLDLEN len; /* length of new value */
int type; /* type of new value */
{
char *convloc; /* location of post-conversion value */
FLDLEN convlen; /* length of post-conversion value */
extern char *Ftypcvt;

/* convert value to fielded buffer type */
if((convloc = Ftypcvt(&convlen,FLDTYPE(fieldid),value,type,len)) == NULL)
return(-1);

if(Fchg(fbfr,fieldid,oc,convloc,convlen) < 0)
return(-1);
return(1);
}

The user may call Ftypcvt directly to do field value conversion without adding or modifying a fielded buffer.

For more information, refer to Ftypcvt, Ftypcvt32(3fml) in the BEA Tuxedo FML Function Reference.

Conversion Rules

In the following list of conversion rules, oldval represents a pointer to the data item being converted, and newval, a pointer to the post-conversion value.

The following table summarizes the conversion rules presented in this section.

Summary of Conversion Rules

src type

dest type

-

char

short

long

float

double

string

carray

dec_t

char

-

cast

cast

cast

cast

st[0]=c

array[0]=c

d

short

cast

-

cast

cast

cast

sprintf

sprintf

d

long

cast

cast

-

cast

cast

sprintf

sprintf

d

float

cast

cast

cast

-

cast

sprintf

sprintf

d

double

cast

cast

cast

cast

-

sprintf

sprintf

d

string

c=st[0]

atoi

atol

atof

atof

-

drop 0

d

carray

c=array[0]

atoi

atol

atof

atof

add 0

-

d

dec_t

d

d

d

d

d

d

d

-

The following table defines the entries listed in the previous table.

Meanings of Entries in the Summary of Conversion Rules

Entry

Meaning

-

src and dest are the same type; no conversion required

cast

Conversion done using C assignment with type casting

sprintf

Conversion done using sprintf function

atoi

Conversion done using atoi function

atof

Conversion done using atof function

atol

Conversion done using atol function

add 0

Conversion done by concatenating NULL byte

drop 0

Conversion done by dropping terminating NULL byte

c=array[0]

Character set to first byte of array

array[0]=c

First byte of array is set to character

c=st[0]

Character set to first byte of string

st[0]=c

First byte of string set to c

d

decimal(3c) conversion function