Fix regression parsing gcc preprocessor linemarkers

These are preprocessor statement in the form:

 # linenum filename flags

Closes #1475
diff --git a/CHANGES.current b/CHANGES.current
index 6d7b0ca..2d26fc4 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,11 @@
 Version 4.0.0 (in progress)
 ===========================
 
+2019-02-19: wsfulton
+            #1475 Fix regression parsing gcc preprocessor linemarkers in the form:
+
+            # linenum filename flags 
+
 2019-02-18: jakecobb
             [Python] #945 #1234 Elements in std::vector memory access fix.
 
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 5a72ba7..3d4edd4 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -707,6 +707,7 @@
 	preproc \
 	preproc_constants_c \
 	preproc_defined \
+	preproc_gcc_output \
 	preproc_include \
 	preproc_line_file \
 	register_par \
diff --git a/Examples/test-suite/errors/pp_unknowndirective3.i b/Examples/test-suite/errors/pp_unknowndirective3.i
new file mode 100644
index 0000000..77dfd5b
--- /dev/null
+++ b/Examples/test-suite/errors/pp_unknowndirective3.i
@@ -0,0 +1,14 @@
+%module xxx
+
+// Testing is_digits detecting gcc linemarkers
+
+// These are valid
+# 1 "/usr/include/stdc-predef.h" 1 3 4
+# 123 "header1.h"
+
+// These are invalid
+#a1 'a.h'
+#1b 'b.h'
+#1c1 'c.h'
+#d1d 'd.h'
+
diff --git a/Examples/test-suite/errors/pp_unknowndirective3.stderr b/Examples/test-suite/errors/pp_unknowndirective3.stderr
new file mode 100644
index 0000000..35bff8a
--- /dev/null
+++ b/Examples/test-suite/errors/pp_unknowndirective3.stderr
@@ -0,0 +1,4 @@
+pp_unknowndirective3.i:10: Error: Unknown SWIG preprocessor directive: a1 (if this is a block of target language code, delimit it with %{ and %})
+pp_unknowndirective3.i:11: Error: Unknown SWIG preprocessor directive: 1b (if this is a block of target language code, delimit it with %{ and %})
+pp_unknowndirective3.i:12: Error: Unknown SWIG preprocessor directive: 1c1 (if this is a block of target language code, delimit it with %{ and %})
+pp_unknowndirective3.i:13: Error: Unknown SWIG preprocessor directive: d1d (if this is a block of target language code, delimit it with %{ and %})
diff --git a/Examples/test-suite/preproc_gcc_output.h b/Examples/test-suite/preproc_gcc_output.h
new file mode 100644
index 0000000..cc5065d
--- /dev/null
+++ b/Examples/test-suite/preproc_gcc_output.h
@@ -0,0 +1,13 @@
+# 1 "header1.h"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "/usr/include/stdc-predef.h" 1 3 4
+# 1 "<command-line>" 2
+# 1 "header1.h"
+# 18 "header1.h"
+void header1_function_a(int a);
+# 1 "header2.h" 1
+# 13 "header2.h"
+void header2_function(int x);
+# 20 "header1.h" 2
+void header1_function_b(int b);
diff --git a/Examples/test-suite/preproc_gcc_output.i b/Examples/test-suite/preproc_gcc_output.i
new file mode 100644
index 0000000..b4db9e7
--- /dev/null
+++ b/Examples/test-suite/preproc_gcc_output.i
@@ -0,0 +1,12 @@
+%module preproc_gcc_output
+// Testcase for Github issue #1475 using the output of gcc -E
+
+// The file below was generated using 'gcc -E header1.h'
+// where header1.h included header2.h
+%include "preproc_gcc_output.h"
+
+%{
+void header1_function_a(int a) {}
+void header2_function(int x) {}
+void header1_function_b(int b) {}
+%}
diff --git a/Examples/test-suite/python/preproc_gcc_output_runme.py b/Examples/test-suite/python/preproc_gcc_output_runme.py
new file mode 100644
index 0000000..66ff7d2
--- /dev/null
+++ b/Examples/test-suite/python/preproc_gcc_output_runme.py
@@ -0,0 +1,5 @@
+import preproc_gcc_output
+
+preproc_gcc_output.header1_function_a(99)
+preproc_gcc_output.header1_function_b(99)
+preproc_gcc_output.header2_function(99)
diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c
index af17750..557b548 100644
--- a/Source/Preprocessor/cpp.c
+++ b/Source/Preprocessor/cpp.c
@@ -109,6 +109,19 @@
   return s;
 }
 
+static int is_digits(const String *str) {
+  const char *s = Char(str);
+  int isdigits = (*s != 0);
+  while (*s) {
+    if (!isdigit(*s)) {
+      isdigits = 0;
+      break;
+    }
+    s++;
+  }
+  return isdigits;
+}
+
 List *Preprocessor_depend(void) {
   return dependencies;
 }
@@ -1484,7 +1497,7 @@
       Putc(c, id);
       break;
 
-    case 42:			/* Strip any leading space before preprocessor value */
+    case 42:			/* Strip any leading space after the preprocessor directive (before preprocessor value) */
       if (isspace(c)) {
 	if (c == '\n') {
 	  Ungetc(c, s);
@@ -1804,6 +1817,8 @@
 	Swig_error(Getfile(s), Getline(id), "cpp debug: level = %d, startlevel = %d\n", level, start_level);
       } else if (Equal(id, "")) {
 	/* Null directive */
+      } else if (is_digits(id)) {
+	/* A gcc linemarker of the form '# linenum filename flags' (resulting from running gcc -E) */
       } else {
 	/* Ignore unknown preprocessor directives which are inside an inactive
 	 * conditional (github issue #394). */