From 040bd93cc4a032804136233ca4bc2b06a32e8c56 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 19 Apr 2017 17:38:34 +0200
Subject: [PATCH] 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.
---
 src/cut.c   | 14 +++++++-------
 src/files.c |  4 ++--
 src/nano.c  | 55 ++++++++++++++++++++++++++---------------------------
 src/text.c  | 10 ++++------
 src/utils.c |  4 ++--
 5 files changed, 42 insertions(+), 45 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index 015c80d4..d4e40497 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -108,8 +108,8 @@ void cut_to_eof(void)
 }
 #endif /* !NANO_TINY */
 
-/* Move text from the current filestruct into the cutbuffer.  If
- * copy_text is TRUE, copy the text back into the filestruct afterward.
+/* Move text from the current buffer into the cutbuffer.  If
+ * 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
  * position to the end of the file into the cutbuffer. */
 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
 }
 
-/* Move text from the current filestruct into the cutbuffer. */
+/* Move text from the current buffer into the cutbuffer. */
 void do_cut_text_void(void)
 {
 #ifndef NANO_TINY
@@ -214,8 +214,8 @@ void do_cut_text_void(void)
 }
 
 #ifndef NANO_TINY
-/* Move text from the current filestruct into the cutbuffer, and copy it
- * back into the filestruct afterward.  If the mark is set or the cursor
+/* Move text from the current buffer into the cutbuffer, and copy it
+ * back into the buffer afterward.  If the mark is set or the cursor
  * was moved, blow away previous contents of the cutbuffer. */
 void do_copy_text(void)
 {
@@ -254,7 +254,7 @@ void do_cut_till_eof(void)
 }
 #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)
 {
     ssize_t was_lineno = openfile->current->lineno;
@@ -273,7 +273,7 @@ void do_uncut_text(void)
 	was_leftedge = (xplustabs() / editwincols) * editwincols;
 #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. */
     copy_from_buffer(cutbuffer);
 
diff --git a/src/files.c b/src/files.c
index b742f5da..e33b2874 100644
--- a/src/files.c
+++ b/src/files.c
@@ -2044,7 +2044,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
     filestruct *top, *bot;
     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,
 		(const filestruct **)&bot, &bot_x, NULL);
     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)
 	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);
 
     if (old_modified)
diff --git a/src/nano.c b/src/nano.c
index 7bb99202..50cf5532 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -51,19 +51,19 @@ static bool no_rcfiles = FALSE;
 #endif
 #ifdef HAVE_TERMIOS_H
 static struct termios oldterm;
+	/* The user's original terminal settings. */
 #else
 # define tcsetattr(...)
 # define tcgetattr(...)
 #endif
-	/* The user's original terminal settings. */
 static struct sigaction act;
 	/* 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. */
 filestruct *make_new_node(filestruct *prevnode)
 {
-    filestruct *newnode = (filestruct *)nmalloc(sizeof(filestruct));
+    filestruct *newnode = nmalloc(sizeof(filestruct));
 
     newnode->data = NULL;
     newnode->prev = prevnode;
@@ -77,17 +77,16 @@ filestruct *make_new_node(filestruct *prevnode)
     return newnode;
 }
 
-/* Make a copy of a filestruct node. */
+/* Make a copy of a linestruct node. */
 filestruct *copy_node(const filestruct *src)
 {
-    filestruct *dst;
-
-    dst = (filestruct *)nmalloc(sizeof(filestruct));
+    filestruct *dst = nmalloc(sizeof(filestruct));
 
     dst->data = mallocstrcpy(NULL, src->data);
     dst->next = src->next;
     dst->prev = src->prev;
     dst->lineno = src->lineno;
+
 #ifndef DISABLE_COLOR
     dst->multidata = NULL;
 #endif
@@ -95,7 +94,7 @@ filestruct *copy_node(const filestruct *src)
     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)
 {
     newnode->next = afterthis->next;
@@ -109,7 +108,7 @@ void splice_node(filestruct *afterthis, filestruct *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)
 {
     if (fileptr->prev != NULL)
@@ -134,7 +133,7 @@ void delete_node(filestruct *fileptr)
     free(fileptr);
 }
 
-/* Duplicate a whole filestruct. */
+/* Duplicate an entire linked list of linestructs. */
 filestruct *copy_filestruct(const filestruct *src)
 {
     filestruct *head, *copy;
@@ -157,7 +156,7 @@ filestruct *copy_filestruct(const filestruct *src)
     return head;
 }
 
-/* Free a whole linked list of filestructs. */
+/* Free an entire linked list of linestructs. */
 void free_filestruct(filestruct *src)
 {
     if (src == NULL)
@@ -171,7 +170,7 @@ void free_filestruct(filestruct *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)
 {
     ssize_t line;
@@ -187,8 +186,8 @@ void renumber(filestruct *fileptr)
 	fileptr->lineno = ++line;
 }
 
-/* Partition a filestruct so that it begins at (top, top_x) and ends at
- * (bot, bot_x). */
+/* Partition the current buffer so that it appears to begin at (top, top_x)
+ * and appears to end at (bot, bot_x). */
 partition *partition_filestruct(filestruct *top, size_t top_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));
 
     /* 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. */
     if (top != openfile->fileage) {
 	p->fileage = openfile->fileage;
@@ -236,8 +235,8 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
     return p;
 }
 
-/* Unpartition a filestruct so that it begins at (fileage, 0) and ends
- * at (filebot, strlen(filebot->data)) again. */
+/* Unpartition the current buffer so that it stretches from (fileage, 0)
+ * to (filebot, $) again. */
 void unpartition_filestruct(partition **p)
 {
     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);
     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. */
     if ((*p)->fileage != NULL)
 	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
- * 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),
  * don't do anything. */
 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)
 	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
      * the edit window is inside the partition, and keep track of
      * 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);
     }
 
