summaryrefslogtreecommitdiffstats
path: root/subs
diff options
context:
space:
mode:
authorThomas Bächler <thomas@archlinux.org>2006-08-04 13:22:16 +0200
committerThomas Bächler <thomas@archlinux.org>2006-08-04 13:22:16 +0200
commitb81b2b920d300f1cb292fecf96e9d590497607f8 (patch)
treedabd9f0256e0775bbd7344d3997f917f97bc5e3c /subs
parente9aa72aef50d72b8bb358cd5ef126d3ce9c64635 (diff)
downloadmkinitcpio-b81b2b920d300f1cb292fecf96e9d590497607f8.tar.gz
mkinitcpio-b81b2b920d300f1cb292fecf96e9d590497607f8.tar.xz
Solved IFS issues
git-svn-id: http://projects.archlinux.org/svn/initramfs/mkinitcpio@139 880c04e9-e011-0410-abf7-b926e227c9cd
Diffstat (limited to 'subs')
-rw-r--r--subs/Makefile11
-rw-r--r--subs/README11
-rw-r--r--subs/subs.c42
3 files changed, 64 insertions, 0 deletions
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 <strings.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void usage(char *name)
+{
+ fprintf(stderr,"Usage:\n\t%s [-n <character>] [-w <character>] <string>\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;
+}