Suppose that in a hypothetical application we need to get the
variable shape
from the application resource named shape.
The variable shape
takes only 4 different values:
triangle
, square
, pentagon
and
hexagon
. These values are represented by, say,
0, 1, 2
and 3
. We can specify these
values in the resource file, but it is more readable
if we use the names instead. The following code segement
does the trick.
#include#define TRIANGLE 0 #define SQUARE 1 #define PETAGON 2 #define HEXAGON 3 main(int argc, char **argv) { int shape; char *value_ret; EZ_InitializeXrm("Test", NULL, 0, &argc, argv, NULL, 0); ... ... /* install 4 name-value pairs */ if( EZ_InstallSymbolicInt("triangle", TRIANGLE) < 0 || EZ_InstallSymbolicInt("square", SQUARE) < 0 || EZ_InstallSymbolicInt("petagon", PETAGON)< 0 || EZ_InstallSymbolicInt("hexagon", HEXAGON)< 0 ) fprintf(stderr,"InstallSymbol Failed"); /* symbol is already in use */ ... ... shape = TRIANGLE; /* default value for shape */ /* get application resource "shape" */ if( EZ_GetApplicationResource("shape", &value_return)) { /* found the resource */ int ivalue; if(EZ_RetrieveSymbolicInt(value_ret, &ivalue) >= 0) { /* has to verify if ivalue is out of range */ if(ivalue >= TRIANGLE && ivalue <= HEXAGON) shape = ivalue; } } ... ... }
This code will set the value of shape
to 2
if the resource file contains a specification
Test.shape: pentagon