Add vimstart
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 24 May 2010 23:04:07 +0000 (16:04 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 24 May 2010 23:04:07 +0000 (16:04 -0700)
Makefile
vimstart.c [new file with mode: 0644]
xx [new file with mode: 0755]

index 27e3efd..22ef97c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,5 +6,7 @@ errno_speak:    errno_speak.o
 
 simple_time:   simple_time.o
 
+vimstart:      vimstart.o
+
 clean:
        rm -rf errno_speak simple_time *.o
diff --git a/vimstart.c b/vimstart.c
new file mode 100644 (file)
index 0000000..a72e878
--- /dev/null
@@ -0,0 +1,16 @@
+#include <unistd.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+       close(0); /* close stdin */
+
+        /* duplicate stdin from stderr */
+       if (dup(2) < 0) {
+               perror("dup failed:");
+               return 1;
+       }
+       execvp("/usr/bin/vim", argv);
+       perror("could not execute program");
+       return 1;
+}
diff --git a/xx b/xx
new file mode 100755 (executable)
index 0000000..11910cb
--- /dev/null
+++ b/xx
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+die() {
+       echo $@
+       exit 1
+}
+
+VIMSTART=`dirname $0`/vimstart
+[ -e "${VIMSTART}" ] || die "can't find vimstart program"
+
+FILES=""
+while read LINE; do
+       if [ -e "${LINE}" ]; then
+               FILES="${FILES} ${LINE}"
+       else
+               echo "no such file as '${LINE}'"
+       fi
+done
+
+${VIMSTART} ${FILES}