[package] util-linux: prevent packaging libtool placeholder scripts (#11224)
[openwrt.git] / scripts / config / expr.c
index 30e4f9d..98c7ddb 100644 (file)
@@ -145,7 +145,8 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
                return;
        }
        if (e1->type == E_SYMBOL && e2->type == E_SYMBOL &&
-           e1->left.sym == e2->left.sym && (e1->left.sym->flags & (SYMBOL_YES|SYMBOL_NO)))
+           e1->left.sym == e2->left.sym &&
+           (e1->left.sym == &symbol_yes || e1->left.sym == &symbol_no))
                return;
        if (!expr_eq(e1, e2))
                return;
@@ -347,7 +348,7 @@ struct expr *expr_trans_bool(struct expr *e)
 /*
  * e1 || e2 -> ?
  */
-struct expr *expr_join_or(struct expr *e1, struct expr *e2)
+static struct expr *expr_join_or(struct expr *e1, struct expr *e2)
 {
        struct expr *tmp;
        struct symbol *sym1, *sym2;
@@ -411,7 +412,7 @@ struct expr *expr_join_or(struct expr *e1, struct expr *e2)
        return NULL;
 }
 
-struct expr *expr_join_and(struct expr *e1, struct expr *e2)
+static struct expr *expr_join_and(struct expr *e1, struct expr *e2)
 {
        struct expr *tmp;
        struct symbol *sym1, *sym2;
@@ -1012,73 +1013,79 @@ int expr_compare_type(enum expr_type t1, enum expr_type t2)
 #endif
 }
 
-void expr_print(struct expr *e, void (*fn)(void *, const char *), void *data, int prevtoken)
+void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
 {
        if (!e) {
-               fn(data, "y");
+               fn(data, NULL, "y");
                return;
        }
 
        if (expr_compare_type(prevtoken, e->type) > 0)
-               fn(data, "(");
+               fn(data, NULL, "(");
        switch (e->type) {
        case E_SYMBOL:
                if (e->left.sym->name)
-                       fn(data, e->left.sym->name);
+                       fn(data, e->left.sym, e->left.sym->name);
                else
-                       fn(data, "<choice>");
+                       fn(data, NULL, "<choice>");
                break;
        case E_NOT:
-               fn(data, "!");
+               fn(data, NULL, "!");
                expr_print(e->left.expr, fn, data, E_NOT);
                break;
        case E_EQUAL:
-               fn(data, e->left.sym->name);
-               fn(data, "=");
-               fn(data, e->right.sym->name);
+               if (e->left.sym->name)
+                       fn(data, e->left.sym, e->left.sym->name);
+               else
+                       fn(data, NULL, "<choice>");
+               fn(data, NULL, "=");
+               fn(data, e->right.sym, e->right.sym->name);
                break;
        case E_UNEQUAL:
-               fn(data, e->left.sym->name);
-               fn(data, "!=");
-               fn(data, e->right.sym->name);
+               if (e->left.sym->name)
+                       fn(data, e->left.sym, e->left.sym->name);
+               else
+                       fn(data, NULL, "<choice>");
+               fn(data, NULL, "!=");
+               fn(data, e->right.sym, e->right.sym->name);
                break;
        case E_OR:
                expr_print(e->left.expr, fn, data, E_OR);
-               fn(data, " || ");
+               fn(data, NULL, " || ");
                expr_print(e->right.expr, fn, data, E_OR);
                break;
        case E_AND:
                expr_print(e->left.expr, fn, data, E_AND);
-               fn(data, " && ");
+               fn(data, NULL, " && ");
                expr_print(e->right.expr, fn, data, E_AND);
                break;
        case E_CHOICE:
-               fn(data, e->right.sym->name);
+               fn(data, e->right.sym, e->right.sym->name);
                if (e->left.expr) {
-                       fn(data, " ^ ");
+                       fn(data, NULL, " ^ ");
                        expr_print(e->left.expr, fn, data, E_CHOICE);
                }
                break;
        case E_RANGE:
-               fn(data, "[");
-               fn(data, e->left.sym->name);
-               fn(data, " ");
-               fn(data, e->right.sym->name);
-               fn(data, "]");
+               fn(data, NULL, "[");
+               fn(data, e->left.sym, e->left.sym->name);
+               fn(data, NULL, " ");
+               fn(data, e->right.sym, e->right.sym->name);
+               fn(data, NULL, "]");
                break;
        default:
          {
                char buf[32];
                sprintf(buf, "<unknown type %d>", e->type);
-               fn(data, buf);
+               fn(data, NULL, buf);
                break;
          }
        }
        if (expr_compare_type(prevtoken, e->type) > 0)
-               fn(data, ")");
+               fn(data, NULL, ")");
 }
 
-static void expr_print_file_helper(void *data, const char *str)
+static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
 {
        fwrite(str, strlen(str), 1, data);
 }
@@ -1088,9 +1095,34 @@ void expr_fprint(struct expr *e, FILE *out)
        expr_print(e, expr_print_file_helper, out, E_NONE);
 }
 
-static void expr_print_gstr_helper(void *data, const char *str)
+static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str)
 {
-       str_append((struct gstr*)data, str);
+       struct gstr *gs = (struct gstr*)data;
+       const char *sym_str = NULL;
+
+       if (sym)
+               sym_str = sym_get_string_value(sym);
+
+       if (gs->max_width) {
+               unsigned extra_length = strlen(str);
+               const char *last_cr = strrchr(gs->s, '\n');
+               unsigned last_line_length;
+
+               if (sym_str)
+                       extra_length += 4 + strlen(sym_str);
+
+               if (!last_cr)
+                       last_cr = gs->s;
+
+               last_line_length = strlen(gs->s) - (last_cr - gs->s);
+
+               if ((last_line_length + extra_length) > gs->max_width)
+                       str_append(gs, "\\\n");
+       }
+
+       str_append(gs, str);
+       if (sym && sym->type != S_UNKNOWN)
+               str_printf(gs, " [=%s]", sym_str);
 }
 
 void expr_gstr_print(struct expr *e, struct gstr *gs)
This page took 0.033932 seconds and 4 git commands to generate.