Re: XForms: Using app-defaults file to set default form values?

Steve Lamont (spl@szechuan.ucsd.edu)
Sat, 20 Dec 97 14:19:20 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> Is it possible to use the app-defaults file to set form values. For
> example, I would like to set the value of the input object,
> ui->input_object[index], from a resource file so that I can change it
> without recompiling.

Elaborate support for Xt type resources is lacking in XForms (mostly
because it's not Xt based).

You would have to read the app_defaults file and process it. I've
done it and it's not especially pretty.

static void set_startup_resources( void )

{

FILE *f = fopen( APP_DEFAULT_FILE, "r" );

if ( f ) {

char buffer[512];

while ( get_buffer( buffer, 512, f ) ) {

char res_name[512];
char value[512];
char *res_name_ptr;
int i;
char *b = buffer;

/*
* Get the resource name.
*/

while ( isspace( *b ) ) /* Eat leading white space */
b++;

if ( sscanf( b, "%s", res_name ) != EOF ) {

char *colon;

/*
* Get rid of the colon.
*/

b += strlen( res_name );

if ( colon = strchr( res_name, ':' ) )
*colon = '\0';
if ( strncmp( APP_CLASS_NAME,
res_name,
sizeof( APP_CLASS_NAME ) ) )
res_name_ptr = res_name + sizeof( APP_CLASS_NAME );
else {

if ( res_name[0] != '.' ) {

bcopy( res_name, res_name + 1, strlen( res_name ) );
res_name[0] = '.';

}
res_name_ptr = res_name;

}

for ( i = 0; i < N_RESOURCES; i++ )
if ( strcmp( res_name_ptr, resources[i].res_name ) == 0 ) {

if ( *b )
while ( *++b && isspace( *b ) )
;
else
b = "";

resources[i].defval = strdup( b );
break;

}

}

}
fclose( f );

}

}

The above is a pretty stoneaxe approach but it did work in some
limited sense.

You'd then feed the modified resources table to XForms in the standard
manner:

display =
fl_initialize( argc, argv,
APP_CLASS_NAME,
command_options, N_COMMAND_OPTIONS );

fl_get_app_resources( resources, N_RESOURCES );

You would then have to fish through and process the resources as
appropriate for the application.

Refer to the appendix "Resources for Forms Library" for more details.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bloch.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/