summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko2007-07-24 15:54:42 +0000
committerDenis Vlasenko2007-07-24 15:54:42 +0000
commit990d0f63eeb502c8762076e5c5499196e09cba55 (patch)
tree30a2091a8159b1694d65f9952e2aba2667d7dc11 /coreutils
parentbcb66ec22e82f6b1ab93f3aec917269393a5b464 (diff)
downloadbusybox-990d0f63eeb502c8762076e5c5499196e09cba55.zip
busybox-990d0f63eeb502c8762076e5c5499196e09cba55.tar.gz
Replace index_in_[sub]str_array with index_in_[sub]strings,
which scans thru "abc\0def\0123\0\0" type strings. Saves 250 bytes. text data bss dec hex filename 781266 1328 11844 794438 c1f46 busybox_old 781010 1328 11844 794182 c1e46 busybox_unstripped
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dd.c23
-rw-r--r--coreutils/env.c2
-rw-r--r--coreutils/expr.c7
-rw-r--r--coreutils/install.c2
-rw-r--r--coreutils/ls.c2
-rw-r--r--coreutils/mkdir.c2
-rw-r--r--coreutils/mv.c2
-rw-r--r--coreutils/od_bloaty.c2
-rw-r--r--coreutils/stty.c22
-rw-r--r--coreutils/tr.c11
10 files changed, 35 insertions, 40 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index dd311d8..22ad192 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -51,7 +51,7 @@ static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
}
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
- const char * const filename)
+ const char *filename)
{
ssize_t n = full_write_or_warn(fd, buf, len, filename);
if (n < 0)
@@ -78,13 +78,12 @@ int dd_main(int argc, char **argv)
TRUNC_FLAG = 1 << 2,
TWOBUFS_FLAG = 1 << 3,
};
- static const char * const keywords[] = {
- "bs=", "count=", "seek=", "skip=", "if=", "of=",
+ static const char keywords[] =
+ "bs=\0""count=\0""seek=\0""skip=\0""if=\0""of=\0"
#if ENABLE_FEATURE_DD_IBS_OBS
- "ibs=", "obs=", "conv=", "notrunc", "sync", "noerror",
+ "ibs=\0""obs=\0""conv=\0""notrunc\0""sync\0""noerror\0"
#endif
- NULL
- };
+ ;
enum {
OP_bs = 1,
OP_count,
@@ -134,7 +133,7 @@ int dd_main(int argc, char **argv)
bb_show_usage();
key_len = key - arg + 1;
key = xstrndup(arg, key_len);
- what = index_in_str_array(keywords, key) + 1;
+ what = index_in_strings(keywords, key) + 1;
if (ENABLE_FEATURE_CLEAN_UP)
free(key);
if (what == 0)
@@ -153,13 +152,13 @@ int dd_main(int argc, char **argv)
if (what == OP_conv) {
while (1) {
/* find ',', replace them with nil so we can use arg for
- * index_in_str_array without copying.
+ * index_in_strings() without copying.
* We rely on arg being non-null, else strchr would fault.
*/
key = strchr(arg, ',');
if (key)
*key = '\0';
- what = index_in_str_array(keywords, arg) + 1;
+ what = index_in_strings(keywords, arg) + 1;
if (what < OP_conv_notrunc)
bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv");
if (what == OP_conv_notrunc)
@@ -298,15 +297,15 @@ int dd_main(int argc, char **argv)
G.out_part++;
}
if (close(ifd) < 0) {
-die_infile:
+ die_infile:
bb_perror_msg_and_die("%s", infile);
}
if (close(ofd) < 0) {
-die_outfile:
+ die_outfile:
bb_perror_msg_and_die("%s", outfile);
}
-out_status:
+ out_status:
dd_output_status(0);
return EXIT_SUCCESS;
diff --git a/coreutils/env.c b/coreutils/env.c
index 8d20eac..31167d0 100644
--- a/coreutils/env.c
+++ b/coreutils/env.c
@@ -38,7 +38,7 @@ extern char **environ;
static const char env_longopts[] =
"ignore-environment\0" No_argument "i"
"unset\0" Required_argument "u"
- "\0";
+ ;
#endif
int env_main(int argc, char** argv);
diff --git a/coreutils/expr.c b/coreutils/expr.c
index ab182a8..6a4683d 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -277,14 +277,13 @@ static VALUE *eval7(void)
static VALUE *eval6(void)
{
- static const char * const keywords[] = {
- "quote", "length", "match", "index", "substr", NULL
- };
+ static const char keywords[] =
+ "quote\0""length\0""match\0""index\0""substr\0";
VALUE *r, *i1, *i2;
VALUE *l = l; /* silence gcc */
VALUE *v = v; /* silence gcc */
- int key = *G.args ? index_in_str_array(keywords, *G.args) + 1 : 0;
+ int key = *G.args ? index_in_strings(keywords, *G.args) + 1 : 0;
if (key == 0) /* not a keyword */
return eval7();
diff --git a/coreutils/install.c b/coreutils/install.c
index 8d54949..c2638f4 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -28,7 +28,7 @@ static const char install_longopts[] =
"preserve_context\0" No_argument "\xff"
"preserve-context\0" No_argument "\xff"
#endif
- "\0";
+ ;
#endif
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 8545edd..f47ec20 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -122,7 +122,7 @@ static smallint show_color;
* equivalent */
static const char ls_color_opt[] =
"color\0" Optional_argument "\xff" /* no short equivalent */
- "\0";
+ ;
#else
enum { show_color = 0 };
#endif
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index b0595b4..a6eaa96 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -31,7 +31,7 @@ static const char mkdir_longopts[] =
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
- "\0";
+ ;
#endif
int mkdir_main(int argc, char **argv);
diff --git a/coreutils/mv.c b/coreutils/mv.c
index bb96af8..0644078 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -24,7 +24,7 @@
static const char mv_longopts[] =
"interactive\0" No_argument "i"
"force\0" No_argument "f"
- "\0";
+ ;
#endif
#define OPT_FILEUTILS_FORCE 1
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 0b77f8b..8034072 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -1242,7 +1242,7 @@ int od_main(int argc, char **argv)
"strings\0" Optional_argument "S"
"width\0" Optional_argument "w"
"traditional\0" No_argument "\xff"
- "\0";
+ ;
#endif
char *str_A, *str_N, *str_j, *str_S;
char *str_w = NULL;
diff --git a/coreutils/stty.c b/coreutils/stty.c
index 0983532..b73e2ea 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -562,18 +562,16 @@ enum {
static int find_param(const char * const name)
{
- static const char * const params[] = {
- "line", /* 1 */
- "rows", /* 2 */
- "cols", /* 3 */
- "columns", /* 4 */
- "size", /* 5 */
- "ispeed"+1, /* 6 */
- "ispeed",
- "ospeed",
- NULL
- };
- int i = index_in_str_array(params, name) + 1;
+ static const char params[] =
+ "line\0" /* 1 */
+ "rows\0" /* 2 */
+ "cols\0" /* 3 */
+ "columns\0" /* 4 */
+ "size\0" /* 5 */
+ "speed\0" /* 6 */
+ "ispeed\0"
+ "ospeed\0";
+ int i = index_in_strings(params, name) + 1;
if (i == 0)
return 0;
if (i != 5 && i != 6)
diff --git a/coreutils/tr.c b/coreutils/tr.c
index c0d0dfa..5945718 100644
--- a/coreutils/tr.c
+++ b/coreutils/tr.c
@@ -51,11 +51,10 @@ static unsigned int expand(const char *arg, char *buffer)
char *buffer_start = buffer;
unsigned i; /* XXX: FIXME: use unsigned char? */
unsigned char ac;
-#define CLO ":]"
- static const char * const classes[] = {
- "alpha"CLO, "alnum"CLO, "digit"CLO, "lower"CLO, "upper"CLO, "space"CLO,
- "blank"CLO, "punct"CLO, "cntrl"CLO, NULL
- };
+#define CLO ":]\0"
+ static const char classes[] =
+ "alpha"CLO "alnum"CLO "digit"CLO "lower"CLO "upper"CLO "space"CLO
+ "blank"CLO "punct"CLO "cntrl"CLO;
#define CLASS_invalid 0 /* we increment the retval */
#define CLASS_alpha 1
#define CLASS_alnum 2
@@ -90,7 +89,7 @@ static unsigned int expand(const char *arg, char *buffer)
smalluint j;
{ /* not really pretty.. */
char *tmp = xstrndup(arg, 7); // warning: xdigit needs 8, not 7
- j = index_in_str_array(classes, tmp) + 1;
+ j = index_in_strings(classes, tmp) + 1;
free(tmp);
}
if (j == CLASS_alnum || j == CLASS_digit) {