зеркало из https://github.com/mozilla/gecko-dev.git
Remove some files from CVS
(the old xml parser was confusing a lot of people even though it wasn't being used.)
This commit is contained in:
Родитель
02ffa1d129
Коммит
7a3b2ad305
|
@ -31,7 +31,6 @@
|
|||
#include "glue.h"
|
||||
#include "remstore.h"
|
||||
#include "rdfparse.h"
|
||||
#include "xmlglue.h"
|
||||
#include "es2mcf.h"
|
||||
#include "mcff2mcf.h"
|
||||
#include "nlcstore.h"
|
||||
|
|
|
@ -1,308 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is some glue code for a "stop-gap" xml parser that is being shipped with the free
|
||||
source. A real xml parser from James Clark will replace this
|
||||
within the next few weeks.
|
||||
|
||||
For more information on this file, contact rjc or guha
|
||||
For more information on RDF, look at the RDF section of www.mozilla.org
|
||||
For more info on XML in navigator, look at the XML section
|
||||
of www.mozilla.org.
|
||||
*/
|
||||
|
||||
#include "xmlglue.h"
|
||||
#include "xmlparse.h"
|
||||
#include "xmlss.h"
|
||||
|
||||
|
||||
|
||||
unsigned int
|
||||
xml_write_ready(NET_StreamClass *stream)
|
||||
{
|
||||
return XML_LINE_SIZE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xml_abort(NET_StreamClass *stream, int status)
|
||||
{
|
||||
void *obj=stream->data_object;
|
||||
freeMem(((XMLFile)obj)->holdOver);
|
||||
freeMem(((XMLFile)obj)->line);
|
||||
((XMLFile)obj)->line = ((XMLFile)obj)->holdOver = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xml_complete (NET_StreamClass *stream)
|
||||
{
|
||||
NET_StreamClass *newstream;
|
||||
void *obj=stream->data_object;
|
||||
URL_Struct *urls = ((XMLFile)obj)->urls;
|
||||
freeMem(((XMLFile)obj)->holdOver);
|
||||
freeMem(((XMLFile)obj)->line);
|
||||
((XMLFile)obj)->line = ((XMLFile)obj)->holdOver = NULL;
|
||||
((XMLFile)obj)->numOpenStreams--;
|
||||
if (((XMLFile)obj)->numOpenStreams < 1) {
|
||||
/* direct the stream to the html parser */
|
||||
URL_Struct *nurls = NET_CreateURLStruct(copyString(urls->address), NET_DONT_RELOAD);
|
||||
StrAllocCopy(nurls->content_type, TEXT_HTML);
|
||||
|
||||
newstream = NET_StreamBuilder(1, nurls, (MWContext*) ((XMLFile)obj)->mwcontext);
|
||||
((XMLFile)obj)->stream = newstream;
|
||||
convertToHTML(((XMLFile)obj));
|
||||
newstream->complete(newstream);
|
||||
NET_FreeURLStruct(nurls);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
outputToStream (XMLFile f, char* s)
|
||||
{
|
||||
int ans = 0;
|
||||
NET_StreamClass *stream = (NET_StreamClass*) f->stream;
|
||||
#ifdef DEBUG
|
||||
/* FE_Trace(s); */
|
||||
#endif
|
||||
(*(stream->put_block))(stream, s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
PR_PUBLIC_API(NET_StreamClass *)
|
||||
#else
|
||||
PUBLIC NET_StreamClass *
|
||||
#endif
|
||||
|
||||
XML_XMLConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id)
|
||||
{
|
||||
NET_StreamClass* stream;
|
||||
XMLFile xmlf;
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
xmlf = (XMLFile) getMem(sizeof(XMLFileStruct));
|
||||
xmlf->holdOver = getMem(XML_BUF_SIZE);
|
||||
xmlf->lineSize = XML_LINE_SIZE;
|
||||
xmlf->line = (char*)getMem(XML_LINE_SIZE);
|
||||
xmlf->urls = URL_s;
|
||||
xmlf->address = copyString(URL_s->address);
|
||||
xmlf->mwcontext = window_id;
|
||||
xmlf->numOpenStreams = 1;
|
||||
/* URL_s->fedata = xmlf; */
|
||||
stream = NET_NewStream("XML", (MKStreamWriteFunc)parseNextXMLBlob,
|
||||
(MKStreamCompleteFunc)xml_complete,
|
||||
(MKStreamAbortFunc)xml_abort,
|
||||
(MKStreamWriteReadyFunc)xml_write_ready, xmlf, window_id);
|
||||
if (stream == NULL) freeMem(xmlf);
|
||||
|
||||
return(stream);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* XML-CSS stuff */
|
||||
|
||||
|
||||
|
||||
unsigned int
|
||||
xmlcss_write_ready(NET_StreamClass *stream)
|
||||
{
|
||||
return XML_LINE_SIZE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xmlcss_abort(NET_StreamClass *stream, int status)
|
||||
{
|
||||
StyleSheet obj=stream->data_object;
|
||||
XMLFile xml = obj->xmlFile;
|
||||
xml->numOpenStreams--;
|
||||
freeMem(obj->holdOver);
|
||||
freeMem(obj->line);
|
||||
obj->line = obj->holdOver = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xmlcss_complete (NET_StreamClass *stream)
|
||||
{
|
||||
StyleSheet ss =stream->data_object;
|
||||
URL_Struct *urls = ss->urls;
|
||||
XMLFile xml = ss->xmlFile;
|
||||
freeMem(ss->holdOver);
|
||||
freeMem(ss->line);
|
||||
ss->line = ss->holdOver = NULL;
|
||||
xml->numOpenStreams--;
|
||||
if (xml->numOpenStreams == 0) {
|
||||
/* direct the stream to the html parser */
|
||||
NET_StreamClass *newstream;
|
||||
URL_Struct *nurls = NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
|
||||
StrAllocCopy(nurls->content_type, TEXT_HTML);
|
||||
newstream = NET_StreamBuilder(1, nurls, (MWContext*) xml->mwcontext);
|
||||
xml->stream = newstream;
|
||||
convertToHTML(xml);
|
||||
newstream->complete(newstream);
|
||||
NET_FreeURLStruct(nurls);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
PR_PUBLIC_API(NET_StreamClass *)
|
||||
#else
|
||||
PUBLIC NET_StreamClass *
|
||||
#endif
|
||||
|
||||
XML_CSSConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id)
|
||||
{
|
||||
StyleSheet ss = (StyleSheet) URL_s->fe_data;
|
||||
TRACEMSG(("Setting up style sheet stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
return NET_NewStream("XML-CSS", (MKStreamWriteFunc)parseNextXMLCSSBlob,
|
||||
(MKStreamCompleteFunc)xmlcss_complete,
|
||||
(MKStreamAbortFunc)xmlcss_abort,
|
||||
(MKStreamWriteReadyFunc)xmlcss_write_ready, ss, window_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xmlcss_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
readCSS (StyleSheet ss)
|
||||
{
|
||||
URL_Struct *urls;
|
||||
urls = NET_CreateURLStruct(ss->address, NET_DONT_RELOAD);
|
||||
if (urls == NULL) {
|
||||
ss->xmlFile->numOpenStreams--;
|
||||
return;
|
||||
}
|
||||
urls->fe_data = ss;
|
||||
NET_GetURL(urls, FO_CACHE_AND_XMLCSS, ss->xmlFile->mwcontext, xmlcss_GetUrlExitFunc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
xmlhtml_write(NET_StreamClass *stream, const char *str, int32 len)
|
||||
{
|
||||
XMLHTMLInclusion obj=stream->data_object;
|
||||
char* newStr;
|
||||
if (obj == NULL || len < 0) {
|
||||
return MK_INTERRUPTED;
|
||||
}
|
||||
newStr = getMem(len+1);
|
||||
memcpy(newStr, str, len);
|
||||
*(obj->content + obj->n++) = newStr;
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned int
|
||||
xmlhtml_write_ready(NET_StreamClass *stream)
|
||||
{
|
||||
return XML_LINE_SIZE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xmlhtml_abort(NET_StreamClass *stream, int status)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xmlhtml_complete (NET_StreamClass *stream)
|
||||
{
|
||||
XMLHTMLInclusion ss =stream->data_object;
|
||||
XMLFile xml = ss->xml;
|
||||
xml->numOpenStreams--;
|
||||
if (xml->numOpenStreams == 0) {
|
||||
/* direct the stream to the html parser */
|
||||
NET_StreamClass *newstream;
|
||||
URL_Struct *nurls = NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
|
||||
StrAllocCopy(nurls->content_type, TEXT_HTML);
|
||||
newstream = NET_StreamBuilder(1, nurls, (MWContext*) xml->mwcontext);
|
||||
xml->stream = newstream;
|
||||
convertToHTML(xml);
|
||||
newstream->complete(newstream);
|
||||
NET_FreeURLStruct(nurls);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
PR_PUBLIC_API(NET_StreamClass *)
|
||||
#else
|
||||
PUBLIC NET_StreamClass *
|
||||
#endif
|
||||
|
||||
XML_HTMLConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id)
|
||||
{
|
||||
XMLHTMLInclusion ss = (XMLHTMLInclusion) URL_s->fe_data;
|
||||
|
||||
return NET_NewStream("XML-HTML", (MKStreamWriteFunc)xmlhtml_write,
|
||||
(MKStreamCompleteFunc)xmlhtml_complete,
|
||||
(MKStreamAbortFunc)xmlhtml_abort,
|
||||
(MKStreamWriteReadyFunc)xmlhtml_write_ready, ss, window_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
xmlhtml_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
readHTML (char* url, XMLHTMLInclusion ss)
|
||||
{
|
||||
URL_Struct *urls;
|
||||
urls = NET_CreateURLStruct(url, NET_DONT_RELOAD);
|
||||
if (urls == NULL) {
|
||||
ss->xml->numOpenStreams--;
|
||||
return;
|
||||
}
|
||||
urls->fe_data = ss;
|
||||
NET_GetURL(urls, FO_CACHE_AND_XMLHTML, ss->xml->mwcontext, xmlhtml_GetUrlExitFunc);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _RDF_XMLGLUE_H_
|
||||
#define _RDF_XMLGLUE_H_
|
||||
|
||||
#include "xmlparse.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/fcntl.h>
|
||||
#elif defined(XP_MAC)
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* xmlglue.c data structures and defines */
|
||||
|
||||
#define XML_LINE_SIZE 500
|
||||
|
||||
|
||||
|
||||
/* xmlglue.c function prototypes */
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
unsigned int xml_write_ready(NET_StreamClass *stream);
|
||||
void xml_abort(NET_StreamClass *stream, int status);
|
||||
void xml_complete (NET_StreamClass *stream);
|
||||
unsigned int xmlcss_write_ready(NET_StreamClass *stream);
|
||||
void xmlcss_abort(NET_StreamClass *stream, int status);
|
||||
void xmlcss_complete (NET_StreamClass *stream);
|
||||
void outputToStream (XMLFile f, char* s);
|
||||
void xmlcss_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx);
|
||||
void readCSS (StyleSheet ss);
|
||||
int xmlhtml_write(NET_StreamClass *stream, const char *str, int32 len);
|
||||
unsigned int xmlhtml_write_ready(NET_StreamClass *stream);
|
||||
void xmlhtml_abort(NET_StreamClass *stream, int status);
|
||||
void xmlhtml_complete (NET_StreamClass *stream);
|
||||
void xmlhtml_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx);
|
||||
void readHTML (char* url, XMLHTMLInclusion ss);
|
||||
|
||||
PUBLIC NET_StreamClass * XML_XMLConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id);
|
||||
PUBLIC NET_StreamClass * XML_CSSConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id);
|
||||
PUBLIC NET_StreamClass * XML_HTMLConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif
|
|
@ -1,429 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is a "stop-gap" xml parser that is being shipped with the free
|
||||
source. A real xml parser from James Clark will replace this
|
||||
within the next few weeks.
|
||||
|
||||
For more information on this file, contact rjc or guha
|
||||
For more information on RDF, look at the RDF section of www.mozilla.org
|
||||
For more info on XML in navigator, look at the XML section
|
||||
of www.mozilla.org.
|
||||
|
||||
*/
|
||||
|
||||
#include "xmlparse.h"
|
||||
#include "xmlglue.h"
|
||||
|
||||
|
||||
#define href "HRef"
|
||||
#define XLL "XML-Link"
|
||||
|
||||
|
||||
|
||||
int
|
||||
parseNextXMLBlob (NET_StreamClass *stream, char* blob, int32 size)
|
||||
{
|
||||
XMLFile f;
|
||||
int32 n, last, m;
|
||||
PRBool somethingseenp = false;
|
||||
n = last = 0;
|
||||
|
||||
f = (XMLFile)(stream->data_object);
|
||||
if ((f == NULL) || (f->urls == NULL) || (size < 0))
|
||||
{
|
||||
return MK_INTERRUPTED;
|
||||
}
|
||||
|
||||
while (n < size) {
|
||||
char c = blob[n];
|
||||
m = 0;
|
||||
somethingseenp = false;
|
||||
memset(f->line, '\0', f->lineSize);
|
||||
if (f->holdOver[0] != '\0') {
|
||||
memcpy(f->line, f->holdOver, strlen(f->holdOver));
|
||||
m = strlen(f->holdOver);
|
||||
somethingseenp = true;
|
||||
memset(f->holdOver, '\0', XML_BUF_SIZE);
|
||||
}
|
||||
while ((m < 300) && (c != '<') && (c != '>')) {
|
||||
f->line[m] = c;
|
||||
m++;
|
||||
somethingseenp = (somethingseenp || (!wsc(c)));
|
||||
n++;
|
||||
if (n < size) {
|
||||
c = blob[n];
|
||||
} else break;
|
||||
}
|
||||
if (c == '>') f->line[m] = c;
|
||||
n++;
|
||||
if (m > 0) {
|
||||
if ((c == '<') || (c == '>')) {
|
||||
last = n;
|
||||
if (c == '<') f->holdOver[0] = '<';
|
||||
if (somethingseenp == true) {
|
||||
if (f->line[0] == '<') {
|
||||
if (f->line[1] == '/') {
|
||||
f->current = f->current->parent;
|
||||
} else {
|
||||
processNextXMLElement(f, f->line);
|
||||
}
|
||||
} else {
|
||||
processNextXMLContent(f, f->line);
|
||||
}
|
||||
}
|
||||
} else if (size > last) {
|
||||
memcpy(f->holdOver, f->line, m);
|
||||
}
|
||||
} else if (c == '<') f->holdOver[0] = '<';
|
||||
}
|
||||
return(size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
processNextXMLContent (XMLFile f, char* content)
|
||||
{
|
||||
XMLElement xmle = (XMLElement)getMem(sizeof(XMLElementStruct));
|
||||
xmle->content = copyString(content);
|
||||
xmle->tag = "xml:content";
|
||||
addChild(f->current, xmle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
char **
|
||||
copyCharStarList (char** list)
|
||||
{
|
||||
size_t length = 0;
|
||||
while (*(list + length++)){}
|
||||
if (length == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
char** ans = getMem(length * sizeof(char*));
|
||||
size_t n = 0;
|
||||
while (*(list + n++)) {
|
||||
*(ans + n - 1) = copyString(*(list + n - 1));
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
makeAbsoluteURL (char* p1, char* p2)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
return p2;
|
||||
#else
|
||||
return NET_MakeAbsoluteURL(p1, p2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
processNextXMLElement (XMLFile f, char* attr)
|
||||
{
|
||||
size_t n = 1;
|
||||
size_t s = strlen(attr);
|
||||
size_t m = 0;
|
||||
PRBool linkp = 0;
|
||||
char* attv;
|
||||
PRBool emptyTagp = ((attr[s-2] == '/') || ((attr[s-2] == '?') && (!startsWith("<?xml", attr))));
|
||||
XMLElement xmle = (XMLElement)getMem(sizeof(XMLElementStruct));
|
||||
char* attlist[2*MAX_ATTRIBUTES+1];
|
||||
char* elementName;
|
||||
if (startsWith("<!--", attr)) return;
|
||||
tokenizeXMLElement(attr, attlist, &elementName);
|
||||
if (stringEquals(elementName, "?StyleSheet")) linkp = 1;
|
||||
|
||||
xmle->parent = f->current;
|
||||
if (f->top == NULL) f->top = xmle;
|
||||
xmle->tag = copyString(elementName);
|
||||
xmle->attributes = copyCharStarList(attlist);
|
||||
if (f->current) addChild(f->current, xmle);
|
||||
if (!emptyTagp || (!f->current)) f->current = xmle;
|
||||
attv = getAttributeValue(xmle->attributes, "Type");
|
||||
if (linkp && attv && (startsWith("css", attv))) {
|
||||
char* url = getAttributeValue(xmle->attributes, href);
|
||||
StyleSheet ss = (StyleSheet) getMem(sizeof(StyleSheetStruct));
|
||||
ss->address = makeAbsoluteURL(f->address, url);
|
||||
ss->line = (char*)getMem(XML_BUF_SIZE);
|
||||
ss->holdOver = (char*)getMem(XML_BUF_SIZE);
|
||||
ss->lineSize = XML_BUF_SIZE;
|
||||
ss->xmlFile = f;
|
||||
f->numOpenStreams++;
|
||||
addStyleSheet(f, ss);
|
||||
readCSS(ss);
|
||||
}
|
||||
if (emptyTagp && (getAttributeValue(xmle->attributes, XLL) != NULL)) {
|
||||
char* linkTag = getAttributeValue(xmle->attributes, XLL);
|
||||
char* hrefVal = getAttributeValue(xmle->attributes, href);
|
||||
char* type = getAttributeValue(xmle->attributes, "Role");
|
||||
char* show = getAttributeValue(xmle->attributes, "Show");
|
||||
|
||||
if (linkTag && (stringEquals(linkTag, "LINK")) &&
|
||||
hrefVal && type && stringEquals(type, "HTML") &&
|
||||
show && (stringEquals(show, "Embed"))) {
|
||||
XMLHTMLInclusion incl = (XMLHTMLInclusion)getMem(sizeof(XMLHTMLInclusionStruct));
|
||||
incl->xml = f;
|
||||
incl->content = (char**)getMem(400);
|
||||
xmle->content = (char*) incl;
|
||||
f->numOpenStreams++;
|
||||
readHTML(makeAbsoluteURL(f->address, hrefVal), incl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
addStyleSheet(XMLFile f, StyleSheet ss)
|
||||
{
|
||||
if (f->ss == NULL) {
|
||||
f->ss = ss;
|
||||
} else {
|
||||
StyleSheet nss = f->ss;
|
||||
while (nss->next != NULL) nss = nss->next;
|
||||
nss->next = ss;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
addChild (XMLElement parent, XMLElement child)
|
||||
{
|
||||
if (parent->child == NULL) {
|
||||
parent->child = child;
|
||||
} else {
|
||||
XMLElement nc = parent->child;
|
||||
while (nc->next) {nc = nc->next;}
|
||||
nc->next = child;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outputAttributes(XMLFile f, char** attlist)
|
||||
{
|
||||
uint32 n = 0;
|
||||
PRBool xmlinkp = (getAttributeValue(attlist, XLL) != NULL);
|
||||
if (!attlist) return ;
|
||||
while ((n < 2*MAX_ATTRIBUTES) && (*(attlist + n) != NULL)) {
|
||||
if (!(xmlinkp && stringEquals(*(attlist + n), href))) {
|
||||
outputToStream(f, *(attlist + n));
|
||||
outputToStream(f, "=\"");
|
||||
outputToStream(f, *(attlist + n + 1));
|
||||
outputToStream(f, "\" ");
|
||||
}
|
||||
|
||||
n = n + 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
outputAsHTML (XMLFile f, XMLElement el)
|
||||
{
|
||||
if (strcmp(el->tag, "xml:content") == 0) {
|
||||
outputToStream(f, el->content);
|
||||
} else {
|
||||
char* htmlEquiv = getAttributeValue(el->attributes, "html-equiv");
|
||||
char* linkTag = getAttributeValue(el->attributes, XLL);
|
||||
char* htmlBuff = getMem(1024);
|
||||
XMLElement child = el->child;
|
||||
PRBool suppressTag = stringEquals(el->tag, "Title") ; /*hack to suppress html docbook interaction */
|
||||
|
||||
|
||||
|
||||
if (linkTag && (stringEquals(linkTag, "LINK"))) {
|
||||
char* hrefVal = getAttributeValue(el->attributes, "HRef");
|
||||
if (hrefVal) {
|
||||
char* type = getAttributeValue(el->attributes, "Role");
|
||||
char* show = getAttributeValue(el->attributes, "Show");
|
||||
if (show &&(strcmp(show, "EMBED") == 0)) {
|
||||
if (type && (strcmp(type, "HTML") == 0)) {
|
||||
int32 n = 0;
|
||||
XMLHTMLInclusion incl = (XMLHTMLInclusion) el->content;
|
||||
while (*(incl->content + n)) {
|
||||
outputToStream(f, (*(incl->content + n)));
|
||||
n++;
|
||||
}
|
||||
} else if (type && (strcmp(type, "IMAGE") == 0)) {
|
||||
sprintf(htmlBuff, "<img src=%s>\n", hrefVal);
|
||||
outputToStream(f, htmlBuff);
|
||||
}
|
||||
freeMem(htmlBuff);
|
||||
return;
|
||||
} else {
|
||||
sprintf(htmlBuff, "<a href=\"%s\">", hrefVal);
|
||||
outputToStream(f, htmlBuff);
|
||||
}
|
||||
} else {
|
||||
linkTag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
outputStyleSpan(f, el, 0);
|
||||
|
||||
if (htmlEquiv) {
|
||||
sprintf(htmlBuff, "<%s ", htmlEquiv);
|
||||
outputToStream(f, htmlBuff);
|
||||
outputAttributes(f, el->attributes);
|
||||
outputToStream(f, ">\n");
|
||||
} else if (!(el->tag[0] == '?') && !suppressTag){
|
||||
sprintf(htmlBuff, "<%s ", el->tag);
|
||||
outputToStream(f, htmlBuff);
|
||||
outputAttributes(f, el->attributes);
|
||||
outputToStream(f, ">\n");
|
||||
}
|
||||
|
||||
while (child) {
|
||||
outputAsHTML(f, child);
|
||||
child = child->next;
|
||||
}
|
||||
if (htmlEquiv) {
|
||||
sprintf(htmlBuff, "</%s>\n", htmlEquiv);
|
||||
outputToStream(f, htmlBuff);
|
||||
} else if (!(el->tag[0] == '?') && !suppressTag) {
|
||||
sprintf(htmlBuff, "</%s>\n", el->tag);
|
||||
outputToStream(f, htmlBuff);
|
||||
}
|
||||
outputStyleSpan(f, el, 1);
|
||||
if (linkTag) outputToStream(f, "</a>");
|
||||
freeMem(htmlBuff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
convertToHTML (XMLFile xf) {
|
||||
XMLElement el = xf->top;
|
||||
xf->numOpenStreams--;
|
||||
if (xf->numOpenStreams < 1) {
|
||||
outputToStream(xf, "<html><body>");
|
||||
outputAsHTML(xf, el);
|
||||
outputToStream(xf, "</body></html>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
outputStyleSpan (XMLFile f, XMLElement el, PRBool endp)
|
||||
{
|
||||
StyleSheet ss ;
|
||||
StyleElement se;
|
||||
for (ss = f->ss; (ss != NULL) ; ss = ss->next) {
|
||||
for (se = ss->el; (se != NULL) ; se = se->next) {
|
||||
|
||||
if (stringEquals((se->tagStack)[0], el->tag)) {
|
||||
PRBool divp = startsWith("Display:Block;", se->style);
|
||||
PRBool listp = startsWith("Display:List-item;", se->style);
|
||||
if (!endp) {
|
||||
if (divp) {
|
||||
outputToStream(f, "<div style=\"");
|
||||
outputToStream(f, &(se->style)[14]);
|
||||
} else if (listp) {
|
||||
outputToStream(f, "<UL><LI><span style=\"");
|
||||
outputToStream(f, &(se->style)[20]);
|
||||
} else {
|
||||
outputToStream(f, "<span style=\"");
|
||||
outputToStream(f, se->style);
|
||||
}
|
||||
outputToStream(f, "\">\n");
|
||||
} else {
|
||||
if (divp) {
|
||||
outputToStream(f, "</div>");
|
||||
} else if (listp) {
|
||||
outputToStream(f, "</UL></span>");
|
||||
} else {
|
||||
outputToStream(f, "</span>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
tokenizeXMLElement (char* attr, char** attlist, char** elementName)
|
||||
{
|
||||
size_t n = 1;
|
||||
size_t s = strlen(attr);
|
||||
char c ;
|
||||
size_t m = 0;
|
||||
size_t atc = 0;
|
||||
PRBool emptyTagp = (attr[s-2] == '/');
|
||||
PRBool inAttrNamep = 1;
|
||||
c = attr[n++];
|
||||
while (wsc(c)) {
|
||||
c = attr[n++];
|
||||
}
|
||||
*elementName = &attr[n-1];
|
||||
while (n < s) {
|
||||
if (wsc(c)) break;
|
||||
c = attr[n++];
|
||||
}
|
||||
attr[n-1] = '\0';
|
||||
while (atc < 2*MAX_ATTRIBUTES+1) {*(attlist + atc++) = NULL;}
|
||||
atc = 0;
|
||||
s = (emptyTagp ? s-2 : s-1);
|
||||
while (n < s) {
|
||||
PRBool attributeOpenStringSeenp = 0;
|
||||
m = 0;
|
||||
c = attr[n++];
|
||||
while ((n <= s) && (atc < 2*MAX_ATTRIBUTES)) {
|
||||
if (inAttrNamep && (m > 0) && (wsc(c) || (c == '='))) {
|
||||
attr[n-1] = '\0';
|
||||
*(attlist + atc++) = &attr[n-m-1];
|
||||
break;
|
||||
}
|
||||
if (!inAttrNamep && attributeOpenStringSeenp && (c == '"')) {
|
||||
attr[n-1] = '\0';
|
||||
*(attlist + atc++) = &attr[n-m-1];
|
||||
break;
|
||||
}
|
||||
if (inAttrNamep) {
|
||||
if ((m > 0) || (!wsc(c))) m++;
|
||||
} else {
|
||||
if (c == '"') {
|
||||
attributeOpenStringSeenp = 1;
|
||||
} else {
|
||||
if ((m > 0) || (!(wsc(c)))) m++;
|
||||
}
|
||||
}
|
||||
c = attr[n++];
|
||||
}
|
||||
inAttrNamep = (inAttrNamep ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Kludge Alert */
|
|
@ -1,141 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _RDF_XMLPARSE_H_
|
||||
#define _RDF_XMLPARSE_H_
|
||||
|
||||
|
||||
/* This is a "stop-gap" xml parser that is being shipped with the free
|
||||
source. A real xml parser from James Clark will replace this
|
||||
within the next few weeks */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "nspr.h"
|
||||
#include "plhash.h"
|
||||
#include "ntypes.h"
|
||||
#include "net.h"
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
#include "utils.h"
|
||||
#include "rdf-int.h"
|
||||
|
||||
|
||||
|
||||
#ifndef true
|
||||
#define true PR_TRUE
|
||||
#endif
|
||||
#ifndef false
|
||||
#define false PR_FALSE
|
||||
#endif
|
||||
#define null NULL
|
||||
#define nullp(x) (((void*)x) == ((void*)0))
|
||||
|
||||
|
||||
|
||||
/* xmlparse.c data structures and defines */
|
||||
|
||||
#define MAX_TAG_SIZE 100
|
||||
#define MAX_ATTRIBUTES 10
|
||||
#define XML_BUF_SIZE 4096
|
||||
#define wsc(c) ((c == ' ') || (c == '\r') || (c == '\n') || (c == '\t'))
|
||||
typedef struct _XMLFileStruct {
|
||||
struct _StyleSheetStruct* ss;
|
||||
struct _XMLElementStruct* top;
|
||||
struct _XMLElementStruct* current;
|
||||
uint32 status;
|
||||
void* stream;
|
||||
int8 numOpenStreams;
|
||||
void* urls;
|
||||
void* mwcontext;
|
||||
char* holdOver;
|
||||
int32 lineSize;
|
||||
char* line;
|
||||
char* address;
|
||||
} XMLFileStruct;
|
||||
|
||||
typedef XMLFileStruct* XMLFile;
|
||||
|
||||
typedef struct _StyleSheetStruct {
|
||||
XMLFile xmlFile;
|
||||
struct _StyleElementStruct* el;
|
||||
struct _StyleSheetStruct* next;
|
||||
void* urls;
|
||||
char* holdOver;
|
||||
int32 lineSize;
|
||||
char* line;
|
||||
char* address;
|
||||
} StyleSheetStruct;
|
||||
|
||||
typedef StyleSheetStruct* StyleSheet;
|
||||
|
||||
typedef struct _StyleElementStruct {
|
||||
char** tagStack;
|
||||
char* style;
|
||||
struct _StyleElementStruct* next;
|
||||
} StyleElementStruct;
|
||||
|
||||
typedef StyleElementStruct* StyleElement;
|
||||
|
||||
|
||||
typedef struct _XMLElementStruct {
|
||||
char* tag;
|
||||
char** attributes;
|
||||
char* content;
|
||||
struct _XMLElementStruct* parent;
|
||||
struct _XMLElementStruct* child;
|
||||
struct _XMLElementStruct* next;
|
||||
} XMLElementStruct;
|
||||
|
||||
typedef XMLElementStruct* XMLElement;
|
||||
|
||||
typedef struct _XMLHTMLInclusionStruct {
|
||||
char** content;
|
||||
XMLFile xml;
|
||||
int32 n;
|
||||
} XMLHTMLInclusionStruct;
|
||||
|
||||
typedef XMLHTMLInclusionStruct *XMLHTMLInclusion;
|
||||
|
||||
|
||||
|
||||
/* xmlparse.c function prototypes */
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
int parseNextXMLBlob (NET_StreamClass *stream, char* blob, int32 size);
|
||||
void processNextXMLContent (XMLFile f, char* content);
|
||||
char ** copyCharStarList (char** list);
|
||||
char * makeAbsoluteURL (char* p1, char* p2);
|
||||
void processNextXMLElement (XMLFile f, char* attr);
|
||||
void addStyleSheet(XMLFile f, StyleSheet ss);
|
||||
void addChild (XMLElement parent, XMLElement child);
|
||||
char * getTagHTMLEquiv (XMLFile f, XMLElement el);
|
||||
void outputAttributes(XMLFile f, char** attlist);
|
||||
void outputAsHTML (XMLFile f, XMLElement el);
|
||||
void convertToHTML (XMLFile xf);
|
||||
void outputStyleSpan (XMLFile f, XMLElement el, PRBool endp);
|
||||
char * getAttributeValue (char** attlist, char* elName);
|
||||
void tokenizeXMLElement (char* attr, char** attlist, char** elementName);
|
||||
void readCSS(StyleSheet ss);
|
||||
void outputToStream(XMLFile f, char* s);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif
|
|
@ -1,169 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is some glue code for a semi-parsing CSS. Its used to
|
||||
output html from XML.
|
||||
This will be changed when we incorporate the real xml parser
|
||||
from James Clark will replace this within the next few weeks.
|
||||
|
||||
For more information on this file, contact rjc or guha
|
||||
For more information on RDF, look at the RDF section of www.mozilla.org
|
||||
For more info on XML in navigator, look at the XML section
|
||||
of www.mozilla.org.
|
||||
*/
|
||||
|
||||
#include "xmlss.h"
|
||||
|
||||
|
||||
|
||||
int
|
||||
parseNextXMLCSSBlob (NET_StreamClass *stream, char* blob, int32 size)
|
||||
{
|
||||
StyleSheet ss;
|
||||
int32 n, last, m;
|
||||
PRBool somethingseenp = false;
|
||||
n = last = 0;
|
||||
|
||||
ss = (StyleSheet)(stream->data_object);
|
||||
if ((ss == NULL) || (size < 0)) {
|
||||
return MK_INTERRUPTED;
|
||||
}
|
||||
|
||||
while (n < size) {
|
||||
char c = blob[n];
|
||||
m = 0;
|
||||
memset(ss->line, '\0', ss->lineSize);
|
||||
if (ss->holdOver[0] != '\0') {
|
||||
memcpy(ss->line, ss->holdOver, strlen(ss->holdOver));
|
||||
m = strlen(ss->holdOver);
|
||||
memset(ss->holdOver, '\0', RDF_BUF_SIZE);
|
||||
}
|
||||
while ((m < 300) && (c != '{') && (c != '}')) {
|
||||
ss->line[m] = c;
|
||||
m++;
|
||||
somethingseenp = (somethingseenp || ((c != ' ') &&
|
||||
(c != '\r') && (c != '\n')));
|
||||
n++;
|
||||
if (n < size) {
|
||||
c = blob[n];
|
||||
} else break;
|
||||
}
|
||||
if (c == '}') ss->line[m] = c;
|
||||
n++;
|
||||
if (m > 0) {
|
||||
if ((c == '}') || (c == '{')) {
|
||||
last = n;
|
||||
if (c == '{') ss->holdOver[0] = '{';
|
||||
if (somethingseenp) {
|
||||
parseNextXMLCSSElement(ss, ss->line);
|
||||
} else if (size > last) {
|
||||
memcpy(ss->holdOver, ss->line, m);
|
||||
}
|
||||
} else if (c == '{') ss->holdOver[0] = '{';
|
||||
}
|
||||
}
|
||||
return(size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
parseNextXMLCSSElement (StyleSheet ss, char* ele)
|
||||
{
|
||||
if (ele[0] == '{') {
|
||||
char* sty = getMem(strlen(ele)-1);
|
||||
memcpy(sty, &ele[1], strlen(ele)-2);
|
||||
ss->el->style = sty;
|
||||
} else {
|
||||
StyleElement se = (StyleElement) getMem(sizeof(StyleElementStruct));
|
||||
size_t numTags, size, n, count;
|
||||
se->next = ss->el;
|
||||
ss->el = se;
|
||||
size = strlen(ele);
|
||||
count = n = 0;
|
||||
numTags = countTagStackSize(ele);
|
||||
while (count < numTags) {
|
||||
size_t st = 0;
|
||||
char** tgs = (char**) getMem(numTags * sizeof(char**));
|
||||
se->tagStack = tgs;
|
||||
while (st < numTags) {
|
||||
*(tgs + st++) = getNextSSTag(ele, &n);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t
|
||||
countSSNumTags (char* ele)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t m = 1;
|
||||
size_t sz = strlen(ele);
|
||||
while (n < sz) {
|
||||
if (ele[n++] == ',') m++;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t
|
||||
countTagStackSize (char* ele)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t m = 0;
|
||||
PRBool inSpace = 1;
|
||||
size_t sz = strlen(ele);
|
||||
while (n < sz) {
|
||||
if (ele[n] == ',') break;
|
||||
if ((ele[n] != ' ') && (ele[n] != '\r') && (ele[n] != '\n')) {
|
||||
if (inSpace) {
|
||||
m++;
|
||||
inSpace = 0;
|
||||
}
|
||||
} else inSpace = 1;
|
||||
n++;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char*
|
||||
getNextSSTag (char* ele, size_t* n)
|
||||
{
|
||||
char tag[100];
|
||||
size_t m = 0;
|
||||
char c = ele[*n];
|
||||
size_t s = strlen(ele);
|
||||
memset(tag, '\0', 100);
|
||||
while ((c == '\r') || (c == ' ') || (c == '\n')) {
|
||||
*n = *n + 1;
|
||||
c = ele[*n];
|
||||
}
|
||||
while ((c != ' ') && (c != ',') && (*n < s)) {
|
||||
tag[m++] = c;
|
||||
*n = *n + 1;
|
||||
c = ele[*n];
|
||||
}
|
||||
return copyString(tag);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _RDF_XMLSS_H_
|
||||
#define _RDF_XMLSS_H_
|
||||
|
||||
|
||||
#include "rdf-int.h"
|
||||
#include "xmlparse.h"
|
||||
|
||||
|
||||
|
||||
/* xmlss.c data structures */
|
||||
|
||||
|
||||
|
||||
|
||||
/* xmlss.c function prototypes */
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
int parseNextXMLCSSBlob (NET_StreamClass *stream, char* blob, int32 size);
|
||||
void parseNextXMLCSSElement (StyleSheet f, char* ele);
|
||||
size_t countSSNumTags (char* ele);
|
||||
size_t countTagStackSize (char* ele);
|
||||
char* getNextSSTag (char* ele, size_t* n);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче