patch-1.3.39 linux/scripts/tkcond.c

Next file: linux/scripts/tkgen.c
Previous file: linux/scripts/tail.tk
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.38/linux/scripts/tkcond.c linux/scripts/tkcond.c
@@ -29,6 +29,7 @@
  * If the input condition contains '(' or ')' it would screw us up, but for now
  * this is not a problem.
  */
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "tkparse.h"
@@ -52,7 +53,15 @@
 	  cnd->op = op_or;
 	  break;
 	case op_or:
-	  cnd->op = op_and;
+	  /*
+	   * This is not turned into op_and - we need to keep track
+	   * of what operators were used here since we have an optimization
+	   * later on to remove duplicate conditions, and having
+	   * inverted ors in there would make it harder if we did not
+	   * distinguish an inverted or from an and we inserted because
+	   * of nested ifs.
+	   */
+	  cnd->op = op_and1;
 	  break;
 	case op_neq:
 	  cnd->op = op_eq;
@@ -82,6 +91,54 @@
 }
 
 /*
+ * Walk all of the conditions, and look for choice values.  Convert
+ * the tokens into something more digestable.
+ */
+void fix_choice_cond()
+{
+  struct condition * cond;
+  struct condition * cond2;
+  struct kconfig * cfg;
+  char tmpbuf[10];
+
+  for(cfg = config;cfg != NULL; cfg = cfg->next)
+    {
+      if( cfg->cond == NULL )
+	{
+	  continue;
+	}
+
+      for(cond = cfg->cond; cond != NULL; cond = cond->next)
+	{
+	  if( cond->op != op_kvariable )
+	    continue;
+
+	  if( cond->variable.cfg->tok != tok_choice )
+	    continue;
+
+	  /*
+	   * Look ahead for what we are comparing this to.  There should
+	   * be one operator inbetween.
+	   */
+	  cond2 = cond->next->next;
+	  sprintf(tmpbuf, "%d", cond->variable.cfg->choice_value);
+
+	  if( strcmp(cond2->variable.str, "y") == 0 )
+	    {
+	      cond->variable.cfg = cond->variable.cfg->choice_label;
+	      cond2->variable.str = strdup(tmpbuf);
+	    }
+	  else
+	    {
+	      fprintf(stderr,"Ooops\n");
+	      exit(0);
+	    }
+	}
+
+    }
+}
+
+/*
  * Walk the stack of conditions, and clone all of them with "&&" operators
  * gluing them together.  The conditions from each level of the stack
  * are wrapped in parenthesis so as to guarantee that the results
@@ -135,6 +192,7 @@
 		    {
 		      if( cfg->tok != tok_bool && cfg->tok != tok_int
 			 && cfg->tok != tok_tristate 
+			 && cfg->tok != tok_choice
 			 && cfg->tok != tok_dep_tristate)
 			{
 			  continue;
@@ -146,6 +204,10 @@
 			  break;
 			}
 		    }
+		  if( cfg == NULL )
+		    {
+		      new->variable.str = strdup(ocond->variable.str);
+		    }
 		}
 	      else
 		{
@@ -288,11 +350,13 @@
 	  cfg->tok = tok_nop;
 	  break;
 	case tok_comment:
+	case tok_define:
 	case tok_menuoption:
 	case tok_bool:
 	case tok_tristate:
 	case tok_dep_tristate:
 	case tok_int:
+	case tok_choice:
 	  /*
 	   * We need to duplicate the chain of conditions and attach them to
 	   * this token.
@@ -303,6 +367,12 @@
 	  break;
 	}
     }
+
+  /*
+   * Fix any conditions involving the "choice" operator.
+   */
+  fix_choice_cond();
+
   /*
    * Walk through and see if there are multiple options that control the
    * same kvariable.  If there are we need to treat them a little bit
@@ -320,6 +390,7 @@
 	    {
 	      switch(cfg1->tok)
 		{
+		case tok_define:
 		case tok_bool:
 		case tok_tristate:
 		case tok_dep_tristate:

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this