Browse Source
Merge branch 'stew' of https://gitea.cslabs.clarkson.edu/cameron/cs142-project-1
stew^2
Merge branch 'stew' of https://gitea.cslabs.clarkson.edu/cameron/cs142-project-1
stew^2
10 changed files with 212 additions and 202 deletions
-
11debug.sh
-
69docs/design.md
-
51docs/design.txt
-
3docs/sample_interface.txt
-
60docs/specification.md
-
55docs/specification.txt
-
121src/Buffer.cpp
-
12src/Buffer.h
-
8src/FileBrowser.cpp
-
24test.txt
@ -0,0 +1,11 @@ |
|||
#!/bin/bash |
|||
if [ ! -d obj ]; then |
|||
mkdir obj |
|||
fi |
|||
cd obj |
|||
g++ ../src/*.cpp -c -g |
|||
cd .. |
|||
if [ ! -d bin ]; then |
|||
mkdir bin |
|||
fi |
|||
g++ obj/*.o -o bin/FileBrowser |
@ -0,0 +1,69 @@ |
|||
# File Browser |
|||
|
|||
|
|||
## DESIGN DOCUMENT |
|||
|
|||
|
|||
### COMPONENT: class FileBrowser |
|||
|
|||
A simple file browser. See program specification for details. |
|||
|
|||
#### Public method: |
|||
|
|||
* void run() |
|||
|
|||
Runs the browser. |
|||
|
|||
**Implementation note**: Holds the lines of text in a Buffer object. The displaying of the buffer contents and the execution of the commands is delegated to the Buffer object. |
|||
|
|||
Collaborator: Buffer. |
|||
|
|||
|
|||
### COMPONENT: class Buffer |
|||
|
|||
A buffer for a simple file browser. Holds the lines of text and executes commands on them. Displays the contents of the buffer. See program specification for details on commands. |
|||
|
|||
#### Public methods: |
|||
|
|||
* Buffer() |
|||
|
|||
(Compiler-generated.) Creates an empty buffer. |
|||
|
|||
* void display() const |
|||
|
|||
Displays the lines of text that the user is currently viewing. |
|||
|
|||
* const string & file_name() const |
|||
|
|||
Returns the name of the file. |
|||
|
|||
* bool go(int link) |
|||
|
|||
Goes to the specified link in the current file. This opens the new link file and adds it to the open history. |
|||
|
|||
* void max_links() |
|||
|
|||
Returns the maximum number of links on the page. This is used by the file browser. |
|||
|
|||
* void move_to_next_page() |
|||
|
|||
Self-explanatory. |
|||
|
|||
* void move_to_previous_page() |
|||
|
|||
Self-explanatory. |
|||
|
|||
* bool open(const string & file_name) |
|||
|
|||
Executes the corresponding file viewer command on the buffer. See program specification for details. The method open returns true if successful. |
|||
|
|||
* void set_maximum_length(int l) |
|||
|
|||
Self-explanatory. |
|||
|
|||
* void set_window_height(int h) |
|||
|
|||
Self-explanatory. |
|||
|
|||
**Implementation note**: Stores each line of text as a string and all the lines in a vector. Also stores the index of the line currently displayed at the top of the window, as well as the name of the file and the window height. |
|||
|
@ -1,51 +0,0 @@ |
|||
File Browser |
|||
|
|||
|
|||
DESIGN DOCUMENT |
|||
|
|||
|
|||
COMPONENT: class FileBrowser |
|||
|
|||
A simple file browser. See program specification for details. |
|||
|
|||
Public method: |
|||
|
|||
* void run() |
|||
|
|||
Runs the browser. |
|||
|
|||
Implementation note: Holds the lines of text in a Buffer object. The displaying of the buffer contents and the execution of the commands is delegated to the Buffer object. |
|||
|
|||
Collaborator: Buffer. |
|||
|
|||
|
|||
COMPONENT: class Buffer |
|||
|
|||
A buffer for a simple file browser. Holds the lines of text and executes commands on them. Displays the contents of the buffer. See program specification for details on commands. |
|||
|
|||
Public methods: |
|||
|
|||
* Buffer() |
|||
|
|||
(Compiler-generated.) Creates an empty buffer. |
|||
|
|||
* void display() const |
|||
|
|||
Displays the lines of text that the user is currently viewing. |
|||
|
|||
* const string & file_name() const |
|||
|
|||
Returns the name of the file. |
|||
|
|||
* void move_to_next_page() |
|||
void move_to_previous_page() |
|||
bool open(const string & file_name) |
|||
|
|||
Executes the corresponding file viewer command on the buffer. See program specification for details. The method open returns true if successful. |
|||
|
|||
* void set_window_height(int h) |
|||
|
|||
Self-explanatory. |
|||
|
|||
Implementation note: Stores each line of text as a string and all the lines in a vector. Also stores the index of the line currently displayed at the top of the window, as well as the name of the file and the window height. |
|||
|
@ -0,0 +1,60 @@ |
|||
File browser |
|||
|
|||
|
|||
# SPECIFICATION |
|||
|
|||
|
|||
## OVERVIEW |
|||
|
|||
A simple file browser 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 These notes are for a second course on computer programming and |
|||
2 software development. In a first course, you likely focused on |
|||
3 learning the basics: variables, control statements, input and |
|||
4 output, files, vectors (or arrays), functions and structures. You |
|||
5 may have also had an introduction to classes. These concepts are |
|||
6 critically important and they are sufficient for the creation of |
|||
7 many useful programs. But many other programs, especially large |
|||
8 ones, require more powerful concepts and techniques. And a deeper |
|||
9 understanding of classes and design principles. |
|||
10 |
|||
11 In fact, the creation of large computer programs poses three basic |
|||
12 challenges. The overall goal of these notes is to teach you |
|||
-------------------------------------------------- |
|||
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". Then, the user will be asked for the maximum number of characters displayed per line. 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. If no file is currently open, the string "<no file opened>" is printed instead of the file name. |
|||
|
|||
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: |
|||
|
|||
* open: Asks for a file name (with prompt "file:") and displays that file after parsing the proper tags and links. If a file named X does not open, the message "ERROR: Could not open X" is displayed just before the file name is redisplayed. |
|||
|
|||
* 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. |
|||
|
|||
* go: Go to the specified link number on the page. This opens the file to that link and displays it starting from the top line. |
|||
|
|||
* back: Allows you to move back to old files that you navigated to through links. **Note**: This does not apply to when files are opened through the open command. |
|||
|
|||
* quit: Stops the program. |
|||
|
|||
## NOTES FOR LATER VERSIONS |
|||
|
|||
Add more error-checking. For example, check that commands are entered properly and that the window height is a positive integer. |
@ -1,55 +0,0 @@ |
|||
File browser |
|||
|
|||
|
|||
SPECIFICATION |
|||
|
|||
|
|||
OVERVIEW |
|||
|
|||
A simple file browser 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 These notes are for a second course on computer programming and |
|||
2 software development. In a first course, you likely focused on |
|||
3 learning the basics: variables, control statements, input and |
|||
4 output, files, vectors (or arrays), functions and structures. You |
|||
5 may have also had an introduction to classes. These concepts are |
|||
6 critically important and they are sufficient for the creation of |
|||
7 many useful programs. But many other programs, especially large |
|||
8 ones, require more powerful concepts and techniques. And a deeper |
|||
9 understanding of classes and design principles. |
|||
10 |
|||
11 In fact, the creation of large computer programs poses three basic |
|||
12 challenges. The overall goal of these notes is to teach you |
|||
-------------------------------------------------- |
|||
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. If no file is currently open, the string "<no file opened>" is printed instead of the file name. |
|||
|
|||
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. For example, check that commands are entered properly and that the window height is a positive integer. |
@ -1,35 +1,35 @@ |
|||
<p>This is the first line in the file. |
|||
<p>This is the second <br> and third line of the file. |
|||
<p>This is the second<br>and third line of the file. |
|||
<p>This line has a link to the <a docs/specification.txt specification> file. |
|||
<p>This line is split into <p>two paragraph tags. |
|||
<p>This line is split into<p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p> tags. |
|||
Derp. Derp. Derp. Derp. Derp. |
|||
<p>This is the first line in the file. |
|||
<p>This is the second <br> and eighth line of the file. |
|||
<p>This is the second<br>and eighth line of the file. |
|||
<p>This line has a link to the <a docs/specification.txt specification> file. |
|||
<p>This line is split into <p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p> tags. |
|||
<p>This line is split into<p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p>tags. |
|||
Derp. Derp. Derp. Derp. Derp. |
|||
<p>This is the first line in the file. |
|||
<p>This is the second <br> and fourteenth line of the file. |
|||
<p>This is the second<br>and fourteenth line of the file. |
|||
<p>This line has a link to the <a docs/specification.txt specification> file. |
|||
<p>This line is split into <p>two paragraph tags. |
|||
<p>This line is split into<p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p> tags. |
|||
Derp. Derp. Derp. Derp. Derp. |
|||
<p>This is the first line in the file. |
|||
<p>This is the second <br> and twentieth line of the file. |
|||
<p>This is the second<br>and twentieth line of the file. |
|||
<p>This line has a link to the <a docs/specification.txt specification> file. |
|||
<p>This line is split into <p>two paragraph tags. |
|||
<p>This line is split into<p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p> tags. |
|||
Derp. Derp. Derp. Derp. Derp. |
|||
<p>This is the first line in the file. |
|||
<p>This is the second <br> and twenty sixth line of the file. |
|||
<p>This is the second<br>and twenty sixth line of the file. |
|||
<p>This line has a link to the <a docs/specification.txt specification> file. |
|||
<p>This line is split into <p>two paragraph tags. |
|||
<p>This line is split into<p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p> tags. |
|||
Derp. Derp. Derp. Derp. Derp. |
|||
<p>This is the first line in the file. |
|||
<p>This is the second <br> and thirty second line of the file. |
|||
<p>This is the second<br>and thirty second line of the file. |
|||
<p>This line has a link to the <a docs/specification.txt specification> file. |
|||
<p>This line is split into <p>two paragraph tags. |
|||
<p>This line con<br>tains some<br > problematic< p> tags. |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue