diff -Naur --exclude=CVS --exclude=Linux* abi-old/src/wp/impexp/xp/Makefile abi/src/wp/impexp/xp/Makefile --- abi-old/src/wp/impexp/xp/Makefile Sat Oct 14 05:48:48 2000 +++ abi/src/wp/impexp/xp/Makefile Sat Oct 14 20:33:09 2000 @@ -40,6 +40,7 @@ ie_imp_XML.cpp \ ie_imp_AbiWord_1.cpp \ ie_imp_GZipAbiWord.cpp \ + ie_imp_DocBook.cpp \ ie_imp_MsWord_97.cpp \ ie_imp_RTF.cpp \ ie_imp_Text.cpp \ diff -Naur --exclude=CVS --exclude=Linux* abi-old/src/wp/impexp/xp/ie_imp.cpp abi/src/wp/impexp/xp/ie_imp.cpp --- abi-old/src/wp/impexp/xp/ie_imp.cpp Sat Oct 14 14:42:32 2000 +++ abi/src/wp/impexp/xp/ie_imp.cpp Sat Oct 14 20:34:48 2000 @@ -35,6 +35,7 @@ #include "ie_imp_WML.h" #include "ie_imp_GraphicAsDocument.h" #include "ie_imp_XHTML.h" +#include "ie_imp_DocBook.h" /*****************************************************************/ /*****************************************************************/ @@ -56,6 +57,9 @@ static struct _imp s_impTable[] = { DeclareImporter(IE_Imp_AbiWord_1), +#ifdef DEBUG + DeclareImporter(IE_Imp_DocBook), +#endif DeclareImporter(IE_Imp_MsWord_97), DeclareImporter(IE_Imp_XHTML), DeclareImporter(IE_Imp_RTF), diff -Naur --exclude=CVS --exclude=Linux* abi-old/src/wp/impexp/xp/ie_imp_DocBook.cpp abi/src/wp/impexp/xp/ie_imp_DocBook.cpp --- abi-old/src/wp/impexp/xp/ie_imp_DocBook.cpp Wed Dec 31 19:00:00 1969 +++ abi/src/wp/impexp/xp/ie_imp_DocBook.cpp Sat Oct 14 21:07:14 2000 @@ -0,0 +1,314 @@ +/* AbiWord + * Copyright (C) 1998 AbiSource, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include +#include +#include +#include "ut_types.h" +#include "ut_assert.h" +#include "ut_debugmsg.h" +#include "ut_string.h" +#include "ie_imp_DocBook.h" +#include "ie_types.h" +#include "pd_Document.h" +#include "ut_growbuf.h" + +/* + * DocBook is a SGML derivate with lots of friggin' tags + * We hardly support any of them now, only the ones we export + */ + +/*****************************************************************/ +/*****************************************************************/ + +IE_Imp_DocBook::~IE_Imp_DocBook() +{ +} + +IE_Imp_DocBook::IE_Imp_DocBook(PD_Document * pDocument) + : IE_Imp_XML(pDocument) +{ + // white space is not significant + m_bWhiteSignificant = UT_FALSE; +} + +/*****************************************************************/ +/*****************************************************************/ + +UT_Bool IE_Imp_DocBook::RecognizeContents(const char * szBuf, UT_uint32 iNumbytes) +{ + // no doubt, this could be better + // but this should sufficefor all I care + + if(strstr(szBuf, " +#define TT_SECTION 2 // card or section +#define TT_BLOCK 3 // a paragraph

