lantiq: switch to kernel 6.1
[openwrt/openwrt.git] / scripts / config / symbol.c
index 5c6f54031437a0d64b98ac6942d6892550c0b753..6ef44adc057e417063036b50a17eac094d134748 100644 (file)
@@ -1,13 +1,13 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  */
 
+#include <sys/types.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 #include <regex.h>
-#include <sys/utsname.h>
 
 #include "lkc.h"
 
@@ -15,23 +15,29 @@ struct symbol symbol_yes = {
        .name = "y",
        .curr = { "y", yes },
        .flags = SYMBOL_CONST|SYMBOL_VALID,
-}, symbol_mod = {
+};
+
+struct symbol symbol_mod = {
        .name = "m",
        .curr = { "m", mod },
        .flags = SYMBOL_CONST|SYMBOL_VALID,
-}, symbol_no = {
+};
+
+struct symbol symbol_no = {
        .name = "n",
        .curr = { "n", no },
        .flags = SYMBOL_CONST|SYMBOL_VALID,
-}, symbol_empty = {
+};
+
+static struct symbol symbol_empty = {
        .name = "",
        .curr = { "", no },
        .flags = SYMBOL_VALID,
 };
 
-struct symbol *sym_defconfig_list;
 struct symbol *modules_sym;
-tristate modules_val;
+static tristate modules_val;
+int recursive_is_error;
 
 enum symbol_type sym_get_type(struct symbol *sym)
 {
@@ -117,9 +123,9 @@ static long long sym_get_range_val(struct symbol *sym, int base)
 static void sym_validate_range(struct symbol *sym)
 {
        struct property *prop;
+       struct symbol *range_sym;
        int base;
        long long val, val2;
-       char str[64];
 
        switch (sym->type) {
        case S_INT:
@@ -135,17 +141,15 @@ static void sym_validate_range(struct symbol *sym)
        if (!prop)
                return;
        val = strtoll(sym->curr.val, NULL, base);
-       val2 = sym_get_range_val(prop->expr->left.sym, base);
+       range_sym = prop->expr->left.sym;
+       val2 = sym_get_range_val(range_sym, base);
        if (val >= val2) {
-               val2 = sym_get_range_val(prop->expr->right.sym, base);
+               range_sym = prop->expr->right.sym;
+               val2 = sym_get_range_val(range_sym, base);
                if (val <= val2)
                        return;
        }
-       if (sym->type == S_INT)
-               sprintf(str, "%lld", val2);
-       else
-               sprintf(str, "0x%llx", val2);
-       sym->curr.val = xstrdup(str);
+       sym->curr.val = range_sym->curr.val;
 }
 
 static void sym_set_changed(struct symbol *sym)
@@ -221,7 +225,7 @@ static void sym_calc_visibility(struct symbol *sym)
                sym_set_changed(sym);
        }
        tri = no;
-       if (sym->implied.expr && sym->dir_dep.tri != no)
+       if (sym->implied.expr)
                tri = expr_calc_value(sym->implied.expr);
        if (tri == mod && sym_get_type(sym) == S_BOOLEAN)
                tri = yes;
@@ -372,17 +376,17 @@ void sym_calc_value(struct symbol *sym)
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_OR(newval.tri, sym->implied.tri);
+                                       newval.tri = EXPR_AND(newval.tri,
+                                                             sym->dir_dep.tri);
                                }
                        }
                calc_newval:
-                       if (sym->dir_dep.tri < sym->rev_dep.tri) {
+                       if (sym->dir_dep.tri == no && sym->rev_dep.tri != no)
                                newval.tri = no;
-                       } else {
+                       else
                                newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
-                       }
                }
-               if (newval.tri == mod &&
-                   (sym_get_type(sym) == S_BOOLEAN || sym->implied.tri == yes))
+               if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
                        newval.tri = yes;
                break;
        case S_STRING:
@@ -446,7 +450,7 @@ void sym_clear_all_valid(void)
 
        for_all_symbols(i, sym)
                sym->flags &= ~SYMBOL_VALID;
-       sym_add_change_count(1);
+       conf_set_changed(true);
        sym_calc_value(modules_sym);
 }
 
@@ -464,8 +468,6 @@ bool sym_tristate_within_range(struct symbol *sym, tristate val)
                return false;
        if (sym->visible <= sym->rev_dep.tri)
                return false;
-       if (sym->implied.tri == yes && val == mod)
-               return false;
        if (sym_is_choice_value(sym) && sym->visible == yes)
                return val == yes;
        return val >= sym->rev_dep.tri && val <= sym->visible;
@@ -812,7 +814,7 @@ struct symbol *sym_lookup(const char *name, int flags)
        memset(symbol, 0, sizeof(*symbol));
        symbol->name = new_name;
        symbol->type = S_UNKNOWN;
-       symbol->flags |= flags;
+       symbol->flags = flags;
 
        symbol->next = symbol_hash[hash];
        symbol_hash[hash] = symbol;
@@ -847,49 +849,6 @@ struct symbol *sym_find(const char *name)
        return symbol;
 }
 
-const char *sym_escape_string_value(const char *in)
-{
-       const char *p;
-       size_t reslen;
-       char *res;
-       size_t l;
-
-       reslen = strlen(in) + strlen("\"\"") + 1;
-
-       p = in;
-       for (;;) {
-               l = strcspn(p, "\"\\");
-               p += l;
-
-               if (p[0] == '\0')
-                       break;
-
-               reslen++;
-               p++;
-       }
-
-       res = xmalloc(reslen);
-       res[0] = '\0';
-
-       strcat(res, "\"");
-
-       p = in;
-       for (;;) {
-               l = strcspn(p, "\"\\");
-               strncat(res, p, l);
-               p += l;
-
-               if (p[0] == '\0')
-                       break;
-
-               strcat(res, "\\");
-               strncat(res, p++, 1);
-       }
-
-       strcat(res, "\"");
-       return res;
-}
-
 struct sym_match {
        struct symbol   *sym;
        off_t           so, eo;
@@ -1250,10 +1209,8 @@ struct symbol *sym_check_deps(struct symbol *sym)
                sym->flags &= ~SYMBOL_CHECK;
        }
 
-#ifdef WARN_RECURSIVE_DEP
-       if (sym2 && sym2 == sym)
+       if (!recursive_is_error && sym2 && sym2 == sym)
                sym2 = NULL;
-#endif
 
        return sym2;
 }