From patchwork Thu Jan 11 13:05:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 124193 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp652908qgn; Thu, 11 Jan 2018 05:06:37 -0800 (PST) X-Google-Smtp-Source: ACJfBotIugJNGkPjwW1KqTXr7SeaU+w+I/2buvN6dMVGXLVHD3hBPzKUhxKqXXPpgYih32d72fui X-Received: by 10.101.80.74 with SMTP id k10mr17717707pgo.430.1515675996911; Thu, 11 Jan 2018 05:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515675996; cv=none; d=google.com; s=arc-20160816; b=z55vNLgfE6ts2c4OJmzb3Bz3JaV8iOunMk0tOq636Zqe35gnPr9MvW7sXfQ57Djm/q KysS6AoURT1a1hIuVNkSaFGJeEzKn5RudBGS9SDcH4HOXFbTmWGWA/K0e5vx3nUJ16m6 4pDKAruPybPLra+xgHzNkVslGpJGRdvfOcavSvR/l0GmDT9/Lojk46IHVk1ParLXednl zH9tsKEdkwPECvXjSV+L3467cZqHn2q430AAiShCZHrIS4g+fvRTNEKKI7sNs8ZMYUwD o0CS8onkladuRWQsjYTw7T+nXYyzWiSPtG/Smtj9ovRv2WisyRJd+edWYYOKUHupknax 9l+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=TOsD+8D2XyvWm4o2T6/N81pAPgp9EqZGN/+gQVNKyL4=; b=NCLjTamD7kqJPSXhCY7mkKMtdZGeaVgR2vUGm/a0EvBVO/Ve2DVG9Wq4YrQ9zi8b5S +63C0NtK3YuN2AZJylsOvJt3887RPdN0UGxFr5nVgbp9FsoJBOY9RgKG8nUUPvYf4PrV NBXMdBc+6HcIyOxMmD664SEm35i0hdc0fUA5+XN7fr1NXk2Gugix+FS+kWmG4/FrR6qW FAYrGiDk8EfS/UcSeZMqdoH64y38LYKSEvhTaa7lHYWESIg4FE+lm/6E5+w9C646NKFH FGZuwrxku/LLJSAKZuMSKuYW5D89/RTm8+IQjewPA1/niM5NpWsVkPVqrkjPUBSTVIiY qIPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=22c3R+P1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z21si4293066pge.348.2018.01.11.05.06.36; Thu, 11 Jan 2018 05:06:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=22c3R+P1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934430AbeAKNGe (ORCPT + 28 others); Thu, 11 Jan 2018 08:06:34 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:60595 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934059AbeAKNG1 (ORCPT ); Thu, 11 Jan 2018 08:06:27 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w0BD5mX5031475; Thu, 11 Jan 2018 22:05:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w0BD5mX5031475 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515675951; bh=TOsD+8D2XyvWm4o2T6/N81pAPgp9EqZGN/+gQVNKyL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=22c3R+P1gG6J+HAN0ZdbXhz7yTxhHYycL3PlnC0I1axbYF+QpoZoccSqvuBhYFCV9 Y4KClpvaFXmfgNk3LdTSqIkUAxB00SC/MQ/4OI7ATrmXLp662nXYqkDwT36edf2ank YKflYCjjLaxyLRMrgPaoWDhwWIbAMtLuMZj4uMCL/IosxPaMzwkLNrCm4bBG0BIJXm C6nB5vkAk13s3hcPbQrFxCeQdNEUv2sHL01NniNFCGVi6OsRo3aUd948L6XuA0yyQW DpzkVv+7aknZ+FroeWcspYw2FFn843kRtXWk+DMT5xEDzylllZI9qjuRVNV/XQz7z3 xG7A3A6jZP+sg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Michal Marek , Sam Ravnborg , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] fixdep: move global variables to local variables of main() Date: Thu, 11 Jan 2018 22:05:44 +0900 Message-Id: <1515675946-7514-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515675946-7514-1-git-send-email-yamada.masahiro@socionext.com> References: <1515675946-7514-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I do not mind global variables where they are useful enough. In this case, I do not see a good reason to use global variables since they are just referenced in shallow places. It is easy to pass them via function arguments. I squashed print_cmdline() into main() since it is just one line code. Signed-off-by: Masahiro Yamada --- Changes in v2: - Squash print_cmdline() into main() scripts/basic/fixdep.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index dfba77b..d33b5a4 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -111,11 +111,6 @@ #include #include -int insert_extra_deps; -char *target; -char *depfile; -char *cmdline; - static void usage(void) { fprintf(stderr, "Usage: fixdep [-e] \n"); @@ -124,14 +119,6 @@ static void usage(void) } /* - * Print out the commandline prefixed with cmd_ := - */ -static void print_cmdline(void) -{ - printf("cmd_%s := %s\n\n", target, cmdline); -} - -/* * Print out a dependency path from a symbol name */ static void print_config(const char *m, int slen) @@ -152,16 +139,16 @@ static void print_config(const char *m, int slen) static void do_extra_deps(void) { - if (insert_extra_deps) { - char buf[80]; - while(fgets(buf, sizeof(buf), stdin)) { - int len = strlen(buf); - if (len < 2 || buf[len-1] != '\n') { - fprintf(stderr, "fixdep: bad data on stdin\n"); - exit(1); - } - print_config(buf, len-1); + char buf[80]; + + while (fgets(buf, sizeof(buf), stdin)) { + int len = strlen(buf); + + if (len < 2 || buf[len - 1] != '\n') { + fprintf(stderr, "fixdep: bad data on stdin\n"); + exit(1); } + print_config(buf, len - 1); } } @@ -300,7 +287,7 @@ static void *read_file(const char *filename) * assignments are parsed not only by make, but also by the rather simple * parser in scripts/mod/sumversion.c. */ -static void parse_dep_file(char *m) +static void parse_dep_file(char *m, const char *target, int insert_extra_deps) { char *p; int is_last, is_target; @@ -385,7 +372,8 @@ static void parse_dep_file(char *m) exit(1); } - do_extra_deps(); + if (insert_extra_deps) + do_extra_deps(); printf("\n%s: $(deps_%s)\n\n", target, target); printf("$(deps_%s):\n", target); @@ -393,6 +381,8 @@ static void parse_dep_file(char *m) int main(int argc, char *argv[]) { + const char *depfile, *target, *cmdline; + int insert_extra_deps = 0; void *buf; if (argc == 5 && !strcmp(argv[1], "-e")) { @@ -405,10 +395,10 @@ int main(int argc, char *argv[]) target = argv[2]; cmdline = argv[3]; - print_cmdline(); + printf("cmd_%s := %s\n\n", target, cmdline); buf = read_file(depfile); - parse_dep_file(buf); + parse_dep_file(buf, target, insert_extra_deps); free(buf); return 0;