From e6417f6fe2ab9ece408075f315a2d958f255a020 Mon Sep 17 00:00:00 2001 From: Hartmut Brandt Date: Tue, 30 Nov 2004 17:46:29 +0000 Subject: [PATCH] Stylification: missing spaces, extra space after function names, casts and the sizeof operator, missing empty lines, void casts, extra empty lines. Checked by: diff on make *.o lst.lib/*.o Submitted by: Max Okumoto (partly) --- usr.bin/make/arch.c | 246 ++++++++------- usr.bin/make/buf.c | 79 ++--- usr.bin/make/buf.h | 2 +- usr.bin/make/compat.c | 119 +++---- usr.bin/make/cond.c | 114 +++---- usr.bin/make/dir.c | 207 +++++++------ usr.bin/make/dir.h | 2 +- usr.bin/make/for.c | 72 ++--- usr.bin/make/hash.c | 13 +- usr.bin/make/hash.h | 4 +- usr.bin/make/job.c | 278 +++++++++-------- usr.bin/make/job.h | 2 - usr.bin/make/lst.lib/lstAppend.c | 4 +- usr.bin/make/lst.lib/lstConcat.c | 5 +- usr.bin/make/lst.lib/lstDeQueue.c | 4 +- usr.bin/make/lst.lib/lstDestroy.c | 10 +- usr.bin/make/lst.lib/lstDupl.c | 6 +- usr.bin/make/lst.lib/lstFindFrom.c | 4 +- usr.bin/make/lst.lib/lstForEachFrom.c | 8 +- usr.bin/make/lst.lib/lstInsert.c | 4 +- usr.bin/make/lst.lib/lstIsAtEnd.c | 2 +- usr.bin/make/lst.lib/lstNext.c | 2 +- usr.bin/make/lst.lib/lstOpen.c | 4 +- usr.bin/make/lst.lib/lstRemove.c | 2 +- usr.bin/make/main.c | 77 ++--- usr.bin/make/make.c | 177 ++++++----- usr.bin/make/parse.c | 408 ++++++++++++------------ usr.bin/make/str.c | 47 +-- usr.bin/make/suff.c | 429 +++++++++++++------------- usr.bin/make/targ.c | 159 +++++----- usr.bin/make/util.c | 41 +-- usr.bin/make/var.c | 258 ++++++++-------- usr.bin/make/var.h | 4 +- usr.bin/make/var_modify.c | 56 ++-- 34 files changed, 1450 insertions(+), 1399 deletions(-) diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c index 1513431c8c14..3018ffa702d8 100644 --- a/usr.bin/make/arch.c +++ b/usr.bin/make/arch.c @@ -138,7 +138,7 @@ static int ArchSVR4Entry(Arch *, char *, size_t, FILE *); static void ArchFree(void *ap) { - Arch *a = (Arch *) ap; + Arch *a = (Arch *)ap; Hash_Search search; Hash_Entry *entry; @@ -154,8 +154,6 @@ ArchFree(void *ap) free(a); } - - /*- *----------------------------------------------------------------------- * Arch_ParseArchive -- @@ -176,7 +174,7 @@ ArchFree(void *ap) *----------------------------------------------------------------------- */ ReturnStatus -Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) +Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) { char *cp; /* Pointer into line */ GNode *gn; /* New node */ @@ -201,9 +199,9 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) Boolean freeIt; char *result; - result=Var_Parse(cp, ctxt, TRUE, &length, &freeIt); + result = Var_Parse(cp, ctxt, TRUE, &length, &freeIt); if (result == var_Error) { - return(FAILURE); + return (FAILURE); } else { subLibName = TRUE; } @@ -211,7 +209,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) if (freeIt) { free(result); } - cp += length-1; + cp += length - 1; } } @@ -229,11 +227,11 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) */ Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */ - while (*cp != '\0' && *cp != ')' && isspace ((unsigned char) *cp)) { + while (*cp != '\0' && *cp != ')' && isspace((unsigned char)*cp)) { cp++; } memName = cp; - while (*cp != '\0' && *cp != ')' && !isspace ((unsigned char) *cp)) { + while (*cp != '\0' && *cp != ')' && !isspace((unsigned char)*cp)) { if (*cp == '$') { /* * Variable spec, so call the Var module to parse the puppy @@ -245,7 +243,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) result=Var_Parse(cp, ctxt, TRUE, &length, &freeIt); if (result == var_Error) { - return(FAILURE); + return (FAILURE); } else { doSubst = TRUE; } @@ -320,18 +318,18 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) if (gn == NULL) { free(buf); - return(FAILURE); + return (FAILURE); } else { gn->type |= OP_ARCHV; - (void)Lst_AtEnd(nodeLst, (void *)gn); + Lst_AtEnd(nodeLst, (void *)gn); } - } else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt)!=SUCCESS) { + } else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt) != SUCCESS) { /* * Error in nested call -- free buffer and return FAILURE * ourselves. */ free(buf); - return(FAILURE); + return (FAILURE); } /* * Free buffer and continue with our work. @@ -356,7 +354,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) snprintf(nameBuf, sz, "%s(%s)", libName, member); free(member); - gn = Targ_FindNode (nameBuf, TARG_CREATE); + gn = Targ_FindNode(nameBuf, TARG_CREATE); if (gn == NULL) { free(nameBuf); return (FAILURE); @@ -369,7 +367,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) * end of the provided list. */ gn->type |= OP_ARCHV; - (void) Lst_AtEnd (nodeLst, (void *)gn); + Lst_AtEnd(nodeLst, (void *)gn); } } Lst_Destroy(members, NOFREE); @@ -378,7 +376,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) size_t sz = strlen(libName) + strlen(memName) + 3; nameBuf = emalloc(sz); snprintf(nameBuf, sz, "%s(%s)", libName, memName); - gn = Targ_FindNode (nameBuf, TARG_CREATE); + gn = Targ_FindNode(nameBuf, TARG_CREATE); free(nameBuf); if (gn == NULL) { return (FAILURE); @@ -391,7 +389,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) * provided list. */ gn->type |= OP_ARCHV; - (void) Lst_AtEnd (nodeLst, (void *)gn); + Lst_AtEnd(nodeLst, (void *)gn); } } if (doSubst) { @@ -415,7 +413,7 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) */ do { cp++; - } while (*cp != '\0' && isspace ((unsigned char) *cp)); + } while (*cp != '\0' && isspace((unsigned char)*cp)); *linePtr = cp; return (SUCCESS); @@ -437,9 +435,9 @@ Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) *----------------------------------------------------------------------- */ static int -ArchFindArchive (void *ar, void *archName) +ArchFindArchive(void *ar, void *archName) { - return (strcmp ((char *) archName, ((Arch *) ar)->name)); + return (strcmp((char *)archName, ((Arch *)ar)->name)); } /*- @@ -461,9 +459,9 @@ ArchFindArchive (void *ar, void *archName) *----------------------------------------------------------------------- */ static struct ar_hdr * -ArchStatMember (char *archive, char *member, Boolean hash) +ArchStatMember(char *archive, char *member, Boolean hash) { -#define AR_MAX_NAME_LEN (sizeof(arh.ar_name)-1) +#define AR_MAX_NAME_LEN (sizeof(arh.ar_name) - 1) FILE * arch; /* Stream to archive */ int size; /* Size of archive member */ char *cp; /* Useful character pointer */ @@ -472,7 +470,7 @@ ArchStatMember (char *archive, char *member, Boolean hash) Arch *ar; /* Archive descriptor */ Hash_Entry *he; /* Entry containing member's description */ struct ar_hdr arh; /* archive-member header for reading archive */ - char memName[MAXPATHLEN+1]; + char memName[MAXPATHLEN + 1]; /* Current member name while hashing. */ /* @@ -481,30 +479,30 @@ ArchStatMember (char *archive, char *member, Boolean hash) * to point 'member' to the final component, if there is one, to make * the comparisons easier... */ - cp = strrchr (member, '/'); + cp = strrchr(member, '/'); if ((cp != NULL) && (strcmp(member, RANLIBMAG) != 0)) member = cp + 1; - ln = Lst_Find (archives, (void *) archive, ArchFindArchive); + ln = Lst_Find(archives, (void *)archive, ArchFindArchive); if (ln != NULL) { - ar = (Arch *) Lst_Datum (ln); + ar = (Arch *)Lst_Datum(ln); - he = Hash_FindEntry (&ar->members, member); + he = Hash_FindEntry(&ar->members, member); if (he != NULL) { - return ((struct ar_hdr *) Hash_GetValue (he)); + return ((struct ar_hdr *)Hash_GetValue (he)); } else { /* Try truncated name */ - char copy[AR_MAX_NAME_LEN+1]; - size_t len = strlen (member); + char copy[AR_MAX_NAME_LEN + 1]; + size_t len = strlen(member); if (len > AR_MAX_NAME_LEN) { len = AR_MAX_NAME_LEN; strncpy(copy, member, AR_MAX_NAME_LEN); copy[AR_MAX_NAME_LEN] = '\0'; } - if ((he = Hash_FindEntry (&ar->members, copy)) != NULL) - return ((struct ar_hdr *) Hash_GetValue (he)); + if ((he = Hash_FindEntry(&ar->members, copy)) != NULL) + return ((struct ar_hdr *)Hash_GetValue(he)); return (NULL); } } @@ -533,7 +531,7 @@ ArchStatMember (char *archive, char *member, Boolean hash) * We don't have this archive on the list yet, so we want to find out * everything that's in it and cache it so we can get at it quickly. */ - arch = fopen (archive, "r"); + arch = fopen(archive, "r"); if (arch == NULL) { return (NULL); } @@ -542,21 +540,21 @@ ArchStatMember (char *archive, char *member, Boolean hash) * We use the ARMAG string to make sure this is an archive we * can handle... */ - if ((fread (magic, SARMAG, 1, arch) != 1) || - (strncmp (magic, ARMAG, SARMAG) != 0)) { - fclose (arch); + if ((fread(magic, SARMAG, 1, arch) != 1) || + (strncmp(magic, ARMAG, SARMAG) != 0)) { + fclose(arch); return (NULL); } - ar = (Arch *)emalloc (sizeof (Arch)); - ar->name = estrdup (archive); + ar = (Arch *)emalloc(sizeof(Arch)); + ar->name = estrdup(archive); ar->fnametab = NULL; ar->fnamesize = 0; - Hash_InitTable (&ar->members, -1); + Hash_InitTable(&ar->members, -1); memName[AR_MAX_NAME_LEN] = '\0'; - while (fread ((char *)&arh, sizeof (struct ar_hdr), 1, arch) == 1) { - if (strncmp ( arh.ar_fmag, ARFMAG, sizeof (arh.ar_fmag)) != 0) { + while (fread((char *)&arh, sizeof(struct ar_hdr), 1, arch) == 1) { + if (strncmp(arh.ar_fmag, ARFMAG, sizeof(arh.ar_fmag)) != 0) { /* * The header is bogus, so the archive is bad * and there's no way we can recover... @@ -569,10 +567,10 @@ ArchStatMember (char *archive, char *member, Boolean hash) * boundary, so we need to extract the size of the file from the * 'size' field of the header and round it up during the seek. */ - arh.ar_size[sizeof(arh.ar_size)-1] = '\0'; - size = (int) strtol(arh.ar_size, NULL, 10); + arh.ar_size[sizeof(arh.ar_size) - 1] = '\0'; + size = (int)strtol(arh.ar_size, NULL, 10); - (void) strncpy (memName, arh.ar_name, sizeof(arh.ar_name)); + strncpy(memName, arh.ar_name, sizeof(arh.ar_name)); for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) { continue; } @@ -613,10 +611,10 @@ ArchStatMember (char *archive, char *member, Boolean hash) if (elen > MAXPATHLEN) goto badarch; - if (fread (memName, elen, 1, arch) != 1) + if (fread(memName, elen, 1, arch) != 1) goto badarch; memName[elen] = '\0'; - fseek (arch, -elen, SEEK_CUR); + fseek(arch, -elen, SEEK_CUR); /* XXX Multiple levels may be asked for, make this conditional * on one, and use DEBUGF. */ @@ -626,35 +624,35 @@ ArchStatMember (char *archive, char *member, Boolean hash) } #endif - he = Hash_CreateEntry (&ar->members, memName, NULL); - Hash_SetValue (he, (void *)emalloc (sizeof (struct ar_hdr))); - memcpy (Hash_GetValue (he), &arh, - sizeof (struct ar_hdr)); + he = Hash_CreateEntry(&ar->members, memName, NULL); + Hash_SetValue(he, (void *)emalloc (sizeof(struct ar_hdr))); + memcpy(Hash_GetValue(he), &arh, + sizeof(struct ar_hdr)); } - fseek (arch, (size + 1) & ~1, SEEK_CUR); + fseek(arch, (size + 1) & ~1, SEEK_CUR); } - fclose (arch); + fclose(arch); - (void) Lst_AtEnd (archives, (void *) ar); + Lst_AtEnd(archives, (void *)ar); /* * Now that the archive has been read and cached, we can look into * the hash table to find the desired member's header. */ - he = Hash_FindEntry (&ar->members, member); + he = Hash_FindEntry(&ar->members, member); if (he != NULL) { - return ((struct ar_hdr *) Hash_GetValue (he)); + return ((struct ar_hdr *)Hash_GetValue (he)); } else { return (NULL); } badarch: - fclose (arch); - Hash_DeleteTable (&ar->members); + fclose(arch); + Hash_DeleteTable(&ar->members); free(ar->fnametab); - free (ar); + free(ar); return (NULL); } @@ -692,7 +690,7 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch) if (ar->fnametab != NULL) { DEBUGF(ARCH, ("Attempted to redefine an SVR4 name table\n")); - return -1; + return (-1); } /* @@ -704,7 +702,7 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch) if (fread(ar->fnametab, size, 1, arch) != 1) { DEBUGF(ARCH, ("Reading an SVR4 name table failed\n")); - return -1; + return (-1); } eptr = ar->fnametab + size; for (entry = 0, ptr = ar->fnametab; ptr < eptr; ptr++) @@ -721,28 +719,28 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch) break; } DEBUGF(ARCH, ("Found svr4 archive name table with %zu entries\n", entry)); - return 0; + return (0); } if (name[1] == ' ' || name[1] == '\0') - return 2; + return (2); - entry = (size_t) strtol(&name[1], &eptr, 0); + entry = (size_t)strtol(&name[1], &eptr, 0); if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) { DEBUGF(ARCH, ("Could not parse SVR4 name %s\n", name)); - return 2; + return (2); } if (entry >= ar->fnamesize) { DEBUGF(ARCH, ("SVR4 entry offset %s is greater than %zu\n", name, ar->fnamesize)); - return 2; + return (2); } DEBUGF(ARCH, ("Replaced %s with %s\n", name, &ar->fnametab[entry])); - (void) strncpy(name, &ar->fnametab[entry], MAXPATHLEN); + strncpy(name, &ar->fnametab[entry], MAXPATHLEN); name[MAXPATHLEN] = '\0'; - return 1; + return (1); } #endif @@ -766,7 +764,7 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch) *----------------------------------------------------------------------- */ static FILE * -ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) +ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, char *mode) { FILE * arch; /* Stream to archive */ int size; /* Size of archive member */ @@ -774,7 +772,7 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) char magic[SARMAG]; size_t len, tlen; - arch = fopen (archive, mode); + arch = fopen(archive, mode); if (arch == NULL) { return (NULL); } @@ -783,9 +781,9 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) * We use the ARMAG string to make sure this is an archive we * can handle... */ - if ((fread (magic, SARMAG, 1, arch) != 1) || - (strncmp (magic, ARMAG, SARMAG) != 0)) { - fclose (arch); + if ((fread(magic, SARMAG, 1, arch) != 1) || + (strncmp(magic, ARMAG, SARMAG) != 0)) { + fclose(arch); return (NULL); } @@ -795,24 +793,24 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) * to point 'member' to the final component, if there is one, to make * the comparisons easier... */ - cp = strrchr (member, '/'); + cp = strrchr(member, '/'); if ((cp != NULL) && (strcmp(member, RANLIBMAG) != 0)) { member = cp + 1; } - len = tlen = strlen (member); - if (len > sizeof (arhPtr->ar_name)) { - tlen = sizeof (arhPtr->ar_name); + len = tlen = strlen(member); + if (len > sizeof(arhPtr->ar_name)) { + tlen = sizeof(arhPtr->ar_name); } - while (fread ((char *)arhPtr, sizeof (struct ar_hdr), 1, arch) == 1) { - if (strncmp(arhPtr->ar_fmag, ARFMAG, sizeof (arhPtr->ar_fmag) ) != 0) { + while (fread((char *)arhPtr, sizeof(struct ar_hdr), 1, arch) == 1) { + if (strncmp(arhPtr->ar_fmag, ARFMAG, sizeof(arhPtr->ar_fmag) ) != 0) { /* * The header is bogus, so the archive is bad * and there's no way we can recover... */ - fclose (arch); + fclose(arch); return (NULL); - } else if (strncmp (member, arhPtr->ar_name, tlen) == 0) { + } else if (strncmp(member, arhPtr->ar_name, tlen) == 0) { /* * If the member's name doesn't take up the entire 'name' field, * we have to be careful of matching prefixes. Names are space- @@ -830,7 +828,7 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) * the file at the actual member, rather than its header, but * not here... */ - fseek (arch, -sizeof(struct ar_hdr), SEEK_CUR); + fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR); return (arch); } } else @@ -847,11 +845,11 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) char ename[MAXPATHLEN]; if (elen > MAXPATHLEN) { - fclose (arch); + fclose(arch); return NULL; } - if (fread (ename, elen, 1, arch) != 1) { - fclose (arch); + if (fread(ename, elen, 1, arch) != 1) { + fclose(arch); return NULL; } ename[elen] = '\0'; @@ -863,10 +861,10 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) } if (strncmp(ename, member, len) == 0) { /* Found as extended name */ - fseek (arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR); + fseek(arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR); return (arch); } - fseek (arch, -elen, SEEK_CUR); + fseek(arch, -elen, SEEK_CUR); goto skip; } else #endif @@ -879,9 +877,9 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) * extract the size of the file from the 'size' field of the * header and round it up during the seek. */ - arhPtr->ar_size[sizeof(arhPtr->ar_size)-1] = '\0'; - size = (int) strtol(arhPtr->ar_size, NULL, 10); - fseek (arch, (size + 1) & ~1, SEEK_CUR); + arhPtr->ar_size[sizeof(arhPtr->ar_size) - 1] = '\0'; + size = (int)strtol(arhPtr->ar_size, NULL, 10); + fseek(arch, (size + 1) & ~1, SEEK_CUR); } } @@ -889,7 +887,7 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) * We've looked everywhere, but the member is not to be found. Close the * archive and return NULL -- an error. */ - fclose (arch); + fclose(arch); return (NULL); } @@ -909,22 +907,22 @@ ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) *----------------------------------------------------------------------- */ void -Arch_Touch (GNode *gn) +Arch_Touch(GNode *gn) { FILE * arch; /* Stream open to archive, positioned properly */ struct ar_hdr arh; /* Current header describing member */ char *p1, *p2; - arch = ArchFindMember(Var_Value (ARCHIVE, gn, &p1), - Var_Value (TARGET, gn, &p2), + arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1), + Var_Value(TARGET, gn, &p2), &arh, "r+"); free(p1); free(p2); - snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long) now); + snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long)now); if (arch != NULL) { - (void)fwrite ((char *)&arh, sizeof (struct ar_hdr), 1, arch); - fclose (arch); + fwrite((char *)&arh, sizeof(struct ar_hdr), 1, arch); + fclose(arch); } } @@ -944,19 +942,19 @@ Arch_Touch (GNode *gn) *----------------------------------------------------------------------- */ void -Arch_TouchLib (GNode *gn) +Arch_TouchLib(GNode *gn) { #ifdef RANLIBMAG FILE * arch; /* Stream open to archive */ struct ar_hdr arh; /* Header describing table of contents */ struct utimbuf times; /* Times for utime() call */ - arch = ArchFindMember (gn->path, RANLIBMAG, &arh, "r+"); + arch = ArchFindMember(gn->path, RANLIBMAG, &arh, "r+"); snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long) now); if (arch != NULL) { - (void)fwrite ((char *)&arh, sizeof (struct ar_hdr), 1, arch); - fclose (arch); + fwrite((char *)&arh, sizeof(struct ar_hdr), 1, arch); + fclose(arch); times.actime = times.modtime = now; utime(gn->path, ×); @@ -971,7 +969,7 @@ Arch_TouchLib (GNode *gn) * name. * * Results: - * The modification time (seconds). + * The modification time(seconds). * * Side Effects: * The mtime field of the given node is filled in with the value @@ -986,14 +984,14 @@ Arch_MTime(GNode *gn) int modTime; /* Modification time as an integer */ char *p1, *p2; - arhPtr = ArchStatMember (Var_Value (ARCHIVE, gn, &p1), - Var_Value (TARGET, gn, &p2), + arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1), + Var_Value(TARGET, gn, &p2), TRUE); free(p1); free(p2); if (arhPtr != NULL) { - modTime = (int) strtol(arhPtr->ar_date, NULL, 10); + modTime = (int)strtol(arhPtr->ar_date, NULL, 10); } else { modTime = 0; } @@ -1017,19 +1015,19 @@ Arch_MTime(GNode *gn) *----------------------------------------------------------------------- */ int -Arch_MemMTime (GNode *gn) +Arch_MemMTime(GNode *gn) { LstNode ln; GNode *pgn; char *nameStart, *nameEnd; - if (Lst_Open (gn->parents) != SUCCESS) { + if (Lst_Open(gn->parents) != SUCCESS) { gn->mtime = 0; return (0); } - while ((ln = Lst_Next (gn->parents)) != NULL) { - pgn = (GNode *) Lst_Datum (ln); + while ((ln = Lst_Next(gn->parents)) != NULL) { + pgn = (GNode *)Lst_Datum(ln); if (pgn->type & OP_ARCHV) { /* @@ -1039,8 +1037,8 @@ Arch_MemMTime (GNode *gn) * child. We keep searching its parents in case some other * parent requires this child to exist... */ - nameStart = strchr (pgn->name, '(') + 1; - nameEnd = strchr (nameStart, ')'); + nameStart = strchr(pgn->name, '(') + 1; + nameEnd = strchr(nameStart, ')'); if (pgn->make && strncmp(nameStart, gn->name, nameEnd - nameStart) == 0) { @@ -1056,7 +1054,7 @@ Arch_MemMTime (GNode *gn) } } - Lst_Close (gn->parents); + Lst_Close(gn->parents); return (gn->mtime); } @@ -1082,7 +1080,7 @@ Arch_MemMTime (GNode *gn) *----------------------------------------------------------------------- */ void -Arch_FindLib (GNode *gn, Lst path) +Arch_FindLib(GNode *gn, Lst path) { char *libName; /* file name for archive */ size_t sz; @@ -1091,14 +1089,14 @@ Arch_FindLib (GNode *gn, Lst path) libName = (char *)emalloc(sz); snprintf(libName, sz, "lib%s.a", &gn->name[2]); - gn->path = Dir_FindFile (libName, path); + gn->path = Dir_FindFile(libName, path); - free (libName); + free(libName); #ifdef LIBRARIES - Var_Set (TARGET, gn->name, gn); + Var_Set(TARGET, gn->name, gn); #else - Var_Set (TARGET, gn->path == NULL ? gn->name : gn->path, gn); + Var_Set(TARGET, gn->path == NULL ? gn->name : gn->path, gn); #endif /* LIBRARIES */ } @@ -1140,7 +1138,7 @@ Arch_FindLib (GNode *gn, Lst path) *----------------------------------------------------------------------- */ Boolean -Arch_LibOODate (GNode *gn) +Arch_LibOODate(GNode *gn) { Boolean oodate; @@ -1153,10 +1151,10 @@ Arch_LibOODate (GNode *gn) struct ar_hdr *arhPtr; /* Header for __.SYMDEF */ int modTimeTOC; /* The table-of-contents's mod time */ - arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE); + arhPtr = ArchStatMember(gn->path, RANLIBMAG, FALSE); if (arhPtr != NULL) { - modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10); + modTimeTOC = (int)strtol(arhPtr->ar_date, NULL, 10); /* XXX choose one. */ if (DEBUG(ARCH) || DEBUG(MAKE)) { @@ -1193,13 +1191,11 @@ Arch_LibOODate (GNode *gn) *----------------------------------------------------------------------- */ void -Arch_Init (void) +Arch_Init(void) { - archives = Lst_Init (FALSE); + archives = Lst_Init(FALSE); } - - /*- *----------------------------------------------------------------------- * Arch_End -- @@ -1214,7 +1210,7 @@ Arch_Init (void) *----------------------------------------------------------------------- */ void -Arch_End (void) +Arch_End(void) { Lst_Destroy(archives, ArchFree); } diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index 49523af4d3cd..c344738e8b09 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -64,8 +64,8 @@ __FBSDID("$FreeBSD$"); */ #define BufExpand(bp,nb) \ if (bp->left < (nb)+1) {\ - int newSize = (bp)->size + max((nb)+1,BUF_ADD_INC); \ - Byte *newBuf = (Byte *) erealloc((bp)->buffer, newSize); \ + int newSize = (bp)->size + max((nb) + 1, BUF_ADD_INC); \ + Byte *newBuf = (Byte *)erealloc((bp)->buffer, newSize); \ \ (bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \ (bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer);\ @@ -92,10 +92,10 @@ __FBSDID("$FreeBSD$"); *----------------------------------------------------------------------- */ void -Buf_OvAddByte (Buffer bp, int byte) +Buf_OvAddByte(Buffer bp, int byte) { bp->left = 0; - BufExpand (bp, 1); + BufExpand(bp, 1); *bp->inPtr++ = byte; bp->left--; @@ -105,7 +105,7 @@ Buf_OvAddByte (Buffer bp, int byte) */ *bp->inPtr = 0; } - + /*- *----------------------------------------------------------------------- * Buf_AddBytes -- @@ -120,12 +120,12 @@ Buf_OvAddByte (Buffer bp, int byte) *----------------------------------------------------------------------- */ void -Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr) +Buf_AddBytes(Buffer bp, int numBytes, const Byte *bytesPtr) { - BufExpand (bp, numBytes); + BufExpand(bp, numBytes); - memcpy (bp->inPtr, bytesPtr, numBytes); + memcpy(bp->inPtr, bytesPtr, numBytes); bp->inPtr += numBytes; bp->left -= numBytes; @@ -134,7 +134,7 @@ Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr) */ *bp->inPtr = 0; } - + /*- *----------------------------------------------------------------------- * Buf_UngetByte -- @@ -149,7 +149,7 @@ Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr) *----------------------------------------------------------------------- */ void -Buf_UngetByte (Buffer bp, int byte) +Buf_UngetByte(Buffer bp, int byte) { if (bp->outPtr != bp->buffer) { @@ -171,10 +171,11 @@ Buf_UngetByte (Buffer bp, int byte) Byte *newBuf; newBuf = (Byte *)emalloc(bp->size + BUF_UNGET_INC); - memcpy ((char *)(newBuf+BUF_UNGET_INC), (char *)bp->outPtr, numBytes+1); + memcpy((char *)(newBuf+BUF_UNGET_INC), (char *)bp->outPtr, + numBytes + 1); bp->outPtr = newBuf + BUF_UNGET_INC; bp->inPtr = bp->outPtr + numBytes; - free ((char *)bp->buffer); + free((char *)bp->buffer); bp->buffer = newBuf; bp->size += BUF_UNGET_INC; bp->left = bp->size - (bp->inPtr - bp->buffer); @@ -182,7 +183,7 @@ Buf_UngetByte (Buffer bp, int byte) *bp->outPtr = byte; } } - + /*- *----------------------------------------------------------------------- * Buf_UngetBytes -- @@ -197,32 +198,32 @@ Buf_UngetByte (Buffer bp, int byte) *----------------------------------------------------------------------- */ void -Buf_UngetBytes (Buffer bp, int numBytes, Byte *bytesPtr) +Buf_UngetBytes(Buffer bp, int numBytes, Byte *bytesPtr) { if (bp->outPtr - bp->buffer >= numBytes) { bp->outPtr -= numBytes; - memcpy (bp->outPtr, bytesPtr, numBytes); + memcpy(bp->outPtr, bytesPtr, numBytes); } else if (bp->outPtr == bp->inPtr) { - Buf_AddBytes (bp, numBytes, bytesPtr); + Buf_AddBytes(bp, numBytes, bytesPtr); } else { int curNumBytes = bp->inPtr - bp->outPtr; Byte *newBuf; int newBytes = max(numBytes,BUF_UNGET_INC); newBuf = (Byte *)emalloc (bp->size + newBytes); - memcpy((char *)(newBuf+newBytes), (char *)bp->outPtr, curNumBytes+1); + memcpy((char *)(newBuf+newBytes), (char *)bp->outPtr, curNumBytes + 1); bp->outPtr = newBuf + newBytes; bp->inPtr = bp->outPtr + curNumBytes; - free ((char *)bp->buffer); + free((char *)bp->buffer); bp->buffer = newBuf; bp->size += newBytes; bp->left = bp->size - (bp->inPtr - bp->buffer); bp->outPtr -= numBytes; - memcpy ((char *)bp->outPtr, (char *)bytesPtr, numBytes); + memcpy((char *)bp->outPtr, (char *)bytesPtr, numBytes); } } - + /*- *----------------------------------------------------------------------- * Buf_GetByte -- @@ -239,14 +240,14 @@ Buf_UngetBytes (Buffer bp, int numBytes, Byte *bytesPtr) *----------------------------------------------------------------------- */ int -Buf_GetByte (Buffer bp) +Buf_GetByte(Buffer bp) { int res; if (bp->inPtr == bp->outPtr) { return (BUF_ERROR); } else { - res = (int) *bp->outPtr; + res = (int)*bp->outPtr; bp->outPtr += 1; if (bp->outPtr == bp->inPtr) { bp->outPtr = bp->inPtr = bp->buffer; @@ -256,7 +257,7 @@ Buf_GetByte (Buffer bp) return (res); } } - + /*- *----------------------------------------------------------------------- * Buf_GetBytes -- @@ -271,13 +272,13 @@ Buf_GetByte (Buffer bp) *----------------------------------------------------------------------- */ int -Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr) +Buf_GetBytes(Buffer bp, int numBytes, Byte *bytesPtr) { if (bp->inPtr - bp->outPtr < numBytes) { numBytes = bp->inPtr - bp->outPtr; } - memcpy (bytesPtr, bp->outPtr, numBytes); + memcpy(bytesPtr, bp->outPtr, numBytes); bp->outPtr += numBytes; if (bp->outPtr == bp->inPtr) { @@ -287,7 +288,7 @@ Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr) } return (numBytes); } - + /*- *----------------------------------------------------------------------- * Buf_GetAll -- @@ -302,7 +303,7 @@ Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr) *----------------------------------------------------------------------- */ Byte * -Buf_GetAll (Buffer bp, int *numBytesPtr) +Buf_GetAll(Buffer bp, int *numBytesPtr) { if (numBytesPtr != (int *)NULL) { @@ -311,7 +312,7 @@ Buf_GetAll (Buffer bp, int *numBytesPtr) return (bp->outPtr); } - + /*- *----------------------------------------------------------------------- * Buf_Discard -- @@ -326,7 +327,7 @@ Buf_GetAll (Buffer bp, int *numBytesPtr) *----------------------------------------------------------------------- */ void -Buf_Discard (Buffer bp, int numBytes) +Buf_Discard(Buffer bp, int numBytes) { if (bp->inPtr - bp->outPtr <= numBytes) { @@ -337,7 +338,7 @@ Buf_Discard (Buffer bp, int numBytes) bp->outPtr += numBytes; } } - + /*- *----------------------------------------------------------------------- * Buf_Size -- @@ -353,11 +354,11 @@ Buf_Discard (Buffer bp, int numBytes) *----------------------------------------------------------------------- */ int -Buf_Size (Buffer buf) +Buf_Size(Buffer buf) { return (buf->inPtr - buf->outPtr); } - + /*- *----------------------------------------------------------------------- * Buf_Init -- @@ -374,7 +375,7 @@ Buf_Size (Buffer buf) *----------------------------------------------------------------------- */ Buffer -Buf_Init (int size) +Buf_Init(int size) { Buffer bp; /* New Buffer */ @@ -390,7 +391,7 @@ Buf_Init (int size) return (bp); } - + /*- *----------------------------------------------------------------------- * Buf_Destroy -- @@ -405,15 +406,15 @@ Buf_Init (int size) *----------------------------------------------------------------------- */ void -Buf_Destroy (Buffer buf, Boolean freeData) +Buf_Destroy(Buffer buf, Boolean freeData) { if (freeData) { - free ((char *)buf->buffer); + free((char *)buf->buffer); } - free ((char *)buf); + free((char *)buf); } - + /*- *----------------------------------------------------------------------- * Buf_ReplaceLastByte -- @@ -429,7 +430,7 @@ Buf_Destroy (Buffer buf, Boolean freeData) *----------------------------------------------------------------------- */ void -Buf_ReplaceLastByte (Buffer buf, int byte) +Buf_ReplaceLastByte(Buffer buf, int byte) { if (buf->inPtr == buf->outPtr) Buf_AddByte(buf, byte); diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index 28403ccd761c..4d075e07326c 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -62,7 +62,7 @@ typedef struct Buffer { /* Buf_AddByte adds a single byte to a buffer. */ #define Buf_AddByte(bp, byte) \ - (void) (--(bp)->left <= 0 ? Buf_OvAddByte(bp, byte), 1 : \ + (void)(--(bp)->left <= 0 ? Buf_OvAddByte(bp, byte), 1 : \ (*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1) #define BUF_ERROR 256 diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index 7fc3cf2e6adc..5ed2fc416389 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -85,8 +85,8 @@ static void CompatInterrupt(int); static int CompatMake(void *, void *); static int shellneed(char *); -static char *sh_builtin[] = { - "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit", +static char *sh_builtin[] = { + "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit", "unalias", "umask", "unset", "wait", ":", 0}; static void @@ -95,7 +95,7 @@ CompatInit(void) char *cp; /* Pointer to string of shell meta-characters */ for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) { - meta[(unsigned char) *cp] = 1; + meta[(unsigned char)*cp] = 1; } /* * The null character serves as a sentinel in the string. @@ -144,12 +144,12 @@ CompatInterrupt (int signo) /* prevent recursion in evaluation of .INTERRUPT */ interrupted = 0; - if ((curTarg != NULL) && !Targ_Precious (curTarg)) { + if ((curTarg != NULL) && !Targ_Precious(curTarg)) { char *p1; - char *file = Var_Value (TARGET, curTarg, &p1); + char *file = Var_Value(TARGET, curTarg, &p1); if (!noExecute && eunlink(file) != -1) { - printf ("*** %s removed\n", file); + printf("*** %s removed\n", file); } free(p1); } @@ -168,21 +168,21 @@ CompatInterrupt (int signo) if (signo == SIGQUIT) exit(signo); - (void) signal(signo, SIG_DFL); - (void) kill(getpid(), signo); + signal(signo, SIG_DFL); + kill(getpid(), signo); } - + /*- *----------------------------------------------------------------------- * shellneed -- - * + * * Results: * Returns 1 if a specified line must be executed by the shell, * 0 if it can be run via execve, and -1 if the command is a no-op. * * Side Effects: * None. - * + * *----------------------------------------------------------------------- */ static int @@ -197,7 +197,7 @@ shellneed (char *cmd) return (1); return (0); } - + /*- *----------------------------------------------------------------------- * Compat_RunCommand -- @@ -214,7 +214,7 @@ shellneed (char *cmd) *----------------------------------------------------------------------- */ int -Compat_RunCommand (void *cmdp, void *gnp) +Compat_RunCommand(void *cmdp, void *gnp) { char *cmdStart; /* Start of expanded command */ char *cp; @@ -230,8 +230,8 @@ Compat_RunCommand (void *cmdp, void *gnp) int argc; /* Number of arguments in av or 0 if not * dynamically allocated */ int internal; /* Various values.. */ - char *cmd = (char *) cmdp; - GNode *gn = (GNode *) gnp; + char *cmd = (char *)cmdp; + GNode *gn = (GNode *)gnp; /* * Avoid clobbered variable warnings by forcing the compiler @@ -245,8 +245,8 @@ Compat_RunCommand (void *cmdp, void *gnp) errCheck = !(gn->type & OP_IGNORE); doit = FALSE; - cmdNode = Lst_Member (gn->commands, (void *)cmd); - cmdStart = Var_Subst (NULL, cmd, gn, FALSE); + cmdNode = Lst_Member(gn->commands, (void *)cmd); + cmdStart = Var_Subst(NULL, cmd, gn, FALSE); /* * brk_string will return an argv with a NULL in av[0], thus causing @@ -258,18 +258,18 @@ Compat_RunCommand (void *cmdp, void *gnp) if (*cmdStart == '\0') { free(cmdStart); Error("%s expands to empty string", cmd); - return(0); + return (0); } else { cmd = cmdStart; } Lst_Replace (cmdNode, (void *)cmdStart); if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) { - (void)Lst_AtEnd(ENDNode->commands, (void *)cmdStart); - return(0); + Lst_AtEnd(ENDNode->commands, (void *)cmdStart); + return (0); } else if (strcmp(cmdStart, "...") == 0) { gn->type |= OP_SAVE_CMDS; - return(0); + return (0); } while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) { @@ -309,7 +309,7 @@ Compat_RunCommand (void *cmdp, void *gnp) * this one. We also print the command if -n given, but not if '+'. */ if (!silent || (noExecute && !doit)) { - printf ("%s\n", cmd); + printf("%s\n", cmd); fflush(stdout); } @@ -374,22 +374,22 @@ Compat_RunCommand (void *cmdp, void *gnp) } if (cpid == 0) { execvp(av[0], av); - (void) write (STDERR_FILENO, av[0], strlen (av[0])); - (void) write (STDERR_FILENO, ":", 1); - (void) write (STDERR_FILENO, strerror(errno), strlen(strerror(errno))); - (void) write (STDERR_FILENO, "\n", 1); + write(STDERR_FILENO, av[0], strlen (av[0])); + write(STDERR_FILENO, ":", 1); + write(STDERR_FILENO, strerror(errno), strlen(strerror(errno))); + write(STDERR_FILENO, "\n", 1); exit(1); } - /* + /* * we need to print out the command associated with this Gnode in * Targ_PrintCmd from Targ_PrintGraph when debugging at level g2, * in main(), Fatal() and DieHorribly(), therefore do not free it - * when debugging. + * when debugging. */ if (!DEBUG(GRAPH2)) { free(cmdStart); - Lst_Replace (cmdNode, cmdp); + Lst_Replace(cmdNode, cmdp); } /* @@ -411,11 +411,11 @@ Compat_RunCommand (void *cmdp, void *gnp) } else if (WIFEXITED(reason)) { status = WEXITSTATUS(reason); /* exited */ if (status != 0) { - printf ("*** Error code %d", status); + printf("*** Error code %d", status); } } else { status = WTERMSIG(reason); /* signaled */ - printf ("*** Signal %d", status); + printf("*** Signal %d", status); } @@ -427,27 +427,27 @@ Compat_RunCommand (void *cmdp, void *gnp) * Abort the current target, but let others * continue. */ - printf (" (continuing)\n"); + printf(" (continuing)\n"); } } else { /* * Continue executing commands for this target. * If we return 0, this will happen... */ - printf (" (ignored)\n"); + printf(" (ignored)\n"); status = 0; } } break; } else { - Fatal ("error in wait: %d", rstat); + Fatal("error in wait: %d", rstat); /*NOTREACHED*/ } } return (status); } - + /*- *----------------------------------------------------------------------- * CompatMake -- @@ -462,10 +462,11 @@ Compat_RunCommand (void *cmdp, void *gnp) *----------------------------------------------------------------------- */ static int -CompatMake (void *gnp, void *pgnp) +CompatMake(void *gnp, void *pgnp) { - GNode *gn = (GNode *) gnp; - GNode *pgn = (GNode *) pgnp; + GNode *gn = (GNode *)gnp; + GNode *pgn = (GNode *)pgnp; + if (gn->type & OP_USE) { Make_HandleUse(gn, pgn); } else if (gn->made == UNMADE) { @@ -479,17 +480,17 @@ CompatMake (void *gnp, void *pgnp) */ gn->make = TRUE; gn->made = BEINGMADE; - Suff_FindDeps (gn); - Lst_ForEach (gn->children, CompatMake, (void *)gn); + Suff_FindDeps(gn); + Lst_ForEach(gn->children, CompatMake, (void *)gn); if (!gn->make) { gn->made = ABORTED; pgn->make = FALSE; return (0); } - if (Lst_Member (gn->iParents, pgn) != NULL) { + if (Lst_Member(gn->iParents, pgn) != NULL) { char *p1; - Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn); + Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn); free(p1); } @@ -500,7 +501,7 @@ CompatMake (void *gnp, void *pgnp) * Make_OODate function. */ DEBUGF(MAKE, ("Examining %s...", gn->name)); - if (! Make_OODate(gn)) { + if (!Make_OODate(gn)) { gn->made = UPTODATE; DEBUGF(MAKE, ("up-to-date.\n")); return (0); @@ -513,7 +514,7 @@ CompatMake (void *gnp, void *pgnp) * to tell him/her "yes". */ if (queryFlag) { - exit (1); + exit(1); } /* @@ -527,24 +528,24 @@ CompatMake (void *gnp, void *pgnp) * Alter our type to tell if errors should be ignored or things * should not be printed so Compat_RunCommand knows what to do. */ - if (Targ_Ignore (gn)) { + if (Targ_Ignore(gn)) { gn->type |= OP_IGNORE; } - if (Targ_Silent (gn)) { + if (Targ_Silent(gn)) { gn->type |= OP_SILENT; } - if (Job_CheckCommands (gn, Fatal)) { + if (Job_CheckCommands(gn, Fatal)) { /* * Our commands are ok, but we still have to worry about the -t * flag... */ if (!touchFlag) { curTarg = gn; - Lst_ForEach (gn->commands, Compat_RunCommand, (void *)gn); + Lst_ForEach(gn->commands, Compat_RunCommand, (void *)gn); curTarg = NULL; } else { - Job_Touch (gn, gn->type & OP_SILENT); + Job_Touch(gn, gn->type & OP_SILENT); } } else { gn->made = ERROR; @@ -623,9 +624,9 @@ CompatMake (void *gnp, void *pgnp) } else { char *p1; - printf ("\n\nStop in %s.\n", Var_Value(".CURDIR", gn, &p1)); + printf("\n\nStop in %s.\n", Var_Value(".CURDIR", gn, &p1)); free(p1); - exit (1); + exit(1); } } else if (gn->made == ERROR) { /* @@ -634,9 +635,9 @@ CompatMake (void *gnp, void *pgnp) */ pgn->make = FALSE; } else { - if (Lst_Member (gn->iParents, pgn) != NULL) { + if (Lst_Member(gn->iParents, pgn) != NULL) { char *p1; - Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn); + Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn); free(p1); } switch(gn->made) { @@ -663,7 +664,7 @@ CompatMake (void *gnp, void *pgnp) return (0); } - + /*- *----------------------------------------------------------------------- * Compat_Run -- @@ -726,14 +727,14 @@ Compat_Run(Lst targs) * could not be made due to errors. */ errors = 0; - while (!Lst_IsEmpty (targs)) { - gn = (GNode *) Lst_DeQueue (targs); - CompatMake (gn, gn); + while (!Lst_IsEmpty(targs)) { + gn = (GNode *)Lst_DeQueue(targs); + CompatMake(gn, gn); if (gn->made == UPTODATE) { - printf ("`%s' is up to date.\n", gn->name); + printf("`%s' is up to date.\n", gn->name); } else if (gn->made == ABORTED) { - printf ("`%s' not remade because of errors.\n", gn->name); + printf("`%s' not remade because of errors.\n", gn->name); errors += 1; } } diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index 194a057a365a..1f99a4e227d6 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -155,11 +155,11 @@ static Boolean skipLine = FALSE; /* Whether the parse module is skipping *----------------------------------------------------------------------- */ static void -CondPushBack (Token t) +CondPushBack(Token t) { condPushBack = t; } - + /*- *----------------------------------------------------------------------- * CondGetArg -- @@ -176,7 +176,7 @@ CondPushBack (Token t) *----------------------------------------------------------------------- */ static int -CondGetArg (char **linePtr, char **argPtr, char *func, Boolean parens) +CondGetArg(char **linePtr, char **argPtr, char *func, Boolean parens) { char *cp; int argLen; @@ -246,7 +246,7 @@ CondGetArg (char **linePtr, char **argPtr, char *func, Boolean parens) cp++; } if (parens && *cp != ')') { - Parse_Error (PARSE_WARNING, "Missing closing parenthesis for %s()", + Parse_Error(PARSE_WARNING, "Missing closing parenthesis for %s()", func); return (0); } else if (parens) { @@ -259,7 +259,7 @@ CondGetArg (char **linePtr, char **argPtr, char *func, Boolean parens) *linePtr = cp; return (argLen); } - + /*- *----------------------------------------------------------------------- * CondDoDefined -- @@ -274,14 +274,14 @@ CondGetArg (char **linePtr, char **argPtr, char *func, Boolean parens) *----------------------------------------------------------------------- */ static Boolean -CondDoDefined (int argLen, char *arg) +CondDoDefined(int argLen, char *arg) { char savec = arg[argLen]; char *p1; Boolean result; arg[argLen] = '\0'; - if (Var_Value (arg, VAR_CMD, &p1) != (char *)NULL) { + if (Var_Value(arg, VAR_CMD, &p1) != (char *)NULL) { result = TRUE; } else { result = FALSE; @@ -290,7 +290,7 @@ CondDoDefined (int argLen, char *arg) arg[argLen] = savec; return (result); } - + /*- *----------------------------------------------------------------------- * CondStrMatch -- @@ -308,9 +308,9 @@ CondDoDefined (int argLen, char *arg) static int CondStrMatch(void *string, void *pattern) { - return(!Str_Match((char *) string,(char *) pattern)); + return (!Str_Match((char *)string, (char *)pattern)); } - + /*- *----------------------------------------------------------------------- * CondDoMake -- @@ -325,13 +325,13 @@ CondStrMatch(void *string, void *pattern) *----------------------------------------------------------------------- */ static Boolean -CondDoMake (int argLen, char *arg) +CondDoMake(int argLen, char *arg) { char savec = arg[argLen]; Boolean result; arg[argLen] = '\0'; - if (Lst_Find (create, (void *)arg, CondStrMatch) == NULL) { + if (Lst_Find(create, (void *)arg, CondStrMatch) == NULL) { result = FALSE; } else { result = TRUE; @@ -339,7 +339,7 @@ CondDoMake (int argLen, char *arg) arg[argLen] = savec; return (result); } - + /*- *----------------------------------------------------------------------- * CondDoExists -- @@ -354,7 +354,7 @@ CondDoMake (int argLen, char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoExists (int argLen, char *arg) +CondDoExists(int argLen, char *arg) { char savec = arg[argLen]; Boolean result; @@ -371,7 +371,7 @@ CondDoExists (int argLen, char *arg) arg[argLen] = savec; return (result); } - + /*- *----------------------------------------------------------------------- * CondDoTarget -- @@ -386,7 +386,7 @@ CondDoExists (int argLen, char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoTarget (int argLen, char *arg) +CondDoTarget(int argLen, char *arg) { char savec = arg[argLen]; Boolean result; @@ -403,7 +403,6 @@ CondDoTarget (int argLen, char *arg) return (result); } - /*- *----------------------------------------------------------------------- * CondCvtArg -- @@ -431,12 +430,12 @@ CondCvtArg(char *str, double *value) for (str += 2, i = 0; ; str++) { int x; - if (isdigit((unsigned char) *str)) + if (isdigit((unsigned char)*str)) x = *str - '0'; - else if (isxdigit((unsigned char) *str)) - x = 10 + *str - isupper((unsigned char) *str) ? 'A' : 'a'; + else if (isxdigit((unsigned char)*str)) + x = 10 + *str - isupper((unsigned char)*str) ? 'A' : 'a'; else { - *value = (double) i; + *value = (double)i; return str; } i = (i << 4) + x; @@ -445,10 +444,10 @@ CondCvtArg(char *str, double *value) else { char *eptr; *value = strtod(str, &eptr); - return eptr; + return (eptr); } } - + /*- *----------------------------------------------------------------------- * CondToken -- @@ -514,17 +513,18 @@ CondToken(Boolean doEval) * value in lhs. */ t = Err; - lhs = Var_Parse(condExpr, VAR_CMD, doEval,&varSpecLen,&doFree); + lhs = Var_Parse(condExpr, VAR_CMD, doEval, + &varSpecLen, &doFree); if (lhs == var_Error) { /* * Even if !doEval, we still report syntax errors, which * is what getting var_Error back with !doEval means. */ - return(Err); + return (Err); } condExpr += varSpecLen; - if (!isspace((unsigned char) *condExpr) && + if (!isspace((unsigned char)*condExpr) && strchr("!=><", *condExpr) == NULL) { Buffer buf; char *cp; @@ -551,7 +551,7 @@ CondToken(Boolean doEval) /* * Skip whitespace to get to the operator */ - while (isspace((unsigned char) *condExpr)) + while (isspace((unsigned char)*condExpr)) condExpr++; /* @@ -577,7 +577,7 @@ CondToken(Boolean doEval) goto do_compare; } - while (isspace((unsigned char) *condExpr)) { + while (isspace((unsigned char)*condExpr)) { condExpr++; } if (*condExpr == '\0') { @@ -622,7 +622,7 @@ CondToken(Boolean doEval) int len; Boolean freeIt; - cp2 = Var_Parse(cp, VAR_CMD, doEval,&len, &freeIt); + cp2 = Var_Parse(cp, VAR_CMD, doEval, &len, &freeIt); if (cp2 != var_Error) { Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); if (freeIt) { @@ -674,7 +674,7 @@ CondToken(Boolean doEval) int len; Boolean freeIt; - string = Var_Parse(rhs, VAR_CMD, doEval,&len,&freeIt); + string = Var_Parse(rhs, VAR_CMD, doEval, &len, &freeIt); if (string == var_Error) { right = 0.0; } else { @@ -702,7 +702,7 @@ CondToken(Boolean doEval) DEBUGF(COND, ("left = %f, right = %f, op = %.2s\n", left, right, op)); - switch(op[0]) { + switch (op[0]) { case '!': if (op[1] != '=') { Parse_Error(PARSE_WARNING, @@ -748,7 +748,7 @@ CondToken(Boolean doEval) char *arg; int arglen; - if (strncmp (condExpr, "defined", 7) == 0) { + if (strncmp(condExpr, "defined", 7) == 0) { /* * Use CondDoDefined to evaluate the argument and * CondGetArg to extract the argument from the 'function @@ -756,12 +756,12 @@ CondToken(Boolean doEval) */ evalProc = CondDoDefined; condExpr += 7; - arglen = CondGetArg (&condExpr, &arg, "defined", TRUE); + arglen = CondGetArg(&condExpr, &arg, "defined", TRUE); if (arglen == 0) { condExpr -= 7; goto use_default; } - } else if (strncmp (condExpr, "make", 4) == 0) { + } else if (strncmp(condExpr, "make", 4) == 0) { /* * Use CondDoMake to evaluate the argument and * CondGetArg to extract the argument from the 'function @@ -769,12 +769,12 @@ CondToken(Boolean doEval) */ evalProc = CondDoMake; condExpr += 4; - arglen = CondGetArg (&condExpr, &arg, "make", TRUE); + arglen = CondGetArg(&condExpr, &arg, "make", TRUE); if (arglen == 0) { condExpr -= 4; goto use_default; } - } else if (strncmp (condExpr, "exists", 6) == 0) { + } else if (strncmp(condExpr, "exists", 6) == 0) { /* * Use CondDoExists to evaluate the argument and * CondGetArg to extract the argument from the @@ -832,7 +832,7 @@ CondToken(Boolean doEval) goto use_default; } break; - } else if (strncmp (condExpr, "target", 6) == 0) { + } else if (strncmp(condExpr, "target", 6) == 0) { /* * Use CondDoTarget to evaluate the argument and * CondGetArg to extract the argument from the @@ -876,7 +876,7 @@ CondToken(Boolean doEval) } return (t); } - + /*- *----------------------------------------------------------------------- * CondT -- @@ -927,7 +927,7 @@ CondT(Boolean doEval) } return (t); } - + /*- *----------------------------------------------------------------------- * CondF -- @@ -962,18 +962,18 @@ CondF(Boolean doEval) if (l == True) { l = CondF(doEval); } else { - (void) CondF(FALSE); + CondF(FALSE); } } else { /* * F -> T */ - CondPushBack (o); + CondPushBack(o); } } return (l); } - + /*- *----------------------------------------------------------------------- * CondE -- @@ -1009,18 +1009,18 @@ CondE(Boolean doEval) if (l == False) { l = CondE(doEval); } else { - (void) CondE(FALSE); + CondE(FALSE); } } else { /* * E -> F */ - CondPushBack (o); + CondPushBack(o); } } return (l); } - + /*- *----------------------------------------------------------------------- * Cond_Eval -- @@ -1043,7 +1043,7 @@ CondE(Boolean doEval) *----------------------------------------------------------------------- */ int -Cond_Eval (char *line) +Cond_Eval(char *line) { struct If *ifp; Boolean isElse; @@ -1065,7 +1065,7 @@ Cond_Eval (char *line) if (line[0] == 'e' && line[1] == 'l') { line += 2; isElse = TRUE; - } else if (strncmp (line, "endif", 5) == 0) { + } else if (strncmp(line, "endif", 5) == 0) { /* * End of a conditional section. If skipIfLevel is non-zero, that * conditional was skipped, so lines following it should also be @@ -1079,7 +1079,7 @@ Cond_Eval (char *line) return (COND_SKIP); } else { if (condTop == MAXIF) { - Parse_Error (level, "if-less endif"); + Parse_Error(level, "if-less endif"); return (COND_INVALID); } else { skipLine = FALSE; @@ -1096,12 +1096,12 @@ Cond_Eval (char *line) * function is, etc. -- by looking in the table of valid "ifs" */ for (ifp = ifs; ifp->form != (char *)0; ifp++) { - if (strncmp (ifp->form, line, ifp->formlen) == 0) { + if (strncmp(ifp->form, line, ifp->formlen) == 0) { break; } } - if (ifp->form == (char *) 0) { + if (ifp->form == (char *)0) { /* * Nothing fit. If the first word on the line is actually * "else", it's a valid conditional whose value is the inverse @@ -1109,7 +1109,7 @@ Cond_Eval (char *line) */ if (isElse && (line[0] == 's') && (line[1] == 'e')) { if (condTop == MAXIF) { - Parse_Error (level, "if-less else"); + Parse_Error(level, "if-less else"); return (COND_INVALID); } else if (skipIfLevel == 0) { value = !condStack[condTop]; @@ -1126,7 +1126,7 @@ Cond_Eval (char *line) } else { if (isElse) { if (condTop == MAXIF) { - Parse_Error (level, "if-less elif"); + Parse_Error(level, "if-less elif"); return (COND_INVALID); } else if (skipIfLevel != 0) { /* @@ -1136,7 +1136,7 @@ Cond_Eval (char *line) * we're skipping... */ skipIfLineno[skipIfLevel - 1] = lineno; - return(COND_SKIP); + return (COND_SKIP); } } else if (skipLine) { /* @@ -1145,7 +1145,7 @@ Cond_Eval (char *line) */ skipIfLineno[skipIfLevel] = lineno; skipIfLevel += 1; - return(COND_SKIP); + return (COND_SKIP); } /* @@ -1179,7 +1179,7 @@ Cond_Eval (char *line) /*FALLTHRU*/ case Err: err: - Parse_Error (level, "Malformed conditional (%s)", + Parse_Error(level, "Malformed conditional (%s)", line); return (COND_INVALID); default: @@ -1205,7 +1205,7 @@ Cond_Eval (char *line) * This is the one case where we can definitely proclaim a fatal * error. If we don't, we're hosed. */ - Parse_Error (PARSE_FATAL, "Too many nested if's. %d max.", MAXIF); + Parse_Error(PARSE_FATAL, "Too many nested if's. %d max.", MAXIF); return (COND_INVALID); } else { condStack[condTop] = value; @@ -1214,7 +1214,7 @@ Cond_Eval (char *line) return (value ? COND_PARSE : COND_SKIP); } } - + /*- *----------------------------------------------------------------------- * Cond_End -- diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index 4f520e6bb1fc..27465d45ea67 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -209,10 +209,11 @@ static int DirPrintDir(void *, void *); *----------------------------------------------------------------------- */ void -Dir_Init (void) +Dir_Init(void) { - dirSearchPath = Lst_Init (FALSE); - openDirectories = Lst_Init (FALSE); + + dirSearchPath = Lst_Init(FALSE); + openDirectories = Lst_Init(FALSE); Hash_InitTable(&mtimes, 0); } @@ -229,11 +230,11 @@ Dir_Init (void) *----------------------------------------------------------------------- */ void -Dir_InitDot (void) +Dir_InitDot(void) { LstNode ln; - Dir_AddDir (openDirectories, "."); + Dir_AddDir(openDirectories, "."); if ((ln = Lst_Last(openDirectories)) == NULL) err(1, "cannot open current directory"); dot = Lst_Datum(ln); @@ -260,6 +261,7 @@ Dir_InitDot (void) void Dir_End(void) { + dot->refCount -= 1; Dir_Destroy((void *) dot); Dir_ClearPath(dirSearchPath); @@ -284,9 +286,9 @@ Dir_End(void) *----------------------------------------------------------------------- */ static int -DirFindName (void *p, void *dname) +DirFindName(void *p, void *dname) { - return (strcmp (((Path *)p)->name, (char *) dname)); + return (strcmp(((Path *)p)->name, (char *)dname)); } /*- @@ -302,13 +304,13 @@ DirFindName (void *p, void *dname) *----------------------------------------------------------------------- */ Boolean -Dir_HasWildcards (char *name) +Dir_HasWildcards(char *name) { char *cp; int wild = 0, brace = 0, bracket = 0; for (cp = name; *cp; cp++) { - switch(*cp) { + switch (*cp) { case '{': brace++; wild = 1; @@ -331,7 +333,7 @@ Dir_HasWildcards (char *name) break; } } - return wild && bracket == 0 && brace == 0; + return (wild && bracket == 0 && brace == 0); } /*- @@ -352,7 +354,7 @@ Dir_HasWildcards (char *name) *----------------------------------------------------------------------- */ static int -DirMatchFiles (char *pattern, Path *p, Lst expansions) +DirMatchFiles(char *pattern, Path *p, Lst expansions) { Hash_Search search; /* Index into the directory's table */ Hash_Entry *entry; /* Current entry in the table */ @@ -374,7 +376,7 @@ DirMatchFiles (char *pattern, Path *p, Lst expansions) ((entry->name[0] != '.') || (pattern[0] == '.'))) { - (void)Lst_AtEnd(expansions, + Lst_AtEnd(expansions, (isDot ? estrdup(entry->name) : str_concat(p->name, entry->name, STR_ADDSLASH))); @@ -418,7 +420,7 @@ DirExpandCurly(char *word, char *brace, Lst path, Lst expansions) char *cp2; /* Pointer for checking for wildcards in * expansion before calling Dir_Expand */ - start = brace+1; + start = brace + 1; /* * Find the end of the brace clause first, being wary of nested brace @@ -457,12 +459,12 @@ DirExpandCurly(char *word, char *brace, Lst path, Lst expansions) */ file = emalloc(otherLen + cp - start + 1); if (brace != word) { - strncpy(file, word, brace-word); + strncpy(file, word, brace - word); } if (cp != start) { - strncpy(&file[brace-word], start, cp-start); + strncpy(&file[brace - word], start, cp - start); } - strcpy(&file[(brace-word)+(cp-start)], end); + strcpy(&file[(brace - word) + (cp - start)], end); /* * See if the result has any wildcards in it. If we find one, call @@ -486,7 +488,7 @@ DirExpandCurly(char *word, char *brace, Lst path, Lst expansions) * Hit the end w/o finding any wildcards, so stick the expansion * on the end of the list. */ - (void)Lst_AtEnd(expansions, file); + Lst_AtEnd(expansions, file); } else { next: free(file); @@ -544,7 +546,8 @@ DirExpandInt(char *word, Lst path, Lst expansions) static int DirPrintWord(void *word, void *dummy __unused) { - DEBUGF(DIR, ("%s ", (char *) word)); + + DEBUGF(DIR, ("%s ", (char *)word)); return (0); } @@ -564,7 +567,7 @@ DirPrintWord(void *word, void *dummy __unused) *----------------------------------------------------------------------- */ void -Dir_Expand (char *word, Lst path, Lst expansions) +Dir_Expand(char *word, Lst path, Lst expansions) { char *cp; @@ -675,7 +678,7 @@ Dir_Expand (char *word, Lst path, Lst expansions) *----------------------------------------------------------------------- */ char * -Dir_FindFile (char *name, Lst path) +Dir_FindFile(char *name, Lst path) { char *p1; /* pointer into p->name */ char *p2; /* pointer into name */ @@ -691,7 +694,7 @@ Dir_FindFile (char *name, Lst path) * Find the final component of the name and note whether it has a * slash in it (the name, I mean) */ - cp = strrchr (name, '/'); + cp = strrchr(name, '/'); if (cp) { hasSlash = TRUE; cp += 1; @@ -708,17 +711,17 @@ Dir_FindFile (char *name, Lst path) * (fish.c) and what pmake finds (./fish.c). */ if ((!hasSlash || (cp - name == 2 && *name == '.')) && - (Hash_FindEntry (&dot->files, cp) != (Hash_Entry *)NULL)) { + (Hash_FindEntry(&dot->files, cp) != (Hash_Entry *)NULL)) { DEBUGF(DIR, ("in '.'\n")); hits += 1; dot->hits += 1; - return (estrdup (name)); + return (estrdup(name)); } - if (Lst_Open (path) == FAILURE) { + if (Lst_Open(path) == FAILURE) { DEBUGF(DIR, ("couldn't open path, file not found\n")); misses += 1; - return ((char *) NULL); + return ((char *)NULL); } /* @@ -729,10 +732,10 @@ Dir_FindFile (char *name, Lst path) * and return the resulting string. If we don't find any such thing, * we go on to phase two... */ - while ((ln = Lst_Next (path)) != NULL) { - p = (Path *) Lst_Datum (ln); + while ((ln = Lst_Next(path)) != NULL) { + p = (Path *)Lst_Datum (ln); DEBUGF(DIR, ("%s...", p->name)); - if (Hash_FindEntry (&p->files, cp) != (Hash_Entry *)NULL) { + if (Hash_FindEntry(&p->files, cp) != (Hash_Entry *)NULL) { DEBUGF(DIR, ("here...")); if (hasSlash) { /* @@ -743,7 +746,7 @@ Dir_FindFile (char *name, Lst path) * we matched only part of one of the components of p * along with all the rest of them (*p1 != '/'). */ - p1 = p->name + strlen (p->name) - 1; + p1 = p->name + strlen(p->name) - 1; p2 = cp - 2; while (p2 >= name && p1 >= p->name && *p1 == *p2) { p1 -= 1; p2 -= 1; @@ -753,9 +756,9 @@ Dir_FindFile (char *name, Lst path) continue; } } - file = str_concat (p->name, cp, STR_ADDSLASH); + file = str_concat(p->name, cp, STR_ADDSLASH); DEBUGF(DIR, ("returning %s\n", file)); - Lst_Close (path); + Lst_Close(path); p->hits += 1; hits += 1; return (file); @@ -769,13 +772,13 @@ Dir_FindFile (char *name, Lst path) continue; } if (*p1 == '\0' && p2 == cp - 1) { - Lst_Close (path); + Lst_Close(path); if (*cp == '\0' || ISDOT(cp) || ISDOTDOT(cp)) { DEBUGF(DIR, ("returning %s\n", name)); return (estrdup(name)); } else { DEBUGF(DIR, ("must be here but isn't -- returning NULL\n")); - return ((char *) NULL); + return ((char *)NULL); } } } @@ -796,18 +799,18 @@ Dir_FindFile (char *name, Lst path) if (!hasSlash) { DEBUGF(DIR, ("failed.\n")); misses += 1; - return ((char *) NULL); + return ((char *)NULL); } if (*name != '/') { Boolean checkedDot = FALSE; DEBUGF(DIR, ("failed. Trying subdirectories...")); - (void) Lst_Open (path); - while ((ln = Lst_Next (path)) != NULL) { - p = (Path *) Lst_Datum (ln); + Lst_Open(path); + while ((ln = Lst_Next(path)) != NULL) { + p = (Path *)Lst_Datum(ln); if (p != dot) { - file = str_concat (p->name, name, STR_ADDSLASH); + file = str_concat(p->name, name, STR_ADDSLASH); } else { /* * Checking in dot -- DON'T put a leading ./ on the thing. @@ -817,10 +820,10 @@ Dir_FindFile (char *name, Lst path) } DEBUGF(DIR, ("checking %s...", file)); - if (stat (file, &stb) == 0) { + if (stat(file, &stb) == 0) { DEBUGF(DIR, ("got it.\n")); - Lst_Close (path); + Lst_Close(path); /* * We've found another directory to search. We know there's @@ -832,9 +835,9 @@ Dir_FindFile (char *name, Lst path) * again in such a manner, we will find it without having to do * numerous numbers of access calls. Hurrah! */ - cp = strrchr (file, '/'); + cp = strrchr(file, '/'); *cp = '\0'; - Dir_AddDir (path, file); + Dir_AddDir(path, file); *cp = '/'; /* @@ -842,18 +845,18 @@ Dir_FindFile (char *name, Lst path) * to fetch it again. */ DEBUGF(DIR, ("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime), file)); - entry = Hash_CreateEntry(&mtimes, (char *) file, + entry = Hash_CreateEntry(&mtimes, (char *)file, (Boolean *)NULL); Hash_SetValue(entry, (long)stb.st_mtime); nearmisses += 1; return (file); } else { - free (file); + free(file); } } DEBUGF(DIR, ("failed. ")); - Lst_Close (path); + Lst_Close(path); if (checkedDot) { /* @@ -861,7 +864,7 @@ Dir_FindFile (char *name, Lst path) * so no point in proceeding... */ DEBUGF(DIR, ("Checked . already, returning NULL\n")); - return(NULL); + return (NULL); } } @@ -884,21 +887,21 @@ Dir_FindFile (char *name, Lst path) */ #ifdef notdef cp[-1] = '\0'; - Dir_AddDir (path, name); + Dir_AddDir(path, name); cp[-1] = '/'; bigmisses += 1; - ln = Lst_Last (path); + ln = Lst_Last(path); if (ln == NULL) { - return ((char *) NULL); + return ((char *)NULL); } else { - p = (Path *) Lst_Datum (ln); + p = (Path *)Lst_Datum (ln); } - if (Hash_FindEntry (&p->files, cp) != (Hash_Entry *)NULL) { - return (estrdup (name)); + if (Hash_FindEntry(&p->files, cp) != (Hash_Entry *)NULL) { + return (estrdup(name)); } else { - return ((char *) NULL); + return ((char *)NULL); } #else /* !notdef */ DEBUGF(DIR, ("Looking for \"%s\"...", name)); @@ -912,7 +915,7 @@ Dir_FindFile (char *name, Lst path) entry = Hash_CreateEntry(&mtimes, name, (Boolean *)NULL); DEBUGF(DIR, ("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime), name)); Hash_SetValue(entry, (long)stb.st_mtime); - return (estrdup (name)); + return (estrdup(name)); } else { DEBUGF(DIR, ("failed. Returning NULL\n")); return ((char *)NULL); @@ -936,16 +939,16 @@ Dir_FindFile (char *name, Lst path) *----------------------------------------------------------------------- */ int -Dir_MTime (GNode *gn) +Dir_MTime(GNode *gn) { char *fullName; /* the full pathname of name */ struct stat stb; /* buffer for finding the mod time */ Hash_Entry *entry; if (gn->type & OP_ARCHV) { - return Arch_MTime (gn); + return (Arch_MTime(gn)); } else if (gn->path == (char *)NULL) { - fullName = Dir_FindFile (gn->name, dirSearchPath); + fullName = Dir_FindFile(gn->name, dirSearchPath); } else { fullName = gn->path; } @@ -965,11 +968,11 @@ Dir_MTime (GNode *gn) Targ_FmtTime((time_t)(long)Hash_GetValue(entry)), fullName)); stb.st_mtime = (time_t)(long)Hash_GetValue(entry); Hash_DeleteEntry(&mtimes, entry); - } else if (stat (fullName, &stb) < 0) { + } else if (stat(fullName, &stb) < 0) { if (gn->type & OP_MEMBER) { if (fullName != gn->path) free(fullName); - return Arch_MemMTime (gn); + return (Arch_MemMTime(gn)); } else { stb.st_mtime = 0; } @@ -998,31 +1001,31 @@ Dir_MTime (GNode *gn) *----------------------------------------------------------------------- */ void -Dir_AddDir (Lst path, char *name) +Dir_AddDir(Lst path, char *name) { LstNode ln; /* node in case Path structure is found */ Path *p; /* pointer to new Path structure */ DIR *d; /* for reading directory */ struct dirent *dp; /* entry in directory */ - ln = Lst_Find (openDirectories, (void *)name, DirFindName); + ln = Lst_Find(openDirectories, (void *)name, DirFindName); if (ln != NULL) { - p = (Path *)Lst_Datum (ln); + p = (Path *)Lst_Datum(ln); if (Lst_Member(path, (void *)p) == NULL) { p->refCount += 1; - (void)Lst_AtEnd (path, (void *)p); + Lst_AtEnd(path, (void *)p); } } else { DEBUGF(DIR, ("Caching %s...", name)); - if ((d = opendir (name)) != (DIR *) NULL) { - p = (Path *) emalloc (sizeof (Path)); - p->name = estrdup (name); + if ((d = opendir(name)) != (DIR *)NULL) { + p = (Path *) emalloc(sizeof(Path)); + p->name = estrdup(name); p->hits = 0; p->refCount = 1; - Hash_InitTable (&p->files, -1); + Hash_InitTable(&p->files, -1); - while ((dp = readdir (d)) != (struct dirent *) NULL) { + while ((dp = readdir(d)) != (struct dirent *)NULL) { #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */ /* * The sun directory library doesn't check for a 0 inode @@ -1044,12 +1047,12 @@ Dir_AddDir (Lst path, char *name) if (ISDOT(dp->d_name) || ISDOTDOT(dp->d_name)) continue; - (void)Hash_CreateEntry(&p->files, dp->d_name, (Boolean *)NULL); + Hash_CreateEntry(&p->files, dp->d_name, (Boolean *)NULL); } - (void) closedir (d); - (void)Lst_AtEnd (openDirectories, (void *)p); + closedir(d); + Lst_AtEnd(openDirectories, (void *)p); if (path != openDirectories) - (void)Lst_AtEnd (path, (void *)p); + Lst_AtEnd(path, (void *)p); } DEBUGF(DIR, ("done\n")); } @@ -1072,7 +1075,8 @@ Dir_AddDir (Lst path, char *name) void * Dir_CopyDir(void *p) { - ((Path *) p)->refCount += 1; + + ((Path *)p)->refCount += 1; return ((void *)p); } @@ -1095,22 +1099,22 @@ Dir_CopyDir(void *p) *----------------------------------------------------------------------- */ char * -Dir_MakeFlags (char *flag, Lst path) +Dir_MakeFlags(char *flag, Lst path) { char *str; /* the string which will be returned */ char *tstr; /* the current directory preceded by 'flag' */ LstNode ln; /* the node of the current directory */ Path *p; /* the structure describing the current directory */ - str = estrdup (""); + str = estrdup(""); - if (Lst_Open (path) == SUCCESS) { - while ((ln = Lst_Next (path)) != NULL) { - p = (Path *) Lst_Datum (ln); - tstr = str_concat (flag, p->name, 0); - str = str_concat (str, tstr, STR_ADDSPACE | STR_DOFREE); + if (Lst_Open(path) == SUCCESS) { + while ((ln = Lst_Next(path)) != NULL) { + p = (Path *)Lst_Datum(ln); + tstr = str_concat(flag, p->name, 0); + str = str_concat(str, tstr, STR_ADDSPACE | STR_DOFREE); } - Lst_Close (path); + Lst_Close(path); } return (str); @@ -1132,18 +1136,18 @@ Dir_MakeFlags (char *flag, Lst path) *----------------------------------------------------------------------- */ void -Dir_Destroy (void *pp) +Dir_Destroy(void *pp) { - Path *p = (Path *) pp; + Path *p = (Path *)pp; p->refCount -= 1; if (p->refCount == 0) { LstNode ln; - ln = Lst_Member (openDirectories, (void *)p); - (void) Lst_Remove (openDirectories, ln); + ln = Lst_Member(openDirectories, (void *)p); + Lst_Remove(openDirectories, ln); - Hash_DeleteTable (&p->files); + Hash_DeleteTable(&p->files); free(p->name); free(p); } @@ -1167,6 +1171,7 @@ void Dir_ClearPath(Lst path) { Path *p; + while (!Lst_IsEmpty(path)) { p = (Path *)Lst_DeQueue(path); Dir_Destroy((void *) p); @@ -1198,7 +1203,7 @@ Dir_Concat(Lst path1, Lst path2) p = (Path *)Lst_Datum(ln); if (Lst_Member(path1, (void *)p) == NULL) { p->refCount += 1; - (void)Lst_AtEnd(path1, (void *)p); + Lst_AtEnd(path1, (void *)p); } } } @@ -1210,31 +1215,33 @@ Dir_PrintDirectories(void) LstNode ln; Path *p; - printf ("#*** Directory Cache:\n"); - printf ("# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n", + printf("#*** Directory Cache:\n"); + printf("# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n", hits, misses, nearmisses, bigmisses, - (hits+bigmisses+nearmisses ? + (hits + bigmisses + nearmisses ? hits * 100 / (hits + bigmisses + nearmisses) : 0)); - printf ("# %-20s referenced\thits\n", "directory"); - if (Lst_Open (openDirectories) == SUCCESS) { - while ((ln = Lst_Next (openDirectories)) != NULL) { - p = (Path *) Lst_Datum (ln); - printf ("# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits); + printf("# %-20s referenced\thits\n", "directory"); + if (Lst_Open(openDirectories) == SUCCESS) { + while ((ln = Lst_Next(openDirectories)) != NULL) { + p = (Path *)Lst_Datum(ln); + printf("# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits); } - Lst_Close (openDirectories); + Lst_Close(openDirectories); } } static int -DirPrintDir (void *p, void *dummy __unused) +DirPrintDir(void *p, void *dummy __unused) { - printf ("%s ", ((Path *) p)->name); + + printf("%s ", ((Path *)p)->name); return (0); } void -Dir_PrintPath (Lst path) +Dir_PrintPath(Lst path) { - Lst_ForEach (path, DirPrintDir, (void *)0); + + Lst_ForEach(path, DirPrintDir, (void *)0); } diff --git a/usr.bin/make/dir.h b/usr.bin/make/dir.h index 549d531e6fc7..38257c1b49c8 100644 --- a/usr.bin/make/dir.h +++ b/usr.bin/make/dir.h @@ -68,6 +68,6 @@ void Dir_Concat(Lst, Lst); void Dir_PrintDirectories(void); void Dir_PrintPath(Lst); void Dir_Destroy(void *); -void * Dir_CopyDir(void *); +void *Dir_CopyDir(void *); #endif /* _DIR */ diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c index 16c8ebfc5a7d..d7ed7c7fd0c2 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -86,9 +86,6 @@ typedef struct _For { static int ForExec(void *, void *); - - - /*- *----------------------------------------------------------------------- * For_Eval -- @@ -107,7 +104,7 @@ static int ForExec(void *, void *); *----------------------------------------------------------------------- */ int -For_Eval (char *line) +For_Eval(char *line) { char *ptr = line, *sub, *wrd; int level; /* Level at which to report errors. */ @@ -119,53 +116,53 @@ For_Eval (char *line) Buffer buf; int varlen; - for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++) + for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++) continue; /* * If we are not in a for loop quickly determine if the statement is * a for. */ if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' || - !isspace((unsigned char) ptr[3])) - return FALSE; + !isspace((unsigned char)ptr[3])) + return (FALSE); ptr += 3; /* * we found a for loop, and now we are going to parse it. */ - while (*ptr && isspace((unsigned char) *ptr)) + while (*ptr && isspace((unsigned char)*ptr)) ptr++; /* * Grab the variable */ buf = Buf_Init(0); - for (wrd = ptr; *ptr && !isspace((unsigned char) *ptr); ptr++) + for (wrd = ptr; *ptr && !isspace((unsigned char)*ptr); ptr++) continue; - Buf_AddBytes(buf, ptr - wrd, (Byte *) wrd); + Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd); - forVar = (char *) Buf_GetAll(buf, &varlen); + forVar = (char *)Buf_GetAll(buf, &varlen); if (varlen == 0) { - Parse_Error (level, "missing variable in for"); - return 0; + Parse_Error(level, "missing variable in for"); + return (0); } Buf_Destroy(buf, FALSE); - while (*ptr && isspace((unsigned char) *ptr)) + while (*ptr && isspace((unsigned char)*ptr)) ptr++; /* * Grab the `in' */ if (ptr[0] != 'i' || ptr[1] != 'n' || - !isspace((unsigned char) ptr[2])) { - Parse_Error (level, "missing `in' in for"); + !isspace((unsigned char)ptr[2])) { + Parse_Error(level, "missing `in' in for"); printf("%s\n", ptr); - return 0; + return (0); } ptr += 3; - while (*ptr && isspace((unsigned char) *ptr)) + while (*ptr && isspace((unsigned char)*ptr)) ptr++; /* @@ -176,19 +173,19 @@ For_Eval (char *line) sub = Var_Subst(NULL, ptr, VAR_CMD, FALSE); #define ADDWORD() \ - Buf_AddBytes(buf, ptr - wrd, (Byte *) wrd), \ - Buf_AddByte(buf, (Byte) '\0'), \ - Lst_AtFront(forLst, (void *) Buf_GetAll(buf, &varlen)), \ + Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd), \ + Buf_AddByte(buf, (Byte)'\0'), \ + Lst_AtFront(forLst, (void *)Buf_GetAll(buf, &varlen)), \ Buf_Destroy(buf, FALSE) - for (ptr = sub; *ptr && isspace((unsigned char) *ptr); ptr++) + for (ptr = sub; *ptr && isspace((unsigned char)*ptr); ptr++) continue; for (wrd = ptr; *ptr; ptr++) - if (isspace((unsigned char) *ptr)) { + if (isspace((unsigned char)*ptr)) { ADDWORD(); buf = Buf_Init(0); - while (*ptr && isspace((unsigned char) *ptr)) + while (*ptr && isspace((unsigned char)*ptr)) ptr++; wrd = ptr--; } @@ -201,35 +198,35 @@ For_Eval (char *line) forBuf = Buf_Init(0); forLevel++; - return 1; + return (1); } else if (*ptr == '.') { - for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++) + for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++) continue; if (strncmp(ptr, "endfor", 6) == 0 && - (isspace((unsigned char) ptr[6]) || !ptr[6])) { + (isspace((unsigned char)ptr[6]) || !ptr[6])) { DEBUGF(FOR, ("For: end for %d\n", forLevel)); if (--forLevel < 0) { - Parse_Error (level, "for-less endfor"); - return 0; + Parse_Error(level, "for-less endfor"); + return (0); } } else if (strncmp(ptr, "for", 3) == 0 && - isspace((unsigned char) ptr[3])) { + isspace((unsigned char)ptr[3])) { forLevel++; DEBUGF(FOR, ("For: new loop %d\n", forLevel)); } } if (forLevel != 0) { - Buf_AddBytes(forBuf, strlen(line), (Byte *) line); - Buf_AddByte(forBuf, (Byte) '\n'); - return 1; + Buf_AddBytes(forBuf, strlen(line), (Byte *)line); + Buf_AddByte(forBuf, (Byte)'\n'); + return (1); } else { - return 0; + return (0); } } @@ -254,14 +251,13 @@ ForExec(void *namep, void *argp) int len; Var_Set(arg->var, name, VAR_GLOBAL); DEBUGF(FOR, ("--- %s = %s\n", arg->var, name)); - Parse_FromString(Var_Subst(arg->var, (char *) Buf_GetAll(arg->buf, &len), + Parse_FromString(Var_Subst(arg->var, (char *)Buf_GetAll(arg->buf, &len), VAR_GLOBAL, FALSE), arg->lineno); Var_Delete(arg->var, VAR_GLOBAL); - return 0; + return (0); } - /*- *----------------------------------------------------------------------- * For_Run -- @@ -290,7 +286,7 @@ For_Run(int lineno) forBuf = NULL; forLst = NULL; - Lst_ForEach(arg.lst, ForExec, (void *) &arg); + Lst_ForEach(arg.lst, ForExec, (void *)&arg); free(arg.var); Lst_Destroy(arg.lst, free); diff --git a/usr.bin/make/hash.c b/usr.bin/make/hash.c index 7d2c64dcc48a..f3103dd95755 100644 --- a/usr.bin/make/hash.c +++ b/usr.bin/make/hash.c @@ -72,7 +72,7 @@ static void RebuildTable(Hash_Table *); *--------------------------------------------------------- * * Hash_InitTable -- - * + * * Set up the hash table t with a given number of buckets, or a * reasonable default if the number requested is less than or * equal to zero. Hash tables will grow in size as needed. @@ -234,13 +234,13 @@ Hash_CreateEntry(Hash_Table *t, char *key, Boolean *newPtr) */ if (t->numEntries >= rebuildLimit * t->size) RebuildTable(t); - e = (Hash_Entry *) emalloc(sizeof(*e) + keylen); + e = (Hash_Entry *)emalloc(sizeof(*e) + keylen); hp = &t->bucketPtr[h & t->mask]; e->next = *hp; *hp = e; e->clientData = NULL; e->namehash = h; - (void) strcpy(e->name, p); + strcpy(e->name, p); t->numEntries++; if (newPtr != NULL) @@ -281,7 +281,7 @@ Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e) return; } } - (void) write(STDERR_FILENO, "bad call to Hash_DeleteEntry\n", 29); + write(STDERR_FILENO, "bad call to Hash_DeleteEntry\n", 29); abort(); } @@ -307,10 +307,11 @@ Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e) Hash_Entry * Hash_EnumFirst(Hash_Table *t, Hash_Search *searchPtr) { + searchPtr->tablePtr = t; searchPtr->nextIndex = 0; searchPtr->hashEntryPtr = NULL; - return Hash_EnumNext(searchPtr); + return (Hash_EnumNext(searchPtr)); } /* @@ -388,7 +389,7 @@ RebuildTable(Hash_Table *t) i <<= 1; t->size = i; t->mask = mask = i - 1; - t->bucketPtr = hp = (struct Hash_Entry **) emalloc(sizeof(*hp) * i); + t->bucketPtr = hp = (struct Hash_Entry **)emalloc(sizeof(*hp) * i); while (--i >= 0) *hp++ = NULL; for (hp = oldhp, i = oldsize; --i >= 0;) { diff --git a/usr.bin/make/hash.h b/usr.bin/make/hash.h index 8620c43906ea..360ee0fec2d4 100644 --- a/usr.bin/make/hash.h +++ b/usr.bin/make/hash.h @@ -99,13 +99,13 @@ typedef struct Hash_Search { * char *val; */ -#define Hash_SetValue(h, val) ((h)->clientData = (void *) (val)) +#define Hash_SetValue(h, val) ((h)->clientData = (void *)(val)) /* * Hash_Size(n) returns the number of words in an object of n bytes */ -#define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int)) +#define Hash_Size(n) (((n) + sizeof(int) - 1) / sizeof(int)) void Hash_InitTable(Hash_Table *, int); void Hash_DeleteTable(Hash_Table *); diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 8dfda985e893..741b6dd64d17 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -139,7 +139,7 @@ static int aborting = 0; /* why is the make aborting? */ * XXX: Avoid SunOS bug... FILENO() is fp->_file, and file * is a char! So when we go above 127 we turn negative! */ -#define FILENO(a) ((unsigned) fileno(a)) +#define FILENO(a) ((unsigned)fileno(a)) /* * post-make command processing. The node postCommands is really just the @@ -162,7 +162,7 @@ static int numCommands; /* The number of commands actually printed /* * tfile is used to build temp file names to store shell commands to - * execute. + * execute. */ static char tfile[sizeof(TMPPAT)]; @@ -233,7 +233,7 @@ STATIC char *targFmt; /* Format string to use to head output from a #define TARG_FMT "--- %s ---\n" /* Default format */ #define MESSAGE(fp, gn) \ - (void) fprintf(fp, targFmt, gn->name); + fprintf(fp, targFmt, gn->name); /* * When JobStart attempts to run a job but isn't allowed to @@ -270,7 +270,7 @@ static sig_atomic_t interrupted; */ #define W_SETMASKED(st, val, fun) \ { \ - int sh = (int) ~0; \ + int sh = (int)~0; \ int mask = fun(sh); \ \ for (sh = 0; ((mask >> sh) & 1) == 0; sh++) \ @@ -328,13 +328,13 @@ JobCatchSig(int signo) static int JobCondPassSig(void *jobp, void *signop) { - Job *job = (Job *) jobp; - int signo = *(int *) signop; + Job *job = (Job *)jobp; + int signo = *(int *)signop; DEBUGF(JOB, ("JobCondPassSig passing signal %d to child %d.\n", signo, job->pid)); KILL(job->pid, signo); - return 0; + return (0); } /*- @@ -362,7 +362,7 @@ JobPassSig(int signo) sigprocmask(SIG_SETMASK, &nmask, &omask); DEBUGF(JOB, ("JobPassSig(%d) called.\n", signo)); - Lst_ForEach(jobs, JobCondPassSig, (void *) &signo); + Lst_ForEach(jobs, JobCondPassSig, (void *)&signo); /* * Deal with proper cleanup based on the signal received. We only run @@ -394,15 +394,16 @@ JobPassSig(int signo) act.sa_flags = 0; sigaction(signo, &act, NULL); - DEBUGF(JOB, ("JobPassSig passing signal to self, mask = %x.\n", ~0 & ~(1 << (signo-1)))); - (void) signal(signo, SIG_DFL); + DEBUGF(JOB, ("JobPassSig passing signal to self, mask = %x.\n", + ~0 & ~(1 << (signo - 1)))); + signal(signo, SIG_DFL); - (void) KILL(getpid(), signo); + KILL(getpid(), signo); signo = SIGCONT; - Lst_ForEach(jobs, JobCondPassSig, (void *) &signo); + Lst_ForEach(jobs, JobCondPassSig, (void *)&signo); - (void) sigprocmask(SIG_SETMASK, &omask, NULL); + sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL); act.sa_handler = JobPassSig; sigaction(signo, &act, NULL); @@ -425,7 +426,7 @@ JobPassSig(int signo) static int JobCmpPid(void *job, void *pid) { - return *(int *) pid - ((Job *) job)->pid; + return (*(int *)pid - ((Job *)job)->pid); } /*- @@ -470,8 +471,8 @@ JobPrintCommand(void *cmdp, void *jobp) * command */ char *cmdStart; /* Start of expanded command */ LstNode cmdNode; /* Node for replacing the command */ - char *cmd = (char *) cmdp; - Job *job = (Job *) jobp; + char *cmd = (char *)cmdp; + Job *job = (Job *)jobp; noSpecials = (noExecute && !(job->node->type & OP_MAKE)); @@ -480,15 +481,15 @@ JobPrintCommand(void *cmdp, void *jobp) if ((job->flags & JOB_IGNDOTS) == 0) { job->tailCmds = Lst_Succ(Lst_Member(job->node->commands, (void *)cmd)); - return 1; + return (1); } - return 0; + return (0); } #define DBPRINTF(fmt, arg) \ DEBUGF(JOB, (fmt, arg)); \ - (void) fprintf(job->cmdFILE, fmt, arg); \ - (void) fflush(job->cmdFILE); + fprintf(job->cmdFILE, fmt, arg); \ + fflush(job->cmdFILE); numCommands += 1; @@ -531,7 +532,7 @@ JobPrintCommand(void *cmdp, void *jobp) cmd++; } - while (isspace((unsigned char) *cmd)) + while (isspace((unsigned char)*cmd)) cmd++; if (shutUp) { @@ -612,7 +613,7 @@ JobPrintCommand(void *cmdp, void *jobp) if (shutUp) { DBPRINTF("%s\n", commandShell->echoOn); } - return 0; + return (0); } /*- @@ -632,9 +633,10 @@ JobPrintCommand(void *cmdp, void *jobp) static int JobSaveCommand(void *cmd, void *gn) { - cmd = (void *) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE); - (void) Lst_AtEnd(postCommands->commands, cmd); - return(0); + + cmd = (void *)Var_Subst(NULL, (char *)cmd, (GNode *)gn, FALSE); + Lst_AtEnd(postCommands->commands, cmd); + return (0); } @@ -654,17 +656,18 @@ JobSaveCommand(void *cmd, void *gn) static void JobClose(Job *job) { + if (usePipes) { #if !defined(USE_KQUEUE) FD_CLR(job->inPipe, &outputs); #endif if (job->outPipe != job->inPipe) { - (void) close(job->outPipe); + close(job->outPipe); } JobDoOutput(job, TRUE); - (void) close(job->inPipe); + close(job->inPipe); } else { - (void) close(job->outFd); + close(job->outFd); JobDoOutput(job, TRUE); } } @@ -712,7 +715,7 @@ JobFinish(Job *job, int *status) */ JobClose(job); if (job->cmdFILE != NULL && job->cmdFILE != stdout) { - (void) fclose(job->cmdFILE); + fclose(job->cmdFILE); } done = TRUE; } else if (WIFEXITED(*status)) { @@ -765,7 +768,7 @@ JobFinish(Job *job, int *status) MESSAGE(out, job->node); lastNode = job->node; } - (void) fprintf(out, "*** Error code %d%s\n", + fprintf(out, "*** Error code %d%s\n", WEXITSTATUS(*status), (job->flags & JOB_IGNERR) ? "(ignored)" : ""); @@ -777,7 +780,7 @@ JobFinish(Job *job, int *status) MESSAGE(out, job->node); lastNode = job->node; } - (void) fprintf(out, "*** Completed successfully\n"); + fprintf(out, "*** Completed successfully\n"); } } else if (WIFSTOPPED(*status)) { DEBUGF(JOB, ("Process %d stopped.\n", job->pid)); @@ -785,11 +788,11 @@ JobFinish(Job *job, int *status) MESSAGE(out, job->node); lastNode = job->node; } - (void) fprintf(out, "*** Stopped -- signal %d\n", + fprintf(out, "*** Stopped -- signal %d\n", WSTOPSIG(*status)); job->flags |= JOB_RESUME; - (void)Lst_AtEnd(stoppedJobs, (void *)job); - (void) fflush(out); + Lst_AtEnd(stoppedJobs, (void *)job); + fflush(out); return; } else if (WTERMSIG(*status) == SIGCONT) { /* @@ -802,7 +805,7 @@ JobFinish(Job *job, int *status) MESSAGE(out, job->node); lastNode = job->node; } - (void) fprintf(out, "*** Continued\n"); + fprintf(out, "*** Continued\n"); } if (!(job->flags & JOB_CONTINUING)) { DEBUGF(JOB, ("Warning: process %d was not continuing.\n", job->pid)); @@ -824,17 +827,17 @@ JobFinish(Job *job, int *status) jobFull = TRUE; DEBUGF(JOB, ("Job queue is full.\n")); } - (void) fflush(out); + fflush(out); return; } else { if (usePipes && job->node != lastNode) { MESSAGE(out, job->node); lastNode = job->node; } - (void) fprintf(out, "*** Signal %d\n", WTERMSIG(*status)); + fprintf(out, "*** Signal %d\n", WTERMSIG(*status)); } - (void) fflush(out); + fflush(out); } /* @@ -944,8 +947,8 @@ Job_Touch(GNode *gn, Boolean silent) } if (!silent) { - (void) fprintf(stdout, "touch %s\n", gn->name); - (void) fflush(stdout); + fprintf(stdout, "touch %s\n", gn->name); + fflush(stdout); } if (noExecute) { @@ -971,15 +974,15 @@ Job_Touch(GNode *gn, Boolean silent) * modification time, then close the file. */ if (read(streamID, &c, 1) == 1) { - (void) lseek(streamID, (off_t)0, SEEK_SET); - (void) write(streamID, &c, 1); + lseek(streamID, (off_t)0, SEEK_SET); + write(streamID, &c, 1); } - (void) close(streamID); + close(streamID); } else { - (void) fprintf(stdout, "*** couldn't touch %s: %s", + fprintf(stdout, "*** couldn't touch %s: %s", file, strerror(errno)); - (void) fflush(stdout); + fflush(stdout); } } } @@ -1001,6 +1004,7 @@ Job_Touch(GNode *gn, Boolean silent) Boolean Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) { + if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) && (gn->type & OP_LIB) == 0) { /* @@ -1032,12 +1036,12 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) static const char msg[] = "make: don't know how to make"; if (gn->type & OP_OPTIONAL) { - (void) fprintf(stdout, "%s %s(ignored)\n", msg, gn->name); - (void) fflush(stdout); + fprintf(stdout, "%s %s(ignored)\n", msg, gn->name); + fflush(stdout); } else if (keepgoing) { - (void) fprintf(stdout, "%s %s(continuing)\n", msg, gn->name); - (void) fflush(stdout); - return FALSE; + fprintf(stdout, "%s %s(continuing)\n", msg, gn->name); + fflush(stdout); + return (FALSE); } else { #if OLD_JOKE if (strcmp(gn->name,"love") == 0) @@ -1045,11 +1049,11 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) else #endif (*abortProc)("%s %s. Stop", msg, gn->name); - return FALSE; + return (FALSE); } } } - return TRUE; + return (TRUE); } /*- @@ -1108,8 +1112,8 @@ JobExec(Job *job, char **argv) */ if (dup2(FILENO(job->cmdFILE), 0) == -1) Punt("Cannot dup2: %s", strerror(errno)); - (void) fcntl(0, F_SETFD, 0); - (void) lseek(0, (off_t)0, SEEK_SET); + fcntl(0, F_SETFD, 0); + lseek(0, (off_t)0, SEEK_SET); if (usePipes) { /* @@ -1133,7 +1137,7 @@ JobExec(Job *job, char **argv) * it before routing the shell's error output to the same place as * its standard output. */ - (void) fcntl(1, F_SETFD, 0); + fcntl(1, F_SETFD, 0); if (dup2(1, 2) == -1) Punt("Cannot dup2: %s", strerror(errno)); @@ -1144,15 +1148,15 @@ JobExec(Job *job, char **argv) * by killing its process family, but not commit suicide. */ # if defined(SYSV) - (void) setsid(); + setsid(); # else - (void) setpgid(0, getpid()); + setpgid(0, getpid()); # endif #endif /* USE_PGRP */ - (void) execv(shellPath, argv); + execv(shellPath, argv); - (void) write(STDERR_FILENO, "Could not execute shell\n", + write(STDERR_FILENO, "Could not execute shell\n", sizeof("Could not execute shell")); _exit(1); } else { @@ -1184,7 +1188,7 @@ JobExec(Job *job, char **argv) } if (job->cmdFILE != NULL && job->cmdFILE != stdout) { - (void) fclose(job->cmdFILE); + fclose(job->cmdFILE); job->cmdFILE = NULL; } } @@ -1193,7 +1197,7 @@ JobExec(Job *job, char **argv) * Now the job is actually running, add it to the table. */ nJobs += 1; - (void) Lst_AtEnd(jobs, (void *)job); + Lst_AtEnd(jobs, (void *)job); if (nJobs == maxJobs) { jobFull = TRUE; } @@ -1229,7 +1233,7 @@ JobMakeArgv(Job *job, char **argv) * Bourne shell thinks its second argument is a file to source. * Grrrr. Note the ten-character limitation on the combined arguments. */ - (void)sprintf(args, "-%s%s", + sprintf(args, "-%s%s", ((job->flags & JOB_IGNERR) ? "" : (commandShell->exit ? commandShell->exit : "")), ((job->flags & JOB_SILENT) ? "" : @@ -1289,7 +1293,7 @@ JobRestart(Job *job) * back on the hold queue and mark the table full */ DEBUGF(JOB, ("holding\n")); - (void)Lst_AtFront(stoppedJobs, (void *)job); + Lst_AtFront(stoppedJobs, (void *)job); jobFull = TRUE; DEBUGF(JOB, ("Job queue is full.\n")); return; @@ -1344,7 +1348,7 @@ JobRestart(Job *job) * place the job back on the list of stopped jobs. */ DEBUGF(JOB, ("table full\n")); - (void) Lst_AtFront(stoppedJobs, (void *)job); + Lst_AtFront(stoppedJobs, (void *)job); jobFull = TRUE; DEBUGF(JOB, ("Job queue is full.\n")); } @@ -1384,7 +1388,7 @@ JobStart(GNode *gn, int flags, Job *previous) previous->flags &= ~(JOB_FIRST|JOB_IGNERR|JOB_SILENT); job = previous; } else { - job = (Job *) emalloc(sizeof(Job)); + job = (Job *)emalloc(sizeof(Job)); flags |= JOB_FIRST; } @@ -1430,7 +1434,7 @@ JobStart(GNode *gn, int flags, Job *previous) DieHorribly(); } - (void) strcpy(tfile, TMPPAT); + strcpy(tfile, TMPPAT); if ((tfd = mkstemp(tfile)) == -1) Punt("Cannot create temp file: %s", strerror(errno)); job->cmdFILE = fdopen(tfd, "w+"); @@ -1439,7 +1443,7 @@ JobStart(GNode *gn, int flags, Job *previous) close(tfd); Punt("Could not open %s", tfile); } - (void) fcntl(FILENO(job->cmdFILE), F_SETFD, 1); + fcntl(FILENO(job->cmdFILE), F_SETFD, 1); /* * Send the commands to the command file, flush all its buffers then * rewind and remove the thing. @@ -1465,8 +1469,8 @@ JobStart(GNode *gn, int flags, Job *previous) LstNode ln = Lst_Next(gn->commands); if ((ln == NULL) || - JobPrintCommand((void *) Lst_Datum(ln), - (void *) job)) + JobPrintCommand((void *)Lst_Datum(ln), + (void *)job)) { noExec = TRUE; Lst_Close(gn->commands); @@ -1544,9 +1548,9 @@ JobStart(GNode *gn, int flags, Job *previous) */ if (job->cmdFILE != stdout) { if (job->cmdFILE != NULL) - (void) fclose(job->cmdFILE); + fclose(job->cmdFILE); } else { - (void) fflush(stdout); + fflush(stdout); } /* @@ -1570,7 +1574,7 @@ JobStart(GNode *gn, int flags, Job *previous) return(JOB_ERROR); } } else { - (void) fflush(job->cmdFILE); + fflush(job->cmdFILE); } /* @@ -1587,19 +1591,20 @@ JobStart(GNode *gn, int flags, Job *previous) if (!compatMake || (job->flags & JOB_FIRST)) { if (usePipes) { int fd[2]; + if (pipe(fd) == -1) Punt("Cannot create pipe: %s", strerror(errno)); job->inPipe = fd[0]; job->outPipe = fd[1]; - (void) fcntl(job->inPipe, F_SETFD, 1); - (void) fcntl(job->outPipe, F_SETFD, 1); + fcntl(job->inPipe, F_SETFD, 1); + fcntl(job->outPipe, F_SETFD, 1); } else { - (void) fprintf(stdout, "Remaking `%s'\n", gn->name); - (void) fflush(stdout); - (void) strcpy(job->outFile, TMPPAT); + fprintf(stdout, "Remaking `%s'\n", gn->name); + fflush(stdout); + strcpy(job->outFile, TMPPAT); if ((job->outFd = mkstemp(job->outFile)) == -1) Punt("cannot create temp file: %s", strerror(errno)); - (void) fcntl(job->outFd, F_SETFD, 1); + fcntl(job->outFd, F_SETFD, 1); } } @@ -1614,7 +1619,7 @@ JobStart(GNode *gn, int flags, Job *previous) DEBUGF(JOB, ("Can only run job locally.\n")); job->flags |= JOB_RESTART; - (void) Lst_AtEnd(stoppedJobs, (void *)job); + Lst_AtEnd(stoppedJobs, (void *)job); } else { if (nJobs >= maxJobs) { /* @@ -1626,7 +1631,7 @@ JobStart(GNode *gn, int flags, Job *previous) } JobExec(job, argv); } - return(JOB_RUNNING); + return (JOB_RUNNING); } static char * @@ -1649,8 +1654,8 @@ JobOutput(Job *job, char *cp, char *endp, int msg) * however, since the non-printable comes after it, * there must be a newline, so we don't print one. */ - (void) fprintf(stdout, "%s", cp); - (void) fflush(stdout); + fprintf(stdout, "%s", cp); + fflush(stdout); } cp = ecp + commandShell->noPLen; if (cp != endp) { @@ -1665,11 +1670,11 @@ JobOutput(Job *job, char *cp, char *endp, int msg) } ecp = strstr(cp, commandShell->noPrint); } else { - return cp; + return (cp); } } } - return cp; + return (cp); } /*- @@ -1808,13 +1813,13 @@ JobDoOutput(Job *job, Boolean finish) MESSAGE(stdout, job->node); lastNode = job->node; } - (void) fprintf(stdout, "%s%s", cp, gotNL ? "\n" : ""); - (void) fflush(stdout); + fprintf(stdout, "%s%s", cp, gotNL ? "\n" : ""); + fflush(stdout); } } if (i < max - 1) { /* shift the remaining characters down */ - (void) memcpy(job->outBuf, &job->outBuf[i + 1], max - (i + 1)); + memcpy(job->outBuf, &job->outBuf[i + 1], max - (i + 1)); job->curPos = max - (i + 1); } else { @@ -1849,8 +1854,8 @@ JobDoOutput(Job *job, Boolean finish) */ oFILE = fopen(job->outFile, "r"); if (oFILE != NULL) { - (void) fprintf(stdout, "Results of making %s:\n", job->node->name); - (void) fflush(stdout); + fprintf(stdout, "Results of making %s:\n", job->node->name); + fflush(stdout); while (fgets(inLine, sizeof(inLine), oFILE) != NULL) { char *cp, *endp, *oendp; @@ -1866,15 +1871,15 @@ JobDoOutput(Job *job, Boolean finish) * we know there's no newline at the end, so we add one of * our own free will. */ - (void) fprintf(stdout, "%s", cp); - (void) fflush(stdout); + fprintf(stdout, "%s", cp); + fflush(stdout); if (endp != oendp) { - (void) fprintf(stdout, "\n"); - (void) fflush(stdout); + fprintf(stdout, "\n"); + fflush(stdout); } } - (void) fclose(oFILE); - (void) eunlink(job->outFile); + fclose(oFILE); + eunlink(job->outFile); } } } @@ -1914,7 +1919,7 @@ Job_CatchChildren(Boolean block) } for (;;) { - pid = waitpid((pid_t) -1, &status, (block?0:WNOHANG)|WUNTRACED); + pid = waitpid((pid_t)-1, &status, (block ? 0 : WNOHANG) | WUNTRACED); if (pid <= 0) break; DEBUGF(JOB, ("Process %d exited or stopped.\n", pid)); @@ -1923,20 +1928,20 @@ Job_CatchChildren(Boolean block) if (jnode == NULL) { if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGCONT)) { - jnode = Lst_Find(stoppedJobs, (void *) &pid, JobCmpPid); + jnode = Lst_Find(stoppedJobs, (void *)&pid, JobCmpPid); if (jnode == NULL) { Error("Resumed child (%d) not in table", pid); continue; } job = (Job *)Lst_Datum(jnode); - (void) Lst_Remove(stoppedJobs, jnode); + Lst_Remove(stoppedJobs, jnode); } else { Error("Child (%d) not in table?", pid); continue; } } else { - job = (Job *) Lst_Datum(jnode); - (void) Lst_Remove(jobs, jnode); + job = (Job *)Lst_Datum(jnode); + Lst_Remove(jobs, jnode); nJobs -= 1; if (fifoFd >= 0 && maxJobs > 1) { write(fifoFd, "+", 1); @@ -1962,7 +1967,7 @@ Job_CatchChildren(Boolean block) * Job_CatchOutput -- * Catch the output from our children, if we're using * pipes do so. Otherwise just block time until we get a - * signal (most likely a SIGCHLD) since there's no point in + * signal(most likely a SIGCHLD) since there's no point in * just spinning when there's nothing to do and the reaping * of a child can wait for a while. * @@ -1988,7 +1993,7 @@ Job_CatchOutput(int flag) Job *job; #endif - (void) fflush(stdout); + fflush(stdout); if (usePipes) { #ifdef USE_KQUEUE @@ -2024,7 +2029,7 @@ Job_CatchOutput(int flag) nfds = select(FD_SETSIZE, &readfds, (fd_set *) 0, (fd_set *) 0, &timeout); if (nfds <= 0) { - if (interrupted) + if (interrupted) JobPassSig(interrupted); return; } @@ -2036,7 +2041,7 @@ Job_CatchOutput(int flag) Punt("Cannot open job table"); } while (nfds && (ln = Lst_Next(jobs)) != NULL) { - job = (Job *) Lst_Datum(ln); + job = (Job *)Lst_Datum(ln); if (FD_ISSET(job->inPipe, &readfds)) { JobDoOutput(job, FALSE); nfds -= 1; @@ -2064,7 +2069,8 @@ Job_CatchOutput(int flag) void Job_Make(GNode *gn) { - (void) JobStart(gn, 0, NULL); + + JobStart(gn, 0, NULL); } /* @@ -2183,8 +2189,8 @@ Job_Init(int maxproc) const char *env; struct sigaction sa; - fifoFd = -1; - jobs = Lst_Init(FALSE); + fifoFd = -1; + jobs = Lst_Init(FALSE); stoppedJobs = Lst_Init(FALSE); env = getenv("MAKE_JOBS_FIFO"); @@ -2234,12 +2240,12 @@ Job_Init(int maxproc) jobFull = FALSE; } else { } - nJobs = 0; + nJobs = 0; - aborting = 0; - errors = 0; + aborting = 0; + errors = 0; - lastNode = NULL; + lastNode = NULL; if ((maxJobs == 1 && fifoFd < 0) || beVerbose == 0) { /* @@ -2263,16 +2269,16 @@ Job_Init(int maxproc) sa.sa_flags = 0; if (signal(SIGINT, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGINT, &sa, NULL); + sigaction(SIGINT, &sa, NULL); } if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGHUP, &sa, NULL); + sigaction(SIGHUP, &sa, NULL); } if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGQUIT, &sa, NULL); + sigaction(SIGQUIT, &sa, NULL); } if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGTERM, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); } /* * There are additional signals that need to be caught and passed if @@ -2282,16 +2288,16 @@ Job_Init(int maxproc) */ #if defined(USE_PGRP) if (signal(SIGTSTP, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGTSTP, &sa, NULL); + sigaction(SIGTSTP, &sa, NULL); } if (signal(SIGTTOU, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGTTOU, &sa, NULL); + sigaction(SIGTTOU, &sa, NULL); } if (signal(SIGTTIN, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGTTIN, &sa, NULL); + sigaction(SIGTTIN, &sa, NULL); } if (signal(SIGWINCH, SIG_IGN) != SIG_IGN) { - (void) sigaction(SIGWINCH, &sa, NULL); + sigaction(SIGWINCH, &sa, NULL); } #endif @@ -2334,7 +2340,7 @@ Job_Full(void) int i; if (aborting) - return(aborting); + return (aborting); if (fifoFd >= 0 && jobFull) { i = read(fifoFd, &c, 1); if (i > 0) { @@ -2342,7 +2348,7 @@ Job_Full(void) jobFull = FALSE; } } - return(jobFull); + return (jobFull); } /*- @@ -2372,12 +2378,12 @@ Job_Empty(void) */ jobFull = FALSE; JobRestartJobs(); - return(FALSE); + return (FALSE); } else { - return(TRUE); + return (TRUE); } } else { - return(FALSE); + return (FALSE); } } @@ -2498,7 +2504,7 @@ Job_ParseShell(char *line) Shell *sh; Boolean fullSpec = FALSE; - while (isspace((unsigned char) *line)) { + while (isspace((unsigned char)*line)) { line++; } words = brk_string(line, &wordCount, TRUE); @@ -2538,7 +2544,7 @@ Job_ParseShell(char *line) } else { Parse_Error(PARSE_FATAL, "Unknown keyword \"%s\"", *argv); - return(FAILURE); + return (FAILURE); } fullSpec = TRUE; } @@ -2635,14 +2641,14 @@ JobInterrupt(int runINTERRUPT, int signo) aborting = ABORT_INTERRUPT; - (void) Lst_Open(jobs); + Lst_Open(jobs); while ((ln = Lst_Next(jobs)) != NULL) { - job = (Job *) Lst_Datum(ln); + job = (Job *)Lst_Datum(ln); if (!Targ_Precious(job->node)) { - char *file = (job->node->path == NULL ? - job->node->name : - job->node->path); + char *file = (job->node->path == NULL ? + job->node->name : + job->node->path); if (!noExecute && eunlink(file) != -1) { Error("*** %s removed", file); } @@ -2685,6 +2691,7 @@ JobInterrupt(int runINTERRUPT, int signo) int Job_Finish(void) { + if (postCommands != NULL && !Lst_IsEmpty(postCommands->commands)) { if (errors) { Error("Errors reported so .END ignored"); @@ -2703,7 +2710,7 @@ Job_Finish(void) if (fifoMaster) unlink(fifoName); } - return(errors); + return (errors); } /*- @@ -2723,6 +2730,7 @@ Job_Finish(void) void Job_Wait(void) { + aborting = ABORT_WAIT; while (nJobs != 0) { Job_CatchOutput(0); @@ -2756,9 +2764,9 @@ Job_AbortAll(void) if (nJobs) { - (void) Lst_Open(jobs); + Lst_Open(jobs); while ((ln = Lst_Next(jobs)) != NULL) { - job = (Job *) Lst_Datum(ln); + job = (Job *)Lst_Datum(ln); /* * kill the child process with increasingly drastic signals to make @@ -2772,7 +2780,7 @@ Job_AbortAll(void) /* * Catch as many children as want to report in at first, then give up */ - while (waitpid((pid_t) -1, &foo, WNOHANG) > 0) + while (waitpid((pid_t)-1, &foo, WNOHANG) > 0) continue; } diff --git a/usr.bin/make/job.h b/usr.bin/make/job.h index fbcd56e5a4f1..82cc3d6dc949 100644 --- a/usr.bin/make/job.h +++ b/usr.bin/make/job.h @@ -60,7 +60,6 @@ #define SEL_USEC 0 #endif /* !USE_KQUEUE */ - /*- * Job Table definitions. * @@ -148,7 +147,6 @@ typedef struct Job { #define outFile output.o_file.of_outFile #define outFd output.o_file.of_outFd - /*- * Shell Specifications: * Each shell type has associated with it the following information: diff --git a/usr.bin/make/lst.lib/lstAppend.c b/usr.bin/make/lst.lib/lstAppend.c index 9ff3f86e783b..f18cee4274e4 100644 --- a/usr.bin/make/lst.lib/lstAppend.c +++ b/usr.bin/make/lst.lib/lstAppend.c @@ -75,11 +75,11 @@ Lst_Append(Lst list, LstNode ln, void *d) { LstNode nLNode; - if (Lst_Valid (list) && (ln == NULL && Lst_IsEmpty (list))) { + if (Lst_Valid(list) && (ln == NULL && Lst_IsEmpty(list))) { goto ok; } - if (!Lst_Valid (list) || Lst_IsEmpty (list) || ! Lst_NodeValid(ln, list)) { + if (!Lst_Valid(list) || Lst_IsEmpty(list) || ! Lst_NodeValid(ln, list)) { return (FAILURE); } ok: diff --git a/usr.bin/make/lst.lib/lstConcat.c b/usr.bin/make/lst.lib/lstConcat.c index 330425f75a07..f0c771c11bb3 100644 --- a/usr.bin/make/lst.lib/lstConcat.c +++ b/usr.bin/make/lst.lib/lstConcat.c @@ -79,7 +79,8 @@ Lst_Concat(Lst list1, Lst list2, int flags) LstNode nln; /* new LstNode */ LstNode last; /* the last element in the list. Keeps * bookkeeping until the end */ - if (!Lst_Valid (list1) || !Lst_Valid (list2)) { + + if (!Lst_Valid(list1) || !Lst_Valid(list2)) { return (FAILURE); } @@ -119,7 +120,7 @@ Lst_Concat(Lst list1, Lst list2, int flags) list1->firstPtr->prevPtr = list1->lastPtr; list1->lastPtr->nextPtr = list1->firstPtr; } - free (list2); + free(list2); } else if (list2->firstPtr != NULL) { /* * We set the nextPtr of the last element of list 2 to be NULL to make diff --git a/usr.bin/make/lst.lib/lstDeQueue.c b/usr.bin/make/lst.lib/lstDeQueue.c index 7cfb4768d329..86a57de6b9f1 100644 --- a/usr.bin/make/lst.lib/lstDeQueue.c +++ b/usr.bin/make/lst.lib/lstDeQueue.c @@ -69,13 +69,13 @@ Lst_DeQueue(Lst l) void * rd; LstNode tln; - tln = Lst_First (l); + tln = Lst_First(l); if (tln == NULL) { return (NULL); } rd = tln->datum; - if (Lst_Remove (l, tln) == FAILURE) { + if (Lst_Remove(l, tln) == FAILURE) { return (NULL); } else { return (rd); diff --git a/usr.bin/make/lst.lib/lstDestroy.c b/usr.bin/make/lst.lib/lstDestroy.c index 2a43c1de0648..5b9dc24ff25c 100644 --- a/usr.bin/make/lst.lib/lstDestroy.c +++ b/usr.bin/make/lst.lib/lstDestroy.c @@ -82,22 +82,22 @@ Lst_Destroy(Lst list, FreeProc *freeProc) if (list->lastPtr != NULL) list->lastPtr->nextPtr = NULL; else { - free (list); + free(list); return; } if (freeProc) { for (ln = list->firstPtr; ln != NULL; ln = tln) { tln = ln->nextPtr; - (*freeProc) (ln->datum); - free (ln); + (*freeProc)(ln->datum); + free(ln); } } else { for (ln = list->firstPtr; ln != NULL; ln = tln) { tln = ln->nextPtr; - free (ln); + free(ln); } } - free (list); + free(list); } diff --git a/usr.bin/make/lst.lib/lstDupl.c b/usr.bin/make/lst.lib/lstDupl.c index 58f3f5605d90..07d4011965e0 100644 --- a/usr.bin/make/lst.lib/lstDupl.c +++ b/usr.bin/make/lst.lib/lstDupl.c @@ -73,11 +73,11 @@ Lst_Duplicate(Lst list, DuplicateProc *copyProc) Lst nl; LstNode ln; - if (!Lst_Valid (list)) { + if (!Lst_Valid(list)) { return (NULL); } - nl = Lst_Init (list->isCirc); + nl = Lst_Init(list->isCirc); if (nl == NULL) { return (NULL); } @@ -85,7 +85,7 @@ Lst_Duplicate(Lst list, DuplicateProc *copyProc) ln = list->firstPtr; while (ln != NULL) { if (copyProc != NOCOPY) { - if (Lst_AtEnd (nl, (*copyProc) (ln->datum)) == FAILURE) { + if (Lst_AtEnd(nl, (*copyProc)(ln->datum)) == FAILURE) { return (NULL); } } else if (Lst_AtEnd (nl, ln->datum) == FAILURE) { diff --git a/usr.bin/make/lst.lib/lstFindFrom.c b/usr.bin/make/lst.lib/lstFindFrom.c index 557048bd72f4..e8f0ac575e13 100644 --- a/usr.bin/make/lst.lib/lstFindFrom.c +++ b/usr.bin/make/lst.lib/lstFindFrom.c @@ -70,14 +70,14 @@ Lst_FindFrom(Lst l, LstNode ln, void *d, CompareProc *cProc) LstNode tln; Boolean found = FALSE; - if (!Lst_Valid (l) || Lst_IsEmpty (l) || !Lst_NodeValid (ln, l)) { + if (!Lst_Valid(l) || Lst_IsEmpty(l) || !Lst_NodeValid(ln, l)) { return (NULL); } tln = ln; do { - if ((*cProc) (tln->datum, d) == 0) { + if ((*cProc)(tln->datum, d) == 0) { found = TRUE; break; } else { diff --git a/usr.bin/make/lst.lib/lstForEachFrom.c b/usr.bin/make/lst.lib/lstForEachFrom.c index 69742d07df88..b95741a53512 100644 --- a/usr.bin/make/lst.lib/lstForEachFrom.c +++ b/usr.bin/make/lst.lib/lstForEachFrom.c @@ -72,7 +72,7 @@ Lst_ForEachFrom(Lst list, LstNode ln, DoProc *proc, void *d) Boolean done; int result; - if (!Lst_Valid (list) || Lst_IsEmpty (list)) { + if (!Lst_Valid(list) || Lst_IsEmpty(list)) { return; } @@ -84,9 +84,9 @@ Lst_ForEachFrom(Lst list, LstNode ln, DoProc *proc, void *d) next = ln->nextPtr; - (void) ln->useCount++; - result = (*proc) (ln->datum, d); - (void) ln->useCount--; + ln->useCount++; + result = (*proc)(ln->datum, d); + ln->useCount--; /* * We're done with the traversal if diff --git a/usr.bin/make/lst.lib/lstInsert.c b/usr.bin/make/lst.lib/lstInsert.c index 486565e95672..160ace3601b1 100644 --- a/usr.bin/make/lst.lib/lstInsert.c +++ b/usr.bin/make/lst.lib/lstInsert.c @@ -76,10 +76,10 @@ Lst_Insert(Lst list, LstNode ln, void *d) /* * check validity of arguments */ - if (Lst_Valid (list) && (Lst_IsEmpty (list) && ln == NULL)) + if (Lst_Valid(list) && (Lst_IsEmpty(list) && ln == NULL)) goto ok; - if (!Lst_Valid (list) || Lst_IsEmpty (list) || !Lst_NodeValid (ln, list)) { + if (!Lst_Valid(list) || Lst_IsEmpty(list) || !Lst_NodeValid(ln, list)) { return (FAILURE); } diff --git a/usr.bin/make/lst.lib/lstIsAtEnd.c b/usr.bin/make/lst.lib/lstIsAtEnd.c index 5f42b70caab8..f8881f0a597f 100644 --- a/usr.bin/make/lst.lib/lstIsAtEnd.c +++ b/usr.bin/make/lst.lib/lstIsAtEnd.c @@ -77,6 +77,6 @@ Boolean Lst_IsAtEnd(Lst list) { - return (!Lst_Valid (list) || !list->isOpen || + return (!Lst_Valid(list) || !list->isOpen || (list->atEnd == LstHead) || (list->atEnd == LstTail)); } diff --git a/usr.bin/make/lst.lib/lstNext.c b/usr.bin/make/lst.lib/lstNext.c index db112c5ea3bf..5d388af208bd 100644 --- a/usr.bin/make/lst.lib/lstNext.c +++ b/usr.bin/make/lst.lib/lstNext.c @@ -74,7 +74,7 @@ Lst_Next(Lst list) { LstNode tln; - if ((Lst_Valid (list) == FALSE) || (list->isOpen == FALSE)) { + if ((Lst_Valid(list) == FALSE) || (list->isOpen == FALSE)) { return (NULL); } diff --git a/usr.bin/make/lst.lib/lstOpen.c b/usr.bin/make/lst.lib/lstOpen.c index 11559aba1945..06ba56661f57 100644 --- a/usr.bin/make/lst.lib/lstOpen.c +++ b/usr.bin/make/lst.lib/lstOpen.c @@ -73,11 +73,11 @@ ReturnStatus Lst_Open(Lst l) { - if (Lst_Valid (l) == FALSE) { + if (Lst_Valid(l) == FALSE) { return (FAILURE); } l->isOpen = TRUE; - l->atEnd = Lst_IsEmpty (l) ? LstHead : LstUnknown; + l->atEnd = Lst_IsEmpty(l) ? LstHead : LstUnknown; l->curPtr = NULL; return (SUCCESS); diff --git a/usr.bin/make/lst.lib/lstRemove.c b/usr.bin/make/lst.lib/lstRemove.c index 5da603f9063e..d11fceaeed80 100644 --- a/usr.bin/make/lst.lib/lstRemove.c +++ b/usr.bin/make/lst.lib/lstRemove.c @@ -68,7 +68,7 @@ ReturnStatus Lst_Remove(Lst list, LstNode ln) { - if (!Lst_Valid (list) || !Lst_NodeValid (ln, list)) { + if (!Lst_Valid(list) || !Lst_NodeValid(ln, list)) { return (FAILURE); } diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 19f00b6ad3a7..50941a8751b7 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -133,6 +133,7 @@ static char *objdir; /* where we chdir'ed to */ static void MFLAGS_append(char *flag, char *arg) { + Var_Append(MAKEFLAGS, flag, VAR_GLOBAL); if (arg != NULL) Var_Append(MAKEFLAGS, arg, VAR_GLOBAL); @@ -255,8 +256,8 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { } case 'E': p = emalloc(strlen(optarg) + 1); - (void)strcpy(p, optarg); - (void)Lst_AtEnd(envFirstVars, (void *)p); + strcpy(p, optarg); + Lst_AtEnd(envFirstVars, (void *)p); MFLAGS_append("-E", optarg); break; case 'e': @@ -264,7 +265,7 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { MFLAGS_append("-e", NULL); break; case 'f': - (void)Lst_AtEnd(makefiles, (void *)optarg); + Lst_AtEnd(makefiles, (void *)optarg); break; case 'i': ignoreErrors = TRUE; @@ -347,7 +348,7 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { optind = 1; /* - */ goto rearg; } - (void)Lst_AtEnd(create, (void *)estrdup(*argv)); + Lst_AtEnd(create, (void *)estrdup(*argv)); } } @@ -391,12 +392,12 @@ chdir_verify_path(char *path, char *obpath) if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) { if (chdir(path) == -1 || getcwd(obpath, MAXPATHLEN) == NULL) { warn("warning: %s", path); - return 0; + return (0); } - return obpath; + return (obpath); } - return 0; + return (0); } static void @@ -498,7 +499,7 @@ main(int argc, char **argv) if (getrlimit(RLIMIT_NOFILE, &rl) != -1 && rl.rlim_cur != rl.rlim_max) { rl.rlim_cur = rl.rlim_max; - (void) setrlimit(RLIMIT_NOFILE, &rl); + setrlimit(RLIMIT_NOFILE, &rl); } } #endif @@ -658,11 +659,11 @@ main(int argc, char **argv) if (!(path = getenv("MAKEOBJDIR"))) { path = _PATH_OBJDIR; pathp = _PATH_OBJDIRPREFIX; - (void) snprintf(mdpath, MAXPATHLEN, "%s.%s", + snprintf(mdpath, MAXPATHLEN, "%s.%s", path, machine); if (!(objdir = chdir_verify_path(mdpath, obpath))) if (!(objdir=chdir_verify_path(path, obpath))) { - (void) snprintf(mdpath, MAXPATHLEN, + snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir); if (!(objdir=chdir_verify_path(mdpath, obpath))) @@ -673,7 +674,7 @@ main(int argc, char **argv) objdir = curdir; } else { - (void) snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir); + snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir); if (!(objdir = chdir_verify_path(mdpath, obpath))) objdir = curdir; } @@ -701,7 +702,7 @@ main(int argc, char **argv) Suff_Init(); DEFAULT = NULL; - (void)time(&now); + time(&now); /* * Set up the .TARGETS variable to contain the list of targets to be @@ -747,8 +748,8 @@ main(int argc, char **argv) if (!noBuiltins) { LstNode ln; - sysMkPath = Lst_Init (FALSE); - Dir_Expand (_PATH_DEFSYSMK, sysIncPath, sysMkPath); + sysMkPath = Lst_Init(FALSE); + Dir_Expand(_PATH_DEFSYSMK, sysIncPath, sysMkPath); if (Lst_IsEmpty(sysMkPath)) Fatal("make: no system rules (%s).", _PATH_DEFSYSMK); ln = Lst_Find(sysMkPath, (void *)NULL, ReadMakefile); @@ -764,9 +765,9 @@ main(int argc, char **argv) Fatal("make: cannot open %s.", (char *)Lst_Datum(ln)); } else if (!ReadMakefile("BSDmakefile", NULL)) if (!ReadMakefile("makefile", NULL)) - (void)ReadMakefile("Makefile", NULL); + ReadMakefile("Makefile", NULL); - (void)ReadMakefile(".depend", NULL); + ReadMakefile(".depend", NULL); /* Install all the flags into the MAKE envariable. */ if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1)) != NULL) && *p) @@ -802,7 +803,7 @@ main(int argc, char **argv) *cp = savec; path = cp + 1; } while (savec == ':'); - (void)free(vpath); + free(vpath); } /* @@ -825,7 +826,7 @@ main(int argc, char **argv) if (expandVars) { p1 = emalloc(strlen((char *)Lst_Datum(ln)) + 1 + 3); /* This sprintf is safe, because of the malloc above */ - (void)sprintf(p1, "${%s}", (char *)Lst_Datum(ln)); + sprintf(p1, "${%s}", (char *)Lst_Datum(ln)); value = Var_Subst(NULL, p1, VAR_GLOBAL, FALSE); } else { value = Var_Value((char *)Lst_Datum(ln), @@ -889,9 +890,9 @@ main(int argc, char **argv) Dir_End(); if (queryFlag && outOfDate) - return(1); + return (1); else - return(0); + return (0); } /*- @@ -923,7 +924,7 @@ ReadMakefile(void *p, void *q __unused) /* if we've chdir'd, rebuild the path name */ if (curdir != objdir && *fname != '/') { - (void)snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname); + snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname); /* * XXX The realpath stuff breaks relative includes * XXX in some cases. The problem likely is in @@ -969,7 +970,7 @@ ReadMakefile(void *p, void *q __unused) if (!name) name = Dir_FindFile(fname, sysIncPath); if (!name || !(stream = fopen(name, "r"))) - return(FALSE); + return (FALSE); MAKEFILE = fname = name; /* * set the MAKEFILE variable desired by System V fans -- the @@ -980,9 +981,9 @@ ReadMakefile(void *p, void *q __unused) if (setMAKEFILE) Var_Set("MAKEFILE", MAKEFILE, VAR_GLOBAL); Parse_File(fname, stream); - (void)fclose(stream); + fclose(stream); } - return(TRUE); + return (TRUE); } /*- @@ -1038,17 +1039,17 @@ Cmd_Exec(char *cmd, char **error) /* * Close input side of pipe */ - (void) close(fds[0]); + close(fds[0]); /* * Duplicate the output stream to the shell's output, then * shut the extra thing down. Note we don't fetch the error * stream...why not? Why? */ - (void) dup2(fds[1], 1); - (void) close(fds[1]); + dup2(fds[1], 1); + close(fds[1]); - (void) execv(shellPath, args); + execv(shellPath, args); _exit(1); /*NOTREACHED*/ @@ -1060,34 +1061,34 @@ Cmd_Exec(char *cmd, char **error) /* * No need for the writing half */ - (void) close(fds[1]); + close(fds[1]); - buf = Buf_Init (MAKE_BSIZE); + buf = Buf_Init(MAKE_BSIZE); do { char result[BUFSIZ]; cc = read(fds[0], result, sizeof(result)); if (cc > 0) - Buf_AddBytes(buf, cc, (Byte *) result); + Buf_AddBytes(buf, cc, (Byte *)result); } while (cc > 0 || (cc == -1 && errno == EINTR)); /* * Close the input side of the pipe. */ - (void) close(fds[0]); + close(fds[0]); /* * Wait for the process to exit. */ - while(((pid = wait(&status)) != cpid) && (pid >= 0)) + while (((pid = wait(&status)) != cpid) && (pid >= 0)) continue; if (cc == -1) *error = "Error reading shell's output for \"%s\""; - res = (char *)Buf_GetAll (buf, &cc); - Buf_Destroy (buf, FALSE); + res = (char *)Buf_GetAll(buf, &cc); + Buf_Destroy(buf, FALSE); if (status) *error = "\"%s\" returned non-zero status"; @@ -1113,11 +1114,11 @@ Cmd_Exec(char *cmd, char **error) } break; } - return res; + return (res); bad: res = emalloc(1); *res = '\0'; - return res; + return (res); } /* @@ -1127,7 +1128,7 @@ Cmd_Exec(char *cmd, char **error) static void usage(void) { - (void)fprintf(stderr, "%s\n%s\n%s\n", + fprintf(stderr, "%s\n%s\n%s\n", "usage: make [-BPSXeiknqrstv] [-C directory] [-D variable] [-d flags]", " [-E variable] [-f makefile] [-I directory] [-j max_jobs]", " [-m directory] [-V variable] [variable=value] [target ...]"); diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c index 4f85b68dc4a2..56da7ea91751 100644 --- a/usr.bin/make/make.c +++ b/usr.bin/make/make.c @@ -93,6 +93,7 @@ static int MakeTimeStamp(void *, void *); static int MakeHandleUse(void *, void *); static Boolean MakeStartJobs(void); static int MakePrintStatus(void *, void *); + /*- *----------------------------------------------------------------------- * Make_TimeStamp -- @@ -108,8 +109,9 @@ static int MakePrintStatus(void *, void *); *----------------------------------------------------------------------- */ int -Make_TimeStamp (GNode *pgn, GNode *cgn) +Make_TimeStamp(GNode *pgn, GNode *cgn) { + if (cgn->mtime > pgn->cmtime) { pgn->cmtime = cgn->mtime; } @@ -117,11 +119,12 @@ Make_TimeStamp (GNode *pgn, GNode *cgn) } static int -MakeTimeStamp (void *pgn, void *cgn) +MakeTimeStamp(void *pgn, void *cgn) { - return Make_TimeStamp((GNode *) pgn, (GNode *) cgn); + + return (Make_TimeStamp((GNode *)pgn, (GNode *)cgn)); } - + /*- *----------------------------------------------------------------------- * Make_OODate -- @@ -141,7 +144,7 @@ MakeTimeStamp (void *pgn, void *cgn) *----------------------------------------------------------------------- */ Boolean -Make_OODate (GNode *gn) +Make_OODate(GNode *gn) { Boolean oodate; @@ -149,8 +152,8 @@ Make_OODate (GNode *gn) * Certain types of targets needn't even be sought as their datedness * doesn't depend on their modification time... */ - if ((gn->type & (OP_JOIN|OP_USE|OP_EXEC)) == 0) { - (void) Dir_MTime (gn); + if ((gn->type & (OP_JOIN | OP_USE | OP_EXEC)) == 0) { + Dir_MTime(gn); if (gn->mtime != 0) { DEBUGF(MAKE, ("modified %s...", Targ_FmtTime(gn->mtime))); } else { @@ -186,7 +189,7 @@ Make_OODate (GNode *gn) * always out of date if no children and :: target */ - oodate = Arch_LibOODate (gn) || + oodate = Arch_LibOODate(gn) || ((gn->cmtime == 0) && (gn->type & OP_DOUBLEDEP)); } else if (gn->type & OP_JOIN) { /* @@ -238,12 +241,12 @@ Make_OODate (GNode *gn) * thinking they're out-of-date. */ if (!oodate) { - Lst_ForEach (gn->parents, MakeTimeStamp, (void *)gn); + Lst_ForEach(gn->parents, MakeTimeStamp, (void *)gn); } return (oodate); } - + /*- *----------------------------------------------------------------------- * MakeAddChild -- @@ -258,17 +261,17 @@ Make_OODate (GNode *gn) *----------------------------------------------------------------------- */ static int -MakeAddChild (void *gnp, void *lp) +MakeAddChild(void *gnp, void *lp) { - GNode *gn = (GNode *) gnp; - Lst l = (Lst) lp; + GNode *gn = (GNode *)gnp; + Lst l = (Lst)lp; if (!gn->make && !(gn->type & OP_USE)) { - (void)Lst_EnQueue (l, (void *)gn); + Lst_EnQueue(l, (void *)gn); } return (0); } - + /*- *----------------------------------------------------------------------- * Make_HandleUse -- @@ -293,7 +296,7 @@ MakeAddChild (void *gnp, void *lp) *----------------------------------------------------------------------- */ int -Make_HandleUse (GNode *cgn, GNode *pgn) +Make_HandleUse(GNode *cgn, GNode *pgn) { GNode *gn; /* A child of the .USE node */ LstNode ln; /* An element in the children list */ @@ -304,23 +307,23 @@ Make_HandleUse (GNode *cgn, GNode *pgn) * .USE or transformation and target has no commands -- append * the child's commands to the parent. */ - (void) Lst_Concat (pgn->commands, cgn->commands, LST_CONCNEW); + Lst_Concat(pgn->commands, cgn->commands, LST_CONCNEW); } - if (Lst_Open (cgn->children) == SUCCESS) { - while ((ln = Lst_Next (cgn->children)) != NULL) { - gn = (GNode *)Lst_Datum (ln); + if (Lst_Open(cgn->children) == SUCCESS) { + while ((ln = Lst_Next(cgn->children)) != NULL) { + gn = (GNode *)Lst_Datum(ln); - if (Lst_Member (pgn->children, gn) == NULL) { - (void) Lst_AtEnd (pgn->children, gn); - (void) Lst_AtEnd (gn->parents, pgn); + if (Lst_Member(pgn->children, gn) == NULL) { + Lst_AtEnd(pgn->children, gn); + Lst_AtEnd(gn->parents, pgn); pgn->unmade += 1; } } - Lst_Close (cgn->children); + Lst_Close(cgn->children); } - pgn->type |= cgn->type & ~(OP_OPMASK|OP_USE|OP_TRANSFORM); + pgn->type |= cgn->type & ~(OP_OPMASK | OP_USE | OP_TRANSFORM); /* * This child node is now "made", so we decrement the count of @@ -335,12 +338,14 @@ Make_HandleUse (GNode *cgn, GNode *pgn) } return (0); } + static int -MakeHandleUse (void *pgn, void *cgn) +MakeHandleUse(void *pgn, void *cgn) { - return Make_HandleUse((GNode *) pgn, (GNode *) cgn); + + return (Make_HandleUse((GNode *)pgn, (GNode *)cgn)); } - + /*- *----------------------------------------------------------------------- * Make_Update -- @@ -367,14 +372,14 @@ MakeHandleUse (void *pgn, void *cgn) *----------------------------------------------------------------------- */ void -Make_Update (GNode *cgn) +Make_Update(GNode *cgn) { GNode *pgn; /* the parent node */ char *cname; /* the child's name */ LstNode ln; /* Element in parents and iParents lists */ char *p1; - cname = Var_Value (TARGET, cgn, &p1); + cname = Var_Value(TARGET, cgn, &p1); free(p1); /* @@ -442,20 +447,20 @@ Make_Update (GNode *cgn) #endif } - if (Lst_Open (cgn->parents) == SUCCESS) { - while ((ln = Lst_Next (cgn->parents)) != NULL) { - pgn = (GNode *)Lst_Datum (ln); + if (Lst_Open(cgn->parents) == SUCCESS) { + while ((ln = Lst_Next(cgn->parents)) != NULL) { + pgn = (GNode *)Lst_Datum(ln); if (pgn->make) { pgn->unmade -= 1; - if ( ! (cgn->type & (OP_EXEC|OP_USE))) { + if (!(cgn->type & (OP_EXEC | OP_USE))) { if (cgn->made == MADE) { pgn->childMade = TRUE; if (pgn->cmtime < cgn->mtime) { pgn->cmtime = cgn->mtime; } } else { - (void)Make_TimeStamp (pgn, cgn); + Make_TimeStamp(pgn, cgn); } } if (pgn->unmade == 0) { @@ -463,13 +468,13 @@ Make_Update (GNode *cgn) * Queue the node up -- any unmade predecessors will * be dealt with in MakeStartJobs. */ - (void)Lst_EnQueue (toBeMade, (void *)pgn); + Lst_EnQueue(toBeMade, (void *)pgn); } else if (pgn->unmade < 0) { - Error ("Graph cycles through %s", pgn->name); + Error("Graph cycles through %s", pgn->name); } } } - Lst_Close (cgn->parents); + Lst_Close(cgn->parents); } /* * Deal with successor nodes. If any is marked for making and has an unmade @@ -483,7 +488,7 @@ Make_Update (GNode *cgn) if (succ->make && succ->unmade == 0 && succ->made == UNMADE && Lst_Member(toBeMade, (void *)succ) == NULL) { - (void)Lst_EnQueue(toBeMade, (void *)succ); + Lst_EnQueue(toBeMade, (void *)succ); } } @@ -491,22 +496,22 @@ Make_Update (GNode *cgn) * Set the .PREFIX and .IMPSRC variables for all the implied parents * of this node. */ - if (Lst_Open (cgn->iParents) == SUCCESS) { + if (Lst_Open(cgn->iParents) == SUCCESS) { char *ptr; char *cpref = Var_Value(PREFIX, cgn, &ptr); - while ((ln = Lst_Next (cgn->iParents)) != NULL) { + while ((ln = Lst_Next(cgn->iParents)) != NULL) { pgn = (GNode *)Lst_Datum (ln); if (pgn->make) { - Var_Set (IMPSRC, cname, pgn); - Var_Set (PREFIX, cpref, pgn); + Var_Set(IMPSRC, cname, pgn); + Var_Set(PREFIX, cpref, pgn); } } free(ptr); - Lst_Close (cgn->iParents); + Lst_Close(cgn->iParents); } } - + /*- *----------------------------------------------------------------------- * MakeAddAllSrc -- @@ -528,11 +533,12 @@ Make_Update (GNode *cgn) *----------------------------------------------------------------------- */ static int -MakeAddAllSrc (void *cgnp, void *pgnp) +MakeAddAllSrc(void *cgnp, void *pgnp) { GNode *cgn = (GNode *) cgnp; GNode *pgn = (GNode *) pgnp; - if ((cgn->type & (OP_EXEC|OP_USE|OP_INVISIBLE)) == 0) { + + if ((cgn->type & (OP_EXEC | OP_USE | OP_INVISIBLE)) == 0) { char *child; char *p1 = NULL; @@ -544,7 +550,7 @@ MakeAddAllSrc (void *cgnp, void *pgnp) } else child = Var_Value(TARGET, cgn, &p1); - Var_Append (ALLSRC, child, pgn); + Var_Append(ALLSRC, child, pgn); if (pgn->type & OP_JOIN) { if (cgn->made == MADE) { Var_Append(OODATE, child, pgn); @@ -574,7 +580,7 @@ MakeAddAllSrc (void *cgnp, void *pgnp) } return (0); } - + /*- *----------------------------------------------------------------------- * Make_DoAllVar -- @@ -598,24 +604,26 @@ MakeAddAllSrc (void *cgnp, void *pgnp) *----------------------------------------------------------------------- */ void -Make_DoAllVar (GNode *gn) +Make_DoAllVar(GNode *gn) { - Lst_ForEach (gn->children, MakeAddAllSrc, (void *) gn); + + Lst_ForEach(gn->children, MakeAddAllSrc, (void *)gn); if (!Var_Exists (OODATE, gn)) { - Var_Set (OODATE, "", gn); + Var_Set(OODATE, "", gn); } if (!Var_Exists (ALLSRC, gn)) { - Var_Set (ALLSRC, "", gn); + Var_Set(ALLSRC, "", gn); } if (gn->type & OP_JOIN) { char *p1; - Var_Set (TARGET, Var_Value (ALLSRC, gn, &p1), gn); + + Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn); free(p1); } } - + /*- *----------------------------------------------------------------------- * MakeStartJobs -- @@ -633,12 +641,12 @@ Make_DoAllVar (GNode *gn) *----------------------------------------------------------------------- */ static Boolean -MakeStartJobs (void) +MakeStartJobs(void) { GNode *gn; while (!Lst_IsEmpty (toBeMade) && !Job_Full()) { - gn = (GNode *) Lst_DeQueue (toBeMade); + gn = (GNode *)Lst_DeQueue(toBeMade); DEBUGF(MAKE, ("Examining %s...", gn->name)); /* * Make sure any and all predecessors that are going to be made, @@ -667,13 +675,13 @@ MakeStartJobs (void) } numNodes--; - if (Make_OODate (gn)) { + if (Make_OODate(gn)) { DEBUGF(MAKE, ("out-of-date\n")); if (queryFlag) { return (TRUE); } - Make_DoAllVar (gn); - Job_Make (gn); + Make_DoAllVar(gn); + Job_Make(gn); } else { DEBUGF(MAKE, ("up-to-date\n")); gn->made = UPTODATE; @@ -684,15 +692,15 @@ MakeStartJobs (void) * value for .TARGET when building up the context variables * of its parent(s)... */ - Make_DoAllVar (gn); + Make_DoAllVar(gn); } - Make_Update (gn); + Make_Update(gn); } } return (FALSE); } - + /*- *----------------------------------------------------------------------- * MakePrintStatus -- @@ -713,10 +721,11 @@ MakeStartJobs (void) static int MakePrintStatus(void *gnp, void *cyclep) { - GNode *gn = (GNode *) gnp; - Boolean cycle = *(Boolean *) cyclep; + GNode *gn = (GNode *)gnp; + Boolean cycle = *(Boolean *)cyclep; + if (gn->made == UPTODATE) { - printf ("`%s' is up to date.\n", gn->name); + printf("`%s' is up to date.\n", gn->name); } else if (gn->unmade != 0) { if (cycle) { Boolean t = TRUE; @@ -733,19 +742,19 @@ MakePrintStatus(void *gnp, void *cyclep) if (gn->made == CYCLE) { Error("Graph cycles through `%s'", gn->name); gn->made = ENDCYCLE; - Lst_ForEach(gn->children, MakePrintStatus, (void *) &t); + Lst_ForEach(gn->children, MakePrintStatus, (void *)&t); gn->made = UNMADE; } else if (gn->made != ENDCYCLE) { gn->made = CYCLE; - Lst_ForEach(gn->children, MakePrintStatus, (void *) &t); + Lst_ForEach(gn->children, MakePrintStatus, (void *)&t); } } else { - printf ("`%s' not remade because of errors.\n", gn->name); + printf("`%s' not remade because of errors.\n", gn->name); } } return (0); } - + /*- *----------------------------------------------------------------------- * Make_Run -- @@ -768,13 +777,13 @@ MakePrintStatus(void *gnp, void *cyclep) *----------------------------------------------------------------------- */ Boolean -Make_Run (Lst targs) +Make_Run(Lst targs) { GNode *gn; /* a temporary pointer */ Lst examine; /* List of targets to examine */ int errors; /* Number of errors the Job module reports */ - toBeMade = Lst_Init (FALSE); + toBeMade = Lst_Init(FALSE); examine = Lst_Duplicate(targs, NOCOPY); numNodes = 0; @@ -787,8 +796,8 @@ Make_Run (Lst targs) * be looked at in a minute, otherwise we add its children to our queue * and go on about our business. */ - while (!Lst_IsEmpty (examine)) { - gn = (GNode *) Lst_DeQueue (examine); + while (!Lst_IsEmpty(examine)) { + gn = (GNode *)Lst_DeQueue(examine); if (!gn->make) { gn->make = TRUE; @@ -798,18 +807,18 @@ Make_Run (Lst targs) * Apply any .USE rules before looking for implicit dependencies * to make sure everything has commands that should... */ - Lst_ForEach (gn->children, MakeHandleUse, (void *)gn); - Suff_FindDeps (gn); + Lst_ForEach(gn->children, MakeHandleUse, (void *)gn); + Suff_FindDeps(gn); if (gn->unmade != 0) { - Lst_ForEach (gn->children, MakeAddChild, (void *)examine); + Lst_ForEach(gn->children, MakeAddChild, (void *)examine); } else { - (void)Lst_EnQueue (toBeMade, (void *)gn); + Lst_EnQueue(toBeMade, (void *)gn); } } } - Lst_Destroy (examine, NOFREE); + Lst_Destroy(examine, NOFREE); if (queryFlag) { /* @@ -826,7 +835,7 @@ Make_Run (Lst targs) * the finishing of a job. So we fill the Job table as much as we can * before going into our loop. */ - (void) MakeStartJobs(); + MakeStartJobs(); } /* @@ -840,9 +849,9 @@ Make_Run (Lst targs) * keepgoing flag was given. */ while (!Job_Empty ()) { - Job_CatchOutput (!Lst_IsEmpty (toBeMade)); - Job_CatchChildren (!usePipes); - (void)MakeStartJobs(); + Job_CatchOutput(!Lst_IsEmpty (toBeMade)); + Job_CatchChildren(!usePipes); + MakeStartJobs(); } errors = Job_Finish(); @@ -852,7 +861,7 @@ Make_Run (Lst targs) * because some inferior reported an error. */ errors = ((errors == 0) && (numNodes != 0)); - Lst_ForEach(targs, MakePrintStatus, (void *) &errors); + Lst_ForEach(targs, MakePrintStatus, (void *)&errors); return (TRUE); } diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 9803e7d543f8..eb93e6fa74d5 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -245,7 +245,7 @@ static void ParseFinishLine(void); *---------------------------------------------------------------------- */ static int -ParseFindKeyword (char *str) +ParseFindKeyword(char *str) { int start, end, @@ -253,11 +253,11 @@ ParseFindKeyword (char *str) int diff; start = 0; - end = (sizeof(parseKeywords)/sizeof(parseKeywords[0])) - 1; + end = (sizeof(parseKeywords) / sizeof(parseKeywords[0])) - 1; do { cur = start + ((end - start) / 2); - diff = strcmp (str, parseKeywords[cur].name); + diff = strcmp(str, parseKeywords[cur].name); if (diff == 0) { return (cur); @@ -289,14 +289,14 @@ Parse_Error(int type, const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)fprintf(stderr, "\"%s\", line %d: ", + fprintf(stderr, "\"%s\", line %d: ", curFile.fname, curFile.lineno); if (type == PARSE_WARNING) - (void)fprintf(stderr, "warning: "); - (void)vfprintf(stderr, fmt, ap); + fprintf(stderr, "warning: "); + vfprintf(stderr, fmt, ap); va_end(ap); - (void)fprintf(stderr, "\n"); - (void)fflush(stderr); + fprintf(stderr, "\n"); + fflush(stderr); if (type == PARSE_FATAL) fatals += 1; } @@ -318,14 +318,15 @@ Parse_Error(int type, const char *fmt, ...) *--------------------------------------------------------------------- */ static int -ParseLinkSrc (void *pgnp, void *cgnp) +ParseLinkSrc(void *pgnp, void *cgnp) { - GNode *pgn = (GNode *) pgnp; - GNode *cgn = (GNode *) cgnp; - if (Lst_Member (pgn->children, (void *)cgn) == NULL) { - (void)Lst_AtEnd (pgn->children, (void *)cgn); + GNode *pgn = (GNode *)pgnp; + GNode *cgn = (GNode *)cgnp; + + if (Lst_Member(pgn->children, (void *)cgn) == NULL) { + Lst_AtEnd (pgn->children, (void *)cgn); if (specType == Not) { - (void)Lst_AtEnd (cgn->parents, (void *)pgn); + Lst_AtEnd (cgn->parents, (void *)pgn); } pgn->unmade += 1; } @@ -349,10 +350,11 @@ ParseLinkSrc (void *pgnp, void *cgnp) *--------------------------------------------------------------------- */ static int -ParseDoOp (void *gnp, void *opp) +ParseDoOp(void *gnp, void *opp) { - GNode *gn = (GNode *) gnp; - int op = *(int *) opp; + GNode *gn = (GNode *)gnp; + int op = *(int *)opp; + /* * If the dependency mask of the operator and the node don't match and * the node has actually had an operator applied to it before, and @@ -361,7 +363,7 @@ ParseDoOp (void *gnp, void *opp) if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) && !OP_NOP(gn->type) && !OP_NOP(op)) { - Parse_Error (PARSE_FATAL, "Inconsistent operator for %s", gn->name); + Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name); return (1); } @@ -389,7 +391,7 @@ ParseDoOp (void *gnp, void *opp) */ Lst_ForEach(gn->parents, ParseLinkSrc, (void *)cohort); cohort->type = OP_DOUBLEDEP|OP_INVISIBLE; - (void)Lst_AtEnd(gn->cohorts, (void *)cohort); + Lst_AtEnd(gn->cohorts, (void *)cohort); /* * Replace the node in the targets list with the new copy @@ -426,8 +428,8 @@ ParseDoOp (void *gnp, void *opp) static int ParseAddDep(void *pp, void *sp) { - GNode *p = (GNode *) pp; - GNode *s = (GNode *) sp; + GNode *p = (GNode *)pp; + GNode *s = (GNode *)sp; if (p->order < s->order) { /* @@ -435,12 +437,12 @@ ParseAddDep(void *pp, void *sp) * but checking is tedious, and the debugging output can show the * problem */ - (void)Lst_AtEnd(p->successors, (void *)s); - (void)Lst_AtEnd(s->preds, (void *)p); - return 0; + Lst_AtEnd(p->successors, (void *)s); + Lst_AtEnd(s->preds, (void *)p); + return (0); } else - return 1; + return (1); } @@ -462,7 +464,7 @@ ParseAddDep(void *pp, void *sp) *--------------------------------------------------------------------- */ static void -ParseDoSrc (int tOp, char *src, Lst allsrc) +ParseDoSrc(int tOp, char *src, Lst allsrc) { GNode *gn = NULL; @@ -491,7 +493,7 @@ ParseDoSrc (int tOp, char *src, Lst allsrc) * invoked if the user didn't specify a target on the command * line. This is to allow #ifmake's to succeed, or something... */ - (void) Lst_AtEnd (create, (void *)estrdup(src)); + Lst_AtEnd (create, (void *)estrdup(src)); /* * Add the name to the .TARGETS variable as well, so the user cna * employ that, if desired. @@ -506,8 +508,8 @@ ParseDoSrc (int tOp, char *src, Lst allsrc) */ gn = Targ_FindNode(src, TARG_CREATE); if (predecessor != NULL) { - (void)Lst_AtEnd(predecessor->successors, (void *)gn); - (void)Lst_AtEnd(gn->preds, (void *)predecessor); + Lst_AtEnd(predecessor->successors, (void *)gn); + Lst_AtEnd(gn->preds, (void *)predecessor); } /* * The current source now becomes the predecessor for the next one. @@ -527,7 +529,7 @@ ParseDoSrc (int tOp, char *src, Lst allsrc) * the 'cohorts' list of the node) or all the cohorts are linked * to all the targets. */ - gn = Targ_FindNode (src, TARG_CREATE); + gn = Targ_FindNode(src, TARG_CREATE); if (tOp) { gn->type |= tOp; } else { @@ -550,7 +552,7 @@ ParseDoSrc (int tOp, char *src, Lst allsrc) } gn->order = waiting; - (void)Lst_AtEnd(allsrc, (void *)gn); + Lst_AtEnd(allsrc, (void *)gn); if (waiting) { Lst_ForEach(allsrc, ParseAddDep, (void *)gn); } @@ -575,7 +577,7 @@ static int ParseFindMain(void *gnp, void *dummy __unused) { GNode *gn = (GNode *) gnp; - if ((gn->type & (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)) == 0) { + if ((gn->type & (OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM)) == 0) { mainNode = gn; Targ_SetMain(gn); return (1); @@ -600,7 +602,8 @@ ParseFindMain(void *gnp, void *dummy __unused) static int ParseAddDir(void *path, void *name) { - Dir_AddDir((Lst) path, (char *) name); + + Dir_AddDir((Lst)path, (char *)name); return(0); } @@ -620,7 +623,8 @@ ParseAddDir(void *path, void *name) static int ParseClearPath(void *path, void *dummy __unused) { - Dir_ClearPath((Lst) path); + + Dir_ClearPath((Lst)path); return (0); } @@ -685,7 +689,7 @@ ParseDoDependency (char *line) do { for (cp = line; - *cp && !isspace ((unsigned char) *cp) && *cp != '('; + *cp && !isspace ((unsigned char)*cp) && *cp != '('; cp++) { if (*cp == '$') { @@ -700,12 +704,12 @@ ParseDoDependency (char *line) Boolean freeIt; char *result; - result=Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt); + result = Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt); if (freeIt) { free(result); } - cp += length-1; + cp += length - 1; } else if (*cp == '!' || *cp == ':') { /* * We don't want to end a word on ':' or '!' if there is a @@ -747,8 +751,8 @@ ParseDoDependency (char *line) * went well and FAILURE if there was an error in the * specification. On error, line should remain untouched. */ - if (Arch_ParseArchive (&line, targets, VAR_CMD) != SUCCESS) { - Parse_Error (PARSE_FATAL, + if (Arch_ParseArchive(&line, targets, VAR_CMD) != SUCCESS) { + Parse_Error(PARSE_FATAL, "Error in archive specification: \"%s\"", line); return; } else { @@ -766,10 +770,10 @@ ParseDoDependency (char *line) if ((strncmp(line, "<<<<<<", 6) == 0) || (strncmp(line, "======", 6) == 0) || (strncmp(line, ">>>>>>", 6) == 0)) - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts"); else - Parse_Error (PARSE_FATAL, "Need an operator"); + Parse_Error(PARSE_FATAL, "Need an operator"); return; } *cp = '\0'; @@ -777,7 +781,7 @@ ParseDoDependency (char *line) * Have a word in line. See if it's a special target and set * specType to match it. */ - if (*line == '.' && isupper ((unsigned char) line[1])) { + if (*line == '.' && isupper ((unsigned char)line[1])) { /* * See if the target is a special target that must have it * or its sources handled specially. @@ -825,7 +829,7 @@ ParseDoDependency (char *line) if (paths == NULL) { paths = Lst_Init(FALSE); } - (void)Lst_AtEnd(paths, (void *)dirSearchPath); + Lst_AtEnd(paths, (void *)dirSearchPath); break; case Main: if (!Lst_IsEmpty(create)) { @@ -837,12 +841,12 @@ ParseDoDependency (char *line) case Interrupt: gn = Targ_FindNode(line, TARG_CREATE); gn->type |= OP_NOTMAIN; - (void)Lst_AtEnd(targets, (void *)gn); + Lst_AtEnd(targets, (void *)gn); break; case Default: gn = Targ_NewGN(".DEFAULT"); gn->type |= (OP_NOTMAIN|OP_TRANSFORM); - (void)Lst_AtEnd(targets, (void *)gn); + Lst_AtEnd(targets, (void *)gn); DEFAULT = gn; break; case NotParallel: @@ -859,7 +863,7 @@ ParseDoDependency (char *line) default: break; } - } else if (strncmp (line, ".PATH", 5) == 0) { + } else if (strncmp(line, ".PATH", 5) == 0) { /* * .PATH has to be handled specially. * Call on the suffix module to give us a path to @@ -868,9 +872,9 @@ ParseDoDependency (char *line) Lst path; specType = ExPath; - path = Suff_GetPath (&line[5]); + path = Suff_GetPath(&line[5]); if (path == NULL) { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Suffix '%s' not defined (yet)", &line[5]); return; @@ -878,7 +882,7 @@ ParseDoDependency (char *line) if (paths == (Lst)NULL) { paths = Lst_Init(FALSE); } - (void)Lst_AtEnd(paths, (void *)path); + Lst_AtEnd(paths, (void *)path); } } } @@ -905,19 +909,19 @@ ParseDoDependency (char *line) * No wildcards, but we want to avoid code duplication, * so create a list with the word on it. */ - (void)Lst_AtEnd(curTargs, (void *)line); + Lst_AtEnd(curTargs, (void *)line); } while(!Lst_IsEmpty(curTargs)) { char *targName = (char *)Lst_DeQueue(curTargs); if (!Suff_IsTransform (targName)) { - gn = Targ_FindNode (targName, TARG_CREATE); + gn = Targ_FindNode(targName, TARG_CREATE); } else { - gn = Suff_AddTransform (targName); + gn = Suff_AddTransform(targName); } - (void)Lst_AtEnd (targets, (void *)gn); + Lst_AtEnd(targets, (void *)gn); } } else if (specType == ExPath && *line != '.' && *line != '\0') { Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line); @@ -988,18 +992,18 @@ ParseDoDependency (char *line) op = OP_DEPENDS; } } else { - Parse_Error (PARSE_FATAL, "Missing dependency operator"); + Parse_Error(PARSE_FATAL, "Missing dependency operator"); return; } cp++; /* Advance beyond operator */ - Lst_ForEach (targets, ParseDoOp, (void *)&op); + Lst_ForEach(targets, ParseDoOp, (void *)&op); /* * Get to the first source */ - while (*cp && isspace ((unsigned char) *cp)) { + while (*cp && isspace ((unsigned char)*cp)) { cp++; } line = cp; @@ -1016,7 +1020,7 @@ ParseDoDependency (char *line) if (!*line) { switch (specType) { case Suffixes: - Suff_ClearSuffixes (); + Suff_ClearSuffixes(); break; case Precious: allPrecious = TRUE; @@ -1042,11 +1046,11 @@ ParseDoDependency (char *line) * set the initial character to a null-character so the loop to * get sources won't get anything */ - Main_ParseArgLine (line); + Main_ParseArgLine(line); *line = '\0'; } else if (specType == ExShell) { - if (Job_ParseShell (line) != SUCCESS) { - Parse_Error (PARSE_FATAL, "improper shell specification"); + if (Job_ParseShell(line) != SUCCESS) { + Parse_Error(PARSE_FATAL, "improper shell specification"); return; } *line = '\0'; @@ -1087,26 +1091,26 @@ ParseDoDependency (char *line) * has no valid suffix. */ char savech; - while (*cp && !isspace ((unsigned char) *cp)) { + while (*cp && !isspace ((unsigned char)*cp)) { cp++; } savech = *cp; *cp = '\0'; switch (specType) { case Suffixes: - Suff_AddSuffix (line); + Suff_AddSuffix(line); break; case ExPath: Lst_ForEach(paths, ParseAddDir, (void *)line); break; case Includes: - Suff_AddInclude (line); + Suff_AddInclude(line); break; case Libs: - Suff_AddLib (line); + Suff_AddLib(line); break; case Null: - Suff_SetNull (line); + Suff_SetNull(line); break; default: break; @@ -1115,7 +1119,7 @@ ParseDoDependency (char *line) if (savech != '\0') { cp++; } - while (*cp && isspace ((unsigned char) *cp)) { + while (*cp && isspace ((unsigned char)*cp)) { cp++; } line = cp; @@ -1130,7 +1134,7 @@ ParseDoDependency (char *line) * specifications (i.e. things with left parentheses in them) * and handle them accordingly. */ - while (*cp && !isspace ((unsigned char) *cp)) { + while (*cp && !isspace ((unsigned char)*cp)) { if ((*cp == '(') && (cp > line) && (cp[-1] != '$')) { /* * Only stop for a left parenthesis if it isn't at the @@ -1147,18 +1151,18 @@ ParseDoDependency (char *line) if (*cp == '(') { GNode *gnp; - sources = Lst_Init (FALSE); - if (Arch_ParseArchive (&line, sources, VAR_CMD) != SUCCESS) { - Parse_Error (PARSE_FATAL, + sources = Lst_Init(FALSE); + if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) { + Parse_Error(PARSE_FATAL, "Error in source archive spec \"%s\"", line); return; } while (!Lst_IsEmpty (sources)) { - gnp = (GNode *) Lst_DeQueue (sources); - ParseDoSrc (tOp, gnp->name, curSrcs); + gnp = (GNode *)Lst_DeQueue(sources); + ParseDoSrc(tOp, gnp->name, curSrcs); } - Lst_Destroy (sources, NOFREE); + Lst_Destroy(sources, NOFREE); cp = line; } else { if (*cp) { @@ -1166,9 +1170,9 @@ ParseDoDependency (char *line) cp += 1; } - ParseDoSrc (tOp, line, curSrcs); + ParseDoSrc(tOp, line, curSrcs); } - while (*cp && isspace ((unsigned char) *cp)) { + while (*cp && isspace ((unsigned char)*cp)) { cp++; } line = cp; @@ -1182,7 +1186,7 @@ ParseDoDependency (char *line) * the first dependency line that is actually a real target * (i.e. isn't a .USE or .EXEC rule) to be made. */ - Lst_ForEach (targets, ParseFindMain, (void *)0); + Lst_ForEach(targets, ParseFindMain, (void *)0); } /* @@ -1208,10 +1212,11 @@ ParseDoDependency (char *line) *--------------------------------------------------------------------- */ Boolean -Parse_IsVar (char *line) +Parse_IsVar(char *line) { Boolean wasSpace = FALSE; /* set TRUE if found a space */ Boolean haveName = FALSE; /* Set TRUE if have a variable name */ + int level = 0; #define ISEQOPERATOR(c) \ (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!')) @@ -1219,7 +1224,7 @@ Parse_IsVar (char *line) /* * Skip to variable name */ - for (;(*line == ' ') || (*line == '\t'); line++) + for (; (*line == ' ') || (*line == '\t'); line++) continue; for (; *line != '=' || level != 0; line++) @@ -1228,7 +1233,7 @@ Parse_IsVar (char *line) /* * end-of-line -- can't be a variable assignment. */ - return FALSE; + return (FALSE); case ' ': case '\t': @@ -1256,7 +1261,7 @@ Parse_IsVar (char *line) * We must have a finished word */ if (level != 0) - return FALSE; + return (FALSE); /* * When an = operator [+?!:] is found, the next @@ -1264,19 +1269,19 @@ Parse_IsVar (char *line) * assignment. */ if (line[1] == '=') - return haveName; + return (haveName); #ifdef SUNSHCMD /* * This is a shell command */ if (strncmp(line, ":sh", 3) == 0) - return haveName; + return (haveName); #endif } /* * This is the start of another word, so not assignment. */ - return FALSE; + return (FALSE); } else { haveName = TRUE; @@ -1285,7 +1290,7 @@ Parse_IsVar (char *line) break; } - return haveName; + return (haveName); } /*- @@ -1309,7 +1314,7 @@ Parse_IsVar (char *line) *--------------------------------------------------------------------- */ void -Parse_DoVar (char *line, GNode *ctxt) +Parse_DoVar(char *line, GNode *ctxt) { char *cp; /* pointer into line */ enum { @@ -1322,8 +1327,8 @@ Parse_DoVar (char *line, GNode *ctxt) * to ``unregister'' variables */ #if __GNUC__ - (void) &cp; - (void) &line; + (void)&cp; + (void)&line; #endif /* @@ -1337,11 +1342,11 @@ Parse_DoVar (char *line, GNode *ctxt) * Skip to operator character, nulling out whitespace as we go */ for (cp = line + 1; *cp != '='; cp++) { - if (isspace ((unsigned char) *cp)) { + if (isspace ((unsigned char)*cp)) { *cp = '\0'; } } - opc = cp-1; /* operator is the previous character */ + opc = cp - 1; /* operator is the previous character */ *cp++ = '\0'; /* nuke the = */ /* @@ -1393,12 +1398,12 @@ Parse_DoVar (char *line, GNode *ctxt) break; } - while (isspace ((unsigned char) *cp)) { + while (isspace ((unsigned char)*cp)) { cp++; } if (type == VAR_APPEND) { - Var_Append (line, cp, ctxt); + Var_Append(line, cp, ctxt); } else if (type == VAR_SUBST) { /* * Allow variables in the old value to be undefined, but leave their @@ -1474,14 +1479,15 @@ static int ParseAddCmd(void *gnp, void *cmd) { GNode *gn = (GNode *) gnp; + /* if target already supplied, ignore commands */ if (!(gn->type & OP_HAS_COMMANDS)) - (void)Lst_AtEnd(gn->commands, cmd); + Lst_AtEnd(gn->commands, cmd); else Parse_Error(PARSE_WARNING, "duplicate script for target \"%s\" ignored", gn->name); - return(0); + return (0); } /*- @@ -1503,7 +1509,9 @@ ParseAddCmd(void *gnp, void *cmd) static void ParseHasCommands(void *gnp) { + GNode *gn = (GNode *) gnp; + if (!Lst_IsEmpty(gn->commands)) { gn->type |= OP_HAS_COMMANDS; } @@ -1524,9 +1532,10 @@ ParseHasCommands(void *gnp) *----------------------------------------------------------------------- */ void -Parse_AddIncludeDir (char *dir) +Parse_AddIncludeDir(char *dir) { - Dir_AddDir (parseIncPath, dir); + + Dir_AddDir(parseIncPath, dir); } /*--------------------------------------------------------------------- @@ -1542,14 +1551,15 @@ Parse_AddIncludeDir (char *dir) static void ParseDoError(char *errmsg) { - if (!isspace((unsigned char) *errmsg)) { + + if (!isspace((unsigned char)*errmsg)) { Parse_Error(PARSE_WARNING, "invalid syntax: .error%s", errmsg); return; } - - while (isspace((unsigned char) *errmsg)) + + while (isspace((unsigned char)*errmsg)) errmsg++; - + errmsg = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE); Parse_Error(PARSE_FATAL, "%s", errmsg); @@ -1570,15 +1580,16 @@ ParseDoError(char *errmsg) static void ParseDoWarning(char *warnmsg) { - if (!isspace((unsigned char) *warnmsg)) { + + if (!isspace((unsigned char)*warnmsg)) { Parse_Error(PARSE_WARNING, "invalid syntax: .warning%s", warnmsg); return; } - - while (isspace((unsigned char) *warnmsg)) + + while (isspace((unsigned char)*warnmsg)) warnmsg++; - + warnmsg = Var_Subst(NULL, warnmsg, VAR_GLOBAL, FALSE); Parse_Error(PARSE_WARNING, "%s", warnmsg); @@ -1619,7 +1630,7 @@ ParseDoInclude (char *file) } if ((*file != '"') && (*file != '<')) { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, ".include filename must be delimited by '\"' or '<'"); return; } @@ -1645,7 +1656,7 @@ ParseDoInclude (char *file) } if (*cp != endc) { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Unclosed %cinclude filename. '%c' expected", '.', endc); return; @@ -1656,7 +1667,7 @@ ParseDoInclude (char *file) * Substitute for any variables in the file name before trying to * find the thing. */ - file = Var_Subst (NULL, file, VAR_CMD, FALSE); + file = Var_Subst(NULL, file, VAR_CMD, FALSE); /* * Now we know the file's name and its search path, we attempt to @@ -1676,7 +1687,7 @@ ParseDoInclude (char *file) /* Make a temporary copy of this, to be safe. */ Fname = estrdup(curFile.fname); - prefEnd = strrchr (Fname, '/'); + prefEnd = strrchr(Fname, '/'); if (prefEnd != (char *)NULL) { char *newName; @@ -1684,17 +1695,17 @@ ParseDoInclude (char *file) if (file[0] == '/') newName = estrdup(file); else - newName = str_concat (Fname, file, STR_ADDSLASH); - fullname = Dir_FindFile (newName, parseIncPath); + newName = str_concat(Fname, file, STR_ADDSLASH); + fullname = Dir_FindFile(newName, parseIncPath); if (fullname == (char *)NULL) { fullname = Dir_FindFile(newName, dirSearchPath); } - free (newName); + free(newName); *prefEnd = '/'; } else { fullname = (char *)NULL; } - free (Fname); + free(Fname); } else { fullname = (char *)NULL; } @@ -1706,7 +1717,7 @@ ParseDoInclude (char *file) * then on the .PATH search path, if not found in a -I directory. * XXX: Suffix specific? */ - fullname = Dir_FindFile (file, parseIncPath); + fullname = Dir_FindFile(file, parseIncPath); if (fullname == (char *)NULL) { fullname = Dir_FindFile(file, dirSearchPath); } @@ -1722,7 +1733,7 @@ ParseDoInclude (char *file) if (fullname == (char *) NULL) { *cp = endc; - Parse_Error (PARSE_FATAL, "Could not find %s", file); + Parse_Error(PARSE_FATAL, "Could not find %s", file); return; } @@ -1735,10 +1746,10 @@ ParseDoInclude (char *file) * is placed on a list with other IFile structures. The list makes * a very nice stack to track how we got here... */ - oldFile = (IFile *) emalloc (sizeof (IFile)); + oldFile = (IFile *) emalloc(sizeof (IFile)); memcpy(oldFile, &curFile, sizeof (IFile)); - (void) Lst_AtFront (includes, (void *)oldFile); + Lst_AtFront(includes, (void *)oldFile); /* * Once the previous state has been saved, we can get down to reading @@ -1749,21 +1760,19 @@ ParseDoInclude (char *file) curFile.fname = fullname; curFile.lineno = 0; - curFile.F = fopen (fullname, "r"); + curFile.F = fopen(fullname, "r"); curFile.p = NULL; if (curFile.F == (FILE * ) NULL) { - Parse_Error (PARSE_FATAL, "Cannot open %s", fullname); + Parse_Error(PARSE_FATAL, "Cannot open %s", fullname); /* * Pop to previous file */ - (void) ParseEOF(0); + ParseEOF(0); } else { Var_Append(".MAKEFILE_LIST", fullname, VAR_GLOBAL); } } - - /*- *--------------------------------------------------------------------- * Parse_FromString -- @@ -1784,19 +1793,18 @@ Parse_FromString(char *str, int lineno) DEBUGF(FOR, ("%s\n---- at line %d\n", str, lineno)); - oldFile = (IFile *) emalloc (sizeof (IFile)); - memcpy(oldFile, &curFile, sizeof (IFile)); + oldFile = (IFile *)emalloc(sizeof(IFile)); + memcpy(oldFile, &curFile, sizeof(IFile)); - (void) Lst_AtFront (includes, (void *)oldFile); + Lst_AtFront (includes, (void *)oldFile); curFile.F = NULL; - curFile.p = (PTR *) emalloc (sizeof (PTR)); + curFile.p = (PTR *)emalloc(sizeof (PTR)); curFile.p->str = curFile.p->ptr = str; curFile.lineno = lineno; curFile.fname = estrdup(curFile.fname); } - #ifdef SYSVINCLUDE /*- *--------------------------------------------------------------------- @@ -1829,7 +1837,7 @@ ParseTraditionalInclude (char *file) } if (*file == '\0') { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Filename missing from \"include\""); return; } @@ -1847,14 +1855,14 @@ ParseTraditionalInclude (char *file) * Substitute for any variables in the file name before trying to * find the thing. */ - file = Var_Subst (NULL, file, VAR_CMD, FALSE); + file = Var_Subst(NULL, file, VAR_CMD, FALSE); /* * Now we know the file's name, we attempt to find the durn thing. * Search for it first on the -I search path, then on the .PATH * search path, if not found in a -I directory. */ - fullname = Dir_FindFile (file, parseIncPath); + fullname = Dir_FindFile(file, parseIncPath); if (fullname == (char *)NULL) { fullname = Dir_FindFile(file, dirSearchPath); } @@ -1868,7 +1876,7 @@ ParseTraditionalInclude (char *file) } if (fullname == (char *) NULL) { - Parse_Error (PARSE_FATAL, "Could not find %s", file); + Parse_Error(PARSE_FATAL, "Could not find %s", file); return; } @@ -1879,10 +1887,10 @@ ParseTraditionalInclude (char *file) * is placed on a list with other IFile structures. The list makes * a very nice stack to track how we got here... */ - oldFile = (IFile *) emalloc (sizeof (IFile)); - memcpy(oldFile, &curFile, sizeof (IFile)); + oldFile = (IFile *)emalloc(sizeof(IFile)); + memcpy(oldFile, &curFile, sizeof(IFile)); - (void) Lst_AtFront (includes, (void *)oldFile); + Lst_AtFront(includes, (void *)oldFile); /* * Once the previous state has been saved, we can get down to reading @@ -1893,14 +1901,14 @@ ParseTraditionalInclude (char *file) curFile.fname = fullname; curFile.lineno = 0; - curFile.F = fopen (fullname, "r"); + curFile.F = fopen(fullname, "r"); curFile.p = NULL; - if (curFile.F == (FILE * ) NULL) { - Parse_Error (PARSE_FATAL, "Cannot open %s", fullname); + if (curFile.F == (FILE * )NULL) { + Parse_Error(PARSE_FATAL, "Cannot open %s", fullname); /* * Pop to previous file */ - (void) ParseEOF(1); + ParseEOF(1); } else { Var_Append(".MAKEFILE_LIST", fullname, VAR_GLOBAL); } @@ -1924,7 +1932,7 @@ ParseTraditionalInclude (char *file) *--------------------------------------------------------------------- */ static int -ParseEOF (int opened) +ParseEOF(int opened) { IFile *ifile; /* the state on the top of the includes stack */ @@ -1933,18 +1941,18 @@ ParseEOF (int opened) return (DONE); } - ifile = (IFile *) Lst_DeQueue (includes); - free (curFile.fname); + ifile = (IFile *)Lst_DeQueue(includes); + free(curFile.fname); if (opened && curFile.F) { - (void) fclose (curFile.F); + fclose(curFile.F); Var_Append(".MAKEFILE_LIST", "..", VAR_GLOBAL); } if (curFile.p) { free(curFile.p->str); free(curFile.p); } - memcpy(&curFile, ifile, sizeof (IFile)); - free (ifile); + memcpy(&curFile, ifile, sizeof(IFile)); + free(ifile); return (CONTINUE); } @@ -1962,12 +1970,13 @@ ParseEOF (int opened) static int ParseReadc(void) { + if (curFile.F) - return fgetc(curFile.F); + return (fgetc(curFile.F)); if (curFile.p && *curFile.p->ptr) - return *curFile.p->ptr++; - return EOF; + return (*curFile.p->ptr++); + return (EOF); } @@ -1985,6 +1994,7 @@ ParseReadc(void) static void ParseUnreadc(int c) { + if (curFile.F) { ungetc(c, curFile.F); return; @@ -2043,7 +2053,7 @@ ParseSkipLine(int skip, int keep_newline) if (c == EOF) { Parse_Error(PARSE_FATAL, "Unclosed conditional/for loop"); Buf_Destroy(buf, TRUE); - return((char *)NULL); + return ((char *)NULL); } curFile.lineno++; @@ -2052,7 +2062,7 @@ ParseSkipLine(int skip, int keep_newline) } while (skip == 1 && line[0] != '.'); Buf_Destroy(buf, FALSE); - return line; + return (line); } @@ -2074,7 +2084,7 @@ ParseSkipLine(int skip, int keep_newline) *--------------------------------------------------------------------- */ static char * -ParseReadLine (void) +ParseReadLine(void) { Buffer buf; /* Buffer for current line */ int c; /* the current character */ @@ -2123,11 +2133,11 @@ ParseReadLine (void) lastc = c; buf = Buf_Init(MAKE_BSIZE); - while (((c = ParseReadc ()) != '\n' || (lastc == '\\')) && + while (((c = ParseReadc()) != '\n' || (lastc == '\\')) && (c != EOF)) { test_char: - switch(c) { + switch (c) { case '\n': /* * Escaped newline: read characters until a non-space or an @@ -2139,7 +2149,7 @@ ParseReadLine (void) */ curFile.lineno++; lastc = ' '; - while ((c = ParseReadc ()) == ' ' || c == '\t') { + while ((c = ParseReadc()) == ' ' || c == '\t') { continue; } if (c == EOF || c == '\n') { @@ -2191,7 +2201,8 @@ ParseReadLine (void) * XXX: Note that a line like "foo : a:=b" will blow up, * but who'd write a line like that anyway? */ - ignDepOp = TRUE; semiNL = FALSE; + ignDepOp = TRUE; + semiNL = FALSE; } break; case '#': @@ -2233,7 +2244,7 @@ ParseReadLine (void) /* * Copy in the previous character and save this one in lastc. */ - Buf_AddByte (buf, (Byte)lastc); + Buf_AddByte(buf, (Byte)lastc); lastc = c; } @@ -2241,11 +2252,11 @@ ParseReadLine (void) curFile.lineno++; if (lastc != '\0') { - Buf_AddByte (buf, (Byte)lastc); + Buf_AddByte(buf, (Byte)lastc); } - Buf_AddByte (buf, (Byte)'\0'); - line = (char *)Buf_GetAll (buf, &lineLength); - Buf_Destroy (buf, FALSE); + Buf_AddByte(buf, (Byte)'\0'); + line = (char *)Buf_GetAll(buf, &lineLength); + Buf_Destroy(buf, FALSE); /* * Strip trailing blanks and tabs from the line. @@ -2267,20 +2278,20 @@ ParseReadLine (void) * The line might be a conditional. Ask the conditional module * about it and act accordingly */ - switch (Cond_Eval (line)) { + switch (Cond_Eval(line)) { case COND_SKIP: /* * Skip to next conditional that evaluates to COND_PARSE. */ do { - free (line); + free(line); line = ParseSkipLine(1, 0); } while (line && Cond_Eval(line) != COND_PARSE); if (line == NULL) break; /*FALLTHRU*/ case COND_PARSE: - free (line); + free(line); line = ParseReadLine(); break; case COND_INVALID: @@ -2294,7 +2305,7 @@ ParseReadLine (void) */ line = ParseSkipLine(0, 1); if (line == NULL) { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Unexpected end of file in for loop.\n"); break; } @@ -2317,7 +2328,7 @@ ParseReadLine (void) /* * Hit end-of-file, so return a NULL line to indicate this. */ - return((char *)NULL); + return ((char *)NULL); } } @@ -2337,9 +2348,10 @@ ParseReadLine (void) static void ParseFinishLine(void) { + if (inLine) { Lst_ForEach(targets, Suff_EndTransform, (void *)NULL); - Lst_Destroy (targets, ParseHasCommands); + Lst_Destroy(targets, ParseHasCommands); targets = NULL; inLine = FALSE; } @@ -2376,31 +2388,31 @@ Parse_File(char *name, FILE *stream) Var_Append(".MAKEFILE_LIST", name, VAR_GLOBAL); do { - while ((line = ParseReadLine ()) != NULL) { + while ((line = ParseReadLine()) != NULL) { if (*line == '.') { /* * Lines that begin with the special character are either * include or undef directives. */ - for (cp = line + 1; isspace ((unsigned char) *cp); cp++) { + for (cp = line + 1; isspace((unsigned char)*cp); cp++) { continue; } - if (strncmp (cp, "include", 7) == 0) { + if (strncmp(cp, "include", 7) == 0) { ParseDoInclude (cp + 7); goto nextLine; - } else if (strncmp (cp, "error", 5) == 0) { + } else if (strncmp(cp, "error", 5) == 0) { ParseDoError(cp + 5); - goto nextLine; - } else if (strncmp (cp, "warning", 7) == 0) { + goto nextLine; + } else if (strncmp(cp, "warning", 7) == 0) { ParseDoWarning(cp + 7); - goto nextLine; + goto nextLine; } else if (strncmp(cp, "undef", 5) == 0) { char *cp2; - for (cp += 5; isspace((unsigned char) *cp); cp++) { + for (cp += 5; isspace((unsigned char)*cp); cp++) { continue; } - for (cp2 = cp; !isspace((unsigned char) *cp2) && + for (cp2 = cp; !isspace((unsigned char)*cp2) && (*cp2 != '\0'); cp2++) { continue; } @@ -2422,7 +2434,7 @@ Parse_File(char *name, FILE *stream) * If a line starts with a tab, it can only hope to be * a creation command. */ - for (cp = line + 1; isspace ((unsigned char) *cp); cp++) { + for (cp = line + 1; isspace((unsigned char)*cp); cp++) { continue; } if (*cp) { @@ -2432,28 +2444,28 @@ Parse_File(char *name, FILE *stream) * in a dependency spec, add the command to the list of * commands of all targets in the dependency spec */ - Lst_ForEach (targets, ParseAddCmd, cp); - Lst_AtEnd(targCmds, (void *) line); + Lst_ForEach(targets, ParseAddCmd, cp); + Lst_AtEnd(targCmds, (void *)line); continue; } else { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Unassociated shell command \"%s\"", cp); } } #ifdef SYSVINCLUDE - } else if (strncmp (line, "include", 7) == 0 && - isspace((unsigned char) line[7]) && + } else if (strncmp(line, "include", 7) == 0 && + isspace((unsigned char)line[7]) && strchr(line, ':') == NULL) { /* * It's an S3/S5-style "include". */ - ParseTraditionalInclude (line + 7); + ParseTraditionalInclude(line + 7); goto nextLine; #endif - } else if (Parse_IsVar (line)) { + } else if (Parse_IsVar(line)) { ParseFinishLine(); - Parse_DoVar (line, VAR_GLOBAL); + Parse_DoVar(line, VAR_GLOBAL); } else { /* * We now know it's a dependency line so it needs to have all @@ -2466,8 +2478,8 @@ Parse_File(char *name, FILE *stream) * and add it to the current list of targets. */ cp = line; - if (isspace((unsigned char) line[0])) { - while ((*cp != '\0') && isspace((unsigned char) *cp)) { + if (isspace((unsigned char)line[0])) { + while ((*cp != '\0') && isspace((unsigned char)*cp)) { cp++; } if (*cp == '\0') { @@ -2477,8 +2489,8 @@ Parse_File(char *name, FILE *stream) ParseFinishLine(); - cp = Var_Subst (NULL, line, VAR_CMD, TRUE); - free (line); + cp = Var_Subst(NULL, line, VAR_CMD, TRUE); + free(line); line = cp; /* @@ -2487,7 +2499,7 @@ Parse_File(char *name, FILE *stream) if (targets) Lst_Destroy(targets, NOFREE); - targets = Lst_Init (FALSE); + targets = Lst_Init(FALSE); inLine = TRUE; ParseDoDependency (line); @@ -2495,7 +2507,7 @@ Parse_File(char *name, FILE *stream) nextLine: - free (line); + free(line); } /* * Reached EOF, but it may be just EOF of an include file... @@ -2524,18 +2536,20 @@ Parse_File(char *name, FILE *stream) *--------------------------------------------------------------------- */ void -Parse_Init (void) +Parse_Init(void) { + mainNode = NULL; - parseIncPath = Lst_Init (FALSE); - sysIncPath = Lst_Init (FALSE); - includes = Lst_Init (FALSE); - targCmds = Lst_Init (FALSE); + parseIncPath = Lst_Init(FALSE); + sysIncPath = Lst_Init(FALSE); + includes = Lst_Init(FALSE); + targCmds = Lst_Init(FALSE); } void -Parse_End (void) +Parse_End(void) { + Lst_Destroy(targCmds, free); if (targets) Lst_Destroy(targets, NOFREE); @@ -2564,16 +2578,16 @@ Parse_MainName(void) { Lst listmain; /* result list */ - listmain = Lst_Init (FALSE); + listmain = Lst_Init(FALSE); if (mainNode == NULL) { - Punt ("no target to make."); + Punt("no target to make."); /*NOTREACHED*/ } else if (mainNode->type & OP_DOUBLEDEP) { - (void) Lst_AtEnd (listmain, (void *)mainNode); + Lst_AtEnd(listmain, (void *)mainNode); Lst_Concat(listmain, mainNode->cohorts, LST_CONCNEW); } else - (void) Lst_AtEnd (listmain, (void *)mainNode); + Lst_AtEnd(listmain, (void *)mainNode); return (listmain); } diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c index 1aa54f78477c..0e5ff67d289b 100644 --- a/usr.bin/make/str.c +++ b/usr.bin/make/str.c @@ -55,6 +55,7 @@ void str_init(void) { char *p1; + argv = (char **)emalloc(((argmax = 50) + 1) * sizeof(char *)); argv[0] = Var_Value(".MAKE", VAR_GLOBAL, &p1); } @@ -115,10 +116,10 @@ str_concat(char *s1, char *s2, int flags) /* free original strings */ if (flags & STR_DOFREE) { - (void)free(s1); - (void)free(s2); + free(s1); + free(s2); } - return(result); + return (result); } /*- @@ -238,11 +239,11 @@ brk_string(char *str, int *store_argc, Boolean expand) } if (!start) start = t; - *t++ = (char) ch; + *t++ = (char)ch; } done: argv[argc] = (char *)NULL; *store_argc = argc; - return(argv); + return (argv); } /* @@ -268,9 +269,9 @@ Str_Match(const char *string, const char *pattern) * pattern but not at the end of the string, we failed. */ if (*pattern == 0) - return(!*string); + return (!*string); if (*string == 0 && *pattern != '*') - return(0); + return (0); /* * Check for a "*" as the next pattern character. It matches * any substring. We handle this by calling ourselves @@ -280,13 +281,13 @@ Str_Match(const char *string, const char *pattern) if (*pattern == '*') { pattern += 1; if (*pattern == 0) - return(1); + return (1); while (*string != 0) { if (Str_Match(string, pattern)) - return(1); + return (1); ++string; } - return(0); + return (0); } /* * Check for a "?" as the next pattern character. It matches @@ -303,13 +304,13 @@ Str_Match(const char *string, const char *pattern) ++pattern; for (;;) { if ((*pattern == ']') || (*pattern == 0)) - return(0); + return (0); if (*pattern == *string) break; if (pattern[1] == '-') { c2 = pattern[2]; if (c2 == 0) - return(0); + return (0); if ((*pattern <= *string) && (c2 >= *string)) break; @@ -331,14 +332,14 @@ Str_Match(const char *string, const char *pattern) if (*pattern == '\\') { ++pattern; if (*pattern == 0) - return(0); + return (0); } /* * There's no special character. Just make sure that the * next characters of each string match. */ if (*pattern != *string) - return(0); + return (0); thisCharOK: ++pattern; ++string; } @@ -370,13 +371,13 @@ Str_SYSVMatch(const char *word, const char *pattern, int *len) if (*w == '\0') { /* Zero-length word cannot be matched against */ *len = 0; - return NULL; + return (NULL); } if (*p == '\0') { /* Null pattern is the whole string */ *len = strlen(w); - return w; + return (w); } if ((m = strchr(p, '%')) != NULL) { @@ -385,12 +386,12 @@ Str_SYSVMatch(const char *word, const char *pattern, int *len) continue; if (p != m) - return NULL; /* No match */ + return (NULL); /* No match */ if (*++p == '\0') { /* No more pattern, return the rest of the string */ *len = strlen(w); - return w; + return (w); } } @@ -400,11 +401,11 @@ Str_SYSVMatch(const char *word, const char *pattern, int *len) do if (strcmp(p, w) == 0) { *len = w - m; - return m; + return (m); } while (*w++ != '\0'); - return NULL; + return (NULL); } @@ -430,14 +431,14 @@ Str_SYSVSubst(Buffer buf, const char *pat, const char *src, int len) if ((m = strchr(pat, '%')) != NULL) { /* Copy the prefix */ - Buf_AddBytes(buf, m - pat, (Byte *) pat); + Buf_AddBytes(buf, m - pat, (Byte *)pat); /* skip the % */ pat = m + 1; } /* Copy the pattern */ - Buf_AddBytes(buf, len, (Byte *) src); + Buf_AddBytes(buf, len, (Byte *)src); /* append the rest */ - Buf_AddBytes(buf, strlen(pat), (Byte *) pat); + Buf_AddBytes(buf, strlen(pat), (Byte *)pat); } diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c index bd02152b5bfb..8369c2993f79 100644 --- a/usr.bin/make/suff.c +++ b/usr.bin/make/suff.c @@ -192,8 +192,9 @@ static int SuffPrintTrans(void *, void *); *----------------------------------------------------------------------- */ static char * -SuffStrIsPrefix (char *pref, char *str) +SuffStrIsPrefix(char *pref, char *str) { + while (*str && *pref == *str) { pref++; str++; @@ -217,7 +218,7 @@ SuffStrIsPrefix (char *pref, char *str) *----------------------------------------------------------------------- */ static char * -SuffSuffIsSuffix (Suff *s, char *str) +SuffSuffIsSuffix(Suff *s, char *str) { char *p1; /* Pointer into suffix name */ char *p2; /* Pointer into string being examined */ @@ -250,7 +251,8 @@ SuffSuffIsSuffix (Suff *s, char *str) static int SuffSuffIsSuffixP(void *s, void *str) { - return(!SuffSuffIsSuffix((Suff *) s, (char *) str)); + + return (!SuffSuffIsSuffix((Suff *)s, (char *)str)); } /*- @@ -267,9 +269,10 @@ SuffSuffIsSuffixP(void *s, void *str) *----------------------------------------------------------------------- */ static int -SuffSuffHasNameP (void *s, void *sname) +SuffSuffHasNameP(void *s, void *sname) { - return (strcmp ((char *) sname, ((Suff *) s)->name)); + + return (strcmp((char *)sname, ((Suff *)s)->name)); } /*- @@ -288,9 +291,10 @@ SuffSuffHasNameP (void *s, void *sname) *----------------------------------------------------------------------- */ static int -SuffSuffIsPrefix (void *s, void *str) +SuffSuffIsPrefix(void *s, void *str) { - return (SuffStrIsPrefix (((Suff *) s)->name, (char *) str) == NULL ? 1 : 0); + + return (SuffStrIsPrefix(((Suff *)s)->name, (char *)str) == NULL ? 1 : 0); } /*- @@ -306,9 +310,10 @@ SuffSuffIsPrefix (void *s, void *str) *----------------------------------------------------------------------- */ static int -SuffGNHasNameP (void *gn, void *name) +SuffGNHasNameP(void *gn, void *name) { - return (strcmp ((char *) name, ((GNode *) gn)->name)); + + return (strcmp((char *)name, ((GNode *)gn)->name)); } /*********** Maintenance Functions ************/ @@ -326,7 +331,7 @@ SuffGNHasNameP (void *gn, void *name) *----------------------------------------------------------------------- */ static void -SuffFree (void *sp) +SuffFree(void *sp) { Suff *s = (Suff *) sp; @@ -336,13 +341,13 @@ SuffFree (void *sp) if (s == emptySuff) emptySuff = NULL; - Lst_Destroy (s->ref, NOFREE); - Lst_Destroy (s->children, NOFREE); - Lst_Destroy (s->parents, NOFREE); - Lst_Destroy (s->searchPath, Dir_Destroy); + Lst_Destroy(s->ref, NOFREE); + Lst_Destroy(s->children, NOFREE); + Lst_Destroy(s->parents, NOFREE); + Lst_Destroy(s->searchPath, Dir_Destroy); - free (s->name); - free (s); + free(s->name); + free(s); } /*- @@ -366,7 +371,7 @@ SuffRemove(Lst l, Suff *s) s->refCount--; } } - + /*- *----------------------------------------------------------------------- * SuffInsert -- @@ -381,16 +386,16 @@ SuffRemove(Lst l, Suff *s) *----------------------------------------------------------------------- */ static void -SuffInsert (Lst l, Suff *s) +SuffInsert(Lst l, Suff *s) { LstNode ln; /* current element in l we're examining */ Suff *s2 = NULL; /* the suffix descriptor in this element */ - if (Lst_Open (l) == FAILURE) { + if (Lst_Open(l) == FAILURE) { return; } - while ((ln = Lst_Next (l)) != NULL) { - s2 = (Suff *) Lst_Datum (ln); + while ((ln = Lst_Next(l)) != NULL) { + s2 = (Suff *)Lst_Datum(ln); if (s2->sNum >= s->sNum) { break; } @@ -399,18 +404,18 @@ SuffInsert (Lst l, Suff *s) DEBUGF(SUFF, ("inserting an empty list?...")); } - Lst_Close (l); + Lst_Close(l); DEBUGF(SUFF, ("inserting %s(%d)...", s->name, s->sNum)); if (ln == NULL) { DEBUGF(SUFF, ("at end of list\n")); - (void)Lst_AtEnd (l, (void *)s); + Lst_AtEnd (l, (void *)s); s->refCount++; - (void)Lst_AtEnd(s->ref, (void *) l); + Lst_AtEnd(s->ref, (void *)l); } else if (s2->sNum != s->sNum) { DEBUGF(SUFF, ("before %s(%d)\n", s2->name, s2->sNum)); - (void)Lst_Insert (l, ln, (void *)s); + Lst_Insert(l, ln, (void *)s); s->refCount++; - (void)Lst_AtEnd(s->ref, (void *) l); + Lst_AtEnd(s->ref, (void *)l); } else { DEBUGF(SUFF, ("already there\n")); } @@ -434,9 +439,10 @@ SuffInsert (Lst l, Suff *s) *----------------------------------------------------------------------- */ void -Suff_ClearSuffixes (void) +Suff_ClearSuffixes(void) { - Lst_Concat (suffClean, sufflist, LST_CONCLINK); + + Lst_Concat(suffClean, sufflist, LST_CONCLINK); sufflist = Lst_Init(FALSE); sNum = 1; suffNull = emptySuff; @@ -446,7 +452,7 @@ Suff_ClearSuffixes (void) * NOFREE is used because all suffixes are are on the suffClean list. * suffNull should not have parents. */ - Lst_Destroy(suffNull->children, NOFREE); + Lst_Destroy(suffNull->children, NOFREE); suffNull->children = Lst_Init(FALSE); } @@ -488,7 +494,7 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) if (srcLn == NULL) { srcLn = Lst_Find(sufflist, (void *)str, SuffSuffIsPrefix); } else { - srcLn = Lst_FindFrom (sufflist, Lst_Succ(srcLn), (void *)str, + srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn), (void *)str, SuffSuffIsPrefix); } if (srcLn == NULL) { @@ -507,7 +513,7 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) */ *srcPtr = single; *targPtr = suffNull; - return(TRUE); + return (TRUE); } return (FALSE); } @@ -542,7 +548,7 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) *----------------------------------------------------------------------- */ Boolean -Suff_IsTransform (char *str) +Suff_IsTransform(char *str) { Suff *src, *targ; @@ -564,21 +570,21 @@ Suff_IsTransform (char *str) *----------------------------------------------------------------------- */ GNode * -Suff_AddTransform (char *line) +Suff_AddTransform(char *line) { GNode *gn; /* GNode of transformation rule */ Suff *s, /* source suffix */ *t; /* target suffix */ LstNode ln; /* Node for existing transformation */ - ln = Lst_Find (transforms, (void *)line, SuffGNHasNameP); + ln = Lst_Find(transforms, (void *)line, SuffGNHasNameP); if (ln == NULL) { /* * Make a new graph node for the transformation. It will be filled in * by the Parse module. */ - gn = Targ_NewGN (line); - (void)Lst_AtEnd (transforms, (void *)gn); + gn = Targ_NewGN(line); + Lst_AtEnd (transforms, (void *)gn); } else { /* * New specification for transformation rule. Just nuke the old list @@ -586,24 +592,24 @@ Suff_AddTransform (char *line) * free the commands themselves, because a given command can be * attached to several different transformations. */ - gn = (GNode *) Lst_Datum (ln); - Lst_Destroy (gn->commands, NOFREE); - Lst_Destroy (gn->children, NOFREE); - gn->commands = Lst_Init (FALSE); - gn->children = Lst_Init (FALSE); + gn = (GNode *)Lst_Datum(ln); + Lst_Destroy(gn->commands, NOFREE); + Lst_Destroy(gn->children, NOFREE); + gn->commands = Lst_Init(FALSE); + gn->children = Lst_Init(FALSE); } gn->type = OP_TRANSFORM; - (void)SuffParseTransform(line, &s, &t); + SuffParseTransform(line, &s, &t); /* * link the two together in the proper relationship and order */ DEBUGF(SUFF, ("defining transformation from `%s' to `%s'\n", s->name, t->name)); - SuffInsert (t->children, s); - SuffInsert (s->parents, t); + SuffInsert(t->children, s); + SuffInsert(s->parents, t); return (gn); } @@ -628,7 +634,7 @@ Suff_AddTransform (char *line) int Suff_EndTransform(void *gnp, void *dummy __unused) { - GNode *gn = (GNode *) gnp; + GNode *gn = (GNode *)gnp; if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) && Lst_IsEmpty(gn->children)) @@ -688,8 +694,8 @@ Suff_EndTransform(void *gnp, void *dummy __unused) static int SuffRebuildGraph(void *transformp, void *sp) { - GNode *transform = (GNode *) transformp; - Suff *s = (Suff *) sp; + GNode *transform = (GNode *)transformp; + Suff *s = (Suff *)sp; char *cp; LstNode ln; Suff *s2 = NULL; @@ -703,7 +709,7 @@ SuffRebuildGraph(void *transformp, void *sp) s2 = suffNull; else { ln = Lst_Find(sufflist, (void *)cp, SuffSuffHasNameP); - if (ln != NULL) + if (ln != NULL) s2 = (Suff *)Lst_Datum(ln); } if (s2 != NULL) { @@ -713,7 +719,7 @@ SuffRebuildGraph(void *transformp, void *sp) */ SuffInsert(s2->children, s); SuffInsert(s->parents, s2); - return(0); + return (0); } } @@ -740,7 +746,7 @@ SuffRebuildGraph(void *transformp, void *sp) SuffInsert(s2->parents, s); } } - return(0); + return (0); } /*- @@ -758,31 +764,31 @@ SuffRebuildGraph(void *transformp, void *sp) *----------------------------------------------------------------------- */ void -Suff_AddSuffix (char *str) +Suff_AddSuffix(char *str) { Suff *s; /* new suffix descriptor */ LstNode ln; - ln = Lst_Find (sufflist, (void *)str, SuffSuffHasNameP); + ln = Lst_Find(sufflist, (void *)str, SuffSuffHasNameP); if (ln == NULL) { - s = (Suff *) emalloc (sizeof (Suff)); + s = (Suff *)emalloc(sizeof(Suff)); - s->name = estrdup (str); - s->nameLen = strlen (s->name); - s->searchPath = Lst_Init (FALSE); - s->children = Lst_Init (FALSE); - s->parents = Lst_Init (FALSE); - s->ref = Lst_Init (FALSE); - s->sNum = sNum++; - s->flags = 0; - s->refCount = 0; + s->name = estrdup(str); + s->nameLen = strlen (s->name); + s->searchPath = Lst_Init(FALSE); + s->children = Lst_Init(FALSE); + s->parents = Lst_Init(FALSE); + s->ref = Lst_Init(FALSE); + s->sNum = sNum++; + s->flags = 0; + s->refCount = 0; - (void)Lst_AtEnd (sufflist, (void *)s); + Lst_AtEnd(sufflist, (void *)s); /* * Look for any existing transformations from or to this suffix. * XXX: Only do this after a Suff_ClearSuffixes? */ - Lst_ForEach (transforms, SuffRebuildGraph, (void *)s); + Lst_ForEach(transforms, SuffRebuildGraph, (void *)s); } } @@ -800,16 +806,16 @@ Suff_AddSuffix (char *str) *----------------------------------------------------------------------- */ Lst -Suff_GetPath (char *sname) +Suff_GetPath(char *sname) { LstNode ln; Suff *s; - ln = Lst_Find (sufflist, (void *)sname, SuffSuffHasNameP); + ln = Lst_Find(sufflist, (void *)sname, SuffSuffHasNameP); if (ln == NULL) { return (NULL); } else { - s = (Suff *) Lst_Datum (ln); + s = (Suff *)Lst_Datum(ln); return (s->searchPath); } } @@ -841,16 +847,16 @@ Suff_DoPaths(void) Lst inIncludes; /* Cumulative .INCLUDES path */ Lst inLibs; /* Cumulative .LIBS path */ - if (Lst_Open (sufflist) == FAILURE) { + if (Lst_Open(sufflist) == FAILURE) { return; } inIncludes = Lst_Init(FALSE); inLibs = Lst_Init(FALSE); - while ((ln = Lst_Next (sufflist)) != NULL) { - s = (Suff *) Lst_Datum (ln); - if (!Lst_IsEmpty (s->searchPath)) { + while ((ln = Lst_Next(sufflist)) != NULL) { + s = (Suff *)Lst_Datum(ln); + if (!Lst_IsEmpty(s->searchPath)) { #ifdef INCLUDES if (s->flags & SUFF_INCLUDE) { Dir_Concat(inIncludes, s->searchPath); @@ -863,7 +869,7 @@ Suff_DoPaths(void) #endif /* LIBRARIES */ Dir_Concat(s->searchPath, dirSearchPath); } else { - Lst_Destroy (s->searchPath, Dir_Destroy); + Lst_Destroy(s->searchPath, Dir_Destroy); s->searchPath = Lst_Duplicate(dirSearchPath, Dir_CopyDir); } } @@ -876,7 +882,7 @@ Suff_DoPaths(void) Lst_Destroy(inIncludes, Dir_Destroy); Lst_Destroy(inLibs, Dir_Destroy); - Lst_Close (sufflist); + Lst_Close(sufflist); } /*- @@ -895,14 +901,14 @@ Suff_DoPaths(void) *----------------------------------------------------------------------- */ void -Suff_AddInclude (char *sname) +Suff_AddInclude(char *sname) { LstNode ln; Suff *s; - ln = Lst_Find (sufflist, (void *)sname, SuffSuffHasNameP); + ln = Lst_Find(sufflist, (void *)sname, SuffSuffHasNameP); if (ln != NULL) { - s = (Suff *) Lst_Datum (ln); + s = (Suff *)Lst_Datum(ln); s->flags |= SUFF_INCLUDE; } } @@ -924,14 +930,14 @@ Suff_AddInclude (char *sname) *----------------------------------------------------------------------- */ void -Suff_AddLib (char *sname) +Suff_AddLib(char *sname) { LstNode ln; Suff *s; - ln = Lst_Find (sufflist, (void *)sname, SuffSuffHasNameP); + ln = Lst_Find(sufflist, (void *)sname, SuffSuffHasNameP); if (ln != NULL) { - s = (Suff *) Lst_Datum (ln); + s = (Suff *)Lst_Datum(ln); s->flags |= SUFF_LIBRARY; } } @@ -953,7 +959,7 @@ Suff_AddLib (char *sname) *----------------------------------------------------------------------- */ static int -SuffAddSrc (void *sp, void *lsp) +SuffAddSrc(void *sp, void *lsp) { Suff *s = (Suff *) sp; LstSrc *ls = (LstSrc *) lsp; @@ -968,16 +974,16 @@ SuffAddSrc (void *sp, void *lsp) * structure for a file with no suffix attached. Two birds, and all * that... */ - s2 = (Src *) emalloc (sizeof (Src)); - s2->file = estrdup(targ->pref); - s2->pref = targ->pref; - s2->parent = targ; - s2->node = NULL; - s2->suff = s; + s2 = (Src *)emalloc(sizeof(Src)); + s2->file = estrdup(targ->pref); + s2->pref = targ->pref; + s2->parent = targ; + s2->node = NULL; + s2->suff = s; s->refCount++; s2->children = 0; targ->children += 1; - (void)Lst_AtEnd (ls->l, (void *)s2); + Lst_AtEnd(ls->l, (void *)s2); #ifdef DEBUG_SRC s2->cp = Lst_Init(FALSE); Lst_AtEnd(targ->cp, (void *) s2); @@ -986,16 +992,16 @@ SuffAddSrc (void *sp, void *lsp) printf("\n"); #endif } - s2 = (Src *) emalloc (sizeof (Src)); - s2->file = str_concat (targ->pref, s->name, 0); - s2->pref = targ->pref; - s2->parent = targ; - s2->node = NULL; - s2->suff = s; + s2 = (Src *)emalloc(sizeof(Src)); + s2->file = str_concat(targ->pref, s->name, 0); + s2->pref = targ->pref; + s2->parent = targ; + s2->node = NULL; + s2->suff = s; s->refCount++; s2->children = 0; targ->children += 1; - (void)Lst_AtEnd (ls->l, (void *)s2); + Lst_AtEnd(ls->l, (void *)s2); #ifdef DEBUG_SRC s2->cp = Lst_Init(FALSE); Lst_AtEnd(targ->cp, (void *) s2); @@ -1004,7 +1010,7 @@ SuffAddSrc (void *sp, void *lsp) printf("\n"); #endif - return(0); + return (0); } /*- @@ -1020,14 +1026,14 @@ SuffAddSrc (void *sp, void *lsp) *----------------------------------------------------------------------- */ static void -SuffAddLevel (Lst l, Src *targ) +SuffAddLevel(Lst l, Src *targ) { LstSrc ls; ls.s = targ; ls.l = l; - Lst_ForEach (targ->suff->children, SuffAddSrc, (void *)&ls); + Lst_ForEach(targ->suff->children, SuffAddSrc, (void *)&ls); } /*- @@ -1043,14 +1049,14 @@ SuffAddLevel (Lst l, Src *targ) *---------------------------------------------------------------------- */ static int -SuffRemoveSrc (Lst l) +SuffRemoveSrc(Lst l) { LstNode ln; Src *s; int t = 0; - if (Lst_Open (l) == FAILURE) { - return 0; + if (Lst_Open(l) == FAILURE) { + return (0); } #ifdef DEBUG_SRC printf("cleaning %lx: ", (unsigned long) l); @@ -1059,10 +1065,10 @@ SuffRemoveSrc (Lst l) #endif - while ((ln = Lst_Next (l)) != NULL) { - s = (Src *) Lst_Datum (ln); + while ((ln = Lst_Next(l)) != NULL) { + s = (Src *)Lst_Datum(ln); if (s->children == 0) { - free (s->file); + free(s->file); if (!s->parent) free(s->pref); else { @@ -1078,7 +1084,7 @@ SuffRemoveSrc (Lst l) Lst_Destroy(s->cp, NOFREE); #endif Lst_Remove(l, ln); - free (s); + free(s); t |= 1; Lst_Close(l); return TRUE; @@ -1086,7 +1092,7 @@ SuffRemoveSrc (Lst l) #ifdef DEBUG_SRC else { printf("keep: [l=%x] p=%x %d: ", l, s, s->children); - Lst_ForEach(s->cp, PrintAddr, (void *) 0); + Lst_ForEach(s->cp, PrintAddr, (void *)0); printf("\n"); } #endif @@ -1094,7 +1100,7 @@ SuffRemoveSrc (Lst l) Lst_Close(l); - return t; + return (t); } /*- @@ -1116,10 +1122,10 @@ SuffFindThem (Lst srcs, Lst slst) Src *rs; /* returned Src */ char *ptr; - rs = (Src *) NULL; + rs = (Src *)NULL; while (!Lst_IsEmpty (srcs)) { - s = (Src *) Lst_DeQueue (srcs); + s = (Src *)Lst_DeQueue(srcs); DEBUGF(SUFF, ("\ttrying %s...", s->file)); @@ -1135,7 +1141,7 @@ SuffFindThem (Lst srcs, Lst slst) break; } - if ((ptr = Dir_FindFile (s->file, s->suff->searchPath)) != NULL) { + if ((ptr = Dir_FindFile(s->file, s->suff->searchPath)) != NULL) { rs = s; #ifdef DEBUG_SRC printf("remove %x from %x\n", s, srcs); @@ -1146,8 +1152,8 @@ SuffFindThem (Lst srcs, Lst slst) DEBUGF(SUFF, ("not there\n")); - SuffAddLevel (srcs, s); - Lst_AtEnd(slst, (void *) s); + SuffAddLevel(srcs, s); + Lst_AtEnd(slst, (void *)s); } if (rs) { @@ -1183,25 +1189,24 @@ SuffFindCmds (Src *targ, Lst slst) char *cp; t = targ->node; - (void) Lst_Open (t->children); - prefLen = strlen (targ->pref); + Lst_Open(t->children); + prefLen = strlen(targ->pref); - while ((ln = Lst_Next (t->children)) != NULL) { - s = (GNode *)Lst_Datum (ln); + while ((ln = Lst_Next(t->children)) != NULL) { + s = (GNode *)Lst_Datum(ln); - cp = strrchr (s->name, '/'); + cp = strrchr(s->name, '/'); if (cp == (char *)NULL) { cp = s->name; } else { cp++; } - if (strncmp (cp, targ->pref, prefLen) == 0) { + if (strncmp(cp, targ->pref, prefLen) == 0) { /* * The node matches the prefix ok, see if it has a known * suffix. */ - ln = Lst_Find (sufflist, (void *)&cp[prefLen], - SuffSuffHasNameP); + ln = Lst_Find(sufflist, (void *)&cp[prefLen], SuffSuffHasNameP); if (ln != NULL) { /* * It even has a known suffix, see if there's a transformation @@ -1209,10 +1214,9 @@ SuffFindCmds (Src *targ, Lst slst) * * XXX: Handle multi-stage transformations here, too. */ - suff = (Suff *)Lst_Datum (ln); + suff = (Suff *)Lst_Datum(ln); - if (Lst_Member (suff->parents, - (void *)targ->suff) != NULL) + if (Lst_Member(suff->parents, (void *)targ->suff) != NULL) { /* * Hot Damn! Create a new Src structure to describe @@ -1220,7 +1224,7 @@ SuffFindCmds (Src *targ, Lst slst) * source node's name so Suff_FindDeps can free it * again (ick)), and return the new structure. */ - ret = (Src *)emalloc (sizeof (Src)); + ret = (Src *)emalloc (sizeof(Src)); ret->file = estrdup(s->name); ret->pref = targ->pref; ret->suff = suff; @@ -1232,16 +1236,16 @@ SuffFindCmds (Src *targ, Lst slst) #ifdef DEBUG_SRC ret->cp = Lst_Init(FALSE); printf("3 add %x %x\n", targ, ret); - Lst_AtEnd(targ->cp, (void *) ret); + Lst_AtEnd(targ->cp, (void *)ret); #endif - Lst_AtEnd(slst, (void *) ret); + Lst_AtEnd(slst, (void *)ret); DEBUGF(SUFF, ("\tusing existing source %s\n", s->name)); return (ret); } } } } - Lst_Close (t->children); + Lst_Close(t->children); return ((Src *)NULL); } @@ -1264,8 +1268,8 @@ SuffFindCmds (Src *targ, Lst slst) static int SuffExpandChildren(void *cgnp, void *pgnp) { - GNode *cgn = (GNode *) cgnp; - GNode *pgn = (GNode *) pgnp; + GNode *cgn = (GNode *)cgnp; + GNode *pgn = (GNode *)pgnp; GNode *gn; /* New source 8) */ LstNode prevLN; /* Node after which new source should be put */ LstNode ln; /* List element for old source */ @@ -1298,7 +1302,7 @@ SuffExpandChildren(void *cgnp, void *pgnp) */ char *sacrifice = cp; - (void)Arch_ParseArchive(&sacrifice, members, pgn); + Arch_ParseArchive(&sacrifice, members, pgn); } else { /* * Break the result into a vector of strings whose nodes @@ -1320,7 +1324,7 @@ SuffExpandChildren(void *cgnp, void *pgnp) */ *cp++ = '\0'; gn = Targ_FindNode(start, TARG_CREATE); - (void)Lst_AtEnd(members, (void *)gn); + Lst_AtEnd(members, (void *)gn); while (*cp == ' ' || *cp == '\t') { cp++; } @@ -1359,7 +1363,7 @@ SuffExpandChildren(void *cgnp, void *pgnp) * Stuff left over -- add it to the list too */ gn = Targ_FindNode(start, TARG_CREATE); - (void)Lst_AtEnd(members, (void *)gn); + Lst_AtEnd(members, (void *)gn); } /* * Point cp back at the beginning again so the variable value @@ -1375,9 +1379,9 @@ SuffExpandChildren(void *cgnp, void *pgnp) DEBUGF(SUFF, ("%s...", gn->name)); if (Lst_Member(pgn->children, (void *)gn) == NULL) { - (void)Lst_Append(pgn->children, prevLN, (void *)gn); + Lst_Append(pgn->children, prevLN, (void *)gn); prevLN = Lst_Succ(prevLN); - (void)Lst_AtEnd(gn->parents, (void *)pgn); + Lst_AtEnd(gn->parents, (void *)pgn); pgn->unmade++; } } @@ -1444,9 +1448,9 @@ SuffExpandChildren(void *cgnp, void *pgnp) * up the parent's count of unmade children. */ if (Lst_Member(pgn->children, (void *)gn) == NULL) { - (void)Lst_Append(pgn->children, prevLN, (void *)gn); + Lst_Append(pgn->children, prevLN, (void *)gn); prevLN = Lst_Succ(prevLN); - (void)Lst_AtEnd(gn->parents, (void *)pgn); + Lst_AtEnd(gn->parents, (void *)pgn); pgn->unmade++; } } @@ -1466,7 +1470,7 @@ SuffExpandChildren(void *cgnp, void *pgnp) DEBUGF(SUFF, ("\n")); } - return(0); + return (0); } /*- @@ -1499,8 +1503,8 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) * Not already linked, so form the proper links between the * target and source. */ - (void)Lst_AtEnd(tGn->children, (void *)sGn); - (void)Lst_AtEnd(sGn->parents, (void *)tGn); + Lst_AtEnd(tGn->children, (void *)sGn); + Lst_AtEnd(sGn->parents, (void *)tGn); tGn->unmade += 1; } @@ -1519,8 +1523,8 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) * Not already linked, so form the proper links between the * target and source. */ - (void)Lst_AtEnd(tGn->children, (void *)gn); - (void)Lst_AtEnd(gn->parents, (void *)tGn); + Lst_AtEnd(tGn->children, (void *)gn); + Lst_AtEnd(gn->parents, (void *)tGn); tGn->unmade += 1; } } @@ -1538,7 +1542,7 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) * called to link an OP_MEMBER and OP_ARCHV node), so return * FALSE. */ - return(FALSE); + return (FALSE); } gn = (GNode *)Lst_Datum(ln); @@ -1553,24 +1557,23 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) /* * Pass the buck to Make_HandleUse to apply the rule */ - (void)Make_HandleUse(gn, tGn); + Make_HandleUse(gn, tGn); /* * Deal with wildcards and variables in any acquired sources */ ln = Lst_Succ(ln); if (ln != NULL) { - Lst_ForEachFrom(tGn->children, ln, - SuffExpandChildren, (void *)tGn); + Lst_ForEachFrom(tGn->children, ln, SuffExpandChildren, (void *)tGn); } /* * Keep track of another parent to which this beast is transformed so * the .IMPSRC variable can be set correctly for the parent. */ - (void)Lst_AtEnd(sGn->iParents, (void *)tGn); + Lst_AtEnd(sGn->iParents, (void *)tGn); - return(TRUE); + return (TRUE); } @@ -1605,8 +1608,8 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) * The node is an archive(member) pair. so we must find a * suffix for both of them. */ - eoarch = strchr (gn->name, '('); - eoname = strchr (eoarch, ')'); + eoarch = strchr(gn->name, '('); + eoname = strchr(eoarch, ')'); *eoname = '\0'; /* Nuke parentheses during suffix search */ *eoarch = '\0'; /* So a suffix can be found */ @@ -1627,15 +1630,15 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) * Create the link between the two nodes right off */ if (Lst_Member(gn->children, (void *)mem) == NULL) { - (void)Lst_AtEnd(gn->children, (void *)mem); - (void)Lst_AtEnd(mem->parents, (void *)gn); + Lst_AtEnd(gn->children, (void *)mem); + Lst_AtEnd(mem->parents, (void *)gn); gn->unmade += 1; } /* * Copy in the variables from the member node to this one. */ - for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) { + for (i = (sizeof(copy) / sizeof(copy[0]))-1; i >= 0; i--) { char *p1; Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn); free(p1); @@ -1655,8 +1658,8 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) /* * Set the other two local variables required for this target. */ - Var_Set (MEMBER, name, gn); - Var_Set (ARCHIVE, gn->name, gn); + Var_Set(MEMBER, name, gn); + Var_Set(ARCHIVE, gn->name, gn); if (ms != NULL) { /* @@ -1777,7 +1780,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) /* * Allocate a Src structure to which things can be transformed */ - target = (Src *)emalloc(sizeof (Src)); + target = (Src *)emalloc(sizeof(Src)); target->file = estrdup(gn->name); target->suff = (Suff *)Lst_Datum(ln); target->suff->refCount++; @@ -1805,7 +1808,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) /* * Record the target so we can nuke it */ - (void)Lst_AtEnd(targs, (void *)target); + Lst_AtEnd(targs, (void *)target); /* * Search from this suffix's successor... @@ -1820,7 +1823,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) if (Lst_IsEmpty(targs) && suffNull != NULL) { DEBUGF(SUFF, ("\tNo known suffix on %s. Using .NULL suffix\n", gn->name)); - targ = (Src *)emalloc(sizeof (Src)); + targ = (Src *)emalloc(sizeof(Src)); targ->file = estrdup(gn->name); targ->suff = suffNull; targ->suff->refCount++; @@ -1844,7 +1847,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) DEBUGF(SUFF, ("adding suffix rules\n")); - (void)Lst_AtEnd(targs, (void *)targ); + Lst_AtEnd(targs, (void *)targ); } /* @@ -1987,8 +1990,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst) * up to, but not including, the parent node. */ while (bottom && bottom->parent != NULL) { - if (Lst_Member(slst, (void *) bottom) == NULL) { - Lst_AtEnd(slst, (void *) bottom); + if (Lst_Member(slst, (void *)bottom) == NULL) { + Lst_AtEnd(slst, (void *)bottom); } bottom = bottom->parent; } @@ -2069,8 +2072,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst) */ sfnd_return: if (bottom) - if (Lst_Member(slst, (void *) bottom) == NULL) - Lst_AtEnd(slst, (void *) bottom); + if (Lst_Member(slst, (void *)bottom) == NULL) + Lst_AtEnd(slst, (void *)bottom); while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs)) continue; @@ -2079,7 +2082,6 @@ SuffFindNormalDeps(GNode *gn, Lst slst) Lst_Concat(slst, targs, LST_CONCLINK); } - /*- *----------------------------------------------------------------------- * Suff_FindDeps -- @@ -2107,7 +2109,6 @@ SuffFindNormalDeps(GNode *gn, Lst slst) * *----------------------------------------------------------------------- */ - void Suff_FindDeps(GNode *gn) { @@ -2119,8 +2120,9 @@ Suff_FindDeps(GNode *gn) static void -SuffFindDeps (GNode *gn, Lst slst) +SuffFindDeps(GNode *gn, Lst slst) { + if (gn->type & OP_DEPS_FOUND) { /* * If dependencies already found, no need to do it again... @@ -2146,16 +2148,16 @@ SuffFindDeps (GNode *gn, Lst slst) LstNode ln; Suff *s; - ln = Lst_Find (sufflist, (void *)LIBSUFF, SuffSuffHasNameP); + ln = Lst_Find(sufflist, (void *)LIBSUFF, SuffSuffHasNameP); if (gn->suffix) gn->suffix->refCount--; if (ln != NULL) { - gn->suffix = s = (Suff *) Lst_Datum (ln); + gn->suffix = s = (Suff *)Lst_Datum (ln); gn->suffix->refCount++; - Arch_FindLib (gn, s->searchPath); + Arch_FindLib(gn, s->searchPath); } else { gn->suffix = NULL; - Var_Set (TARGET, gn->name, gn); + Var_Set(TARGET, gn->name, gn); } /* * Because a library (-lfoo) target doesn't follow the standard @@ -2203,7 +2205,7 @@ Suff_SetNull(char *name) */ suffNull = s; } else { - Parse_Error (PARSE_WARNING, "Desired null suffix %s not defined.", + Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.", name); } } @@ -2221,12 +2223,13 @@ Suff_SetNull(char *name) *----------------------------------------------------------------------- */ void -Suff_Init (void) +Suff_Init(void) { - sufflist = Lst_Init (FALSE); + + sufflist = Lst_Init(FALSE); suffClean = Lst_Init(FALSE); - srclist = Lst_Init (FALSE); - transforms = Lst_Init (FALSE); + srclist = Lst_Init(FALSE); + transforms = Lst_Init(FALSE); sNum = 0; /* @@ -2234,22 +2237,20 @@ Suff_Init (void) * actually go on the suffix list or everyone will think that's its * suffix. */ - emptySuff = suffNull = (Suff *) emalloc (sizeof (Suff)); + emptySuff = suffNull = (Suff *)emalloc(sizeof(Suff)); - suffNull->name = estrdup (""); - suffNull->nameLen = 0; - suffNull->searchPath = Lst_Init (FALSE); + suffNull->name = estrdup(""); + suffNull->nameLen = 0; + suffNull->searchPath = Lst_Init(FALSE); Dir_Concat(suffNull->searchPath, dirSearchPath); - suffNull->children = Lst_Init (FALSE); - suffNull->parents = Lst_Init (FALSE); - suffNull->ref = Lst_Init (FALSE); - suffNull->sNum = sNum++; - suffNull->flags = SUFF_NULL; - suffNull->refCount = 1; - + suffNull->children = Lst_Init(FALSE); + suffNull->parents = Lst_Init(FALSE); + suffNull->ref = Lst_Init(FALSE); + suffNull->sNum = sNum++; + suffNull->flags = SUFF_NULL; + suffNull->refCount = 1; } - /*- *---------------------------------------------------------------------- * Suff_End -- @@ -2266,6 +2267,7 @@ Suff_Init (void) void Suff_End(void) { + Lst_Destroy(sufflist, SuffFree); Lst_Destroy(suffClean, SuffFree); if (suffNull) @@ -2274,40 +2276,40 @@ Suff_End(void) Lst_Destroy(transforms, NOFREE); } - /********************* DEBUGGING FUNCTIONS **********************/ static int SuffPrintName(void *s, void *dummy __unused) { - printf ("`%s' ", ((Suff *) s)->name); + + printf("`%s' ", ((Suff *)s)->name); return (0); } static int -SuffPrintSuff (void *sp, void *dummy __unused) +SuffPrintSuff(void *sp, void *dummy __unused) { - Suff *s = (Suff *) sp; + Suff *s = (Suff *)sp; int flags; int flag; - printf ("# `%s' [%d] ", s->name, s->refCount); + printf("# `%s' [%d] ", s->name, s->refCount); flags = s->flags; if (flags) { - fputs (" (", stdout); + fputs(" (", stdout); while (flags) { flag = 1 << (ffs(flags) - 1); flags &= ~flag; switch (flag) { case SUFF_NULL: - printf ("NULL"); + printf("NULL"); break; case SUFF_INCLUDE: - printf ("INCLUDE"); + printf("INCLUDE"); break; case SUFF_LIBRARY: - printf ("LIBRARY"); + printf("LIBRARY"); break; default: break; @@ -2315,38 +2317,39 @@ SuffPrintSuff (void *sp, void *dummy __unused) fputc(flags ? '|' : ')', stdout); } } - fputc ('\n', stdout); - printf ("#\tTo: "); + fputc('\n', stdout); + printf("#\tTo: "); Lst_ForEach (s->parents, SuffPrintName, (void *)0); - fputc ('\n', stdout); - printf ("#\tFrom: "); + fputc('\n', stdout); + printf("#\tFrom: "); Lst_ForEach (s->children, SuffPrintName, (void *)0); - fputc ('\n', stdout); - printf ("#\tSearch Path: "); - Dir_PrintPath (s->searchPath); - fputc ('\n', stdout); + fputc('\n', stdout); + printf("#\tSearch Path: "); + Dir_PrintPath(s->searchPath); + fputc('\n', stdout); return (0); } static int -SuffPrintTrans (void *tp, void *dummy __unused) +SuffPrintTrans(void *tp, void *dummy __unused) { - GNode *t = (GNode *) tp; + GNode *t = (GNode *)tp; - printf ("%-16s: ", t->name); - Targ_PrintType (t->type); - fputc ('\n', stdout); - Lst_ForEach (t->commands, Targ_PrintCmd, (void *)0); - fputc ('\n', stdout); + printf("%-16s: ", t->name); + Targ_PrintType(t->type); + fputc('\n', stdout); + Lst_ForEach(t->commands, Targ_PrintCmd, (void *)0); + fputc('\n', stdout); return (0); } void Suff_PrintAll(void) { - printf ("#*** Suffixes:\n"); - Lst_ForEach (sufflist, SuffPrintSuff, (void *)0); - printf ("#*** Transformations:\n"); - Lst_ForEach (transforms, SuffPrintTrans, (void *)0); + printf("#*** Suffixes:\n"); + Lst_ForEach(sufflist, SuffPrintSuff, (void *)0); + + printf("#*** Transformations:\n"); + Lst_ForEach(transforms, SuffPrintTrans, (void *)0); } diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c index ca8a718e649c..cddf34a634a0 100644 --- a/usr.bin/make/targ.c +++ b/usr.bin/make/targ.c @@ -112,10 +112,11 @@ static void TargFreeGN(void *); *----------------------------------------------------------------------- */ void -Targ_Init (void) +Targ_Init(void) { - allTargets = Lst_Init (FALSE); - Hash_InitTable (&targets, HTSIZE); + + allTargets = Lst_Init(FALSE); + Hash_InitTable(&targets, HTSIZE); } /*- @@ -131,8 +132,9 @@ Targ_Init (void) *----------------------------------------------------------------------- */ void -Targ_End (void) +Targ_End(void) { + Lst_Destroy(allTargets, NOFREE); if (allGNs) Lst_Destroy(allGNs, TargFreeGN); @@ -153,37 +155,37 @@ Targ_End (void) *----------------------------------------------------------------------- */ GNode * -Targ_NewGN (char *name) +Targ_NewGN(char *name) { GNode *gn; - gn = (GNode *) emalloc (sizeof (GNode)); - gn->name = estrdup (name); - gn->path = (char *) 0; + gn = (GNode *)emalloc(sizeof(GNode)); + gn->name = estrdup(name); + gn->path = (char *)0; if (name[0] == '-' && name[1] == 'l') { gn->type = OP_LIB; } else { gn->type = 0; } - gn->unmade = 0; - gn->make = FALSE; - gn->made = UNMADE; - gn->childMade = FALSE; - gn->order = 0; + gn->unmade = 0; + gn->make = FALSE; + gn->made = UNMADE; + gn->childMade = FALSE; + gn->order = 0; gn->mtime = gn->cmtime = 0; - gn->iParents = Lst_Init (FALSE); - gn->cohorts = Lst_Init (FALSE); - gn->parents = Lst_Init (FALSE); - gn->children = Lst_Init (FALSE); - gn->successors = Lst_Init (FALSE); - gn->preds = Lst_Init (FALSE); - gn->context = Lst_Init (FALSE); - gn->commands = Lst_Init (FALSE); - gn->suffix = NULL; + gn->iParents = Lst_Init(FALSE); + gn->cohorts = Lst_Init(FALSE); + gn->parents = Lst_Init(FALSE); + gn->children = Lst_Init(FALSE); + gn->successors = Lst_Init(FALSE); + gn->preds = Lst_Init(FALSE); + gn->context = Lst_Init(FALSE); + gn->commands = Lst_Init(FALSE); + gn->suffix = NULL; if (allGNs == NULL) allGNs = Lst_Init(FALSE); - Lst_AtEnd(allGNs, (void *) gn); + Lst_AtEnd(allGNs, (void *)gn); return (gn); } @@ -201,11 +203,10 @@ Targ_NewGN (char *name) *----------------------------------------------------------------------- */ static void -TargFreeGN (void *gnp) +TargFreeGN(void *gnp) { GNode *gn = (GNode *) gnp; - free(gn->name); free(gn->path); @@ -236,29 +237,28 @@ TargFreeGN (void *gnp) *----------------------------------------------------------------------- */ GNode * -Targ_FindNode (char *name, int flags) +Targ_FindNode(char *name, int flags) { GNode *gn; /* node in that element */ Hash_Entry *he; /* New or used hash entry for node */ Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */ /* an entry for the node */ - if (flags & TARG_CREATE) { - he = Hash_CreateEntry (&targets, name, &isNew); + he = Hash_CreateEntry(&targets, name, &isNew); if (isNew) { - gn = Targ_NewGN (name); + gn = Targ_NewGN(name); Hash_SetValue (he, gn); - (void) Lst_AtEnd (allTargets, (void *)gn); + Lst_AtEnd(allTargets, (void *)gn); } } else { - he = Hash_FindEntry (&targets, name); + he = Hash_FindEntry(&targets, name); } if (he == (Hash_Entry *) NULL) { return (NULL); } else { - return ((GNode *) Hash_GetValue (he)); + return ((GNode *)Hash_GetValue(he)); } } @@ -278,36 +278,36 @@ Targ_FindNode (char *name, int flags) * ----------------------------------------------------------------------- */ Lst -Targ_FindList (Lst names, int flags) +Targ_FindList(Lst names, int flags) { Lst nodes; /* result list */ LstNode ln; /* name list element */ GNode *gn; /* node in tLn */ char *name; - nodes = Lst_Init (FALSE); + nodes = Lst_Init(FALSE); - if (Lst_Open (names) == FAILURE) { + if (Lst_Open(names) == FAILURE) { return (nodes); } - while ((ln = Lst_Next (names)) != NULL) { + while ((ln = Lst_Next(names)) != NULL) { name = (char *)Lst_Datum(ln); - gn = Targ_FindNode (name, flags); + gn = Targ_FindNode(name, flags); if (gn != NULL) { /* * Note: Lst_AtEnd must come before the Lst_Concat so the nodes * are added to the list in the order in which they were * encountered in the makefile. */ - (void) Lst_AtEnd (nodes, (void *)gn); + Lst_AtEnd(nodes, (void *)gn); if (gn->type & OP_DOUBLEDEP) { - (void)Lst_Concat (nodes, gn->cohorts, LST_CONCNEW); + Lst_Concat(nodes, gn->cohorts, LST_CONCNEW); } } else if (flags == TARG_NOCREATE) { - Error ("\"%s\" -- target unknown.", name); + Error("\"%s\" -- target unknown.", name); } } - Lst_Close (names); + Lst_Close(names); return (nodes); } @@ -324,9 +324,10 @@ Targ_FindList (Lst names, int flags) *----------------------------------------------------------------------- */ Boolean -Targ_Ignore (GNode *gn) +Targ_Ignore(GNode *gn) { - if (ignoreErrors || gn->type & OP_IGNORE) { + + if (ignoreErrors || (gn->type & OP_IGNORE)) { return (TRUE); } else { return (FALSE); @@ -346,9 +347,10 @@ Targ_Ignore (GNode *gn) *----------------------------------------------------------------------- */ Boolean -Targ_Silent (GNode *gn) +Targ_Silent(GNode *gn) { - if (beSilent || gn->type & OP_SILENT) { + + if (beSilent || (gn->type & OP_SILENT)) { return (TRUE); } else { return (FALSE); @@ -368,9 +370,10 @@ Targ_Silent (GNode *gn) *----------------------------------------------------------------------- */ Boolean -Targ_Precious (GNode *gn) +Targ_Precious(GNode *gn) { - if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) { + + if (allPrecious || (gn->type & (OP_PRECIOUS | OP_DOUBLEDEP))) { return (TRUE); } else { return (FALSE); @@ -380,6 +383,7 @@ Targ_Precious (GNode *gn) /******************* DEBUG INFO PRINTING ****************/ static GNode *mainTarg; /* the main target, as set by Targ_SetMain */ + /*- *----------------------------------------------------------------------- * Targ_SetMain -- @@ -394,23 +398,25 @@ static GNode *mainTarg; /* the main target, as set by Targ_SetMain */ *----------------------------------------------------------------------- */ void -Targ_SetMain (GNode *gn) +Targ_SetMain(GNode *gn) { + mainTarg = gn; } static int -TargPrintName (void *gnp, void *ppath) +TargPrintName(void *gnp, void *ppath) { GNode *gn = (GNode *) gnp; - printf ("%s ", gn->name); + + printf("%s ", gn->name); #ifdef notdef if (ppath) { if (gn->path) { - printf ("[%s] ", gn->path); + printf("[%s] ", gn->path); } if (gn == mainTarg) { - printf ("(MAIN NAME) "); + printf("(MAIN NAME) "); } } #endif /* notdef */ @@ -419,9 +425,10 @@ TargPrintName (void *gnp, void *ppath) int -Targ_PrintCmd (void *cmd, void *dummy __unused) +Targ_PrintCmd(void *cmd, void *dummy __unused) { - printf ("\t%s\n", (char *) cmd); + + printf("\t%s\n", (char *)cmd); return (0); } @@ -440,7 +447,7 @@ Targ_PrintCmd (void *cmd, void *dummy __unused) *----------------------------------------------------------------------- */ char * -Targ_FmtTime (time_t modtime) +Targ_FmtTime(time_t modtime) { struct tm *parts; static char buf[128]; @@ -449,7 +456,7 @@ Targ_FmtTime (time_t modtime) strftime(buf, sizeof buf, "%H:%M:%S %b %d, %Y", parts); buf[sizeof(buf) - 1] = '\0'; - return(buf); + return (buf); } /*- @@ -465,7 +472,7 @@ Targ_FmtTime (time_t modtime) *----------------------------------------------------------------------- */ void -Targ_PrintType (int type) +Targ_PrintType(int type) { int tbit; @@ -504,10 +511,11 @@ Targ_PrintType (int type) *----------------------------------------------------------------------- */ static int -TargPrintNode (void *gnp, void *passp) +TargPrintNode(void *gnp, void *passp) { - GNode *gn = (GNode *) gnp; - int pass = *(int *) passp; + GNode *gn = (GNode *)gnp; + int pass = *(int *)passp; + if (!OP_NOP(gn->type)) { printf("#\n"); if (gn == mainTarg) { @@ -539,14 +547,14 @@ TargPrintNode (void *gnp, void *passp) } if (!Lst_IsEmpty (gn->iParents)) { printf("# implicit parents: "); - Lst_ForEach (gn->iParents, TargPrintName, (void *)0); - fputc ('\n', stdout); + Lst_ForEach(gn->iParents, TargPrintName, (void *)0); + fputc('\n', stdout); } } if (!Lst_IsEmpty (gn->parents)) { printf("# parents: "); - Lst_ForEach (gn->parents, TargPrintName, (void *)0); - fputc ('\n', stdout); + Lst_ForEach(gn->parents, TargPrintName, (void *)0); + fputc('\n', stdout); } printf("%-16s", gn->name); @@ -560,13 +568,13 @@ TargPrintNode (void *gnp, void *passp) default: break; } - Targ_PrintType (gn->type); - Lst_ForEach (gn->children, TargPrintName, (void *)0); - fputc ('\n', stdout); - Lst_ForEach (gn->commands, Targ_PrintCmd, (void *)0); + Targ_PrintType(gn->type); + Lst_ForEach(gn->children, TargPrintName, (void *)0); + fputc('\n', stdout); + Lst_ForEach(gn->commands, Targ_PrintCmd, (void *)0); printf("\n\n"); if (gn->type & OP_DOUBLEDEP) { - Lst_ForEach (gn->cohorts, TargPrintNode, (void *)&pass); + Lst_ForEach(gn->cohorts, TargPrintNode, (void *)&pass); } } return (0); @@ -588,7 +596,8 @@ TargPrintNode (void *gnp, void *passp) static int TargPrintOnlySrc(void *gnp, void *dummy __unused) { - GNode *gn = (GNode *) gnp; + GNode *gn = (GNode *)gnp; + if (OP_NOP(gn->type)) printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name); @@ -608,17 +617,17 @@ TargPrintOnlySrc(void *gnp, void *dummy __unused) *----------------------------------------------------------------------- */ void -Targ_PrintGraph (int pass) +Targ_PrintGraph(int pass) { printf("#*** Input graph:\n"); - Lst_ForEach (allTargets, TargPrintNode, (void *)&pass); + Lst_ForEach(allTargets, TargPrintNode, (void *)&pass); printf("\n\n"); printf("#\n# Files that are only sources:\n"); - Lst_ForEach (allTargets, TargPrintOnlySrc, (void *) 0); + Lst_ForEach(allTargets, TargPrintOnlySrc, (void *)0); printf("#*** Global Variables:\n"); - Var_Dump (VAR_GLOBAL); + Var_Dump(VAR_GLOBAL); printf("#*** Command-line Variables:\n"); - Var_Dump (VAR_CMD); + Var_Dump(VAR_CMD); printf("\n"); Dir_PrintDirectories(); printf("\n"); diff --git a/usr.bin/make/util.c b/usr.bin/make/util.c index 55e6c3dc1926..29e1e50dcb63 100644 --- a/usr.bin/make/util.c +++ b/usr.bin/make/util.c @@ -81,9 +81,9 @@ Debug(const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)vfprintf(stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); - (void)fflush(stderr); + fflush(stderr); } /*- @@ -103,10 +103,10 @@ Error(const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)vfprintf(stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); - (void)fprintf(stderr, "\n"); - (void)fflush(stderr); + fprintf(stderr, "\n"); + fflush(stderr); } /*- @@ -130,10 +130,10 @@ Fatal(const char *fmt, ...) if (jobsRunning) Job_Wait(); - (void)vfprintf(stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); - (void)fprintf(stderr, "\n"); - (void)fflush(stderr); + fprintf(stderr, "\n"); + fflush(stderr); if (DEBUG(GRAPH2)) Targ_PrintGraph(2); @@ -158,11 +158,11 @@ Punt(const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)fprintf(stderr, "make: "); - (void)vfprintf(stderr, fmt, ap); + fprintf(stderr, "make: "); + vfprintf(stderr, fmt, ap); va_end(ap); - (void)fprintf(stderr, "\n"); - (void)fflush(stderr); + fprintf(stderr, "\n"); + fflush(stderr); DieHorribly(); } @@ -201,6 +201,7 @@ DieHorribly(void) void Finish(int errors) { + Fatal("%d error%s", errors, errors == 1 ? "" : "s"); } @@ -215,7 +216,7 @@ emalloc(size_t len) if ((p = malloc(len)) == NULL) enomem(); - return(p); + return (p); } /* @@ -229,7 +230,7 @@ estrdup(const char *str) if ((p = strdup(str)) == NULL) enomem(); - return(p); + return (p); } /* @@ -239,9 +240,10 @@ estrdup(const char *str) void * erealloc(void *ptr, size_t size) { + if ((ptr = realloc(ptr, size)) == NULL) enomem(); - return(ptr); + return (ptr); } /* @@ -264,13 +266,13 @@ eunlink(const char *file) struct stat st; if (lstat(file, &st) == -1) - return -1; + return (-1); if (S_ISDIR(st.st_mode)) { errno = EISDIR; - return -1; + return (-1); } - return unlink(file); + return (unlink(file)); } /* @@ -280,6 +282,7 @@ eunlink(const char *file) int PrintAddr(void *a, void *b __unused) { + printf("%p ", a); - return 0; + return (0); } diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index c00353bc4fad..fef69e0e0588 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -135,7 +135,7 @@ static void VarPossiblyExpand(char **, GNode *); static Var *VarFind(char *, GNode *, int); static void VarAdd(char *, char *, GNode *); static void VarDelete(void *); -static char *VarGetPattern(GNode *, int, char **, int, int *, int *, +static char *VarGetPattern(GNode *, int, char **, int, int *, int *, VarPattern *); static char *VarModify(char *, Boolean (*)(const char *, Boolean, Buffer, void *), @@ -156,9 +156,10 @@ static int VarPrintVar(void *, void *); *----------------------------------------------------------------------- */ static int -VarCmp (void *v, void *name) +VarCmp(void *v, void *name) { - return (strcmp ((char *) name, ((Var *) v)->name)); + + return (strcmp((char *)name, ((Var *)v)->name)); } /*- @@ -176,6 +177,7 @@ VarCmp (void *v, void *name) static void VarPossiblyExpand(char **name, GNode *ctxt) { + if (strchr(*name, '$') != NULL) *name = Var_Subst(NULL, *name, ctxt, 0); else @@ -202,7 +204,7 @@ VarPossiblyExpand(char **name, GNode *ctxt) *----------------------------------------------------------------------- */ static Var * -VarFind (char *name, GNode *ctxt, int flags) +VarFind(char *name, GNode *ctxt, int flags) { Boolean localCheckEnvFirst; LstNode var; @@ -214,7 +216,7 @@ VarFind (char *name, GNode *ctxt, int flags) * and substitute the short version in for 'name' if it matches one of * them. */ - if (*name == '.' && isupper((unsigned char) name[1])) + if (*name == '.' && isupper((unsigned char)name[1])) switch (name[1]) { case 'A': if (!strcmp(name, ".ALLSRC")) @@ -248,7 +250,7 @@ VarFind (char *name, GNode *ctxt, int flags) * Note whether this is one of the specific variables we were told through * the -E flag to use environment-variable-override for. */ - if (Lst_Find (envFirstVars, (void *)name, + if (Lst_Find(envFirstVars, (void *)name, (int (*)(void *, void *)) strcmp) != NULL) { localCheckEnvFirst = TRUE; @@ -261,23 +263,23 @@ VarFind (char *name, GNode *ctxt, int flags) * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, * depending on the FIND_* flags in 'flags' */ - var = Lst_Find (ctxt->context, (void *)name, VarCmp); + var = Lst_Find(ctxt->context, (void *)name, VarCmp); if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) { - var = Lst_Find (VAR_CMD->context, (void *)name, VarCmp); + var = Lst_Find(VAR_CMD->context, (void *)name, VarCmp); } if ((var == NULL) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL) && !checkEnvFirst && !localCheckEnvFirst) { - var = Lst_Find (VAR_GLOBAL->context, (void *)name, VarCmp); + var = Lst_Find(VAR_GLOBAL->context, (void *)name, VarCmp); } if ((var == NULL) && (flags & FIND_ENV)) { char *env; - if ((env = getenv (name)) != NULL) { + if ((env = getenv(name)) != NULL) { int len; - v = (Var *) emalloc(sizeof(Var)); + v = (Var *)emalloc(sizeof(Var)); v->name = estrdup(name); len = strlen(env); @@ -290,19 +292,19 @@ VarFind (char *name, GNode *ctxt, int flags) } else if ((checkEnvFirst || localCheckEnvFirst) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL)) { - var = Lst_Find (VAR_GLOBAL->context, (void *)name, VarCmp); + var = Lst_Find(VAR_GLOBAL->context, (void *)name, VarCmp); if (var == NULL) { - return ((Var *) NULL); + return ((Var *)NULL); } else { return ((Var *)Lst_Datum(var)); } } else { - return((Var *)NULL); + return ((Var *)NULL); } } else if (var == NULL) { - return ((Var *) NULL); + return ((Var *)NULL); } else { - return ((Var *) Lst_Datum (var)); + return ((Var *)Lst_Datum(var)); } } @@ -321,14 +323,14 @@ VarFind (char *name, GNode *ctxt, int flags) *----------------------------------------------------------------------- */ static void -VarAdd (char *name, char *val, GNode *ctxt) +VarAdd(char *name, char *val, GNode *ctxt) { Var *v; int len; - v = (Var *) emalloc (sizeof (Var)); + v = (Var *)emalloc(sizeof(Var)); - v->name = estrdup (name); + v->name = estrdup(name); len = val ? strlen(val) : 0; v->val = Buf_Init(len+1); @@ -336,12 +338,11 @@ VarAdd (char *name, char *val, GNode *ctxt) v->flags = 0; - (void) Lst_AtFront (ctxt->context, (void *)v); - (void) Lst_AtEnd (allVars, (void *) v); + Lst_AtFront(ctxt->context, (void *)v); + Lst_AtEnd(allVars, (void *)v); DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val)); } - /*- *----------------------------------------------------------------------- * VarDelete -- @@ -357,14 +358,13 @@ VarAdd (char *name, char *val, GNode *ctxt) static void VarDelete(void *vp) { - Var *v = (Var *) vp; + Var *v = (Var *)vp; + free(v->name); Buf_Destroy(v->val, TRUE); free(v); } - - /*- *----------------------------------------------------------------------- * Var_Delete -- @@ -392,7 +392,7 @@ Var_Delete(char *name, GNode *ctxt) Lst_Remove(ctxt->context, ln); ln = Lst_Member(allVars, v); Lst_Remove(allVars, ln); - VarDelete((void *) v); + VarDelete((void *)v); } } @@ -418,7 +418,7 @@ Var_Delete(char *name, GNode *ctxt) *----------------------------------------------------------------------- */ void -Var_Set (char *name, char *val, GNode *ctxt) +Var_Set(char *name, char *val, GNode *ctxt) { Var *v; @@ -428,9 +428,9 @@ Var_Set (char *name, char *val, GNode *ctxt) * point in searching them all just to save a bit of memory... */ VarPossiblyExpand(&name, ctxt); - v = VarFind (name, ctxt, 0); - if (v == (Var *) NULL) { - VarAdd (name, val, ctxt); + v = VarFind(name, ctxt, 0); + if (v == (Var *)NULL) { + VarAdd(name, val, ctxt); } else { Buf_Discard(v->val, Buf_Size(v->val)); Buf_AddBytes(v->val, strlen(val), (Byte *)val); @@ -470,21 +470,21 @@ Var_Set (char *name, char *val, GNode *ctxt) *----------------------------------------------------------------------- */ void -Var_Append (char *name, char *val, GNode *ctxt) +Var_Append(char *name, char *val, GNode *ctxt) { Var *v; VarPossiblyExpand(&name, ctxt); - v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); + v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); - if (v == (Var *) NULL) { - VarAdd (name, val, ctxt); + if (v == (Var *)NULL) { + VarAdd(name, val, ctxt); } else { Buf_AddByte(v->val, (Byte)' '); Buf_AddBytes(v->val, strlen(val), (Byte *)val); - DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, - (char *) Buf_GetAll(v->val, (int *)NULL))); + DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, + (char *)Buf_GetAll(v->val, (int *)NULL))); if (v->flags & VAR_FROM_ENV) { /* @@ -523,13 +523,13 @@ Var_Exists(char *name, GNode *ctxt) free(name); if (v == (Var *)NULL) { - return(FALSE); + return (FALSE); } else if (v->flags & VAR_FROM_ENV) { free(v->name); Buf_Destroy(v->val, TRUE); free((char *)v); } - return(TRUE); + return (TRUE); } /*- @@ -545,12 +545,12 @@ Var_Exists(char *name, GNode *ctxt) *----------------------------------------------------------------------- */ char * -Var_Value (char *name, GNode *ctxt, char **frp) +Var_Value(char *name, GNode *ctxt, char **frp) { Var *v; VarPossiblyExpand(&name, ctxt); - v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); + v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); free(name); *frp = NULL; if (v != (Var *) NULL) { @@ -560,9 +560,9 @@ Var_Value (char *name, GNode *ctxt, char **frp) free(v); *frp = p; } - return p; + return (p); } else { - return ((char *) NULL); + return ((char *)NULL); } } @@ -581,7 +581,7 @@ Var_Value (char *name, GNode *ctxt, char **frp) *----------------------------------------------------------------------- */ static char * -VarModify (char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *), +VarModify(char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *), void *datum) { Buffer buf; /* Buffer for the new string */ @@ -591,7 +591,7 @@ VarModify (char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *), char **av; /* word list [first word does not count] */ int ac, i; - buf = Buf_Init (0); + buf = Buf_Init(0); addSpace = FALSE; av = brk_string(str, &ac, FALSE); @@ -600,8 +600,8 @@ VarModify (char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *), addSpace = (*modProc)(av[i], addSpace, buf, datum); Buf_AddByte (buf, '\0'); - str = (char *)Buf_GetAll (buf, (int *)NULL); - Buf_Destroy (buf, FALSE); + str = (char *)Buf_GetAll(buf, (int *)NULL); + Buf_Destroy(buf, FALSE); return (str); } @@ -644,6 +644,7 @@ VarSortWords(char *str, int (*cmp)(const void *, const void *)) static int SortIncreasing(const void *l, const void *r) { + return (strcmp(*(const char* const*)l, *(const char* const*)r)); } @@ -676,6 +677,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, char *cp; Buffer buf = Buf_Init(0); int junk; + if (length == NULL) length = &junk; @@ -691,12 +693,12 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, */ for (cp = *tstr; *cp && (*cp != delim); cp++) { if (IS_A_MATCH(cp, delim)) { - Buf_AddByte(buf, (Byte) cp[1]); + Buf_AddByte(buf, (Byte)cp[1]); cp++; } else if (*cp == '$') { if (cp[1] == delim) { if (flags == NULL) - Buf_AddByte(buf, (Byte) *cp); + Buf_AddByte(buf, (Byte)*cp); else /* * Unescaped $ at end of pattern => anchor @@ -715,7 +717,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, * substitution and recurse. */ cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *) cp2); + Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); if (freeIt) free(cp2); cp += len - 1; @@ -743,33 +745,31 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, Buf_AddBytes(buf, cp2 - cp, (Byte *)cp); cp = --cp2; } else - Buf_AddByte(buf, (Byte) *cp); + Buf_AddByte(buf, (Byte)*cp); } } } else if (pattern && *cp == '&') Buf_AddBytes(buf, pattern->leftLen, (Byte *)pattern->lhs); else - Buf_AddByte(buf, (Byte) *cp); + Buf_AddByte(buf, (Byte)*cp); } - Buf_AddByte(buf, (Byte) '\0'); + Buf_AddByte(buf, (Byte)'\0'); if (*cp != delim) { *tstr = cp; *length = 0; - return NULL; - } - else { + return (NULL); + } else { *tstr = ++cp; - cp = (char *) Buf_GetAll(buf, length); + cp = (char *)Buf_GetAll(buf, length); *length -= 1; /* Don't count the NULL */ Buf_Destroy(buf, FALSE); - return cp; + return (cp); } } - /*- *----------------------------------------------------------------------- * Var_Quote -- @@ -786,22 +786,21 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, char * Var_Quote(const char *str) { - Buffer buf; /* This should cover most shells :-( */ static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; char *ret; - buf = Buf_Init (MAKE_BSIZE); + buf = Buf_Init(MAKE_BSIZE); for (; *str; str++) { if (strchr(meta, *str) != NULL) Buf_AddByte(buf, (Byte)'\\'); Buf_AddByte(buf, (Byte)*str); } - Buf_AddByte(buf, (Byte) '\0'); - ret = Buf_GetAll (buf, NULL); - Buf_Destroy (buf, FALSE); - return ret; + Buf_AddByte(buf, (Byte)'\0'); + ret = Buf_GetAll(buf, NULL); + Buf_Destroy(buf, FALSE); + return (ret); } /*- @@ -889,7 +888,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) name[0] = str[1]; name[1] = '\0'; - v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); + v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); if (v == (Var *)NULL) { if (str[1] != '\0') *lengthPtr = 2; @@ -909,13 +908,13 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) /* XXX: It looks like $% and $! are reversed here */ switch (str[1]) { case '@': - return("$(.TARGET)"); + return ("$(.TARGET)"); case '%': - return("$(.ARCHIVE)"); + return ("$(.ARCHIVE)"); case '*': - return("$(.PREFIX)"); + return ("$(.PREFIX)"); case '!': - return("$(.MEMBER)"); + return ("$(.MEMBER)"); default: break; } @@ -945,18 +944,18 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) int rlen; Boolean rfree; char* rval = Var_Parse(tstr, ctxt, err, &rlen, &rfree); - + if (rval == var_Error) { Fatal("Error expanding embedded variable."); } else if (rval != NULL) { - Buf_AddBytes(buf, strlen(rval), (Byte *) rval); + Buf_AddBytes(buf, strlen(rval), (Byte *)rval); if (rfree) free(rval); } tstr += rlen - 1; } else - Buf_AddByte(buf, (Byte) *tstr); - + Buf_AddByte(buf, (Byte)*tstr); + if (*tstr == '\0') { /* * If we never did find the end character, return NULL @@ -966,15 +965,15 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) *lengthPtr = tstr - str; return (var_Error); } - + haveModifier = (*tstr == ':'); *tstr = '\0'; - Buf_AddByte(buf, (Byte) '\0'); + Buf_AddByte(buf, (Byte)'\0'); str = Buf_GetAll(buf, NULL); vlen = strlen(str); - v = VarFind (str, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); + v = VarFind(str, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); if ((v == (Var *)NULL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) && (vlen == 2) && (str[1] == 'F' || str[1] == 'D')) { @@ -982,7 +981,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) * Check for bogus D and F forms of local variables since we're * in a local context and the name is the right length. */ - switch(str[0]) { + switch (str[0]) { case '@': case '%': case '*': @@ -1021,7 +1020,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) *lengthPtr = tstr-start+1; *tstr = endc; Buf_Destroy(buf, TRUE); - return(val); + return (val); } break; default: @@ -1032,8 +1031,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) if (v == (Var *)NULL) { if (((vlen == 1) || - (((vlen == 2) && (str[1] == 'F' || - str[1] == 'D')))) && + (((vlen == 2) && (str[1] == 'F' || str[1] == 'D')))) && ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL))) { /* @@ -1056,7 +1054,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) break; } } else if ((vlen > 2) && (str[0] == '.') && - isupper((unsigned char) str[1]) && + isupper((unsigned char)str[1]) && ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL))) { int len; @@ -1084,7 +1082,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) str[*lengthPtr] = '\0'; *freePtr = TRUE; Buf_Destroy(buf, TRUE); - return(str); + return (str); } else { Buf_Destroy(buf, TRUE); return (err ? var_Error : varNoError); @@ -1094,7 +1092,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) * Still need to get to the end of the variable specification, * so kludge up a Var structure for the modifications */ - v = (Var *) emalloc(sizeof(Var)); + v = (Var *)emalloc(sizeof(Var)); v->name = estrdup(str); v->val = Buf_Init(1); v->flags = VAR_JUNK; @@ -1119,7 +1117,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) * return. */ str = (char *)Buf_GetAll(v->val, (int *)NULL); - if (strchr (str, '$') != (char *)NULL) { + if (strchr(str, '$') != (char *)NULL) { str = Var_Subst(NULL, str, ctxt, err); *freePtr = TRUE; } @@ -1170,7 +1168,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) *cp != '\0' && *cp != ':' && *cp != endc; cp++) { - if (*cp == '\\' && (cp[1] == ':' || cp[1] == endc)){ + if (*cp == '\\' && (cp[1] == ':' || cp[1] == endc)) { copy = TRUE; cp++; } @@ -1203,8 +1201,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) if (*tstr == 'M' || *tstr == 'm') { newStr = VarModify(str, VarMatch, (void *)pattern); } else { - newStr = VarModify(str, VarNoMatch, - (void *)pattern); + newStr = VarModify(str, VarNoMatch, (void *)pattern); } if (copy) { free(pattern); @@ -1374,8 +1371,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) Fatal("Global substitution of the empty string"); termc = *cp; - newStr = VarModify(str, VarSubstitute, - (void *)&pattern); + newStr = VarModify(str, VarSubstitute, (void *)&pattern); /* * Free the two strings. */ @@ -1465,10 +1461,10 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) Buffer buf; buf = Buf_Init(MAKE_BSIZE); for (cp = str; *cp ; cp++) - Buf_AddByte(buf, (Byte) tolower(*cp)); + Buf_AddByte(buf, (Byte)tolower(*cp)); - Buf_AddByte(buf, (Byte) '\0'); - newStr = (char *) Buf_GetAll(buf, (int *) NULL); + Buf_AddByte(buf, (Byte)'\0'); + newStr = (char *)Buf_GetAll(buf, (int *)NULL); Buf_Destroy(buf, FALSE); cp = tstr + 1; @@ -1486,7 +1482,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) /* FALLTHROUGH */ case 'Q': if (tstr[1] == endc || tstr[1] == ':') { - newStr = Var_Quote (str); + newStr = Var_Quote(str); cp = tstr + 1; termc = *cp; break; @@ -1494,7 +1490,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) /*FALLTHRU*/ case 'T': if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify (str, VarTail, (void *)0); + newStr = VarModify(str, VarTail, (void *)0); cp = tstr + 1; termc = *cp; break; @@ -1505,10 +1501,10 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) Buffer buf; buf = Buf_Init(MAKE_BSIZE); for (cp = str; *cp ; cp++) - Buf_AddByte(buf, (Byte) toupper(*cp)); + Buf_AddByte(buf, (Byte)toupper(*cp)); - Buf_AddByte(buf, (Byte) '\0'); - newStr = (char *) Buf_GetAll(buf, (int *) NULL); + Buf_AddByte(buf, (Byte)'\0'); + newStr = (char *)Buf_GetAll(buf, (int *)NULL); Buf_Destroy(buf, FALSE); cp = tstr + 1; @@ -1518,7 +1514,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) /* FALLTHROUGH */ case 'H': if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify (str, VarHead, (void *)0); + newStr = VarModify(str, VarHead, (void *)0); cp = tstr + 1; termc = *cp; break; @@ -1526,7 +1522,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) /*FALLTHRU*/ case 'E': if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify (str, VarSuffix, (void *)0); + newStr = VarModify(str, VarSuffix, (void *)0); cp = tstr + 1; termc = *cp; break; @@ -1534,7 +1530,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) /*FALLTHRU*/ case 'R': if (tstr[1] == endc || tstr[1] == ':') { - newStr = VarModify (str, VarRoot, (void *)0); + newStr = VarModify(str, VarRoot, (void *)0); cp = tstr + 1; termc = *cp; break; @@ -1544,9 +1540,9 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) case 's': if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) { char *error; - newStr = Cmd_Exec (str, &error); + newStr = Cmd_Exec(str, &error); if (error) - Error (error, str); + Error(error, str); cp = tstr + 2; termc = *cp; break; @@ -1626,8 +1622,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) */ termc = *--cp; delim = '\0'; - newStr = VarModify(str, VarSYSVMatch, - (void *)&pattern); + newStr = VarModify(str, VarSYSVMatch, (void *)&pattern); free(pattern.lhs); free(pattern.rhs); @@ -1636,7 +1631,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) } else #endif { - Error ("Unknown modifier '%c'\n", *tstr); + Error("Unknown modifier '%c'\n", *tstr); for (cp = tstr+1; *cp != ':' && *cp != endc && *cp != '\0'; cp++) @@ -1649,7 +1644,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) DEBUGF(VAR, ("Result is \"%s\"\n", newStr)); if (*freePtr) { - free (str); + free(str); } str = newStr; if (str != var_Error) { @@ -1726,7 +1721,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr) *----------------------------------------------------------------------- */ char * -Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) +Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr) { Buffer buf; /* Buffer for forming things */ char *val; /* Value to substitute for a variable */ @@ -1736,7 +1731,7 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) * been reported to prevent a plethora * of messages when recursing */ - buf = Buf_Init (MAKE_BSIZE); + buf = Buf_Init(MAKE_BSIZE); errorReported = FALSE; while (*str) { @@ -1765,7 +1760,7 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) for (;;) { if (str[1] != '(' && str[1] != '{') { if (str[1] != *var || var[1] != '\0') { - Buf_AddBytes(buf, 2, (Byte *) str); + Buf_AddBytes(buf, 2, (Byte *)str); str += 2; expand = FALSE; } @@ -1789,7 +1784,7 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) * the nested one */ if (*p == '$') { - Buf_AddBytes(buf, p - str, (Byte *) str); + Buf_AddBytes(buf, p - str, (Byte *)str); str = p; continue; } @@ -1802,7 +1797,7 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) */ for (;*p != '$' && *p != '\0'; p++) continue; - Buf_AddBytes(buf, p - str, (Byte *) str); + Buf_AddBytes(buf, p - str, (Byte *)str); str = p; expand = FALSE; } @@ -1815,7 +1810,7 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) continue; } - val = Var_Parse (str, ctxt, undefErr, &length, &doFree); + val = Var_Parse(str, ctxt, undefErr, &length, &doFree); /* * When we come down here, val should either point to the @@ -1839,7 +1834,7 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) * when the file is parsed. */ if (!errorReported) { - Parse_Error (PARSE_FATAL, + Parse_Error(PARSE_FATAL, "Undefined variable \"%.*s\"",length,str); } str += length; @@ -1859,17 +1854,17 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) * Copy all the characters from the variable value straight * into the new string. */ - Buf_AddBytes (buf, strlen (val), (Byte *)val); + Buf_AddBytes(buf, strlen(val), (Byte *)val); if (doFree) { - free (val); + free(val); } } } } - Buf_AddByte (buf, '\0'); - str = (char *)Buf_GetAll (buf, (int *)NULL); - Buf_Destroy (buf, FALSE); + Buf_AddByte(buf, '\0'); + str = (char *)Buf_GetAll(buf, (int *)NULL); + Buf_Destroy(buf, FALSE); return (str); } @@ -1890,7 +1885,8 @@ Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr) char * Var_GetTail(char *file) { - return(VarModify(file, VarTail, (void *)0)); + + return (VarModify(file, VarTail, (void *)0)); } /*- @@ -1911,7 +1907,8 @@ Var_GetTail(char *file) char * Var_GetHead(char *file) { - return(VarModify(file, VarHead, (void *)0)); + + return (VarModify(file, VarHead, (void *)0)); } /*- @@ -1927,28 +1924,30 @@ Var_GetHead(char *file) *----------------------------------------------------------------------- */ void -Var_Init (void) +Var_Init(void) { - VAR_GLOBAL = Targ_NewGN ("Global"); - VAR_CMD = Targ_NewGN ("Command"); + + VAR_GLOBAL = Targ_NewGN("Global"); + VAR_CMD = Targ_NewGN("Command"); allVars = Lst_Init(FALSE); } - void -Var_End (void) +Var_End(void) { + Lst_Destroy(allVars, VarDelete); } /****************** PRINT DEBUGGING INFO *****************/ static int -VarPrintVar (void *vp, void *dummy __unused) +VarPrintVar(void *vp, void *dummy __unused) { Var *v = (Var *) vp; - printf ("%-16s = %s\n", v->name, (char *) Buf_GetAll(v->val, (int *)NULL)); + + printf("%-16s = %s\n", v->name, (char *)Buf_GetAll(v->val, (int *)NULL)); return (0); } @@ -1959,7 +1958,8 @@ VarPrintVar (void *vp, void *dummy __unused) *----------------------------------------------------------------------- */ void -Var_Dump (GNode *ctxt) +Var_Dump(GNode *ctxt) { - Lst_ForEach (ctxt->context, VarPrintVar, (void *) 0); + + Lst_ForEach (ctxt->context, VarPrintVar, (void *)0); } diff --git a/usr.bin/make/var.h b/usr.bin/make/var.h index 7a94f0628687..1621b46abcc9 100644 --- a/usr.bin/make/var.h +++ b/usr.bin/make/var.h @@ -68,8 +68,8 @@ typedef struct { int flags; } VarPattern; -typedef struct { - regex_t re; +typedef struct { + regex_t re; int nsub; regmatch_t *matches; char *replace; diff --git a/usr.bin/make/var_modify.c b/usr.bin/make/var_modify.c index 06a9cbff5a51..a71641a1d082 100644 --- a/usr.bin/make/var_modify.c +++ b/usr.bin/make/var_modify.c @@ -66,19 +66,19 @@ __FBSDID("$FreeBSD$"); *----------------------------------------------------------------------- */ Boolean -VarHead (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) +VarHead(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) { char *slash; char *buffer; buffer = estrdup(word); - slash = strrchr (buffer, '/'); + slash = strrchr(buffer, '/'); if (slash != NULL) { if (addSpace) { - Buf_AddByte (buf, (Byte)' '); + Buf_AddByte(buf, (Byte)' '); } *slash = '\0'; - Buf_AddBytes (buf, strlen (buffer), (Byte *)buffer); + Buf_AddBytes(buf, strlen (buffer), (Byte *)buffer); free(buffer); return (TRUE); } else { @@ -111,7 +111,7 @@ VarHead (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) *----------------------------------------------------------------------- */ Boolean -VarTail (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) +VarTail(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) { const char *slash; @@ -119,11 +119,11 @@ VarTail (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) Buf_AddByte (buf, (Byte)' '); } - slash = strrchr (word, '/'); + slash = strrchr(word, '/'); if (slash++ != NULL) { - Buf_AddBytes (buf, strlen(slash), (Byte *)slash); + Buf_AddBytes(buf, strlen(slash), (Byte *)slash); } else { - Buf_AddBytes (buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), (Byte *)word); } return (TRUE); } @@ -143,16 +143,16 @@ VarTail (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) *----------------------------------------------------------------------- */ Boolean -VarSuffix (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) +VarSuffix(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) { const char *dot; - dot = strrchr (word, '.'); + dot = strrchr(word, '.'); if (dot++ != (char *)NULL) { if (addSpace) { - Buf_AddByte (buf, (Byte)' '); + Buf_AddByte(buf, (Byte)' '); } - Buf_AddBytes (buf, strlen (dot), (Byte *)dot); + Buf_AddBytes(buf, strlen (dot), (Byte *)dot); addSpace = TRUE; } return (addSpace); @@ -174,21 +174,21 @@ VarSuffix (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) *----------------------------------------------------------------------- */ Boolean -VarRoot (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) +VarRoot(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) { char *buffer; char *dot; if (addSpace) { - Buf_AddByte (buf, (Byte)' '); + Buf_AddByte(buf, (Byte)' '); } buffer = estrdup(word); - dot = strrchr (buffer, '.'); + dot = strrchr(buffer, '.'); if (dot != NULL) { *dot = '\0'; } - Buf_AddBytes (buf, strlen(buffer), (Byte *)buffer); + Buf_AddBytes(buf, strlen(buffer), (Byte *)buffer); free(buffer); return (TRUE); } @@ -211,8 +211,9 @@ VarRoot (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) *----------------------------------------------------------------------- */ Boolean -VarMatch (const char *word, Boolean addSpace, Buffer buf, void *pattern) +VarMatch(const char *word, Boolean addSpace, Buffer buf, void *pattern) { + if (Str_Match(word, pattern)) { if (addSpace) { Buf_AddByte(buf, (Byte)' '); @@ -220,7 +221,7 @@ VarMatch (const char *word, Boolean addSpace, Buffer buf, void *pattern) addSpace = TRUE; Buf_AddBytes(buf, strlen(word), word); } - return(addSpace); + return (addSpace); } #ifdef SYSVVARSUB @@ -241,11 +242,11 @@ VarMatch (const char *word, Boolean addSpace, Buffer buf, void *pattern) *----------------------------------------------------------------------- */ Boolean -VarSYSVMatch (const char *word, Boolean addSpace, Buffer buf, void *patp) +VarSYSVMatch(const char *word, Boolean addSpace, Buffer buf, void *patp) { int len; const char *ptr; - VarPattern *pat = (VarPattern *) patp; + VarPattern *pat = (VarPattern *)patp; if (addSpace) Buf_AddByte(buf, (Byte)' '); @@ -257,7 +258,7 @@ VarSYSVMatch (const char *word, Boolean addSpace, Buffer buf, void *patp) else Buf_AddBytes(buf, strlen(word), (Byte *) word); - return(addSpace); + return (addSpace); } #endif @@ -279,8 +280,9 @@ VarSYSVMatch (const char *word, Boolean addSpace, Buffer buf, void *patp) *----------------------------------------------------------------------- */ Boolean -VarNoMatch (const char *word, Boolean addSpace, Buffer buf, void *pattern) +VarNoMatch(const char *word, Boolean addSpace, Buffer buf, void *pattern) { + if (!Str_Match(word, pattern)) { if (addSpace) { Buf_AddByte(buf, (Byte)' '); @@ -288,7 +290,7 @@ VarNoMatch (const char *word, Boolean addSpace, Buffer buf, void *pattern) addSpace = TRUE; Buf_AddBytes(buf, strlen(word), (Byte *)word); } - return(addSpace); + return (addSpace); } @@ -307,11 +309,11 @@ VarNoMatch (const char *word, Boolean addSpace, Buffer buf, void *pattern) *----------------------------------------------------------------------- */ Boolean -VarSubstitute (const char *word, Boolean addSpace, Buffer buf, void *patternp) +VarSubstitute(const char *word, Boolean addSpace, Buffer buf, void *patternp) { int wordLen; /* Length of word */ const char *cp; /* General pointer */ - VarPattern *pattern = (VarPattern *) patternp; + VarPattern *pattern = (VarPattern *)patternp; wordLen = strlen(word); if (1) { /* substitute in each word of the variable */ @@ -452,7 +454,7 @@ VarSubstitute (const char *word, Boolean addSpace, Buffer buf, void *patternp) Buf_AddByte(buf, (Byte)' '); } Buf_AddBytes(buf, wordLen, (Byte *)word); - return(TRUE); + return (TRUE); } /*- @@ -579,5 +581,5 @@ VarRESubstitute(const char *word, Boolean addSpace, Buffer buf, void *patternp) } break; } - return(addSpace||added); + return (addSpace||added); }