comparison model/defaults.c @ 0:5242703e91d3 tip

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