aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-02-26 00:36:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-02-26 00:36:53 +0100
commit1961aea305e258ba7ab3910d084451220f55ed44 (patch)
treebd889c8e596051c187b93af9c50508c6009f2683
parent3305c008ed6084f58b59dde5198ae92e3a458e46 (diff)
downloadbusybox-w32-1961aea305e258ba7ab3910d084451220f55ed44.tar.gz
busybox-w32-1961aea305e258ba7ab3910d084451220f55ed44.tar.bz2
busybox-w32-1961aea305e258ba7ab3910d084451220f55ed44.zip
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 e52006020..79a37a759 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;
386const char *bb_basename(const char *name) FAST_FUNC; 386const char *bb_basename(const char *name) FAST_FUNC;
387/* NB: can violate const-ness (similarly to strchr) */ 387/* NB: can violate const-ness (similarly to strchr) */
388char *last_char_is(const char *s, int c) FAST_FUNC; 388char *last_char_is(const char *s, int c) FAST_FUNC;
389const char* endofname(const char *name) FAST_FUNC;
389 390
390void ndelay_on(int fd) FAST_FUNC; 391void ndelay_on(int fd) FAST_FUNC;
391void ndelay_off(int fd) FAST_FUNC; 392void ndelay_off(int fd) FAST_FUNC;
diff --git a/libbb/endofname.c b/libbb/endofname.c
new file mode 100644
index 000000000..305f0932b
--- /dev/null
+++ b/libbb/endofname.c
@@ -0,0 +1,26 @@
1/*
2 * Utility routines.
3 *
4 * Copyright (C) 2013 Denys Vlasenko
5 *
6 * Licensed under GPLv2, see file LICENSE in this source tree.
7 */
8
9//kbuild:lib-y += endofname.o
10
11#include "libbb.h"
12
13#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
14#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
15
16const char* FAST_FUNC
17endofname(const char *name)
18{
19 if (!is_name(*name))
20 return name;
21 while (*++name) {
22 if (!is_in_name(*name))
23 break;
24 }
25 return name;
26}
diff --git a/shell/ash.c b/shell/ash.c
index 31fbc550a..0b5111a39 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -385,6 +385,9 @@ static void trace_vprintf(const char *fmt, va_list va);
385/* ============ Utility functions */ 385/* ============ Utility functions */
386#define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0) 386#define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0)
387 387
388#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
389#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
390
388static int isdigit_str9(const char *str) 391static int isdigit_str9(const char *str)
389{ 392{
390 int maxlen = 9 + 1; /* max 9 digits: 999999999 */ 393 int maxlen = 9 + 1; /* max 9 digits: 999999999 */
@@ -2008,27 +2011,6 @@ getoptsreset(const char *value)
2008} 2011}
2009#endif 2012#endif
2010 2013
2011/* math.h has these, otherwise define our private copies */
2012#if !ENABLE_SH_MATH_SUPPORT
2013#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
2014#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
2015/*
2016 * Return the pointer to the first char which is not part of a legal variable name
2017 * (a letter or underscore followed by letters, underscores, and digits).
2018 */
2019static const char*
2020endofname(const char *name)
2021{
2022 if (!is_name(*name))
2023 return name;
2024 while (*++name) {
2025 if (!is_in_name(*name))
2026 break;
2027 }
2028 return name;
2029}
2030#endif
2031
2032/* 2014/*
2033 * Compares two strings up to the first = or '\0'. The first 2015 * Compares two strings up to the first = or '\0'. The first
2034 * string must be terminated by '='; the second may be terminated by 2016 * string must be terminated by '='; the second may be terminated by
diff --git a/shell/math.c b/shell/math.c
index 15c003965..3da151137 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -494,18 +494,6 @@ static const char op_tokens[] ALIGN1 = {
494}; 494};
495#define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7]) 495#define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7])
496 496
497const char* FAST_FUNC
498endofname(const char *name)
499{
500 if (!is_name(*name))
501 return name;
502 while (*++name) {
503 if (!is_in_name(*name))
504 break;
505 }
506 return name;
507}
508
509static arith_t FAST_FUNC 497static arith_t FAST_FUNC
510evaluate_string(arith_state_t *math_state, const char *expr) 498evaluate_string(arith_state_t *math_state, const char *expr)
511{ 499{
diff --git a/shell/math.h b/shell/math.h
index 2d305eb12..864bee691 100644
--- a/shell/math.h
+++ b/shell/math.h
@@ -73,11 +73,6 @@ typedef long arith_t;
73#define strto_arith_t strtoul 73#define strto_arith_t strtoul
74#endif 74#endif
75 75
76/* ash's and hush's endofname is the same, so... */
77# define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
78# define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
79const char* FAST_FUNC endofname(const char *name);
80
81typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name); 76typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name);
82typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val); 77typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val);
83//typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name); 78//typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name);