2 * \file lyxtextclasslist.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "lyxtextclasslist.h"
15 #include "lyxtextclass.h"
19 #include "support/lyxfunctional.h"
20 #include "support/filetools.h"
23 using namespace lyx::support;
25 #ifndef CXX_GLOBAL_CSTD
29 using lyx::textclass_type;
37 // Gets textclass number from name
38 pair<bool, textclass_type> const
39 LyXTextClassList::NumberOfClass(string const & textclass) const
41 ClassList::const_iterator cit =
42 find_if(classlist_.begin(), classlist_.end(),
43 lyx::compare_memfun(&LyXTextClass::name, textclass));
44 return cit != classlist_.end() ?
45 make_pair(true, textclass_type(cit - classlist_.begin())) :
46 make_pair(false, textclass_type(0));
50 // Gets a textclass structure from number
52 LyXTextClassList::operator[](textclass_type textclass) const
54 classlist_[textclass].load();
55 if (textclass < classlist_.size())
56 return classlist_[textclass];
62 // used when sorting the textclass list.
63 class less_textclass_avail_desc {
65 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
67 // 1. Availability of text class
68 // 2. Description (lexicographic)
70 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
71 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
72 tc1.description() < tc2.description());
77 // Reads LyX textclass definitions according to textclass config file
78 bool LyXTextClassList::Read()
81 string real_file = LibFileSearch("", "textclass.lst");
82 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
83 << real_file << '\'' << endl;
85 if (real_file.empty()) {
86 lyxerr << "LyXTextClassList::Read: unable to find "
87 "textclass file `" << MakeDisplayPath(real_file, 1000)
88 << "'. Exiting." << endl;
90 // This causes LyX to end... Not a desirable behaviour. Lgb
91 // What do you propose? That the user gets a file dialog
92 // and is allowed to hunt for the file? (Asger)
93 // more that we have a layout for minimal.cls statically
94 // compiled in... (Lgb)
97 if (!lex.setFile(real_file)) {
98 lyxerr << "LyXTextClassList::Read: "
99 "lyxlex was not able to set file: "
100 << real_file << endl;
104 lyxerr << "LyXTextClassList::Read: unable to open "
105 "textclass file `" << MakeDisplayPath(real_file, 1000)
106 << "'\nCheck your installation. LyX can't continue."
111 bool finished = false;
113 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
114 while (lex.isOK() && !finished) {
115 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
117 case LyXLex::LEX_FEOF:
121 string const fname = lex.getString();
122 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
124 string const clname = lex.getString();
125 lyxerr[Debug::TCLASS] << "Clname: " << clname << endl;
127 string const desc = lex.getString();
128 lyxerr[Debug::TCLASS] << "Desc: " << desc << endl;
130 bool avail = lex.getBool();
131 lyxerr[Debug::TCLASS] << "Avail: " << avail << endl;
132 // This code is run when we have
133 // fname, clname, desc, and avail
134 LyXTextClass tmpl(fname, clname, desc, avail);
135 if (lyxerr.debugging(Debug::TCLASS)) {
138 classlist_.push_back(tmpl);
144 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
146 if (classlist_.empty()) {
147 lyxerr << "LyXTextClassList::Read: no textclasses found!"
151 // Ok everything loaded ok, now sort the list.
152 sort(classlist_.begin(), classlist_.end(), less_textclass_avail_desc());
157 // Global variable: textclass table.
158 LyXTextClassList textclasslist;
161 // Reads the style files
164 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration..." << endl;
166 if (!textclasslist.Read()) {
167 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
168 "during parsing.\n Exiting." << endl;
172 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;