summaryrefslogtreecommitdiff
path: root/render/textplain.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-11-22 00:33:04 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-11-22 00:33:04 +0000
commit1105d9c39741f0429dc5f5549b12ab351bcf94b3 (patch)
tree022bd4d3028a93a2c23b34d2a2616a88d5aaea46 /render/textplain.c
parentdfad215d1b5fffdb8b8cbeee02f176f7a28f0d65 (diff)
downloadnetsurf-1105d9c39741f0429dc5f5549b12ab351bcf94b3.tar.gz
netsurf-1105d9c39741f0429dc5f5549b12ab351bcf94b3.tar.bz2
[project @ 2004-11-22 00:33:04 by jmb]
Improve plain text rendering (converts occurrences of '<' with '&lt;') svn path=/import/netsurf/; revision=1369
Diffstat (limited to 'render/textplain.c')
-rw-r--r--render/textplain.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/render/textplain.c b/render/textplain.c
index 0a7f5db7c..4b08e0acc 100644
--- a/render/textplain.c
+++ b/render/textplain.c
@@ -9,6 +9,7 @@
#include "netsurf/content/content.h"
#include "netsurf/render/html.h"
#include "netsurf/render/textplain.h"
+#include "netsurf/utils/messages.h"
static const char header[] = "<html><body><pre>";
@@ -25,6 +26,52 @@ bool textplain_create(struct content *c, const char *params[])
return true;
}
+bool textplain_process_data(struct content *c, char *data,
+ unsigned int size)
+{
+ unsigned int i, s;
+ char *d, *p;
+ union content_msg_data msg_data;
+ bool ret;
+
+ /* count number of '<' in data buffer */
+ for (d = data, i = 0, s = 0; i != size; i++, d++) {
+ if (*d == '<')
+ s++;
+ }
+
+ /* create buffer for modified input */
+ d = calloc(size + 3*s, sizeof(char));
+ if (!d) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+
+ /* copy data across to modified buffer,
+ * replacing occurrences of '<' with '&lt;'
+ * This prevents the parser stripping sequences of '<...>'
+ */
+ for (p = d, i = 0, s = 0; i != size; i++, data++) {
+ if (*data == '<') {
+ *p++ = '&';
+ *p++ = 'l';
+ *p++ = 't';
+ *p++ = ';';
+ s += 4;
+ }
+ else {
+ *p++ = *data;
+ s++;
+ }
+ }
+
+ ret = html_process_data(c, d, s);
+
+ free(d);
+
+ return ret;
+}
bool textplain_convert(struct content *c, int width, int height)
{