]> git.lyx.org Git - lyx.git/blobdiff - src/Counters.cpp
* lyx_1_6.py:
[lyx.git] / src / Counters.cpp
index 305cb17a2c344456a85c8561d561ade27a935127..cf4bfeed43f644412e9ff11710c7ece07a940d0e 100644 (file)
 
 #include "Counters.h"
 
+#include "Lexer.h"
+
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/lstrings.h"
 
-#include "support/assert.h"
+#include "support/lassert.h"
 
 #include <sstream>
 
@@ -43,6 +45,63 @@ Counter::Counter(docstring const & mc, docstring const & ls,
 }
 
 
+bool Counter::read(Lexer & lex)
+{
+       enum {
+               CT_WITHIN = 1,
+               CT_LABELSTRING,
+               CT_LABELSTRING_APPENDIX,
+               CT_END
+       };
+
+       LexerKeyword counterTags[] = {
+               { "end", CT_END },
+               { "labelstring", CT_LABELSTRING },
+               { "labelstringappendix", CT_LABELSTRING_APPENDIX },
+               { "within", CT_WITHIN }
+       };
+
+       lex.pushTable(counterTags);
+
+       bool getout = false;
+       while (!getout && lex.isOK()) {
+               int le = lex.lex();
+               switch (le) {
+                       case Lexer::LEX_UNDEF:
+                               lex.printError("Unknown counter tag `$$Token'");
+                               continue;
+                       default: 
+                               break;
+               }
+               switch (le) {
+                       case CT_WITHIN:
+                               lex.next();
+                               master_ = lex.getDocString();
+                               if (master_ == "none")
+                                       master_.erase();
+                               break;
+                       case CT_LABELSTRING:
+                               lex.next();
+                               labelstring_ = lex.getDocString();
+                               labelstringappendix_ = labelstring_;
+                               break;
+                       case CT_LABELSTRING_APPENDIX:
+                               lex.next();
+                               labelstringappendix_ = lex.getDocString();
+                               break;
+                       case CT_END:
+                               getout = true;
+                               break;
+               }
+       }
+
+       // Here if have a full counter if getout == true
+       if (!getout)
+               LYXERR0("No End tag found for counter!");
+       lex.popTable();
+       return getout;
+}
+
 void Counter::set(int v)
 {
        value_ = v;
@@ -112,6 +171,23 @@ bool Counters::hasCounter(docstring const & c) const
 }
 
 
+bool Counters::read(Lexer & lex, docstring const & name)
+{
+       if (hasCounter(name)) {
+               LYXERR(Debug::TCLASS, "Reading existing counter " << to_utf8(name));
+               return counterList[name].read(lex);
+       }
+       LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name));
+       Counter cnt;
+       bool success = cnt.read(lex);
+       if (success)
+               counterList[name] = cnt;
+       else
+               LYXERR0("Error reading counter `" << name << "'!");
+       return success;
+}
+
+
 void Counters::set(docstring const & ctr, int const val)
 {
        CounterList::iterator const it = counterList.find(ctr);