This is what a program using tags could look like.
#define ATTR_COLOR (TAG_USER|0x01L)
#define ATTR_SHAPE (TAG_USER|0x02L)
#define ATTR_LTYPE (TAG_USER|0x03L)
#deinfe ATTR_WIDTH (TAG_USER|0x04L)
#define ATTR_HEIGHT (TAG_USER|0x05L)
#define SHAPE_DOT 0
#define SHAPE_BOX 1
#define SHAPE_CIRCLE 2
char *defaultcol="#008080";
/* Varargs stub */
int TestFunc( int x, int y, ... )
{
struct TagItem *tags=&y+1;
return( TestFuncA( x, y, tags ) );
}
int TestFuncA( int x, int y, struct TagItem *tags )
{
char *color;
/* If a tag with ATTR_COLOR is found it's value is used */
/* otherwise the default value will be used */
color=(char *)GetTagData( ATTR_COLOR, defaultcol, tags );
...
DoSomeImportantStuff(TM);
...
return(...);
}
void main( void )
{
TestFunc( 40, 25,
ATTR_COLOR,"#804000",
ATTR_SHAPE, SHAPE_BOX,
ATTR_WIDTH, 19,
ATTR_HEIGHT, 25,
TAG_DONE
);
}
You see that it's great for optional values. There are ofcause a bunch more functions than GetTagData. Manual included =).
|