Index: configure.in
===================================================================
RCS file: /cvs/gnome/vte/configure.in,v
retrieving revision 1.192
diff -u -p -r1.192 configure.in
--- configure.in	24 Aug 2006 20:40:52 -0000	1.192
+++ configure.in	3 Sep 2006 01:13:16 -0000
@@ -265,6 +265,9 @@ if test x$have_recvmsg = x1 ; then
 fi
 AC_CHECK_FUNC(floor,,AC_CHECK_LIB(m,floor,LIBS=["$LIBS -lm"]))
 
+AC_CHECK_FUNC(getline,
+	AC_DEFINE(HAVE_GETLINE,1,[Define if you have the getline function.]))
+
 # Look for ncurses or curses or termcap.
 AC_CHECK_HEADER(ncurses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES,1,[Define if you have ncurses.h and libncurses])])])])
 if test x$ac_cv_lib_ncurses_tgetent != xyes ; then
Index: src/vtetc.c
===================================================================
RCS file: /cvs/gnome/vte/src/vtetc.c,v
retrieving revision 1.10
diff -u -p -r1.10 vtetc.c
--- src/vtetc.c	31 Aug 2006 20:03:12 -0000	1.10
+++ src/vtetc.c	3 Sep 2006 01:13:16 -0000
@@ -58,78 +58,55 @@ static GCache *_vte_termcap_cache = NULL
 static char *
 nextline(FILE *fp, gssize *outlen)
 {
+#ifdef HAVE_GETLINE
+	char *line=malloc(LINE_MAX);
+	size_t llen=LINE_MAX;
+#else
 	char buf[LINE_MAX];
+#endif
 	gssize len = 0;
 	char *ret = NULL;
 	gssize retlen = 0;
-	char *tmp = NULL;
 
+next_line:
+#ifdef HAVE_GETLINE
+	if ((len=getline(&line, &llen, fp)) != -1) {
+		ret = g_realloc(ret, retlen + len + 1);
+		memcpy(ret + retlen, line, len);
+		retlen += len;
+	}
+#else
 	if (!feof(fp)) do {
 		if (fgets(buf, sizeof(buf), fp) != buf) {
 			break;
 		}
 		len = strlen(buf);
-		tmp = g_malloc(retlen + len + 1);
-		if (retlen > 0) {
-			memcpy(tmp, ret, retlen);
-		}
-		memcpy(tmp + retlen, buf, len + 1);
-		if (ret != NULL) {
-			g_free(ret);
-		}
+		ret = g_realloc(ret, retlen + len + 1);
+		memcpy(ret + retlen, buf, len + 1);
 		retlen += len;
-		ret = tmp;
-		ret[retlen] = '\0';
 	} while ((len > 0) && (buf[retlen - 1] != '\n') && !feof(fp));
+#endif
 
-	if ((ret != NULL) && (retlen > 0) && (ret[retlen - 1] == '\n')) {
-		retlen--;
+	if (ret != NULL) {
+		if (retlen > 0 && ret[retlen - 1] == '\n')
+			retlen--;
+		if (retlen > 0 && ret[retlen - 1] == '\r')
+			retlen--;
+		if (retlen > 0 && ret[retlen - 1] == '\\') {
+			retlen--;
+			if (!feof (fp)) goto next_line;
+		}
 		ret[retlen] = '\0';
 	}
 
-	if ((ret != NULL) && (retlen > 0) && (ret[retlen - 1] == '\r')) {
-		retlen--;
-		ret[retlen] = '\0';
-	}
+#ifdef HAVE_GETLINE
+	free(line);
+#endif
 
 	*outlen = retlen;
 	return ret;
 }
 
-static char *
-nextline_with_continuation(FILE *fp)
-{
-	char *ret = NULL;
-	gssize rlen = 0, slen = 0;
-	char *s, *tmp;
-	gboolean continuation = FALSE;
-	do {
-		s = nextline(fp, &slen);
-		if (s == NULL) {
-			break;
-		}
-		tmp = g_malloc(slen + rlen + 1);
-		if (rlen > 0) {
-			memcpy(tmp, ret, rlen);
-		}
-		memcpy(tmp + rlen, s, slen + 1);
-		if (ret != NULL) {
-			g_free(ret);
-		}
-		g_free(s);
-		ret = tmp;
-		rlen += slen;
-		if ((rlen > 0) && (ret[rlen - 1] == '\\')) {
-			ret[rlen - 1] = '\0';
-			rlen--;
-			continuation = TRUE;
-		} else {
-			continuation = FALSE;
-		}
-	} while ((rlen == 0) || continuation);
-	return ret;
-}
-
 static void
 _vte_termcap_add_aliases(struct _vte_termcap *termcap,
 			 struct _vte_termcap_entry *entry,
@@ -201,11 +178,13 @@ _vte_termcap_add_entry(struct _vte_termc
 }
 
 static void
-_vte_termcap_strip_with_pad(const char *termcap, char **stripped, gssize *len)
+_vte_termcap_strip_with_pad(const char *termcap, gssize length, char **stripped, gssize *len)
 {
 	char *ret;
-	gssize i, o, length;
-	length = strlen(termcap);
+	gssize i, o;
+
+	if (length<0)
+		length = strlen(termcap);
 
 	ret = g_malloc(length + 2);
 	for (i = o = 0; i < length; i++) {
@@ -318,7 +297,7 @@ _vte_termcap_strip_with_pad(const char *
 void
 _vte_termcap_strip(const char *termcap, char **stripped, gssize *len)
 {
-	_vte_termcap_strip_with_pad(termcap, stripped, len);
+	_vte_termcap_strip_with_pad(termcap, -1, stripped, len);
 	while (((*len) > 0) && ((*stripped)[(*len) - 1] == ':')) {
 		(*len)--;
 		(*stripped)[*len] = '\0';
@@ -339,6 +318,7 @@ _vte_termcap_create(gpointer key)
 	struct _vte_termcap *ret = NULL;
 	FILE *fp;
 	char *s, *stripped, *comment = NULL;
+	gssize clen=0;
 
 #ifdef VTE_DEBUG
 	if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
@@ -347,42 +327,35 @@ _vte_termcap_create(gpointer key)
 #endif
 	fp = fopen(filename, "r");
 	if (fp != NULL) {
-		while ((s = nextline_with_continuation(fp)) != NULL) {
-			gssize slen;
+		gssize slen;
+		while ((s = nextline(fp, &slen)) != NULL) {
 			if ((s[0] != '#') && (isprint(s[0]))) {
 				if (ret == NULL) {
 					ret = g_slice_new0(struct _vte_termcap);
 					ret->nametree = g_tree_new(_vte_direct_compare);
 				}
 				stripped = NULL;
-				_vte_termcap_strip_with_pad(s, &stripped, &slen);
+				_vte_termcap_strip_with_pad(s, slen, &stripped, &slen);
 				if (stripped) {
 					_vte_termcap_add_entry(ret, stripped,
 							       slen, comment);
 					comment = NULL;
+					clen = 0;
 					g_free(stripped);
 				}
 			} else {
-				slen = strlen(s);
 				if (comment == NULL) {
 					comment = g_malloc(slen + 2);
 					memcpy(comment, s, slen);
 					comment[slen] = '\n';
 					comment[slen + 1] = '\0';
+					clen = slen+ 1;
 				} else {
-					char *tmp;
-					gssize clen;
-					clen = strlen(comment);
-					tmp = g_malloc(slen + clen + 2);
-					if (tmp == NULL) {
-						return NULL;
-					}
-					memcpy(tmp, comment, clen);
-					memcpy(tmp + clen, s, slen);
-					tmp[clen + slen] = '\n';
-					tmp[clen + slen + 1] = '\0';
-					g_free(comment);
-					comment = tmp;
+					comment = g_realloc(comment, slen + clen + 2);
+					memcpy(comment + clen, s, slen);
+					comment[clen + slen] = '\n';
+					comment[clen + slen + 1] = '\0';
+					clen += slen + 1;
 				}
 			}
 			g_free(s);
