summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2013-02-26 00:36:53 +0100
committerDenys Vlasenko2013-02-26 00:36:53 +0100
commit1961aea305e258ba7ab3910d084451220f55ed44 (patch)
treebd889c8e596051c187b93af9c50508c6009f2683
parent3305c008ed6084f58b59dde5198ae92e3a458e46 (diff)
downloadbusybox-1961aea305e258ba7ab3910d084451220f55ed44.zip
busybox-1961aea305e258ba7ab3910d084451220f55ed44.tar.gz
move endofname() to libbb
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/endofname.c26
-rw-r--r--shell/ash.c24
-rw-r--r--shell/math.c12
-rw-r--r--shell/math.h5
5 files changed, 30 insertions, 38 deletions
diff --git a/include/libbb.h b/include/libbb.h
index e520060..79a37a7 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -386,6 +386,7 @@ char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
const char *bb_basename(const char *name) FAST_FUNC;
/* NB: can violate const-ness (similarly to strchr) */
char *last_char_is(const char *s, int c) FAST_FUNC;
+const char* endofname(const char *name) FAST_FUNC;
void ndelay_on(int fd) FAST_FUNC;
void ndelay_off(int fd) FAST_FUNC;
diff --git a/libbb/endofname.c b/libbb/endofname.c
new file mode 100644
index 0000000..305f093
--- /dev/null
+++ b/libbb/endofname.c
@@ -0,0 +1,26 @@
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2013 Denys Vlasenko
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+
+//kbuild:lib-y += endofname.o
+
+#include "libbb.h"
+
+#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
+#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
+
+const char* FAST_FUNC
+endofname(const char *name)
+{
+ if (!is_name(*name))
+ return name;
+ while (*++name) {
+ if (!is_in_name(*name))
+ break;
+ }
+ return name;
+}
diff --git a/shell/ash.c b/shell/ash.c
index 31fbc55..0b5111a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -385,6 +385,9 @@ static void trace_vprintf(const char *fmt, va_list va);
/* ============ Utility functions */
#define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0)
+#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
+#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
+
static int isdigit_str9(const char *str)
{
int maxlen = 9 + 1; /* max 9 digits: 999999999 */
@@ -2008,27 +2011,6 @@ getoptsreset(const char *value)
}
#endif
-/* math.h has these, otherwise define our private copies */
-#if !ENABLE_SH_MATH_SUPPORT
-#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
-#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
-/*
- * Return the pointer to the first char which is not part of a legal variable name
- * (a letter or underscore followed by letters, underscores, and digits).
- */
-static const char*
-endofname(const char *name)
-{
- if (!is_name(*name))
- return name;
- while (*++name) {
- if (!is_in_name(*name))
- break;
- }
- return name;
-}
-#endif
-
/*
* Compares two strings up to the first = or '\0'. The first
* string must be terminated by '='; the second may be terminated by
diff --git a/shell/math.c b/shell/math.c
index 15c0039..3da1511 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -494,18 +494,6 @@ static const char op_tokens[] ALIGN1 = {
};
#define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7])
-const char* FAST_FUNC
-endofname(const char *name)
-{
- if (!is_name(*name))
- return name;
- while (*++name) {
- if (!is_in_name(*name))
- break;
- }
- return name;
-}
-
static arith_t FAST_FUNC
evaluate_string(arith_state_t *math_state, const char *expr)
{
diff --git a/shell/math.h b/shell/math.h
index 2d305eb..864bee6 100644
--- a/shell/math.h
+++ b/shell/math.h
@@ -73,11 +73,6 @@ typedef long arith_t;
#define strto_arith_t strtoul
#endif
-/* ash's and hush's endofname is the same, so... */
-# define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
-# define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
-const char* FAST_FUNC endofname(const char *name);
-
typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name);
typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val);
//typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name);