tomwalters@0
|
1 /*
|
tomwalters@0
|
2 defaults.c
|
tomwalters@0
|
3 ==========
|
tomwalters@0
|
4
|
tomwalters@0
|
5
|
tomwalters@0
|
6 override the optiuons table defaults
|
tomwalters@0
|
7
|
tomwalters@0
|
8 */
|
tomwalters@0
|
9
|
tomwalters@0
|
10 #include <string.h>
|
tomwalters@0
|
11 #include <stdio.h>
|
tomwalters@0
|
12
|
tomwalters@0
|
13 #include "options.h"
|
tomwalters@0
|
14 #include "stitch.h"
|
tomwalters@0
|
15 #include "source.h"
|
tomwalters@0
|
16 #include "model.h"
|
tomwalters@0
|
17
|
tomwalters@0
|
18 /**************************************************************************
|
tomwalters@0
|
19 * constructOptions( which )
|
tomwalters@0
|
20 * Return an options table, (an array of Option structs).
|
tomwalters@0
|
21 * This table is used by getopts(), helpopts(), readopts(), and writeopts().
|
tomwalters@0
|
22 * (These are all called from gen.c, and defined in options.c).
|
tomwalters@0
|
23 *
|
tomwalters@0
|
24 * The display options particular to the current application (given by "which")
|
tomwalters@0
|
25 * are listed at the end of the table.
|
tomwalters@0
|
26 * The rest of the options table is ordered with the
|
tomwalters@0
|
27 * earliest options at the end of the table. The earliest options are those
|
tomwalters@0
|
28 * corresponding to the earliest processing stages (at the bottom of the stage
|
tomwalters@0
|
29 * table). Note that the options table is printed in reverse order by the
|
tomwalters@0
|
30 * help-handler routine in options.c, so that the earliest options appear at
|
tomwalters@0
|
31 * the top of the help menu.
|
tomwalters@0
|
32 * The option defaults (as defined in displayopts and in table.c), are over-
|
tomwalters@0
|
33 * written by application defaults, so that each application can have specific
|
tomwalters@0
|
34 * defaults. The tables of option defaults for each application are defined
|
tomwalters@0
|
35 * in gen.c, and each is referenced by the entry in the defaults field of the
|
tomwalters@0
|
36 * stage struct for the application, (in model.c:FindStage()).
|
tomwalters@0
|
37 **************************************************************************/
|
tomwalters@0
|
38
|
tomwalters@0
|
39 /* override option defaults with specific defaults for this application */
|
tomwalters@0
|
40
|
tomwalters@0
|
41 Option *constructOptions( which, applicationTable )
|
tomwalters@0
|
42 char *which;
|
tomwalters@0
|
43 Option *applicationTable ;
|
tomwalters@0
|
44 {
|
tomwalters@0
|
45 struct _stage *sptr, *stage=FindStage( which ) ;
|
tomwalters@0
|
46 Option *optr, *options;
|
tomwalters@0
|
47 char **cptr, *vptr;
|
tomwalters@0
|
48 int i, j, n=0;
|
tomwalters@0
|
49
|
tomwalters@0
|
50 /* count the stage options and find the bottom of the stage table */
|
tomwalters@0
|
51 for (sptr=stage ; sptr->ident != (char *)0 ; sptr++)
|
tomwalters@0
|
52 if ((optr=sptr->options) != (Option *) 0)
|
tomwalters@0
|
53 for (i=0 ; optr[i].name != (char *)0 ; i++, n++)
|
tomwalters@0
|
54 ;
|
tomwalters@0
|
55
|
tomwalters@0
|
56 /* add in the count of the display options for this application */
|
tomwalters@0
|
57 for (i=0 ; applicationTable[i].name != (char *)0 ; i++, n++)
|
tomwalters@0
|
58 ;
|
tomwalters@0
|
59
|
tomwalters@0
|
60 /* allocate and null-terminate space for the complete options table */
|
tomwalters@0
|
61 options = NewArray(Option, n+1, "option_list");
|
tomwalters@0
|
62 options[n--].name = (char *)0;
|
tomwalters@0
|
63
|
tomwalters@0
|
64 /* copy the display options table into the options table */
|
tomwalters@0
|
65 for (i=0 ; applicationTable[i].name != (char *)0 ; i++, --n)
|
tomwalters@0
|
66 CopyArray( &applicationTable[i], &options[n], 1 );
|
tomwalters@0
|
67
|
tomwalters@0
|
68 /* copy stage options into options table from bottom up */
|
tomwalters@0
|
69 for (--sptr ; sptr>=stage ; --sptr)
|
tomwalters@0
|
70 if ((optr=sptr->options) != (Option *) 0)
|
tomwalters@0
|
71 for (i=0 ; optr[i].name != (char *)0 ; i++, --n) {
|
tomwalters@0
|
72 CopyArray( &optr[i], &options[n], 1 );
|
tomwalters@0
|
73 }
|
tomwalters@0
|
74
|
tomwalters@0
|
75 if( (cptr = stage->defaults) != (char **) 0 ) {
|
tomwalters@0
|
76
|
tomwalters@0
|
77 for (i=0 ; cptr[i] != (char *) 0 ; i++) {
|
tomwalters@0
|
78 /* split string at '=', so cptr[i] is name and vptr is value */
|
tomwalters@0
|
79 for (vptr=cptr[i] ; *vptr != '=' ; vptr++)
|
tomwalters@0
|
80 ;
|
tomwalters@0
|
81 vptr++ ;
|
tomwalters@0
|
82 /* find name in options table, and substitute default value */
|
tomwalters@0
|
83 for ( j=n+1 ; options[j].name != (char *) 0 ; j++)
|
tomwalters@0
|
84 if (strncmp(options[j].name, cptr[i], vptr-1-cptr[i]) == 0) {
|
tomwalters@0
|
85 options[j].defaultValue = vptr ;
|
tomwalters@0
|
86 break;
|
tomwalters@0
|
87 }
|
tomwalters@0
|
88 /*
|
tomwalters@0
|
89 if( options[j].name == (char *) 0 ) stitch_error( "problem with %s", cptr[i] ) ;
|
tomwalters@0
|
90 */
|
tomwalters@0
|
91 }
|
tomwalters@0
|
92 }
|
tomwalters@0
|
93
|
tomwalters@0
|
94 return ( options ) ;
|
tomwalters@0
|
95 }
|
tomwalters@0
|
96
|