#include #include using namespace std; #define ROWS 23 #define COLUMNS 80 //this version does not print the percentage //of bytes seen but it is trivial to add struct undo { bool canundo; //can we undo? int seek_last; //last page action before current action int seek_pos; //last page action int seek_end; //end of last page int line_skip; //lines to skip since seek_last int line_count; //lines counted since seek_last undo() { canundo=false; seek_last=seek_pos=seek_end=line_skip=line_count=0; } }; void do_more_of(istream& is); int get_user_input(istream& is, ifstream& tty, undo& myundo); int main( int argc , char *argv[] ) { if (argc==1) do_more_of(cin); else while (0<--argc) { ifstream is(*++argv); if (is.good()) { do_more_of(is) ; is.close(); } else cout<<"skipping "<<*argv<<"\n"; } return 0; } void do_more_of(istream& is) { undo myundo; char line[COLUMNS+1]; // buffer to store line of input int num_of_lines = ROWS; // # of lines left on screen ifstream tty("/dev/tty"); if (!tty.good()) { exit(1); } while (true) { if (num_of_lines==0) { myundo.seek_end=is.tellg(); //end of current page num_of_lines = get_user_input(is, tty, myundo); if (num_of_lines==-1) exit(1); //quit if (num_of_lines==-2) return; //next file } else { is.getline(line, COLUMNS+1); if (is.fail() && !is.eof()) //if line is long, clear error bit is.clear(); cout<