tweaks: distinguish (in the comments) between buffers and linestructs

Call something a buffer when it refers to a linked list of linestructs,
and call something a linestruct when it is a struct that describes a
single line.
master
Benno Schulenberg 2017-04-19 17:38:34 +02:00
parent e935fd4f88
commit 040bd93cc4
5 changed files with 42 additions and 45 deletions

View File

@ -108,8 +108,8 @@ void cut_to_eof(void)
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
/* Move text from the current filestruct into the cutbuffer. If /* Move text from the current buffer into the cutbuffer. If
* copy_text is TRUE, copy the text back into the filestruct afterward. * copy_text is TRUE, copy the text back into the buffer afterward.
* If cut_till_eof is TRUE, move all text from the current cursor * If cut_till_eof is TRUE, move all text from the current cursor
* position to the end of the file into the cutbuffer. */ * position to the end of the file into the cutbuffer. */
void do_cut_text(bool copy_text, bool cut_till_eof) void do_cut_text(bool copy_text, bool cut_till_eof)
@ -201,7 +201,7 @@ void do_cut_text(bool copy_text, bool cut_till_eof)
#endif #endif
} }
/* Move text from the current filestruct into the cutbuffer. */ /* Move text from the current buffer into the cutbuffer. */
void do_cut_text_void(void) void do_cut_text_void(void)
{ {
#ifndef NANO_TINY #ifndef NANO_TINY
@ -214,8 +214,8 @@ void do_cut_text_void(void)
} }
#ifndef NANO_TINY #ifndef NANO_TINY
/* Move text from the current filestruct into the cutbuffer, and copy it /* Move text from the current buffer into the cutbuffer, and copy it
* back into the filestruct afterward. If the mark is set or the cursor * back into the buffer afterward. If the mark is set or the cursor
* was moved, blow away previous contents of the cutbuffer. */ * was moved, blow away previous contents of the cutbuffer. */
void do_copy_text(void) void do_copy_text(void)
{ {
@ -254,7 +254,7 @@ void do_cut_till_eof(void)
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
/* Copy text from the cutbuffer into the current filestruct. */ /* Copy text from the cutbuffer into the current buffer. */
void do_uncut_text(void) void do_uncut_text(void)
{ {
ssize_t was_lineno = openfile->current->lineno; ssize_t was_lineno = openfile->current->lineno;
@ -273,7 +273,7 @@ void do_uncut_text(void)
was_leftedge = (xplustabs() / editwincols) * editwincols; was_leftedge = (xplustabs() / editwincols) * editwincols;
#endif #endif
/* Add a copy of the text in the cutbuffer to the current filestruct /* Add a copy of the text in the cutbuffer to the current buffer
* at the current cursor position. */ * at the current cursor position. */
copy_from_buffer(cutbuffer); copy_from_buffer(cutbuffer);

View File

@ -2044,7 +2044,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
filestruct *top, *bot; filestruct *top, *bot;
size_t top_x, bot_x; size_t top_x, bot_x;
/* Partition the filestruct so that it contains only the marked text. */ /* Partition the buffer so that it contains only the marked text. */
mark_order((const filestruct **)&top, &top_x, mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, NULL); (const filestruct **)&bot, &bot_x, NULL);
filepart = partition_filestruct(top, top_x, bot, bot_x); filepart = partition_filestruct(top, top_x, bot, bot_x);
@ -2062,7 +2062,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
if (added_magicline) if (added_magicline)
remove_magicline(); remove_magicline();
/* Unpartition the filestruct so that it contains all the text again. */ /* Unpartition the buffer so that it contains all the text again. */
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
if (old_modified) if (old_modified)

View File

@ -51,19 +51,19 @@ static bool no_rcfiles = FALSE;
#endif #endif
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
static struct termios oldterm; static struct termios oldterm;
/* The user's original terminal settings. */
#else #else
# define tcsetattr(...) # define tcsetattr(...)
# define tcgetattr(...) # define tcgetattr(...)
#endif #endif
/* The user's original terminal settings. */
static struct sigaction act; static struct sigaction act;
/* Used to set up all our fun signal handlers. */ /* Used to set up all our fun signal handlers. */
/* Create a new filestruct node. Note that we do not set prevnode->next /* Create a new linestruct node. Note that we do not set prevnode->next
* to the new line. */ * to the new line. */
filestruct *make_new_node(filestruct *prevnode) filestruct *make_new_node(filestruct *prevnode)
{ {
filestruct *newnode = (filestruct *)nmalloc(sizeof(filestruct)); filestruct *newnode = nmalloc(sizeof(filestruct));
newnode->data = NULL; newnode->data = NULL;
newnode->prev = prevnode; newnode->prev = prevnode;
@ -77,17 +77,16 @@ filestruct *make_new_node(filestruct *prevnode)
return newnode; return newnode;
} }
/* Make a copy of a filestruct node. */ /* Make a copy of a linestruct node. */
filestruct *copy_node(const filestruct *src) filestruct *copy_node(const filestruct *src)
{ {
filestruct *dst; filestruct *dst = nmalloc(sizeof(filestruct));
dst = (filestruct *)nmalloc(sizeof(filestruct));
dst->data = mallocstrcpy(NULL, src->data); dst->data = mallocstrcpy(NULL, src->data);
dst->next = src->next; dst->next = src->next;
dst->prev = src->prev; dst->prev = src->prev;
dst->lineno = src->lineno; dst->lineno = src->lineno;
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
dst->multidata = NULL; dst->multidata = NULL;
#endif #endif
@ -95,7 +94,7 @@ filestruct *copy_node(const filestruct *src)
return dst; return dst;
} }
/* Splice a new node into an existing linked list of filestructs. */ /* Splice a new node into an existing linked list of linestructs. */
void splice_node(filestruct *afterthis, filestruct *newnode) void splice_node(filestruct *afterthis, filestruct *newnode)
{ {
newnode->next = afterthis->next; newnode->next = afterthis->next;
@ -109,7 +108,7 @@ void splice_node(filestruct *afterthis, filestruct *newnode)
openfile->filebot = newnode; openfile->filebot = newnode;
} }
/* Disconnect a node from a linked list of filestructs and delete it. */ /* Disconnect a node from a linked list of linestructs and delete it. */
void unlink_node(filestruct *fileptr) void unlink_node(filestruct *fileptr)
{ {
if (fileptr->prev != NULL) if (fileptr->prev != NULL)
@ -134,7 +133,7 @@ void delete_node(filestruct *fileptr)
free(fileptr); free(fileptr);
} }
/* Duplicate a whole filestruct. */ /* Duplicate an entire linked list of linestructs. */
filestruct *copy_filestruct(const filestruct *src) filestruct *copy_filestruct(const filestruct *src)
{ {
filestruct *head, *copy; filestruct *head, *copy;
@ -157,7 +156,7 @@ filestruct *copy_filestruct(const filestruct *src)
return head; return head;
} }
/* Free a whole linked list of filestructs. */ /* Free an entire linked list of linestructs. */
void free_filestruct(filestruct *src) void free_filestruct(filestruct *src)
{ {
if (src == NULL) if (src == NULL)
@ -171,7 +170,7 @@ void free_filestruct(filestruct *src)
delete_node(src); delete_node(src);
} }
/* Renumber all entries in a filestruct, starting with fileptr. */ /* Renumber the lines in a buffer, starting with fileptr. */
void renumber(filestruct *fileptr) void renumber(filestruct *fileptr)
{ {
ssize_t line; ssize_t line;
@ -187,8 +186,8 @@ void renumber(filestruct *fileptr)
fileptr->lineno = ++line; fileptr->lineno = ++line;
} }
/* Partition a filestruct so that it begins at (top, top_x) and ends at /* Partition the current buffer so that it appears to begin at (top, top_x)
* (bot, bot_x). */ * and appears to end at (bot, bot_x). */
partition *partition_filestruct(filestruct *top, size_t top_x, partition *partition_filestruct(filestruct *top, size_t top_x,
filestruct *bot, size_t bot_x) filestruct *bot, size_t bot_x)
{ {
@ -200,7 +199,7 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
p = (partition *)nmalloc(sizeof(partition)); p = (partition *)nmalloc(sizeof(partition));
/* If the top and bottom of the partition are different from the top /* If the top and bottom of the partition are different from the top
* and bottom of the filestruct, save the latter and then set them * and bottom of the buffer, save the latter and then set them
* to top and bot. */ * to top and bot. */
if (top != openfile->fileage) { if (top != openfile->fileage) {
p->fileage = openfile->fileage; p->fileage = openfile->fileage;
@ -236,8 +235,8 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
return p; return p;
} }
/* Unpartition a filestruct so that it begins at (fileage, 0) and ends /* Unpartition the current buffer so that it stretches from (fileage, 0)
* at (filebot, strlen(filebot->data)) again. */ * to (filebot, $) again. */
void unpartition_filestruct(partition **p) void unpartition_filestruct(partition **p)
{ {
assert(p != NULL && openfile->fileage != NULL && openfile->filebot != NULL); assert(p != NULL && openfile->fileage != NULL && openfile->filebot != NULL);
@ -266,7 +265,7 @@ void unpartition_filestruct(partition **p)
strcat(openfile->filebot->data, (*p)->bot_data); strcat(openfile->filebot->data, (*p)->bot_data);
free((*p)->bot_data); free((*p)->bot_data);
/* Restore the top and bottom of the filestruct, if they were /* Restore the top and bottom of the buffer, if they were
* different from the top and bottom of the partition. */ * different from the top and bottom of the partition. */
if ((*p)->fileage != NULL) if ((*p)->fileage != NULL)
openfile->fileage = (*p)->fileage; openfile->fileage = (*p)->fileage;
@ -279,7 +278,7 @@ void unpartition_filestruct(partition **p)
} }
/* Move all the text between (top, top_x) and (bot, bot_x) in the /* Move all the text between (top, top_x) and (bot, bot_x) in the
* current filestruct to a filestruct beginning with file_top and ending * current buffer to a new buffer beginning with file_top and ending
* with file_bot. If no text is between (top, top_x) and (bot, bot_x), * with file_bot. If no text is between (top, top_x) and (bot, bot_x),
* don't do anything. */ * don't do anything. */
void extract_buffer(filestruct **file_top, filestruct **file_bot, void extract_buffer(filestruct **file_top, filestruct **file_bot,
@ -298,7 +297,7 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot,
if (top == bot && top_x == bot_x) if (top == bot && top_x == bot_x)
return; return;
/* Partition the filestruct so that it contains only the text from /* Partition the buffer so that it contains only the text from
* (top, top_x) to (bot, bot_x), keep track of whether the top of * (top, top_x) to (bot, bot_x), keep track of whether the top of
* the edit window is inside the partition, and keep track of * the edit window is inside the partition, and keep track of
* whether the mark begins inside the partition. */ * whether the mark begins inside the partition. */
@ -356,7 +355,7 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot,
renumber(file_bot_save->next); renumber(file_bot_save->next);
} }
/* Since the text has now been saved, remove it from the filestruct. */ /* Since the text has now been saved, remove it from the buffer. */
openfile->fileage = make_new_node(NULL); openfile->fileage = make_new_node(NULL);
openfile->fileage->data = mallocstrcpy(NULL, ""); openfile->fileage->data = mallocstrcpy(NULL, "");
openfile->filebot = openfile->fileage; openfile->filebot = openfile->fileage;
@ -377,7 +376,7 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot,
top_save = openfile->fileage; top_save = openfile->fileage;
/* Unpartition the filestruct so that it contains all the text /* Unpartition the buffer so that it contains all the text
* again, minus the saved text. */ * again, minus the saved text. */
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
@ -423,14 +422,14 @@ void ingraft_buffer(filestruct *somebuffer)
} }
#endif #endif
/* Partition the filestruct so that it contains no text, and remember /* Partition the buffer so that it contains no text, and remember
* whether the current line is at the top of the edit window. */ * whether the current line is at the top of the edit window. */
filepart = partition_filestruct(openfile->current, openfile->current_x, filepart = partition_filestruct(openfile->current, openfile->current_x,
openfile->current, openfile->current_x); openfile->current, openfile->current_x);
edittop_inside = (openfile->edittop == openfile->fileage); edittop_inside = (openfile->edittop == openfile->fileage);
free_filestruct(openfile->fileage); free_filestruct(openfile->fileage);
/* Put the top and bottom of the current filestruct at the top and /* Put the top and bottom of the current buffer at the top and
* bottom of the passed buffer. */ * bottom of the passed buffer. */
openfile->fileage = somebuffer; openfile->fileage = somebuffer;
openfile->filebot = openfile->fileage; openfile->filebot = openfile->fileage;
@ -476,7 +475,7 @@ void ingraft_buffer(filestruct *somebuffer)
top_save = openfile->fileage; top_save = openfile->fileage;
/* Unpartition the filestruct so that it contains all the text /* Unpartition the buffer so that it contains all the text
* again, plus the copied text. */ * again, plus the copied text. */
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
@ -496,13 +495,13 @@ void copy_from_buffer(filestruct *somebuffer)
ingraft_buffer(the_copy); ingraft_buffer(the_copy);
} }
/* Create a new openfilestruct node. */ /* Create a new openfile node. */
openfilestruct *make_new_opennode(void) openfilestruct *make_new_opennode(void)
{ {
return (openfilestruct *)nmalloc(sizeof(openfilestruct)); return (openfilestruct *)nmalloc(sizeof(openfilestruct));
} }
/* Unlink a node from the rest of the openfilestruct, and delete it. */ /* Unlink a node from the rest of the circular list, and delete it. */
void unlink_opennode(openfilestruct *fileptr) void unlink_opennode(openfilestruct *fileptr)
{ {
assert(fileptr != fileptr->prev && fileptr != fileptr->next); assert(fileptr != fileptr->prev && fileptr != fileptr->next);
@ -600,7 +599,7 @@ void die(const char *msg, ...)
/* If the current file buffer was modified, save it. */ /* If the current file buffer was modified, save it. */
if (openfile && openfile->modified) { if (openfile && openfile->modified) {
/* If the filestruct is partitioned, unpartition it first. */ /* If the buffer is partitioned, unpartition it first. */
if (filepart != NULL) if (filepart != NULL)
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);

View File

@ -2009,13 +2009,11 @@ void backup_lines(filestruct *first_line, size_t par_len)
for (i = par_len; i > 0 && bot != openfile->filebot; i--) for (i = par_len; i > 0 && bot != openfile->filebot; i--)
bot = bot->next; bot = bot->next;
/* Move the paragraph from the current buffer's filestruct to the /* Move the paragraph from the current buffer to the justify buffer. */
* justify buffer. */
extract_buffer(&jusbuffer, &jusbottom, top, 0, bot, extract_buffer(&jusbuffer, &jusbottom, top, 0, bot,
(i == 1 && bot == openfile->filebot) ? strlen(bot->data) : 0); (i == 1 && bot == openfile->filebot) ? strlen(bot->data) : 0);
/* Copy the paragraph back to the current buffer's filestruct from /* Copy the paragraph back to the current buffer. */
* the justify buffer. */
copy_from_buffer(jusbuffer); copy_from_buffer(jusbuffer);
/* Move upward from the last line of the paragraph to the first /* Move upward from the last line of the paragraph to the first
@ -3499,7 +3497,7 @@ void do_wordlinechar_count(void)
filestruct *top, *bot; filestruct *top, *bot;
size_t top_x, bot_x; size_t top_x, bot_x;
/* If the mark is on, partition the filestruct so that it /* If the mark is on, partition the buffer so that it
* contains only the marked text, and turn the mark off. */ * contains only the marked text, and turn the mark off. */
if (old_mark_set) { if (old_mark_set) {
mark_order((const filestruct **)&top, &top_x, mark_order((const filestruct **)&top, &top_x,
@ -3529,7 +3527,7 @@ void do_wordlinechar_count(void)
nlines = openfile->filebot->lineno - openfile->fileage->lineno + 1; nlines = openfile->filebot->lineno - openfile->fileage->lineno + 1;
chars = get_totsize(openfile->fileage, openfile->filebot); chars = get_totsize(openfile->fileage, openfile->filebot);
/* Unpartition the filestruct so that it contains all the text /* Unpartition the buffer so that it contains all the text
* again, and turn the mark back on. */ * again, and turn the mark back on. */
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
openfile->mark_set = TRUE; openfile->mark_set = TRUE;

View File

@ -535,7 +535,7 @@ size_t get_totsize(const filestruct *begin, const filestruct *end)
} }
#ifdef DEBUG #ifdef DEBUG
/* Dump the filestruct inptr to stderr. */ /* Dump the given buffer to stderr. */
void dump_filestruct(const filestruct *inptr) void dump_filestruct(const filestruct *inptr)
{ {
if (inptr == openfile->fileage) if (inptr == openfile->fileage)
@ -551,7 +551,7 @@ void dump_filestruct(const filestruct *inptr)
} }
} }
/* Dump the current buffer's filestruct to stderr in reverse. */ /* Dump the current buffer to stderr in reverse. */
void dump_filestruct_reverse(void) void dump_filestruct_reverse(void)
{ {
const filestruct *fileptr = openfile->filebot; const filestruct *fileptr = openfile->filebot;