aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-11-26 14:14:29 -0600
committerRob Landley <rob@landley.net>2012-11-26 14:14:29 -0600
commit6cf0a115451d6d5ead94860f0731040dc2293db0 (patch)
treef04a6b76ca8572fccf01f1dc0b8b71710bde439c
parent471ce1b29933702bdd63bf27e4470898cb37b451 (diff)
downloadtoybox-6cf0a115451d6d5ead94860f0731040dc2293db0.tar.gz
Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
-rw-r--r--main.c5
-rwxr-xr-xscripts/make.sh32
-rw-r--r--toys.h4
-rw-r--r--toys/posix/wc.c9
4 files changed, 32 insertions, 18 deletions
diff --git a/main.c b/main.c
index 2b04d135..829b787a 100644
--- a/main.c
+++ b/main.c
@@ -101,9 +101,6 @@ void toy_exec(char *argv[])
which = toy_find(argv[0]);
if (!which) return;
toy_init(which, argv);
-#ifdef CFG_TOYBOX_I18N
- setlocale(LC_ALL, "");
-#endif
toys.which->toy_main();
exit(toys.exitval);
}
@@ -145,6 +142,8 @@ void toybox_main(void)
int main(int argc, char *argv[])
{
+ if (CFG_TOYBOX_I18N) setlocale(LC_ALL, "");
+
// Artificial scope to eat less stack for things we call
{
char *name;
diff --git a/scripts/make.sh b/scripts/make.sh
index f9fa0a40..921d1994 100755
--- a/scripts/make.sh
+++ b/scripts/make.sh
@@ -54,11 +54,27 @@ sed -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \
| sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \
| sed 's/[^ ]* //' >> generated/newtoys.h
+# Extract list of command letters from processed header file
+
+function getflags()
+{
+ sed -n -e "s/.*TOY($1"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \
+ -e 't keep;d;:keep' -e 's/^[<>=][0-9]//' -e 's/[?&^]//' \
+ -e 't keep' -e 's/[><=][0-9][0-9]*//g' -e 's/+.//g' \
+ -e 's/([^)]*)//g' -e 's/\[[^]]*\]//g' -e 's/[-?^:&#|@*]//g' -e 'p'
+}
+
# Extract global structure definitions and flag definitions from toys/*/*.c
function getglobals()
{
+ # Run newtoys.h through the compiler's preprocessor to resolve USE macros
+ # against current config.
NEWTOYS="$(cat generated/config.h generated/newtoys.h | gcc -E - | sed 's/" *"//g')"
+
+ # Grab allyesconfig for comparison
+ ALLTOYS="$((sed '/USE_.*([^)]*)$/s/$/ __VA_ARGS__/' generated/config.h && cat generated/newtoys.h) | gcc -E - | sed 's/" *"//g')"
+
for i in toys/*/*.c
do
NAME="$(echo $i | sed 's@.*/\(.*\)\.c@\1@')"
@@ -68,13 +84,9 @@ function getglobals()
-e 's/^GLOBALS(/struct '"$NAME"'_data {/' \
-e 's/^)/};/' -e 'p' $i
- # And get flag definitions
- FLAGS="$(echo "$NEWTOYS" | sed -n \
- -e "s/.*TOY($NAME"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \
- -e 't keep;d;:keep' -e 's/^[<>=][0-9]//' -e 's/[?&^]//' \
- -e 't keep' -e 's/[><=][0-9][0-9]*//g' -e 's/+.//g' \
- -e 's/([^)]*)//g' -e 's/\[[^]]*\]//g' -e 's/[-?^:&#|@*]//g' \
- -e 'p')"
+ FLAGS="$(echo "$NEWTOYS" | getflags "$NAME")"
+ ZFLAGS="$(echo "$ALLTOYS" | getflags "$NAME" | sed 's/[-'"$FLAGS"']//g')"
+
echo "#ifdef FOR_${NAME}"
X=0
while [ $X -lt ${#FLAGS} ]
@@ -83,6 +95,12 @@ function getglobals()
X=$(($X+1))
echo "(1<<$((${#FLAGS}-$X)))"
done
+ X=0
+ while [ $X -lt ${#ZFLAGS} ]
+ do
+ echo "#define FLAG_${ZFLAGS:$X:1} 0"
+ X=$(($X+1))
+ done
echo "#define TT this.${NAME}"
echo "#endif"
done
diff --git a/toys.h b/toys.h
index 69876f23..40946d79 100644
--- a/toys.h
+++ b/toys.h
@@ -47,11 +47,11 @@
#include <utime.h>
#include <utmpx.h>
-#ifdef CFG_TOYBOX_I18N
+// Internationalization support
+
#include <locale.h>
#include <wchar.h>
#include <wctype.h>
-#endif
#include "lib/lib.h"
#include "toys/e2fs.h"
diff --git a/toys/posix/wc.c b/toys/posix/wc.c
index 63128d67..d2eb306d 100644
--- a/toys/posix/wc.c
+++ b/toys/posix/wc.c
@@ -4,7 +4,7 @@
*
* See http://opengroup.org/onlinepubs/9699919799/utilities/wc.html
-USE_WC(NEWTOY(wc, "mcwl", TOYFLAG_USR|TOYFLAG_BIN))
+USE_WC(NEWTOY(wc, USE_TOYBOX_I18N("m")"cwl", TOYFLAG_USR|TOYFLAG_BIN))
config WC
bool "wc"
@@ -58,9 +58,8 @@ static void do_wc(int fd, char *name)
}
if (len<1) break;
for (i=0; i<len; i+=clen) {
-#ifdef CFG_TOYBOX_I18N
wchar_t wchar;
- if(toys.optflags&8) {
+ if (CFG_TOYBOX_I18N && (toys.optflags&FLAG_m)) {
clen = mbrtowc(&wchar, toybuf+i, len-i, 0);
if(clen==(size_t)(-1)) {
if(i!=len-1) {
@@ -71,9 +70,7 @@ static void do_wc(int fd, char *name)
if(clen==(size_t)(-2)) break;
if(clen==0) clen=1;
space = iswspace(wchar);
- } else
-#endif
- space = isspace(toybuf[i]);
+ } else space = isspace(toybuf[i]);
if (toybuf[i]==10) lengths[0]++;
if (space) word=0;