3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
19 #include "lyxtextclass.h"
20 #include "support/path_defines.h"
21 #include "support/os.h"
36 using std::istringstream;
37 using std::ostringstream;
38 using std::stringstream;
42 // Hacks to allow the thing to link in the lyxlayout stuff
43 LyXErr lyxerr(std::cerr.rdbuf());
45 void handle_comment(Parser & p)
49 Token const & t = p.get_token();
50 if (t.cat() == catNewline)
54 //cerr << "comment: " << s << "\n";
59 string const trim(string const & a, char const * p)
66 string::size_type r = a.find_last_not_of(p);
67 string::size_type l = a.find_first_not_of(p);
69 // Is this the minimal test? (lgb)
70 if (r == string::npos && l == string::npos)
73 return a.substr(l, r - l + 1);
77 void split(string const & s, vector<string> & result, char delim)
79 //cerr << "split 1: '" << s << "'\n";
82 while (getline(is, t, delim))
84 //cerr << "split 2\n";
88 string join(vector<string> const & input, char const * delim)
91 for (size_t i = 0; i < input.size(); ++i) {
100 char const ** is_known(string const & str, char const ** what)
102 for ( ; *what; ++what)
110 // current stack of nested environments
111 vector<string> active_environments;
114 string active_environment()
116 return active_environments.empty() ? string() : active_environments.back();
120 int main(int argc, char * argv[])
123 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
127 lyx::support::os::init(&argc, &argv);
128 lyx::support::setLyxPaths();
130 ifstream is(argv[1]);
135 LyXTextClass textclass = parse_preamble(p, ss);
136 active_environments.push_back("document");
137 Context context(true, textclass);
138 parse_text(p, ss, FLAG_END, true, context);
139 context.check_end_layout(ss);
140 ss << "\n\\end_document\n";