File Viewer


SPECIFICATION


OVERVIEW

A simple file viewer that allows the user view the contents of a text file.  


DETAILS

The program interacts with the user as shown in the following example:

preface.txt
--------------------------------------------------
  1  After a few computer science courses, students may start to
  2  get the feeling that programs can always be written to
  3  solve any computational problem.  Writing the program may
  4  be hard work.  For example, it may involve learning a
  5  difficult technique.  And many hours of debugging.  But
  6  with enough time and effort, the program can be written.
  7
  8  So it may come as a surprise that this is not the case:
  9  there are computational problems for which no program
 10  exists.  And these are not ill-defined problems (Can a
--------------------------------------------------
  next  previous  open  quit 
-------
command: o
file: introduction.txt

The program begins by asking the user for a window height.  This is the number of lines that will be displayed as each "page".  The displayed lines are numbered starting at 1 for the first line of the file.  If the number of lines on the last page is smaller than the window height, the rest of the window is filled with unnumbered empty lines. 

Each page is displayed between two lines of 50 dashes.  The name of the file is printed above the first line of dashes.  Below the second line of dashes, a menu of commands is displayed.  Below that menu, the prompt "choice:" is displayed.  The user types the first letter of a command, the command executes and everything is redisplayed.  Some commands prompt the user for more information.  

Here is a description of the various commands:

next: The next page is displayed.  Does nothing if the last line of the file is already displayed.

previous: The previous page is displayed.  Does nothing if the first line of the file is already displayed.

open: Asks for a file name (with prompt "file:") and displays that file.  If a file named X does not open, the message "ERROR: Could not open X" is displayed just before the file name is redisplayed.

quit: Stops the program.


NOTES FOR LATER VERSIONS

Add more error-checking.  (Check that commands are entered properly and that the window height is a positive integer.)
