]> git.lyx.org Git - features.git/commitdiff
Include file inset now works with linuxdoc and docbook.
authorJosé Matox <jamatos@lyx.org>
Sat, 1 Jul 2000 12:54:45 +0000 (12:54 +0000)
committerJosé Matox <jamatos@lyx.org>
Sat, 1 Jul 2000 12:54:45 +0000 (12:54 +0000)
Several small cleanups regarding docbook and linuxdoc code, (see Changelog).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@851 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/LaTeXFeatures.C
src/LaTeXFeatures.h
src/buffer.C
src/buffer.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/lyx_cb.C
src/lyx_main.C

index 6c8f432e980d6a45e0ccdfafefc0401b7b10d6f5..71d09cef3dde3cf96cc1275c9df6d697642b4806 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2000-07-01 José Abílio Matos <jamatos@fep.up.pt>
+       * src/LaTeXFeatures.h: new member IncludedFiles, for
+       a map of key, included file name.
+
+       * src/LaTeXFeatures.C (getIncludedFiles): returns a string
+       with the included files for inclusion in SGML preamble,
+       i. e., linuxdoc and docbook.
+
+       * src/buffer.h:
+       * src/buffer.C (makeLinuxDocFile): takes two new arguments,
+       nice (is the generated linuxdoc code to be exported?), that
+       allows to remove column, and only_body that will be true for
+       slave documents. Insets are allowed inside SGML font type.
+       New handling of the SGML preamble for included files.
+       (makeDocBookFile): the same for docbook.
+
+       * src/insets/insetinclude.h:
+       * src/insets/insetinclude.C (Validate): keeps a list of included files.
+       (Linuxdoc): 
+       (DocBook): new export methods.
+
+       * src/lyx_cb.C: adjust to the new calling sequence for makeLinuxDocFile
+       and makeDocBookFile.
+
+       * src/lyx_main.C (easyParse): accept linuxdoc and docbook as
+       formats to export with command line argument -x.
+
 2000-06-28  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
        * src/BufferView_pimpl.h: remove member variables lyx_focus and
index 67341747bdaf5ce14ff24c14e606e469fe709e29..d64f96b3ee45f1fde11b8f8b08fa1cb3fe38e875 100644 (file)
@@ -332,6 +332,17 @@ string LaTeXFeatures::getTClassPreamble()
 }      
 
 
