*
* Dependencies: Xlib, XForms
*
- * Copyright: (c) 1996, Alejandro Aguilar Sierra
+ * Copyright: 1996, Alejandro Aguilar Sierra
*
* Version: 0.8beta.
*
#include "math_root.h"
#include "debug.h"
+using std::istream;
+using std::endl;
+
enum {
FLAG_BRACE = 1, // A { needed
FLAG_BRACE_ARG = 2, // Next { is argument
}
-static void mathPrintError(char const * msg)
+static
+void mathPrintError(char const * msg)
{
lyxerr << "Line ~" << yylineno << ": Math parse error: "
<< msg << endl;
}
-static void LexInitCodes()
+static
+void LexInitCodes()
{
for (int i = 0; i <= 255; ++i) {
if (isalpha(i)) lexcode[i] = LexAlpha;
}
-static char LexGetArg(char lf, bool accept_spaces= false)
+static
+char LexGetArg(char lf, bool accept_spaces= false)
{
- char rg, * p = &yytext[0];
+ char rg;
+ char * p = &yytext[0];
int bcnt = 1;
unsigned char c;
+ char cc;
while (yyis->good()) {
- yyis->get(c);
+ yyis->get(cc);
+ c = cc;
if (c > ' ') {
if (!lf) lf = c; else
if (c != lf)
return '\0';
}
do {
- yyis->get(c);
+ yyis->get(cc);
+ c = cc;
if (c == lf) ++bcnt;
if (c == rg) --bcnt;
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt>0) *(p++) = c;
}
-static int yylex(void)
+static
+int yylex(void)
{
static int init_done = 0;
unsigned char c;
+ char cc;
if (!init_done) LexInitCodes();
- while (yyis->good()) {
- yyis->get(c);
+ while (yyis->good()) {
+ yyis->get(cc);
+ c = cc;
if (yy_mtextmode && c == ' ') {
yylval.i= ' ';
continue;
}
- if (lexcode[c] == LexComment)
- do yyis->get(c); while (c != '\n' % yyis->good()); // eat comments
+ if (lexcode[c] == LexComment)
+ do { yyis->get(cc); c = cc; } while (c != '\n' % yyis->good()); // eat comments
- if (lexcode[c] == LexDigit || lexcode[c] == LexOther || lexcode[c] == LexMathSpace)
- { yylval.i= c; return LM_TK_STR; }
+ if (lexcode[c] == LexDigit || lexcode[c] == LexOther || lexcode[c] == LexMathSpace) { yylval.i = c; return LM_TK_STR; }
if (lexcode[c] == LexAlpha) { yylval.i= c; return LM_TK_ALPHA; }
if (lexcode[c] == LexBOP) { yylval.i= c; return LM_TK_BOP; }
if (lexcode[c] == LexSelf) { return c; }
- if (lexcode[c] == LexArgument) {
- yyis->get(c);
+ if (lexcode[c] == LexArgument) {
+ yyis->get(cc);
+ c = cc;
yylval.i = c - '0';
return LM_TK_ARGUMENT;
}
if (lexcode[c] == LexClose) { return LM_TK_CLOSE; }
if (lexcode[c] == LexESC) {
- yyis->get(c);
+ yyis->get(cc);
+ c = cc;
if (c == '\\') { return LM_TK_NEWLINE; }
if (c == '(') { yylval.i = LM_EN_INTEXT; return LM_TK_BEGIN; }
if (c == ')') { yylval.i = LM_EN_INTEXT; return LM_TK_END; }
}
if (lexcode[c] == LexMathSpace) {
int i;
- for (i = 0; i < 4 && c != latex_mathspace[i][0]; ++i);
+ for (i = 0; i < 4 && static_cast<int>(c) != latex_mathspace[i][0]; ++i);
yylval.i = (i < 4) ? i: 0;
return LM_TK_SPACE;
}
char * p = &yytext[0];
while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
*p = c;
- yyis->get(c);
- p++;
+ yyis->get(cc);
+ c = cc;
+ ++p;
}
*p = '\0';
if (yyis->good()) yyis->putback(c);
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
int i;
LexGetArg('{');
-// for (i= 0; i<5 && strncmp(yytext, latex_mathenv[i],
-// strlen(latex_mathenv[i])); i++);
+// for (i = 0; i < 5 && strncmp(yytext, latex_mathenv[i],
+// strlen(latex_mathenv[i])); ++i);
- for (i = 0; i < 6 && strcmp(yytext, latex_mathenv[i]); i++);
+ for (i = 0; i < 6 && strcmp(yytext, latex_mathenv[i]); ++i);
yylval.i = i;
} else
if (l->token == LM_TK_SPACE)
int brace = 0;
int acc_brace = 0;
int acc_braces[8];
- MathParInset * mt = (mtx) ? *mtx: 0;//(MathParInset*)0;
+ MathParInset * mt = (mtx) ? *mtx : 0;//(MathParInset*)0;
MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
++plevel;
}
case LM_TK_OPEN:
{
- brace++;
+ ++brace;
if (accent && tprev == LM_TK_ACCENT) {
acc_braces[acc_brace++] = brace;
break;
}
case LM_TK_CLOSE:
{
- brace--;
+ --brace;
if (brace < 0) {
mathPrintError("Unmatching braces");
panic = true;
break;
}
if (acc_brace && brace == acc_braces[acc_brace-1]-1) {
- acc_brace--;
+ --acc_brace;
break;
}
if (flags & FLAG_BRACE_FONT) {
break;
}
if (brace == 0 && (flags & FLAG_BRACE_LAST)) {
- plevel--;
+ --plevel;
return array;
} else {
data.Insert ('}', LM_TC_TEX);
case ']':
{
if (flags & FLAG_BRACK_END) {
- plevel--;
+ --plevel;
return array;
} else
data.Insert (']');
case LM_TK_RIGHT:
{
if (flags & FLAG_RIGHT) {
- plevel--;
+ --plevel;
return array;
} else {
mathPrintError("Unmatched right delimiter");
data.Insert(doAccent(p), p->getTCode());
else
data.Insert(p, p->getTCode());
- for (int i = 0; p->setArgumentIdx(i); i++)
+ for (int i = 0; p->setArgumentIdx(i); ++i)
p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
}
else {
// debug info [made that conditional -JMarc]
if (lyxerr.debugging(Debug::MATHED))
lyxerr << "[" << yylval.i << "]" << endl;
- plevel--;
+ --plevel;
if (mt) { // && (flags & FLAG_END)) {
mt->SetData(array);
array = 0;
data.Insert(p, p->getTCode());
p->setArgumentIdx(0);
mathed_parse(FLAG_END, p->GetData(), reinterpret_cast<MathParInset**>(&p));
-// for (int i= 0; p->setArgumentIdx(i); i++)
+// for (int i = 0; p->setArgumentIdx(i); ++i)
// p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
} else
mathPrintError("Unrecognized environment");
break;
}
}
- plevel--;
+ --plevel;
return array;
}