Write a C++ program that implements a simple command-oriented text editor. The program reads
commands from its standard input that modify the text of the document. When the program reaches
end-of-file on its input, it writes the current contents of the document to standard output and exits.
Background
In addition to the text of the document, the editor maintains a current position indicator, referred to
as point, that defines the location for text-modifying commands. Conceptually, point is interpreted
as specifying the location between characters rather than the characters themselves. Thus its
smallest value specifies the location before the first character in the document, and its largest value
specifies the location after the last character.
Some commands operate on whole lines. In such cases, the line containing point is the location of
the action, and the contents of the line is considered to consist of all of the characters that make up
the text (which could be nothing if the line is empty) plus an end-of-line indicator. The lowest
value of point for a given line is the location before the first character; the highest value is after the
last character but before the end-of-line indicator.
Input commands that begin with a dot define operations on the document, such as moving point,
inserting and deleting text, and searching. All other input defines text to be inserted as-is. For
example the input
of our discontent...
. moves point to the end of the document. p moves point to the
beginning of the previous line. n moves point to the beginning of the next line. k deletes the
current line and leaves point at the beginning of the following line.
3. Process dot commands that move point in character increments. a moves point to the
beginning of the current line. e moves point to the end of the current line. f moves point
one character forward; if point is already at the end of the current line, it moves to the
beginning of the following line. b moves point one character backward; if point is already at
the beginning of the current line, it moves to the end of the previous line.
4. Process dot commands that insert and delete characters within lines. d deletes the
character after point (for this level, you can assume that point is not at the end of the line). i
inserts the following characters (up to but not including the newline) at point and leaves point
after the inserted characters.
5. Process insert and delete commands that cross line boundaries. If a d command is
processed when point is at the end of the line, it is interpreted as deleting the end-of-line
indicator, thus joining the current line and the following line. The effect is that the characters
of the following line are appended to the current line. If the text to be inserted by an i
command contains the special sequence \n, that sequence is interpreted as an end-of-line
indicator, thus dividing the current line. The effect is that that text preceding the end-of-line
indicator will appear at the end of the current line, and text following the indicator will appear
at the beginning of the next line.
6. Process dot commands that contain multiple commands and repeat counts. Each
character in a dot command line is processed in turn. An integer value followed by a
command character is interpreted as shorthand for repeating the character the given number of
times. A line can contain any combination of commands, except that the i command can only
be the last command character, since any following characters will be interpreted as the text to
insert. However, the i command can be given a repeat count, in which case the text will be
inserted multiple times.
7. Kill buffer. Extend the processing of the k command so that the deleted line is stored in a
buffer for subsequent re-insertion with a y command, which inserts the contents of the buffer
before the current line. Successive k commands with no other intervening commands,
specified either by explicit repetition or using a repeat count, add lines to the buffer so that the
subsequent y command will insert a block of lines.
Flinders University / College of Science and Engineering !2
Computer Programming 2 Assignment 2
8. Searching. The s command searches for specified text and leaves point positioned at the
beginning of the first match. The search begins at point and continues to the end of the
document, then resumes at the beginning. If no match is found, point is left unchanged. The
text to search for consists of the remainder of the command line up to but not including the
newline, which implies that s must be the final command on a command line. For this level,
you can assume that the search text will match only within a single document line, although
not necessarily the current line.
9. Searching across line boundaries. Extend the processing for the s command so that if the
search text contains the special sequence \n it will match across line boundaries.
10. Selection and clipboard. The m command marks the current value of point and then moves
point one character forward. The region between mark and point defines a text selection for
subsequent processing. Successive m commands with no other intervening commands,
specified either by explicit repetition or using a repeat count, move point further forwards,
thus adding to the selection. The c command copies the current selection to a clipboard; x
copies the selection to the clipboard and then deletes the text; v inserts the current contents of
the clipboard at point.
Assessment
Pairing
You are encouraged to work on this assignment in pairs. If you work as a pair, you must both hand
in the same ticket number. All work handed in will be checked using a similarity checker; if more
that 2 solutions appear similar, marks will be withheld pending investigation.
Automatic assessment
The function points for this task will be assessed automatically using the demo and try programs
under the task name editor. You can run the demo version using demo editor and you can
test your work using try editor >. As the source code consists of more than
one file, you'll need to submit your work as a zip file.
Scoring
The assignment will be submitted and assessed twice: once following the "core" hand-in date, and
again following the "extension" hand-in date. The core submission will be given a score out of 10,
based on the first 5 function points. The extension submission will also be given a score out of 10,
based on the last 5 function points.