Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!ucbcad!ucbvax!ucsfcgl!pixar!brighton From: brighton@pixar ("Amazing what a pair of fives can do . . . ") Newsgroups: net.sources Subject: pipe input to vi (svi.c) Message-ID: <3115@pixar> Date: Mon, 15-Sep-86 14:19:24 EDT Article-I.D.: pixar.3115 Posted: Mon Sep 15 14:19:24 1986 Date-Received: Tue, 16-Sep-86 18:50:43 EDT References: <3646@amdahl.UUCP> Reply-To: brighton@pixar.UUCP ("Amazing what a pair of fives can do . . . ") Followup-To: net.sources.d Organization: Pixar -- Marin County, California Lines: 67 Keywords: vi pipe /* I wrote this late one night, to facilitate saving files from rn ( s | svi ) Bevare: Written under 4.2BSD, and has not been tested elsewhere. Improvements welcome. Enjoy! Bill Carson @ Pixar 415 499 3600 uucp: ...!{ucbvax,sun}!pixar!brighton arpa: brighton%pixar.uucp@ucbvax.berkeley.edu */ /*% cc -o svi svi.c */ #include #include char editor[99]; char file[1024]; char buf[10240]; char *getenv(); main() { int fd, tty_in, tty_out; sprintf (file, "/tmp/svi.%d", getpid()); fd = open (file, O_CREAT|O_RDWR, 0644); if (fd < 0) { perror (file); exit (1); } while (write(fd,buf,read(0,buf,1024))) ; close (fd); close (0); close(1); tty_in = open ("/dev/tty", O_RDONLY); if (tty_in < 0) { perror ("tty_in"); exit (1); } tty_out = open ("/dev/tty", O_WRONLY); if (tty_out < 0) { perror ("tty_out"); exit (1); } strcpy (editor, getenv ("EDITOR")); if (editor[0] == 0) { strcpy (editor, getenv ("VISUAL")); if (editor[0] == 0) { /* fprintf (stderr, "svi: defaulting to vi\n"); */ strcpy (editor, "/usr/ucb/vi"); } } execl (editor, editor, file, 0); /* should never return */ fprintf (stderr, "execl() returned!\007\n"); }