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