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 "FuncRequest.h"
16 #include "LyXAction.h"
19 #include "support/debug.h"
20 #include "support/FileName.h"
21 #include "support/filetools.h"
22 #include "support/lstrings.h"
27 using namespace lyx::support;
31 bool CmdDef::read(string const & def_file)
38 LexerKeyword cmdDefTags[] = {
39 { "\\def_file", BN_DEFFILE },
40 { "\\define", BN_DEFINE }
43 Lexer lex(cmdDefTags);
44 FileName const tmp(i18nLibFileSearch("commands", def_file, "def"));
45 lex.setContext("CmdDef::read");
48 LYXERR0( "CmdDef::read: cannot open def file:" << tmp);
55 case Lexer::LEX_UNDEF:
56 lex.printError("Unknown tag");
66 name = lex.getString();
68 lex.printError("BN_DEFINE: Missing command name");
74 def = lex.getString();
76 lex.printError("BN_DEFINE: missing command definition");
81 newCmdDefResult e = newCmdDef(name, def);
84 lex.printError("BN_DEFINE: Command name is empty");
88 lex.printError("BN_DEFINE: Command `" + name + "' already defined");
92 lex.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
103 string const stmp = lex.getString();
104 error |= !read(stmp);
106 lex.printError("BN_DEFFILE: Missing file name");
116 LYXERR0("CmdDef::read: error while reading def file:" << tmp);
121 bool CmdDef::lock(string const & name, FuncRequest & func)
123 if (cmdDefMap.empty()) {
124 func = FuncRequest::unknown;
128 string const name2 = trim(name);
130 if (lockSet.find(name2) != lockSet.end()) {
131 func = FuncRequest::noaction;
135 CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
137 if (pos == cmdDefMap.end()) {
138 func = FuncRequest::unknown;
142 lockSet.insert(name2);
148 void CmdDef::release(string const & name)
150 string const name2 = trim(name);
151 lockSet.erase(name2);
155 CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
158 string const name2 = trim(name);
161 return CmdDefNameEmpty;
163 if (cmdDefMap.find(name) != cmdDefMap.end())
166 FuncRequest func = lyxaction.lookupFunc(def);
167 if (func.action() == LFUN_NOACTION
168 || func.action() == LFUN_UNKNOWN_ACTION) {
169 return CmdDefInvalid;
172 cmdDefMap[name2] = func;