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 = lexrc.GetString();
527 subst(labelsep, 'x', ' ');
531 case LT_PARSEP: /* par. separation size */
533 parsep = lexrc.GetFloat();
536 case LT_FILL_TOP: /* fill top flag */
538 fill_top = lexrc.GetInteger();
541 case LT_FILL_BOTTOM: /* fill bottom flag */
543 fill_bottom = lexrc.GetInteger();
546 case LT_NEWLINE: /* newlines allowed ? */
548 newline_allowed = lexrc.GetInteger();
551 case LT_ALIGN: /* paragraph align */
552 switch (lexrc.lex()) {
554 align = LYX_ALIGN_BLOCK;
557 align = LYX_ALIGN_LEFT;
560 align = LYX_ALIGN_RIGHT;
563 align = LYX_ALIGN_CENTER;
566 align = LYX_ALIGN_LAYOUT;
569 lexrc.printError("Unknown alignment `$$Token'");
573 case LT_ALIGNPOSSIBLE: /* paragraph allowed align */
576 int lineno = lexrc.GetLineNo();
578 switch (lexrc.lex()) {
580 alignpossible |= LYX_ALIGN_BLOCK;
583 alignpossible |= LYX_ALIGN_LEFT;
586 alignpossible |= LYX_ALIGN_RIGHT;
589 alignpossible |= LYX_ALIGN_CENTER;
592 alignpossible |= LYX_ALIGN_LAYOUT;
595 lexrc.printError("Unknown alignment `$$Token'");
598 } while (lineno==lexrc.GetLineNo());
602 case LT_LABELSTRING: /* label string definition */
604 labelstring = lexrc.GetString();
607 case LT_LABELSTRING_APPENDIX: /* label string appendix definition */
609 labelstring_appendix = lexrc.GetString();
612 case LT_FREE_SPACING: /* Allow for free spacing. */
614 free_spacing = lexrc.GetInteger();
617 case LT_SPACING: // setspace.sty
618 switch(lexrc.lex()) {
619 case LT_SPACING_SINGLE:
620 spacing.set(Spacing::Single);
621 //spacing_value = 1.0;
623 case LT_SPACING_ONEHALF:
624 spacing.set(Spacing::Onehalf);
625 //spacing_value = 1.25;
627 case LT_SPACING_DOUBLE:
628 spacing.set(Spacing::Double);
629 //spacing_value = 1.667;
633 spacing.set(Spacing::Other, lexrc.GetFloat());
636 lexrc.printError("Unknown spacing `$$Token'");
639 default: /* context error */
640 lexrc.printError("Tag `$$Token' is not "
641 "allowed in layout");
650 /* ******************************************************************* */
652 LyXLayoutList::LyXLayoutList()
660 LyXLayoutList::~LyXLayoutList()
662 //don't do anything. the layouts will be extracted by ToAr.
663 //destruction is done by Clean in emergencies
667 int LyXLayoutList::GetNum ()
673 void LyXLayoutList::Add (LyXLayout *lay)
675 LyXLayoutL * tmp = new LyXLayoutL;
679 else eol->next = tmp;
685 bool LyXLayoutList::Delete (string const &name)
687 LyXLayoutL * layoutl = l;
689 if (layoutl->layout && layoutl->layout->name == name) {
690 delete layoutl->layout;
691 layoutl->layout = 0; // not sure it is necessary
695 layoutl = layoutl->next;
701 LyXLayout * LyXLayoutList::GetLayout (string const &name)
703 LyXLayoutL * layoutl = l;
705 if (layoutl->layout && layoutl->layout->name == name)
706 return layoutl->layout;
707 layoutl = layoutl->next;
713 LyXLayout * LyXLayoutList::ToAr ()
715 LyXLayoutL * lp, * op;
717 LyXLayout* ar = new LyXLayout [num_layouts];
721 ar[idx].Copy (*lp->layout);
733 //wipe up any dead layouts
734 void LyXLayoutList::Clean ()
736 LyXLayoutL * lp, * op;
746 /* ******************************************************************* */
748 LyXTextClass::LyXTextClass(string const &fn, string const &cln,
760 pagestyle = "default";
761 maxcounter = LABEL_COUNTER_CHAPTER;
762 defaultfont = LyXFont(LyXFont::ALL_SANE);
763 number_of_defined_layouts = 0;
764 opt_fontsize = "10|11|12";
765 opt_pagestyle = "empty|plain|headings|fancy";
766 provides_amsmath = false;
767 provides_makeidx = false;
768 provides_url = false;
773 // This is not a proper copy.
774 // It just references the style rather than copying it!
775 void LyXTextClass::Copy (LyXTextClass const &l)
778 latexname = l.latexname;
779 description = l.description;
780 output_type = l.output_type;
781 preamble = l.preamble;
783 if (style) delete style;
784 style = l.style; //just aliases NO COPY
785 number_of_defined_layouts = l.number_of_defined_layouts;
788 secnumdepth = l.secnumdepth;
789 tocdepth = l.tocdepth;
790 pagestyle = l.pagestyle;
791 maxcounter = l.maxcounter;
792 defaultfont = l.defaultfont;
793 opt_fontsize = l.opt_fontsize;
794 opt_pagestyle = l.opt_pagestyle;
795 provides_amsmath = l.provides_amsmath;
796 provides_makeidx = l.provides_makeidx;
797 provides_url = l.provides_url;
800 leftmargin = l.leftmargin;
801 rightmargin = l.rightmargin;
806 LyXTextClass::~LyXTextClass()
808 //we can't delete the style here because otherwise
809 //our list classes wouldn't work
813 /* Reads a textclass structure from file */
814 int LyXTextClass::Read (string const &filename, LyXLayoutList *list)
817 lyxerr[Debug::TCLASS] << "Reading textclass "
818 << MakeDisplayPath(filename)
821 lyxerr[Debug::TCLASS] << "Reading input file "
822 << MakeDisplayPath(filename) << endl;
824 LyXLex lexrc(layoutTags, sizeof(layoutTags)/sizeof(keyword_item));
827 lexrc.setFile(filename);
828 if (!lexrc.IsOK()) return -2;
836 l = new LyXLayoutList;
839 while (lexrc.IsOK() && !error) {
840 switch(lexrc.lex()) {
845 lexrc.printError("Unknown tag `$$Token'");
849 case LT_OUTPUTTYPE: // output type definition
850 switch(lexrc.lex()) {
855 output_type=LINUXDOC;
861 output_type=LITERATE;
864 lexrc.printError("Unknown output type `$$Token'");
869 case LT_INPUT: // Include file
871 string tmp = LibFileSearch("layouts",
876 lexrc.printError("Error reading input"
885 string name = lexrc.GetString();
888 subst(name, '_',' ');
889 tmpl = l->GetLayout(name);
892 tmpl = new LyXLayout;
896 lyxerr[Debug::TCLASS] << " Reading style "
900 if (!tmpl->Read(lexrc, l)) {
902 tmpl->resfont = tmpl->font;
903 tmpl->resfont.realize(defaultfont);
904 tmpl->reslabelfont = tmpl->labelfont;
905 tmpl->reslabelfont.realize(defaultfont);
908 // NB! we don't delete because
909 // we just pass it in....
913 "Error parsing style `"
918 //we delete dead ones here
923 lexrc.printError("No name given for style: `$$Token'.");
930 string style = lexrc.GetString();
931 if (!l->Delete(subst(style, '_', ' ')))
932 lexrc.printError("Cannot delete style `$$Token'");
938 columns = lexrc.GetInteger();
943 sides = lexrc.GetInteger();
948 pagestyle = strip(lexrc.GetString());
952 defaultfont.lyxRead(lexrc);
953 if (!defaultfont.resolved()) {
954 lexrc.printError("Warning: defaultfont should "
955 "be fully instantiated!");
956 defaultfont.realize(LyXFont::ALL_SANE);
961 switch (lexrc.lex()) {
962 case LT_COUNTER_CHAPTER:
963 maxcounter = LABEL_COUNTER_CHAPTER;
965 case LT_COUNTER_SECTION:
966 maxcounter = LABEL_COUNTER_SECTION;
968 case LT_COUNTER_SUBSECTION:
969 maxcounter = LABEL_COUNTER_SUBSECTION;
971 case LT_COUNTER_SUBSUBSECTION:
972 maxcounter = LABEL_COUNTER_SUBSUBSECTION;
974 case LT_COUNTER_PARAGRAPH:
975 maxcounter = LABEL_COUNTER_PARAGRAPH;
977 case LT_COUNTER_SUBPARAGRAPH:
978 maxcounter = LABEL_COUNTER_SUBPARAGRAPH;
980 case LT_COUNTER_ENUMI:
981 maxcounter = LABEL_COUNTER_ENUMI;
983 case LT_COUNTER_ENUMII:
984 maxcounter = LABEL_COUNTER_ENUMII;
986 case LT_COUNTER_ENUMIII:
987 maxcounter = LABEL_COUNTER_ENUMIII;
989 case LT_COUNTER_ENUMIV:
990 maxcounter = LABEL_COUNTER_ENUMIV;
997 secnumdepth = lexrc.GetInteger();
1002 tocdepth = lexrc.GetInteger();
1005 // First step to support options
1006 case LT_CLASSOPTIONS:
1009 while (getout && lexrc.IsOK()) {
1010 switch (lexrc.lex()) {
1013 opt_fontsize = strip(lexrc.GetString());
1017 opt_pagestyle = strip(lexrc.GetString());
1021 options = lexrc.GetString();
1023 case LT_END: getout = false; break;
1025 lexrc.printError("Out of context tag `$$Token'");
1033 preamble = lexrc.getLongString("EndPreamble");
1036 case LT_PROVIDESAMSMATH:
1038 provides_amsmath = lexrc.GetInteger();
1041 case LT_PROVIDESMAKEIDX:
1043 provides_makeidx = lexrc.GetInteger();
1046 case LT_PROVIDESURL:
1048 provides_url = lexrc.GetInteger();
1051 case LT_LEFTMARGIN: /* left margin type */
1053 leftmargin = lexrc.GetString();
1056 case LT_RIGHTMARGIN: /* right margin type */
1058 rightmargin = lexrc.GetString();
1062 lexrc.printError("Out of context tag `$$Token'");
1067 if (!list) { // we are at top level here.
1069 number_of_defined_layouts = 0;
1070 l->Clean(); //wipe any we may have found
1075 number_of_defined_layouts = l->GetNum();
1078 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1079 << MakeDisplayPath(filename)
1083 lyxerr[Debug::TCLASS] << "Finished reading input file "
1084 << MakeDisplayPath(filename)
1091 // Load textclass info if not loaded yet
1092 void LyXTextClass::load()
1098 string real_file = LibFileSearch("layouts", name, "layout");
1100 if (Read(real_file)) {
1101 lyxerr << "Error reading `"
1102 << MakeDisplayPath(real_file)
1103 << "'\n(Check `" << name
1104 << "')\nCheck your installation and "
1105 "try Options/Reconfigure..." << endl;
1110 /* ******************************************************************* */
1112 LyXTextClassList::LyXTextClassList()
1120 LyXTextClassList::~LyXTextClassList()
1122 // The textclass list is in ar.
1129 // Gets textclass number from name
1130 signed char LyXTextClassList::NumberOfClass(string const &textclass)
1134 while (i < num_textclass && textclass != ar[i].name)
1137 if (i >= num_textclass)
1144 // Gets layout structure from style number and textclass number
1145 LyXLayout *LyXTextClassList::Style(char textclass, char layout)
1147 ar[textclass].load();
1149 if (layout < ar[textclass].number_of_defined_layouts)
1150 return &ar[textclass].style[layout];
1152 return &ar[textclass].style[0];
1157 // Gets layout number from name and textclass number
1158 char LyXTextClassList::NumberOfLayout(char textclass, string const &name)
1160 ar[textclass].load();
1163 while (i < ar[textclass].number_of_defined_layouts
1164 && name != ar[textclass].style[i].name)
1167 if (i >= ar[textclass].number_of_defined_layouts) {
1168 if (name == "dummy")
1169 i = LYX_DUMMY_LAYOUT;
1171 // so that we can detect if the layout doesn't exist.
1172 i = -1; // not found
1178 // Gets a layout (style) name from layout number and textclass number
1179 string LyXTextClassList::NameOfLayout(char textclass, char layout)
1181 ar[textclass].load();
1183 if (layout < ar[textclass].number_of_defined_layouts)
1184 return ar[textclass].style[layout].name;
1185 else if (layout == LYX_DUMMY_LAYOUT)
1192 // Gets a textclass name from number
1193 string LyXTextClassList::NameOfClass(char number)
1195 if (num_textclass == 0) {
1196 if (number == 0) return "dummy";
1197 else return "@@end@@";
1199 if (number < num_textclass)
1200 return ar[number].name;
1205 // Gets a textclass latexname from number
1206 string LyXTextClassList::LatexnameOfClass(char number)
1210 if (num_textclass == 0) {
1211 if (number == 0) return "dummy";
1212 else return "@@end@@";
1214 if (number < num_textclass)
1215 return ar[number].latexname;
1220 // Gets a textclass description from number
1221 string LyXTextClassList::DescOfClass(char number)
1223 if (num_textclass == 0) {
1224 if (number == 0) return "dummy";
1225 else return "@@end@@";
1227 if (number < num_textclass)
1228 return ar[number].description;
1234 // Gets a textclass structure from number
1235 LyXTextClass * LyXTextClassList::TextClass(char textclass)
1237 ar[textclass].load();
1238 if (textclass < num_textclass)
1239 return &ar[textclass];
1245 void LyXTextClassList::Add (LyXTextClass *t)
1247 LyXTextClassL ** h = &l;
1248 string const desc = t->description;
1249 while (*h && compare_no_case((*h)->textclass->description, desc) < 0)
1251 LyXTextClassL * tmp = new LyXTextClassL;
1259 void LyXTextClassList::ToAr ()
1261 LyXTextClassL * lp, *op;
1263 ar = new LyXTextClass [num_textclass];
1266 ar[idx].Copy (*lp->textclass);
1268 delete lp->textclass; // note we don't delete layouts
1277 // Reads LyX textclass definitions according to textclass config file
1278 bool LyXTextClassList::Read ()
1281 string real_file = LibFileSearch("", "textclass.lst");
1282 lyxerr[Debug::TCLASS] << "Reading textclasses from "
1283 << real_file << endl;
1285 if (real_file.empty()) {
1286 lyxerr << "LyXTextClassList::Read: unable to find "
1287 "textclass file `" << MakeDisplayPath(real_file, 1000)
1288 << "'. Exiting." << endl;
1290 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1291 _("Check that the file \"textclass.lst\""),
1292 _("is installed correctly. Sorry, has to exit :-("));
1294 // This causes LyX to end... Not a desirable behaviour. Lgb
1295 // What do you propose? That the user gets a file dialog
1296 // and is allowed to hunt for the file? (Asger)
1299 lex.setFile(real_file);
1302 lyxerr << "LyXTextClassList::Read: unable to open "
1303 "textclass file `" << MakeDisplayPath(real_file, 1000)
1304 << "\'\nCheck your installation. LyX can't continue."
1308 bool finished = false;
1309 string fname, clname, desc;
1310 LyXTextClass * tmpl;
1312 // Parse config-file
1313 while (lex.IsOK() && !finished) {
1314 switch (lex.lex()) {
1315 case LyXLex::LEX_FEOF:
1319 fname = lex.GetString();
1320 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1322 clname = lex.GetString();
1323 lyxerr[Debug::TCLASS]
1324 << "Clname: " << clname << endl;
1326 desc = lex.GetString();
1327 lyxerr[Debug::TCLASS]
1328 << "Desc: " << desc << endl;
1329 // This code is run when we have
1330 // fname, clname and desc
1331 tmpl =new LyXTextClass(fname,
1336 debugging(Debug::TCLASS)) {
1344 if (num_textclass == 0) {
1345 lyxerr << "LyXTextClassList::Read: no textclass found!" << endl;
1346 WriteAlert(_("LyX wasn't able to find any layout description!"),
1347 _("Check the contents of the file \"textclass.lst\""),
1348 _("Sorry, has to exit :-("));
1358 /* Returns false if this fails */
1359 bool LyXTextClassList::Load (char const number)
1363 if (number < num_textclass) {
1365 if (!ar[number].number_of_defined_layouts) {