all in C code
Command Operation
F Moves the editing cursor forward one character position
B Moves the editing cursor backward one character position
J Jumps to the beginning of the buffer (before the first character)
E Moves the cursor to the end of the buffer (after the last character)
I Inserts the characters xxx at the current cursor position
D Deletes the character just after the current cursor position.
use the following type definition
for the nodes of this linked list:
typedef struct node{
char ch;
struct node *link;
} node;
The data structure for the buffer must contain at least two fields:
one pointer where the buffer starts and
one pointer to indicate the current cursor position
typedef struct bufferType{
node *start;
node *cursor;
...
} bufferType;
typedef bufferType *bufferT;
function prototypes in program:
/* This function dynamically allocates enough memory for the
underlying representation of a buffer and initializes to represent an
empty buffer
*/
bufferT NewBuffer();
/* This function frees the storage associated with the buffer.
*/
void FreeBuffer(bufferT buffer);
/* These functions move the cursor forward or backward one character
respectively. If Move CursorForward is called at the end of the buffer
or MoveCursorBackward is called at the beginning, the function call
has no effect.
*/
void MoveCursorForward(bufferT buffer);
void MoveCursorBackward(bufferT buffer);
/* These functions move the cursor to the start or to the end of the
buffer, respectively
*/
void MoveCursorToStart(bufferT buffer);
void MoveCursorToEnd(bufferT buffer);
/* This function inserts the single character ch into the buffer at
the current cursor position. The cursor is positioned after the
inserted character, which allows for consecutive insertions.
*/
void InsertCharacter(bufferT buffer, char c);
/* This function deletes the character immediately after the cursor.
If cursor is already at the end the function has no effect.
*/
void DeleteCharacter(bufferT buffer);
/* This function displays the current contents of the buffer on the
screen (as a sequence of characters)
*/
void DisplayBuffer(bufferT buffer);
/* This function stores a copy of the next count characters somewhere
in the internal structure for the buffer.
*/
void CopyFromBuffer(bufferT buffer, int count);
/* This function inserts those saved characters back into the buffer
at the current cursor position
*/
void PasteIntoBuffer(bufferT buffer);
/* This function stores a copy of the next count characters somewhere
in the internal structure for the buffer and then deletes those count
characters from the buffer.
*/
void CutFromBuffer(bufferT buffer, int count); |