# Incremented to format 9, 5 October 2008 by rgh
# ForcePlain and CustomPars tags added to InsetLayout
-currentFormat = 9
+# Incremented to format 10, 6 October 2008 by rgh
+# Change format of counters
+
+currentFormat = 10
def usage(prog_name):
def convert(lines):
" Convert to new format."
re_Comment = re.compile(r'^(\s*)#')
+ re_Counter = re.compile(r'\s*Counter\s*')
+ re_Name = re.compile(r'\s*Name\s+(\S+)\s*')
re_Empty = re.compile(r'^(\s*)$')
re_Format = re.compile(r'^(\s*)(Format)(\s+)(\S+)', re.IGNORECASE)
re_Preamble = re.compile(r'^(\s*)Preamble', re.IGNORECASE)
i += 1
continue
+ if format == 9:
+ match = re_Counter.match(lines[i])
+ if match:
+ counterline = i
+ i += 1
+ while i < len(lines):
+ namem = re_Name.match(lines[i])
+ if namem:
+ name = namem.group(1)
+ lines.pop(i)
+ lines[counterline] = "Counter %s" % name
+ # we don't need to increment i
+ continue
+ endem = re_End.match(lines[i])
+ if endem:
+ i += 1
+ break
+ i += 1
+ i += 1
+ continue
+
# These just involved new features, not any changes to old ones
if format >= 5 and format <= 8:
i += 1
#include "Counters.h"
+#include "Lexer.h"
+
#include "support/convert.h"
#include "support/debug.h"
#include "support/lstrings.h"
}
+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;
}
+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);
namespace lyx {
+class Lexer;
+
/// This represents a single counter.
class Counter {
public:
///
Counter(docstring const & mc, docstring const & ls,
docstring const & lsa);
+ /// \return true on success
+ bool read(Lexer & lex);
///
void set(int v);
///
public:
///
Counters() : appendix_(false), subfloat_(false) {}
- /// Add a new counter to array.
- void newCounter(docstring const & newc);
/// Add new counter newc having masterc as its master,
/// ls as its label, and lsa as its appendix label.
void newCounter(docstring const & newc,
docstring const & lsa);
/// Checks whether the given counter exists.
bool hasCounter(docstring const & c) const;
+ /// reads the counter name
+ /// \return true on success
+ bool read(Lexer & lex, docstring const & name);
///
void set(docstring const & ctr, int val);
///
};
-int const FORMAT = 9;
+int const FORMAT = 10;
bool layout2layout(FileName const & filename, FileName const & tempfile)
break;
case TC_COUNTER:
- readCounter(lexrc);
+ if (lexrc.next()) {
+ docstring const name = lexrc.getDocString();
+ if (name.empty()) {
+ string s = "Could not read name for counter: `$$Token' "
+ + lexrc.getString() + " is probably not valid UTF-8!";
+ lexrc.printError(s.c_str());
+ Counter c;
+ // Since we couldn't read the name, we just scan the rest
+ // and discard it.
+ c.read(lexrc);
+ } else
+ error = !counters_.read(lexrc, name);
+ }
+ else {
+ lexrc.printError("No name given for style: `$$Token'.");
+ error = true;
+ }
break;
case TC_TITLELATEXTYPE:
}
-void TextClass::readCounter(Lexer & lexrc)
-{
- enum {
- CT_NAME = 1,
- CT_WITHIN,
- CT_LABELSTRING,
- CT_LABELSTRING_APPENDIX,
- CT_END
- };
-
- LexerKeyword counterTags[] = {
- { "end", CT_END },
- { "labelstring", CT_LABELSTRING },
- { "labelstringappendix", CT_LABELSTRING_APPENDIX },
- { "name", CT_NAME },
- { "within", CT_WITHIN }
- };
-
- lexrc.pushTable(counterTags);
-
- docstring name;
- docstring within;
- docstring labelstring;
- docstring labelstring_appendix;
-
- bool getout = false;
- while (!getout && lexrc.isOK()) {
- int le = lexrc.lex();
- switch (le) {
- case Lexer::LEX_UNDEF:
- lexrc.printError("Unknown counter tag `$$Token'");
- continue;
- default: break;
- }
- switch (le) {
- case CT_NAME:
- lexrc.next();
- name = lexrc.getDocString();
- if (counters_.hasCounter(name))
- LYXERR(Debug::TCLASS, "Reading existing counter " << to_utf8(name));
- else
- LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name));
- break;
- case CT_WITHIN:
- lexrc.next();
- within = lexrc.getDocString();
- if (within == "none")
- within.erase();
- break;
- case CT_LABELSTRING:
- lexrc.next();
- labelstring = lexrc.getDocString();
- labelstring_appendix = labelstring;
- break;
- case CT_LABELSTRING_APPENDIX:
- lexrc.next();
- labelstring_appendix = lexrc.getDocString();
- break;
- case CT_END:
- getout = true;
- break;
- }
- }
-
- // Here if have a full counter if getout == true
- if (getout)
- counters_.newCounter(name, within,
- labelstring, labelstring_appendix);
-
- lexrc.popTable();
-}
-
-
bool TextClass::hasLayout(docstring const & n) const
{
docstring const name = n.empty() ? defaultLayoutName() : n;
void readCharStyle(Lexer &, std::string const &);
///
void readFloat(Lexer &);
- ///
- void readCounter(Lexer &);
};