+string LaTeXFeatures::getIncludedFiles()
+{
+       string sgmlpreamble;
+
+       for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi)
+               sgmlpreamble += "\n<!entity " + fi->first + " system \"" + fi->second + "\">";
+
+       return sgmlpreamble;
+}
+
+
 void LaTeXFeatures::showStruct() {
        lyxerr << "LyX needs the following commands when LaTeXing:"
               << "\n***** Packages:" << getPackages()
index 70054ca33d61b436fcdac1879a6fe0db67fc5b63..1446ebe64a55c39a0e08ad3c96b3406ebbb17cf9 100644 (file)
@@ -40,6 +40,8 @@ struct LaTeXFeatures {
        string getMacros();
        /// The definitions needed by the document's textclass
        string getTClassPreamble();
+       ///
+       string getIncludedFiles();
 
        ///
        void showStruct();
@@ -152,6 +154,10 @@ struct LaTeXFeatures {
        typedef std::set<string> FloatList;
        ///
        FloatList usedFloats;
+       ///
+       typedef map<string , string> FileMap;
+       ///
+       FileMap IncludedFiles;                                                                     
        //@}
        BufferParams const & bufferParams() const;
 private:
index 1d4b8dc05957f693b41355f1ad2d8b479df05cd3..bb1d109db18bd4a2ce98f87d6f69f3ae327511ac 100644 (file)
@@ -2149,10 +2149,12 @@ void Buffer::sgmlCloseTag(ostream & os, int depth,
 }
 
 
-void Buffer::makeLinuxDocFile(string const & fname, int column)
+void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 {
        LyXParagraph * par = paragraph;
 
+       niceFile = nice; // this will be used by Insetincludes.
+
        string top_element = textclasslist.LatexnameOfClass(params.textclass);
        string environment_stack[10];
         string item_name;
@@ -2165,35 +2167,49 @@ void Buffer::makeLinuxDocFile(string const & fname, int column)
                WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
                return;
        }
-   
-       tex_code_break_column = column; 
+
+        LyXTextClass const & tclass =
+               textclasslist.TextClass(params.textclass);
+
+       LaTeXFeatures features(params, tclass.numLayouts());
+       validate(features);
+
+       if(nice)
+               tex_code_break_column = lyxrc.ascii_linelen;
+       else
+               tex_code_break_column = 0;
+
        texrow.reset();
-   
-       if (params.preamble.empty()) {
-               ofs << "<!doctype linuxdoc system>\n\n";
-       }
-       else {
-               ofs << "<!doctype linuxdoc system \n [ "
-                   << params.preamble << " \n]>\n\n";
+
+       if (!body_only) {
+               string sgml_includedfiles=features.getIncludedFiles();
+
+               if (params.preamble.empty() && sgml_includedfiles.empty()) {
+                       ofs << "<!doctype linuxdoc system>\n\n";
+               }
+               else {
+                       ofs << "<!doctype linuxdoc system [ "
+                           << params.preamble << sgml_includedfiles << " \n]>\n\n";
+               }
+
+               if(params.options.empty())
+                       sgmlOpenTag(ofs, 0, top_element);
+               else {
+                       string top = top_element;
+                       top += " ";
+                       top += params.options;
+                       sgmlOpenTag(ofs, 0, top);
+               }
        }
 
        ofs << "<!-- "  << LYX_DOCVERSION 
            << " created this file. For more info see http://www.lyx.org/"
            << " -->\n";
 
-       if(params.options.empty())
-               sgmlOpenTag(ofs, 0, top_element);
-       else {
-               string top = top_element;
-               top += " ";
-               top += params.options;
-               sgmlOpenTag(ofs, 0, top);
-       }
-
        while (par) {
                int desc_on = 0; // description mode
                LyXLayout const & style =
-                       textclasslist.Style(users->buffer()->params.textclass,
+                       textclasslist.Style(params.textclass,
                                            par->layout);
 
                // treat <toc> as a special case for compatibility with old code
@@ -2314,8 +2330,10 @@ void Buffer::makeLinuxDocFile(string const & fname, int column)
        if(!environment_stack[depth].empty())
                sgmlCloseTag(ofs, depth, environment_stack[depth]);
 
-       ofs << "\n\n";
-       sgmlCloseTag(ofs, 0, top_element);
+       if (!body_only) {
+               ofs << "\n\n";
+               sgmlCloseTag(ofs, 0, top_element);
+       }
 
        ofs.close();
        // How to check for successful close
@@ -2659,15 +2677,17 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
                }
 
                c = par->GetChar(i);
-      
+
+               if (c == LyXParagraph::META_INSET) {
+                       inset = par->GetInset(i);
+                       inset->Linuxdoc(this, os);
+               }
+
                if (font2.latex() == LyXFont::ON) {
                        // "TeX"-Mode on == > SGML-Mode on.
                        if (c != '\0')
                                os << c; // see LaTeX-Generation...
                        ++char_line_count;
-               } else if (c == LyXParagraph::META_INSET) {
-                       inset = par->GetInset(i);
-                       inset->Linuxdoc(this, os);
                } else {
                        string sgml_string;
                        if (par->linuxDocConvertChar(c, sgml_string)
@@ -2738,10 +2758,12 @@ void Buffer::LinuxDocError(LyXParagraph * par, int pos,
 
 enum { MAX_NEST_LEVEL = 25};
 
-void Buffer::makeDocBookFile(string const & fname, int column)
+void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 {
        LyXParagraph * par = paragraph;
 
+       niceFile = nice; // this will be used by Insetincludes.
+
        string top_element= textclasslist.LatexnameOfClass(params.textclass);
        // Please use a real stack.
        string environment_stack[MAX_NEST_LEVEL];
@@ -2755,8 +2777,16 @@ void Buffer::makeDocBookFile(string const & fname, int column)
        string c_depth, c_params, tmps;
 
        int depth = 0; // paragraph depth
+        LyXTextClass const & tclass =
+               textclasslist.TextClass(params.textclass);
 
-       tex_code_break_column = column; 
+       LaTeXFeatures features(params, tclass.numLayouts());
+       validate(features);
+
+       if(nice)
+               tex_code_break_column = lyxrc.ascii_linelen;
+       else
+               tex_code_break_column = 0;
 
        ofstream ofs(fname.c_str());
        if (!ofs) {
@@ -2766,30 +2796,35 @@ void Buffer::makeDocBookFile(string const & fname, int column)
    
        texrow.reset();
 
-       ofs << "<!doctype " << top_element
-           << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
+       if(!only_body) {
+               string sgml_includedfiles=features.getIncludedFiles();
 
-       if (params.preamble.empty())
-               ofs << ">\n\n";
-       else
-               ofs << "\n [ " << params.preamble << " \n]>\n\n";
+               ofs << "<!doctype " << top_element
+                   << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
 
-       ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION 
-           << "\n  See http://www.lyx.org/ for more information -->\n";
+               if (params.preamble.empty() && sgml_includedfiles.empty())
+                       ofs << ">\n\n";
+               else
+                       ofs << "\n [ " << params.preamble 
+                           << sgml_includedfiles << " \n]>\n\n";
 
-       if(params.options.empty())
-               sgmlOpenTag(ofs, 0, top_element);
-       else {
-               string top = top_element;
-               top += " ";
-               top += params.options;
-               sgmlOpenTag(ofs, 0, top);
+               if(params.options.empty())
+                       sgmlOpenTag(ofs, 0, top_element);
+               else {
+                       string top = top_element;
+                       top += " ";
+                       top += params.options;
+                       sgmlOpenTag(ofs, 0, top);
+               }
        }
 
+       ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION 
+           << "\n  See http://www.lyx.org/ for more information -->\n";
+
        while (par) {
                int desc_on = 0; // description mode
                LyXLayout const & style =
-                       textclasslist.Style(users->buffer()->params.textclass,
+                       textclasslist.Style(params.textclass,
                                            par->layout);
 
                // environment tag closing
@@ -3011,8 +3046,10 @@ void Buffer::makeDocBookFile(string const & fname, int column)
                if(!command_stack[j].empty())
                        sgmlCloseTag(ofs, j, command_stack[j]);
 
-       ofs << "\n\n";
-       sgmlCloseTag(ofs, 0, top_element);
+       if (!only_body) {
+               ofs << "\n\n";
+               sgmlCloseTag(ofs, 0, top_element);
+       }
 
        ofs.close();
        // How to check for successful close
index 6e02dfce38503e0a1900eb282a250601c99e8975..9f968892a87cc27aa5f44ec52e2b7ec8e3e33a11 100644 (file)
@@ -171,9 +171,11 @@ public:
        int runChktex();
 
        ///
-       void makeLinuxDocFile(string const & filename, int column);
+       void makeLinuxDocFile(string const & filename,
+                             bool nice, bool only_body = false);
        ///
-       void makeDocBookFile(string const & filename, int column);
+       void makeDocBookFile(string const & filename,
+                            bool nice, bool only_body = false);
 
        /// returns the main language for the buffer (document)
        string GetLanguage() const {
index 3f511181550d4d5e6de77c8c551f98e7f97ed2a0..9bc670cf7b343667920d05e403d89337df2ae623 100644 (file)
@@ -404,8 +404,115 @@ int InsetInclude::Latex(Buffer const *, ostream & os,
 }
 
 
+int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const
+{
+       // Do nothing if no file name has been specified
+       if (getContents().empty())
+               return 0;
+    
+       string incfile(getContents());
+
+       if (loadIfNeeded()) {
+               Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+               // write it to a file (so far the complete file)
+               string writefile = ChangeExtension(getFileName(), ".sgml");
+               if (!master->tmppath.empty() && !master->niceFile) {
+                       incfile = subst(incfile, '/','@');
+                       writefile = AddName(master->tmppath, incfile);
+               } else
+                       writefile = getFileName();
+
+               if(IsLyXFilename(getFileName()))
+                       writefile = ChangeExtension(writefile, ".sgml");
+
+               lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+               lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+               
+               tmp->makeLinuxDocFile(writefile, master->niceFile, true);
+       } 
+
+       if (isVerb()) {
+               os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+       } else 
+               os << '&' << include_label << ';';
+       
+       return 0;
+}
+
+
+int InsetInclude::DocBook(Buffer const *, ostream & os) const
+{
+       // Do nothing if no file name has been specified
+       if (getContents().empty())
+               return 0;
+    
+       string incfile(getContents());
+
+       if (loadIfNeeded()) {
+               Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+               // write it to a file (so far the complete file)
+               string writefile = ChangeExtension(getFileName(), ".sgml");
+               if (!master->tmppath.empty() && !master->niceFile) {
+                       incfile = subst(incfile, '/','@');
+                       writefile = AddName(master->tmppath, incfile);
+               } else
+                       writefile = getFileName();
+               if(IsLyXFilename(getFileName()))
+                       writefile = ChangeExtension(writefile, ".sgml");
+
+               lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+               lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+               
+               tmp->makeDocBookFile(writefile, master->niceFile, true);
+       } 
+
+       if (isVerb()) {
+               os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+       } else 
+               os << '&' << include_label << ';';
+       
+       return 0;
+}
+
+
+static unsigned int unique_id() {
+       static unsigned int seed=1000;
+
+       return ++seed;
+}
+
+
 void InsetInclude::Validate(LaTeXFeatures & features) const
 {
+
+#ifdef HAVE_SSTREAM
+       std::ostringstream ost;
+       ost << "file" << unique_id();
+       include_label = ost.str();
+#else
+       char ctmp[16];
+       ostrstream ost(ctmp,16);
+       ost << "file" << unique_id() << '\0';
+       include_label = ost.str();
+#endif
+
+       string incfile(getContents());
+       string writefile = ChangeExtension(getFileName(), ".sgml");
+       if (!master->tmppath.empty() && !master->niceFile) {
+               incfile = subst(incfile, '/','@');
+               writefile = AddName(master->tmppath, incfile);
+       } else
+               // writefile = getFileName();
+               // Use the relative path.
+               writefile = incfile;
+
+       if(IsLyXFilename(getFileName()))
+               writefile = ChangeExtension(writefile, ".sgml");
+
+       features.IncludedFiles[include_label] = writefile;
+
        if (isVerb())
                features.verbatim = true;
 
index 90c1f71ef933a5d9659f2852b1a38bf169abdb9b..8bb15af6310dba4808c3e681e9050f52ad04e82a 100644 (file)
@@ -58,6 +58,10 @@ public:
        /// 
        int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
        ///
+       int Linuxdoc(Buffer const *, std::ostream &) const;
+       ///
+       int DocBook(Buffer const *, std::ostream &) const;
+       ///
        void Validate(LaTeXFeatures &) const;
        
         /// Input inserts anything inside a paragraph, Display can give some visual feedback 
@@ -120,6 +124,8 @@ private:
        Buffer * master;
        ///
        string filename;
+       ///
+       string include_label;
 };
 
 
index ebf9ceb8144c41f16f6f8cea1c8327de5067804c..b8cbbb89a2e43cfbac7b5a15b946f49bbcad928e 100644 (file)
@@ -743,7 +743,7 @@ void MenuMakeLinuxDoc(Buffer * buffer)
        ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
                                          MakeDisplayPath(s),"'...");
        
-       buffer->makeLinuxDocFile(s, 65);
+       buffer->makeLinuxDocFile(s, true);
        buffer->redraw();
        ShowMessage(buffer, _("LinuxDoc SGML file save as"),
                                          MakeDisplayPath(s)); 
@@ -770,7 +770,7 @@ void MenuMakeDocBook(Buffer * buffer)
        ShowMessage(buffer, _("Building DocBook SGML file `"),
                                          MakeDisplayPath(s), "'..."); 
        
-       buffer->makeDocBookFile(s, 65);
+       buffer->makeDocBookFile(s, true);
        buffer->redraw();
        ShowMessage(buffer, _("DocBook SGML file save as"),
                                          MakeDisplayPath(s)); 
@@ -1212,7 +1212,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
        
        if (!bv->available())
                return 0;
-       bv->buffer()->makeLinuxDocFile(name, 0);
+       bv->buffer()->makeLinuxDocFile(name, false);
 
        // CHECK remove this once we have a proper geometry class
 
@@ -1273,7 +1273,7 @@ int RunDocBook(int flag, string const & filename)
        if (!current_view->available())
                return 0;
        
-       current_view->buffer()->makeDocBookFile(name, 0);
+       current_view->buffer()->makeDocBookFile(name, false);
 
        // Shall this code go or should it stay? (Lgb)
        // This code is a placeholder for future implementation. (Jose')
index 585ef8da557f40a09efbfe98650ca25f29d26451..db2e00c1aa08b3b3752b2141587736e135d6ec5c 100644 (file)
@@ -682,6 +682,7 @@ bool LyX::easyParse(int * argc, char * argv[])
                                        type = "ascii";
 
                                if (type == "latex" || type == "postscript"
+                                   || type == "linuxdoc" || type == "docbook"
                                    || type == "ascii" || type == "html") 
                                        batch_command = "buffer-export " + type;
                                else