Programming Guide |
Formats a string for an engine
#include <dmuproto.h>int dm_expand(char *engine, char *data, int type, char *buf, int buflen, char *edit);
engine
- The name of an initialized engine. If this argument is null, Panther uses the default engine.
data
- The string to format. Use Panther library functions such as sm_getfield to get the value of a field or LDB entry.
type
- A Panther data type, specified by one of the following constants defined in
smedits.h
:
FT_CHAR
FT_DOUBLE
FT_LONG
DT_CURRENCY
FT_FLOAT
FT_SHORT
DT_DATETIME
FT_INT
DT_YESNO
buf
- A buffer provided by the program. The program is responsible for allocating a buffer large enough for the formatted string.
buflen
- Points to the size of the buffer. Upon return from
dm_expand
, the value contained in the integer will be the length of the formatted text. The program can compare this value with the allocated length to ensure that truncation did not occur.edit
- A date-time edit string describing
data
. It is required when type isDT_DATETIME
.
C only
dm_expand
lets you format a string for a particular engine and Panther type. The function copies the formatted string to a buffer provided by the program.
#include <smdefs.h>
#include <smedits.h>
#include >dmuproto.h>char *
formatter (src_name, prolfxtype)
char *src_name;
int prolfxtype;
{
char src_buf[256]; /* For widget contents */
char *edit=0; /* For datetime edit */
char dst_buf[256]; int dst_len=256; /* For formatted string*/strcat (dst_buf, "");/* Get contents of non-null widget. */
if ((sm_n_null (src_name) == 0) &&
(sm_n_getfield (src_buf, src_name) > 0))
{
/* If no type was supplied, get it from the source
field.*/
if (prolfxtype == 0)
{
prolfxtype =
sm_n_ftype(src_name, (int*)0) & DT_DTYPE;
}/* If type is DT_DATETIME get format from source field. */
if (prolfxtype == DT_DATETIME)
{
edit = sm_n_edit_ptr (src_name, UDATETIME);
/* If there is no user format, check for
system format. */
if (edit == 0)
{
edit = sm_n_edit_ptr(src_name, SDATETIME);
}
edit = edit + 2;
}/* Format text for the current engine. */
dm_expand ("", src_buf, prolfxtype, dst_buf, &dst_len, edit);
}
return dst_buf;
}