From b99188440b5c459ac62114ae1dd1c38e92d65bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 11 Jul 2021 12:11:31 +0200 Subject: Change coding style --- build.c | 106 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/build.c b/build.c index 994303e..b430fb2 100644 --- a/build.c +++ b/build.c @@ -9,12 +9,12 @@ #include #define USAGE "usage: %s file [...]\n", name -#define d(...) do { if (dflag > 0) \ - fprintf(stderr, __VA_ARGS__); } while (0); -#define dd(...) do { if (dflag > 1) \ - fprintf(stderr, __VA_ARGS__); } while (0); -#define ddd(...) do { if (dflag > 2) \ - fprintf(stderr, __VA_ARGS__); } while (0); +#define d(...) do{ if(dflag > 0) \ + fprintf(stderr, __VA_ARGS__); } while(0); +#define dd(...) do{ if(dflag > 1) \ + fprintf(stderr, __VA_ARGS__); } while(0); +#define ddd(...) do{ if(dflag > 2) \ + fprintf(stderr, __VA_ARGS__); } while(0); #define MAXBUF 1024 #define MAXCMDS 32 /* Maximum number of commands across all files. */ @@ -38,12 +38,12 @@ main(int argc, char *argv[]) struct stat sb, ssb; /* Allocate memory. */ - for (i = 0; i < MAXCMDS; i++) - if (!(cmd[i] = malloc(MAXCMD))) + for(i = 0; i < MAXCMDS; i++) + if(!(cmd[i] = malloc(MAXCMD))) err(1, "malloc"); - if (!(dep = malloc(MAXDEP))) + if(!(dep = malloc(MAXDEP))) err(1, "malloc"); - if (!(tgt = malloc(MAXTGT))) + if(!(tgt = malloc(MAXTGT))) err(1, "malloc"); tgt[0] = dep[0] = 0; @@ -51,8 +51,8 @@ main(int argc, char *argv[]) /* Process command-line flags (debug, force). */ name = argv[0]; dflag = fflag = 0; - while ((c = getopt(argc, argv, "df")) != -1) - switch (c) { + while((c = getopt(argc, argv, "df")) != -1) + switch(c){ case 'd': dflag++; break; @@ -65,30 +65,30 @@ main(int argc, char *argv[]) } argc -= optind; argv += optind; - if (argc == 0) { + if(argc == 0){ fprintf(stderr, USAGE); return 1; } /* Process dependencies and commands in each file. */ - for (i = icmd = 0; i < argc; i++, icmd = 0) { - if (!(fp = fopen(argv[i], "r"))) + for(i = icmd = 0; i < argc; i++, icmd = 0){ + if(!(fp = fopen(argv[i], "r"))) err(1, "fopen"); /* Read line by line, at most twenty. */ - for (j = 0; j < 20 && fgets(buf, MAXBUF, fp); j++) { + for(j = 0; j < 20 && fgets(buf, MAXBUF, fp); j++){ buf[strcspn(buf, "\n")] = 0; - for (b = buf; *b; b++) { + for(b = buf; *b; b++){ /* Find command line. */ - if (strncmp(b, " $ ", 3) == 0 - || strncmp(b, " $ ", 3) == 0) { + if(strncmp(b, " $ ", 3) == 0 + || strncmp(b, " $ ", 3) == 0){ strncpy(cmd[icmd++], b+3, MAXBUF-1); /* Find target inside command. */ - for (b = b+3; *b; b++) { - if (!(*b+1)) continue; - if (*b != '>') continue; + for(b = b+3; *b; b++){ + if(!(*b+1)) continue; + if(*b != '>') continue; strncpy(tgt, b+1, MAXTGT-1); } @@ -99,8 +99,8 @@ main(int argc, char *argv[]) } /* Find dependency line. */ - if (strncmp(b, " % ", 3) == 0 - || strncmp(b, " % ", 3) == 0) { + if(strncmp(b, " % ", 3) == 0 + || strncmp(b, " % ", 3) == 0){ strncpy(dep, b+3, MAXDEP-1); ddd("%s: dependency line '%s'\n", argv[i], buf); @@ -109,13 +109,13 @@ main(int argc, char *argv[]) } } - if (!icmd) { + if(!icmd){ fprintf(stderr, "%s: no command line found\n", argv[i]); goto next; } /* Build immediately if forced or no target found. */ - if (fflag || !*tgt) + if(fflag || !*tgt) goto build; /* Trim shell meta-characters and whitespace. */ @@ -124,14 +124,14 @@ main(int argc, char *argv[]) /* Build immediately if source is newer than target. */ dd("%s: target '%s'\n", argv[i], tgt); - if (stat(argv[i], &sb)) + if(stat(argv[i], &sb)) err(1, argv[i]); - if (stat(tgt, &ssb)) { - if (errno == ENOENT) + if(stat(tgt, &ssb)){ + if(errno == ENOENT) goto build; err(1, tgt); } - if (sb.st_mtime > ssb.st_mtime) { + if(sb.st_mtime > ssb.st_mtime){ d("%s: %s is modified, building\n", argv[i], argv[i]); goto build; @@ -141,22 +141,22 @@ main(int argc, char *argv[]) * If target is newer than source and there are no * dependencies, the target is up-to-date. */ - if (!*dep) + if(!*dep) goto uptodate; /* Build immediately if any dependency is newer than target. */ - while (d = nextdep(&dep)) { + while(d = nextdep(&dep)){ dd("%s: depend '%s'\n", argv[i], d); - if (stat(d, &sb)) { - if (errno == ENOENT) { + if(stat(d, &sb)){ + if(errno == ENOENT){ fprintf(stderr, "%s: dependency %s " "does not exist\n", argv[i], d); continue; } err(1, d); } - if (sb.st_mtime > ssb.st_mtime) { + if(sb.st_mtime > ssb.st_mtime){ d("%s: %s is modified, building\n", argv[i], d); free(d); goto build; @@ -182,14 +182,14 @@ build: */ buf[0] = 0; strcat(buf, "set -ex\n"); - for (j = 0; j < icmd; j++) { + for(j = 0; j < icmd; j++){ strncat(buf, cmd[j], MAXBUF-1); strncat(buf, "\n", MAXBUF-1); } s = system(buf); /* Process next file if shell command succeeded. */ - if (s == 0) + if(s == 0) goto next; /* @@ -198,11 +198,11 @@ build: * and printed to the user. The program exits * with a positive status. */ - if (WIFEXITED(s)) { + if(WIFEXITED(s)){ fprintf(stderr, "%s: exited with %d\n", argv[i], WEXITSTATUS(s)); exit(WEXITSTATUS(s)); - } else if (WIFSIGNALED(s)) { + } else if(WIFSIGNALED(s)){ fprintf(stderr, "%s: terminated by signal %d\n", argv[i], WTERMSIG(s)); exit(1); @@ -216,8 +216,8 @@ next: void cleandep(char **dep) { - for (; **dep; ++*dep) - if (!isspace(**dep)) break; + for(; **dep; ++*dep) + if(!isspace(**dep)) break; } void @@ -225,15 +225,15 @@ cleantgt(char **tgt) { char *t; - for (; **tgt; ++*tgt) - if (!isspace(**tgt)) break; + for(; **tgt; ++*tgt) + if(!isspace(**tgt)) break; - for (t = *tgt; *t; t++) - if (isspace(*t) - || *t == '|' - || *t == '&' - || *t == ';' - || *t == ')') { + for(t = *tgt; *t; t++) + if(isspace(*t) + || *t == '|' + || *t == '&' + || *t == ';' + || *t == ')'){ *t = 0; break; } @@ -246,12 +246,12 @@ nextdep(char **dep) int i; /* Read dependency string character-by-character. */ - for (i = 0; (*dep)[i]; i++) { + for(i = 0;(*dep)[i]; i++){ /* * Upon encountering a space or the final character, the * hitherto gathered string is stored in a copy. */ - if (isspace((*dep)[i]) || (*dep)[i+1] == 0 && i++) { + if(isspace((*dep)[i]) || (*dep)[i+1] == 0 && i++){ d = strdup(*dep); d[i] = 0; goto found; @@ -269,8 +269,8 @@ found: * The original dependency string is incremented until the next * dependency. */ - for (; (*dep)[i]; i++) - if (!isspace((*dep)[i])) break; + for(; (*dep)[i]; i++) + if(!isspace((*dep)[i])) break; *dep += i; return d; -- cgit v1.2.3