1.1 --- a/kconfig/expr.c Fri Oct 17 12:47:53 2008 +0000
1.2 +++ b/kconfig/expr.c Sat Aug 04 23:41:25 2012 +0200
1.3 @@ -64,7 +64,7 @@
1.4 return e2 ? expr_alloc_two(E_OR, e1, e2) : e1;
1.5 }
1.6
1.7 -struct expr *expr_copy(struct expr *org)
1.8 +struct expr *expr_copy(const struct expr *org)
1.9 {
1.10 struct expr *e;
1.11
1.12 @@ -348,7 +348,7 @@
1.13 /*
1.14 * e1 || e2 -> ?
1.15 */
1.16 -struct expr *expr_join_or(struct expr *e1, struct expr *e2)
1.17 +static struct expr *expr_join_or(struct expr *e1, struct expr *e2)
1.18 {
1.19 struct expr *tmp;
1.20 struct symbol *sym1, *sym2;
1.21 @@ -412,7 +412,7 @@
1.22 return NULL;
1.23 }
1.24
1.25 -struct expr *expr_join_and(struct expr *e1, struct expr *e2)
1.26 +static struct expr *expr_join_and(struct expr *e1, struct expr *e2)
1.27 {
1.28 struct expr *tmp;
1.29 struct symbol *sym1, *sym2;
1.30 @@ -1013,6 +1013,48 @@
1.31 #endif
1.32 }
1.33
1.34 +static inline struct expr *
1.35 +expr_get_leftmost_symbol(const struct expr *e)
1.36 +{
1.37 +
1.38 + if (e == NULL)
1.39 + return NULL;
1.40 +
1.41 + while (e->type != E_SYMBOL)
1.42 + e = e->left.expr;
1.43 +
1.44 + return expr_copy(e);
1.45 +}
1.46 +
1.47 +/*
1.48 + * Given expression `e1' and `e2', returns the leaf of the longest
1.49 + * sub-expression of `e1' not containing 'e2.
1.50 + */
1.51 +struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2)
1.52 +{
1.53 + struct expr *ret;
1.54 +
1.55 + switch (e1->type) {
1.56 + case E_OR:
1.57 + return expr_alloc_and(
1.58 + expr_simplify_unmet_dep(e1->left.expr, e2),
1.59 + expr_simplify_unmet_dep(e1->right.expr, e2));
1.60 + case E_AND: {
1.61 + struct expr *e;
1.62 + e = expr_alloc_and(expr_copy(e1), expr_copy(e2));
1.63 + e = expr_eliminate_dups(e);
1.64 + ret = (!expr_eq(e, e1)) ? e1 : NULL;
1.65 + expr_free(e);
1.66 + break;
1.67 + }
1.68 + default:
1.69 + ret = e1;
1.70 + break;
1.71 + }
1.72 +
1.73 + return expr_get_leftmost_symbol(ret);
1.74 +}
1.75 +
1.76 void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
1.77 {
1.78 if (!e) {
1.79 @@ -1087,7 +1129,7 @@
1.80
1.81 static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
1.82 {
1.83 - fwrite(str, strlen(str), 1, data);
1.84 + xfwrite(str, strlen(str), 1, data);
1.85 }
1.86
1.87 void expr_fprint(struct expr *e, FILE *out)
1.88 @@ -1097,7 +1139,32 @@
1.89
1.90 static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str)
1.91 {
1.92 - str_append((struct gstr*)data, str);
1.93 + struct gstr *gs = (struct gstr*)data;
1.94 + const char *sym_str = NULL;
1.95 +
1.96 + if (sym)
1.97 + sym_str = sym_get_string_value(sym);
1.98 +
1.99 + if (gs->max_width) {
1.100 + unsigned extra_length = strlen(str);
1.101 + const char *last_cr = strrchr(gs->s, '\n');
1.102 + unsigned last_line_length;
1.103 +
1.104 + if (sym_str)
1.105 + extra_length += 4 + strlen(sym_str);
1.106 +
1.107 + if (!last_cr)
1.108 + last_cr = gs->s;
1.109 +
1.110 + last_line_length = strlen(gs->s) - (last_cr - gs->s);
1.111 +
1.112 + if ((last_line_length + extra_length) > gs->max_width)
1.113 + str_append(gs, "\\\n");
1.114 + }
1.115 +
1.116 + str_append(gs, str);
1.117 + if (sym && sym->type != S_UNKNOWN)
1.118 + str_printf(gs, " [=%s]", sym_str);
1.119 }
1.120
1.121 void expr_gstr_print(struct expr *e, struct gstr *gs)