Added checks for mismatched curly braces so that when docs are generated, a count of the curly braces that have been processed are kept track of. If they mismatch, the file name is reported as having mismatched braces. If more closed braces are detected than open braces, then the line that the first extra close brace is detected on is reported.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker
2000-04-11 15:50:53 +00:00
parent b92f1634b4
commit f018ef133c
2 changed files with 57 additions and 6 deletions

View File

@@ -363,6 +363,10 @@ bool FindEndEnvironment(char *buffer, int *pos, char *env)
bool readingVerbatim = FALSE;
bool readInVerbatim = FALSE; // Within a verbatim, but not nec. verbatiminput
ULONG leftCurly = 0;
ULONG rightCurly = 0;
wxString currentFileName = "";
bool read_a_line(char *buf)
{
if (CurrentInputIndex < 0)
@@ -374,6 +378,7 @@ bool read_a_line(char *buf)
int ch = -2;
int i = 0;
buf[0] = 0;
while (ch != EOF && ch != 10)
{
if (((i == 14) && (strncmp(buf, "\\end{verbatim}", 14) == 0)) ||
@@ -381,6 +386,23 @@ bool read_a_line(char *buf)
readInVerbatim = FALSE;
ch = getc(Inputs[CurrentInputIndex]);
if (ch == '{' && !readInVerbatim)
leftCurly++;
if (ch == '}' && !readInVerbatim)
{
rightCurly++;
if (rightCurly > leftCurly)
{
wxString errBuf;
errBuf.Printf("An extra right Curly brace ('}') was detected at line %lu inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
OnError((char *)errBuf.c_str());
// Reduce the count of right curly braces, so the mismatched count
// isn't reported on every line that has a '}' after the first mismatch
rightCurly--;
}
}
if (ch != EOF)
{
// Check for 2 consecutive newlines and replace with \par
@@ -450,8 +472,18 @@ bool read_a_line(char *buf)
buf[i] = 0;
fclose(Inputs[CurrentInputIndex]);
Inputs[CurrentInputIndex] = NULL;
if (CurrentInputIndex > 0) ch = ' '; // No real end of file
if (CurrentInputIndex > 0)
ch = ' '; // No real end of file
CurrentInputIndex --;
if (leftCurly != rightCurly)
{
wxString errBuf;
errBuf.Printf("Curly braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName.c_str(),leftCurly,rightCurly);
OnError((char *)errBuf.c_str());
}
leftCurly = 0;
rightCurly = 0;
if (readingVerbatim)
{
readingVerbatim = FALSE;
@@ -491,6 +523,7 @@ bool read_a_line(char *buf)
if (buf[j-1] == '}') buf[j-1] = 0; // Ignore final brace
wxString actualFile = TexPathList.FindValidPath(fileName);
currentFileName = actualFile;
if (actualFile == "")
{
char errBuf[300];
@@ -500,6 +533,9 @@ bool read_a_line(char *buf)
}
else
{
wxString informStr;
informStr.Printf("Processing: %s",actualFile.c_str());
OnInform((char *)informStr.c_str());
CurrentInputIndex ++;
Inputs[CurrentInputIndex] = fopen(actualFile, "r");
LineNumbers[CurrentInputIndex] = 1;
@@ -552,6 +588,7 @@ bool read_a_line(char *buf)
// Ignore some types of input files (e.g. macro definition files)
char *fileOnly = FileNameFromPath(fileName);
currentFileName = fileOnly;
if (IgnorableInputFiles.Member(fileOnly))
return read_a_line(buf);
@@ -562,6 +599,8 @@ bool read_a_line(char *buf)
sprintf(buf2, "%s.tex", fileName);
actualFile = TexPathList.FindValidPath(buf2);
}
currentFileName = actualFile;
if (actualFile == "")
{
char errBuf[300];
@@ -575,6 +614,9 @@ bool read_a_line(char *buf)
// then we look in the same directory as this one.
TexPathList.EnsureFileAccessible(actualFile);
wxString informStr;
informStr.Printf("Processing: %s",actualFile.c_str());
OnInform((char *)informStr.c_str());
CurrentInputIndex ++;
Inputs[CurrentInputIndex] = fopen(actualFile, "r");
LineNumbers[CurrentInputIndex] = 1;
@@ -600,6 +642,13 @@ bool read_a_line(char *buf)
strncmp(buf, "\\end{toocomplex}", 16) == 0)
readInVerbatim = FALSE;
if (ch == EOF && leftCurly != rightCurly)
{
wxString errBuf;
errBuf.Printf("Curly braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName.c_str(),leftCurly,rightCurly);
OnError((char *)errBuf.c_str());
}
return (ch == EOF);
}
@@ -2024,7 +2073,7 @@ void DefineDefaultMacros(void)
AddMacroDef(ltNABLA, "nabla", 0);
AddMacroDef(ltNEG, "neg", 0);
AddMacroDef(ltNEQ, "neq", 0);
AddMacroDef(ltNEWCOUNTER, "newcounter", 1, FALSE, FORBID_ABSOLUTELY);
AddMacroDef(ltNEWCOUNTER, "newcounter", 1, FALSE, (bool)FORBID_ABSOLUTELY);
AddMacroDef(ltNEWLINE, "newline", 0);
AddMacroDef(ltNEWPAGE, "newpage", 0);
AddMacroDef(ltNI, "ni", 0);
@@ -2077,8 +2126,8 @@ void DefineDefaultMacros(void)
AddMacroDef(ltPRECEQ, "preceq", 0);
AddMacroDef(ltPRINTINDEX, "printindex", 0);
AddMacroDef(ltPROPTO, "propto", 0);
AddMacroDef(ltPSBOXTO, "psboxto", 1, FALSE, FORBID_ABSOLUTELY);
AddMacroDef(ltPSBOX, "psbox", 1, FALSE, FORBID_ABSOLUTELY);
AddMacroDef(ltPSBOXTO, "psboxto", 1, FALSE, (bool)FORBID_ABSOLUTELY);
AddMacroDef(ltPSBOX, "psbox", 1, FALSE, (bool)FORBID_ABSOLUTELY);
AddMacroDef(ltPSI, "psi", 0);
AddMacroDef(ltCAP_PSI, "Psi", 0);

View File

@@ -170,7 +170,8 @@ bool MyApp::OnInit()
if (!InputFile || !OutputFile)
isInteractive = TRUE;
for (int i = n; i < argc;)
int i;
for (i = n; i < argc;)
{
if (strcmp(argv[i], "-winhelp") == 0)
{
@@ -497,6 +498,7 @@ void MyFrame::OnExit(wxCommandEvent& event)
void MyFrame::OnGo(wxCommandEvent& event)
{
passNumber = 1;
menuBar->EnableTop(0, FALSE);
menuBar->EnableTop(1, FALSE);
menuBar->EnableTop(2, FALSE);
@@ -826,7 +828,7 @@ bool Go(void)
char buf[100];
#ifndef NO_GUI
long tim = wxGetElapsedTime();
sprintf(buf, "Finished in %ld seconds.", (long)(tim/1000.0));
sprintf(buf, "Finished PASS #%d in %ld seconds.\n", passNumber, (long)(tim/1000.0));
OnInform(buf);
if (isInteractive)
{