]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/preamble.C
Removed all redundant using directives from the source.
[lyx.git] / src / tex2lyx / preamble.C
index 7c565068c6d478cbf7de69a7fc2d1aaf31c27bec..777aec4695853857ba32ef7ca280253c63b52537 100644 (file)
@@ -1,5 +1,11 @@
-/** The .tex to .lyx converter
-    \author André Pönitz (2003)
+/**
+ * \file preamble.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 // {[(
 
 #include "tex2lyx.h"
 
+#include "layout.h"
+#include "lyxtextclass.h"
+#include "lyxlex.h"
+#include "support/filetools.h"
+
 #include <algorithm>
 #include <iostream>
 #include <sstream>
 #include <string>
 #include <vector>
+#include <map>
 
-using std::cerr;
-using std::endl;
-using std::getline;
-using std::istream;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
 using std::string;
 using std::vector;
 
+using lyx::support::LibFileSearch;
+
+// special columntypes
+extern std::map<char, int> special_columns;
 
 namespace {
 
@@ -125,10 +137,10 @@ void handle_package(string const & name, string const & options)
 
 
 
-void end_preamble(ostream & os)
+void end_preamble(ostream & os, LyXTextClass const & /*textclass*/)
 {
-       os << "# tex2lyx 0.0.2 created this file\n"
-          << "\\lyxformat 222\n"
+       os << "#LyX file created by  tex2lyx 0.1.2 \n"
+          << "\\lyxformat 225\n"
           << "\\textclass " << h_textclass << "\n"
           << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
        if (h_options.size())
@@ -156,14 +168,16 @@ void end_preamble(ostream & os)
           << "\\papersides " << h_papersides << "\n"
           << "\\paperpagestyle " << h_paperpagestyle << "\n"
           << "\\tracking_changes " << h_tracking_changes << "\n"
-          << "\\end_header\n\n\\layout Standard\n";
+          << "\\end_header\n";
 }
 
-
 } // anonymous namespace
 
-void parse_preamble(Parser & p, ostream & os)
+LyXTextClass const parse_preamble(Parser & p, ostream & os)
 {
+       // initialize fixed types
+       special_columns['D'] = 3;
+
        while (p.good()) {
                Token const & t = p.get_token();
 
@@ -284,6 +298,23 @@ void parse_preamble(Parser & p, ostream & os)
                        h_preamble << "\\def\\" << name << '{' << p.verbatim_item() << "}\n";
                }
 
+               else if (t.cs() == "newcolumntype") {
+                       string const name = p.getArg('{', '}');
+                       trim(name);
+                       int nargs = 0;
+                       string opts = p.getOpt();
+                       if (opts.size()) {
+                               istringstream is(string(opts, 1));
+                               //cerr << "opt: " << is.str() << "\n";
+                               is >> nargs;
+                       }
+                       special_columns[name[0]] = nargs;
+                       h_preamble << "\\newcolumntype{" << name << "}";
+                       if (nargs)
+                               h_preamble << "[" << nargs << "]";
+                       h_preamble << "{" << p.verbatim_item() << "}\n";
+               }
+
                else if (t.cs() == "setcounter") {
                        string const name = p.getArg('{', '}');
                        string const content = p.getArg('{', '}');
@@ -303,7 +334,7 @@ void parse_preamble(Parser & p, ostream & os)
                        else if (name == "parindent")
                                h_paragraph_separation = "skip";
                        else
-                               h_preamble << "\\setlength{" + name + "}{" + content + "}\n";
+                               h_preamble << "\\setlength{" << name << "}{" << content << "}\n";
                }
 
                else if (t.cs() == "par")
@@ -311,17 +342,19 @@ void parse_preamble(Parser & p, ostream & os)
 
                else if (t.cs() == "begin") {
                        string const name = p.getArg('{', '}');
-                       if (name == "document") {
-                               end_preamble(os);
-                               return;
-                       }
+                       if (name == "document")
+                               break;
                        h_preamble << "\\begin{" << name << "}";
                }
 
                else if (t.cs().size())
                        h_preamble << '\\' << t.cs() << ' ';
        }
-}
 
+       LyXTextClass textclass;
+       textclass.Read(LibFileSearch("layouts", h_textclass, "layout"));
+       end_preamble(os, textclass);
+       return textclass;
+}
 
 // }])