Mercurial > hg > toybox
annotate kconfig/expr.c @ 683:8d7fbb4c2205
Add vconfig.c  Creates virtual ethernet devices.
author  Kyungwan Han <asura321@gmail.com> 

date  Thu, 01 Nov 2012 09:55:29 0500 
parents  4d21d59f3206 
children 
rev  line source 

10
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1 /* 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

2 * Copyright (C) 2002 Roman Zippel <zippel@linuxm68k.org> 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

3 * Released under the terms of the GNU GPL v2.0. 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

4 */ 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

5 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

6 #include <stdio.h> 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

7 #include <stdlib.h> 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

8 #include <string.h> 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

9 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

10 #define LKC_DIRECT_LINK 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

11 #include "lkc.h" 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

12 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

13 #define DEBUG_EXPR 0 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

14 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

15 struct expr *expr_alloc_symbol(struct symbol *sym) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

16 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

17 struct expr *e = malloc(sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

18 memset(e, 0, sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

19 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

20 e>left.sym = sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

21 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

22 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

23 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

24 struct expr *expr_alloc_one(enum expr_type type, struct expr *ce) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

25 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

26 struct expr *e = malloc(sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

27 memset(e, 0, sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

28 e>type = type; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

29 e>left.expr = ce; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

30 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

31 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

32 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

33 struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

34 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

35 struct expr *e = malloc(sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

36 memset(e, 0, sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

37 e>type = type; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

38 e>left.expr = e1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

39 e>right.expr = e2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

40 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

41 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

42 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

43 struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

44 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

45 struct expr *e = malloc(sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

46 memset(e, 0, sizeof(*e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

47 e>type = type; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

48 e>left.sym = s1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

49 e>right.sym = s2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

50 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

51 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

52 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

53 struct expr *expr_alloc_and(struct expr *e1, struct expr *e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

54 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

55 if (!e1) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

56 return e2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

57 return e2 ? expr_alloc_two(E_AND, e1, e2) : e1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

58 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

59 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

60 struct expr *expr_alloc_or(struct expr *e1, struct expr *e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

61 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

62 if (!e1) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

63 return e2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

64 return e2 ? expr_alloc_two(E_OR, e1, e2) : e1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

65 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

66 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

67 struct expr *expr_copy(struct expr *org) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

68 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

69 struct expr *e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

70 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

71 if (!org) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

72 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

73 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

74 e = malloc(sizeof(*org)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

75 memcpy(e, org, sizeof(*org)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

76 switch (org>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

77 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

78 e>left = org>left; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

79 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

80 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

81 e>left.expr = expr_copy(org>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

82 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

83 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

84 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

85 e>left.sym = org>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

86 e>right.sym = org>right.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

87 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

88 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

89 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

90 case E_CHOICE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

91 e>left.expr = expr_copy(org>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

92 e>right.expr = expr_copy(org>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

93 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

94 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

95 printf("can't copy type %d\n", e>type); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

96 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

97 e = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

98 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

99 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

100 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

101 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

102 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

103 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

104 void expr_free(struct expr *e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

105 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

106 if (!e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

107 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

108 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

109 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

110 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

111 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

112 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

113 expr_free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

114 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

115 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

116 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

117 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

118 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

119 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

120 expr_free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

121 expr_free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

122 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

123 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

124 printf("how to free type %d?\n", e>type); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

125 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

126 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

127 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

128 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

129 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

130 static int trans_count; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

131 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

132 #define e1 (*ep1) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

133 #define e2 (*ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

134 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

135 static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

136 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

137 if (e1>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

138 __expr_eliminate_eq(type, &e1>left.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

139 __expr_eliminate_eq(type, &e1>right.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

140 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

141 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

142 if (e2>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

143 __expr_eliminate_eq(type, &e1, &e2>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

144 __expr_eliminate_eq(type, &e1, &e2>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

145 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

146 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

147 if (e1>type == E_SYMBOL && e2>type == E_SYMBOL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

148 e1>left.sym == e2>left.sym && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

149 (e1>left.sym == &symbol_yes  e1>left.sym == &symbol_no)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

150 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

151 if (!expr_eq(e1, e2)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

152 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

153 trans_count++; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

154 expr_free(e1); expr_free(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

155 switch (type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

156 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

157 e1 = expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

158 e2 = expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

159 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

160 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

161 e1 = expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

162 e2 = expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

163 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

164 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

165 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

166 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

167 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

168 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

169 void expr_eliminate_eq(struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

170 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

171 if (!e1  !e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

172 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

173 switch (e1>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

174 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

175 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

176 __expr_eliminate_eq(e1>type, ep1, ep2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

177 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

178 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

179 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

180 if (e1>type != e2>type) switch (e2>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

181 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

182 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

183 __expr_eliminate_eq(e2>type, ep1, ep2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

184 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

185 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

186 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

187 e1 = expr_eliminate_yn(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

188 e2 = expr_eliminate_yn(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

189 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

190 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

191 #undef e1 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

192 #undef e2 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

193 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

194 int expr_eq(struct expr *e1, struct expr *e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

195 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

196 int res, old_count; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

197 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

198 if (e1>type != e2>type) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

199 return 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

200 switch (e1>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

201 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

202 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

203 return e1>left.sym == e2>left.sym && e1>right.sym == e2>right.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

204 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

205 return e1>left.sym == e2>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

206 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

207 return expr_eq(e1>left.expr, e2>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

208 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

209 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

210 e1 = expr_copy(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

211 e2 = expr_copy(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

212 old_count = trans_count; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

213 expr_eliminate_eq(&e1, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

214 res = (e1>type == E_SYMBOL && e2>type == E_SYMBOL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

215 e1>left.sym == e2>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

216 expr_free(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

217 expr_free(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

218 trans_count = old_count; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

219 return res; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

220 case E_CHOICE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

221 case E_RANGE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

222 case E_NONE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

223 /* panic */; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

224 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

225 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

226 if (DEBUG_EXPR) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

227 expr_fprint(e1, stdout); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

228 printf(" = "); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

229 expr_fprint(e2, stdout); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

230 printf(" ?\n"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

231 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

232 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

233 return 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

234 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

235 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

236 struct expr *expr_eliminate_yn(struct expr *e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

237 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

238 struct expr *tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

239 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

240 if (e) switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

241 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

242 e>left.expr = expr_eliminate_yn(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

243 e>right.expr = expr_eliminate_yn(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

244 if (e>left.expr>type == E_SYMBOL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

245 if (e>left.expr>left.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

246 expr_free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

247 expr_free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

248 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

249 e>left.sym = &symbol_no; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

250 e>right.expr = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

251 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

252 } else if (e>left.expr>left.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

253 free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

254 tmp = e>right.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

255 *e = *(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

256 free(tmp); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

257 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

258 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

259 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

260 if (e>right.expr>type == E_SYMBOL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

261 if (e>right.expr>left.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

262 expr_free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

263 expr_free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

264 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

265 e>left.sym = &symbol_no; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

266 e>right.expr = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

267 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

268 } else if (e>right.expr>left.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

269 free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

270 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

271 *e = *(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

272 free(tmp); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

273 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

274 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

275 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

276 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

277 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

278 e>left.expr = expr_eliminate_yn(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

279 e>right.expr = expr_eliminate_yn(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

280 if (e>left.expr>type == E_SYMBOL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

281 if (e>left.expr>left.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

282 free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

283 tmp = e>right.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

284 *e = *(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

285 free(tmp); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

286 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

287 } else if (e>left.expr>left.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

288 expr_free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

289 expr_free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

290 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

291 e>left.sym = &symbol_yes; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

292 e>right.expr = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

293 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

294 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

295 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

296 if (e>right.expr>type == E_SYMBOL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

297 if (e>right.expr>left.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

298 free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

299 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

300 *e = *(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

301 free(tmp); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

302 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

303 } else if (e>right.expr>left.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

304 expr_free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

305 expr_free(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

306 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

307 e>left.sym = &symbol_yes; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

308 e>right.expr = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

309 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

310 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

311 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

312 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

313 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

314 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

315 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

316 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

317 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

318 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

319 /* 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

320 * bool FOO!=n => FOO 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

321 */ 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

322 struct expr *expr_trans_bool(struct expr *e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

323 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

324 if (!e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

325 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

326 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

327 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

328 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

329 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

330 e>left.expr = expr_trans_bool(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

331 e>right.expr = expr_trans_bool(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

332 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

333 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

334 // FOO!=n > FOO 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

335 if (e>left.sym>type == S_TRISTATE) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

336 if (e>right.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

337 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

338 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

339 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

340 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

341 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

342 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

343 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

344 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

345 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

346 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

347 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

348 /* 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

349 * e1  e2 > ? 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

350 */ 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

351 struct expr *expr_join_or(struct expr *e1, struct expr *e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

352 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

353 struct expr *tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

354 struct symbol *sym1, *sym2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

355 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

356 if (expr_eq(e1, e2)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

357 return expr_copy(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

358 if (e1>type != E_EQUAL && e1>type != E_UNEQUAL && e1>type != E_SYMBOL && e1>type != E_NOT) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

359 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

360 if (e2>type != E_EQUAL && e2>type != E_UNEQUAL && e2>type != E_SYMBOL && e2>type != E_NOT) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

361 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

362 if (e1>type == E_NOT) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

363 tmp = e1>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

364 if (tmp>type != E_EQUAL && tmp>type != E_UNEQUAL && tmp>type != E_SYMBOL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

365 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

366 sym1 = tmp>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

367 } else 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

368 sym1 = e1>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

369 if (e2>type == E_NOT) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

370 if (e2>left.expr>type != E_SYMBOL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

371 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

372 sym2 = e2>left.expr>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

373 } else 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

374 sym2 = e2>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

375 if (sym1 != sym2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

376 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

377 if (sym1>type != S_BOOLEAN && sym1>type != S_TRISTATE) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

378 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

379 if (sym1>type == S_TRISTATE) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

380 if (e1>type == E_EQUAL && e2>type == E_EQUAL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

381 ((e1>right.sym == &symbol_yes && e2>right.sym == &symbol_mod)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

382 (e1>right.sym == &symbol_mod && e2>right.sym == &symbol_yes))) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

383 // (a='y')  (a='m') > (a!='n') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

384 return expr_alloc_comp(E_UNEQUAL, sym1, &symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

385 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

386 if (e1>type == E_EQUAL && e2>type == E_EQUAL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

387 ((e1>right.sym == &symbol_yes && e2>right.sym == &symbol_no)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

388 (e1>right.sym == &symbol_no && e2>right.sym == &symbol_yes))) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

389 // (a='y')  (a='n') > (a!='m') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

390 return expr_alloc_comp(E_UNEQUAL, sym1, &symbol_mod); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

391 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

392 if (e1>type == E_EQUAL && e2>type == E_EQUAL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

393 ((e1>right.sym == &symbol_mod && e2>right.sym == &symbol_no)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

394 (e1>right.sym == &symbol_no && e2>right.sym == &symbol_mod))) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

395 // (a='m')  (a='n') > (a!='y') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

396 return expr_alloc_comp(E_UNEQUAL, sym1, &symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

397 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

398 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

399 if (sym1>type == S_BOOLEAN && sym1 == sym2) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

400 if ((e1>type == E_NOT && e1>left.expr>type == E_SYMBOL && e2>type == E_SYMBOL)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

401 (e2>type == E_NOT && e2>left.expr>type == E_SYMBOL && e1>type == E_SYMBOL)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

402 return expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

403 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

404 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

405 if (DEBUG_EXPR) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

406 printf("optimize ("); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

407 expr_fprint(e1, stdout); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

408 printf(")  ("); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

409 expr_fprint(e2, stdout); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

410 printf(")?\n"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

411 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

412 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

413 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

414 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

415 struct expr *expr_join_and(struct expr *e1, struct expr *e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

416 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

417 struct expr *tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

418 struct symbol *sym1, *sym2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

419 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

420 if (expr_eq(e1, e2)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

421 return expr_copy(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

422 if (e1>type != E_EQUAL && e1>type != E_UNEQUAL && e1>type != E_SYMBOL && e1>type != E_NOT) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

423 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

424 if (e2>type != E_EQUAL && e2>type != E_UNEQUAL && e2>type != E_SYMBOL && e2>type != E_NOT) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

425 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

426 if (e1>type == E_NOT) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

427 tmp = e1>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

428 if (tmp>type != E_EQUAL && tmp>type != E_UNEQUAL && tmp>type != E_SYMBOL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

429 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

430 sym1 = tmp>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

431 } else 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

432 sym1 = e1>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

433 if (e2>type == E_NOT) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

434 if (e2>left.expr>type != E_SYMBOL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

435 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

436 sym2 = e2>left.expr>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

437 } else 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

438 sym2 = e2>left.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

439 if (sym1 != sym2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

440 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

441 if (sym1>type != S_BOOLEAN && sym1>type != S_TRISTATE) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

442 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

443 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

444 if ((e1>type == E_SYMBOL && e2>type == E_EQUAL && e2>right.sym == &symbol_yes)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

445 (e2>type == E_SYMBOL && e1>type == E_EQUAL && e1>right.sym == &symbol_yes)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

446 // (a) && (a='y') > (a='y') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

447 return expr_alloc_comp(E_EQUAL, sym1, &symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

448 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

449 if ((e1>type == E_SYMBOL && e2>type == E_UNEQUAL && e2>right.sym == &symbol_no)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

450 (e2>type == E_SYMBOL && e1>type == E_UNEQUAL && e1>right.sym == &symbol_no)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

451 // (a) && (a!='n') > (a) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

452 return expr_alloc_symbol(sym1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

453 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

454 if ((e1>type == E_SYMBOL && e2>type == E_UNEQUAL && e2>right.sym == &symbol_mod)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

455 (e2>type == E_SYMBOL && e1>type == E_UNEQUAL && e1>right.sym == &symbol_mod)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

456 // (a) && (a!='m') > (a='y') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

457 return expr_alloc_comp(E_EQUAL, sym1, &symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

458 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

459 if (sym1>type == S_TRISTATE) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

460 if (e1>type == E_EQUAL && e2>type == E_UNEQUAL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

461 // (a='b') && (a!='c') > 'b'='c' ? 'n' : a='b' 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

462 sym2 = e1>right.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

463 if ((e2>right.sym>flags & SYMBOL_CONST) && (sym2>flags & SYMBOL_CONST)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

464 return sym2 != e2>right.sym ? expr_alloc_comp(E_EQUAL, sym1, sym2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

465 : expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

466 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

467 if (e1>type == E_UNEQUAL && e2>type == E_EQUAL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

468 // (a='b') && (a!='c') > 'b'='c' ? 'n' : a='b' 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

469 sym2 = e2>right.sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

470 if ((e1>right.sym>flags & SYMBOL_CONST) && (sym2>flags & SYMBOL_CONST)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

471 return sym2 != e1>right.sym ? expr_alloc_comp(E_EQUAL, sym1, sym2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

472 : expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

473 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

474 if (e1>type == E_UNEQUAL && e2>type == E_UNEQUAL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

475 ((e1>right.sym == &symbol_yes && e2>right.sym == &symbol_no)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

476 (e1>right.sym == &symbol_no && e2>right.sym == &symbol_yes))) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

477 // (a!='y') && (a!='n') > (a='m') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

478 return expr_alloc_comp(E_EQUAL, sym1, &symbol_mod); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

479 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

480 if (e1>type == E_UNEQUAL && e2>type == E_UNEQUAL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

481 ((e1>right.sym == &symbol_yes && e2>right.sym == &symbol_mod)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

482 (e1>right.sym == &symbol_mod && e2>right.sym == &symbol_yes))) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

483 // (a!='y') && (a!='m') > (a='n') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

484 return expr_alloc_comp(E_EQUAL, sym1, &symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

485 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

486 if (e1>type == E_UNEQUAL && e2>type == E_UNEQUAL && 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

487 ((e1>right.sym == &symbol_mod && e2>right.sym == &symbol_no)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

488 (e1>right.sym == &symbol_no && e2>right.sym == &symbol_mod))) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

489 // (a!='m') && (a!='n') > (a='m') 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

490 return expr_alloc_comp(E_EQUAL, sym1, &symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

491 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

492 if ((e1>type == E_SYMBOL && e2>type == E_EQUAL && e2>right.sym == &symbol_mod)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

493 (e2>type == E_SYMBOL && e1>type == E_EQUAL && e1>right.sym == &symbol_mod)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

494 (e1>type == E_SYMBOL && e2>type == E_UNEQUAL && e2>right.sym == &symbol_yes)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

495 (e2>type == E_SYMBOL && e1>type == E_UNEQUAL && e1>right.sym == &symbol_yes)) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

496 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

497 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

498 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

499 if (DEBUG_EXPR) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

500 printf("optimize ("); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

501 expr_fprint(e1, stdout); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

502 printf(") && ("); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

503 expr_fprint(e2, stdout); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

504 printf(")?\n"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

505 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

506 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

507 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

508 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

509 static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

510 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

511 #define e1 (*ep1) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

512 #define e2 (*ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

513 struct expr *tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

514 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

515 if (e1>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

516 expr_eliminate_dups1(type, &e1>left.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

517 expr_eliminate_dups1(type, &e1>right.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

518 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

519 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

520 if (e2>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

521 expr_eliminate_dups1(type, &e1, &e2>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

522 expr_eliminate_dups1(type, &e1, &e2>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

523 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

524 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

525 if (e1 == e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

526 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

527 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

528 switch (e1>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

529 case E_OR: case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

530 expr_eliminate_dups1(e1>type, &e1, &e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

531 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

532 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

533 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

534 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

535 switch (type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

536 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

537 tmp = expr_join_or(e1, e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

538 if (tmp) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

539 expr_free(e1); expr_free(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

540 e1 = expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

541 e2 = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

542 trans_count++; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

543 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

544 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

545 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

546 tmp = expr_join_and(e1, e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

547 if (tmp) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

548 expr_free(e1); expr_free(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

549 e1 = expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

550 e2 = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

551 trans_count++; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

552 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

553 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

554 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

555 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

556 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

557 #undef e1 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

558 #undef e2 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

559 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

560 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

561 static void expr_eliminate_dups2(enum expr_type type, struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

562 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

563 #define e1 (*ep1) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

564 #define e2 (*ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

565 struct expr *tmp, *tmp1, *tmp2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

566 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

567 if (e1>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

568 expr_eliminate_dups2(type, &e1>left.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

569 expr_eliminate_dups2(type, &e1>right.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

570 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

571 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

572 if (e2>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

573 expr_eliminate_dups2(type, &e1, &e2>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

574 expr_eliminate_dups2(type, &e1, &e2>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

575 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

576 if (e1 == e2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

577 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

578 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

579 switch (e1>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

580 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

581 expr_eliminate_dups2(e1>type, &e1, &e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

582 // (FOO  BAR) && (!FOO && !BAR) > n 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

583 tmp1 = expr_transform(expr_alloc_one(E_NOT, expr_copy(e1))); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

584 tmp2 = expr_copy(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

585 tmp = expr_extract_eq_and(&tmp1, &tmp2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

586 if (expr_is_yes(tmp1)) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

587 expr_free(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

588 e1 = expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

589 trans_count++; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

590 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

591 expr_free(tmp2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

592 expr_free(tmp1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

593 expr_free(tmp); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

594 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

595 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

596 expr_eliminate_dups2(e1>type, &e1, &e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

597 // (FOO && BAR)  (!FOO  !BAR) > y 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

598 tmp1 = expr_transform(expr_alloc_one(E_NOT, expr_copy(e1))); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

599 tmp2 = expr_copy(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

600 tmp = expr_extract_eq_or(&tmp1, &tmp2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

601 if (expr_is_no(tmp1)) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

602 expr_free(e1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

603 e1 = expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

604 trans_count++; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

605 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

606 expr_free(tmp2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

607 expr_free(tmp1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

608 expr_free(tmp); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

609 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

610 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

611 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

612 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

613 #undef e1 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

614 #undef e2 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

615 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

616 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

617 struct expr *expr_eliminate_dups(struct expr *e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

618 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

619 int oldcount; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

620 if (!e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

621 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

622 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

623 oldcount = trans_count; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

624 while (1) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

625 trans_count = 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

626 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

627 case E_OR: case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

628 expr_eliminate_dups1(e>type, &e, &e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

629 expr_eliminate_dups2(e>type, &e, &e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

630 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

631 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

632 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

633 if (!trans_count) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

634 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

635 e = expr_eliminate_yn(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

636 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

637 trans_count = oldcount; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

638 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

639 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

640 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

641 struct expr *expr_transform(struct expr *e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

642 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

643 struct expr *tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

644 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

645 if (!e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

646 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

647 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

648 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

649 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

650 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

651 case E_CHOICE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

652 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

653 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

654 e>left.expr = expr_transform(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

655 e>right.expr = expr_transform(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

656 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

657 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

658 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

659 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

660 if (e>left.sym>type != S_BOOLEAN) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

661 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

662 if (e>right.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

663 e>type = E_NOT; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

664 e>left.expr = expr_alloc_symbol(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

665 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

666 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

667 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

668 if (e>right.sym == &symbol_mod) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

669 printf("boolean symbol %s tested for 'm'? test forced to 'n'\n", e>left.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

670 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

671 e>left.sym = &symbol_no; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

672 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

673 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

674 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

675 if (e>right.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

676 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

677 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

678 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

679 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

680 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

681 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

682 if (e>left.sym>type != S_BOOLEAN) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

683 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

684 if (e>right.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

685 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

686 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

687 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

688 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

689 if (e>right.sym == &symbol_mod) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

690 printf("boolean symbol %s tested for 'm'? test forced to 'y'\n", e>left.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

691 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

692 e>left.sym = &symbol_yes; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

693 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

694 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

695 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

696 if (e>right.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

697 e>type = E_NOT; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

698 e>left.expr = expr_alloc_symbol(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

699 e>right.sym = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

700 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

701 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

702 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

703 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

704 switch (e>left.expr>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

705 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

706 // !!a > a 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

707 tmp = e>left.expr>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

708 free(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

709 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

710 e = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

711 e = expr_transform(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

712 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

713 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

714 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

715 // !a='x' > a!='x' 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

716 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

717 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

718 e = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

719 e>type = e>type == E_EQUAL ? E_UNEQUAL : E_EQUAL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

720 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

721 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

722 // !(a  b) > !a && !b 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

723 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

724 e>type = E_AND; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

725 e>right.expr = expr_alloc_one(E_NOT, tmp>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

726 tmp>type = E_NOT; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

727 tmp>right.expr = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

728 e = expr_transform(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

729 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

730 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

731 // !(a && b) > !a  !b 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

732 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

733 e>type = E_OR; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

734 e>right.expr = expr_alloc_one(E_NOT, tmp>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

735 tmp>type = E_NOT; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

736 tmp>right.expr = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

737 e = expr_transform(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

738 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

739 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

740 if (e>left.expr>left.sym == &symbol_yes) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

741 // !'y' > 'n' 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

742 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

743 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

744 e = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

745 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

746 e>left.sym = &symbol_no; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

747 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

748 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

749 if (e>left.expr>left.sym == &symbol_mod) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

750 // !'m' > 'm' 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

751 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

752 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

753 e = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

754 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

755 e>left.sym = &symbol_mod; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

756 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

757 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

758 if (e>left.expr>left.sym == &symbol_no) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

759 // !'n' > 'y' 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

760 tmp = e>left.expr; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

761 free(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

762 e = tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

763 e>type = E_SYMBOL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

764 e>left.sym = &symbol_yes; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

765 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

766 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

767 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

768 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

769 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

770 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

771 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

772 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

773 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

774 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

775 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

776 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

777 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

778 int expr_contains_symbol(struct expr *dep, struct symbol *sym) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

779 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

780 if (!dep) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

781 return 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

782 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

783 switch (dep>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

784 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

785 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

786 return expr_contains_symbol(dep>left.expr, sym)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

787 expr_contains_symbol(dep>right.expr, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

788 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

789 return dep>left.sym == sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

790 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

791 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

792 return dep>left.sym == sym  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

793 dep>right.sym == sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

794 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

795 return expr_contains_symbol(dep>left.expr, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

796 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

797 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

798 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

799 return 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

800 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

801 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

802 bool expr_depends_symbol(struct expr *dep, struct symbol *sym) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

803 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

804 if (!dep) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

805 return false; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

806 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

807 switch (dep>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

808 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

809 return expr_depends_symbol(dep>left.expr, sym)  
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

810 expr_depends_symbol(dep>right.expr, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

811 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

812 return dep>left.sym == sym; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

813 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

814 if (dep>left.sym == sym) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

815 if (dep>right.sym == &symbol_yes  dep>right.sym == &symbol_mod) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

816 return true; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

817 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

818 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

819 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

820 if (dep>left.sym == sym) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

821 if (dep>right.sym == &symbol_no) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

822 return true; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

823 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

824 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

825 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

826 ; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

827 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

828 return false; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

829 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

830 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

831 struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

832 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

833 struct expr *tmp = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

834 expr_extract_eq(E_AND, &tmp, ep1, ep2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

835 if (tmp) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

836 *ep1 = expr_eliminate_yn(*ep1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

837 *ep2 = expr_eliminate_yn(*ep2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

838 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

839 return tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

840 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

841 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

842 struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

843 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

844 struct expr *tmp = NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

845 expr_extract_eq(E_OR, &tmp, ep1, ep2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

846 if (tmp) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

847 *ep1 = expr_eliminate_yn(*ep1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

848 *ep2 = expr_eliminate_yn(*ep2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

849 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

850 return tmp; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

851 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

852 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

853 void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

854 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

855 #define e1 (*ep1) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

856 #define e2 (*ep2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

857 if (e1>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

858 expr_extract_eq(type, ep, &e1>left.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

859 expr_extract_eq(type, ep, &e1>right.expr, &e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

860 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

861 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

862 if (e2>type == type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

863 expr_extract_eq(type, ep, ep1, &e2>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

864 expr_extract_eq(type, ep, ep1, &e2>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

865 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

866 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

867 if (expr_eq(e1, e2)) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

868 *ep = *ep ? expr_alloc_two(type, *ep, e1) : e1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

869 expr_free(e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

870 if (type == E_AND) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

871 e1 = expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

872 e2 = expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

873 } else if (type == E_OR) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

874 e1 = expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

875 e2 = expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

876 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

877 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

878 #undef e1 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

879 #undef e2 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

880 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

881 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

882 struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

883 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

884 struct expr *e1, *e2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

885 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

886 if (!e) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

887 e = expr_alloc_symbol(sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

888 if (type == E_UNEQUAL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

889 e = expr_alloc_one(E_NOT, e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

890 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

891 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

892 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

893 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

894 e1 = expr_trans_compare(e>left.expr, E_EQUAL, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

895 e2 = expr_trans_compare(e>right.expr, E_EQUAL, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

896 if (sym == &symbol_yes) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

897 e = expr_alloc_two(E_AND, e1, e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

898 if (sym == &symbol_no) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

899 e = expr_alloc_two(E_OR, e1, e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

900 if (type == E_UNEQUAL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

901 e = expr_alloc_one(E_NOT, e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

902 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

903 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

904 e1 = expr_trans_compare(e>left.expr, E_EQUAL, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

905 e2 = expr_trans_compare(e>right.expr, E_EQUAL, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

906 if (sym == &symbol_yes) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

907 e = expr_alloc_two(E_OR, e1, e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

908 if (sym == &symbol_no) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

909 e = expr_alloc_two(E_AND, e1, e2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

910 if (type == E_UNEQUAL) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

911 e = expr_alloc_one(E_NOT, e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

912 return e; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

913 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

914 return expr_trans_compare(e>left.expr, type == E_EQUAL ? E_UNEQUAL : E_EQUAL, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

915 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

916 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

917 if (type == E_EQUAL) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

918 if (sym == &symbol_yes) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

919 return expr_copy(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

920 if (sym == &symbol_mod) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

921 return expr_alloc_symbol(&symbol_no); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

922 if (sym == &symbol_no) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

923 return expr_alloc_one(E_NOT, expr_copy(e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

924 } else { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

925 if (sym == &symbol_yes) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

926 return expr_alloc_one(E_NOT, expr_copy(e)); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

927 if (sym == &symbol_mod) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

928 return expr_alloc_symbol(&symbol_yes); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

929 if (sym == &symbol_no) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

930 return expr_copy(e); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

931 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

932 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

933 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

934 return expr_alloc_comp(type, e>left.sym, sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

935 case E_CHOICE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

936 case E_RANGE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

937 case E_NONE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

938 /* panic */; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

939 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

940 return NULL; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

941 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

942 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

943 tristate expr_calc_value(struct expr *e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

944 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

945 tristate val1, val2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

946 const char *str1, *str2; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

947 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

948 if (!e) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

949 return yes; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

950 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

951 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

952 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

953 sym_calc_value(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

954 return e>left.sym>curr.tri; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

955 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

956 val1 = expr_calc_value(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

957 val2 = expr_calc_value(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

958 return E_AND(val1, val2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

959 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

960 val1 = expr_calc_value(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

961 val2 = expr_calc_value(e>right.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

962 return E_OR(val1, val2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

963 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

964 val1 = expr_calc_value(e>left.expr); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

965 return E_NOT(val1); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

966 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

967 sym_calc_value(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

968 sym_calc_value(e>right.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

969 str1 = sym_get_string_value(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

970 str2 = sym_get_string_value(e>right.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

971 return !strcmp(str1, str2) ? yes : no; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

972 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

973 sym_calc_value(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

974 sym_calc_value(e>right.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

975 str1 = sym_get_string_value(e>left.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

976 str2 = sym_get_string_value(e>right.sym); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

977 return !strcmp(str1, str2) ? no : yes; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

978 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

979 printf("expr_calc_value: %d?\n", e>type); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

980 return no; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

981 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

982 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

983 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

984 int expr_compare_type(enum expr_type t1, enum expr_type t2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

985 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

986 #if 0 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

987 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

988 #else 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

989 if (t1 == t2) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

990 return 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

991 switch (t1) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

992 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

993 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

994 if (t2 == E_NOT) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

995 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

996 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

997 if (t2 == E_AND) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

998 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

999 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1000 if (t2 == E_OR) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1001 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1002 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1003 if (t2 == E_CHOICE) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1004 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1005 case E_CHOICE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1006 if (t2 == 0) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1007 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1008 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1009 return 1; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1010 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1011 printf("[%dgt%d?]", t1, t2); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1012 return 0; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1013 #endif 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1014 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1015 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1016 void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1017 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1018 if (!e) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1019 fn(data, NULL, "y"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1020 return; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1021 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1022 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1023 if (expr_compare_type(prevtoken, e>type) > 0) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1024 fn(data, NULL, "("); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1025 switch (e>type) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1026 case E_SYMBOL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1027 if (e>left.sym>name) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1028 fn(data, e>left.sym, e>left.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1029 else 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1030 fn(data, NULL, "<choice>"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1031 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1032 case E_NOT: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1033 fn(data, NULL, "!"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1034 expr_print(e>left.expr, fn, data, E_NOT); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1035 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1036 case E_EQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1037 fn(data, e>left.sym, e>left.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1038 fn(data, NULL, "="); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1039 fn(data, e>right.sym, e>right.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1040 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1041 case E_UNEQUAL: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1042 fn(data, e>left.sym, e>left.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1043 fn(data, NULL, "!="); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1044 fn(data, e>right.sym, e>right.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1045 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1046 case E_OR: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1047 expr_print(e>left.expr, fn, data, E_OR); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1048 fn(data, NULL, "  "); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1049 expr_print(e>right.expr, fn, data, E_OR); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1050 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1051 case E_AND: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1052 expr_print(e>left.expr, fn, data, E_AND); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1053 fn(data, NULL, " && "); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1054 expr_print(e>right.expr, fn, data, E_AND); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1055 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1056 case E_CHOICE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1057 fn(data, e>right.sym, e>right.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1058 if (e>left.expr) { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1059 fn(data, NULL, " ^ "); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1060 expr_print(e>left.expr, fn, data, E_CHOICE); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1061 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1062 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1063 case E_RANGE: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1064 fn(data, NULL, "["); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1065 fn(data, e>left.sym, e>left.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1066 fn(data, NULL, " "); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1067 fn(data, e>right.sym, e>right.sym>name); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1068 fn(data, NULL, "]"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1069 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1070 default: 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1071 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1072 char buf[32]; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1073 sprintf(buf, "<unknown type %d>", e>type); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1074 fn(data, NULL, buf); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1075 break; 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1076 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1077 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1078 if (expr_compare_type(prevtoken, e>type) > 0) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1079 fn(data, NULL, ")"); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1080 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1081 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1082 static void expr_print_file_helper(void *data, struct symbol *sym, const char *str) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1083 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1084 fwrite(str, strlen(str), 1, data); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1085 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1086 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1087 void expr_fprint(struct expr *e, FILE *out) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1088 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1089 expr_print(e, expr_print_file_helper, out, E_NONE); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1090 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1091 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1092 static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1093 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1094 str_append((struct gstr*)data, str); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1095 } 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1096 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1097 void expr_gstr_print(struct expr *e, struct gstr *gs) 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1098 { 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1099 expr_print(e, expr_print_gstr_helper, gs, E_NONE); 
4d21d59f3206
Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff
changeset

1100 } 