1 /** The .tex to .lyx converter
2 \author André Pönitz (2003)
12 #include "lyxtextclass.h"
13 #include "support/path_defines.h"
14 #include "support/os.h"
29 using std::istringstream;
31 using std::ostringstream;
32 using std::stringstream;
36 // Hacks to allow the thing to link in the lyxlayout stuff
37 Debug::type const Debug::ANY = Debug::type(0);
40 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 int main(int argc, char * argv[])
120 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
124 lyx::support::os::init(&argc, &argv);
125 lyx::support::setLyxPaths();
127 ifstream is(argv[1]);
132 LyXTextClass textclass = parse_preamble(p, ss);
133 active_environments.push_back("document");
134 Context context(true, textclass);
135 parse_text(p, ss, FLAG_END, true, context);
136 context.check_end_layout(ss);
137 ss << "\n\\end_document\n";