CSE 326, Data Structures
Project2: Text Editor

Due: Tuesday, May 5th, 11:30PM (the Tuesday after the midterm)

Objective To build data structures for use by a text editor and develop experience with list-like data structures.

Overview

        Although different text editors (pico, Emacs, Word, vi, et cetera) have different user interfaces, they have some basic features in common: they all display a block of text, and have a cursor. When the user types, characters are inserted just before the cursor. Deletion removes the character just before the cursor, and the cursor can be moved around with the arrow keys or the mouse.
        The text editor we will implement for this project follows this same archetype. The main challenge will be to design a data structure to hold the text which efficiently implements the basic operations required for text editing.
        To make the project simpler, we have provided you with the skeleton of a Text and iterator class. An instance of the Text class is used to store the data the user types in, and the cursor is an instance of iterator. The iterator acts like a pointer to data in the text class. So, if our cursor is an iterator i, we can move the cursor forward with i++, backwards with i--, and access the character the cursor is under with *i.
        An iterator provides a way to access the elements of a data structure without exposing the underlying structure of the data. This allows you to implement the Text class using any data structure you like, and still have a standard interface. That way we can provide you with a driver program that handles user input from the keyboard and mouse, refreshes the display, et cetera. All you need to worry about is the implementation of Text and iterator.

Assignment

Your job is to implement the Text and iterator ADT's, which we have declared for you in Text.h, there are 9 functions for the Text class and 9 functions for the iterator class that you need to implement. These are listed below.

What we`ve provided



All provided files can be found in the project directory:
        cse/courses/cse326/98sp/project2

Choosing your data structure

You should examine a few different options before you decide on a data structure for an internal representation of the text. There are a number of criteria that you should consider in choosing your data structure including simplicity, ease of programming, time and storage efficiency, and ease of maintenance. In particular, a good data structure for the Text class should perform the following key operations quickly: Consider at least two different data structures that would efficiently implement these operations. Then, choose the best one for your implementation.

Sample executable

We've provided a sample executable in /cse/courses/cse326/98sp/project2/sample, to use it type sample at the command line. Optionally, you can provide the name of a file to edit after the name of the program. If the file does not exist already, sample will try to create it.

orcas% sample
orcas% sample mytextfile


Here is a brief list of commands for the sample editor that users of pico (the worlds greatest editor) and Emacs will find familiar:

BACKSPACE Deletes the character before the cursor
CTRL_A Moves cursor to start of line
CTRL_E Moves cursor to end of line
CTRL_SPACE Sets the mark
CTRL_D Long delete from cursor to mark
CTRL_X Exits the program and saves the file
CTRL_R Redraws the screen
Arrow keys Moves the cursor around
Mouse button Moves the cursor around

The sample editor was written with ease of implementation in mind, and does not use the most efficient data structure to store the text. So, you may notice some sluggishness when reading large files.

What to hand in
You are required to hand in your project2 directory with your implementation of the Text and iterator ADTs. Included in this directory should be at least these files

How to hand in
As with Project 1 use the turnin program. See the directions in Project 1 . For example you must type:
% cd ~/326stuff/myproj2dir
% make clean
% cd ../
% turnin -c cse326=AA -p project2 myproj2dir
if your project is found in your subdirectory ~/326stuff/myproj2dir.

Hints

Start early, and ask lots of questions. You may find it helpful to talk about the program with your fellow students, but remember that all work should be your own.