From 7c27be42d0dd4f5ebfbbb0a3965327fb68404f89 Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Sun, 5 May 2002 23:03:54 +0000
Subject: [PATCH] added an update_color, updated edit_add, i18ned a string and
 changed some getopt handlers in main to mallocstrcpy

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1203 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog |  8 +++++++-
 files.c   |  4 ++++
 global.c  |  2 +-
 nano.c    |  6 ++----
 winio.c   | 28 ++++++++++++++++++++++------
 5 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2a70b9ce..9c85d466 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,7 +24,6 @@ CVS code -
 	  syntaxfile_regexp and synfilematches.  Global flag -Y ,--syntax
 	  to specify the type on the command line, if there's no good 
 	  filename regex to use.  Global variable syntaxstr.
-	- Made some rc file errors less fatal.
 - configure.ac:
 	- Define NDEBUG to silence asserts (David Benbennick).
 - files.c:
@@ -40,6 +39,8 @@ CVS code -
 	- Optimizations (David Benbennick).
   do_wrap()
 	- Complete rewrite (David Benbennick).
+  main()
+	- Changed charalloc(), strcpy()s to mallocstrcpy()s.
 - nano.h:
 	- NANO_ALT_COMMAND and NANO_ALT_PERIOD were reversed (lol)
 	  (David Benbennick).
@@ -48,6 +49,11 @@ CVS code -
 	  by default (Im an idiot).
 - nano.1:
 	- Changed references to Debian GNU/Linux to Debian GNU (Jordi).
+- rcfile.c
+	- Made some rc file errors less fatal.
+- winio.c:
+  edit_add()
+	- Changed some syntax hilight computations for the sake of COLS.
 - po/gl.po:
 	- Galician translation updates (Jacobo Tarrio).
 - po/de.po:
diff --git a/files.c b/files.c
index 9f864c87..9e52548c 100644
--- a/files.c
+++ b/files.c
@@ -102,6 +102,10 @@ void new_file(void)
     UNSET(VIEW_MODE);
 #endif
 
+#ifdef ENABLE_COLOR
+    update_color();
+#endif
+
 }
 
 filestruct *read_line(char *buf, filestruct * prev, int *line1ins)
diff --git a/global.c b/global.c
index b64f67a5..b32990fb 100644
--- a/global.c
+++ b/global.c
@@ -87,7 +87,7 @@ char *full_operating_dir = NULL;/* go higher than */
 #endif
 
 #ifndef DISABLE_SPELLER
-char *alt_speller;		/* Alternative spell command */
+char *alt_speller = NULL;		/* Alternative spell command */
 #endif
 
 shortcut *main_list = NULL;
diff --git a/nano.c b/nano.c
index de74b842..73bf5f60 100644
--- a/nano.c
+++ b/nano.c
@@ -2959,8 +2959,7 @@ int main(int argc, char *argv[])
 	    break;
 #ifndef DISABLE_OPERATINGDIR
 	case 'o':
-	    operating_dir = charalloc(strlen(optarg) + 1);
-	    strcpy(operating_dir, optarg);
+	    operating_dir = mallocstrcpy(operating_dir, optarg);
 
 	    /* make sure we're inside the operating directory */
 	    if (check_operating_dir(".", 0)) {
@@ -2991,8 +2990,7 @@ int main(int argc, char *argv[])
 #endif
 #ifndef DISABLE_SPELLER
 	case 's':
-	    alt_speller = charalloc(strlen(optarg) + 1);
-	    strcpy(alt_speller, optarg);
+	    alt_speller = mallocstrcpy(alt_speller, optarg);
 	    break;
 #endif
 	case 't':
diff --git a/winio.c b/winio.c
index 796f4b2b..6883d23c 100644
--- a/winio.c
+++ b/winio.c
@@ -803,7 +803,7 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 				colormatches, 0)) {
 
 		    if (colormatches[0].rm_eo - colormatches[0].rm_so < 1) {
-			statusbar("Refusing 0 length regex match");
+			statusbar(_("Refusing 0 length regex match"));
 			break;
 		    }
 #ifdef DEBUG
@@ -816,11 +816,22 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 			    wattron(edit, A_BOLD);
 			wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
 
-			if (colormatches[0].rm_eo + k <= COLS)
+			if (colormatches[0].rm_eo + k <= COLS) {
 			    paintlen =
 				colormatches[0].rm_eo - colormatches[0].rm_so;
-			else
+#ifdef DEBUG
+			    fprintf(stderr, "paintlen (%d) = eo (%d) - so (%d)\n", 
+				paintlen, colormatches[0].rm_eo, colormatches[0].rm_so);
+#endif
+
+			}
+			else {
 			    paintlen = COLS - k - colormatches[0].rm_so - 1;
+#ifdef DEBUG
+			    fprintf(stderr, "paintlen (%d) = COLS (%d) - k (%d), - rm.so (%d) - 1\n", 
+					paintlen, COLS, k, colormatches[0].rm_so);
+#endif
+			}
 
 			mvwaddnstr(edit, yval, colormatches[0].rm_so + k,
 				   &fileptr->data[k + colormatches[0].rm_so],
@@ -902,18 +913,23 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 
 			    wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
 
-			    if (s == fileptr && e == fileptr)
+			    if (s == fileptr && e == fileptr && ematch < COLS) {
 				mvwaddnstr(edit, yval, start + smatch, 
 					&fileptr->data[start + smatch],
 					ematch - smatch);
-		    	    else if (s == fileptr)
+#ifdef DEBUG
+			fprintf(stderr, "start = %d, smatch = %d, ematch = %d\n", start,
+				smatch, ematch);
+#endif
+
+		    	    } else if (s == fileptr)
 				mvwaddnstr(edit, yval, start + smatch, 
 					&fileptr->data[start + smatch],
 					COLS - smatch);
 			    else if (e == fileptr)
 				mvwaddnstr(edit, yval, start, 
 					&fileptr->data[start],
-					ematch - start);
+					COLS - start);
 			    else
 				mvwaddnstr(edit, yval, start, 
 					&fileptr->data[start],
-- 
GitLab