# Patch #5 for c3270 3.2.18.
# Fixes problems with parsing profile files, where line continuations were
# being accepted for comment lines, and (illegal) comment lines starting with
# '#' characters and line continuations would cause an infinite loop.

--- c3270-3.2/glue.c	2002/01/05 04:38:03	1.51
+++ c3270-3.2/glue.c	2002/01/23 15:44:46
@@ -813,6 +813,23 @@
 		}
 		*t = '\0';
 
+		/* Skip leading whitespace. */
+		s = buf;
+		while (isspace(*s))
+			s++;
+
+		/* Skip comments _before_ checking for line continuation. */
+		if (*s == '!') {
+		    ilen = 0;
+		    continue;
+		}
+		if (*s == '#') {
+			(void) sprintf(where, "%s:%d: Invalid profile "
+			    "syntax ('#' ignored)", filename, lno);
+			Warning(where);
+			ilen = 0;
+			continue;
+		}
 
 		/* If this line is a continuation, try again. */
 		if (bsl) {
@@ -826,20 +843,16 @@
 			continue;
 		}
 
-		s = buf;
-		while (isspace(*s))
-			s++;
+		/* Strip trailing whitespace and check for empty lines. */
 		sl = strlen(s);
 		while (sl && isspace(s[sl-1]))
 			s[--sl] = '\0';
-		if (!sl || *s == '!')
-			continue;
-		if (*s == '#') {
-			(void) sprintf(where, "%s:%d: Invalid profile "
-			    "syntax ('#' ignored)", filename, lno);
-			Warning(where);
+		if (!sl) {
+			ilen = 0;
 			continue;
 		}
+
+		/* Digest it. */
 		(void) sprintf(where, "%s:%d", filename, lno);
 		parse_xrm(s, where);
 
