Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!security!genrad!grkermit!masscomp!clyde!akgua!sb1!mb2c!jed From: jed@mb2c.UUCP (John E. Duncan III) Newsgroups: net.sources Subject: echo.c for APPLE AZTEC, new & improved Message-ID: <192@mb2c.UUCP> Date: Tue, 15-Nov-83 20:59:34 EST Article-I.D.: mb2c.192 Posted: Tue Nov 15 20:59:34 1983 Date-Received: Thu, 17-Nov-83 01:23:39 EST Lines: 91 /* echo.c for APPLE AZTEC 'C' system */ /* This command echoes its arguments to STDOUT. Any special characters * can be produced by using the backslash to quote the character or * octal string (ex: \012 is same as \n) or hex string (ex. \x0C is * same as \n). Stdio is avoided like the plague to keep it small, fast * and reusable via the 'run' command. */ #define STDOUT 1 #define BUFSIZ 256 static char *buf, *op; static char hex[] = "0123456789ABCDEF"; main(argc, argv) int argc; char **argv; { register char *ap, *endbuf, *hp, ch, cx; register int i, j; char space[BUFSIZ]; op = buf = space; endbuf = space + BUFSIZ - 1; if( --argc ) { for( i = 1; i <= argc; i++ ) { for( ap = *++argv; *ap; ++ap ) { if(*ap == '\\') { switch(*++ap) { case 'b': ch = '\b'; break; case 'c': goto done; case 'f': ch = '\f'; break; case 'n': ch = '\n'; break; case 'r': ch = '\r'; break; case 't': ch = '\t'; break; case 'x': ch = 0; if( hp = index( hex, *++ap )) ch = hp - hex; if( hp = index( hex, *++ap )) ch = (ch<<4) + hp - hex; break; case '\\': ch = '\\'; break; case '0': j = ch = 0; hp = ap + 4; while (((cx = *++ap) >= '0' && cx <= '7') && ap < hp) ch = (ch<<3) + cx - '0'; default: --ap; } *op = ch; } else *op = *ap; if( ++op == endbuf ) flush(); } *op = (i == argc ? '\n' : ' '); if( ++op == endbuf ) flush(); } } else { /* no arguments, just emit new-line and exit */ *space = '\n'; ++op; } done: flush(); exit(0); } flush() { register int i; i = op - buf; if( i ) write( STDOUT, buf, i ); op = buf; }