From bf1a080923a69192ef7480b4a807f3d9b934c796 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 23 Mar 2018 10:53:06 +0100
Subject: [PATCH] build: exclude more things when configured with
 --disable-multibuffer

This will make the tiny version slightly smaller.
---
 src/files.c  | 5 ++++-
 src/global.c | 2 ++
 src/nano.c   | 5 ++++-
 src/nano.h   | 2 ++
 src/proto.h  | 2 ++
 src/text.c   | 6 +++---
 src/winio.c  | 4 ++++
 7 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/files.c b/src/files.c
index 10e2f624..c32fce1b 100644
--- a/src/files.c
+++ b/src/files.c
@@ -66,16 +66,19 @@ void make_new_buffer(void)
 
 	if (openfile == NULL) {
 		/* Make the first open file the only element in the list. */
+#ifdef ENABLE_MULTIBUFFER
 		newnode->prev = newnode;
 		newnode->next = newnode;
+#endif
 		firstfile = newnode;
 	} else {
 		/* Add the new open file after the current one in the list. */
+#ifdef ENABLE_MULTIBUFFER
 		newnode->prev = openfile;
 		newnode->next = openfile->next;
 		openfile->next->prev = newnode;
 		openfile->next = newnode;
-
+#endif
 		/* There is more than one file open: show "Close" in help lines. */
 		exitfunc->desc = close_tag;
 		more_than_one = !inhelp || more_than_one;
diff --git a/src/global.c b/src/global.c
index 1bf5c261..41d63833 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1779,12 +1779,14 @@ void thanks_for_all_the_fish(void)
 	free(alt_speller);
 #endif
 	free_filestruct(cutbuffer);
+#ifdef ENABLE_MULTIBUFFER
 	/* Free the memory associated with each open file buffer. */
 	while (openfile != openfile->next) {
 		openfile = openfile->next;
 		delete_opennode(openfile->prev);
 	}
 	delete_opennode(openfile);
+#endif
 #ifdef ENABLE_COLOR
 	free(syntaxstr);
 	while (syntaxes != NULL) {
diff --git a/src/nano.c b/src/nano.c
index 7f593a3d..878309c9 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -512,17 +512,19 @@ openfilestruct *make_new_opennode(void)
 	return (openfilestruct *)nmalloc(sizeof(openfilestruct));
 }
 
+#ifdef ENABLE_MULTIBUFFER
 /* 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);
 
+#ifdef ENABLE_MULTIBUFFER
 	if (fileptr == firstfile)
 		firstfile = firstfile->next;
 
 	fileptr->prev->next = fileptr->next;
 	fileptr->next->prev = fileptr->prev;
-
+#endif
 	delete_opennode(fileptr);
 }
 
@@ -539,6 +541,7 @@ void delete_opennode(openfilestruct *fileptr)
 #endif
 	free(fileptr);
 }
+#endif
 
 /* Display a warning about a key disabled in view mode. */
 void print_view_warning(void)
diff --git a/src/nano.h b/src/nano.h
index d3f87860..5812b506 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -408,10 +408,12 @@ typedef struct openfilestruct {
 	colortype *colorstrings;
 		/* The file's associated colors. */
 #endif
+#ifdef ENABLE_MULTIBUFFER
 	struct openfilestruct *next;
 		/* The next open file, if any. */
 	struct openfilestruct *prev;
 		/* The preceding open file, if any. */
+#endif
 } openfilestruct;
 
 #ifdef ENABLE_NANORC
diff --git a/src/proto.h b/src/proto.h
index 2d6ebfc1..befabe4a 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -410,8 +410,10 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot,
 void ingraft_buffer(filestruct *somebuffer);
 void copy_from_buffer(filestruct *somebuffer);
 openfilestruct *make_new_opennode(void);
+#ifdef ENABLE_MULTIBUFFER
 void unlink_opennode(openfilestruct *fileptr);
 void delete_opennode(openfilestruct *fileptr);
+#endif
 void print_view_warning(void);
 void show_restricted_warning(void);
 #ifndef ENABLE_HELP
diff --git a/src/text.c b/src/text.c
index efe123fd..37fea69b 100644
--- a/src/text.c
+++ b/src/text.c
@@ -3200,7 +3200,7 @@ void do_linter(void)
 		functionptrtype func;
 
 		if (tmplint != curlint) {
-#ifndef NANO_TINY
+#ifdef ENABLE_MULTIBUFFER
 			struct stat lintfileinfo;
 
 		  new_lint_loop:
@@ -3265,7 +3265,7 @@ void do_linter(void)
 						openfile = tmpof;
 				}
 			}
-#endif /* !NANO_TINY */
+#endif /* ENABLE_MULTIBUFFER */
 			goto_line_posx(curlint->lineno, curlint->colno - 1);
 			titlebar(NULL);
 			adjust_viewport(CENTERING);
@@ -3307,7 +3307,7 @@ void do_linter(void)
 
 	wipe_statusbar();
 
-#ifndef NANO_TINY
+#ifdef ENABLE_MULTIBUFFER
   free_lints_and_return:
 #endif
 	for (curlint = lints; curlint != NULL;) {
diff --git a/src/winio.c b/src/winio.c
index 9257fe79..b1488d5b 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1973,6 +1973,7 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata)
 	return converted;
 }
 
+#ifdef ENABLE_MULTIBUFFER
 /* Determine the sequence number of the given buffer in the circular list. */
 int buffer_number(openfilestruct *buffer)
 {
@@ -1985,6 +1986,7 @@ int buffer_number(openfilestruct *buffer)
 
 	return count;
 }
+#endif
 
 /* If path is NULL, we're in normal editing mode, so display the current
  * version of nano, the current filename, and whether the current file
@@ -2030,6 +2032,7 @@ void titlebar(const char *path)
 	else
 #endif
 	if (!inhelp) {
+#ifdef ENABLE_MULTIBUFFER
 		/* If there are/were multiple buffers, show which out of how many. */
 		if (more_than_one) {
 			indicator = charalloc(24);
@@ -2037,6 +2040,7 @@ void titlebar(const char *path)
 										buffer_number(firstfile->prev));
 			upperleft = indicator;
 		} else
+#endif
 			upperleft = BRANDING;
 
 		if (openfile->filename[0] == '\0')
-- 
GitLab