about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTFormat.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>1998-11-10 19:47:00 -0500
committerThomas E. Dickey <dickey@invisible-island.net>1998-11-10 19:47:00 -0500
commitd3f9d5478df478427c2aa5db4507ddd0a38f0eb6 (patch)
treee27eacd6bbda653dd77f11cc020b9e0a59f7f4fc /WWW/Library/Implementation/HTFormat.c
parent18024037b515bfff83e0230b35151babe6005e18 (diff)
downloadlynx-snapshots-d3f9d5478df478427c2aa5db4507ddd0a38f0eb6.tar.gz
snapshot of project "lynx", label v2-8-2dev_2
Diffstat (limited to 'WWW/Library/Implementation/HTFormat.c')
-rw-r--r--WWW/Library/Implementation/HTFormat.c253
1 files changed, 108 insertions, 145 deletions
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index baffca71..bdad295d 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -11,7 +11,6 @@
 */
 
 #include <HTUtils.h>
-#include <tcp.h>
 #include <HTAccess.h>
 
 /* Implements:
@@ -48,13 +47,10 @@ PUBLIC long int HTMaxBytes  = 0;	/* No effective limit */
 
 #include <LYexit.h>
 #include <LYUtils.h>
+#include <GridText.h>
 #include <LYGlobalDefs.h>
 #include <LYLeaks.h>
 
-#define FREE(x) if (x) {free(x); x = NULL;}
-
-extern int HTCheckForInterrupt NOPARAMS;
-
 PUBLIC	BOOL HTOutputSource = NO;	/* Flag: shortcut parser to stdout */
 /* extern  BOOL interactive; LJM */
 
@@ -235,14 +231,11 @@ PUBLIC char HTGetCharacter NOARGS
 		if (status == 0)
 		    return (char)EOF;
 		if (status == HT_INTERRUPTED) {
-		    if (TRACE)
-			fprintf(stderr,
-				"HTFormat: Interrupted in HTGetCharacter\n");
+		    CTRACE(tfp, "HTFormat: Interrupted in HTGetCharacter\n");
 		    interrupted_in_htgetcharacter = 1;
 		    return (char)EOF;
 		}
-		if (TRACE)
-		    fprintf(stderr, "HTFormat: File read error %d\n", status);
+		CTRACE(tfp, "HTFormat: File read error %d\n", status);
 		return (char)EOF; /* -1 is returned by UCX
 				     at end of HTTP link */
 	    }
@@ -266,9 +259,8 @@ PRIVATE int half_match ARGS2(char *,trial_type, char *,target)
     if (!cp || *(cp+1) != '*')
 	return 0;
 
-    if (TRACE)
-	fprintf(stderr,"HTFormat: comparing %s and %s for half match\n",
-						      trial_type, target);
+    CTRACE(tfp, "HTFormat: comparing %s and %s for half match\n",
+		trial_type, target);
 
 	/* main type matches */
     if (!strncmp(trial_type, target, (cp-trial_type)-1))
