X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flayout.C;h=bad3b274118812ec634e630be50b5cb6c8520857;hb=d5b3b6807a719bdc3510444b307a1d22a94c6876;hp=899f10baa089645df4608ba0a74c4afa67513964;hpb=3227c66baf8ad482fb025b634067f40203e66fa6;p=lyx.git diff --git a/src/layout.C b/src/layout.C index 899f10baa0..bad3b27411 100644 --- a/src/layout.C +++ b/src/layout.C @@ -4,9 +4,10 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-1999 The LyX Team. + * Copyright 1995-2000 The LyX Team. * - * ====================================================== */ + * ====================================================== + */ #include @@ -15,8 +16,6 @@ #endif #include -using std::make_pair; -using std::sort; #include "layout.h" #include "lyxlex.h" @@ -25,10 +24,19 @@ using std::sort; #include "debug.h" #include "gettext.h" #include "support/LAssert.h" +#include "support/lyxfunctional.h" + +using std::pair; +using std::make_pair; +using std::sort; +using std::endl; +using std::find_if; +using std::remove_if; // Global variable: textclass table. LyXTextClassList textclasslist; + // Reads the style files void LyXSetStyle() { @@ -72,7 +80,9 @@ enum LayoutTags { LT_LABELSEP, LT_LABELSTRING, LT_LABELSTRING_APPENDIX, - LT_LABELTYPE, + LT_LABELTYPE, + LT_ENDLABELSTRING, + LT_ENDLABELTYPE, LT_LATEXNAME, LT_LATEXPARAM, LT_LATEXTYPE, @@ -92,47 +102,6 @@ enum LayoutTags { }; -// This table is sorted alphabetically [asierra 30March96] -static keyword_item layoutTags[] = { - { "align", LT_ALIGN }, - { "alignpossible", LT_ALIGNPOSSIBLE }, - { "bottomsep", LT_BOTTOMSEP }, - { "copystyle", LT_COPYSTYLE }, - { "end", LT_END }, - { "fill_bottom", LT_FILL_BOTTOM }, - { "fill_top", LT_FILL_TOP }, - { "font", LT_FONT }, - { "freespacing", LT_FREE_SPACING }, - { "intitle", LT_INTITLE }, - { "itemsep", LT_ITEMSEP }, - { "keepempty", LT_KEEPEMPTY }, - { "labelbottomsep", LT_LABEL_BOTTOMSEP }, - { "labelfont", LT_LABELFONT }, - { "labelindent", LT_LABELINDENT }, - { "labelsep", LT_LABELSEP }, - { "labelstring", LT_LABELSTRING }, - { "labelstringappendix", LT_LABELSTRING_APPENDIX }, - { "labeltype", LT_LABELTYPE }, - { "latexname", LT_LATEXNAME }, - { "latexparam", LT_LATEXPARAM }, - { "latextype", LT_LATEXTYPE }, - { "leftmargin", LT_LEFTMARGIN }, - { "margin", LT_MARGIN }, - { "needprotect", LT_NEED_PROTECT }, - { "newline", LT_NEWLINE }, - { "nextnoindent", LT_NEXTNOINDENT }, - { "obsoletedby", LT_OBSOLETEDBY }, - { "parindent", LT_PARINDENT }, - { "parsep", LT_PARSEP }, - { "parskip", LT_PARSKIP }, - { "preamble", LT_PREAMBLE }, - { "rightmargin", LT_RIGHTMARGIN }, - { "spacing", LT_SPACING }, - { "textfont", LT_TEXTFONT }, - { "topsep", LT_TOPSEP } -}; - - ///////////////////// // Constructor for layout @@ -157,6 +126,7 @@ LyXLayout::LyXLayout () align = LYX_ALIGN_BLOCK; alignpossible = LYX_ALIGN_BLOCK; labeltype = LABEL_NO_LABEL; + endlabeltype = END_LABEL_NO_LABEL; // Should or should not. That is the question. // spacing.set(Spacing::OneHalf); fill_top = false; @@ -169,6 +139,48 @@ LyXLayout::LyXLayout () // Reads a layout definition from file bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) { + // This table is sorted alphabetically [asierra 30March96] + keyword_item layoutTags[] = { + { "align", LT_ALIGN }, + { "alignpossible", LT_ALIGNPOSSIBLE }, + { "bottomsep", LT_BOTTOMSEP }, + { "copystyle", LT_COPYSTYLE }, + { "end", LT_END }, + { "endlabelstring", LT_ENDLABELSTRING }, + { "endlabeltype", LT_ENDLABELTYPE }, + { "fill_bottom", LT_FILL_BOTTOM }, + { "fill_top", LT_FILL_TOP }, + { "font", LT_FONT }, + { "freespacing", LT_FREE_SPACING }, + { "intitle", LT_INTITLE }, + { "itemsep", LT_ITEMSEP }, + { "keepempty", LT_KEEPEMPTY }, + { "labelbottomsep", LT_LABEL_BOTTOMSEP }, + { "labelfont", LT_LABELFONT }, + { "labelindent", LT_LABELINDENT }, + { "labelsep", LT_LABELSEP }, + { "labelstring", LT_LABELSTRING }, + { "labelstringappendix", LT_LABELSTRING_APPENDIX }, + { "labeltype", LT_LABELTYPE }, + { "latexname", LT_LATEXNAME }, + { "latexparam", LT_LATEXPARAM }, + { "latextype", LT_LATEXTYPE }, + { "leftmargin", LT_LEFTMARGIN }, + { "margin", LT_MARGIN }, + { "needprotect", LT_NEED_PROTECT }, + { "newline", LT_NEWLINE }, + { "nextnoindent", LT_NEXTNOINDENT }, + { "obsoletedby", LT_OBSOLETEDBY }, + { "parindent", LT_PARINDENT }, + { "parsep", LT_PARSEP }, + { "parskip", LT_PARSKIP }, + { "preamble", LT_PREAMBLE }, + { "rightmargin", LT_RIGHTMARGIN }, + { "spacing", LT_SPACING }, + { "textfont", LT_TEXTFONT }, + { "topsep", LT_TOPSEP } + }; + bool error = false; bool finished = false; lexrc.pushTable(layoutTags, LT_INTITLE); @@ -178,12 +190,12 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) // See comment in lyxrc.C. switch(le) { case LyXLex::LEX_FEOF: - continue; break; + continue; case LyXLex::LEX_UNDEF: // parse error lexrc.printError("Unknown layout tag `$$Token'"); error = true; - continue; break; + continue; default: break; } switch(static_cast(le)) { @@ -277,6 +289,10 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) case LT_LABELTYPE: readLabelType(lexrc); break; + + case LT_ENDLABELTYPE: + readEndLabelType(lexrc); + break; case LT_LEFTMARGIN: // left margin type if (lexrc.next()) @@ -361,6 +377,11 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) labelstring_ = lexrc.GetString(); break; + case LT_ENDLABELSTRING: // endlabel string definition + if (lexrc.next()) + endlabelstring_ = lexrc.GetString(); + break; + case LT_LABELSTRING_APPENDIX: // label string appendix definition if (lexrc.next()) labelstring_appendix_ = lexrc.GetString(); @@ -380,6 +401,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) return error; } + enum AlignTags { AT_BLOCK = 1, AT_LEFT, @@ -388,23 +410,23 @@ enum AlignTags { AT_LAYOUT }; -static keyword_item alignTags[] = { - { "block", AT_BLOCK }, - { "center", AT_CENTER }, - { "layout", AT_LAYOUT }, - { "left", AT_LEFT }, - { "right", AT_RIGHT } -}; - void LyXLayout::readAlign(LyXLex & lexrc) { + keyword_item alignTags[] = { + { "block", AT_BLOCK }, + { "center", AT_CENTER }, + { "layout", AT_LAYOUT }, + { "left", AT_LEFT }, + { "right", AT_RIGHT } + }; + pushpophelper pph(lexrc, alignTags, AT_LAYOUT); int le = lexrc.lex(); switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown alignment `$$Token'"); - return; break; + return; default: break; }; switch(static_cast(le)) { @@ -429,6 +451,14 @@ void LyXLayout::readAlign(LyXLex & lexrc) void LyXLayout::readAlignPossible(LyXLex & lexrc) { + keyword_item alignTags[] = { + { "block", AT_BLOCK }, + { "center", AT_CENTER }, + { "layout", AT_LAYOUT }, + { "left", AT_LEFT }, + { "right", AT_RIGHT } + }; + lexrc.pushTable(alignTags, AT_LAYOUT); alignpossible = LYX_ALIGN_NONE; int lineno = lexrc.GetLineNo(); @@ -437,7 +467,7 @@ void LyXLayout::readAlignPossible(LyXLex & lexrc) switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown alignment `$$Token'"); - continue; break; + continue; default: break; }; switch (static_cast(le)) { @@ -461,6 +491,7 @@ void LyXLayout::readAlignPossible(LyXLex & lexrc) lexrc.popTable(); } + enum LabelTypeTags { LA_NO_LABEL = 1, LA_MANUAL, @@ -481,7 +512,10 @@ enum LabelTypeTags { LA_BIBLIO }; -static keyword_item labelTypeTags[] = { + +void LyXLayout::readLabelType(LyXLex & lexrc) +{ + keyword_item labelTypeTags[] = { { "bibliography", LA_BIBLIO }, { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT }, { "counter_chapter", LA_COUNTER_CHAPTER }, @@ -501,14 +535,12 @@ static keyword_item labelTypeTags[] = { { "top_environment", LA_TOP_ENVIRONMENT } }; -void LyXLayout::readLabelType(LyXLex & lexrc) -{ pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO); int le = lexrc.lex(); switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown labeltype tag `$$Token'"); - return; break; + return; default: break; } switch (static_cast(le)) { @@ -566,96 +598,99 @@ void LyXLayout::readLabelType(LyXLex & lexrc) } } -enum MarginTags { - MT_STATIC = 1, - MT_MANUAL, - MT_DYNAMIC, - MT_FIRST_DYNAMIC, - MT_RIGHT_ADDRESS_BOX -}; - -static keyword_item marginTags[] = { - { "dynamic", MT_DYNAMIC }, - { "first_dynamic", MT_FIRST_DYNAMIC }, - { "manual", MT_MANUAL }, - { "right_address_box", MT_RIGHT_ADDRESS_BOX }, - { "static", MT_STATIC } +static keyword_item endlabelTypeTags[] = { + { "box", END_LABEL_BOX }, + { "filled_box", END_LABEL_FILLED_BOX }, + { "no_label", END_LABEL_NO_LABEL }, + { "static", END_LABEL_STATIC } }; -void LyXLayout::readMargin(LyXLex & lexrc) +void LyXLayout::readEndLabelType(LyXLex & lexrc) { - pushpophelper pph(lexrc, marginTags, MT_RIGHT_ADDRESS_BOX); + pushpophelper pph(lexrc, endlabelTypeTags, + END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1); int le = lexrc.lex(); switch(le) { case LyXLex::LEX_UNDEF: - lexrc.printError("Unknown margin type tag `$$Token'"); - return; break; - default: break; - } - switch(static_cast(le)) { - case MT_STATIC: - margintype = MARGIN_STATIC; + lexrc.printError("Unknown labeltype tag `$$Token'"); break; - case MT_MANUAL: - margintype = MARGIN_MANUAL; + case END_LABEL_STATIC: + case END_LABEL_BOX: + case END_LABEL_FILLED_BOX: + case END_LABEL_NO_LABEL: + endlabeltype = static_cast(le); break; - case MT_DYNAMIC: - margintype = MARGIN_DYNAMIC; + default: + lyxerr << "Unhandled value " << le + << " in LyXLayout::readEndLabelType." << endl; break; - case MT_FIRST_DYNAMIC: - margintype = MARGIN_FIRST_DYNAMIC; + } +} + + +void LyXLayout::readMargin(LyXLex & lexrc) +{ + keyword_item marginTags[] = { + { "dynamic", MARGIN_DYNAMIC }, + { "first_dynamic", MARGIN_FIRST_DYNAMIC }, + { "manual", MARGIN_MANUAL }, + { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX }, + { "static", MARGIN_STATIC } + }; + + pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX); + + int le = lexrc.lex(); + switch(le) { + case LyXLex::LEX_UNDEF: + lexrc.printError("Unknown margin type tag `$$Token'"); + return; + case MARGIN_STATIC: + case MARGIN_MANUAL: + case MARGIN_DYNAMIC: + case MARGIN_FIRST_DYNAMIC: + case MARGIN_RIGHT_ADDRESS_BOX: + margintype = static_cast(le); break; - case MT_RIGHT_ADDRESS_BOX: - margintype = MARGIN_RIGHT_ADDRESS_BOX; + default: + lyxerr << "Unhandled value " << le + << " in LyXLayout::readMargin." << endl; break; } } -enum LatexTypeTags { - LX_PARAGRAPH = 1, - LX_COMMAND, - LX_ENVIRONMENT, - LX_ITEM_ENVIRONMENT, - LX_LIST_ENVIRONMENT -}; - -static keyword_item latexTypeTags[] = { - { "command", LX_COMMAND }, - { "environment", LX_ENVIRONMENT }, - { "item_environment", LX_ITEM_ENVIRONMENT }, - { "list_environment", LX_LIST_ENVIRONMENT }, - { "paragraph", LX_PARAGRAPH } -}; void LyXLayout::readLatexType(LyXLex & lexrc) { - pushpophelper pph(lexrc, latexTypeTags, LX_LIST_ENVIRONMENT); + keyword_item latexTypeTags[] = { + { "command", LATEX_COMMAND }, + { "environment", LATEX_ENVIRONMENT }, + { "item_environment", LATEX_ITEM_ENVIRONMENT }, + { "list_environment", LATEX_LIST_ENVIRONMENT }, + { "paragraph", LATEX_PARAGRAPH } + }; + + pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT); int le = lexrc.lex(); switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown latextype tag `$$Token'"); - return; break; - default: break; - } - switch (static_cast(le)) { - case LX_PARAGRAPH: - latextype= LATEX_PARAGRAPH; + return; + case LATEX_PARAGRAPH: + case LATEX_COMMAND: + case LATEX_ENVIRONMENT: + case LATEX_ITEM_ENVIRONMENT: + case LATEX_LIST_ENVIRONMENT: + latextype = static_cast(le); break; - case LX_COMMAND: - latextype= LATEX_COMMAND; - break; - case LX_ENVIRONMENT: - latextype= LATEX_ENVIRONMENT; - break; - case LX_ITEM_ENVIRONMENT: - latextype= LATEX_ITEM_ENVIRONMENT; - break; - case LX_LIST_ENVIRONMENT: - latextype= LATEX_LIST_ENVIRONMENT; + default: + lyxerr << "Unhandled value " << le + << " in LyXLayout::readLatexType." << endl; break; } } + enum SpacingTags { ST_SPACING_SINGLE = 1, ST_SPACING_ONEHALF, @@ -663,21 +698,22 @@ enum SpacingTags { ST_OTHER }; -static keyword_item spacingTags[] = { - {"double", ST_SPACING_DOUBLE }, - {"onehalf", ST_SPACING_ONEHALF }, - {"other", ST_OTHER }, - {"single", ST_SPACING_SINGLE } -}; void LyXLayout::readSpacing(LyXLex & lexrc) { + keyword_item spacingTags[] = { + {"double", ST_SPACING_DOUBLE }, + {"onehalf", ST_SPACING_ONEHALF }, + {"other", ST_OTHER }, + {"single", ST_SPACING_SINGLE } + }; + pushpophelper pph(lexrc, spacingTags, ST_OTHER); int le = lexrc.lex(); switch(le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown spacing token `$$Token'"); - return; break; + return; default: break; } switch(static_cast(le)) { @@ -697,6 +733,7 @@ void LyXLayout::readSpacing(LyXLex & lexrc) } } + /* ******************************************************************* */ LyXTextClass::LyXTextClass(string const & fn, string const & cln, @@ -755,30 +792,31 @@ enum TextClassTags { TC_RIGHTMARGIN }; -static keyword_item textClassTags[] = { - { "classoptions", TC_CLASSOPTIONS }, - { "columns", TC_COLUMNS }, - { "defaultfont", TC_DEFAULTFONT }, - { "input", TC_INPUT }, - { "leftmargin", TC_LEFTMARGIN }, - { "maxcounter", TC_MAXCOUNTER }, - { "nostyle", TC_NOSTYLE }, - { "outputtype", TC_OUTPUTTYPE }, - { "pagestyle", TC_PAGESTYLE }, - { "preamble", TC_PREAMBLE }, - { "providesamsmath", TC_PROVIDESAMSMATH }, - { "providesmakeidx", TC_PROVIDESMAKEIDX }, - { "providesurl", TC_PROVIDESURL }, - { "rightmargin", TC_RIGHTMARGIN }, - { "secnumdepth", TC_SECNUMDEPTH }, - { "sides", TC_SIDES }, - { "style", TC_STYLE }, - { "tocdepth", TC_TOCDEPTH } -}; // Reads a textclass structure from file. bool LyXTextClass::Read(string const & filename, bool merge) { + keyword_item textClassTags[] = { + { "classoptions", TC_CLASSOPTIONS }, + { "columns", TC_COLUMNS }, + { "defaultfont", TC_DEFAULTFONT }, + { "input", TC_INPUT }, + { "leftmargin", TC_LEFTMARGIN }, + { "maxcounter", TC_MAXCOUNTER }, + { "nostyle", TC_NOSTYLE }, + { "outputtype", TC_OUTPUTTYPE }, + { "pagestyle", TC_PAGESTYLE }, + { "preamble", TC_PREAMBLE }, + { "providesamsmath", TC_PROVIDESAMSMATH }, + { "providesmakeidx", TC_PROVIDESMAKEIDX }, + { "providesurl", TC_PROVIDESURL }, + { "rightmargin", TC_RIGHTMARGIN }, + { "secnumdepth", TC_SECNUMDEPTH }, + { "sides", TC_SIDES }, + { "style", TC_STYLE }, + { "tocdepth", TC_TOCDEPTH } + }; + if (!merge) lyxerr[Debug::TCLASS] << "Reading textclass " << MakeDisplayPath(filename) @@ -799,12 +837,12 @@ bool LyXTextClass::Read(string const & filename, bool merge) int le = lexrc.lex(); switch(le) { case LyXLex::LEX_FEOF: - continue; break; + continue; case LyXLex::LEX_UNDEF: lexrc.printError("Unknown TextClass tag `$$Token'"); error = true; - continue; break; + continue; default: break; } switch(static_cast(le)) { @@ -835,7 +873,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) error = do_readStyle(lexrc, lay); } else { LyXLayout lay; - lay.name(name); + lay.setName(name); if (!(error = do_readStyle(lexrc, lay))) layoutlist.push_back(lay); } @@ -886,7 +924,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) if (!defaultfont_.resolved()) { lexrc.printError("Warning: defaultfont should " "be fully instantiated!"); - defaultfont_.realize(LyXFont::ALL_SANE); + defaultfont_.realize(LyXFont(LyXFont::ALL_SANE)); } break; @@ -952,46 +990,38 @@ bool LyXTextClass::Read(string const & filename, bool merge) return error; } -enum OutputTypeTags { - OT_OTLATEX = 1, - OT_OTLINUXDOC, - OT_OTDOCBOOK, - OT_OTLITERATE -}; - -static keyword_item outputTypeTags[] = { - { "docbook", OT_OTDOCBOOK }, - { "latex", OT_OTLATEX }, - { "linuxdoc", OT_OTLINUXDOC }, - { "literate", OT_OTLITERATE } -}; void LyXTextClass::readOutputType(LyXLex & lexrc) { - pushpophelper pph(lexrc, outputTypeTags, OT_OTLITERATE); + keyword_item outputTypeTags[] = { + { "docbook", DOCBOOK }, + { "latex", LATEX }, + { "linuxdoc", LINUXDOC }, + { "literate", LITERATE } + }; + + pushpophelper pph(lexrc, outputTypeTags, LITERATE); + int le = lexrc.lex(); switch(le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown output type `$$Token'"); - return; break; - default: break; - } - switch(static_cast(le)) { - case OT_OTLATEX: - outputType_ = LATEX; - break; - case OT_OTLINUXDOC: - outputType_ = LINUXDOC; - break; - case OT_OTDOCBOOK: - outputType_ = DOCBOOK; + return; + case LATEX: + case LINUXDOC: + case DOCBOOK: + case LITERATE: + outputType_ = static_cast(le); break; - case OT_OTLITERATE: - outputType_ = LITERATE; + default: + lyxerr << "Unhandled value " << le + << " in LyXTextClass::readOutputType." << endl; + break; } } + enum MaxCounterTags { MC_COUNTER_CHAPTER = 1, MC_COUNTER_SECTION, @@ -1005,27 +1035,28 @@ enum MaxCounterTags { MC_COUNTER_ENUMIV }; -static keyword_item maxCounterTags[] = { - {"counter_chapter", MC_COUNTER_CHAPTER }, - {"counter_enumi", MC_COUNTER_ENUMI }, - {"counter_enumii", MC_COUNTER_ENUMII }, - {"counter_enumiii", MC_COUNTER_ENUMIII }, - {"counter_enumiv", MC_COUNTER_ENUMIV }, - {"counter_paragraph", MC_COUNTER_PARAGRAPH }, - {"counter_section", MC_COUNTER_SECTION }, - {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH }, - {"counter_subsection", MC_COUNTER_SUBSECTION }, - {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION } -}; void LyXTextClass::readMaxCounter(LyXLex & lexrc) { + keyword_item maxCounterTags[] = { + {"counter_chapter", MC_COUNTER_CHAPTER }, + {"counter_enumi", MC_COUNTER_ENUMI }, + {"counter_enumii", MC_COUNTER_ENUMII }, + {"counter_enumiii", MC_COUNTER_ENUMIII }, + {"counter_enumiv", MC_COUNTER_ENUMIV }, + {"counter_paragraph", MC_COUNTER_PARAGRAPH }, + {"counter_section", MC_COUNTER_SECTION }, + {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH }, + {"counter_subsection", MC_COUNTER_SUBSECTION }, + {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION } + }; + pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV); int le = lexrc.lex(); switch(le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown MaxCounter tag `$$Token'"); - return; break; + return; default: break; } switch (static_cast(le)) { @@ -1062,6 +1093,7 @@ void LyXTextClass::readMaxCounter(LyXLex & lexrc) } } + enum ClassOptionsTags { CO_FONTSIZE = 1, CO_PAGESTYLE, @@ -1069,15 +1101,16 @@ enum ClassOptionsTags { CO_END }; -static keyword_item classOptionsTags[] = { - {"end", CO_END }, - {"fontsize", CO_FONTSIZE }, - {"other", CO_OTHER }, - {"pagestyle", CO_PAGESTYLE } -}; void LyXTextClass::readClassOptions(LyXLex & lexrc) { + keyword_item classOptionsTags[] = { + {"end", CO_END }, + {"fontsize", CO_FONTSIZE }, + {"other", CO_OTHER }, + {"pagestyle", CO_PAGESTYLE } + }; + lexrc.pushTable(classOptionsTags, CO_END); bool getout = false; while (!getout && lexrc.IsOK()) { @@ -1085,7 +1118,7 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc) switch (le) { case LyXLex::LEX_UNDEF: lexrc.printError("Unknown ClassOption tag `$$Token'"); - continue; break; + continue; default: break; } switch (static_cast(le)) { @@ -1112,49 +1145,43 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc) bool LyXTextClass::hasLayout(string const & name) const { - for (LayoutList::const_iterator cit = layoutlist.begin(); - cit != layoutlist.end(); ++cit) { - if ((*cit).name() == name) - return true; - } - return false; + return find_if(layoutlist.begin(), layoutlist.end(), + compare_memfun(&LyXLayout::name, name)) + != layoutlist.end(); } LyXLayout const & LyXTextClass::GetLayout (string const & name) const { - for (LayoutList::const_iterator cit = layoutlist.begin(); - cit != layoutlist.end(); ++cit) { - if ((*cit).name() == name) - return (*cit); - } - Assert(false); // we actually require the name to exist. - return layoutlist.front(); + LayoutList::const_iterator cit = + find_if(layoutlist.begin(), + layoutlist.end(), + compare_memfun(&LyXLayout::name, name)); + Assert(cit != layoutlist.end()); // we require the name to exist + return (*cit); } LyXLayout & LyXTextClass::GetLayout(string const & name) { - for (LayoutList::iterator it = layoutlist.begin(); - it != layoutlist.end(); ++it) { - if ((*it).name() == name) - return (*it); - } - Assert(false); // we actually require the name to exist. - return layoutlist.front(); + LayoutList::iterator it = + find_if(layoutlist.begin(), + layoutlist.end(), + compare_memfun(&LyXLayout::name, name)); + Assert(it != layoutlist.end()); // we require the name to exist + return (*it); } -bool LyXTextClass::delete_layout (string const & name) +bool LyXTextClass::delete_layout(string const & name) { - for(LayoutList::iterator it = layoutlist.begin(); - it != layoutlist.end(); ++it) { - if ((*it).name() == name) { - layoutlist.erase(it); - return true; - } - } - return false; + LayoutList::iterator it = + remove_if(layoutlist.begin(), layoutlist.end(), + compare_memfun(&LyXLayout::name, name)); + LayoutList::iterator end = layoutlist.end(); + bool const ret = (it != end); + layoutlist.erase(it, end); + return ret; } @@ -1164,7 +1191,7 @@ void LyXTextClass::load() if (loaded) return; // Read style-file - string real_file = LibFileSearch("layouts", name_, "layout"); + string const real_file = LibFileSearch("layouts", name_, "layout"); if (Read(real_file)) { lyxerr << "Error reading `" @@ -1180,22 +1207,22 @@ void LyXTextClass::load() ////////////////////////////////////////// // Gets textclass number from name -pair +pair const LyXTextClassList::NumberOfClass(string const & textclass) const { - for (ClassList::const_iterator cit = classlist.begin(); - cit != classlist.end(); ++cit) { - if ((*cit).name() == textclass) - return make_pair(true, cit - classlist.begin()); - } - return make_pair(false, 0); + ClassList::const_iterator cit = + find_if(classlist.begin(), classlist.end(), + compare_memfun(&LyXTextClass::name, textclass)); + return cit != classlist.end() ? + make_pair(true, size_type(cit - classlist.begin())) : + make_pair(false, size_type(0)); } // Gets layout structure from style number and textclass number LyXLayout const & -LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass, - LyXTextClass::LayoutList::size_type layout) const +LyXTextClassList::Style(LyXTextClassList::size_type textclass, + LyXTextClass::size_type layout) const { classlist[textclass].load(); if (layout < classlist[textclass].numLayouts()) @@ -1205,8 +1232,9 @@ LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass, // Gets layout number from name and textclass number -pair -LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclass, string const & name) const +pair const +LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass, + string const & name) const { classlist[textclass].load(); for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) { @@ -1214,83 +1242,67 @@ LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclas return make_pair(true, i); } if (name == "dummy") - return make_pair(true, LYX_DUMMY_LAYOUT); - return make_pair(false, 0); // not found + return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT)); + return make_pair(false, LyXTextClass::size_type(0)); // not found } // Gets a layout (style) name from layout number and textclass number string const & -LyXTextClassList::NameOfLayout(LyXTextClassList::ClassList::size_type textclass, - LyXTextClass::LayoutList::size_type layout) const +LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass, + LyXTextClass::size_type layout) const { static string dummy("dummy"); - static string end("@@end@@"); classlist[textclass].load(); if (layout < classlist[textclass].numLayouts()) return classlist[textclass][layout].name(); - else if (layout == LYX_DUMMY_LAYOUT) - return dummy; - else - return end; + return dummy; } // Gets a textclass name from number string const & -LyXTextClassList::NameOfClass(LyXTextClassList::ClassList::size_type number) const +LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const { static string dummy("dummy"); - static string end("@@end@@"); if (classlist.size() == 0) { - if (number == 0) return dummy; - else return end; + return dummy; } - if (number < classlist.size()) - return classlist[number].name(); - else - return end; + Assert(number < classlist.size()); + return classlist[number].name(); } // Gets a textclass latexname from number string const & -LyXTextClassList::LatexnameOfClass(LyXTextClassList::ClassList::size_type number) const +LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const { static string dummy("dummy"); - static string end("@@end@@"); classlist[number].load(); if (classlist.size() == 0) { - if (number == 0) return dummy; - else return end; + return dummy; } - if (number < classlist.size()) - return classlist[number].latexname(); - else - return end; + Assert(number < classlist.size()); + return classlist[number].latexname(); } // Gets a textclass description from number string const & -LyXTextClassList::DescOfClass(LyXTextClassList::ClassList::size_type number) const +LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const { static string dummy("dummy"); - static string end("@@end@@"); if (classlist.size() == 0) { - if (number == 0) return dummy; - else return end; + return dummy; } - if (number < classlist.size()) - return classlist[number].description(); - else - return end; + Assert(number < classlist.size()); + return classlist[number].description(); } // Gets a textclass structure from number LyXTextClass const & -LyXTextClassList::TextClass(LyXTextClassList::ClassList::size_type textclass) const +LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const { classlist[textclass].load(); if (textclass < classlist.size()) @@ -1320,8 +1332,8 @@ bool LyXTextClassList::Read () { LyXLex lex(0, 0); string real_file = LibFileSearch("", "textclass.lst"); - lyxerr[Debug::TCLASS] << "Reading textclasses from " - << real_file << endl; + lyxerr[Debug::TCLASS] << "Reading textclasses from `" + << real_file << "'" << endl; if (real_file.empty()) { lyxerr << "LyXTextClassList::Read: unable to find " @@ -1335,9 +1347,15 @@ bool LyXTextClassList::Read () // This causes LyX to end... Not a desirable behaviour. Lgb // What do you propose? That the user gets a file dialog // and is allowed to hunt for the file? (Asger) + // more that we have a layout for minimal.cls statically + // compiled in... (Lgb) } - lex.setFile(real_file); + if (!lex.setFile(real_file)) { + lyxerr << "LyXTextClassList::Read: " + "lyxlex was not able to set file: " + << real_file << endl; + } if (!lex.IsOK()) { lyxerr << "LyXTextClassList::Read: unable to open " @@ -1349,7 +1367,9 @@ bool LyXTextClassList::Read () bool finished = false; string fname, clname, desc; // Parse config-file + lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl; while (lex.IsOK() && !finished) { + lyxerr[Debug::TCLASS] << "\tline by line" << endl; switch (lex.lex()) { case LyXLex::LEX_FEOF: finished = true; @@ -1379,9 +1399,10 @@ bool LyXTextClassList::Read () } } } - + lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl; + if (classlist.size() == 0) { - lyxerr << "LyXTextClassList::Read: no textclass found!" + lyxerr << "LyXTextClassList::Read: no textclasses found!" << endl; WriteAlert(_("LyX wasn't able to find any layout description!"), _("Check the contents of the file \"textclass.lst\""), @@ -1398,7 +1419,7 @@ bool LyXTextClassList::Read () Returns false if this fails */ bool -LyXTextClassList::Load (LyXTextClassList::ClassList::size_type number) const +LyXTextClassList::Load (LyXTextClassList::size_type number) const { bool result = true; if (number < classlist.size()) { @@ -1411,3 +1432,18 @@ LyXTextClassList::Load (LyXTextClassList::ClassList::size_type number) const } return result; } + + +std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p) +{ + switch (p) { + case LyXTextClass::OneSide: + os << "1"; + break; + case LyXTextClass::TwoSides: + os << "2"; + break; + } + return os; +} +