1 /** The .tex to .lyx converter
2 \author André Pönitz (2003)
11 #include "lyxtextclass.h"
26 using std::istringstream;
28 using std::ostringstream;
29 using std::stringstream;
33 // Hacks to allow the thing to link in the lyxlayout stuff
34 string system_lyxdir = "../../../lib";
35 string build_lyxdir = "../../lib";
36 string user_lyxdir = ".";
37 Debug::type const Debug::ANY = Debug::type(0);
40 void LyX::emergencyCleanup() {}
43 void handle_comment(Parser & p)
47 Token const & t = p.get_token();
48 if (t.cat() == catNewline)
52 //cerr << "comment: " << s << "\n";
57 string const trim(string const & a, char const * p)
64 string::size_type r = a.find_last_not_of(p);
65 string::size_type l = a.find_first_not_of(p);
67 // Is this the minimal test? (lgb)
68 if (r == string::npos && l == string::npos)
71 return a.substr(l, r - l + 1);
75 void split(string const & s, vector<string> & result, char delim)
77 //cerr << "split 1: '" << s << "'\n";
80 while (getline(is, t, delim))
82 //cerr << "split 2\n";
86 string join(vector<string> const & input, char const * delim)
89 for (size_t i = 0; i < input.size(); ++i) {
98 char const ** is_known(string const & str, char const ** what)
100 for ( ; *what; ++what)
108 // current stack of nested environments
109 vector<string> active_environments;
112 string active_environment()
114 return active_environments.empty() ? string() : active_environments.back();
118 void clean_layouts(istream & is, ostream & os)
123 while (getline(is, line)) {
124 string tline = trim(line, " ");
125 if (line.substr(0, 8) == "\\layout ") {
126 //cerr << "layout: " << line << "\n";
129 } else if (eating && tline.empty()) {
130 //cerr << "eat empty line\n";
131 } else if (line.substr(0, 13) == "\\begin_deeper") {
135 //cerr << "ordinary line\n";
138 os << last << "\n\n";
146 int main(int argc, char * argv[])
149 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
153 ifstream is(argv[1]);
158 LyXTextClass textclass = parse_preamble(p, ss);
159 active_environments.push_back("document");
160 parse_text(p, ss, FLAG_END, true, textclass);
161 ss << "\n\\the_end\n";
164 clean_layouts(ss, cout);