1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ======================================================
14 #include "lyxtextclasslist.h"
15 #include "lyxtextclass.h"
19 #include "frontends/Alert.h"
21 #include "support/lyxfunctional.h"
22 #include "support/LAssert.h"
23 #include "support/filetools.h"
27 #ifndef CXX_GLOBAL_CSTD
31 using lyx::textclass_type;
39 // Gets textclass number from name
40 pair<bool, textclass_type> const
41 LyXTextClassList::NumberOfClass(string const & textclass) const
43 ClassList::const_iterator cit =
44 find_if(classlist_.begin(), classlist_.end(),
45 lyx::compare_memfun(&LyXTextClass::name, textclass));
46 return cit != classlist_.end() ?
47 make_pair(true, textclass_type(cit - classlist_.begin())) :
48 make_pair(false, textclass_type(0));
52 // Gets a textclass structure from number
54 LyXTextClassList::operator[](textclass_type textclass) const
56 classlist_[textclass].load();
57 if (textclass < classlist_.size())
58 return classlist_[textclass];
64 // used when sorting the textclass list.
65 class less_textclass_desc {
67 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
68 return tc1.description() < tc2.description();
73 // Reads LyX textclass definitions according to textclass config file
74 bool LyXTextClassList::Read()
77 string real_file = LibFileSearch("", "textclass.lst");
78 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
79 << real_file << '\'' << endl;
81 if (real_file.empty()) {
82 lyxerr << "LyXTextClassList::Read: unable to find "
83 "textclass file `" << MakeDisplayPath(real_file, 1000)
84 << "'. Exiting." << endl;
86 // This causes LyX to end... Not a desirable behaviour. Lgb
87 // What do you propose? That the user gets a file dialog
88 // and is allowed to hunt for the file? (Asger)
89 // more that we have a layout for minimal.cls statically
90 // compiled in... (Lgb)
93 if (!lex.setFile(real_file)) {
94 lyxerr << "LyXTextClassList::Read: "
95 "lyxlex was not able to set file: "
100 lyxerr << "LyXTextClassList::Read: unable to open "
101 "textclass file `" << MakeDisplayPath(real_file, 1000)
102 << "'\nCheck your installation. LyX can't continue."
107 bool finished = false;
109 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
110 while (lex.isOK() && !finished) {
111 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
113 case LyXLex::LEX_FEOF:
117 string const fname = lex.getString();
118 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
120 string const clname = lex.getString();
121 lyxerr[Debug::TCLASS] << "Clname: " << clname << endl;
123 string const desc = lex.getString();
124 lyxerr[Debug::TCLASS] << "Desc: " << desc << endl;
125 // This code is run when we have
126 // fname, clname and desc
127 LyXTextClass tmpl(fname, clname, desc);
128 if (lyxerr.debugging(Debug::TCLASS)) {
131 classlist_.push_back(tmpl);
136 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
138 if (classlist_.empty()) {
139 lyxerr << "LyXTextClassList::Read: no textclasses found!"
143 // Ok everything loaded ok, now sort the list.
144 sort(classlist_.begin(), classlist_.end(), less_textclass_desc());
149 // Global variable: textclass table.
150 LyXTextClassList textclasslist;
152 // Reads the style files
155 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
157 if (!textclasslist.Read()) {
158 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
159 "during parsing.\n Exiting." << endl;
163 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;