-    /* 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->data = mallocstrcpy(NULL, "");
     openfile->filebot = openfile->fileage;
@@ -377,7 +376,7 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot,
 
     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. */
     unpartition_filestruct(&filepart);
 
@@ -423,14 +422,14 @@ void ingraft_buffer(filestruct *somebuffer)
     }
 #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. */
     filepart = partition_filestruct(openfile->current, openfile->current_x,
 				openfile->current, openfile->current_x);
     edittop_inside = (openfile->edittop == 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. */
     openfile->fileage = somebuffer;
     openfile->filebot = openfile->fileage;
@@ -476,7 +475,7 @@ void ingraft_buffer(filestruct *somebuffer)
 
     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. */
     unpartition_filestruct(&filepart);
 
@@ -496,13 +495,13 @@ void copy_from_buffer(filestruct *somebuffer)
     ingraft_buffer(the_copy);
 }
 
-/* Create a new openfilestruct node. */
+/* Create a new openfile node. */
 openfilestruct *make_new_opennode(void)
 {
     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)
 {
     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 (openfile && openfile->modified) {
-	/* If the filestruct is partitioned, unpartition it first. */
+	/* If the buffer is partitioned, unpartition it first. */
 	if (filepart != NULL)
 	    unpartition_filestruct(&filepart);
 
diff --git a/src/text.c b/src/text.c
index c53ccf6a..83c94254 100644
--- a/src/text.c
+++ b/src/text.c
@@ -2009,13 +2009,11 @@ void backup_lines(filestruct *first_line, size_t par_len)
     for (i = par_len; i > 0 && bot != openfile->filebot; i--)
 	bot = bot->next;
 
-    /* Move the paragraph from the current buffer's filestruct to the
-     * justify buffer. */
+    /* Move the paragraph from the current buffer to the justify buffer. */
     extract_buffer(&jusbuffer, &jusbottom, top, 0, bot,
 		(i == 1 && bot == openfile->filebot) ? strlen(bot->data) : 0);
 
-    /* Copy the paragraph back to the current buffer's filestruct from
-     * the justify buffer. */
+    /* Copy the paragraph back to the current buffer. */
     copy_from_buffer(jusbuffer);
 
     /* Move upward from the last line of the paragraph to the first
@@ -3499,7 +3497,7 @@ void do_wordlinechar_count(void)
     filestruct *top, *bot;
     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. */
     if (old_mark_set) {
 	mark_order((const filestruct **)&top, &top_x,
@@ -3529,7 +3527,7 @@ void do_wordlinechar_count(void)
 	nlines = openfile->filebot->lineno - openfile->fileage->lineno + 1;
 	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. */
 	unpartition_filestruct(&filepart);
 	openfile->mark_set = TRUE;
diff --git a/src/utils.c b/src/utils.c
index fe486609..c633f4b3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -535,7 +535,7 @@ size_t get_totsize(const filestruct *begin, const filestruct *end)
 }
 
 #ifdef DEBUG
-/* Dump the filestruct inptr to stderr. */
+/* Dump the given buffer to stderr. */
 void dump_filestruct(const filestruct *inptr)
 {
     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)
 {
     const filestruct *fileptr = openfile->filebot;
-- 
GitLab