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...");
49 if (!lyxstyle.Read()) {
50 lyxerr.print("LyXSetStyle: an error occured during parsing.");
51 lyxerr.print(" Exiting.");
55 lyxerr.debug("LyXSetStyle: configuration parsed.");
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("Reading textclass "
818 + MakeDisplayPath(filename), Error::TCLASS);
820 lyxerr.debug("Reading input file "
821 + MakeDisplayPath(filename), Error::TCLASS);
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"
884 string name = lexrc.GetString();
887 subst(name, '_',' ');
888 tmpl = l->GetLayout(name);
891 tmpl = new LyXLayout;
895 lyxerr.debug(" Reading style "+tmpl->name, Error::TCLASS);
897 if (!tmpl->Read(lexrc, l)) {
899 tmpl->resfont = tmpl->font;
900 tmpl->resfont.realize(defaultfont);
901 tmpl->reslabelfont = tmpl->labelfont;
902 tmpl->reslabelfont.realize(defaultfont);
905 // NB! we don't delete because
906 // we just pass it in....
910 "Error parsing style `"
915 //we delete dead ones here
920 lexrc.printError("No name given for style: `$$Token'.");
927 string style = lexrc.GetString();
928 if (!l->Delete(subst(style, '_', ' ')))
929 lexrc.printError("Cannot delete style `$$Token'");
935 columns = lexrc.GetInteger();
940 sides = lexrc.GetInteger();
945 pagestyle = strip(lexrc.GetString());
949 defaultfont.lyxRead(lexrc);
950 if (!defaultfont.resolved()) {
951 lexrc.printError("Warning: defaultfont should "
952 "be fully instantiated!");
953 defaultfont.realize(LyXFont::ALL_SANE);
958 switch (lexrc.lex()) {
959 case LT_COUNTER_CHAPTER:
960 maxcounter = LABEL_COUNTER_CHAPTER;
962 case LT_COUNTER_SECTION:
963 maxcounter = LABEL_COUNTER_SECTION;
965 case LT_COUNTER_SUBSECTION:
966 maxcounter = LABEL_COUNTER_SUBSECTION;
968 case LT_COUNTER_SUBSUBSECTION:
969 maxcounter = LABEL_COUNTER_SUBSUBSECTION;
971 case LT_COUNTER_PARAGRAPH:
972 maxcounter = LABEL_COUNTER_PARAGRAPH;
974 case LT_COUNTER_SUBPARAGRAPH:
975 maxcounter = LABEL_COUNTER_SUBPARAGRAPH;
977 case LT_COUNTER_ENUMI:
978 maxcounter = LABEL_COUNTER_ENUMI;
980 case LT_COUNTER_ENUMII:
981 maxcounter = LABEL_COUNTER_ENUMII;
983 case LT_COUNTER_ENUMIII:
984 maxcounter = LABEL_COUNTER_ENUMIII;
986 case LT_COUNTER_ENUMIV:
987 maxcounter = LABEL_COUNTER_ENUMIV;
994 secnumdepth = lexrc.GetInteger();
999 tocdepth = lexrc.GetInteger();
1002 // First step to support options
1003 case LT_CLASSOPTIONS:
1006 while (getout && lexrc.IsOK()) {
1007 switch (lexrc.lex()) {
1010 opt_fontsize = strip(lexrc.GetString());
1014 opt_pagestyle = strip(lexrc.GetString());
1018 options = lexrc.GetString();
1020 case LT_END: getout = false; break;
1022 lexrc.printError("Out of context tag `$$Token'");
1030 preamble = lexrc.getLongString("EndPreamble");
1033 case LT_PROVIDESAMSMATH:
1035 provides_amsmath = lexrc.GetInteger();
1038 case LT_PROVIDESMAKEIDX:
1040 provides_makeidx = lexrc.GetInteger();
1043 case LT_PROVIDESURL:
1045 provides_url = lexrc.GetInteger();
1048 case LT_LEFTMARGIN: /* left margin type */
1050 leftmargin = lexrc.GetString();
1053 case LT_RIGHTMARGIN: /* right margin type */
1055 rightmargin = lexrc.GetString();
1059 lexrc.printError("Out of context tag `$$Token'");
1064 if (!list) { // we are at top level here.
1066 number_of_defined_layouts = 0;
1067 l->Clean(); //wipe any we may have found
1072 number_of_defined_layouts = l->GetNum();
1075 lyxerr.debug("Finished reading textclass "
1076 + MakeDisplayPath(filename), Error::TCLASS);
1079 lyxerr.debug("Finished reading input file "
1080 + MakeDisplayPath(filename), Error::TCLASS);
1086 // Load textclass info if not loaded yet
1087 void LyXTextClass::load()
1093 string real_file = LibFileSearch("layouts", name, "layout");
1095 if (Read(real_file)) {
1096 lyxerr.print("Error reading `"
1097 + MakeDisplayPath(real_file) + '\'');
1098 lyxerr.print("(Check `" + name + "')");
1099 lyxerr.print("Check your installation and "
1100 "try Options/Reconfigure...");
1105 /* ******************************************************************* */
1107 LyXTextClassList::LyXTextClassList()
1115 LyXTextClassList::~LyXTextClassList()
1117 // The textclass list is in ar.
1124 // Gets textclass number from name
1125 signed char LyXTextClassList::NumberOfClass(string const &textclass)
1129 while (i < num_textclass && textclass != ar[i].name)
1132 if (i >= num_textclass)
1139 // Gets layout structure from style number and textclass number
1140 LyXLayout *LyXTextClassList::Style(char textclass, char layout)
1142 ar[textclass].load();
1144 if (layout < ar[textclass].number_of_defined_layouts)
1145 return &ar[textclass].style[layout];
1147 return &ar[textclass].style[0];
1152 // Gets layout number from name and textclass number
1153 char LyXTextClassList::NumberOfLayout(char textclass, string const &name)
1155 ar[textclass].load();
1158 while (i < ar[textclass].number_of_defined_layouts
1159 && name != ar[textclass].style[i].name)
1162 if (i >= ar[textclass].number_of_defined_layouts) {
1163 if (name == "dummy")
1164 i = LYX_DUMMY_LAYOUT;
1166 // so that we can detect if the layout doesn't exist.
1167 i = -1; // not found
1173 // Gets a layout (style) name from layout number and textclass number
1174 string LyXTextClassList::NameOfLayout(char textclass, char layout)
1176 ar[textclass].load();
1178 if (layout < ar[textclass].number_of_defined_layouts)
1179 return ar[textclass].style[layout].name;
1180 else if (layout == LYX_DUMMY_LAYOUT)
1187 // Gets a textclass name from number
1188 string LyXTextClassList::NameOfClass(char number)
1190 if (num_textclass == 0) {
1191 if (number == 0) return "dummy";
1192 else return "@@end@@";
1194 if (number < num_textclass)
1195 return ar[number].name;
1200 // Gets a textclass latexname from number
1201 string LyXTextClassList::LatexnameOfClass(char number)
1205 if (num_textclass == 0) {
1206 if (number == 0) return "dummy";
1207 else return "@@end@@";
1209 if (number < num_textclass)
1210 return ar[number].latexname;
1215 // Gets a textclass description from number
1216 string LyXTextClassList::DescOfClass(char number)
1218 if (num_textclass == 0) {
1219 if (number == 0) return "dummy";
1220 else return "@@end@@";
1222 if (number < num_textclass)
1223 return ar[number].description;
1229 // Gets a textclass structure from number
1230 LyXTextClass * LyXTextClassList::TextClass(char textclass)
1232 ar[textclass].load();
1233 if (textclass < num_textclass)
1234 return &ar[textclass];
1240 void LyXTextClassList::Add (LyXTextClass *t)
1242 LyXTextClassL ** h = &l;
1243 string const desc = t->description;
1244 while (*h && compare_no_case((*h)->textclass->description, desc) < 0)
1246 LyXTextClassL * tmp = new LyXTextClassL;
1254 void LyXTextClassList::ToAr ()
1256 LyXTextClassL * lp, *op;
1258 ar = new LyXTextClass [num_textclass];
1261 ar[idx].Copy (*lp->textclass);
1263 delete lp->textclass; // note we don't delete layouts
1272 // Reads LyX textclass definitions according to textclass config file
1273 bool LyXTextClassList::Read ()
1276 string real_file = LibFileSearch("", "textclass.lst");
1277 lyxerr.debug("Reading textclasses from "+real_file,Error::TCLASS);
1279 if (real_file.empty()) {
1280 lyxerr.print("LyXTextClassList::Read: unable to find "
1281 "textclass file `" +
1282 MakeDisplayPath(real_file, 1000) + "'. Exiting.");
1284 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1285 _("Check that the file \"textclass.lst\""),
1286 _("is installed correctly. Sorry, has to exit :-("));
1288 // This causes LyX to end... Not a desirable behaviour. Lgb
1289 // What do you propose? That the user gets a file dialog
1290 // and is allowed to hunt for the file? (Asger)
1293 lex.setFile(real_file);
1296 lyxerr.print("LyXTextClassList::Read: unable to open "
1297 "textclass file `" +
1298 MakeDisplayPath(real_file, 1000) + '\'');
1299 lyxerr.print("Check your installation. LyX can't continue.");
1302 bool finished = false;
1303 string fname, clname, desc;
1304 LyXTextClass * tmpl;
1306 // Parse config-file
1307 while (lex.IsOK() && !finished) {
1308 switch (lex.lex()) {
1309 case LyXLex::LEX_FEOF:
1313 fname = lex.GetString();
1314 lyxerr.debug("Fname: " + fname, Error::TCLASS);
1316 clname = lex.GetString();
1317 lyxerr.debug("Clname: " + clname,
1320 desc = lex.GetString();
1321 lyxerr.debug("Desc: " + desc,
1323 // This code is run when we have
1324 // fname, clname and desc
1325 tmpl =new LyXTextClass(fname,
1330 debugging(Error::TCLASS)) {
1338 if (num_textclass == 0) {
1339 lyxerr.print("LyXTextClassList::Read: no textclass found!");
1340 WriteAlert(_("LyX wasn't able to find any layout description!"),
1341 _("Check the contents of the file \"textclass.lst\""),
1342 _("Sorry, has to exit :-("));
1352 /* Returns false if this fails */
1353 bool LyXTextClassList::Load (char const number)
1357 if (number < num_textclass) {
1359 if (!ar[number].number_of_defined_layouts) {