@@ -295,9 +287,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 {
     HTAtom * wildcard = HTAtom_for("*");
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFormat: Looking up presentation for %s to %s\n",
+    CTRACE(tfp, "HTFormat: Looking up presentation for %s to %s\n",
 		HTAtom_name(rep_in), HTAtom_name(rep_out));
 
     /* don't do anymore do it in the Lynx code at startup LJM */
@@ -316,9 +306,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 	    pres = (HTPresentation *)HTList_objectAt(HTPresentations, i);
 	    if (pres->rep == rep_in) {
 		if (pres->rep_out == rep_out) {
-		    if (TRACE)
-			fprintf(stderr,
-				"FindPresentation: found exact match: %s\n",
+		    CTRACE(tfp, "FindPresentation: found exact match: %s\n",
 				HTAtom_name(pres->rep));
 		    return pres;
 
@@ -328,9 +316,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 		    if (!strong_wildcard_match)
 			strong_wildcard_match = pres;
 		    /* otherwise use the first one */
-		    if (TRACE)
-			fprintf(stderr,
-			     "StreamStack: found strong wildcard match: %s\n",
+		    CTRACE(tfp, "StreamStack: found strong wildcard match: %s\n",
 				HTAtom_name(pres->rep));
 		}
 
@@ -343,9 +329,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 		    if (!strong_subtype_wildcard_match)
 			strong_subtype_wildcard_match = pres;
 		    /* otherwise use the first one */
-		    if (TRACE)
-			fprintf(stderr,
-		     "StreamStack: found strong subtype wildcard match: %s\n",
+		    CTRACE(tfp, "StreamStack: found strong subtype wildcard match: %s\n",
 				HTAtom_name(pres->rep));
 		}
 	    }
@@ -355,9 +339,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 		    if (!weak_wildcard_match)
 			weak_wildcard_match = pres;
 		    /* otherwise use the first one */
-		    if (TRACE)
-			fprintf(stderr,
-			    "StreamStack: found weak wildcard match: %s\n",
+		    CTRACE(tfp, "StreamStack: found weak wildcard match: %s\n",
 				HTAtom_name(pres->rep_out));
 		}
 		if (pres->rep_out == wildcard) {
@@ -403,9 +385,7 @@ PUBLIC HTStream * HTStreamStack ARGS4(
     HTPresentation temp;
     HTPresentation *match;
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFormat: Constructing stream stack for %s to %s\n",
+    CTRACE(tfp, "HTFormat: Constructing stream stack for %s to %s\n",
 		HTAtom_name(rep_in), HTAtom_name(rep_out));
 
     /* don't return on WWW_SOURCE some people might like
@@ -419,13 +399,9 @@ PUBLIC HTStream * HTStreamStack ARGS4(
 
     if ((match = HTFindPresentation(rep_in, rep_out, &temp))) {
 	if (match == &temp) {
-	    if (TRACE)
-		fprintf(stderr,
-			"StreamStack: Using %s\n", HTAtom_name(temp.rep_out));
+	    CTRACE(tfp, "StreamStack: Using %s\n", HTAtom_name(temp.rep_out));
 	} else {
-	    if (TRACE)
-		fprintf(stderr,
-			"StreamStack: found exact match: %s\n",
+	    CTRACE(tfp, "StreamStack: found exact match: %s\n",
 			HTAtom_name(match->rep));
 	}
 	return (*match->converter)(match, anchor, sink);
@@ -466,9 +442,7 @@ PUBLIC float HTStackValue ARGS4(
 {
     HTAtom * wildcard = HTAtom_for("*");
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFormat: Evaluating stream stack for %s worth %.3f to %s\n",
+    CTRACE(tfp, "HTFormat: Evaluating stream stack for %s worth %.3f to %s\n",
 		HTAtom_name(rep_in), initial_value, HTAtom_name(rep_out));
 
     if (rep_out == WWW_SOURCE || rep_out == rep_in)
@@ -498,13 +472,61 @@ PUBLIC float HTStackValue ARGS4(
 
 }
 
+/*	Display the page while transfer in progress
+**	-------------------------------------------
+**
+**   Repaint the page only when necessary.
+**
+*/
+#ifdef DISP_PARTIAL
+PRIVATE void HTDisplayPartial NOARGS
+{
+    if (display_partial) {
+	/*
+	**  HText_getNumOfLines() = "current" number of lines received
+	**  NumOfLines_partial = number of lines at the moment of last repaint.
+	**
+	**  We update NumOfLines_partial only when we repaint the display.
+	**  -1 is the special value:
+	**  This is a synchronization flag switched to 0 when HText_new()
+	**  starts a new HTMainText object - all hypertext functions use it,
+	**  lines counter in particular [we call it from HText_getNumOfLines()].
+	**
+	**  Otherwise HTMainText holds info from the previous document
+	**  and we may repaint it instead of the new one:
+	**  prev doc scrolled to the first line (=Newline_partial)
+	**  is not good looking :-)	  23 Aug 1998 Leonid Pauzner
+	**
+	**  So repaint the page only when necessary:
+	*/
+	if ((NumOfLines_partial != -1)
+		/* new hypertext document available  */
+	&& ((Newline_partial + display_lines) > NumOfLines_partial)
+		/* current page not complete... */
+	&& (partial_threshold > 0 ? ((Newline_partial + partial_threshold)  < HText_getNumOfLines()) : 
+		 ((Newline_partial + display_lines) < HText_getNumOfLines()))) { 
+		/* 
+		 * Originally we rendered by increments of 2 lines, 
+		 * but that got annoying on slow network connections. 
+		 * Then we switched to full-pages.  Now it's configurable. 
+		 * If partial_threshold < 0, then it's a full page 
+		 */
+	    NumOfLines_partial = HText_getNumOfLines();
+	    HText_pageDisplay(Newline_partial, "");
+	}
+    }
+}
+#else
+#define HTDisplayPartial() /*nothing*/
+#endif
+
 /*	Push data from a socket down a stream
 **	-------------------------------------
 **
 **   This routine is responsible for creating and PRESENTING any
 **   graphic (or other) objects described by the file.
 **
-**   The file number given is assumed to be a TELNET stream ie containing
+**   The file number given is assumed to be a TELNET stream, i.e., containing
 **   CRLF at the end of lines which need to be stripped to LF for unix
 **   when the format is textual.
 **
@@ -516,8 +538,7 @@ PUBLIC int HTCopy ARGS4(
 	HTStream*,		sink)
 {
     HTStreamClass targetClass;
-    char line[256];
-    int bytes = 0;
+    int bytes;
     int rv = 0;
 
     /*	Push the data down the stream
@@ -528,6 +549,7 @@ PUBLIC int HTCopy ARGS4(
     **
     **	This operation could be put into a main event loop
     */
+    HTReadProgress(bytes = 0, 0);
     for (;;) {
 	int status;
 
@@ -539,7 +561,7 @@ PUBLIC int HTCopy ARGS4(
 	}
 
 	if (HTCheckForInterrupt()) {
-	    _HTProgress ("Data transfer interrupted.");
+	    _HTProgress (gettext("Data transfer interrupted."));
 	    (*targetClass._abort)(sink, NULL);
 	    if (bytes)
 		rv = HT_INTERRUPTED;
@@ -554,7 +576,7 @@ PUBLIC int HTCopy ARGS4(
 	    if (status == 0) {
 		break;
 	    } else if (status == HT_INTERRUPTED) {
-		_HTProgress ("Data transfer interrupted.");
+		_HTProgress (gettext("Data transfer interrupted."));
 		(*targetClass._abort)(sink, NULL);
 		if (bytes)
 		    rv = HT_INTERRUPTED;
@@ -565,7 +587,7 @@ PUBLIC int HTCopy ARGS4(
 		       SOCKET_ERRNO == ECONNRESET ||
 		       SOCKET_ERRNO == EPIPE) {
 		/*
-		 *  Arrrrgh, HTTP 0/1 compability problem, maybe.
+		 *  Arrrrgh, HTTP 0/1 compatibility problem, maybe.
 		 */
 		if (bytes <= 0) {
 		    /*
@@ -579,8 +601,7 @@ PUBLIC int HTCopy ARGS4(
 		    *  Treat what we've gotten already
 		    *  as the complete transmission. - FM
 		    */
-		   if (TRACE)
-		       fprintf(stderr,
+		   CTRACE(tfp,
 	    "HTCopy: Unexpected server disconnect. Treating as completed.\n");
 		   status = 0;
 		   break;
@@ -599,18 +620,13 @@ PUBLIC int HTCopy ARGS4(
 #endif /* NOT_ASCII */
 
 	(*targetClass.put_block)(sink, input_buffer, status);
-
 	bytes += status;
-	if (anchor && anchor->content_length > 0)
-	    sprintf(line, "Read %d of %d bytes of data.",
-			  bytes, anchor->content_length);
-	else
-	    sprintf(line, "Read %d bytes of data.", bytes);
-	HTProgress(line);
+	HTReadProgress(bytes, anchor ? anchor->content_length : 0);
+	HTDisplayPartial();
 
     } /* next bufferload */
 
-    _HTProgress("Data transfer complete");
+    _HTProgress(gettext("Data transfer complete"));
     (void)NETCLOSE(file_number);
     rv = HT_LOADED;
 
@@ -631,8 +647,7 @@ PUBLIC int HTFileCopy ARGS2(
 	HTStream*,		sink)
 {
     HTStreamClass targetClass;
-    char line[256];
-    int status, bytes = 0, nreads = 0, nprogr = 0;
+    int status, bytes;
     int rv = HT_OK;
 
     /*	Push the data down the stream
@@ -641,17 +656,15 @@ PUBLIC int HTFileCopy ARGS2(
 
     /*	Push binary from socket down sink
     */
+    HTReadProgress(bytes = 0, 0);
     for (;;) {
 	status = fread(input_buffer, 1, INPUT_BUFFER_SIZE, fp);
-	nreads++;
 	if (status == 0) { /* EOF or error */
 	    if (ferror(fp) == 0) {
 		rv = HT_LOADED;
 		break;
 	    }
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFormat: Read error, read returns %d\n",
+	    CTRACE(tfp, "HTFormat: Read error, read returns %d\n",
 			ferror(fp));
 	    if (bytes) {
 		rv = HT_PARTIAL_CONTENT;
@@ -660,41 +673,20 @@ PUBLIC int HTFileCopy ARGS2(
 	    }
 	    break;
 	}
-	(*targetClass.put_block)(sink, input_buffer, status);
 
+	(*targetClass.put_block)(sink, input_buffer, status);
 	bytes += status;
-	if (nreads >= 100) {
-	    /*
-	    **	Show progress messages for local files, and check for
-	    **	user interruption.  Start doing so only after a certain
-	    **	number of reads have been done, and don't update it on
-	    **	every read (normally reading in a local file should be
-	    **	speedy). - KW
-	    */
-	    if (nprogr == 0) {
-		if (bytes < 1024000) {
-		    sprintf(line, "Read %d bytes of data.", bytes);
-		} else {
-		    sprintf(line, "Read %d KB of data. %s",
-				  bytes/1024,
-		    "(Press 'z' if you want to abort loading.)");
-		}
-		HTProgress(line);
-		if (HTCheckForInterrupt()) {
-		    _HTProgress ("Data transfer interrupted.");
-		    if (bytes) {
-			rv = HT_INTERRUPTED;
-		    } else {
-			rv = -1;
-		    }
-		    break;
-		}
-		nprogr++;
-	    } else if (nprogr == 25) {
-		nprogr = 0;
+	HTReadProgress(bytes, 0);
+	HTDisplayPartial();
+
+	if (HTCheckForInterrupt()) {
+	    _HTProgress (gettext("Data transfer interrupted."));
+	    if (bytes) {
+		rv = HT_INTERRUPTED;
 	    } else {
-		nprogr++;
+		rv = -1;
 	    }
+	    break;
 	}
     } /* next bufferload */
 
@@ -715,8 +707,7 @@ PRIVATE int HTGzFileCopy ARGS2(
 	HTStream*,		sink)
 {
     HTStreamClass targetClass;
-    char line[256];
-    int status, bytes = 0, nreads = 0, nprogr = 0;
+    int status, bytes;
     int gzerrnum;
     int rv = HT_OK;
 
@@ -724,23 +715,21 @@ PRIVATE int HTGzFileCopy ARGS2(
     */
     targetClass = *(sink->isa); /* Copy pointers to procedures */
 
-    /*	read and inflate gzipped file, and push binary down sink
+    /*	read and inflate gzip'd file, and push binary down sink
     */
+    HTReadProgress(bytes = 0, 0);
     for (;;) {
 	status = gzread(gzfp, input_buffer, INPUT_BUFFER_SIZE);
-	nreads++;
 	if (status <= 0) { /* EOF or error */
 	    if (status == 0) {
 		rv = HT_LOADED;
 		break;
 	    }
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTGzFileCopy: Read error, gzread returns %d\n",
+	    CTRACE(tfp, "HTGzFileCopy: Read error, gzread returns %d\n",
 			status);
-		fprintf(stderr,
-			"gzerror   : %s\n",
+	    CTRACE(tfp, "gzerror   : %s\n",
 			gzerror(gzfp, &gzerrnum));
+	    if (TRACE) {
 		if (gzerrnum == Z_ERRNO)
 		    perror("gzerror   ");
 	    }
@@ -751,42 +740,20 @@ PRIVATE int HTGzFileCopy ARGS2(
 	    }
 	    break;
 	}
-	(*targetClass.put_block)(sink, input_buffer, status);
 
+	(*targetClass.put_block)(sink, input_buffer, status);
 	bytes += status;
-	if (nreads >= 100) {
-	    /*
-	    **	Show progress messages for local files, and check for
-	    **	user interruption.  Start doing so only after a certain
-	    **	number of reads have been done, and don't update it on
-	    **	every read (normally reading in a local file should be
-	    **	speedy). - KW
-	    */
-	    if (nprogr == 0) {
-		if (bytes < 1024000) {
-		    sprintf(line,
-			    "Read %d uncompressed bytes of data.", bytes);
-		} else {
-		    sprintf(line, "Read %d uncompressed KB of data. %s",
-				  bytes/1024,
-		    "(Press 'z' to abort.)");
-		}
-		HTProgress(line);
-		if (HTCheckForInterrupt()) {
-		    _HTProgress ("Data transfer interrupted.");
-		    if (bytes) {
-			rv = HT_INTERRUPTED;
-		    } else {
-			rv = -1;
-		    }
-		    break;
-		}
-		nprogr++;
-	    } else if (nprogr == 25) {
-		nprogr = 0;
+	HTReadProgress(bytes, -1);
+	HTDisplayPartial();
+
+	if (HTCheckForInterrupt()) {
+	    _HTProgress (gettext("Data transfer interrupted."));
+	    if (bytes) {
+		rv = HT_INTERRUPTED;
 	    } else {
-		nprogr++;
+		rv = -1;
 	    }
+	    break;
 	}
     } /* next bufferload */
 
@@ -860,10 +827,9 @@ PUBLIC int HTParseSocket ARGS5(
 	    LYCancelDownload = FALSE;
 	    return -1;
 	}
-	sprintf(buffer, "Sorry, can't convert from %s to %s.",
+	sprintf(buffer, gettext("Sorry, can't convert from %s to %s."),
 		HTAtom_name(rep_in), HTAtom_name(format_out));
-	if (TRACE)
-	    fprintf(stderr, "HTFormat: %s\n", buffer);
+	CTRACE(tfp, "HTFormat: %s\n", buffer);
 	return HTLoadError(sink, 501, buffer); /* returns -501 */
     }
 
@@ -909,10 +875,9 @@ PUBLIC int HTParseFile ARGS5(
 	    LYCancelDownload = FALSE;
 	    return -1;
 	}
-	sprintf(buffer, "Sorry, can't convert from %s to %s.",
+	sprintf(buffer, gettext("Sorry, can't convert from %s to %s."),
 		HTAtom_name(rep_in), HTAtom_name(format_out));
-	if (TRACE)
-	    fprintf(stderr, "HTFormat(in HTParseFile): %s\n", buffer);
+	CTRACE(tfp, "HTFormat(in HTParseFile): %s\n", buffer);
 	return HTLoadError(sink, 501, buffer);
     }
 
@@ -950,7 +915,7 @@ PRIVATE int HTCloseGzFile ARGS1(
 	if (gzres == Z_ERRNO) {
 	    perror("gzclose   ");
 	} else if (gzres != Z_OK) {
-	    fprintf(stderr, "gzclose   : error number %d\n", gzres);
+	    CTRACE(tfp, "gzclose   : error number %d\n", gzres);
 	}
     }
     return(gzres);
@@ -973,16 +938,14 @@ PUBLIC int HTParseGzFile ARGS5(
 
     if (!stream) {
 	char buffer[1024];	/* @@@@@@@@ */
-	extern char LYCancelDownload;
 	HTCloseGzFile(gzfp);
 	if (LYCancelDownload) {
 	    LYCancelDownload = FALSE;
 	    return -1;
 	}
-	sprintf(buffer, "Sorry, can't convert from %s to %s.",
+	sprintf(buffer, gettext("Sorry, can't convert from %s to %s."),
 		HTAtom_name(rep_in), HTAtom_name(format_out));
-	if (TRACE)
-	    fprintf(stderr, "HTFormat(in HTParseGzFile): %s\n", buffer);
+	CTRACE(tfp, "HTFormat(in HTParseGzFile): %s\n", buffer);
 	return HTLoadError(sink, 501, buffer);
     }