Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp943031pxb; Thu, 30 Sep 2021 23:00:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFNBDhIngTNCyAfwgDlGLbBT0QWMReylE5WEUP34kaLOPhoLK82DEkhpe+axPQi4wtUxIa X-Received: by 2002:a17:90a:4812:: with SMTP id a18mr17683515pjh.40.1633068034529; Thu, 30 Sep 2021 23:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633068034; cv=none; d=google.com; s=arc-20160816; b=OTAUVcf9LzD5F9vP9EYoa4VpF8F96hrQqRNoFAmBBOiTXiegPex9q9OAIlmkaxMGHj eGkWzWpqv2FMFAyTJeZM5R6sEP8MyRKApnnRM6ty+ieONl2WPfzHTK1Ui+eRhQWJrN9b 7lGpC4/3dVFXcvIlh7MpV8eoBBUyvaCa2qiRMX4FfCnG2Xvii92v6UFA4ack8qA1g4Rz QfrIRCbO3ffaSye5OWxAD50IsCRMW2lshi15en77XCmyB7jeqc/M0YXcO92UZSWAPlHm VHCDYkpPQGGZm1GnHvDv0jCFmQpm281cHcnn+uotiaRYPEch5skiy5Mqe+LhWiA2UJXj 2kMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=fQ8kuzKZhFdV66W9VpMSV4OyHXc8vSXpDVIuBoKabHQ=; b=buD93aQj7v+D9MckVfDBCXj+ErQJyYDNYeTQaa8r80XoDO469xO0zAWApSbFNZB41Y 3WbIeABawgkkDluaiW4OpCaaH303HYtN+BnSDqKCj/cAjUn5e6rOa8sAsYV2QSRL+VK3 daJseXfY1yln32zuGlKUIXGTdwjhvMLo0KJjJbvvV6ey0lgFV9MYANKn03IkQMtXuyvI b3imj55IwlzDYmiIoL0MUjq50n0bspRXG3NVACXgR5BXPr03Ju0gDYNWTUwTUWM7Rq3k 5jRXVIyNU2BonSKb+6fLhpBQFFMdNyUUQSMdZpdgmZEgOyH+7ik+ak/vYn10use+6r3m i0bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=IZDaBStG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si7107481plk.313.2021.09.30.23.00.21; Thu, 30 Sep 2021 23:00:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=IZDaBStG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352105AbhJAFfT (ORCPT + 99 others); Fri, 1 Oct 2021 01:35:19 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25305 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241541AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVV000646; Fri, 1 Oct 2021 14:33:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVV000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066380; bh=fQ8kuzKZhFdV66W9VpMSV4OyHXc8vSXpDVIuBoKabHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZDaBStGJluPWW8kX5Jx91FTyB8BWmra6pY/KBedZ6yXMBivP9Sik9EuAYBJsqRmz IdlRhP/Zz+aGPN0PDqFolignpilGmU511TrkvVm6C2NhXq14ESSGSlJ9dE1phb3BjT Gc4wdrR8/ZQqvXfXTgqo657CYGO44ZjVpBkQOeUvkfpOX0ZSJB1ACKkGDQDcRbzmI0 XO2Y85cEfwJiL4GsF7m30akxh144LP2NGIcwyWr7/OQgybJlJP4kEvsS90811KMIMK 39WJYfg8j4X+d/t6ey844dzzYtQ01/rOV06CxrzOLHYMy+aJwBz/yV9V4QPnlySWFr EMJzgiSH+YdBw== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 03/10] kconfig: refactor conf_write_symbol() Date: Fri, 1 Oct 2021 14:32:46 +0900 Message-Id: <20211001053253.1223316-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I do not think 'struct conf_printer' is so useful. Add simple functions, print_symbol_for_*() to write out one symbol. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 136 ++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 79 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index ed1bb8ba971b..ce11e7442d12 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -159,10 +160,6 @@ static int conf_touch_dep(const char *name) return 0; } -struct conf_printer { - void (*print_symbol)(FILE *, struct symbol *, const char *, void *); -}; - static void conf_warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); @@ -629,91 +626,52 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs) * This printer is used when generating the resulting configuration after * kconfig invocation and `defconfig' files. Unset symbol might be omitted by * passing a non-NULL argument to the printer. - * */ -static void -kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: - if (*value == 'n') { - bool skip_unset = (arg != NULL); - - if (!skip_unset) - fprintf(fp, "# %s%s is not set\n", - CONFIG_, sym->name); - return; - } - break; - default: - break; - } - - fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value); -} +enum output_n { OUTPUT_N, OUTPUT_N_AS_UNSET, OUTPUT_N_NONE }; -static struct conf_printer kconfig_printer_cb = +static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n, + bool escape_string) { - .print_symbol = kconfig_print_symbol, -}; + const char *val; + char *escaped = NULL; -/* - * Header printer - * - * This printer is used when generating the `include/generated/autoconf.h' file. - */ -static void -header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ + if (sym->type == S_UNKNOWN) + return; - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: { - const char *suffix = ""; + val = sym_get_string_value(sym); - switch (*value) { - case 'n': - break; - case 'm': - suffix = "_MODULE"; - /* fall through */ - default: - fprintf(fp, "#define %s%s%s 1\n", - CONFIG_, sym->name, suffix); - } - break; + if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) && + output_n != OUTPUT_N && *val == 'n') { + if (output_n == OUTPUT_N_AS_UNSET) + fprintf(fp, "# %s%s is not set\n", CONFIG_, sym->name); + return; } - case S_HEX: { - const char *prefix = ""; - if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) - prefix = "0x"; - fprintf(fp, "#define %s%s %s%s\n", - CONFIG_, sym->name, prefix, value); - break; - } - case S_STRING: - case S_INT: - fprintf(fp, "#define %s%s %s\n", - CONFIG_, sym->name, value); - break; - default: - break; + if (sym->type == S_STRING && escape_string) { + escaped = sym_escape_string_value(val); + val = escaped; } + fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, val); + + free(escaped); } -static struct conf_printer header_printer_cb = +static void print_symbol_for_dotconfig(FILE *fp, struct symbol *sym) { - .print_symbol = header_print_symbol, -}; + __print_symbol(fp, sym, OUTPUT_N_AS_UNSET, true); +} + +static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) +{ + __print_symbol(fp, sym, OUTPUT_N_NONE, true); +} -static void conf_write_symbol(FILE *fp, struct symbol *sym, - struct conf_printer *printer, void *printer_arg) +static void print_symbol_for_c(FILE *fp, struct symbol *sym) { const char *val; + const char *sym_suffix = ""; + const char *val_prefix = ""; char *escaped = NULL; if (sym->type == S_UNKNOWN) @@ -721,12 +679,32 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym, val = sym_get_string_value(sym); - if (sym->type == S_STRING) { + switch (sym->type) { + case S_BOOLEAN: + case S_TRISTATE: + switch (*val) { + case 'n': + return; + case 'm': + sym_suffix = "_MODULE"; + /* fall through */ + default: + val = "1"; + } + break; + case S_HEX: + if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) + val_prefix = "0x"; + break; + case S_STRING: escaped = sym_escape_string_value(val); val = escaped; + default: + break; } - printer->print_symbol(fp, sym, val, printer_arg); + fprintf(fp, "#define %s%s%s %s%s\n", CONFIG_, sym->name, sym_suffix, + val_prefix, val); free(escaped); } @@ -787,7 +765,7 @@ int conf_write_defconfig(const char *filename) goto next_menu; } } - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + print_symbol_for_dotconfig(out, sym); } next_menu: if (menu->list != NULL) { @@ -874,7 +852,7 @@ int conf_write(const char *name) need_newline = false; } sym->flags |= SYMBOL_WRITTEN; - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + print_symbol_for_dotconfig(out, sym); } next: @@ -1060,8 +1038,8 @@ int conf_write_autoconf(int overwrite) continue; /* write symbols to auto.conf and autoconf.h */ - conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); - conf_write_symbol(out_h, sym, &header_printer_cb, NULL); + print_symbol_for_autoconf(out, sym); + print_symbol_for_c(out_h, sym); } fclose(out); fclose(out_h); -- 2.30.2