derek@uqpsych.OZ (Derek Austin) (08/28/84)
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 <garbage */ #include <stdio.h> 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 ); } }