1 /** The .tex to .lyx converter
2 \author André Pönitz (2003)
11 #include "lyxtextclass.h"
12 #include "support/path_defines.h"
13 #include "support/os.h"
28 using std::istringstream;
30 using std::ostringstream;
31 using std::stringstream;
35 // Hacks to allow the thing to link in the lyxlayout stuff
36 Debug::type const Debug::ANY = Debug::type(0);
39 void LyX::emergencyCleanup() {}
42 void handle_comment(Parser & p)
46 Token const & t = p.get_token();
47 if (t.cat() == catNewline)
51 //cerr << "comment: " << s << "\n";
56 string const trim(string const & a, char const * p)
63 string::size_type r = a.find_last_not_of(p);
64 string::size_type l = a.find_first_not_of(p);
66 // Is this the minimal test? (lgb)
67 if (r == string::npos && l == string::npos)
70 return a.substr(l, r - l + 1);
74 void split(string const & s, vector<string> & result, char delim)
76 //cerr << "split 1: '" << s << "'\n";
79 while (getline(is, t, delim))
81 //cerr << "split 2\n";
85 string join(vector<string> const & input, char const * delim)
88 for (size_t i = 0; i < input.size(); ++i) {
97 char const ** is_known(string const & str, char const ** what)
99 for ( ; *what; ++what)
107 // current stack of nested environments
108 vector<string> active_environments;
111 string active_environment()
113 return active_environments.empty() ? string() : active_environments.back();
117 void clean_layouts(istream & is, ostream & os)
122 while (getline(is, line)) {
123 string tline = trim(line, " ");
124 if (line.substr(0, 8) == "\\layout ") {
125 //cerr << "layout: " << line << "\n";
128 } else if (eating && tline.empty()) {
129 //cerr << "eat empty line\n";
130 } else if (line.substr(0, 13) == "\\begin_deeper") {
134 //cerr << "ordinary line\n";
137 os << last << "\n\n";
145 int main(int argc, char * argv[])
148 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
152 lyx::support::os::init(&argc, &argv);
153 lyx::support::setLyxPaths();
155 ifstream is(argv[1]);
160 LyXTextClass textclass = parse_preamble(p, ss);
161 active_environments.push_back("document");
162 parse_text(p, ss, FLAG_END, true, textclass);
163 ss << "\n\\the_end\n";
166 clean_layouts(ss, cout);