+#define TT_PHRASE 4 // formatted text +#define TT_EMPHASIS 5 // emphasized (italic) text +#define TT_SUPERSCRIPT 6 // superscript +#define TT_SUBSCRIPT 7 // subscript +#define TT_BLOCKQUOTE 8 // block quote + +struct _TokenTable +{ + const char * m_name; + int m_type; +}; + +static struct _TokenTable s_Tokens[] = +{ + { "book", TT_DOCUMENT }, + { "chapter", TT_SECTION }, + { "para", TT_BLOCK }, + { "phrase", TT_PHRASE }, + { "emphasis", TT_EMPHASIS }, + { "superscript", TT_SUPERSCRIPT }, + { "subscript", TT_SUBSCRIPT }, + { "*", TT_OTHER } +}; + +#define TokenTableSize ((sizeof(s_Tokens)/sizeof(s_Tokens[0]))) + +static UT_uint32 s_mapNameToToken(const XML_Char * name) +{ + for (unsigned int k=0; kappendStrux(PTX_Section,(const XML_Char **)NULL)); + return; + } + + case TT_BLOCK: + X_VerifyParseState(_PS_Sec); + m_parseState = _PS_Block; + X_CheckError(m_pDocument->appendStrux(PTX_Block, NULL)); + return; + + case TT_BLOCKQUOTE: + X_VerifyParseState(_PS_Sec); + m_parseState = _PS_Block; + { + const XML_Char **p_atts; + XML_Char *buf[3]; + buf[2] = NULL; + + X_CheckError(m_pDocument->appendStrux(PTX_Block, NULL)); + UT_XML_cloneString(buf[0], PT_STYLE_ATTRIBUTE_NAME); + UT_XML_cloneString(buf[1], (XML_Char *)"Block Text"); + p_atts = (const XML_Char **)buf; + X_CheckError(m_pDocument->appendFmt(p_atts)); + return; + } + + case TT_PHRASE: + case TT_EMPHASIS: + case TT_SUPERSCRIPT: + case TT_SUBSCRIPT: + X_VerifyParseState(_PS_Block); + { + const XML_Char **p_atts; + XML_Char *buf[3]; + UT_XML_cloneString(buf[0], (XML_Char *)"props"); + buf[2] = NULL; + + switch(s_Tokens[tokenIndex].m_type) { + case TT_EMPHASIS: + UT_XML_cloneString(buf[1], (XML_Char *)"font-style:italic"); + break; + case TT_SUPERSCRIPT: + UT_XML_cloneString(buf[1], (XML_Char *)"text-position:superscript"); + break; + case TT_SUBSCRIPT: + UT_XML_cloneString(buf[1], (XML_Char *)"text-position:subscript"); + break; + case TT_PHRASE: + { + const XML_Char *p_val = _getXMLPropValue("role", atts); + if(p_val != NULL && !strcmp(p_val, "strong")) + UT_XML_cloneString(buf[1], (XML_Char *)"font-weight:bold"); + else + buf[0] = NULL; + break; + } + + default: + UT_ASSERT(UT_SHOULD_NOT_HAPPEN); + break; + } + + p_atts = (const XML_Char **)buf; + X_CheckError(_pushInlineFmt(p_atts)); + X_CheckError(m_pDocument->appendFmt(&m_vecInlineFmt)); + } + return; + + case TT_OTHER: + default: + UT_DEBUGMSG(("Unknown or knowingly unhandled tag [%s]\n",name)); + } + +} + +void IE_Imp_DocBook::_endElement(const XML_Char *name) +{ + + UT_DEBUGMSG(("DocBook import: endElement: %s\n", name)); + + // xml parser keeps running until buffer consumed + X_EatIfAlreadyError(); + + UT_uint32 tokenIndex = s_mapNameToToken(name); + + switch (s_Tokens[tokenIndex].m_type) + { + case TT_DOCUMENT: + X_VerifyParseState(_PS_Doc); + m_parseState = _PS_Init; + return; + + case TT_SECTION: + X_VerifyParseState(_PS_Sec); + m_parseState = _PS_Doc; + return; + + case TT_BLOCKQUOTE: + UT_ASSERT(m_lenCharDataSeen==0); + X_VerifyParseState(_PS_Block); + m_parseState = _PS_Block; + X_CheckDocument(_getInlineDepth()==0); + _popInlineFmt(); + X_CheckError(m_pDocument->appendFmt(&m_vecInlineFmt)); + return; + + case TT_BLOCK: + UT_ASSERT(m_lenCharDataSeen==0); + X_VerifyParseState(_PS_Block); + m_parseState = _PS_Sec; + X_CheckDocument(_getInlineDepth()==0); + return; + + case TT_PHRASE: + case TT_EMPHASIS: + case TT_SUPERSCRIPT: + case TT_SUBSCRIPT: + UT_ASSERT(m_lenCharDataSeen==0); + X_VerifyParseState(_PS_Block); + X_CheckDocument(_getInlineDepth()>0); + _popInlineFmt(); + X_CheckError(m_pDocument->appendFmt(&m_vecInlineFmt)); + return; + + case TT_OTHER: + default: + UT_DEBUGMSG(("Unknown or intentionally unhandled end tag [%s]\n",name)); + } +} + diff -Naur --exclude=CVS --exclude=Linux* abi-old/src/wp/impexp/xp/ie_imp_DocBook.h abi/src/wp/impexp/xp/ie_imp_DocBook.h --- abi-old/src/wp/impexp/xp/ie_imp_DocBook.h Wed Dec 31 19:00:00 1969 +++ abi/src/wp/impexp/xp/ie_imp_DocBook.h Sat Oct 14 18:32:40 2000 @@ -0,0 +1,55 @@ +/* AbiWord + * Copyright (C) 1998 AbiSource, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + + +#ifndef IE_IMP_DOCBOOK_H +#define IE_IMP_DOCBOOK_H + +#include +#include "ut_vector.h" +#include "ut_stack.h" +#include "ie_imp_XML.h" +#include "ut_bytebuf.h" +class PD_Document; + +// The importer/reader for WML files. + +class IE_Imp_DocBook : public IE_Imp_XML +{ +public: + IE_Imp_DocBook(PD_Document * pDocument); + virtual ~IE_Imp_DocBook(); + + static UT_Bool RecognizeContents(const char * szBuf, + UT_uint32 iNumbytes); + static UT_Bool RecognizeSuffix(const char * szSuffix); + static UT_Error StaticConstructor(PD_Document * pDocument, + IE_Imp ** ppie); + static UT_Bool GetDlgLabels(const char ** pszDesc, + const char ** pszSuffixList, + IEFileType * ft); + static UT_Bool SupportsFileType(IEFileType ft); + + + void _startElement(const XML_Char *name, + const XML_Char **atts); + void _endElement(const XML_Char *name); +}; + +#endif /* IE_IMP_DocBook_H */