3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Bernhard Roider
8 * Full author contact details are available in file CREDITS.
15 #include "LyXAction.h"
18 #include "support/debug.h"
19 #include "support/FileName.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
27 using namespace lyx::support;
38 LexerKeyword cmdDefTags[] = {
39 { "\\def_file", BN_DEFFILE },
40 { "\\define", BN_DEFINE }
46 bool CmdDef::read(string const & def_file)
48 Lexer lexrc(cmdDefTags);
49 if (lyxerr.debugging(Debug::PARSER))
50 lexrc.printTable(lyxerr);
52 FileName const tmp(i18nLibFileSearch("commands", def_file, "def"));
55 lyxerr << "CmdDef::read: cannot open def file:"
61 while (lexrc.isOK()) {
62 switch (lexrc.lex()) {
63 case Lexer::LEX_UNDEF:
64 lexrc.printError("Unknown tag `$$Token'");
74 name = lexrc.getString();
76 lexrc.printError("BN_DEFINE: Missing command name");
81 if (lexrc.next(true)) {
82 def = lexrc.getString();
84 lexrc.printError("BN_DEFINE: missing command definition");
89 newCmdDefResult e = newCmdDef(name, def);
92 lexrc.printError("BN_DEFINE: Command name is empty");
96 lexrc.printError("BN_DEFINE: Command `" + name + "' already defined");
100 lexrc.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
111 string const tmp(lexrc.getString());
114 lexrc.printError("BN_DEFFILE: Missing file name");
124 lyxerr << "CmdDef::read: error while reading def file:"
130 bool CmdDef::lock(string const & name, FuncRequest & func)
132 if (cmdDefMap.empty()) {
133 func = FuncRequest::unknown;
137 string const name2 = trim(name);
139 if (lockSet.find(name2) != lockSet.end()) {
140 func = FuncRequest::noaction;
144 CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
146 if (pos == cmdDefMap.end()) {
147 func = FuncRequest::unknown;
151 lockSet.insert(name2);
157 void CmdDef::release(string const & name)
159 string const name2 = trim(name);
161 lockSet.erase(name2);
164 CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
167 string const name2 = trim(name);
170 return CmdDefNameEmpty;
172 if (cmdDefMap.find(name) != cmdDefMap.end())
175 FuncRequest func = lyxaction.lookupFunc(def);
176 if (func.action == LFUN_NOACTION ||
177 func.action == LFUN_UNKNOWN_ACTION) {
178 return CmdDefInvalid;
181 cmdDefMap[name2] = func;