#include "lyxtextclass.h"
#include "support/path_defines.h"
#include "support/filetools.h"
+#include "support/lstrings.h"
+#include "support/lyxlib.h"
#include "support/os.h"
#include <boost/function.hpp>
using std::vector;
using std::map;
+using lyx::support::isStrUnsignedInt;
+using lyx::support::ltrim;
+using lyx::support::rtrim;
+using lyx::support::strToUnsignedInt;
using lyx::support::system_lyxdir;
using lyx::support::user_lyxdir;
using lyx::support::IsFileReadable;
}
-char const ** is_known(string const & str, char const ** what)
+char const * const * is_known(string const & str, char const * const * what)
{
for ( ; *what; ++what)
if (str == *what)
map<string, vector<ArgumentType> > known_commands;
+void add_known_command(string const & command, string const & o1,
+ bool o2)
+{
+ // We have to handle the following cases:
+ // definition o1 o2 invocation result
+ // \newcommand{\foo}{bar} "" false \foo bar
+ // \newcommand{\foo}[1]{bar #1} "[1]" false \foo{x} bar x
+ // \newcommand{\foo}[1][]{bar #1} "[1]" true \foo bar
+ // \newcommand{\foo}[1][]{bar #1} "[1]" true \foo[x] bar x
+ // \newcommand{\foo}[1][x]{bar #1} "[1]" true \foo[x] bar x
+ unsigned int nargs = 0;
+ vector<ArgumentType> arguments;
+ string const opt1 = rtrim(ltrim(o1, "["), "]");
+ if (isStrUnsignedInt(opt1)) {
+ // The command has arguments
+ nargs = strToUnsignedInt(opt1);
+ if (nargs > 0 && o2) {
+ // The first argument is optional
+ arguments.push_back(optional);
+ --nargs;
+ }
+ }
+ for (unsigned int i = 0; i < nargs; ++i)
+ arguments.push_back(required);
+ known_commands[command] = arguments;
+}
+
+
namespace {
}
}
+
+// path of the parsed file
+string masterFilePath;
+
} // anonymous namespace
+string getMasterFilePath()
+{
+ return masterFilePath;
+}
+
+
void tex2lyx(std::istream &is, std::ostream &os)
{
Parser p(is);
Context context(true, textclass);
parse_text(p, ss, FLAG_END, true, context);
context.check_end_layout(ss);
- ss << "\n\\end_document\n";
+ ss << "\n\\end_body\n\\end_document\n";
active_environments.pop_back();
ss.seekg(0);
os << ss.str();
return 2;
}
- lyx::support::os::init(&argc, &argv);
+ lyx::support::os::init(argc, argv);
lyx::support::setLyxPaths();
string const system_syntaxfile = lyx::support::LibFileSearch("reLyX", "syntax.default");
<< "\" for reading." << endl;
return 2;
}
+
+ if (lyx::support::AbsolutePath(argv[1]))
+ masterFilePath = lyx::support::OnlyPath(argv[1]);
+ else
+ masterFilePath = lyx::support::getcwd();
+
ifstream is(argv[1]);
tex2lyx(is, cout);