summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Novoa III2001-08-12 17:32:56 +0000
committerManuel Novoa III2001-08-12 17:32:56 +0000
commitc639a35f50014bf9d43b6893b7ed92564e69a9a9 (patch)
treec2e76689aa1f3bfc4b81c1c9802ad8ef47d4265c
parentdd9173c07fd7222bacd132611aa6b4c9d1090215 (diff)
downloadbusybox-c639a35f50014bf9d43b6893b7ed92564e69a9a9.zip
busybox-c639a35f50014bf9d43b6893b7ed92564e69a9a9.tar.gz
I stupidly forgot one level of pointer indirection in the cmdtxt(), calcsize(),
and copynode() table implementations. Commit the fix but keep them disabled until others check them out. Uncomment "//#define CMDTXT_TABLE", "//#define CALCSIZE_TABLE", and "//#define COPYNODE_TABLE" to try them out. Saves over 600 bytes on i386.
-rw-r--r--ash.c42
-rw-r--r--shell/ash.c42
2 files changed, 46 insertions, 38 deletions
diff --git a/ash.c b/ash.c
index 417ef5d..53fb56c 100644
--- a/ash.c
+++ b/ash.c
@@ -685,7 +685,7 @@ static void out2fmt (const char *, ...)
__attribute__((__format__(__printf__,1,2)));
static int xwrite (int, const char *, int);
-#define outstr(p,file) fputs(p, file)
+static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
static void out1str(const char *p) { outstr(p, stdout); }
static void out2str(const char *p) { outstr(p, stderr); }
@@ -7447,11 +7447,14 @@ cmdtxt(const union node *n)
do {
if (*p & CMDTXT_STRING) { /* output fixed string */
cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
- } else if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
- cmdputs(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK)));
- } else { /* output field */
- cmdtxt((const union node *)
- (((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK))));
+ } else {
+ const char *pf = ((const char *) n)
+ + ((int)(*p & CMDTXT_OFFSETMASK));
+ if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
+ cmdputs(*((const char **) pf));
+ } else { /* output field */
+ cmdtxt(*((const union node **) pf));
+ }
}
} while (!(*p++ & CMDTXT_NOMORE));
} else if (n->type == NCMD) {
@@ -7630,7 +7633,7 @@ redir:
break;
}
}
-#endif
+#endif /* CMDTXT_TABLE */
static char *
commandtext(const union node *n)
@@ -8832,8 +8835,9 @@ copynode(const union node *n)
union node *new;
const unsigned char *p;
- if (n == NULL)
- return NULL;
+ if (n == NULL) {
+ return NULL;
+ }
new = funcblock;
new->type = n->type;
funcblock = (char *) funcblock + (int) nodesize[n->type];
@@ -8843,12 +8847,12 @@ copynode(const union node *n)
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
if (!(*p & NODE_MBRMASK)) { /* standard node */
- (union node *) nn = copynode((const union node *) no);
+ *((union node **)nn) = copynode(*((const union node **) no));
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
- nn = nodesavestr(no);
+ *((const char **)nn) = nodesavestr(*((const char **)no));
} else if (*p & NODE_NODELIST) { /* nodelist */
- (struct nodelist *) nn
- = copynodelist((const struct nodelist *) no);
+ *((struct nodelist **)nn)
+ = copynodelist(*((const struct nodelist **) no));
} else { /* integer */
*((int *) nn) = *((int *) no);
}
@@ -8862,7 +8866,7 @@ copynode(const union node *n)
union node *new;
if (n == NULL)
- return NULL;
+ return NULL;
new = funcblock;
funcblock = (char *) funcblock + nodesize[n->type];
switch (n->type) {
@@ -8961,12 +8965,12 @@ calcsize(const union node *n)
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
if (!(*p & NODE_MBRMASK)) { /* standard node */
- calcsize((const union node *) no);
+ calcsize(*((const union node **) no));
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
- funcstringsize += strlen(no) + 1;
+ funcstringsize += strlen(*((const char **)no)) + 1;
} else if (*p & NODE_NODELIST) { /* nodelist */
- sizenodelist((const struct nodelist *) no);
- }
+ sizenodelist(*((const struct nodelist **) no));
+ } /* else integer -- ignore */
} while (!(*p++ & NODE_NOMORE));
}
#else /* CALCSIZE_TABLE */
@@ -12669,7 +12673,7 @@ findvar(struct var **vpp, const char *name)
/*
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
* This file contains code for the times builtin.
- * $Id: ash.c,v 1.21 2001/08/10 21:11:56 andersen Exp $
+ * $Id: ash.c,v 1.22 2001/08/12 17:32:56 mjn3 Exp $
*/
static int timescmd (int argc, char **argv)
{
diff --git a/shell/ash.c b/shell/ash.c
index 417ef5d..53fb56c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -685,7 +685,7 @@ static void out2fmt (const char *, ...)
__attribute__((__format__(__printf__,1,2)));
static int xwrite (int, const char *, int);
-#define outstr(p,file) fputs(p, file)
+static inline void outstr (const char *p, FILE *file) { fputs(p, file); }
static void out1str(const char *p) { outstr(p, stdout); }
static void out2str(const char *p) { outstr(p, stderr); }
@@ -7447,11 +7447,14 @@ cmdtxt(const union node *n)
do {
if (*p & CMDTXT_STRING) { /* output fixed string */
cmdputs(cmdtxt_strings[((int)(*p & CMDTXT_OFFSETMASK) >> 1)]);
- } else if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
- cmdputs(((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK)));
- } else { /* output field */
- cmdtxt((const union node *)
- (((const char *) n) + ((int)(*p & CMDTXT_OFFSETMASK))));
+ } else {
+ const char *pf = ((const char *) n)
+ + ((int)(*p & CMDTXT_OFFSETMASK));
+ if (*p & CMDTXT_CHARPTR) { /* output dynamic string */
+ cmdputs(*((const char **) pf));
+ } else { /* output field */
+ cmdtxt(*((const union node **) pf));
+ }
}
} while (!(*p++ & CMDTXT_NOMORE));
} else if (n->type == NCMD) {
@@ -7630,7 +7633,7 @@ redir:
break;
}
}
-#endif
+#endif /* CMDTXT_TABLE */
static char *
commandtext(const union node *n)
@@ -8832,8 +8835,9 @@ copynode(const union node *n)
union node *new;
const unsigned char *p;
- if (n == NULL)
- return NULL;
+ if (n == NULL) {
+ return NULL;
+ }
new = funcblock;
new->type = n->type;
funcblock = (char *) funcblock + (int) nodesize[n->type];
@@ -8843,12 +8847,12 @@ copynode(const union node *n)
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
if (!(*p & NODE_MBRMASK)) { /* standard node */
- (union node *) nn = copynode((const union node *) no);
+ *((union node **)nn) = copynode(*((const union node **) no));
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
- nn = nodesavestr(no);
+ *((const char **)nn) = nodesavestr(*((const char **)no));
} else if (*p & NODE_NODELIST) { /* nodelist */
- (struct nodelist *) nn
- = copynodelist((const struct nodelist *) no);
+ *((struct nodelist **)nn)
+ = copynodelist(*((const struct nodelist **) no));
} else { /* integer */
*((int *) nn) = *((int *) no);
}
@@ -8862,7 +8866,7 @@ copynode(const union node *n)
union node *new;
if (n == NULL)
- return NULL;
+ return NULL;
new = funcblock;
funcblock = (char *) funcblock + nodesize[n->type];
switch (n->type) {
@@ -8961,12 +8965,12 @@ calcsize(const union node *n)
const char *no = ((const char *) n) + ((int)(*p & NODE_OFFSETMASK));
if (!(*p & NODE_MBRMASK)) { /* standard node */
- calcsize((const union node *) no);
+ calcsize(*((const union node **) no));
} else if ((*p & NODE_MBRMASK) == NODE_CHARPTR) { /* string */
- funcstringsize += strlen(no) + 1;
+ funcstringsize += strlen(*((const char **)no)) + 1;
} else if (*p & NODE_NODELIST) { /* nodelist */
- sizenodelist((const struct nodelist *) no);
- }
+ sizenodelist(*((const struct nodelist **) no));
+ } /* else integer -- ignore */
} while (!(*p++ & NODE_NOMORE));
}
#else /* CALCSIZE_TABLE */
@@ -12669,7 +12673,7 @@ findvar(struct var **vpp, const char *name)
/*
* Copyright (c) 1999 Herbert Xu <herbert@debian.org>
* This file contains code for the times builtin.
- * $Id: ash.c,v 1.21 2001/08/10 21:11:56 andersen Exp $
+ * $Id: ash.c,v 1.22 2001/08/12 17:32:56 mjn3 Exp $
*/
static int timescmd (int argc, char **argv)
{