From patchwork Tue Jan 9 08:30:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123807 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3749693qgn; Tue, 9 Jan 2018 00:32:06 -0800 (PST) X-Google-Smtp-Source: ACJfBou36FY90cEW0uxK5MkPj/nEfleq+tulLcX6lvkLrh0QXO+4e/Xs3L9Sna4s4Pmc9mdpkCKs X-Received: by 10.99.107.195 with SMTP id g186mr10831449pgc.97.1515486726205; Tue, 09 Jan 2018 00:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486726; cv=none; d=google.com; s=arc-20160816; b=Nm7fPFGSDnd7OmkEyUZcURTI2RBKm05zrjLPOyuNnsvu/GHpIrF2qirMTS5XvscQqd ZjExeaBfoSSHQt69CoWZ4ezIfWOuG8txfe1POlvjb2l6IdVCGIiR2EAjaisZV+tJv6CI 95WTzJMU0tlaz63Bm00989yBYN+Y1HFeegX4kKKDPibAZkcHZwiqRD5O0ZfG7mh6m1qO RXUZfGuC4oXAiRbxiPn6/HVeydnxeICSlEt+gC4CbH6ljbCvUm5EIh6g6e5yGzapb2jw LpY4YkfYZqjMnVF5ghzuQ1oLFz/yRBZSEQke9IkN3Ashn5pxXSJVjRmBMjNbJdFNXamd NKrA== 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=kFQqw9B1ZpEwtLnGmxlW+fopBVk/ZdaFpWqH3N7SoBE=; b=wa9CscRnNKUCPcQ53/QF4GxT4nS9fNqmuBDzK/+pkyW8o3/WXnZoUBjEgoGMPr0qh6 zJWNubxfG27cHcxqNrcKMX4OP5ADdckWYhTG07Y6uSltKmPb1+L1JQ+q/YYA/hXZWWil gpenZgC6N7dEMqPdFtDvG2R/W0x7bwaz0qFePnfXmfGCsHu5kZJ3Nt0fCg4gjD1kJeEP Z4eM/Y++seHlisUsClFYEA9gWy2LvwdPt+i0adPQtfa+VkeFYpdwBJ1XuFhBC0+JdFQb dlTEtcTzhOFEHr5h6NfTJvLxgArIIH1edYgjthtB8132tNeEcVj5A0IiDnW9EuDimA1H WV2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Rk/VE+DK; 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 e190si9729631pfe.96.2018.01.09.00.32.05; Tue, 09 Jan 2018 00:32:06 -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=Rk/VE+DK; 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 S1751477AbeAIIcE (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:04 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27300 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751150AbeAIIb7 (ORCPT ); Tue, 9 Jan 2018 03:31:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugv024960; Tue, 9 Jan 2018 17:30:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugv024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486658; bh=kFQqw9B1ZpEwtLnGmxlW+fopBVk/ZdaFpWqH3N7SoBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rk/VE+DKzpNpaQRHSGqF8/5JgfhD5grucX0gFc1RcRSSkGU+nPjn9TQezQ30cmOa8 OJDInSmWz9C8UK9jA3HbXKmyw6y/gNIxiSzWNvGtcC++zr6JEmvVFPxZqPpztXiD8R YM8ARKOLQ2L4KnXpBaiAFV1o7W63iM/hcjY5fQeW9GgZvoEv4RgxwlOPNj4c09sYtT wmiqpY19Tg5uJPdv1++qE/ZDllstFRC4QgSnGWr3Wr5lAvYnj8HSSXm0tn3HTUzRHT uwYG4nbwfHEpL+nsyY2ou4+t4aAgSglbSDiraSoKe+CjBPLz1ctbnqiNyKFFD6d0s4 cbuNwRY4DYYAw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 4/6] fixdep: move global variables to local variables of main() Date: Tue, 9 Jan 2018 17:30:48 +0900 Message-Id: <1515486650-1141-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-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. Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bc2364e..bb6d2da 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -114,11 +114,6 @@ #include #include -int insert_extra_deps; -char *target; -char *depfile; -char *cmdline; - static void usage(void) { fprintf(stderr, "Usage: fixdep [-e] \n"); @@ -129,7 +124,7 @@ static void usage(void) /* * Print out the commandline prefixed with cmd_ := */ -static void print_cmdline(void) +static void print_cmdline(const char *target, const char *cmdline) { printf("cmd_%s := %s\n\n", target, cmdline); } @@ -155,16 +150,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); } } @@ -303,7 +298,7 @@ static void *load_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; @@ -388,7 +383,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); @@ -396,6 +392,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")) { @@ -408,10 +406,10 @@ int main(int argc, char *argv[]) target = argv[2]; cmdline = argv[3]; - print_cmdline(); + print_cmdline(target, cmdline); buf = load_file(depfile); - parse_dep_file(buf); + parse_dep_file(buf, target, insert_extra_deps); free(buf); return 0;