]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_hash.C
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / math_hash.C
index c8f221d4457ce299ae527d59dad6f6f3939b95e7..dcc7643a130755148559b5ec585fee340afeadd8 100644 (file)
@@ -1,35 +1,33 @@
 #include <config.h>
 
 #include "math_parser.h"
+#include "math_metricsinfo.h"
 #include "lyxlex.h"
 #include "debug.h"
 #include "support/filetools.h" // LibFileSearch
-#include "support/lyxfunctional.h"
 
-#include <vector>
-#include <algorithm>
+#include <map>
 
-using std::endl;
-
-bool operator<(const latexkeys & a, const latexkeys & b)
-{
-       return string(a.name) < string(b.name);
-}
+using std::map;
 
 namespace {
 
-// This lists needs to remain sorted all the time!
+// file scope
+typedef map<string, latexkeys> WordList;
+WordList theWordList;
 
-struct latexkeys_a {
+
+struct key_type {
        ///
        char const * name;
        ///
-       short token;
+       MathTokenEnum token;
        ///
        unsigned int id;
 };
 
-latexkeys_a wordlist_array[] = 
+
+key_type wordlist_array[] =
 {
        {"!",  LM_TK_SPACE, 0},
        {"#",  LM_TK_SPECIAL, '#'},
@@ -44,49 +42,51 @@ latexkeys_a wordlist_array[] =
        {";",  LM_TK_SPACE, 3},
        {"Pr",  LM_TK_FUNCLIM, 0},
        {"[",  LM_TK_BEGIN, LM_OT_EQUATION},
-       {"\\",  LM_TK_NEWLINE, static_cast<unsigned>(-1)}, // -1 needed in mathed_parse_lines!
        {"]",  LM_TK_END, LM_OT_EQUATION},
        {"_",  LM_TK_SPECIAL, '_'},
-       {"acute",  LM_TK_DECORATION, LM_acute},
+       {"acute",  LM_TK_DECORATION, 0},
        {"arccos",  LM_TK_FUNC, 0},
        {"arcsin",  LM_TK_FUNC, 0},
        {"arctan",  LM_TK_FUNC, 0},
        {"arg",  LM_TK_FUNC, 0},
        {"atop",  LM_TK_ATOP, 0},
-       {"backslash",  LM_TK_SPECIAL, '\\'},
-       {"bar",  LM_TK_DECORATION, LM_bar},
+       {"bar",  LM_TK_DECORATION, 0},
        {"begin",  LM_TK_BEGIN, 0},
+       {"bf",  LM_TK_OLDFONT, LM_TC_BF},
        {"binom",  LM_TK_BINOM, 0},
        {"bmod",  LM_TK_FUNC, 0},
-       {"breve",  LM_TK_DECORATION, LM_breve},
+       {"breve",  LM_TK_DECORATION, 0},
        {"cal",  LM_TK_OLDFONT, LM_TC_CAL},
-       {"cdots",  LM_TK_DOTS, LM_cdots},
-       {"check",  LM_TK_DECORATION, LM_check},
+       {"cdots",  LM_TK_DOTS, 0},
+       {"check",  LM_TK_DECORATION, 0},
        {"choose",  LM_TK_CHOOSE, 0},
        {"cos",  LM_TK_FUNC, 0},
        {"cosh",  LM_TK_FUNC, 0},
        {"cot",  LM_TK_FUNC, 0},
        {"coth",  LM_TK_FUNC, 0},
        {"csc",  LM_TK_FUNC, 0},
-       {"ddot",  LM_TK_DECORATION, LM_ddot},
-       {"ddots",  LM_TK_DOTS, LM_ddots},
+       {"ddot",  LM_TK_DECORATION, 0},
+       {"dddot",  LM_TK_DECORATION, 0},
+       {"ddots",  LM_TK_DOTS, 0},
        {"deg",  LM_TK_FUNC, 0},
        {"det",  LM_TK_FUNCLIM, 0},
        {"dim",  LM_TK_FUNC, 0},
-       //{"displaystyle",  LM_TK_STY, LM_ST_DISPLAY},
-       {"dot",  LM_TK_DECORATION, LM_dot},
+       {"displaystyle",  LM_TK_STY, LM_ST_DISPLAY},
+       {"dot",  LM_TK_DECORATION, 0},
        {"end",  LM_TK_END, 0},
        {"exp",  LM_TK_FUNC, 0},
        {"frac",  LM_TK_FRAC, 0},
+       {"frak",  LM_TK_FONT, LM_TC_EUFRAK},
        {"gcd",  LM_TK_FUNCLIM, 0},
-       {"grave",  LM_TK_DECORATION, LM_grave},
-       {"hat",  LM_TK_DECORATION, LM_hat},
+       {"grave",  LM_TK_DECORATION, 0},
+       {"hat",  LM_TK_DECORATION, 0},
        {"hom",  LM_TK_FUNC, 0},
        {"inf",  LM_TK_FUNCLIM, 0},
+       {"it",  LM_TK_OLDFONT, LM_TC_IT},
        {"ker",  LM_TK_FUNC, 0},
-       {"kern",  LM_TK_KERN, 0},
        {"label",  LM_TK_LABEL, 0},
-       {"ldots",  LM_TK_DOTS, LM_ldots},
+       {"lefteqn",  LM_TK_LEFTEQN, 1},
+       {"ldots",  LM_TK_DOTS, 0},
        {"left",  LM_TK_LEFT, 0},
        {"lg",  LM_TK_FUNC, 0},
        {"lim",  LM_TK_FUNCLIM, 0},
@@ -95,32 +95,38 @@ latexkeys_a wordlist_array[] =
        {"limsup",  LM_TK_FUNCLIM, 0},
        {"ln",  LM_TK_FUNC, 0},
        {"log",  LM_TK_FUNC, 0},
+       {"lyxbox",  LM_TK_BOX, 0},
+       {"lyxnegspace",  LM_TK_SPACE, 6},
        {"mathbb",  LM_TK_FONT, LM_TC_BB},
        {"mathbf",  LM_TK_FONT, LM_TC_BF},
        {"mathcal",  LM_TK_FONT, LM_TC_CAL},
+       {"mathfrak",  LM_TK_FONT, LM_TC_EUFRAK},
        {"mathit",  LM_TK_FONT, LM_TC_IT},
        {"mathnormal",  LM_TK_FONT, LM_TC_VAR},
        {"mathrm",  LM_TK_FONT, LM_TC_RM},
        {"mathsf",  LM_TK_FONT, LM_TC_SF},
        {"mathtt",  LM_TK_FONT, LM_TC_TT},
        {"max",  LM_TK_FUNCLIM, 0},
+       //{"mbox",  LM_TK_BOX, 0},
        {"min",  LM_TK_FUNCLIM, 0},
        {"newcommand",  LM_TK_NEWCOMMAND, 0 },
        {"nolimits",  LM_TK_LIMIT, static_cast<unsigned>(-1)},
        {"nonumber",  LM_TK_NONUM, 0},
-       {"not",  LM_TK_NOT, LM_not},
+       {"not",  LM_TK_NOT, 0},
        {"over",  LM_TK_OVER, 0},
-       {"overbrace",  LM_TK_DECORATION, LM_overbrace},
-       {"overleftarrow",  LM_TK_DECORATION, LM_overleftarrow},
-       {"overline",  LM_TK_DECORATION, LM_overline},
-       {"overrightarrow",  LM_TK_DECORATION, LM_overightarrow},
+       {"overbrace",  LM_TK_DECORATION, 0},
+       {"overleftarrow",  LM_TK_DECORATION, 0},
+       {"overline",  LM_TK_DECORATION, 0},
+       {"overrightarrow",  LM_TK_DECORATION, 0},
+       {"overleftrightarrow", LM_TK_DECORATION, 0},
        {"protect",  LM_TK_PROTECT, 0},
        {"qquad",  LM_TK_SPACE, 5},
        {"quad",  LM_TK_SPACE, 4},
        {"right",  LM_TK_RIGHT, 0},
+       {"rm",  LM_TK_OLDFONT, LM_TC_RM},
        {"root",  LM_TK_ROOT, 0},
-       //{"scriptscriptstyle",  LM_TK_STY, LM_ST_SCRIPTSCRIPT},
-       //{"scriptstyle",  LM_TK_STY, LM_ST_SCRIPT},
+       {"scriptscriptstyle",  LM_TK_STY, LM_ST_SCRIPTSCRIPT},
+       {"scriptstyle",  LM_TK_STY, LM_ST_SCRIPT},
        {"sec",  LM_TK_FUNC, 0},
        {"sin",  LM_TK_FUNC, 0},
        {"sinh",  LM_TK_FUNC, 0},
@@ -130,110 +136,103 @@ latexkeys_a wordlist_array[] =
        {"tan",  LM_TK_FUNC, 0},
        {"tanh",  LM_TK_FUNC, 0},
        {"textrm",  LM_TK_FONT, LM_TC_TEXTRM},
-       //{"textstyle",  LM_TK_STY, LM_ST_TEXT},
-       {"tilde",  LM_TK_DECORATION, LM_tilde},
-       {"underbrace",  LM_TK_DECORATION, LM_underbrace},
-       {"underline",  LM_TK_DECORATION, LM_underline},
-       {"vdots",  LM_TK_DOTS, LM_vdots},
-       {"vec",  LM_TK_DECORATION, LM_vec},
-       {"widehat",  LM_TK_DECORATION, LM_widehat},
-       {"widetilde",  LM_TK_DECORATION, LM_widetilde},
+       {"textstyle",  LM_TK_STY, LM_ST_TEXT},
+       {"tilde",  LM_TK_DECORATION, 0},
+       {"tt",  LM_TK_OLDFONT, LM_TC_TT},
+       {"underbar",  LM_TK_DECORATION, 0},
+       {"underbrace",  LM_TK_DECORATION, 0},
+       {"underleftarrow", LM_TK_DECORATION, 0},
+       {"underline",  LM_TK_DECORATION, 0},
+       {"underrightarrow", LM_TK_DECORATION, 0},
+       {"underleftrightarrow", LM_TK_DECORATION, 0},
+       {"underset",  LM_TK_UNDERSET, 0},
+       {"vdots",  LM_TK_DOTS, 0},
+       {"vec",  LM_TK_DECORATION, 0},
+       {"widehat",  LM_TK_DECORATION, 0},
+       {"widetilde",  LM_TK_DECORATION, 0},
        {"{",  LM_TK_SPECIAL, '{'},
-       {"|",  LM_TK_UNDEF, '|'},
-       {"}",  LM_TK_SPECIAL, '}'},
-       {"", LM_TK_SPECIAL, 0}
+       {"}",  LM_TK_SPECIAL, '}'}
 };
 
 
-std::vector<latexkeys> wordlist;
-
-bool initialized = false;
 
-} // namespace anon
+MathTokenEnum tokenEnum(const string & font)
+{
+       if (font == "cmr")
+               return LM_TK_CMR;
+       if (font == "cmsy")
+               return LM_TK_CMSY;
+       if (font == "cmm")
+               return LM_TK_CMM;
+       if (font == "cmex")
+               return LM_TK_CMEX;
+       if (font == "msa")
+               return LM_TK_MSA;
+       if (font == "msb")
+               return LM_TK_MSB;
+       return LM_TK_SYM;
+}
 
 
-void ReadSymbols(string const & filename)
+void readSymbols(string const & filename)
 {
        LyXLex lex(0, 0);
        lex.setFile(filename);
-       while (lex.isOK()) {
+       while (lex.isOK() && lex.next()) {
                latexkeys tmp;
-               string font;
-               string type;
-               
+               tmp.name = lex.getString();
                if (lex.next())
-                       tmp.name = lex.getString();
-               else
-                       break;
-
-               if (lex.next())
-                       font = lex.getString();
+                       tmp.token = tokenEnum(lex.getString());
                if (lex.next())
                        tmp.latex_font_id = lex.getInteger();
                if (lex.next())
                        tmp.id = lex.getInteger();
                if (lex.next())
-                       type = lex.getString();
-
-               if (font == "cmr")
-                       tmp.token = LM_TK_CMR;
-               else if (font == "cmsy")
-                       tmp.token = LM_TK_CMSY;
-               else if (font == "cmm")
-                       tmp.token = LM_TK_CMM;
-               else if (font == "cmex")
-                       tmp.token = LM_TK_CMEX;
-               else if (font == "msa")
-                       tmp.token = LM_TK_MSA;
-               else if (font == "msb")
-                       tmp.token = LM_TK_MSB;
-               else
-                       tmp.token = LM_TK_SYM;
-
-               if (type == "mathrel")
-                       tmp.type = LMB_RELATION;
-               else if (type == "mathbin")
-                       tmp.type = LMB_OPERATOR;
+                       tmp.type = lex.getString();
+               if (lex.next())
+                       tmp.xmlname = lex.getString();
+               if (theWordList.find(tmp.name) != theWordList.end())
+                       lyxerr << "readSymbols: token " << tmp.name
+                              << " already exists.\n";
                else
-                       tmp.type = LMB_NONE;
-
-               wordlist.push_back(tmp);
+                       theWordList[tmp.name] = tmp;
        }
 }
 
 
-void InitSymbols()
+void initSymbols()
 {
-       for (latexkeys_a * p = wordlist_array; !string(p->name).empty(); ++p) {
+       unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
+       for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
                latexkeys tmp;
-               tmp.name   = p->name;
-               tmp.token  = p->token;
-               tmp.id     = p->id;
-               tmp.type   = LMB_NONE;
+               tmp.name          = p->name;
+               tmp.token         = p->token;
+               tmp.id            = p->id;
                tmp.latex_font_id = 0;
-               wordlist.push_back(tmp);
+               theWordList[p->name] = tmp;
        }
 
-       lyxerr[Debug::MATHED] << "Reading symbols file\n";
+       lyxerr[Debug::MATHED] << "reading symbols file\n";
        string const file = LibFileSearch(string(), "symbols");
        if (file.empty())
-               lyxerr << "Could not find symbols file" << endl;
+               lyxerr << "Could not find symbols file\n";
        else
-               ReadSymbols(file);
-
-       std::sort(wordlist.begin(), wordlist.end());
+               readSymbols(file);
 }
 
 
+} // namespace anon
+
+
 latexkeys const * in_word_set(string const & str)
 {
+       static bool initialized = false;
+
        if (!initialized) {
-               InitSymbols();
+               initSymbols();
                initialized = true;
        }
 
-       std::vector<latexkeys>::iterator it =
-               std::find_if(wordlist.begin(), wordlist.end(),
-                            lyx::compare_memfun(&latexkeys::Name, str));
-       return  (it != wordlist.end()) ? &(*it) : 0;
+       WordList::iterator it = theWordList.find(str);
+       return (it != theWordList.end()) ? &(it->second) : 0;
 }