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() {}
41 void handle_comment(Parser & p)
45 Token const & t = p.get_token();
46 if (t.cat() == catNewline)
50 //cerr << "comment: " << s << "\n";
55 string const trim(string const & a, char const * p)
62 string::size_type r = a.find_last_not_of(p);
63 string::size_type l = a.find_first_not_of(p);
65 // Is this the minimal test? (lgb)
66 if (r == string::npos && l == string::npos)
69 return a.substr(l, r - l + 1);
73 void split(string const & s, vector<string> & result, char delim)
75 //cerr << "split 1: '" << s << "'\n";
78 while (getline(is, t, delim))
80 //cerr << "split 2\n";
84 string join(vector<string> const & input, char const * delim)
87 for (size_t i = 0; i < input.size(); ++i) {
96 char const ** is_known(string const & str, char const ** what)
98 for ( ; *what; ++what)
106 // current stack of nested environments
107 vector<string> active_environments;
110 string active_environment()
112 return active_environments.empty() ? string() : active_environments.back();
116 int main(int argc, char * argv[])
119 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
123 lyx::support::os::init(&argc, &argv);
124 lyx::support::setLyxPaths();
126 ifstream is(argv[1]);
131 LyXTextClass textclass = parse_preamble(p, ss);
132 active_environments.push_back("document");
133 parse_text(p, ss, FLAG_END, true, textclass);
134 check_end_layout(ss);
135 ss << "\n\\end_document\n";