Skip to content

Commit 5d1ef76

Browse files
committed
fixdep: move global variables to local variables of main()
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 <yamada.masahiro@socionext.com>
1 parent ccfe788 commit 5d1ef76

1 file changed

Lines changed: 16 additions & 26 deletions

File tree

‎scripts/basic/fixdep.c‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,13 @@
111111
#include <stdio.h>
112112
#include <ctype.h>
113113

114-
int insert_extra_deps;
115-
char *target;
116-
char *depfile;
117-
char *cmdline;
118-
119114
static void usage(void)
120115
{
121116
fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n");
122117
fprintf(stderr, " -e insert extra dependencies given on stdin\n");
123118
exit(1);
124119
}
125120

126-
/*
127-
* Print out the commandline prefixed with cmd_<target filename> :=
128-
*/
129-
static void print_cmdline(void)
130-
{
131-
printf("cmd_%s := %s\n\n", target, cmdline);
132-
}
133-
134121
/*
135122
* Print out a dependency path from a symbol name
136123
*/
@@ -152,16 +139,16 @@ static void print_config(const char *m, int slen)
152139

153140
static void do_extra_deps(void)
154141
{
155-
if (insert_extra_deps) {
156-
char buf[80];
157-
while(fgets(buf, sizeof(buf), stdin)) {
158-
int len = strlen(buf);
159-
if (len < 2 || buf[len-1] != '\n') {
160-
fprintf(stderr, "fixdep: bad data on stdin\n");
161-
exit(1);
162-
}
163-
print_config(buf, len-1);
142+
char buf[80];
143+
144+
while (fgets(buf, sizeof(buf), stdin)) {
145+
int len = strlen(buf);
146+
147+
if (len < 2 || buf[len - 1] != '\n') {
148+
fprintf(stderr, "fixdep: bad data on stdin\n");
149+
exit(1);
164150
}
151+
print_config(buf, len - 1);
165152
}
166153
}
167154

@@ -300,7 +287,7 @@ static void *read_file(const char *filename)
300287
* assignments are parsed not only by make, but also by the rather simple
301288
* parser in scripts/mod/sumversion.c.
302289
*/
303-
static void parse_dep_file(char *m)
290+
static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
304291
{
305292
char *p;
306293
int is_last, is_target;
@@ -385,14 +372,17 @@ static void parse_dep_file(char *m)
385372
exit(1);
386373
}
387374

388-
do_extra_deps();
375+
if (insert_extra_deps)
376+
do_extra_deps();
389377

390378
printf("\n%s: $(deps_%s)\n\n", target, target);
391379
printf("$(deps_%s):\n", target);
392380
}
393381

394382
int main(int argc, char *argv[])
395383
{
384+
const char *depfile, *target, *cmdline;
385+
int insert_extra_deps = 0;
396386
void *buf;
397387

398388
if (argc == 5 && !strcmp(argv[1], "-e")) {
@@ -405,10 +395,10 @@ int main(int argc, char *argv[])
405395
target = argv[2];
406396
cmdline = argv[3];
407397

408-
print_cmdline();
398+
printf("cmd_%s := %s\n\n", target, cmdline);
409399

410400
buf = read_file(depfile);
411-
parse_dep_file(buf);
401+
parse_dep_file(buf, target, insert_extra_deps);
412402
free(buf);
413403

414404
return 0;

0 commit comments

Comments
 (0)