Subject: usr.bin/make code cleanups
To: None <tech-toolchain@netbsd.org>
From: Max Okumoto <okumoto@ucsd.edu>
List: tech-toolchain
Date: 02/02/2005 03:43:31
This is a multi-part message in MIME format.
--------------080506050003020508070005
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Here is another patch that cleans up more style(9) type problems and the
script that I used fix the problem.
- removes space between sizeof and paren.
- removes (object *) casts of emalloc(sizeof).
Both are things that style says not to do.
Max
--------------080506050003020508070005
Content-Type: text/plain;
name="scrub.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="scrub.sh"
#!/bin/sh
# Remove cast of (void *) functions. - style(9)
# do not follow sizeof with white space - style(9)
scrub() {
# Line 1 remove white space between sizeof and init paren.
# Line 2 remove cast (object **)
# Line 3 remove cast (object *)
# Line 4 remove cast (object*)
# Line 5 remove cast (object)
sed \
-e 's/sizeof[\t ]*(/sizeof(/g' \
-e 's/\(=[\t ]*\)([A-Za-z_][A-Za-z0-9_]* \*\*)[\t ]*emalloc[\t ]*(/\1emalloc(/g' \
-e 's/\(=[\t ]*\)([A-Za-z_][A-Za-z0-9_]* \*)[\t ]*emalloc[\t ]*(/\1emalloc(/g' \
-e 's/\(=[\t ]*\)([A-Za-z_][A-Za-z0-9_]*\*)[\t ]*emalloc[\t ]*(/\1emalloc(/g' \
-e 's/\(=[\t ]*\)([A-Za-z_][A-Za-z0-9_]*)[\t ]*emalloc[\t ]*(/\1emalloc(/g' \
-e '' < $1 > /tmp/$USER.scrub.$$
cp /tmp/$USER.scrub.$$ $1
}
for i in *.c; do
scrub $i
done
--------------080506050003020508070005
Content-Type: text/plain;
name="p2"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="p2"
diff nbsd-src fbsd-src
diff -ru nbsd-src/make.orig/arch.c nbsd-src/make/arch.c
--- nbsd-src/make.orig/arch.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/arch.c Wed Feb 2 03:35:21 2005
@@ -608,7 +608,7 @@
return ((struct ar_hdr *) NULL);
}
- ar = (Arch *)emalloc (sizeof (Arch));
+ ar = emalloc(sizeof(Arch));
ar->name = estrdup(archive);
ar->fnametab = NULL;
ar->fnamesize = 0;
@@ -1182,7 +1182,7 @@
char *libName; /* file name for archive */
size_t sz = strlen(gn->name) + 6 - 2;
- libName = (char *)emalloc(sz);
+ libName = emalloc(sz);
snprintf(libName, sz, "lib%s.a", &gn->name[2]);
gn->path = Dir_FindFile(libName, path);
diff -ru nbsd-src/make.orig/buf.c nbsd-src/make/buf.c
--- nbsd-src/make.orig/buf.c Wed Feb 2 02:52:24 2005
+++ nbsd-src/make/buf.c Wed Feb 2 03:35:21 2005
@@ -263,13 +263,13 @@
{
Buffer bp; /* New Buffer */
- bp = (Buffer)emalloc(sizeof(*bp));
+ bp = emalloc(sizeof(*bp));
if (size <= 0) {
size = BUF_DEF_SIZE;
}
bp->left = bp->size = size;
- bp->buffer = (Byte *)emalloc(size);
+ bp->buffer = emalloc(size);
bp->inPtr = bp->outPtr = bp->buffer;
*bp->inPtr = 0;
diff -ru nbsd-src/make.orig/dir.c nbsd-src/make/dir.c
--- nbsd-src/make.orig/dir.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/dir.c Wed Feb 2 03:35:21 2005
@@ -272,7 +272,7 @@
Dir_InitCur(cdname);
- dotLast = (Path *) emalloc(sizeof (Path));
+ dotLast = emalloc(sizeof(Path));
dotLast->refCount = 1;
dotLast->hits = 0;
dotLast->name = estrdup(".DOTLAST");
@@ -1518,7 +1518,7 @@
}
if ((d = opendir (name)) != (DIR *) NULL) {
- p = (Path *) emalloc(sizeof (Path));
+ p = emalloc(sizeof(Path));
p->name = estrdup(name);
p->hits = 0;
p->refCount = 1;
diff -ru nbsd-src/make.orig/hash.c nbsd-src/make/hash.c
--- nbsd-src/make.orig/hash.c Wed Feb 2 02:52:24 2005
+++ nbsd-src/make/hash.c Wed Feb 2 03:35:21 2005
@@ -283,7 +283,7 @@
*/
if (t->numEntries >= rebuildLimit * t->size)
RebuildTable(t);
- e = (Hash_Entry *) emalloc(sizeof(*e) + keylen);
+ e = emalloc(sizeof(*e) + keylen);
hp = &t->bucketPtr[h & t->mask];
e->next = *hp;
*hp = e;
diff -ru nbsd-src/make.orig/job.c nbsd-src/make/job.c
--- nbsd-src/make.orig/job.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/job.c Wed Feb 2 03:35:21 2005
@@ -733,7 +733,7 @@
if (!commandShell->hasErrCtl) {
/* Worst that could happen is every char needs escaping. */
- escCmd = (char *) emalloc((strlen(cmd) * 2) + 1);
+ escCmd = emalloc((strlen(cmd) * 2) + 1);
for (i = 0, j= 0; cmd[i] != '\0'; i++, j++) {
if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' ||
cmd[i] == '"')
@@ -1920,7 +1920,7 @@
previous->flags &= ~(JOB_FIRST|JOB_IGNERR|JOB_SILENT|JOB_REMOTE);
job = previous;
} else {
- job = (Job *) emalloc(sizeof(Job));
+ job = emalloc(sizeof(Job));
if (job == NULL) {
Punt("JobStart out of memory");
}
@@ -3009,7 +3009,7 @@
}
commandShell = sh;
} else {
- commandShell = (Shell *) emalloc(sizeof(Shell));
+ commandShell = emalloc(sizeof(Shell));
*commandShell = newShell;
}
}
diff -ru nbsd-src/make.orig/parse.c nbsd-src/make/parse.c
--- nbsd-src/make.orig/parse.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/parse.c Wed Feb 2 03:35:21 2005
@@ -1990,7 +1990,7 @@
* 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 = emalloc(sizeof(IFile));
memcpy(oldFile, &curFile, sizeof (IFile));
@@ -2074,13 +2074,13 @@
if (DEBUG(FOR))
(void) fprintf(stderr, "%s\n---- at line %d\n", str, lineno);
- oldFile = (IFile *) emalloc(sizeof (IFile));
+ oldFile = emalloc(sizeof(IFile));
memcpy(oldFile, &curFile, sizeof (IFile));
(void) Lst_AtFront(includes, (ClientData)oldFile);
curFile.F = NULL;
- curFile.P = (PTR *) emalloc(sizeof (PTR));
+ curFile.P = emalloc(sizeof(PTR));
curFile.P->str = curFile.P->ptr = str;
curFile.lineno = lineno;
curFile.fname = estrdup(curFile.fname);
@@ -2216,7 +2216,7 @@
* 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 = emalloc(sizeof(IFile));
memcpy(oldFile, &curFile, sizeof (IFile));
(void) Lst_AtFront(includes, (ClientData)oldFile);
diff -ru nbsd-src/make.orig/str.c nbsd-src/make/str.c
--- nbsd-src/make.orig/str.c Wed Feb 2 02:52:25 2005
+++ nbsd-src/make/str.c Wed Feb 2 03:35:21 2005
@@ -135,7 +135,7 @@
const char *p;
int len;
int argmax = 50, curlen = 0;
- char **argv = (char **)emalloc((argmax + 1) * sizeof(char *));
+ char **argv = emalloc((argmax + 1) * sizeof(char *));
/* skip leading space chars. */
for (; *str == ' ' || *str == '\t'; ++str)
diff -ru nbsd-src/make.orig/suff.c nbsd-src/make/suff.c
--- nbsd-src/make.orig/suff.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/suff.c Wed Feb 2 03:35:21 2005
@@ -961,7 +961,7 @@
ln = Lst_Find(sufflist, (ClientData)str, SuffSuffHasNameP);
if (ln == NILLNODE) {
- s = (Suff *) emalloc(sizeof (Suff));
+ s = emalloc(sizeof(Suff));
s->name = estrdup(str);
s->nameLen = strlen (s->name);
@@ -1184,7 +1184,7 @@
* structure for a file with no suffix attached. Two birds, and all
* that...
*/
- s2 = (Src *) emalloc(sizeof (Src));
+ s2 = emalloc(sizeof(Src));
s2->file = estrdup(targ->pref);
s2->pref = targ->pref;
s2->parent = targ;
@@ -1202,7 +1202,7 @@
printf("\n");
#endif
}
- s2 = (Src *) emalloc(sizeof (Src));
+ s2 = emalloc(sizeof(Src));
s2->file = str_concat(targ->pref, s->name, 0);
s2->pref = targ->pref;
s2->parent = targ;
@@ -1458,7 +1458,7 @@
* source node's name so Suff_FindDeps can free it
* again (ick)), and return the new structure.
*/
- ret = (Src *)emalloc (sizeof (Src));
+ ret = emalloc(sizeof(Src));
ret->file = estrdup(s->name);
ret->pref = targ->pref;
ret->suff = suff;
@@ -2042,7 +2042,7 @@
/*
* Allocate a Src structure to which things can be transformed
*/
- targ = (Src *)emalloc(sizeof (Src));
+ targ = emalloc(sizeof(Src));
targ->file = estrdup(gn->name);
targ->suff = (Suff *)Lst_Datum(ln);
targ->suff->refCount++;
@@ -2087,7 +2087,7 @@
printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
}
- targ = (Src *)emalloc(sizeof (Src));
+ targ = emalloc(sizeof(Src));
targ->file = estrdup(gn->name);
targ->suff = suffNull;
targ->suff->refCount++;
@@ -2505,7 +2505,7 @@
* actually go on the suffix list or everyone will think that's its
* suffix.
*/
- emptySuff = suffNull = (Suff *) emalloc(sizeof (Suff));
+ emptySuff = suffNull = emalloc(sizeof(Suff));
suffNull->name = estrdup("");
suffNull->nameLen = 0;
diff -ru nbsd-src/make.orig/targ.c nbsd-src/make/targ.c
--- nbsd-src/make.orig/targ.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/targ.c Wed Feb 2 03:35:21 2005
@@ -225,7 +225,7 @@
{
GNode *gn;
- gn = (GNode *) emalloc(sizeof (GNode));
+ gn = emalloc(sizeof(GNode));
gn->name = estrdup(name);
gn->uname = NULL;
gn->path = NULL;
diff -ru nbsd-src/make.orig/util.c nbsd-src/make/util.c
--- nbsd-src/make.orig/util.c Wed Feb 2 02:52:25 2005
+++ nbsd-src/make/util.c Wed Feb 2 03:35:21 2005
@@ -64,7 +64,7 @@
{
char *p;
int len = strlen(name) + strlen(value) + 2; /* = \0 */
- char *ptr = (char*) emalloc(len);
+ char *ptr = emalloc(len);
(void) dum;
diff -ru nbsd-src/make.orig/var.c nbsd-src/make/var.c
--- nbsd-src/make.orig/var.c Wed Feb 2 02:53:57 2005
+++ nbsd-src/make/var.c Wed Feb 2 03:35:21 2005
@@ -373,7 +373,7 @@
if ((env = getenv (name)) != NULL) {
int len;
- v = (Var *) emalloc(sizeof(Var));
+ v = emalloc(sizeof(Var));
v->name = estrdup(name);
len = strlen(env);
@@ -428,7 +428,7 @@
int len;
Hash_Entry *h;
- v = (Var *) emalloc(sizeof (Var));
+ v = emalloc(sizeof(Var));
len = val ? strlen(val) : 0;
v->val = Buf_Init(len+1);
@@ -1414,7 +1414,7 @@
if (vpstate->oneBigWord) {
/* fake what brk_string() would do if there were only one word */
ac = 1;
- av = (char **)emalloc((ac + 1) * sizeof(char *));
+ av = emalloc((ac + 1) * sizeof(char *));
as = strdup(str);
av[0] = as;
av[1] = NULL;
@@ -1507,7 +1507,7 @@
if (vpstate->oneBigWord) {
/* fake what brk_string() would do if there were only one word */
ac = 1;
- av = (char **)emalloc((ac + 1) * sizeof(char *));
+ av = emalloc((ac + 1) * sizeof(char *));
as = strdup(str);
av[0] = as;
av[1] = NULL;
@@ -2094,7 +2094,7 @@
* 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 = emalloc(sizeof(Var));
v->name = UNCONST(str);
v->val = Buf_Init(1);
v->flags = VAR_JUNK;
--------------080506050003020508070005--