tomwalters@0: /* tomwalters@0: defaults.c tomwalters@0: ========== tomwalters@0: tomwalters@0: tomwalters@0: override the optiuons table defaults tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #include "options.h" tomwalters@0: #include "stitch.h" tomwalters@0: #include "source.h" tomwalters@0: #include "model.h" tomwalters@0: tomwalters@0: /************************************************************************** tomwalters@0: * constructOptions( which ) tomwalters@0: * Return an options table, (an array of Option structs). tomwalters@0: * This table is used by getopts(), helpopts(), readopts(), and writeopts(). tomwalters@0: * (These are all called from gen.c, and defined in options.c). tomwalters@0: * tomwalters@0: * The display options particular to the current application (given by "which") tomwalters@0: * are listed at the end of the table. tomwalters@0: * The rest of the options table is ordered with the tomwalters@0: * earliest options at the end of the table. The earliest options are those tomwalters@0: * corresponding to the earliest processing stages (at the bottom of the stage tomwalters@0: * table). Note that the options table is printed in reverse order by the tomwalters@0: * help-handler routine in options.c, so that the earliest options appear at tomwalters@0: * the top of the help menu. tomwalters@0: * The option defaults (as defined in displayopts and in table.c), are over- tomwalters@0: * written by application defaults, so that each application can have specific tomwalters@0: * defaults. The tables of option defaults for each application are defined tomwalters@0: * in gen.c, and each is referenced by the entry in the defaults field of the tomwalters@0: * stage struct for the application, (in model.c:FindStage()). tomwalters@0: **************************************************************************/ tomwalters@0: tomwalters@0: /* override option defaults with specific defaults for this application */ tomwalters@0: tomwalters@0: Option *constructOptions( which, applicationTable ) tomwalters@0: char *which; tomwalters@0: Option *applicationTable ; tomwalters@0: { tomwalters@0: struct _stage *sptr, *stage=FindStage( which ) ; tomwalters@0: Option *optr, *options; tomwalters@0: char **cptr, *vptr; tomwalters@0: int i, j, n=0; tomwalters@0: tomwalters@0: /* count the stage options and find the bottom of the stage table */ tomwalters@0: for (sptr=stage ; sptr->ident != (char *)0 ; sptr++) tomwalters@0: if ((optr=sptr->options) != (Option *) 0) tomwalters@0: for (i=0 ; optr[i].name != (char *)0 ; i++, n++) tomwalters@0: ; tomwalters@0: tomwalters@0: /* add in the count of the display options for this application */ tomwalters@0: for (i=0 ; applicationTable[i].name != (char *)0 ; i++, n++) tomwalters@0: ; tomwalters@0: tomwalters@0: /* allocate and null-terminate space for the complete options table */ tomwalters@0: options = NewArray(Option, n+1, "option_list"); tomwalters@0: options[n--].name = (char *)0; tomwalters@0: tomwalters@0: /* copy the display options table into the options table */ tomwalters@0: for (i=0 ; applicationTable[i].name != (char *)0 ; i++, --n) tomwalters@0: CopyArray( &applicationTable[i], &options[n], 1 ); tomwalters@0: tomwalters@0: /* copy stage options into options table from bottom up */ tomwalters@0: for (--sptr ; sptr>=stage ; --sptr) tomwalters@0: if ((optr=sptr->options) != (Option *) 0) tomwalters@0: for (i=0 ; optr[i].name != (char *)0 ; i++, --n) { tomwalters@0: CopyArray( &optr[i], &options[n], 1 ); tomwalters@0: } tomwalters@0: tomwalters@0: if( (cptr = stage->defaults) != (char **) 0 ) { tomwalters@0: tomwalters@0: for (i=0 ; cptr[i] != (char *) 0 ; i++) { tomwalters@0: /* split string at '=', so cptr[i] is name and vptr is value */ tomwalters@0: for (vptr=cptr[i] ; *vptr != '=' ; vptr++) tomwalters@0: ; tomwalters@0: vptr++ ; tomwalters@0: /* find name in options table, and substitute default value */ tomwalters@0: for ( j=n+1 ; options[j].name != (char *) 0 ; j++) tomwalters@0: if (strncmp(options[j].name, cptr[i], vptr-1-cptr[i]) == 0) { tomwalters@0: options[j].defaultValue = vptr ; tomwalters@0: break; tomwalters@0: } tomwalters@0: /* tomwalters@0: if( options[j].name == (char *) 0 ) stitch_error( "problem with %s", cptr[i] ) ; tomwalters@0: */ tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: return ( options ) ; tomwalters@0: } tomwalters@0: