#include <u.h>
#include <ctype.h>
#include <libc.h>
#include <bio.h>
Biobuf bin, bout;
static int
rot13(Biobuf *bp, char *file)
{
long got;
char buf[1024], *p;
while((got = Bread(bp, buf, sizeof(buf))) > 0){
for (p = buf; p < buf + got; p++){
if(!isprint(*p) && !isspace(*p)){
fprint(2, "%s: %s - '%c' bad character\n", argv0, file, *p);
}
if (isalpha(*p))
if (tolower(*p) <= 'm')
*p += 13;
else
*p -= 13;
}
Bwrite(&bout, buf, got);
}
return 0;
}
void
main(int argc, char *argv[])
{
Biobuf *bp;
Binit(&bout, 1, OWRITE);
argv0 = argv[0];
if(argc == 1){
Binit(&bin, 0, OREAD);
rot13(&bin, "stdin");
exits(0);
}
while(argv++, --argc){
if((bp = Bopen(*argv, OREAD)) == nil){
fprint(2, "%s: %s - cannot open - %r\n", argv0, *argv);
continue;
}
rot13(bp, *argv);
Bterm(bp);
}
exits(0);
}
|