/* * File: buffer.h * -------------- * This file defines the interface for an ed
ID: 3572428 • Letter: #
Question
/*
* File: buffer.h
* --------------
* This file defines the interface for an editor buffer abstraction.
*/
#ifndef _buffer_h
#define _buffer_h
#include "genlib.h"
/*
* Type: bufferADT
* ---------------
* This type defines the abstract type used to represent
* an editor buffer.
*/
typedef struct bufferCDT *bufferADT;
/* Exported entries */
/*
* Function: NewBuffer
* Usage: buffer = NewBuffer();
* ----------------------------
* This function dynamically allocates enough memory for the
* underlying representation of a bufferADT and initializes
* it to represent an empty buffer.
*/
bufferADT NewBuffer(void);
/*
* Function: FreeBuffer
* Usage: FreeBuffer(buffer);
* --------------------------
* This function frees the storage associated with the buffer.
*/
void FreeBuffer(bufferADT buffer);
/*
* Functions: MoveCursorForward, MoveCursorBackward
* Usage: MoveCursorForward(buffer);
* MoveCursorBackward(buffer);
* ----------------------------------
* These functions move the cursor forward or backward one
* character, respectively. If you call MoveCursorForward
* at the end of the buffer or MoveCursorBackward at the
* beginning, the function call has no effect.
*/
void MoveCursorForward(bufferADT buffer);
void MoveCursorBackward(bufferADT buffer);
/*
* Functions: MoveCursorToStart, MoveCursorToEnd
* Usage: MoveCursorToStart(buffer);
* MoveCursorToEnd(buffer);
* -------------------------------
* These functions move the cursor to the start or the
* end of the buffer, respectively.
*/
void MoveCursorToStart(bufferADT buffer);
void MoveCursorToEnd(bufferADT buffer);
/*
* Function: InsertCharacter
* Usage: InsertCharacter(buffer, ch);
* -----------------------------------
* 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(bufferADT buffer, char ch);
/*
* Function: DeleteCharacter
* Usage: DeleteCharacter(buffer);
* -------------------------------
* This function deletes the character immediately after
* the cursor. If the cursor is at the end of the buffer,
* this function has no effect.
*/
void DeleteCharacter(bufferADT buffer);
/*
* Function: DisplayBuffer
* Usage: DisplayBuffer(buffer);
* -----------------------------
* This function displays the current contents of the buffer
* on the console.
*/
void DisplayBuffer(bufferADT buffer);
#endif
From this point, it is a simple matter to insert the Fin the second block: Reimplement the EditorBuffer class so that the data representation of the buffer is a linked list of blocks, where each block can hold up to MAx BLocK sIzE characters In writing your implementation, you should be sure to remember the following points: You are responsible for designing the data structure for the EditorBuffer class. Think hard about the design of your data structure before you start writing the code. Draw pictures. Figure out what the empty buffer looks like. Consider carefully how the data structures change as blocks are split. You should choose a strategy for representing the cursor that allows you to represent the possible states of a buffer in a consistent, understandable way. To get a sense of whether your representation works well, make sure that you can answer basic questions about your representation. How does your buffer structure indicate that the cursor is at the beginning of the buffer? What about a cursor at the end? What about a cursor that falls between characters in different blocks? Is there a unique representation for such circumstances, or is there ambiguity in your design? In general, it will help a great deal if you try to simplify your design and avoid introducing lots of special case handling. If you have to insert a character into a block that is full, you should divide the block in half before making the insertion. This policy helps ensure that neither of the two resulting blocks starts out being filled, which might immediately require another split when the next character came alongExplanation / Answer
//editor.c
=============================================================
//buffer.h
========================================================================
//arraybuf.c
========================================================
//listbuf.c
==============================================================
//stack.c
=====================================================================
//stack.h
====================================================================
//stackbuf.c
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.