#-h- rev.r 1185 asc 6-oct-80 07:17:19 #-h- defns 60 asc 6-oct-80 07:15:48 # include general symbol definitions # include ratdef #-h- rev 690 asc 6-oct-80 07:15:49 # rev - reverse lines subroutine main character lin(MAXLINE) integer i, fd integer getarg, open fd = ERR for (i=1; getarg(i, lin, FILENAMESIZE) != EOF; i=i+1) { if (lin(1) == QMARK & lin(2) == EOS) call error ("usage: rev [files.].") else if (lin(1) == MINUS & lin(2) == EOS) fd = STDIN else { fd = open(lin, READ) if (fd == ERR) call cant(lin) } call revl(fd) if (fd != STDIN) call close(fd) } if (fd == ERR) #no files given, read STDIN call revl(STDIN) return end #-h- revl 288 asc 6-oct-80 07:15:49 ## revl - reverse lines in file 'fd' subroutine revl(fd) integer fd, i integer getlin character lin(MAXLINE) for (i = getlin(lin, fd); i ^= EOF; i = getlin(lin, fd)) { for (i = i - 1; i > 0; i = i - 1) call putc(lin(i)) call putc(NEWLINE) } return end