Add forgotten functions and apply literate programming fix from Edmar.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/lyx-1_1_5@1080 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-10-04 10:53:36 +00:00
parent be967977f2
commit 62a50191cc
6 changed files with 416 additions and 1254 deletions

View File

@ -1,3 +1,12 @@
2000-10-04 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/support/lstrings.[Ch]: add isStrDbl and StrToDbl that I
forgot earlier :(
2000-10-04 Edmar Wienskoski Jr <edmar-w-jr@technologist.com>
* src/Literate.[Ch]: fix parsing of LaTeX errors.
2000-09-29 Dekel Tsur <dekelts@tau.ac.il> 2000-09-29 Dekel Tsur <dekelts@tau.ac.il>
* src/paragraph.C (TeXFootnote): Fixed bug with LTR table floats. * src/paragraph.C (TeXFootnote): Fixed bug with LTR table floats.

File diff suppressed because it is too large Load Diff

View File

@ -66,13 +66,13 @@ int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
ret1 = one.startscript(Systemcalls::System, tmp1); ret1 = one.startscript(Systemcalls::System, tmp1);
ret2 = two.startscript(Systemcalls::System, tmp2); ret2 = two.startscript(Systemcalls::System, tmp2);
lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl; lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
scanres = scanLiterateLogFile(); scanres = scanLiterateLogFile(terr);
if (scanres & Literate::ERRORS) return scanres; // return on literate error if (scanres & Literate::ERRORS) return scanres; // return on literate error
return run(terr, minib); return run(terr, minib);
} }
int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib) int Literate::build(TeXErrors & terr, MiniBuffer * minib)
// We know that this function will only be run if the lyx buffer // We know that this function will only be run if the lyx buffer
// has been changed. // has been changed.
{ {
@ -95,66 +95,156 @@ int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib)
tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log"; tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
ret1 = one.startscript(Systemcalls::System, tmp1); ret1 = one.startscript(Systemcalls::System, tmp1);
ret2 = two.startscript(Systemcalls::System, tmp2); ret2 = two.startscript(Systemcalls::System, tmp2);
scanres = scanBuildLogFile(); scanres = scanBuildLogFile(terr);
lyxerr[Debug::LATEX] << "Done." << endl; lyxerr[Debug::LATEX] << "Done." << endl;
return scanres; return scanres;
} }
int Literate::scanLiterateLogFile() int Literate::scanLiterateLogFile(TeXErrors & terr)
{ {
string token;
int retval = NO_ERRORS;
string tmp = litfile + ".log"; string tmp = litfile + ".log";
ifstream ifs(tmp.c_str()); int last_line = -1;
while (getline(ifs, token)) { int line_count = 1;
lyxerr[Debug::LATEX] << token << endl; int retval = NO_ERRORS;
lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
ifstream ifs(tmp.c_str());
if (prefixIs(token, "Build Warning:")) { string token;
// Here shall we handle different while (getline(ifs, token)) {
// types of warnings lyxerr[Debug::LATEX] << "Log line: " << token << endl;
retval |= LATEX_WARNING;
lyxerr[Debug::LATEX] << "Build Warning." << endl; if (token.empty())
} else if (prefixIs(token, "! Build Error:")) { continue;
// Here shall we handle different
// types of errors if (prefixIs(token, "! ")) {
retval |= LATEX_ERROR; // Ok, we have something that looks like a TeX Error
lyxerr[Debug::LATEX] << "Build Error." << endl; // but what do we really have.
// this is not correct yet
++num_errors; // Just get the error description:
} string desc(token, 2);
} if (contains(token, "Build Error:"))
return retval; retval |= LATEX_ERROR;
// get the next line
string tmp;
int count = 0;
do {
if (!getline(ifs, tmp))
break;
if (++count > 10)
break;
} while (!prefixIs(tmp, "l."));
if (prefixIs(tmp, "l.")) {
// we have a build error
retval |= TEX_ERROR;
// get the line number:
int line = 0;
sscanf(tmp.c_str(), "l.%d", &line);
// get the rest of the message:
string errstr(tmp, tmp.find(' '));
errstr += '\n';
getline(ifs, tmp);
while (!contains(errstr, "l.")
&& !tmp.empty()
&& !prefixIs(tmp, "! ")
&& !contains(tmp, " ...")) {
errstr += tmp;
errstr += "\n";
getline(ifs, tmp);
}
lyxerr[Debug::LATEX]
<< "line: " << line << '\n'
<< "Desc: " << desc << '\n'
<< "Text: " << errstr << endl;
if (line == last_line)
++line_count;
else {
line_count = 1;
last_line = line;
}
if (line_count <= 5) {
terr.insertError(line, desc, errstr);
++num_errors;
}
}
}
}
lyxerr[Debug::LATEX] << "Log line: " << token << endl;
return retval;
} }
int Literate::scanBuildLogFile() int Literate::scanBuildLogFile(TeXErrors & terr)
{ {
string token;
int retval = NO_ERRORS;
string tmp = litfile + ".log"; string tmp = litfile + ".log";
ifstream ifs(tmp.c_str()); int last_line = -1;
while (getline(ifs, token)) { int line_count = 1;
lyxerr[Debug::LATEX] << token << endl; int retval = NO_ERRORS;
lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
ifstream ifs(tmp.c_str());
if (prefixIs(token, "Build Warning:")) { string token;
// Here shall we handle different while (getline(ifs, token)) {
// types of warnings lyxerr[Debug::LATEX] << "Log line: " << token << endl;
retval |= LATEX_WARNING;
lyxerr[Debug::LATEX] << "Build Warning." << endl; if (token.empty())
} else if (prefixIs(token, "! Build Error:")) { continue;
// Here shall we handle different
// types of errors if (prefixIs(token, "! ")) {
retval |= LATEX_ERROR; // Ok, we have something that looks like a TeX Error
lyxerr[Debug::LATEX] << "Build Error." << endl; // but what do we really have.
// this is not correct yet
++num_errors; // Just get the error description:
} string desc(token, 2);
} if (contains(token, "Build Error:"))
return retval; retval |= LATEX_ERROR;
// get the next line
string tmp;
int count = 0;
do {
if (!getline(ifs, tmp))
break;
if (++count > 10)
break;
} while (!prefixIs(tmp, "l."));
if (prefixIs(tmp, "l.")) {
// we have a build error
retval |= TEX_ERROR;
// get the line number:
int line = 0;
sscanf(tmp.c_str(), "l.%d", &line);
// get the rest of the message:
string errstr(tmp, tmp.find(' '));
errstr += '\n';
getline(ifs, tmp);
while (!contains(errstr, "l.")
&& !tmp.empty()
&& !prefixIs(tmp, "! ")
&& !contains(tmp, " ...")) {
errstr += tmp;
errstr += "\n";
getline(ifs, tmp);
}
lyxerr[Debug::LATEX]
<< "line: " << line << '\n'
<< "Desc: " << desc << '\n'
<< "Text: " << errstr << endl;
if (line == last_line)
++line_count;
else {
line_count = 1;
last_line = line;
}
if (line_count <= 5) {
terr.insertError(line, desc, errstr);
++num_errors;
}
}
}
}
lyxerr[Debug::LATEX] << "Log line: " << token << endl;
return retval;
} }

