fix macro, small cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1623 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-26 12:53:35 +00:00
parent b6cff00278
commit 2be247f6ef
23 changed files with 964 additions and 891 deletions

View File

@ -1,3 +1,21 @@
2001-02-26 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* math_macroarg.C (MathMacroArgument): delete
* math_macro.C (~MathMacro): delete
* math_macrotemplate.C (~MathMacroTemplate): delete
* math_decorationinset.[Ch]: add pragma
* math_deliminset.[Ch]: likewise
* math_fracinset.[Ch]: likewise
* math_macroarg.[Ch]: likewise
* math_macrotemplate.[Ch]: likewise
* math_matrixinset.[Ch]: likewise
* formulamacro.C (Read): set contents of tmacro_ to ar.
* formulamacro.h: add '_' to private variables.
* formalamacro.C: changes because of this.
2001-02-23 Juergen Vigna <jug@sad.it> 2001-02-23 Juergen Vigna <jug@sad.it>
* formula.C (LocalDispatch): changed action to be a kb_action (as it * formula.C (LocalDispatch): changed action to be a kb_action (as it

View File

@ -34,6 +34,7 @@
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include "mathed/support.h" #include "mathed/support.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "debug.h"
using std::ostream; using std::ostream;
using std::istream; using std::istream;
@ -41,20 +42,20 @@ using std::istream;
InsetFormulaMacro::InsetFormulaMacro() InsetFormulaMacro::InsetFormulaMacro()
: InsetFormula(true) : InsetFormula(true)
{ {
tmacro = 0; tmacro_ = 0;
opened = false; opened_ = false;
} }
InsetFormulaMacro::InsetFormulaMacro(string nm, int na, bool /*e*/) InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
: InsetFormula(true), name(nm) : InsetFormula(true), name_(nm)
{ {
tmacro = MathMacroTable::mathMTable.getTemplate(name); tmacro_ = MathMacroTable::mathMTable.getTemplate(name_);
if (!tmacro) { if (!tmacro_) {
tmacro = new MathMacroTemplate(name.c_str(), na); tmacro_ = new MathMacroTemplate(name_, na);
MathMacroTable::mathMTable.addTemplate(tmacro); MathMacroTable::mathMTable.addTemplate(tmacro_);
} }
opened = false; opened_ = false;
} }
@ -66,21 +67,21 @@ InsetFormulaMacro::~InsetFormulaMacro()
Inset * InsetFormulaMacro::Clone(Buffer const &) const Inset * InsetFormulaMacro::Clone(Buffer const &) const
{ {
return new InsetFormulaMacro(name); return new InsetFormulaMacro(name_);
} }
void InsetFormulaMacro::Write(Buffer const *, ostream & os) const void InsetFormulaMacro::Write(Buffer const *, ostream & os) const
{ {
os << "FormulaMacro "; os << "FormulaMacro ";
tmacro->WriteDef(os, false); tmacro_->WriteDef(os, false);
} }
int InsetFormulaMacro::Latex(Buffer const *, ostream & os, bool /*fragile*/, int InsetFormulaMacro::Latex(Buffer const *, ostream & os, bool /*fragile*/,
bool /*free_spacing*/) const bool /*free_spacing*/) const
{ {
tmacro->WriteDef(os, true); // or false? tmacro_->WriteDef(os, true); // or false?
return 2; return 2;
} }
@ -102,14 +103,18 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
istream & is = lex.getStream(); istream & is = lex.getStream();
mathed_parser_file(is, lex.GetLineNo()); mathed_parser_file(is, lex.GetLineNo());
MathedArray ar; MathedArray ar;
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro));
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_));
tmacro_->setData(ar);
// Update line number // Update line number
lex.setLineNo(mathed_parser_lineno()); lex.setLineNo(mathed_parser_lineno());
MathMacroTable::mathMTable.addTemplate(tmacro); MathMacroTable::mathMTable.addTemplate(tmacro_);
name = tmacro->GetName(); name_ = tmacro_->GetName();
par = tmacro; par = tmacro_;
// reading of end_inset in the inset!!! // reading of end_inset in the inset!!!
while (lex.IsOK()) { while (lex.IsOK()) {
lex.nextToken(); lex.nextToken();
@ -121,8 +126,8 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
{ {
if (opened) { if (opened_) {
tmacro->update(); tmacro_->update();
return InsetFormula::ascent(pain, f); return InsetFormula::ascent(pain, f);
} }
return lyxfont::maxAscent(f) + 3; return lyxfont::maxAscent(f) + 3;
@ -131,8 +136,8 @@ int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
{ {
if (opened) { if (opened_) {
tmacro->update(); tmacro_->update();
return InsetFormula::descent(pain, f); return InsetFormula::descent(pain, f);
} }
return lyxfont::maxDescent(f) + 1; return lyxfont::maxDescent(f) + 1;
@ -141,12 +146,12 @@ int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
{ {
if (opened) { if (opened_) {
tmacro->update(); tmacro_->update();
return InsetFormula::width(bv, f); return InsetFormula::width(bv, f);
} }
string ilabel(_("Macro: ")); string ilabel(_("Macro: "));
ilabel += name; ilabel += name_;
return 6 + lyxfont::width(ilabel, f); return 6 + lyxfont::width(ilabel, f);
} }
@ -156,11 +161,11 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
{ {
Painter & pain = bv->painter(); Painter & pain = bv->painter();
LyXFont font(f); LyXFont font(f);
tmacro->update(); tmacro_->update();
if (opened) { if (opened_) {
tmacro->setEditMode(true); tmacro_->setEditMode(true);
InsetFormula::draw(bv, font, baseline, x, cleared); InsetFormula::draw(bv, font, baseline, x, cleared);
tmacro->setEditMode(false); tmacro_->setEditMode(false);
} else { } else {
font.setColor(LColor::math); font.setColor(LColor::math);
@ -172,7 +177,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
pain.rectangle(int(x), y, w, h, LColor::mathframe); pain.rectangle(int(x), y, w, h, LColor::mathframe);
string s(_("Macro: ")); string s(_("Macro: "));
s += name; s += name_;
pain.text(int(x + 2), baseline, s, font); pain.text(int(x + 2), baseline, s, font);
x += width(bv, font) - 1; x += width(bv, font) - 1;
} }
@ -187,17 +192,17 @@ string const InsetFormulaMacro::EditMessage() const
void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button) void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
{ {
opened = true; opened_ = true;
par = static_cast<MathParInset*>(tmacro->Clone()); par = static_cast<MathParInset*>(tmacro_->Clone());
InsetFormula::Edit(bv, x, y, button); InsetFormula::Edit(bv, x, y, button);
} }
void InsetFormulaMacro::InsetUnlock(BufferView * bv) void InsetFormulaMacro::InsetUnlock(BufferView * bv)
{ {
opened = false; opened_ = false;
tmacro->setData(par->GetData()); tmacro_->setData(par->GetData());
tmacro->setEditMode(false); tmacro_->setEditMode(false);
InsetFormula::InsetUnlock(bv); InsetFormula::InsetUnlock(bv);
} }
@ -207,19 +212,19 @@ InsetFormulaMacro::LocalDispatch(BufferView * bv,
kb_action action, string const & arg) kb_action action, string const & arg)
{ {
if (action == LFUN_MATH_MACROARG) { if (action == LFUN_MATH_MACROARG) {
int i = lyx::atoi(arg) - 1; int const i = lyx::atoi(arg) - 1;
if (i >= 0 && i < tmacro->getNoArgs()) { if (i >= 0 && i < tmacro_->getNoArgs()) {
mathcursor->insertInset(tmacro->getMacroPar(i), mathcursor->insertInset(tmacro_->getMacroPar(i),
LM_TC_INSET); LM_TC_INSET);
InsetFormula::UpdateLocal(bv); InsetFormula::UpdateLocal(bv);
} }
return DISPATCHED; return DISPATCHED;
} }
tmacro->setEditMode(true); tmacro_->setEditMode(true);
tmacro->Metrics(); tmacro_->Metrics();
RESULT result = InsetFormula::LocalDispatch(bv, action, arg); RESULT result = InsetFormula::LocalDispatch(bv, action, arg);
tmacro->setEditMode(false); tmacro_->setEditMode(false);
return result; return result;
} }

View File

@ -33,7 +33,7 @@ public:
InsetFormulaMacro(); InsetFormulaMacro();
/// ///
explicit explicit
InsetFormulaMacro(string name, int na = 0, bool env = false); InsetFormulaMacro(string name, int na = 0);
/// ///
~InsetFormulaMacro(); ~InsetFormulaMacro();
/// ///
@ -58,7 +58,7 @@ public:
/// ///
Inset * Clone(Buffer const &) const; Inset * Clone(Buffer const &) const;
/// ///
Inset::Code LyxCode() const { return Inset::MATHMACRO_CODE; } Inset::Code LyxCode() const;
/// what appears in the minibuffer when opening /// what appears in the minibuffer when opening
string const EditMessage() const; string const EditMessage() const;
/// ///
@ -70,11 +70,17 @@ public:
private: private:
/// ///
bool opened; bool opened_;
/// ///
string name; string name_;
/// ///
MathMacroTemplate * tmacro; MathMacroTemplate * tmacro_;
}; };
inline
Inset::Code InsetFormulaMacro::LyxCode() const
{
return Inset::MATHMACRO_CODE;
}
#endif #endif

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_decorationinset.h" #include "math_decorationinset.h"
#include "math_iter.h" #include "math_iter.h"
#include "mathed/support.h" #include "mathed/support.h"
@ -39,7 +43,7 @@ MathDecorationInset::draw(Painter & pain, int x, int y)
void void
MathDecorationInset::Metrics() MathDecorationInset::Metrics()
{ {
int h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I', int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
ascent, descent); ascent, descent);
MathParInset::Metrics(); MathParInset::Metrics();
int w = Width() + 4; int w = Width() + 4;

View File

@ -1,12 +1,17 @@
// -*- C++ -*-
#ifndef MATH_DECORATIONINSET_H #ifndef MATH_DECORATIONINSET_H
#define MATH_DECORATIONINSET_H #define MATH_DECORATIONINSET_H
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Decorations over (below) a math object /** Decorations over (below) a math object
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
class MathDecorationInset: public MathParInset { class MathDecorationInset : public MathParInset {
public: public:
/// ///
MathDecorationInset(int, short st = LM_ST_TEXT); MathDecorationInset(int, short st = LM_ST_TEXT);

View File

@ -120,7 +120,7 @@ enum MathedTextCodes {
LM_TC_MAX LM_TC_MAX
}; };
/// /// Defined in math_macro.C
std::ostream & operator<<(std::ostream &, MathedTextCodes mtc); std::ostream & operator<<(std::ostream &, MathedTextCodes mtc);

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_deliminset.h" #include "math_deliminset.h"
#include "math_iter.h" #include "math_iter.h"
#include "math_parser.h" #include "math_parser.h"
@ -78,8 +82,8 @@ void
MathDelimInset::Metrics() MathDelimInset::Metrics()
{ {
MathParInset::Metrics(); MathParInset::Metrics();
int d;
int d;
mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_); mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_);
dh_ /= 2; dh_ /= 2;
ascent += 2 + dh_; ascent += 2 + dh_;

View File

@ -4,6 +4,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** A delimiter /** A delimiter
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_fracinset.h" #include "math_fracinset.h"
#include "math_iter.h" #include "math_iter.h"
#include "LColor.h" #include "LColor.h"
@ -96,7 +100,7 @@ MathedArray & MathFracInset::GetData()
bool MathFracInset::Inside(int x, int y) bool MathFracInset::Inside(int x, int y)
{ {
int xx = xo() - (width - w0_) / 2; int const xx = xo() - (width - w0_) / 2;
return x >= xx return x >= xx
&& x <= xx + width && x <= xx + width

View File

@ -4,6 +4,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Fraction like objects (frac, stackrel, binom) /** Fraction like objects (frac, stackrel, binom)
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */

View File

@ -75,11 +75,6 @@ MathMacro::MathMacro(MathMacro * m):
} }
MathMacro::~MathMacro()
{
}
MathedInset * MathMacro::Clone() MathedInset * MathMacro::Clone()
{ {
return new MathMacro(this); return new MathMacro(this);

View File

@ -41,8 +41,6 @@ public:
explicit explicit
MathMacro(MathMacro *); MathMacro(MathMacro *);
/// ///
~MathMacro();
///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
void Metrics(); void Metrics();

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macroarg.h" #include "math_macroarg.h"
#include "mathed/support.h" #include "mathed/support.h"
#include "debug.h" #include "debug.h"
@ -19,12 +23,6 @@ MathMacroArgument::MathMacroArgument(int n)
} }
MathMacroArgument::~MathMacroArgument()
{
lyxerr << "help, destroyme!" << std::endl;
}
MathedInset * MathMacroArgument::Clone() MathedInset * MathMacroArgument::Clone()
{ {
return this; return this;

View File

@ -4,6 +4,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** A macro argument /** A macro argument
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
@ -15,8 +19,6 @@ public:
explicit explicit
MathMacroArgument(int); MathMacroArgument(int);
/// ///
~MathMacroArgument();
///
MathedInset * Clone(); MathedInset * Clone();
/// ///
void Metrics(); void Metrics();

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
#include "math_macro.h" #include "math_macro.h"
#include "macro_support.h" #include "macro_support.h"
@ -8,24 +12,6 @@
using std::ostream; using std::ostream;
void MathMacroTemplate::setTCode(MathedTextCodes t)
{
tcode_ = t;
}
MathedTextCodes MathMacroTemplate::getTCode() const
{
return tcode_;
}
int MathMacroTemplate::getNoArgs() const
{
return nargs_;
}
MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg): MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO), MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags_(flg), nargs_(na) flags_(flg), nargs_(na)
@ -44,8 +30,26 @@ MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
} }
MathMacroTemplate::~MathMacroTemplate() //MathMacroTemplate::~MathMacroTemplate()
{} //{}
void MathMacroTemplate::setTCode(MathedTextCodes t)
{
tcode_ = t;
}
MathedTextCodes MathMacroTemplate::getTCode() const
{
return tcode_;
}
int MathMacroTemplate::getNoArgs() const
{
return nargs_;
}
void MathMacroTemplate::setEditMode(bool ed) void MathMacroTemplate::setEditMode(bool ed)

View File

@ -7,6 +7,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#include "math_macroarg.h" #include "math_macroarg.h"
#ifdef __GNUG__
#pragma interface
#endif
class MathMacro; class MathMacro;
/** This class contains the macro definition /** This class contains the macro definition
@ -18,7 +22,7 @@ public:
explicit explicit
MathMacroTemplate(string const &, int na = 0, int f = 0); MathMacroTemplate(string const &, int na = 0, int f = 0);
/// ///
~MathMacroTemplate(); //~MathMacroTemplate();
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
@ -45,9 +49,7 @@ public:
/// Replace the appropriate arguments with a specific macro's data /// Replace the appropriate arguments with a specific macro's data
void update(MathMacro * m = 0); void update(MathMacro * m = 0);
/// ///
short flags() const { short flags() const;
return flags_;
}
private: private:
/// ///
short flags_; short flags_;
@ -58,4 +60,10 @@ private:
/// ///
int nargs_; int nargs_;
}; };
inline
short MathMacroTemplate::flags() const {
return flags_;
}
#endif #endif

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_matrixinset.h" #include "math_matrixinset.h"
#include "math_rowst.h" #include "math_rowst.h"
#include "math_xiter.h" #include "math_xiter.h"
@ -171,7 +175,7 @@ void MathMatrixInset::Metrics()
cxrow = cxrow->getNext(); cxrow = cxrow->getNext();
} }
int hl = Descent(); int const hl = Descent();
h -= MATH_ROWSEP; h -= MATH_ROWSEP;
// Compute vertical align // Compute vertical align
@ -229,7 +233,7 @@ void MathMatrixInset::Metrics()
lf = (ws_[i] - cxrow->getTab(i))/2; lf = (ws_[i] - cxrow->getTab(i))/2;
break; break;
} }
int ww = (isvoid) ? lf : lf + cxrow->getTab(i); int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
cxrow->setTab(i, lf + rg); cxrow->setTab(i, lf + rg);
rg = ws_[i] - ww + MATH_COLSEP; rg = ws_[i] - ww + MATH_COLSEP;
if (cxrow == row_) if (cxrow == row_)

View File

@ -6,6 +6,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Multiline math paragraph base class. /** Multiline math paragraph base class.
This is the base to all multiline editable math objects This is the base to all multiline editable math objects
like array and eqnarray. like array and eqnarray.
@ -20,9 +24,9 @@ public:
explicit explicit
MathMatrixInset(MathMatrixInset *); MathMatrixInset(MathMatrixInset *);
/// ///
MathedInset * Clone(); ~MathMatrixInset();
/// ///
virtual ~MathMatrixInset(); MathedInset * Clone();
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///

View File

@ -78,6 +78,7 @@ union YYSTYPE {
latexkeys const * l; latexkeys const * l;
}; };
static static
YYSTYPE yylval; YYSTYPE yylval;
@ -85,6 +86,7 @@ YYSTYPE yylval;
static static
MathedInsetTypes mathed_env = LM_OT_MIN; MathedInsetTypes mathed_env = LM_OT_MIN;
string mathed_label; string mathed_label;
@ -105,10 +107,9 @@ char const * latex_mathenv[latex_mathenv_num] = {
}; };
char const * latex_special_chars = "#$%&_{}"; char const * latex_special_chars = "#$%&_{}";
// These are lexical codes, not semantic // These are lexical codes, not semantic
enum lexcode_enum { enum lexcode_enum {
LexNone, LexNone,
@ -127,6 +128,7 @@ enum lexcode_enum {
LexSelf LexSelf
}; };
static lexcode_enum lexcode[256]; static lexcode_enum lexcode[256];
#warning Replace with string #warning Replace with string
//static char yytext[256]; //static char yytext[256];
@ -135,7 +137,8 @@ static int yylineno;
static istream * yyis; static istream * yyis;
static bool yy_mtextmode= false; static bool yy_mtextmode= false;
static
static inline
void mathPrintError(string const & msg) void mathPrintError(string const & msg)
{ {
lyxerr << "Line ~" << yylineno << ": Math parse error: " lyxerr << "Line ~" << yylineno << ": Math parse error: "
@ -147,20 +150,25 @@ static
void LexInitCodes() void LexInitCodes()
{ {
for (int i = 0; i <= 255; ++i) { for (int i = 0; i <= 255; ++i) {
if (isalpha(i)) lexcode[i] = LexAlpha; if (isalpha(i))
else if (isdigit(i)) lexcode[i] = LexDigit; lexcode[i] = LexAlpha;
else if (isspace(i)) lexcode[i] = LexSpace; else if (isdigit(i))
else lexcode[i] = LexNone; lexcode[i] = LexDigit;
else if (isspace(i))
lexcode[i] = LexSpace;
else
lexcode[i] = LexNone;
} }
lexcode['\t'] = lexcode['\f'] = lexcode[' '] = LexSpace; lexcode['\t'] = lexcode['\f'] = lexcode[' '] = LexSpace;
lexcode['\n'] = LexNewLine; lexcode['\n'] = LexNewLine;
lexcode['%'] = LexComment; lexcode['%'] = LexComment;
lexcode['#'] = LexArgument; lexcode['#'] = LexArgument;
lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/'] = lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/']
lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP; = lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP;
lexcode['!'] = lexcode[','] = lexcode[':'] = lexcode[';'] = LexMathSpace; lexcode['!'] = lexcode[','] = lexcode[':']
= lexcode[';'] = LexMathSpace;
lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] = lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] =
lexcode['?'] = LexOther; lexcode['?'] = LexOther;
@ -177,13 +185,14 @@ void LexInitCodes()
static static
char LexGetArg(char lf, bool accept_spaces= false) char LexGetArg(char lf, bool accept_spaces = false)
{ {
unsigned char c; // unsigned char c;
char cc; // char cc;
while (yyis->good()) { while (yyis->good()) {
char cc;
yyis->get(cc); yyis->get(cc);
c = cc; unsigned char c = cc;
if (c > ' ') { if (c > ' ') {
if (!lf) if (!lf)
lf = c; lf = c;
@ -196,7 +205,9 @@ char LexGetArg(char lf, bool accept_spaces= false)
} }
} }
char const rg = char const rg =
(lf == '{') ? '}' : ((lf == '[') ? ']' : ((lf == '(') ? ')' : 0)); (lf == '{') ? '}' :
((lf == '[') ? ']'
: ((lf == '(') ? ')' : 0));
if (!rg) { if (!rg) {
lyxerr << "Math parse error: unknown bracket '" lyxerr << "Math parse error: unknown bracket '"
<< lf << "'" << endl; << lf << "'" << endl;
@ -205,12 +216,15 @@ char LexGetArg(char lf, bool accept_spaces= false)
char * p = &yytext[0]; char * p = &yytext[0];
int bcnt = 1; int bcnt = 1;
do { do {
char cc;
yyis->get(cc); yyis->get(cc);
c = cc; unsigned char c = cc;
if (c == lf) ++bcnt; if (c == lf) ++bcnt;
if (c == rg) --bcnt; if (c == rg) --bcnt;
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) *(p++) = c; if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0)
*(p++) = c;
} while (bcnt > 0 && yyis->good() && p - yytext.data() < 255); } while (bcnt > 0 && yyis->good() && p - yytext.data() < 255);
*p = '\0'; *p = '\0';
return rg; return rg;
} }
@ -232,50 +246,37 @@ int yylex(void)
if (yy_mtextmode && c == ' ') { if (yy_mtextmode && c == ' ') {
yylval.i= ' '; yylval.i= ' ';
return LM_TK_ALPHA; return LM_TK_ALPHA;
} else } else if (lexcode[c] == LexNewLine) {
if (lexcode[c] == LexNewLine) {
++yylineno; ++yylineno;
continue; continue;
} else } else if (lexcode[c] == LexComment) {
if (lexcode[c] == LexComment) {
do { do {
yyis->get(cc); yyis->get(cc);
c = cc; c = cc;
} while (c != '\n' % yyis->good()); // eat comments } while (c != '\n' % yyis->good()); // eat comments
} else } else if (lexcode[c] == LexDigit
if (lexcode[c] == LexDigit
|| lexcode[c] == LexOther || lexcode[c] == LexOther
|| lexcode[c] == LexMathSpace) { || lexcode[c] == LexMathSpace) {
yylval.i = c; yylval.i = c;
return LM_TK_STR; return LM_TK_STR;
} else } else if (lexcode[c] == LexAlpha) {
if (lexcode[c] == LexAlpha) {
yylval.i= c; yylval.i= c;
return LM_TK_ALPHA; return LM_TK_ALPHA;
} else } else if (lexcode[c] == LexBOP) {
if (lexcode[c] == LexBOP) {
yylval.i= c; yylval.i= c;
return LM_TK_BOP; return LM_TK_BOP;
} else } else if (lexcode[c] == LexSelf) {
if (lexcode[c] == LexSelf) {
return c; return c;
} else } else if (lexcode[c] == LexArgument) {
if (lexcode[c] == LexArgument) {
yyis->get(cc); yyis->get(cc);
c = cc; c = cc;
yylval.i = c - '0'; yylval.i = c - '0';
return LM_TK_ARGUMENT; return LM_TK_ARGUMENT;
} else } else if (lexcode[c] == LexOpen) {
if (lexcode[c] == LexOpen) {
return LM_TK_OPEN; return LM_TK_OPEN;
} else } else if (lexcode[c] == LexClose) {
if (lexcode[c] == LexClose) {
return LM_TK_CLOSE; return LM_TK_CLOSE;
} else } else if (lexcode[c] == LexESC) {
if (lexcode[c] == LexESC) {
yyis->get(cc); yyis->get(cc);
c = cc; c = cc;
if (c == '\\') { if (c == '\\') {
@ -326,11 +327,11 @@ int yylex(void)
// for (i = 0; i < 5 && compare(yytext, latex_mathenv[i], // for (i = 0; i < 5 && compare(yytext, latex_mathenv[i],
// strlen(latex_mathenv[i])); ++i); // strlen(latex_mathenv[i])); ++i);
for (i = 0; i < latex_mathenv_num for (i = 0;
i < latex_mathenv_num
&& compare(yytext.data(), latex_mathenv[i]); ++i); && compare(yytext.data(), latex_mathenv[i]); ++i);
yylval.i = i; yylval.i = i;
} else } else if (l->token == LM_TK_SPACE)
if (l->token == LM_TK_SPACE)
yylval.i = l->id; yylval.i = l->id;
else else
yylval.l = l; yylval.l = l;
@ -346,7 +347,7 @@ int yylex(void)
} }
static static inline
int parse_align(char * hor, char *) int parse_align(char * hor, char *)
{ {
int nc = 0; int nc = 0;
@ -361,7 +362,7 @@ int accent = 0;
static static
int nestaccent[8]; int nestaccent[8];
static static inline
void setAccent(int ac) void setAccent(int ac)
{ {
if (ac > 0 && accent < 8) { if (ac > 0 && accent < 8) {
@ -405,6 +406,8 @@ MathedInset * doAccent(MathedInset * p)
} }
/**
*/
void mathed_parse(MathedArray & array, unsigned flags = 0, void mathed_parse(MathedArray & array, unsigned flags = 0,
MathParInset ** mtx = 0) MathParInset ** mtx = 0)
{ {
@ -420,7 +423,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
int brace = 0; int brace = 0;
int acc_brace = 0; int acc_brace = 0;
int acc_braces[8]; int acc_braces[8];
MathParInset * mt = (mtx) ? *mtx : 0;//(MathParInset*)0; MathParInset * mt = (mtx) ? *mtx : 0;
MathedRowSt * crow = (mt) ? mt->getRowSt() : 0; MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
++plevel; ++plevel;
@ -428,8 +431,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
while (t) { while (t) {
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) { if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
if ((flags & FLAG_BRACK_ARG) && t == '[') { if ((flags & FLAG_BRACK_ARG) && t == '[') {
} } else {
else {
mathPrintError("Expected {. Maybe you forgot to enclose an argument in {}"); mathPrintError("Expected {. Maybe you forgot to enclose an argument in {}");
panic = true; panic = true;
break; break;
@ -437,21 +439,26 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} }
MathedInsetTypes fractype = LM_OT_FRAC; MathedInsetTypes fractype = LM_OT_FRAC;
switch (t) { switch (t) {
case LM_TK_ALPHA: case LM_TK_ALPHA:
{
if (accent) { if (accent) {
data.insertInset(doAccent(yylval.i, varcode), LM_TC_INSET); data.insertInset(doAccent(yylval.i, varcode),
LM_TC_INSET);
} else } else
data.insert(yylval.i, varcode); //LM_TC_VAR); data.insert(yylval.i, varcode); //LM_TC_VAR);
break; break;
}
case LM_TK_ARGUMENT: case LM_TK_ARGUMENT:
{
if (macro) { if (macro) {
data.insertInset(macro->getMacroPar(yylval.i-1), LM_TC_INSET); data.insertInset(macro
->getMacroPar(yylval.i - 1),
LM_TC_INSET);
} else {
lyxerr[Debug::MATHED] << "mathed_parse: macro arg outside macro def." << endl;
} }
break; break;
}
case LM_TK_NEWCOMMAND: case LM_TK_NEWCOMMAND:
{ {
int na = 0; int na = 0;
@ -467,25 +474,24 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} }
macro = new MathMacroTemplate(name, na); macro = new MathMacroTemplate(name, na);
flags = FLAG_BRACE|FLAG_BRACE_LAST; flags = FLAG_BRACE|FLAG_BRACE_LAST;
*mtx = macro; *mtx = macro;
macro->setData(array); macro->setData(array);
break; break;
} }
case LM_TK_SPECIAL: case LM_TK_SPECIAL:
{
data.insert(yylval.i, LM_TC_SPECIAL); data.insert(yylval.i, LM_TC_SPECIAL);
break; break;
}
case LM_TK_STR: case LM_TK_STR:
{
if (accent) { if (accent) {
data.insertInset(doAccent(yylval.i, LM_TC_CONST), LM_TC_INSET); data.insertInset(doAccent(yylval.i, LM_TC_CONST), LM_TC_INSET);
} else } else
data.insert(yylval.i, LM_TC_CONST); data.insert(yylval.i, LM_TC_CONST);
break; break;
}
case LM_TK_OPEN: case LM_TK_OPEN:
{
++brace; ++brace;
if (accent && tprev == LM_TK_ACCENT) { if (accent && tprev == LM_TK_ACCENT) {
acc_braces[acc_brace++] = brace; acc_braces[acc_brace++] = brace;
@ -502,16 +508,15 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insert('{', LM_TC_TEX); data.insert('{', LM_TC_TEX);
} }
break; break;
}
case LM_TK_CLOSE: case LM_TK_CLOSE:
{
--brace; --brace;
if (brace < 0) { if (brace < 0) {
mathPrintError("Unmatching braces"); mathPrintError("Unmatching braces");
panic = true; panic = true;
break; break;
} }
if (acc_brace && brace == acc_braces[acc_brace-1]-1) { if (acc_brace && brace == acc_braces[acc_brace - 1] - 1) {
--acc_brace; --acc_brace;
break; break;
} }
@ -528,10 +533,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insert('}', LM_TC_TEX); data.insert('}', LM_TC_TEX);
} }
break; break;
}
case '[': case '[':
{
if (flags & FLAG_BRACK_ARG) { if (flags & FLAG_BRACK_ARG) {
flags &= ~FLAG_BRACK_ARG; flags &= ~FLAG_BRACK_ARG;
char const rg = LexGetArg('['); char const rg = LexGetArg('[');
@ -540,34 +543,35 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
panic = true; panic = true;
break; break;
} }
// if (arg) strcpy(arg, yytext); // if (arg) strcpy(arg, yytext);
} else } else
data.insert('[', LM_TC_CONST); data.insert('[', LM_TC_CONST);
break; break;
}
case ']': case ']':
{
if (flags & FLAG_BRACK_END) { if (flags & FLAG_BRACK_END) {
--plevel; --plevel;
return; return;
} else } else
data.insert(']', LM_TC_CONST); data.insert(']', LM_TC_CONST);
break; break;
}
case '^': case '^':
{ {
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT); MathParInset * p = new MathParInset(size, "",
LM_OT_SCRIPT);
MathedArray ar; MathedArray ar;
mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST); mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar); p->setData(ar);
// lyxerr << "UP[" << p->GetStyle() << "]" << endl; // lyxerr << "UP[" << p->GetStyle() << "]" << endl;
data.insertInset(p, LM_TC_UP); data.insertInset(p, LM_TC_UP);
break; break;
} }
case '_': case '_':
{ {
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT); MathParInset * p = new MathParInset(size, "",
LM_OT_SCRIPT);
MathedArray ar; MathedArray ar;
mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST); mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar); p->setData(ar);
@ -576,28 +580,26 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} }
case LM_TK_LIMIT: case LM_TK_LIMIT:
{
if (binset) { if (binset) {
binset->SetLimits(bool(yylval.l->id)); binset->SetLimits(bool(yylval.l->id));
binset = 0; binset = 0;
} }
break; break;
}
case '&': // Tab case '&': // Tab
{ if ((flags & FLAG_END) && mt
if ((flags & FLAG_END) && mt && data.getCol()<mt->GetColumns() - 1) { && data.getCol()<mt->GetColumns() - 1) {
data.setNumCols(mt->GetColumns()); data.setNumCols(mt->GetColumns());
data.insert('T', LM_TC_TAB); data.insert('T', LM_TC_TAB);
} else } else
mathPrintError("Unexpected tab"); mathPrintError("Unexpected tab");
// debug info. [made that conditional -JMarc] // debug info. [made that conditional -JMarc]
if (lyxerr.debugging(Debug::MATHED)) if (lyxerr.debugging(Debug::MATHED))
lyxerr << data.getCol() << " " << mt->GetColumns() << endl; lyxerr << data.getCol() << " "
<< mt->GetColumns() << endl;
break; break;
}
case LM_TK_NEWLINE: case LM_TK_NEWLINE:
{
if (mt && (flags & FLAG_END)) { if (mt && (flags & FLAG_END)) {
if (mt->Permit(LMPF_ALLOW_CR)) { if (mt->Permit(LMPF_ALLOW_CR)) {
if (crow) { if (crow) {
@ -609,15 +611,15 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
mathPrintError("Unexpected newline"); mathPrintError("Unexpected newline");
} }
break; break;
}
case LM_TK_BIGSYM: case LM_TK_BIGSYM:
{ {
binset = new MathBigopInset(yylval.l->name, yylval.l->id); binset = new MathBigopInset(yylval.l->name, yylval.l->id);
data.insertInset(binset, LM_TC_INSET); data.insertInset(binset, LM_TC_INSET);
break; break;
} }
case LM_TK_SYM: case LM_TK_SYM:
{
if (yylval.l->id < 256) { if (yylval.l->id < 256) {
MathedTextCodes tc = MathIsBOPS(yylval.l->id) ? LM_TC_BOPS: LM_TC_SYMB; MathedTextCodes tc = MathIsBOPS(yylval.l->id) ? LM_TC_BOPS: LM_TC_SYMB;
if (accent) { if (accent) {
@ -636,38 +638,37 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} }
break; break;
}
case LM_TK_BOP: case LM_TK_BOP:
{
if (accent) { if (accent) {
data.insertInset(doAccent(yylval.i, LM_TC_BOP), LM_TC_INSET); data.insertInset(doAccent(yylval.i, LM_TC_BOP), LM_TC_INSET);
} else } else
data.insert(yylval.i, LM_TC_BOP); data.insert(yylval.i, LM_TC_BOP);
break; break;
}
case LM_TK_STY: case LM_TK_STY:
{
if (mt) { if (mt) {
mt->UserSetSize(yylval.l->id); mt->UserSetSize(yylval.l->id);
} }
break; break;
}
case LM_TK_SPACE: case LM_TK_SPACE:
{
if (yylval.i >= 0) { if (yylval.i >= 0) {
MathSpaceInset * sp = new MathSpaceInset(yylval.i); MathSpaceInset * sp = new MathSpaceInset(yylval.i);
data.insertInset(sp, LM_TC_INSET); data.insertInset(sp, LM_TC_INSET);
} }
break; break;
}
case LM_TK_DOTS: case LM_TK_DOTS:
{ {
MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id); MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id);
data.insertInset(p, LM_TC_INSET); data.insertInset(p, LM_TC_INSET);
break; break;
} }
case LM_TK_STACK: case LM_TK_STACK:
fractype = LM_OT_STACKREL; fractype = LM_OT_STACKREL;
// fallthru
case LM_TK_FRAC: case LM_TK_FRAC:
{ {
MathFracInset * fc = new MathFracInset(fractype); MathFracInset * fc = new MathFracInset(fractype);
@ -679,11 +680,13 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insertInset(fc, LM_TC_ACTIVE_INSET); data.insertInset(fc, LM_TC_ACTIVE_INSET);
break; break;
} }
case LM_TK_SQRT: case LM_TK_SQRT:
{ {
MathParInset * rt; MathParInset * rt;
char c; yyis->get(c); char c;
yyis->get(c);
if (c == '[') { if (c == '[') {
rt = new MathRootInset(size); rt = new MathRootInset(size);
@ -721,8 +724,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
// lyxerr << "RL[" << lfd << " " << rgd << "]"; // lyxerr << "RL[" << lfd << " " << rgd << "]";
break; break;
} }
case LM_TK_RIGHT: case LM_TK_RIGHT:
{
if (flags & FLAG_RIGHT) { if (flags & FLAG_RIGHT) {
--plevel; --plevel;
return; return;
@ -731,15 +734,13 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
// panic = true; // panic = true;
} }
break; break;
}
case LM_TK_FONT: case LM_TK_FONT:
{
varcode = static_cast<MathedTextCodes>(yylval.l->id); varcode = static_cast<MathedTextCodes>(yylval.l->id);
yy_mtextmode = bool(varcode == LM_TC_TEXTRM); yy_mtextmode = bool(varcode == LM_TC_TEXTRM);
flags |= (FLAG_BRACE|FLAG_BRACE_FONT); flags |= (FLAG_BRACE|FLAG_BRACE_FONT);
break; break;
}
case LM_TK_WIDE: case LM_TK_WIDE:
{ {
MathDecorationInset * sq = new MathDecorationInset(yylval.l->id, MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
@ -756,11 +757,9 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
break; break;
case LM_TK_NONUM: case LM_TK_NONUM:
{
if (crow) if (crow)
crow->setNumbered(false); crow->setNumbered(false);
break; break;
}
case LM_TK_PMOD: case LM_TK_PMOD:
case LM_TK_FUNC: case LM_TK_FUNC:
@ -774,12 +773,12 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insertInset(bg, LM_TC_INSET); data.insertInset(bg, LM_TC_INSET);
break; break;
} }
case LM_TK_FUNCLIM: case LM_TK_FUNCLIM:
{
data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM), data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM),
LM_TC_INSET); LM_TC_INSET);
break; break;
}
case LM_TK_UNDEF: case LM_TK_UNDEF:
{ {
@ -795,8 +794,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST); mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST);
p->setData(ar); p->setData(ar);
} }
} } else {
else {
MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF); MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
if (accent) { if (accent) {
data.insertInset(doAccent(q), LM_TC_INSET); data.insertInset(doAccent(q), LM_TC_INSET);
@ -806,8 +804,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} }
break; break;
} }
case LM_TK_END: case LM_TK_END:
{
if (mathed_env != yylval.i && yylval.i != LM_OT_MATRIX) if (mathed_env != yylval.i && yylval.i != LM_OT_MATRIX)
mathPrintError("Unmatched environment"); mathPrintError("Unmatched environment");
// debug info [made that conditional -JMarc] // debug info [made that conditional -JMarc]
@ -819,11 +817,11 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
array.clear(); array.clear();
} }
return; return;
}
case LM_TK_BEGIN: case LM_TK_BEGIN:
{
if (yylval.i == LM_OT_MATRIX) { if (yylval.i == LM_OT_MATRIX) {
char ar[120], ar2[8]; char ar[120];
char ar2[8];
ar[0] = ar2[0] = '\0'; ar[0] = ar2[0] = '\0';
char rg = LexGetArg(0); char rg = LexGetArg(0);
if (rg == ']') { if (rg == ']') {
@ -893,7 +891,6 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
mathPrintError("Unrecognized environment"); mathPrintError("Unrecognized environment");
} }
break; break;
}
case LM_TK_MACRO: case LM_TK_MACRO:
{ {
@ -929,12 +926,14 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
#endif #endif
break; break;
} }
default: default:
mathPrintError("Unrecognized token"); mathPrintError("Unrecognized token");
// debug info // debug info
lyxerr << "[" << t << " " << yytext.data() << "]" << endl; lyxerr << "[" << t << " " << yytext.data() << "]" << endl;
break; break;
} } // end of switch
tprev = t; tprev = t;
if (panic) { if (panic) {
lyxerr << " Math Panic, expect problems!" << endl; lyxerr << " Math Panic, expect problems!" << endl;
@ -968,4 +967,3 @@ int mathed_parser_lineno()
{ {
return yylineno; return yylineno;
} }

View File

@ -19,8 +19,8 @@
#pragma implementation #pragma implementation
#endif #endif
#include "math_iter.h"
#include "math_root.h" #include "math_root.h"
#include "math_iter.h"
#include "support/LOstream.h" #include "support/LOstream.h"
using std::ostream; using std::ostream;

View File

@ -15,13 +15,12 @@
#ifndef MATH_ROOT #ifndef MATH_ROOT
#define MATH_ROOT #define MATH_ROOT
#ifdef __GNUG__
#pragma interface
#endif
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "symbol_def.h" #include "symbol_def.h"
#ifdef __GNUG__
#pragma interface
#endif
/** The general n-th root inset. /** The general n-th root inset.
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "math_iter.h" #include "math_iter.h"
#include "LColor.h" #include "LColor.h"
@ -9,6 +13,7 @@
using std::ostream; using std::ostream;
MathSqrtInset::MathSqrtInset(short st) MathSqrtInset::MathSqrtInset(short st)
: MathParInset(st, "sqrt", LM_OT_SQRT) {} : MathParInset(st, "sqrt", LM_OT_SQRT) {}

View File

@ -1,9 +1,13 @@
// -*- C++ -*-
#ifndef MATH_SQRTINSET_H #ifndef MATH_SQRTINSET_H
#define MATH_SQRTINSET_H #define MATH_SQRTINSET_H
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** The square root inset. /** The square root inset.
\author Alejandro Aguilar Siearra \author Alejandro Aguilar Siearra
*/ */