mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-28 23:09:43 +03:00
[project @ 2004-05-22 13:45:20 by joty]
Renamed "this" variable (avoiding C++ keywords); simplified code a little bit. svn path=/import/netsurf/; revision=886
This commit is contained in:
parent
9644508737
commit
d36e4314be
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
||||||
* Licensed under the GNU General Public License,
|
* Licensed under the GNU General Public License,
|
||||||
* http://www.opensource.org/licenses/gpl-license
|
* http://www.opensource.org/licenses/gpl-license
|
||||||
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -25,21 +25,21 @@ static FILE *out;
|
|||||||
|
|
||||||
void save_as_text(struct content *c, char *path) {
|
void save_as_text(struct content *c, char *path) {
|
||||||
|
|
||||||
htmlParserCtxtPtr toSave;
|
htmlParserCtxtPtr toSave;
|
||||||
|
|
||||||
if (c->type != CONTENT_HTML) {
|
if (c->type != CONTENT_HTML) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(path, "w");
|
out = fopen(path, "w");
|
||||||
if (!out) return;
|
if (!out) return;
|
||||||
|
|
||||||
toSave = htmlCreateMemoryParserCtxt(c->source_data, c->source_size);
|
toSave = htmlCreateMemoryParserCtxt(c->source_data, c->source_size);
|
||||||
htmlParseDocument(toSave);
|
htmlParseDocument(toSave);
|
||||||
|
|
||||||
extract_text(toSave->myDoc);
|
extract_text(toSave->myDoc);
|
||||||
|
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
|
||||||
xmlFreeDoc(toSave->myDoc);
|
xmlFreeDoc(toSave->myDoc);
|
||||||
htmlFreeParserCtxt(toSave);
|
htmlFreeParserCtxt(toSave);
|
||||||
@ -47,71 +47,69 @@ void save_as_text(struct content *c, char *path) {
|
|||||||
|
|
||||||
void extract_text(xmlDoc *doc)
|
void extract_text(xmlDoc *doc)
|
||||||
{
|
{
|
||||||
xmlNode *html;
|
xmlNode *html;
|
||||||
|
|
||||||
/* find the html element */
|
/* find the html element */
|
||||||
for (html = doc->children;
|
for (html = doc->children;
|
||||||
html!=0 && html->type != XML_ELEMENT_NODE;
|
html!=0 && html->type != XML_ELEMENT_NODE;
|
||||||
html = html->next)
|
html = html->next)
|
||||||
;
|
;
|
||||||
if (html == 0 || strcmp((const char*)html->name, "html") != 0) {
|
if (html == 0 || strcmp((const char*)html->name, "html") != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_text_from_tree(html);
|
extract_text_from_tree(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extract_text_from_tree(xmlNode *n)
|
void extract_text_from_tree(xmlNode *n)
|
||||||
{
|
{
|
||||||
xmlNode *this;
|
xmlNode *this_node;
|
||||||
char *text;
|
const char *text;
|
||||||
int len, need_nl = 0;
|
int need_nl = 0;
|
||||||
|
|
||||||
if (n->type == XML_ELEMENT_NODE) {
|
if (n->type == XML_ELEMENT_NODE) {
|
||||||
if (strcmp(n->name, "dl") == 0 ||
|
if (strcmp(n->name, "dl") == 0 ||
|
||||||
strcmp(n->name, "h1") == 0 ||
|
strcmp(n->name, "h1") == 0 ||
|
||||||
strcmp(n->name, "h2") == 0 ||
|
strcmp(n->name, "h2") == 0 ||
|
||||||
strcmp(n->name, "h3") == 0 ||
|
strcmp(n->name, "h3") == 0 ||
|
||||||
strcmp(n->name, "ol") == 0 ||
|
strcmp(n->name, "ol") == 0 ||
|
||||||
strcmp(n->name, "title") == 0 ||
|
strcmp(n->name, "title") == 0 ||
|
||||||
strcmp(n->name, "ul") == 0) {
|
strcmp(n->name, "ul") == 0) {
|
||||||
need_nl = 2;
|
need_nl = 2;
|
||||||
}
|
}
|
||||||
else if (strcmp(n->name, "applet") == 0 ||
|
else if (strcmp(n->name, "applet") == 0 ||
|
||||||
strcmp(n->name, "br") == 0 ||
|
strcmp(n->name, "br") == 0 ||
|
||||||
strcmp(n->name, "div") == 0 ||
|
strcmp(n->name, "div") == 0 ||
|
||||||
strcmp(n->name, "dt") == 0 ||
|
strcmp(n->name, "dt") == 0 ||
|
||||||
strcmp(n->name, "h4") == 0 ||
|
strcmp(n->name, "h4") == 0 ||
|
||||||
strcmp(n->name, "h5") == 0 ||
|
strcmp(n->name, "h5") == 0 ||
|
||||||
strcmp(n->name, "h6") == 0 ||
|
strcmp(n->name, "h6") == 0 ||
|
||||||
strcmp(n->name, "li") == 0 ||
|
strcmp(n->name, "li") == 0 ||
|
||||||
strcmp(n->name, "object") == 0 ||
|
strcmp(n->name, "object") == 0 ||
|
||||||
strcmp(n->name, "p") == 0 ||
|
strcmp(n->name, "p") == 0 ||
|
||||||
strcmp(n->name, "tr") == 0) {
|
strcmp(n->name, "tr") == 0) {
|
||||||
need_nl = 1;
|
need_nl = 1;
|
||||||
}
|
}
|
||||||
/* do nothing, we just recurse through these nodes */
|
/* do nothing, we just recurse through these nodes */
|
||||||
}
|
}
|
||||||
else if (n->type == XML_TEXT_NODE) {
|
else if (n->type == XML_TEXT_NODE) {
|
||||||
text = squash_tolat1(n->content);
|
if ((text = squash_tolat1(n->content)) != NULL) {
|
||||||
fprintf(out, "%s", text);
|
fputs(text, out);
|
||||||
xfree(text);
|
free(text);
|
||||||
return;
|
}
|
||||||
}
|
return;
|
||||||
else {
|
}
|
||||||
return;
|
else {
|
||||||
}
|
return;
|
||||||
|
|
||||||
/* now recurse */
|
|
||||||
for (this = n->children; this != 0; this = this->next) {
|
|
||||||
extract_text_from_tree(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (need_nl) {
|
/* now recurse */
|
||||||
for (len = 0; len != need_nl; len++) {
|
for (this_node = n->children; this_node != 0; this_node = this_node->next) {
|
||||||
fprintf(out, "\n");
|
extract_text_from_tree(this_node);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (need_nl--)
|
||||||
|
fputc('\n', out);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user