]> git.lyx.org Git - features.git/blobdiff - src/CmdDef.cpp
simplify Lexer use a bit
[features.git] / src / CmdDef.cpp
index ed7cdbb08767f71e11ae9ef0844af4a583924887..2a3158c3dd9d2c2c7ea2e25fb96356b688df2eb0 100644 (file)
 #include "Lexer.h"
 
 #include "support/debug.h"
+#include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 
 #include <ostream>
+#include <string>
 
-using std::endl;
-using std::string;
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::FileName;
-using support::i18nLibFileSearch;
-using support::trim;
-
-
 namespace {
 
 enum CmdDefTags {
@@ -38,7 +35,7 @@ enum CmdDefTags {
        BN_DEFINE
 };
 
-keyword_item cmdDefTags[] = {
+LexerKeyword cmdDefTags[] = {
        { "\\def_file", BN_DEFFILE },
        { "\\define", BN_DEFINE }
 };
@@ -48,9 +45,7 @@ keyword_item cmdDefTags[] = {
 
 bool CmdDef::read(string const & def_file)
 {
-       const int cmdDefCount = sizeof(cmdDefTags) / sizeof(keyword_item);
-
-       Lexer lexrc(cmdDefTags, cmdDefCount);
+       Lexer lexrc(cmdDefTags);
        if (lyxerr.debugging(Debug::PARSER))
                lexrc.printTable(lyxerr);
 
@@ -62,8 +57,6 @@ bool CmdDef::read(string const & def_file)
                return false;
        }
 
-       //LYXERR(Debug::KBMAP, "Reading def file:" << tmp);
-
        bool error = false;
        while (lexrc.isOK()) {
                switch (lexrc.lex()) {
@@ -95,17 +88,20 @@ bool CmdDef::read(string const & def_file)
 
                        newCmdDefResult e = newCmdDef(name, def);
                        switch (e) {
-                               case CmdDefNameEmpty:
-                                       lexrc.printError("BN_DEFINE: Command name is empty");
-                                       error = true;
-                                       break;
-                               case CmdDefExists:
-                                       lexrc.printError("BN_DEFINE: Command `" + name + "' already defined");
-                                       error = true;
-                                       break;
-                               case CmdDefInvalid:
-                                       lexrc.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
-                                       error = true;
+                       case CmdDefNameEmpty:
+                               lexrc.printError("BN_DEFINE: Command name is empty");
+                               error = true;
+                               break;
+                       case CmdDefExists:
+                               lexrc.printError("BN_DEFINE: Command `" + name + "' already defined");
+                               error = true;
+                               break;
+                       case CmdDefInvalid:
+                               lexrc.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
+                               error = true;
+                               break;
+                       case CmdDefOk:
+                               break;
                        }
 
                        break;
@@ -133,47 +129,36 @@ bool CmdDef::read(string const & def_file)
 
 bool CmdDef::lock(string const & name, FuncRequest & func)
 {
-       if (cmdDefMap.empty())
-       {
+       if (cmdDefMap.empty()) {
                func = FuncRequest::unknown;
                return false;
        }
 
        string const name2 = trim(name);
 
-       CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
-
-       if (pos == cmdDefMap.end()) 
-       {
-               func = FuncRequest::unknown;
+       if (lockSet.find(name2) != lockSet.end()) {
+               func = FuncRequest::noaction;
                return false;
        }
 
-       if (pos->second->locked)
-       {
-               func = FuncRequest::noaction;
+       CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
+
+       if (pos == cmdDefMap.end()) {
+               func = FuncRequest::unknown;
                return false;
        }
 
-       pos->second->locked = true;
-       func = pos->second->func;
+       lockSet.insert(name2);
+       func = pos->second;
        return true;
 }
 
 
 void CmdDef::release(string const & name)
 {
-       if (cmdDefMap.empty()) 
-               return;
-
        string const name2 = trim(name);
 
-       CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
-
-       if (pos == cmdDefMap.end()) 
-               return;
-
-       pos->second->locked = false;
+       lockSet.erase(name2);
 }
 
 CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name, 
@@ -193,9 +178,7 @@ CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
                        return CmdDefInvalid;
        }
 
-       boost::shared_ptr<CmdDefInfo> info;
-       info.reset(new CmdDefInfo(func));
-       cmdDefMap[name2] = info;
+       cmdDefMap[name2] = func;
 
        return CmdDefOk;
 }