#include <stdlib.h>
#include <str.h>
#include <errno.h>
#include <adt/list.h>
#include <align.h>
#include <macros.h>
#include "sheet.h"
Go to the source code of this file.
Enumerations | |
enum | { , INITIAL_SIZE = 32 } |
Functions | |
void | sheet_copy_out (sheet_t *sh, spt_t const *spos, spt_t const *epos, char *buf, size_t bufsize, spt_t *fpos) |
Read text from sheet. | |
int | sheet_delete (sheet_t *sh, spt_t *spos, spt_t *epos) |
Delete text from sheet. | |
void | sheet_get_cell_pt (sheet_t *sh, coord_t const *coord, enum dir_spec dir, spt_t *pt) |
Get point preceding or following character cell. | |
void | sheet_get_num_rows (sheet_t *sh, int *rows) |
Get the number of rows in a sheet. | |
void | sheet_get_row_width (sheet_t *sh, int row, int *length) |
Get the number of character cells a row occupies. | |
int | sheet_init (sheet_t *sh) |
Initialize an empty sheet. | |
int | sheet_insert (sheet_t *sh, spt_t *pos, enum dir_spec dir, char *str) |
Insert text into sheet. | |
void | sheet_place_tag (sheet_t *sh, spt_t const *pt, tag_t *tag) |
Place a tag on the specified s-point. | |
void | sheet_remove_tag (sheet_t *sh, tag_t *tag) |
Remove a tag from the sheet. | |
bool | spt_equal (spt_t const *a, spt_t const *b) |
Test if two s-points are equal. | |
void | spt_get_coord (spt_t const *pos, coord_t *coord) |
Get the coordinates of an s-point. | |
void | tag_get_pt (tag_t const *tag, spt_t *pt) |
Get s-point on which the tag is located right now. |
The sheet is an abstract data structure representing a piece of text. On top of this data structure we can implement a text editor. It is possible to implement the sheet such that the editor can make small changes to large files or files containing long lines efficiently.
The sheet structure allows basic operations of text insertion, deletion, retrieval and mapping of coordinates to position in the file and vice versa. The text that is inserted or deleted can contain tabs and newlines which are interpreted and properly acted upon.
This is a trivial implementation with poor efficiency with O(N+n) insertion and deletion and O(N) mapping (in both directions), where N is the size of the file and n is the size of the inserted/deleted text.
Definition in file sheet.c.