1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
13 * 14/11/1995, Pascal André <andre@via.ecp.fr>
14 * Modified for external style definition.
16 * 15/11/1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
17 * Modified to use binary search and a small pseudo lexical analyzer.
19 * 29/03/1996, Dirk Niggeman
20 * Created classes LyXTextClass & LyXLayout.
23 * Created class LyxLex and improved the lexical analyzer.
29 #pragma implementation
32 #include "definitions.h"
36 #include "support/filetools.h"
37 #include "lyx_gui_misc.h"
41 /* Global variable: textclass table */
42 LyXTextClassList lyxstyle;
44 // Reads the style files
47 lyxerr.debug() << "LyXSetStyle: parsing configuration..." << endl;
49 if (!lyxstyle.Read()) {
50 lyxerr << "LyXSetStyle: an error occured during parsing.\n"
51 << " Exiting." << endl;
55 lyxerr.debug() << "LyXSetStyle: configuration parsed." << endl;
59 // The order of the LayoutTags enum is no more important. [asierra300396]
62 LT_ALIGN, LT_ALIGNPOSSIBLE,
64 LT_BOTTOMSEP, LT_CENTER, LT_CENTERED_TOP_ENVIRONMENT, LT_COLUMNS,
65 LT_COPYSTYLE, LT_OBSOLETEDBY,
66 LT_COMMAND, LT_COUNTER_CHAPTER, LT_COUNTER_ENUMI, LT_COUNTER_ENUMII,
67 LT_COUNTER_ENUMIII, LT_COUNTER_ENUMIV, LT_COUNTER_PARAGRAPH,
68 LT_COUNTER_SECTION, LT_COUNTER_SUBPARAGRAPH, LT_COUNTER_SUBSECTION,
69 LT_COUNTER_SUBSUBSECTION, LT_DEFAULTFONT, LT_DYNAMIC, LT_EMPTY,
70 LT_END, LT_ENVIRONMENT, LT_ENVIRONMENT_DEFAULT,
71 LT_FANCYHDR, LT_FILL_BOTTOM, LT_FILL_TOP, LT_FIRST_COUNTER,
72 LT_FIRST_DYNAMIC, LT_FONT, LT_FREE_SPACING, LT_HEADINGS, LT_INPUT,
73 LT_ITEM_ENVIRONMENT, LT_ITEMSEP, LT_KEEPEMPTY,
74 LT_LABEL_BOTTOMSEP, LT_LABELFONT, LT_TEXTFONT,
75 LT_LABELINDENT, LT_LABELSEP, LT_LABELSTRING,
76 LT_LABELSTRING_APPENDIX, LT_LABELTYPE,
77 LT_LATEXNAME, LT_LATEXPARAM, LT_LATEXTYPE, LT_LAYOUT, LT_LEFT,
79 LT_LIST_ENVIRONMENT , LT_MANUAL, LT_MAXCOUNTER,
80 LT_NEED_PROTECT, LT_NEWLINE,
81 LT_NEXTNOINDENT, LT_NO_LABEL, LT_NOSTYLE,
82 LT_PAGESTYLE, LT_PARAGRAPH,
83 LT_PARINDENT, LT_PARSEP, LT_PARSKIP, LT_PLAIN, LT_PREAMBLE,
84 LT_PROVIDESAMSMATH, LT_PROVIDESMAKEIDX, LT_PROVIDESURL, LT_RIGHT,
85 LT_RIGHT_ADDRESS_BOX, LT_RIGHTMARGIN, LT_SENSITIVE, LT_SIDES,
86 LT_SPACING, LT_SPACING_SINGLE, LT_SPACING_ONEHALF,
87 LT_SPACING_DOUBLE, LT_OTHER, LT_CLASSOPTIONS, LT_FONTSIZE,
88 LT_STATIC, LT_STYLE, LT_TOP_ENVIRONMENT, LT_TOPSEP, LT_BIBLIO,
89 LT_INTITLE, LT_SECNUMDEPTH, LT_TOCDEPTH,
90 LT_OUTPUTTYPE, LT_OTLATEX, LT_OTLINUXDOC, LT_OTDOCBOOK, LT_OTLITERATE
94 // This table is sorted alphabetically [asierra 30March96]
95 static keyword_item layoutTags[] = {
96 { "align", LT_ALIGN },
97 { "alignpossible", LT_ALIGNPOSSIBLE },
98 { "bibliography", LT_BIBLIO },
99 { "block", LT_BLOCK },
100 { "bottomsep", LT_BOTTOMSEP },
101 { "center", LT_CENTER },
102 { "centered_top_environment", LT_CENTERED_TOP_ENVIRONMENT },
103 { "classoptions", LT_CLASSOPTIONS },
104 { "columns", LT_COLUMNS },
105 { "command", LT_COMMAND },
106 { "copystyle", LT_COPYSTYLE },
107 { "counter_chapter", LT_COUNTER_CHAPTER },
108 { "counter_enumi", LT_COUNTER_ENUMI },
109 { "counter_enumii", LT_COUNTER_ENUMII },
110 { "counter_enumiii", LT_COUNTER_ENUMIII },
111 { "counter_enumiv", LT_COUNTER_ENUMIV },
112 { "counter_paragraph", LT_COUNTER_PARAGRAPH },
113 { "counter_section", LT_COUNTER_SECTION },
114 { "counter_subparagraph", LT_COUNTER_SUBPARAGRAPH },
115 { "counter_subsection", LT_COUNTER_SUBSECTION },
116 { "counter_subsubsection", LT_COUNTER_SUBSUBSECTION },
117 { "defaultfont", LT_DEFAULTFONT },
118 { "docbook", LT_OTDOCBOOK },
119 { "double", LT_SPACING_DOUBLE },
120 { "dynamic", LT_DYNAMIC },
121 { "empty", LT_EMPTY },
123 { "environment", LT_ENVIRONMENT },
124 { "environment_default", LT_ENVIRONMENT_DEFAULT },
125 { "fancyhdr", LT_FANCYHDR },
126 { "fill_bottom", LT_FILL_BOTTOM },
127 { "fill_top", LT_FILL_TOP },
128 { "first_counter", LT_FIRST_COUNTER },
129 { "first_dynamic", LT_FIRST_DYNAMIC },
131 { "fontsize", LT_FONTSIZE },
132 { "freespacing", LT_FREE_SPACING },
133 { "headings", LT_HEADINGS },
134 { "input", LT_INPUT },
135 { "intitle", LT_INTITLE },
136 { "item_environment", LT_ITEM_ENVIRONMENT },
137 { "itemsep", LT_ITEMSEP },
138 { "keepempty", LT_KEEPEMPTY },
139 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
140 { "labelfont", LT_LABELFONT },
141 { "labelindent", LT_LABELINDENT },
142 { "labelsep", LT_LABELSEP },
143 { "labelstring", LT_LABELSTRING },
144 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
145 { "labeltype", LT_LABELTYPE },
146 { "latex", LT_OTLATEX },
147 { "latexname", LT_LATEXNAME },
148 { "latexparam", LT_LATEXPARAM }, //arrae970411
149 { "latextype", LT_LATEXTYPE },
150 { "layout", LT_LAYOUT },
152 { "leftmargin", LT_LEFTMARGIN },
153 { "linuxdoc", LT_OTLINUXDOC },
154 { "list_environment", LT_LIST_ENVIRONMENT },
155 { "literate", LT_OTLITERATE },
156 { "manual", LT_MANUAL },
157 { "margin", LT_MARGIN },
158 { "maxcounter", LT_MAXCOUNTER },
159 { "needprotect", LT_NEED_PROTECT },
160 { "newline", LT_NEWLINE },
161 { "nextnoindent", LT_NEXTNOINDENT },
162 { "no_label", LT_NO_LABEL },
163 { "nostyle", LT_NOSTYLE },
164 { "obsoletedby", LT_OBSOLETEDBY },
165 { "onehalf", LT_SPACING_ONEHALF },
166 { "other", LT_OTHER },
167 { "outputtype", LT_OUTPUTTYPE },
168 { "pagestyle", LT_PAGESTYLE },
169 { "paragraph", LT_PARAGRAPH },
170 { "parindent", LT_PARINDENT },
171 { "parsep", LT_PARSEP },
172 { "parskip", LT_PARSKIP },
173 { "plain", LT_PLAIN },
174 { "preamble", LT_PREAMBLE },
175 { "providesamsmath", LT_PROVIDESAMSMATH },
176 { "providesmakeidx", LT_PROVIDESMAKEIDX },
177 { "providesurl", LT_PROVIDESURL },
178 { "right", LT_RIGHT },
179 { "right_address_box", LT_RIGHT_ADDRESS_BOX },
180 { "rightmargin", LT_RIGHTMARGIN },
181 { "secnumdepth", LT_SECNUMDEPTH },
182 { "sensitive", LT_SENSITIVE },
183 { "sides", LT_SIDES },
184 { "single", LT_SPACING_SINGLE },
185 { "spacing", LT_SPACING },
186 { "static", LT_STATIC },
187 { "style", LT_STYLE },
188 { "textfont", LT_TEXTFONT },
189 { "tocdepth", LT_TOCDEPTH },
190 { "top_environment", LT_TOP_ENVIRONMENT },
191 { "topsep", LT_TOPSEP }
195 /* ******************************************************************* */
197 // Constructor for layout
198 LyXLayout::LyXLayout ()
200 margintype = MARGIN_STATIC;
201 latextype = LATEX_PARAGRAPH;
205 font = LyXFont(LyXFont::ALL_INHERIT);
206 labelfont = LyXFont(LyXFont::ALL_INHERIT);
207 resfont = LyXFont(LyXFont::ALL_SANE);
208 reslabelfont = LyXFont(LyXFont::ALL_SANE);
209 nextnoindent = false;
214 labelbottomsep = 0.0;
216 align = LYX_ALIGN_BLOCK;
217 alignpossible = LYX_ALIGN_BLOCK;
218 labeltype = LABEL_NO_LABEL;
219 // Should or should not. That is the question.
220 // spacing.set(Spacing::OneHalf);
223 newline_allowed = true;
224 free_spacing = false;
228 LyXLayout::~LyXLayout ()
233 void LyXLayout::Copy (LyXLayout const &l)
236 obsoleted_by = l.obsoleted_by;
237 margintype = l.margintype;
238 latextype = l.latextype;
240 needprotect = l.needprotect;
241 keepempty = l.keepempty;
242 latexname = l.latexname;
243 latexparam = l.latexparam; //arrae970411
244 preamble = l.preamble;
246 labelfont = l.labelfont;
248 reslabelfont = l.reslabelfont;
249 nextnoindent = l.nextnoindent;
250 leftmargin = l.leftmargin;
251 rightmargin = l.rightmargin;
252 labelsep = l.labelsep;
253 labelindent = l.labelindent;
254 parindent = l.parindent;
258 bottomsep = l.bottomsep;
259 labelbottomsep = l.labelbottomsep;
262 alignpossible = l.alignpossible;
263 labeltype = l.labeltype;
265 labelstring = l.labelstring;
266 labelstring_appendix = l.labelstring_appendix;
267 fill_top = l.fill_top;
268 fill_bottom = l.fill_bottom;
269 newline_allowed = l.newline_allowed;
270 free_spacing = l.free_spacing;
274 /* Reads a layout definition from file */
275 bool LyXLayout::Read (LyXLex & lexrc, LyXLayoutList * list)
278 bool finished = false;
280 /* parse style section */
281 while (!finished && lexrc.IsOK() && !error) {
282 switch(lexrc.lex()) {
287 case -1: /* parse error */
288 lexrc.printError("Unknown tag `$$Token'");
292 case LT_END: /* end of structure */
296 case LT_COPYSTYLE: // initialize with a known style
298 LyXLayout * layout = list->GetLayout(lexrc.GetString());
300 string tmpname = name;
304 lexrc.printError("Cannot copy unknown "
310 case LT_OBSOLETEDBY: // replace with a known style
312 LyXLayout * layout = list->GetLayout(lexrc.GetString());
314 string tmpname = name;
317 if (obsoleted_by.empty())
318 obsoleted_by = lexrc.GetString();
320 lexrc.printError("Cannot replace with"
327 case LT_MARGIN: /* margin style definition */
329 switch(lexrc.lex()) {
331 margintype = MARGIN_STATIC;
334 margintype = MARGIN_MANUAL;
337 margintype = MARGIN_DYNAMIC;
339 case LT_FIRST_DYNAMIC:
340 margintype = MARGIN_FIRST_DYNAMIC;
342 case LT_RIGHT_ADDRESS_BOX:
343 margintype = MARGIN_RIGHT_ADDRESS_BOX;
346 lexrc.printError("Unknown margin type `$$Token'");
351 case LT_LATEXTYPE: /* latex style definition */
352 switch (lexrc.lex()) {
354 latextype=LATEX_PARAGRAPH;
357 latextype=LATEX_COMMAND;
360 latextype=LATEX_ENVIRONMENT;
362 case LT_ITEM_ENVIRONMENT:
363 latextype=LATEX_ITEM_ENVIRONMENT;
365 case LT_LIST_ENVIRONMENT:
366 latextype=LATEX_LIST_ENVIRONMENT;
369 lexrc.printError("Unknown latextype `$$Token'");
375 intitle = lexrc.next() && lexrc.GetInteger();
378 case LT_NEED_PROTECT:
379 needprotect = lexrc.next() && lexrc.GetInteger();
383 keepempty = lexrc.next() && lexrc.GetInteger();
396 labelfont.lyxRead(lexrc);
399 case LT_NEXTNOINDENT: /* indent next paragraph ? */
400 if (lexrc.next() && lexrc.GetInteger())
403 nextnoindent = false;
406 case LT_LATEXNAME: /* latex name */
408 latexname = lexrc.GetString();
412 case LT_LATEXPARAM: /* latex parameter */
414 latexparam = lexrc.GetString();
418 preamble = lexrc.getLongString("EndPreamble");
421 case LT_LABELTYPE: /* label type */
422 switch (lexrc.lex()) {
424 labeltype = LABEL_NO_LABEL;
427 labeltype = LABEL_MANUAL;
429 case LT_TOP_ENVIRONMENT:
430 labeltype = LABEL_TOP_ENVIRONMENT;
432 case LT_CENTERED_TOP_ENVIRONMENT:
433 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
436 labeltype = LABEL_STATIC;
439 labeltype = LABEL_SENSITIVE;
441 case LT_COUNTER_CHAPTER:
442 labeltype = LABEL_COUNTER_CHAPTER;
444 case LT_COUNTER_SECTION:
445 labeltype = LABEL_COUNTER_SECTION;
447 case LT_COUNTER_SUBSECTION:
448 labeltype = LABEL_COUNTER_SUBSECTION;
450 case LT_COUNTER_SUBSUBSECTION:
451 labeltype = LABEL_COUNTER_SUBSUBSECTION;
453 case LT_COUNTER_PARAGRAPH:
454 labeltype = LABEL_COUNTER_PARAGRAPH;
456 case LT_COUNTER_SUBPARAGRAPH:
457 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
459 case LT_COUNTER_ENUMI:
460 labeltype = LABEL_COUNTER_ENUMI;
462 case LT_COUNTER_ENUMII:
463 labeltype = LABEL_COUNTER_ENUMII;
465 case LT_COUNTER_ENUMIII:
466 labeltype = LABEL_COUNTER_ENUMIII;
468 case LT_COUNTER_ENUMIV:
469 labeltype = LABEL_COUNTER_ENUMIV;
472 labeltype = LABEL_BIBLIO;
475 lexrc.printError("Unknown labeltype `$$Token'");
479 case LT_LEFTMARGIN: /* left margin type */
481 leftmargin = lexrc.GetString();
484 case LT_RIGHTMARGIN: /* right margin type */
486 rightmargin = lexrc.GetString();
489 case LT_LABELINDENT: /* label indenting flag */
491 labelindent = lexrc.GetString();
494 case LT_PARINDENT: /* paragraph indent. flag */
496 parindent = lexrc.GetString();
499 case LT_PARSKIP: /* paragraph skip size */
501 parskip = lexrc.GetFloat();
504 case LT_ITEMSEP: /* item separation size */
506 itemsep = lexrc.GetFloat();
509 case LT_TOPSEP: /* top separation size */
511 topsep = lexrc.GetFloat();
514 case LT_BOTTOMSEP: /* bottom separation size */
516 bottomsep = lexrc.GetFloat();
519 case LT_LABEL_BOTTOMSEP:/* label bottom separation size */
521 labelbottomsep = lexrc.GetFloat();
524 case LT_LABELSEP: /* label separator */
526 labelsep = subst(lexrc.GetString(), 'x', ' ');
530 case LT_PARSEP: /* par. separation size */
532 parsep = lexrc.GetFloat();
535 case LT_FILL_TOP: /* fill top flag */
537 fill_top = lexrc.GetInteger();
540 case LT_FILL_BOTTOM: /* fill bottom flag */
542 fill_bottom = lexrc.GetInteger();
545 case LT_NEWLINE: /* newlines allowed ? */
547 newline_allowed = lexrc.GetInteger();
550 case LT_ALIGN: /* paragraph align */
551 switch (lexrc.lex()) {
553 align = LYX_ALIGN_BLOCK;
556 align = LYX_ALIGN_LEFT;
559 align = LYX_ALIGN_RIGHT;
562 align = LYX_ALIGN_CENTER;
565 align = LYX_ALIGN_LAYOUT;
568 lexrc.printError("Unknown alignment `$$Token'");
572 case LT_ALIGNPOSSIBLE: /* paragraph allowed align */
575 int lineno = lexrc.GetLineNo();
577 switch (lexrc.lex()) {
579 alignpossible |= LYX_ALIGN_BLOCK;
582 alignpossible |= LYX_ALIGN_LEFT;
585 alignpossible |= LYX_ALIGN_RIGHT;
588 alignpossible |= LYX_ALIGN_CENTER;
591 alignpossible |= LYX_ALIGN_LAYOUT;
594 lexrc.printError("Unknown alignment `$$Token'");
597 } while (lineno==lexrc.GetLineNo());
601 case LT_LABELSTRING: /* label string definition */
603 labelstring = lexrc.GetString();
606 case LT_LABELSTRING_APPENDIX: /* label string appendix definition */
608 labelstring_appendix = lexrc.GetString();
611 case LT_FREE_SPACING: /* Allow for free spacing. */
613 free_spacing = lexrc.GetInteger();
616 case LT_SPACING: // setspace.sty
617 switch(lexrc.lex()) {
618 case LT_SPACING_SINGLE:
619 spacing.set(Spacing::Single);
620 //spacing_value = 1.0;
622 case LT_SPACING_ONEHALF:
623 spacing.set(Spacing::Onehalf);
624 //spacing_value = 1.25;
626 case LT_SPACING_DOUBLE:
627 spacing.set(Spacing::Double);
628 //spacing_value = 1.667;
632 spacing.set(Spacing::Other, lexrc.GetFloat());
635 lexrc.printError("Unknown spacing `$$Token'");
638 default: /* context error */
639 lexrc.printError("Tag `$$Token' is not "
640 "allowed in layout");
649 /* ******************************************************************* */
651 LyXLayoutList::LyXLayoutList()
659 LyXLayoutList::~LyXLayoutList()
661 //don't do anything. the layouts will be extracted by ToAr.
662 //destruction is done by Clean in emergencies
666 int LyXLayoutList::GetNum ()
672 void LyXLayoutList::Add (LyXLayout *lay)
674 LyXLayoutL * tmp = new LyXLayoutL;
678 else eol->next = tmp;
684 bool LyXLayoutList::Delete (string const &name)
686 LyXLayoutL * layoutl = l;
688 if (layoutl->layout && layoutl->layout->name == name) {
689 delete layoutl->layout;
690 layoutl->layout = 0; // not sure it is necessary
694 layoutl = layoutl->next;
700 LyXLayout * LyXLayoutList::GetLayout (string const &name)
702 LyXLayoutL * layoutl = l;
704 if (layoutl->layout && layoutl->layout->name == name)
705 return layoutl->layout;
706 layoutl = layoutl->next;
712 LyXLayout * LyXLayoutList::ToAr ()
714 LyXLayoutL * lp, * op;
716 LyXLayout* ar = new LyXLayout [num_layouts];
720 ar[idx].Copy (*lp->layout);
732 //wipe up any dead layouts
733 void LyXLayoutList::Clean ()
735 LyXLayoutL * lp, * op;
745 /* ******************************************************************* */
747 LyXTextClass::LyXTextClass(string const &fn, string const &cln,
759 pagestyle = "default";
760 maxcounter = LABEL_COUNTER_CHAPTER;
761 defaultfont = LyXFont(LyXFont::ALL_SANE);
762 number_of_defined_layouts = 0;
763 opt_fontsize = "10|11|12";
764 opt_pagestyle = "empty|plain|headings|fancy";
765 provides_amsmath = false;
766 provides_makeidx = false;
767 provides_url = false;
772 // This is not a proper copy.
773 // It just references the style rather than copying it!
774 void LyXTextClass::Copy (LyXTextClass const &l)
777 latexname = l.latexname;
778 description = l.description;
779 output_type = l.output_type;
780 preamble = l.preamble;
782 if (style) delete style;
783 style = l.style; //just aliases NO COPY
784 number_of_defined_layouts = l.number_of_defined_layouts;
787 secnumdepth = l.secnumdepth;
788 tocdepth = l.tocdepth;
789 pagestyle = l.pagestyle;
790 maxcounter = l.maxcounter;
791 defaultfont = l.defaultfont;
792 opt_fontsize = l.opt_fontsize;
793 opt_pagestyle = l.opt_pagestyle;
794 provides_amsmath = l.provides_amsmath;
795 provides_makeidx = l.provides_makeidx;
796 provides_url = l.provides_url;
799 leftmargin = l.leftmargin;
800 rightmargin = l.rightmargin;
805 LyXTextClass::~LyXTextClass()
807 //we can't delete the style here because otherwise
808 //our list classes wouldn't work
812 /* Reads a textclass structure from file */
813 int LyXTextClass::Read (string const &filename, LyXLayoutList *list)
816 lyxerr[Debug::TCLASS] << "Reading textclass "
817 << MakeDisplayPath(filename)
820 lyxerr[Debug::TCLASS] << "Reading input file "
821 << MakeDisplayPath(filename) << endl;
823 LyXLex lexrc(layoutTags, sizeof(layoutTags)/sizeof(keyword_item));
826 lexrc.setFile(filename);
827 if (!lexrc.IsOK()) return -2;
835 l = new LyXLayoutList;
838 while (lexrc.IsOK() && !error) {
839 switch(lexrc.lex()) {
844 lexrc.printError("Unknown tag `$$Token'");
848 case LT_OUTPUTTYPE: // output type definition
849 switch(lexrc.lex()) {
854 output_type=LINUXDOC;
860 output_type=LITERATE;
863 lexrc.printError("Unknown output type `$$Token'");
868 case LT_INPUT: // Include file
870 string tmp = LibFileSearch("layouts",
875 lexrc.printError("Error reading input"
886 string name = subst(lexrc.GetString(), '_', ' ');
887 tmpl = l->GetLayout(name);
890 tmpl = new LyXLayout;
894 lyxerr[Debug::TCLASS] << " Reading style "
898 if (!tmpl->Read(lexrc, l)) {
900 tmpl->resfont = tmpl->font;
901 tmpl->resfont.realize(defaultfont);
902 tmpl->reslabelfont = tmpl->labelfont;
903 tmpl->reslabelfont.realize(defaultfont);
906 // NB! we don't delete because
907 // we just pass it in....
911 "Error parsing style `"
916 //we delete dead ones here
921 lexrc.printError("No name given for style: `$$Token'.");
928 string style = lexrc.GetString();
929 if (!l->Delete(subst(style, '_', ' ')))
930 lexrc.printError("Cannot delete style `$$Token'");
936 columns = lexrc.GetInteger();
941 sides = lexrc.GetInteger();
946 pagestyle = strip(lexrc.GetString());
950 defaultfont.lyxRead(lexrc);
951 if (!defaultfont.resolved()) {
952 lexrc.printError("Warning: defaultfont should "
953 "be fully instantiated!");
954 defaultfont.realize(LyXFont::ALL_SANE);
959 switch (lexrc.lex()) {
960 case LT_COUNTER_CHAPTER:
961 maxcounter = LABEL_COUNTER_CHAPTER;
963 case LT_COUNTER_SECTION:
964 maxcounter = LABEL_COUNTER_SECTION;
966 case LT_COUNTER_SUBSECTION:
967 maxcounter = LABEL_COUNTER_SUBSECTION;
969 case LT_COUNTER_SUBSUBSECTION:
970 maxcounter = LABEL_COUNTER_SUBSUBSECTION;
972 case LT_COUNTER_PARAGRAPH:
973 maxcounter = LABEL_COUNTER_PARAGRAPH;
975 case LT_COUNTER_SUBPARAGRAPH:
976 maxcounter = LABEL_COUNTER_SUBPARAGRAPH;
978 case LT_COUNTER_ENUMI:
979 maxcounter = LABEL_COUNTER_ENUMI;
981 case LT_COUNTER_ENUMII:
982 maxcounter = LABEL_COUNTER_ENUMII;
984 case LT_COUNTER_ENUMIII:
985 maxcounter = LABEL_COUNTER_ENUMIII;
987 case LT_COUNTER_ENUMIV:
988 maxcounter = LABEL_COUNTER_ENUMIV;
995 secnumdepth = lexrc.GetInteger();
1000 tocdepth = lexrc.GetInteger();
1003 // First step to support options
1004 case LT_CLASSOPTIONS:
1007 while (getout && lexrc.IsOK()) {
1008 switch (lexrc.lex()) {
1011 opt_fontsize = strip(lexrc.GetString());
1015 opt_pagestyle = strip(lexrc.GetString());
1019 options = lexrc.GetString();
1021 case LT_END: getout = false; break;
1023 lexrc.printError("Out of context tag `$$Token'");
1031 preamble = lexrc.getLongString("EndPreamble");
1034 case LT_PROVIDESAMSMATH:
1036 provides_amsmath = lexrc.GetInteger();
1039 case LT_PROVIDESMAKEIDX:
1041 provides_makeidx = lexrc.GetInteger();
1044 case LT_PROVIDESURL:
1046 provides_url = lexrc.GetInteger();
1049 case LT_LEFTMARGIN: /* left margin type */
1051 leftmargin = lexrc.GetString();
1054 case LT_RIGHTMARGIN: /* right margin type */
1056 rightmargin = lexrc.GetString();
1060 lexrc.printError("Out of context tag `$$Token'");
1065 if (!list) { // we are at top level here.
1067 number_of_defined_layouts = 0;
1068 l->Clean(); //wipe any we may have found
1073 number_of_defined_layouts = l->GetNum();
1076 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1077 << MakeDisplayPath(filename)
1081 lyxerr[Debug::TCLASS] << "Finished reading input file "
1082 << MakeDisplayPath(filename)
1089 // Load textclass info if not loaded yet
1090 void LyXTextClass::load()
1096 string real_file = LibFileSearch("layouts", name, "layout");
1098 if (Read(real_file)) {
1099 lyxerr << "Error reading `"
1100 << MakeDisplayPath(real_file)
1101 << "'\n(Check `" << name
1102 << "')\nCheck your installation and "
1103 "try Options/Reconfigure..." << endl;
1108 /* ******************************************************************* */
1110 LyXTextClassList::LyXTextClassList()
1118 LyXTextClassList::~LyXTextClassList()
1120 // The textclass list is in ar.
1127 // Gets textclass number from name
1128 signed char LyXTextClassList::NumberOfClass(string const &textclass)
1132 while (i < num_textclass && textclass != ar[i].name)
1135 if (i >= num_textclass)
1142 // Gets layout structure from style number and textclass number
1143 LyXLayout *LyXTextClassList::Style(char textclass, char layout)
1145 ar[textclass].load();
1147 if (layout < ar[textclass].number_of_defined_layouts)
1148 return &ar[textclass].style[layout];
1150 return &ar[textclass].style[0];
1155 // Gets layout number from name and textclass number
1156 char LyXTextClassList::NumberOfLayout(char textclass, string const &name)
1158 ar[textclass].load();
1161 while (i < ar[textclass].number_of_defined_layouts
1162 && name != ar[textclass].style[i].name)
1165 if (i >= ar[textclass].number_of_defined_layouts) {
1166 if (name == "dummy")
1167 i = LYX_DUMMY_LAYOUT;
1169 // so that we can detect if the layout doesn't exist.
1170 i = -1; // not found
1176 // Gets a layout (style) name from layout number and textclass number
1177 string LyXTextClassList::NameOfLayout(char textclass, char layout)
1179 ar[textclass].load();
1181 if (layout < ar[textclass].number_of_defined_layouts)
1182 return ar[textclass].style[layout].name;
1183 else if (layout == LYX_DUMMY_LAYOUT)
1190 // Gets a textclass name from number
1191 string LyXTextClassList::NameOfClass(char number)
1193 if (num_textclass == 0) {
1194 if (number == 0) return "dummy";
1195 else return "@@end@@";
1197 if (number < num_textclass)
1198 return ar[number].name;
1203 // Gets a textclass latexname from number
1204 string LyXTextClassList::LatexnameOfClass(char number)
1208 if (num_textclass == 0) {
1209 if (number == 0) return "dummy";
1210 else return "@@end@@";
1212 if (number < num_textclass)
1213 return ar[number].latexname;
1218 // Gets a textclass description from number
1219 string LyXTextClassList::DescOfClass(char number)
1221 if (num_textclass == 0) {
1222 if (number == 0) return "dummy";
1223 else return "@@end@@";
1225 if (number < num_textclass)
1226 return ar[number].description;
1232 // Gets a textclass structure from number
1233 LyXTextClass * LyXTextClassList::TextClass(char textclass)
1235 ar[textclass].load();
1236 if (textclass < num_textclass)
1237 return &ar[textclass];
1243 void LyXTextClassList::Add (LyXTextClass *t)
1245 LyXTextClassL ** h = &l;
1246 string const desc = t->description;
1247 while (*h && compare_no_case((*h)->textclass->description, desc) < 0)
1249 LyXTextClassL * tmp = new LyXTextClassL;
1257 void LyXTextClassList::ToAr ()
1259 LyXTextClassL * lp, *op;
1261 ar = new LyXTextClass [num_textclass];
1264 ar[idx].Copy (*lp->textclass);
1266 delete lp->textclass; // note we don't delete layouts
1275 // Reads LyX textclass definitions according to textclass config file
1276 bool LyXTextClassList::Read ()
1279 string real_file = LibFileSearch("", "textclass.lst");
1280 lyxerr[Debug::TCLASS] << "Reading textclasses from "
1281 << real_file << endl;
1283 if (real_file.empty()) {
1284 lyxerr << "LyXTextClassList::Read: unable to find "
1285 "textclass file `" << MakeDisplayPath(real_file, 1000)
1286 << "'. Exiting." << endl;
1288 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1289 _("Check that the file \"textclass.lst\""),
1290 _("is installed correctly. Sorry, has to exit :-("));
1292 // This causes LyX to end... Not a desirable behaviour. Lgb
1293 // What do you propose? That the user gets a file dialog
1294 // and is allowed to hunt for the file? (Asger)
1297 lex.setFile(real_file);
1300 lyxerr << "LyXTextClassList::Read: unable to open "
1301 "textclass file `" << MakeDisplayPath(real_file, 1000)
1302 << "\'\nCheck your installation. LyX can't continue."
1306 bool finished = false;
1307 string fname, clname, desc;
1308 LyXTextClass * tmpl;
1310 // Parse config-file
1311 while (lex.IsOK() && !finished) {
1312 switch (lex.lex()) {
1313 case LyXLex::LEX_FEOF:
1317 fname = lex.GetString();
1318 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1320 clname = lex.GetString();
1321 lyxerr[Debug::TCLASS]
1322 << "Clname: " << clname << endl;
1324 desc = lex.GetString();
1325 lyxerr[Debug::TCLASS]
1326 << "Desc: " << desc << endl;
1327 // This code is run when we have
1328 // fname, clname and desc
1329 tmpl =new LyXTextClass(fname,
1334 debugging(Debug::TCLASS)) {
1342 if (num_textclass == 0) {
1343 lyxerr << "LyXTextClassList::Read: no textclass found!" << endl;
1344 WriteAlert(_("LyX wasn't able to find any layout description!"),
1345 _("Check the contents of the file \"textclass.lst\""),
1346 _("Sorry, has to exit :-("));
1356 /* Returns false if this fails */
1357 bool LyXTextClassList::Load (char const number)
1361 if (number < num_textclass) {
1363 if (!ar[number].number_of_defined_layouts) {