// {[(
-#include <config.h>
-
-#include "Lsstream.h"
#include "tex2lyx.h"
+#include "context.h"
+
+#include "debug.h"
+#include "lyx_main.h"
+#include "lyxtextclass.h"
+#include "support/path_defines.h"
+#include "support/os.h"
#include <cctype>
#include <fstream>
#include <iostream>
#include <string>
+#include <sstream>
#include <vector>
using std::cout;
using std::string;
using std::vector;
+// Hacks to allow the thing to link in the lyxlayout stuff
+Debug::type const Debug::ANY = Debug::type(0);
+DebugStream lyxerr;
+void LyX::emergencyCleanup() {}
void handle_comment(Parser & p)
{
s += t.asString();
}
//cerr << "comment: " << s << "\n";
- p.skipSpaces();
+ p.skip_spaces();
}
}
-void clean_layouts(istream & is, ostream & os)
-{
- string last;
- string line;
- bool eating = false;
- while (getline(is, line)) {
- string tline = trim(line, " ");
- if (line.substr(0, 8) == "\\layout ") {
- //cerr << "layout: " << line << "\n";
- last = line;
- eating = true;
- } else if (eating && tline.empty()) {
- //cerr << "eat empty line\n";
- } else if (line.substr(0, 13) == "\\begin_deeper") {
- os << line << "\n";
- } else {
- // ordinary line
- //cerr << "ordinary line\n";
- if (eating) {
- eating = false;
- os << last << "\n\n";
- }
- os << line << "\n";
- }
- }
-}
-
-
int main(int argc, char * argv[])
{
if (argc <= 1) {
return 2;
}
+ lyx::support::os::init(&argc, &argv);
+ lyx::support::setLyxPaths();
+
ifstream is(argv[1]);
Parser p(is);
//p.dump();
stringstream ss;
- parse_preamble(p, ss);
+ LyXTextClass textclass = parse_preamble(p, ss);
active_environments.push_back("document");
- parse_text(p, ss, FLAG_END, true);
- ss << "\n\\the_end\n";
+ Context context(true, textclass);
+ parse_text(p, ss, FLAG_END, true, context);
+ context.check_end_layout(ss);
+ ss << "\n\\end_document\n";
ss.seekg(0);
- clean_layouts(ss, cout);
-
+ cout << ss.str();
return 0;
}