Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B UNSW 1.0 3/14/84; site uqpsych.OZ Path: utzoo!linus!decvax!mulga!munnari!basser!uqcspe!uqpsych!derek From: derek@uqpsych.OZ (Derek Austin) Newsgroups: net.sources Subject: Line Editors and Arrow Keys Don't Mix Message-ID: <104@uqpsych.OZ> Date: Mon, 27-Aug-84 23:07:49 EDT Article-I.D.: uqpsych.104 Posted: Mon Aug 27 23:07:49 1984 Date-Received: Thu, 13-Sep-84 03:36:15 EDT Organization: Dept of Psychology, University of Queensland, Australia Lines: 73 istakes are impossible to spot). I offer the humble program below to anyone who might have similar problems. I'd also be interested in a method for solving this problem that doesn't involve an invocation of cc. Even more interesting would be a noncc method that could cope with up-arrows and down-arrows! Anyone? ACSnet: derek:uqpsych UUCP: decvax!mulga!derek:uqpsych ARPA: decvax!mulga!derek.uqpsych@Berkeley ------------------------------------------------------------------- /*** ** m a s s a g e ** ** Distill a file suffering from left and right arrow ** key affliction. ** Usage: massage left-arrow right-arrow char *progname; main( argc, argv ) int argc; char *argv[]; { progname = *argv; if (argc != 3 ) { fprintf( stderr, "Usage: %s left-string right-string\n", progname); exit(1); } process( argv[1], argv[2] ); } process( left, right ) char *left, *right; { char buf[BUFSIZ]; while( gets(buf) != (char *)NULL ) { char betterbuf[BUFSIZ], *newptr, *oldptr; oldptr=buf; newptr=betterbuf; while( *oldptr ) { if ( (oldptr+strlen(left) < buf+BUFSIZ) && strncmp(left, oldptr, strlen(left)) == 0) { if (newptr > betterbuf) newptr--; oldptr += strlen(left); } else if ( (oldptr+strlen(right) < buf+BUFSIZ) && strncmp(right, oldptr, strlen(right)) == 0) { if (newptr < (betterbuf+BUFSIZ-1) ) newptr++; oldptr += strlen(right); } else *newptr++ = *oldptr++; } *newptr = '\0'; printf( "%s\n", betterbuf ); } }