/* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1998 The LyX Team. *
*======================================================*/
/* Change log: * * 14/11/1995, Pascal André <andre@via.ecp.fr> * Modified for external style definition. * * 15/11/1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx> * Modified to use binary search and a small pseudo lexical analyzer. * * 29/03/1996, Dirk Niggeman * Created classes LyXTextClass & LyXLayout. * * 30/03/1996, asierra * Created class LyxLex and improved the lexical analyzer.
*/
lexrc.setFile(filename); if (!lexrc.IsOK()) return -2;
LyXLayoutList * l;
LyXLayout * tmpl;
if (list)
l = list; else
l = new LyXLayoutList;
/* parsing */ while (lexrc.IsOK() && !error) { switch(lexrc.lex()) { case -2: break;
case -1:
lexrc.printError("Unknown tag `$$Token'");
error = true; break;
case LT_OUTPUTTYPE: // output type definition switch(lexrc.lex()) { case LT_OTLATEX:
output_type=LATEX; break; case LT_OTLINUXDOC:
output_type=LINUXDOC; break; case LT_OTDOCBOOK:
output_type=DOCBOOK; break; default:
lexrc.printError("Unknown output type `$$Token'"); break;
} break;
case LT_INPUT: // Include file if (lexrc.next()) {
LString tmp = LibFileSearch("layouts",
lexrc.GetString(), "layout");
if (!tmpl->Read(lexrc, l)) { // Resolve fonts
tmpl->resfont = tmpl->font;
tmpl->resfont.realize(defaultfont);
tmpl->reslabelfont = tmpl->labelfont;
tmpl->reslabelfont.realize(defaultfont); if (is_new) {
l->Add (tmpl); // NB! we don't delete because // we just pass it in....
}
} else {
lexrc.printError( "Error parsing style `"
+tmpl->name+'\'');
error = true; if (is_new) { delete tmpl; //we delete dead ones here
}
}
} else {
lexrc.printError("No name given for style: `$$Token'.");
error = true;
} break;
case LT_NOSTYLE: if (lexrc.next()) {
LString style = lexrc.GetString(); if (!l->Delete(style.subst('_', ' ')))
lexrc.printError("Cannot delete style `$$Token'");
} break;
case LT_COLUMNS: if (lexrc.next())
columns = lexrc.GetInteger(); break;
case LT_SIDES: if (lexrc.next())
sides = lexrc.GetInteger(); break;
case LT_PAGESTYLE:
lexrc.next();
pagestyle = lexrc.GetString();
pagestyle.strip(); break;
case LT_DEFAULTFONT:
defaultfont.lyxRead(lexrc); if (!defaultfont.resolved()) {
lexrc.printError("Warning: defaultfont should " "be fully instantiated!");
defaultfont.realize(LyXFont::ALL_SANE);
} break;
case LT_MAXCOUNTER: switch (lexrc.lex()) { case LT_COUNTER_CHAPTER:
maxcounter = LABEL_COUNTER_CHAPTER; break; case LT_COUNTER_SECTION:
maxcounter = LABEL_COUNTER_SECTION; break; case LT_COUNTER_SUBSECTION:
maxcounter = LABEL_COUNTER_SUBSECTION; break; case LT_COUNTER_SUBSUBSECTION:
maxcounter = LABEL_COUNTER_SUBSUBSECTION; break; case LT_COUNTER_PARAGRAPH:
maxcounter = LABEL_COUNTER_PARAGRAPH; break; case LT_COUNTER_SUBPARAGRAPH:
maxcounter = LABEL_COUNTER_SUBPARAGRAPH; break; case LT_COUNTER_ENUMI:
maxcounter = LABEL_COUNTER_ENUMI; break; case LT_COUNTER_ENUMII:
maxcounter = LABEL_COUNTER_ENUMII; break; case LT_COUNTER_ENUMIII:
maxcounter = LABEL_COUNTER_ENUMIII; break; case LT_COUNTER_ENUMIV:
maxcounter = LABEL_COUNTER_ENUMIV; break;
} break;
case LT_SECNUMDEPTH:
lexrc.next();
secnumdepth = lexrc.GetInteger(); break;
case LT_TOCDEPTH:
lexrc.next();
tocdepth = lexrc.GetInteger(); break;
// First step to support options case LT_CLASSOPTIONS:
{ bool getout = true; while (getout && lexrc.IsOK()) { switch (lexrc.lex()) { case LT_FONTSIZE:
lexrc.next();
opt_fontsize = lexrc.GetString();
opt_fontsize.strip(); break; case LT_PAGESTYLE:
lexrc.next();
opt_pagestyle = lexrc.GetString();
opt_pagestyle.strip(); break; case LT_OTHER:
lexrc.next();
options = lexrc.GetString(); break; case LT_END: getout = false; break; default:
lexrc.printError("Out of context tag `$$Token'"); break;
}
} break;
}
case LT_PREAMBLE:
preamble = lexrc.getLongString("EndPreamble"); break;
case LT_LEFTMARGIN: /* left margin type */ if (lexrc.next())
leftmargin = lexrc.GetString(); break;
case LT_RIGHTMARGIN: /* right margin type */ if (lexrc.next())
rightmargin = lexrc.GetString(); break;
default:
lexrc.printError("Out of context tag `$$Token'"); break;
}
}
if (!list) { // we are at top level here. if (error) {
number_of_defined_layouts = 0;
l->Clean(); //wipe any we may have found delete l;
} else {
style = l->ToAr();
number_of_defined_layouts = l->GetNum(); delete l;
}
lyxerr.debug("Finished reading textclass "
+ MakeDisplayPath(filename), Error::TCLASS);
} else
lyxerr.debug("Finished reading input file "
+ MakeDisplayPath(filename), Error::TCLASS);
return error;
}
// Load textclass info if not loaded yet void LyXTextClass::load()
{ if (loaded) return;
LyXTextClassList::LyXTextClassList()
{
l = 0;
ar = 0;
num_textclass = 0;
}
LyXTextClassList::~LyXTextClassList()
{ // The textclass list is in ar. if (ar) { delete [] ar;
}
}
// Gets textclass number from name signedchar LyXTextClassList::NumberOfClass(LString const &textclass)
{ int i = 0;
while (i < num_textclass && textclass != ar[i].name)
i++;
if (i >= num_textclass)
i = -1;
return i;
}
// Gets layout structure from style number and textclass number
LyXLayout *LyXTextClassList::Style(char textclass, char layout)
{
ar[textclass].load();
// Gets layout number from name and textclass number char LyXTextClassList::NumberOfLayout(char textclass, LString const &name)
{
ar[textclass].load();
int i = 0; while (i < ar[textclass].number_of_defined_layouts
&& name != ar[textclass].style[i].name)
i++;
if (i >= ar[textclass].number_of_defined_layouts) { if (name == "dummy")
i = LYX_DUMMY_LAYOUT; else // so that we can detect if the layout doesn't exist.
i = -1; // not found
} return i;
}
// Gets a layout (style) name from layout number and textclass number
LString LyXTextClassList::NameOfLayout(char textclass, char layout)
{
ar[textclass].load();
// Gets a textclass name from number
LString LyXTextClassList::NameOfClass(char number)
{ if (num_textclass == 0) { if (number == 0) return"dummy"; elsereturn"@@end@@";
} if (number < num_textclass) return ar[number].name; else return"@@end@@";
}
// Gets a textclass latexname from number
LString LyXTextClassList::LatexnameOfClass(char number)
{
ar[number].load();
if (num_textclass == 0) { if (number == 0) return"dummy"; elsereturn"@@end@@";
} if (number < num_textclass) return ar[number].latexname; else return"@@end@@";
}
// Gets a textclass description from number
LString LyXTextClassList::DescOfClass(char number)
{ if (num_textclass == 0) { if (number == 0) return"dummy"; elsereturn"@@end@@";
} if (number < num_textclass) return ar[number].description; else return"@@end@@";
}
// Gets a textclass structure from number
LyXTextClass * LyXTextClassList::TextClass(char textclass)
{
ar[textclass].load(); if (textclass < num_textclass) return &ar[textclass]; else return &ar[0];
}
void LyXTextClassList::Add (LyXTextClass *t)
{
LyXTextClassL ** h = &l; charconst *desc = t->description.c_str(); while (*h && strcasecmp((*h)->textclass->description.c_str(),desc)<0)
h = &((*h)->next);
LyXTextClassL * tmp = new LyXTextClassL;
tmp->textclass = t;
tmp->next = *h;
*h = tmp;
num_textclass++;
}
void LyXTextClassList::ToAr ()
{
LyXTextClassL * lp, *op; int idx = 0;
ar = new LyXTextClass [num_textclass];
lp = l; while (lp) {
ar[idx].Copy (*lp->textclass);
idx++; delete lp->textclass; // note we don't delete layouts // here at all
op = lp;
lp = lp->next; delete op;
}
}
// Reads LyX textclass definitions according to textclass config file bool LyXTextClassList::Read ()
{
LyXLex lex(NULL, 0);
LString real_file = LibFileSearch("", "textclass.lst");
lyxerr.debug("Reading textclasses from "+real_file,Error::TCLASS);
if (real_file.empty()) {
lyxerr.print("LyXTextClassList::Read: unable to find " "textclass file `" +
MakeDisplayPath(real_file, 1000) + "'. Exiting.");
WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
_("Check that the file \"textclass.lst\""),
_("is installed correctly. Sorry, has to exit :-(")); returnfalse; // This causes LyX to end... Not a desirable behaviour. Lgb // What do you propose? That the user gets a file dialog // and is allowed to hunt for the file? (Asger)
}
lex.setFile(real_file);
if (!lex.IsOK()) {
lyxerr.print("LyXTextClassList::Read: unable to open " "textclass file `" +
MakeDisplayPath(real_file, 1000) + '\'');
lyxerr.print("Check your installation. LyX can't continue."); returnfalse;
} bool finished = false;
LString fname, clname, desc;
LyXTextClass * tmpl;
// Parse config-file while (lex.IsOK() && !finished) { switch (lex.lex()) { case LyXLex::LEX_FEOF:
finished = true; break; default:
fname = lex.GetString();
lyxerr.debug("Fname: " + fname, Error::TCLASS); if (lex.next()) {
clname = lex.GetString();
lyxerr.debug("Clname: " + clname,
Error::TCLASS); if (lex.next()) {
desc = lex.GetString();
lyxerr.debug("Desc: " + desc,
Error::TCLASS); // This code is run when we have // fname, clname and desc
tmpl =new LyXTextClass(fname,
clname,
desc);
Add (tmpl); if (lyxerr.
debugging(Error::TCLASS)) {
tmpl->load();
}
}
}
}
}
if (num_textclass == 0) {
lyxerr.print("LyXTextClassList::Read: no textclass found!");
WriteAlert(_("LyX wasn't able to find any layout description!"),
_("Check the contents of the file \"textclass.lst\""),
_("Sorry, has to exit :-(")); returnfalse;
} else {
ToAr(); returntrue;
}
}
// Load textclass /* Returns false if this fails */ bool LyXTextClassList::Load (charconst number)
{ bool result = 1;
if (number < num_textclass) {
ar[number].load(); if (!ar[number].number_of_defined_layouts) {
result = 0;
}
} else {
result = 0;
} return result;
}
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.