]> git.lyx.org Git - lyx.git/blobdiff - src/CmdDef.cpp
Disable CheckTeX while buffer is processed
[lyx.git] / src / CmdDef.cpp
index f7dbb71a0921a167a0efeaa488f6240505b44f5c..7f2f0a654c28a3d6832da80e3f1196e2da449dd6 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 namespace std;
@@ -27,42 +27,32 @@ using namespace lyx::support;
 
 namespace lyx {
 
-namespace {
-
-enum CmdDefTags {
-       BN_DEFFILE,
-       BN_DEFINE
-};
-
-keyword_item cmdDefTags[] = {
-       { "\\def_file", BN_DEFFILE },
-       { "\\define", BN_DEFINE }
-};
-
-}
-
-
 bool CmdDef::read(string const & def_file)
 {
-       const int cmdDefCount = sizeof(cmdDefTags) / sizeof(keyword_item);
+       enum {
+               BN_DEFFILE,
+               BN_DEFINE
+       };
 
-       Lexer lexrc(cmdDefTags, cmdDefCount);
-       if (lyxerr.debugging(Debug::PARSER))
-               lexrc.printTable(lyxerr);
+       LexerKeyword cmdDefTags[] = {
+               { "\\def_file", BN_DEFFILE },
+               { "\\define", BN_DEFINE }
+       };
 
+       Lexer lex(cmdDefTags);
        FileName const tmp(i18nLibFileSearch("commands", def_file, "def"));
-       lexrc.setFile(tmp);
-       if (!lexrc.isOK()) {
-               lyxerr << "CmdDef::read: cannot open def file:"
-                      << tmp << endl;
+       lex.setContext("CmdDef::read");
+       lex.setFile(tmp);
+       if (!lex.isOK()) {
+               LYXERR0( "CmdDef::read: cannot open def file:" << tmp);
                return false;
        }
 
        bool error = false;
-       while (lexrc.isOK()) {
-               switch (lexrc.lex()) {
+       while (lex.isOK()) {
+               switch (lex.lex()) {
                case Lexer::LEX_UNDEF:
-                       lexrc.printError("Unknown tag `$$Token'");
+                       lex.printError("Unknown tag");
                        error = true;
                        continue;
                case Lexer::LEX_FEOF:
@@ -71,45 +61,48 @@ bool CmdDef::read(string const & def_file)
                {
                        string name, def;
 
-                       if (lexrc.next()) {
-                               name = lexrc.getString();
+                       if (lex.next()) {
+                               name = lex.getString();
                        } else {
-                               lexrc.printError("BN_DEFINE: Missing command name");
+                               lex.printError("BN_DEFINE: Missing command name");
                                error = true;
                                break;
                        }
 
-                       if (lexrc.next(true)) {
-                               def = lexrc.getString();
+                       if (lex.next(true)) {
+                               def = lex.getString();
                        } else {
-                               lexrc.printError("BN_DEFINE: missing command definition");
+                               lex.printError("BN_DEFINE: missing command definition");
                                error = true;
                                break;
                        }
 
                        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:
+                               lex.printError("BN_DEFINE: Command name is empty");
+                               error = true;
+                               break;
+                       case CmdDefExists:
+                               lex.printError("BN_DEFINE: Command `" + name + "' already defined");
+                               error = true;
+                               break;
+                       case CmdDefInvalid:
+                               lex.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
+                               error = true;
+                               break;
+                       case CmdDefOk:
+                               break;
                        }
 
                        break;
                }
                case BN_DEFFILE:
-                       if (lexrc.next()) {
-                               string const tmp(lexrc.getString());
+                       if (lex.next()) {
+                               string const tmp = lex.getString();
                                error |= !read(tmp);
                        } else {
-                               lexrc.printError("BN_DEFFILE: Missing file name");
+                               lex.printError("BN_DEFFILE: Missing file name");
                                error = true;
                                break;
 
@@ -119,8 +112,7 @@ bool CmdDef::read(string const & def_file)
        }
 
        if (error)
-               lyxerr << "CmdDef::read: error while reading def file:"
-                      << tmp << endl;
+               LYXERR0("CmdDef::read: error while reading def file:" << tmp);
        return !error;
 }
 
@@ -155,24 +147,24 @@ bool CmdDef::lock(string const & name, FuncRequest & func)
 void CmdDef::release(string const & name)
 {
        string const name2 = trim(name);
-
        lockSet.erase(name2);
 }
 
-CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name, 
-                                                                                 string const & def)
+
+CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
+                                         string const & def)
 {
        string const name2 = trim(name);
 
-       if (name2.empty()) 
+       if (name2.empty())
                return CmdDefNameEmpty;
 
        if (cmdDefMap.find(name) != cmdDefMap.end())
                return CmdDefExists;
 
        FuncRequest     func = lyxaction.lookupFunc(def);
-       if (func.action == LFUN_NOACTION ||
-               func.action == LFUN_UNKNOWN_ACTION) {
+       if (func.action() == LFUN_NOACTION
+               || func.action() == LFUN_UNKNOWN_ACTION) {
                        return CmdDefInvalid;
        }