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"
26 using namespace lyx::support
;
30 bool CmdDef::read(string
const & def_file
)
37 LexerKeyword cmdDefTags
[] = {
38 { "\\def_file", BN_DEFFILE
},
39 { "\\define", BN_DEFINE
}
42 Lexer
lex(cmdDefTags
);
43 FileName
const tmp(i18nLibFileSearch("commands", def_file
, "def"));
44 lex
.setContext("CmdDef::read");
47 LYXERR0( "CmdDef::read: cannot open def file:" << tmp
);
54 case Lexer::LEX_UNDEF
:
55 lex
.printError("Unknown tag");
65 name
= lex
.getString();
67 lex
.printError("BN_DEFINE: Missing command name");
73 def
= lex
.getString();
75 lex
.printError("BN_DEFINE: missing command definition");
80 newCmdDefResult e
= newCmdDef(name
, def
);
83 lex
.printError("BN_DEFINE: Command name is empty");
87 lex
.printError("BN_DEFINE: Command `" + name
+ "' already defined");
91 lex
.printError("BN_DEFINE: Command definition for `" + name
+ "' is not valid");
102 string
const tmp
= lex
.getString();
105 lex
.printError("BN_DEFFILE: Missing file name");
115 LYXERR0("CmdDef::read: error while reading def file:" << tmp
);
120 bool CmdDef::lock(string
const & name
, FuncRequest
& func
)
122 if (cmdDefMap
.empty()) {
123 func
= FuncRequest::unknown
;
127 string
const name2
= trim(name
);
129 if (lockSet
.find(name2
) != lockSet
.end()) {
130 func
= FuncRequest::noaction
;
134 CmdDefMap::const_iterator pos
= cmdDefMap
.find(name2
);
136 if (pos
== cmdDefMap
.end()) {
137 func
= FuncRequest::unknown
;
141 lockSet
.insert(name2
);
147 void CmdDef::release(string
const & name
)
149 string
const name2
= trim(name
);
150 lockSet
.erase(name2
);
154 CmdDef::newCmdDefResult
CmdDef::newCmdDef(string
const & name
,
157 string
const name2
= trim(name
);
160 return CmdDefNameEmpty
;
162 if (cmdDefMap
.find(name
) != cmdDefMap
.end())
165 FuncRequest func
= lyxaction
.lookupFunc(def
);
166 if (func
.action
== LFUN_NOACTION
167 || func
.action
== LFUN_UNKNOWN_ACTION
) {
168 return CmdDefInvalid
;
171 cmdDefMap
[name2
] = func
;