From b81b2b920d300f1cb292fecf96e9d590497607f8 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Fri, 4 Aug 2006 11:22:16 +0000 Subject: Solved IFS issues git-svn-id: http://projects.archlinux.org/svn/initramfs/mkinitcpio@139 880c04e9-e011-0410-abf7-b926e227c9cd --- init | 7 ++----- install.sh | 5 +++++ subs/Makefile | 11 +++++++++++ subs/README | 11 +++++++++++ subs/subs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 subs/Makefile create mode 100644 subs/README create mode 100644 subs/subs.c diff --git a/init b/init index fb504d7..aa95ae4 100644 --- a/init +++ b/init @@ -25,20 +25,17 @@ for cmd in $CMDLINE; do esac done -OLDIFS=$IFS -IFS=, if [ "x${disablehooks}" != "x" ]; then - for d in ${disablehooks}; do + for d in $(subs -n ',' ${disablehooks}); do export "hook_${d}=disabled" done fi if [ "x${disablemodules}" != "x" ]; then - for d in ${disablemodules}; do + for d in $(subs -n ',' ${disablemodules}); do export "mod_${d}=disabled" done fi -IFS=$OLDIFS . /config diff --git a/install.sh b/install.sh index a704f29..0820065 100755 --- a/install.sh +++ b/install.sh @@ -16,3 +16,8 @@ install -D -m755 init ${1}/lib/initcpio/init install -D -m644 functions ${1}/lib/initcpio/functions cp -r hooks/ ${1}/lib/initcpio/ cp -r install/ ${1}/lib/initcpio/ + +# install subs tool to solve IFS issues +cd subs +make +install -D -m755 subs ${1}/usr/lib/klibc/bin/subs diff --git a/subs/Makefile b/subs/Makefile new file mode 100644 index 0000000..e3ae446 --- /dev/null +++ b/subs/Makefile @@ -0,0 +1,11 @@ +CC = klcc +CFLAGS = -Wall +TARGET = subs + +all: $(TARGET) + +$(TARGET): $(TARGET).c + $(CC) $(CFLAGS) $(TARGET).c -o $(TARGET) + +clean: + rm -f $(TARGET) diff --git a/subs/README b/subs/README new file mode 100644 index 0000000..ca29eb2 --- /dev/null +++ b/subs/README @@ -0,0 +1,11 @@ +The subs tool has been created to solve the IFS ignorance of dash. +Instead of doing + +OLDIFS=$IFS +IFS=$char +func $arglist +IFS=$OLDIFS + +now do + +func $(subs -n $char $arglist) diff --git a/subs/subs.c b/subs/subs.c new file mode 100644 index 0000000..03f05c5 --- /dev/null +++ b/subs/subs.c @@ -0,0 +1,42 @@ +#include +#include +#include + +void usage(char *name) +{ + fprintf(stderr,"Usage:\n\t%s [-n ] [-w ] \n",name); +} + +int main(int argc, char *argv[]) +{ + char *h,n=':',w=' '; + int c; + + while((c=getopt(argc, argv, "n:w:"))!=-1) + switch(c) + { + case 'n': + n=optarg[0]; + break; + case 'w': + w=optarg[0]; + break; + default: + usage(argv[0]); + return 1; + } + + if(optind>=argc) + { + usage(argv[0]); + return 1; + } + + h=argv[optind]; + while( (h=index(h, n)) !=NULL ) + *h++=w; + + printf("%s",argv[optind]); + + return 0; +} -- cgit v1.2.3-24-g4f1b