From bf1346f3429ec00c552bb46753b3602d23e9acd7 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Fri, 22 Oct 2004 20:25:56 +0000
Subject: [PATCH] in main(), tweak the command line parsing routine so that
 multiple +LINE flags are properly interpreted in multibuffer mode

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2014 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog  |  3 +++
 src/nano.c | 31 ++++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7e03e593..a0fea0f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -163,6 +163,9 @@ CVS code -
 	- Make goal a ssize_t instead of an int, since fill is now a
 	  ssize_t, and the position at which a line is broken can be
 	  greater than COLS. (DLR)
+  main()
+	- Tweak the command line parsing routine so that multiple +LINE
+	  flags are properly interpreted in multibuffer mode. (DLR)
 - nano.h:
 	- Add WIDTH_OF_TAB #define, containing the default width of a
 	  tab. (DLR)
diff --git a/src/nano.c b/src/nano.c
index f8d0f5b2..77a74747 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -3415,12 +3415,6 @@ int main(int argc, char **argv)
     if (tabsize == -1)
 	tabsize = WIDTH_OF_TAB;
 
-    /* If there's a +LINE flag, it is the first non-option argument. */
-    if (0 < optind && optind < argc && argv[optind][0] == '+') {
-	startline = atoi(&argv[optind][1]);
-	optind++;
-    }
-
     /* Back up the old terminal settings so that they can be restored. */
     tcgetattr(0, &oldterm);
 
@@ -3449,6 +3443,14 @@ int main(int argc, char **argv)
     fprintf(stderr, "Main: open file\n");
 #endif
 
+    /* If there's a +LINE flag here, it is the first non-option
+     * argument, and it is followed by at least one other argument, the
+     * filename it applies to. */
+    if (0 < optind && optind < argc - 1 && argv[optind][0] == '+') {
+	startline = atoi(&argv[optind][1]);
+	optind++;
+    }
+
 #ifdef ENABLE_MULTIBUFFER
     old_multibuffer = ISSET(MULTIBUFFER);
     SET(MULTIBUFFER);
@@ -3456,9 +3458,20 @@ int main(int argc, char **argv)
     /* Read all the files after the first one on the command line into
      * new buffers. */
     {
-	int i;
-	for (i = optind + 1; i < argc; i++)
-	    load_buffer(argv[i]);
+	int i = optind + 1, iline = 0;
+	for (; i < argc; i++) {
+	    /* If there's a +LINE flag here, it is followed by at least
+	     * one other argument, the filename it applies to. */
+	    if (i < argc - 1 && argv[i][0] == '+' && iline == 0) {
+		iline = atoi(&argv[i][1]);
+	    } else {
+		load_buffer(argv[i]);
+		if (iline > 0) {
+		    do_gotoline(iline, FALSE);
+		    iline = 0;
+		}
+	    }
+	}
     }
 #endif
 
-- 
GitLab