View File

@ -34,10 +34,10 @@ public:
int build(TeXErrors &, MiniBuffer *); int build(TeXErrors &, MiniBuffer *);
private: private:
/// ///
int scanLiterateLogFile(); int scanLiterateLogFile(TeXErrors & terr);
/// ///
int scanBuildLogFile(); int scanBuildLogFile(TeXErrors & terr);
/// ///
string litfile; string litfile;

View File

@ -95,6 +95,49 @@ int strToInt(string const & str)
} }
bool isStrDbl(string const & str)
{
if (str.empty()) return false;
// Remove leading and trailing white space chars.
string const tmpstr = frontStrip(strip(str, ' '), ' ');
if (tmpstr.empty()) return false;
// if (1 < tmpstr.count('.')) return false;
string::const_iterator cit = tmpstr.begin();
bool found_dot(false);
if ( (*cit) == '-') ++cit;
string::const_iterator end = tmpstr.end();
for (; cit != end; ++cit) {
if (!isdigit((*cit))
&& '.' != (*cit)) {
return false;
}
if ('.' == (*cit)) {
if (found_dot) {
return false;
} else {
found_dot = true;
}
}
}
return true;
}
double strToDbl(string const & str)
{
if (isStrDbl(str)) {
// Remove leading and trailing white space chars.
string const tmpstr = frontStrip(strip(str, ' '), ' ');
// Do the conversion proper.
return ::atof(tmpstr.c_str());
} else {
return 0.0;
}
}
string lowercase(string const & a) string lowercase(string const & a)
{ {
string tmp(a); string tmp(a);

View File

@ -48,6 +48,12 @@ bool isStrInt(string const & str);
/// ///
int strToInt(string const & str); int strToInt(string const & str);
///
bool isStrDbl(string const & str);
///
double strToDbl(string const & str);
/// ///
string lowercase(string const &); string lowercase(string const &);