#include <stdlib.h>
#include <time.h>
-#if !WXWIN_COMPATIBILITY_2_4
static inline wxChar* copystring(const wxChar* s)
{ return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
-#endif
/*
* Variables accessible from clients
delete [] macroBody;
}
-void TexOutput(const wxChar *s, bool ordinaryText)
+void TexOutput(const wxString& s, bool ordinaryText)
{
- int len = wxStrlen(s);
-
// Update current column, but only if we're guaranteed to
// be ordinary text (not mark-up stuff)
int i;
if (ordinaryText)
- for (i = 0; i < len; i++)
+ for (wxString::const_iterator i = s.begin(); i != s.end(); ++i)
{
- if (s[i] == 13 || s[i] == 10)
+ if (*i == 13 || *i == 10)
currentColumn = 0;
else
currentColumn ++;
case FORBID_WARN:
{
informBuf.Printf(_T("Warning: it is recommended that command %s is not used."), def->name);
- OnInform((const wxChar *)informBuf.c_str());
+ OnInform(informBuf);
break;
}
case FORBID_ABSOLUTELY:
{
informBuf.Printf(_T("Error: command %s cannot be used and will lead to errors."), def->name);
- OnInform((const wxChar *)informBuf.c_str());
+ OnInform(informBuf);
break;
}
default:
TexMacroDef *MatchMacro(wxChar *buffer, int *pos, wxChar **env, bool *parseToBrace)
{
- *parseToBrace = true;
- int i = (*pos);
- TexMacroDef *def = NULL;
- wxChar macroBuf[40];
+ *parseToBrace = true;
+ int i = (*pos);
+ TexMacroDef *def = NULL;
+ wxChar macroBuf[40];
- // First, try to find begin{thing}
- if (wxStrncmp(buffer+i, _T("begin{"), 6) == 0)
- {
- i += 6;
-
- int j = i;
- while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39))
+ // First, try to find begin{thing}
+ if (wxStrncmp(buffer+i, _T("begin{"), 6) == 0)
{
- macroBuf[j-i] = buffer[j];
- j ++;
- }
- macroBuf[j-i] = 0;
- def = (TexMacroDef *)MacroDefs.Get(macroBuf);
+ i += 6;
- if (def)
- {
- *pos = j + 1; // BUGBUG Should this be + 1???
- *env = def->name;
- ForbidWarning(def);
- return def;
+ int j = i;
+ while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39))
+ {
+ macroBuf[j-i] = buffer[j];
+ j ++;
+ }
+ macroBuf[j-i] = 0;
+ def = (TexMacroDef *)MacroDefs.Get(macroBuf);
+
+ if (def)
+ {
+ *pos = j + 1; // BUGBUG Should this be + 1???
+ *env = def->name;
+ ForbidWarning(def);
+ return def;
+ }
+ else
+ {
+ return NULL;
+ }
}
- else return NULL;
- }
- // Failed, so try to find macro from definition list
- int j = i;
+ // Failed, so try to find macro from definition list
+ int j = i;
- // First try getting a one-character macro, but ONLY
- // if these TWO characters are not both alphabetical (could
- // be a longer macro)
- if (!(isalpha(buffer[i]) && isalpha(buffer[i+1])))
- {
- macroBuf[0] = buffer[i];
- macroBuf[1] = 0;
+ // First try getting a one-character macro, but ONLY
+ // if these TWO characters are not both alphabetical (could
+ // be a longer macro)
+ if (!(isalpha(buffer[i]) && isalpha(buffer[i+1])))
+ {
+ macroBuf[0] = buffer[i];
+ macroBuf[1] = 0;
- def = (TexMacroDef *)MacroDefs.Get(macroBuf);
- if (def) j ++;
- }
+ def = (TexMacroDef *)MacroDefs.Get(macroBuf);
+ if (def) j ++;
+ }
- if (!def)
- {
- while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39))
+ if (!def)
{
- macroBuf[j-i] = buffer[j];
- j ++;
+ while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39))
+ {
+ macroBuf[j-i] = buffer[j];
+ j ++;
+ }
+ macroBuf[j-i] = 0;
+ def = (TexMacroDef *)MacroDefs.Get(macroBuf);
}
- macroBuf[j-i] = 0;
- def = (TexMacroDef *)MacroDefs.Get(macroBuf);
- }
- if (def)
- {
- i = j;
-
- // We want to check whether this is a space-consuming macro
- // (e.g. {\bf word})
- // No brace, e.g. \input thing.tex instead of \input{thing};
- // or a numeric argument, such as \parindent0pt
- if ((def->no_args > 0) && ((buffer[i] == 32) || (buffer[i] == '=') || (isdigit(buffer[i]))))
+ if (def)
{
- if ((buffer[i] == 32) || (buffer[i] == '='))
- i ++;
+ i = j;
- *parseToBrace = false;
+ // We want to check whether this is a space-consuming macro
+ // (e.g. {\bf word})
+ // No brace, e.g. \input thing.tex instead of \input{thing};
+ // or a numeric argument, such as \parindent0pt
+ if ((def->no_args > 0) && ((buffer[i] == 32) || (buffer[i] == '=') || (isdigit(buffer[i]))))
+ {
+ if ((buffer[i] == 32) || (buffer[i] == '='))
+ i ++;
+
+ *parseToBrace = false;
+ }
+ *pos = i;
+ ForbidWarning(def);
+ return def;
}
- *pos = i;
- ForbidWarning(def);
- return def;
- }
- return NULL;
+ return NULL;
}
void EatWhiteSpace(wxChar *buffer, int *pos)
wxString errBuf;
errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(), MAX_LINE_BUFFER_SIZE);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
return false;
}
{
wxString errBuf;
errBuf.Printf(_T("An extra right Curly brace ('}') was detected at line %lu inside file %s"), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
// Reduce the count of right Curly braces, so the mismatched count
// isn't reported on every line that has a '}' after the first mismatch
wxString errBuf;
errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
return false;
}
wxStrcat(buf, _T("\\par"));
wxString errBuf;
errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
return false;
}
wxString errBuf;
errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
return false;
}
buf[bufIndex++]='\\';
wxString errBuf;
errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
return false;
}
buf[bufIndex++]='\\';
wxString errBuf;
errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
return false;
}
// If the current character read in is a '_', we need to check
// wxString errBuf;
// errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it."),
// LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
-// OnError((wxChar *)errBuf.c_str());
+// OnError(errBuf);
}
}
else
wxString errBuf;
errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
else if ((buf[bufIndex-1] != '\\') && (buf[0] != '%') && // If it is a comment line, then no warnings
(wxStrncmp(buf, _T("\\input"), 6))) // do not report filenames that have underscores in them
wxString errBuf;
errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
}
}
wxString errBuf;
errBuf.Printf(_T("Curly braces do not match inside file %s\n%lu opens, %lu closes"),
(const wxChar*) currentFileName.c_str(),leftCurly,rightCurly);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
leftCurly = 0;
rightCurly = 0;
{
wxString errBuf;
errBuf.Printf(_T("Could not find file: %s"),fileName);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
else
{
wxString informStr;
informStr.Printf(_T("Processing: %s"),actualFile.c_str());
- OnInform((wxChar *)informStr.c_str());
+ OnInform(informStr);
CurrentInputIndex ++;
Inputs[CurrentInputIndex] = wxFopen(actualFile, _T("r"));
fileNameStr.Replace(_T("\\"), _T(""));
// Ignore some types of input files (e.g. macro definition files)
- wxChar *fileOnly = wxFileNameFromPath((wxChar*) (const wxChar*) fileNameStr);
+ wxString fileOnly = wxFileNameFromPath(fileNameStr);
currentFileName = fileOnly;
if (IgnorableInputFiles.Member(fileOnly))
return read_a_line(buf);
{
wxString errBuf;
errBuf.Printf(_T("Could not find file: %s"),fileName);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
else
{
wxString informStr;
informStr.Printf(_T("Processing: %s"),actualFile.c_str());
- OnInform((wxChar *)informStr.c_str());
+ OnInform(informStr);
CurrentInputIndex ++;
Inputs[CurrentInputIndex] = wxFopen(actualFile, _T("r"));
wxString errBuf;
errBuf.Printf(_T("Could not open include file %s"), (const wxChar*) actualFile);
CurrentInputIndex --;
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
}
bool succ = read_a_line(buf);
LineNumbers[CurrentInputIndex],
currentFileName.c_str());
}
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
}
}
wxString errBuf;
errBuf.Printf(_T("Curly braces do not match inside file %s\n%lu opens, %lu closes"),
(const wxChar*) currentFileName.c_str(),leftCurly,rightCurly);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
}
errBuf.Printf(_T("Could not find macro: %s at line %d, file %s"),
macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
if (wxStrcmp(macroBuf,_T("\\end{document}")) == 0)
{
children.Append((wxObject *)chunk);
// Eliminate newline after a \begin{} or a \\ if possible
- if (env || wxStrcmp(def->name, _T("\\")) == 0)
- if (buffer[pos] == 13)
- {
+ if ((env || wxStrcmp(def->name, _T("\\")) == 0) && (buffer[pos] == 13))
+ {
pos ++;
if (buffer[pos] == 10)
pos ++;
- }
+ }
- pos = ParseMacroBody(def->name, chunk, chunk->no_args,
- buffer, pos, env, tmpParseToBrace, customMacroArgs);
+ pos = ParseMacroBody(def->name,
+ chunk, chunk->no_args,
+ buffer,
+ pos,
+ env,
+ tmpParseToBrace,
+ customMacroArgs);
// If custom macro, parse the body substituting the above found args.
if (customMacro)
tmpBuffer = tmpBuffer.Mid(0,tmpBuffer.length()-4);
}
errBuf.Printf(_T("Missing macro argument in the line:\n\t%s\n"),tmpBuffer.c_str());
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
}
case ltCINSERT:
if (start)
- TexOutput(_T("<<"), true);
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<<"));
+ else
+ TexOutput(_T("<<"), true);
+ }
break;
case ltCEXTRACT:
if (start)
- TexOutput(_T(">>"), true);
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T(">>"));
+ else
+ TexOutput(_T(">>"), true);
+ }
break;
case ltDESTRUCT:
if (start)
// Binary operation symbols
case ltLE:
case ltLEQ:
- if (start) TexOutput(_T("<="));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<="));
+ else
+ TexOutput(_T("<="));
+ }
break;
case ltLL:
- if (start) TexOutput(_T("<<"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<<"));
+ else
+ TexOutput(_T("<<"));
+ }
break;
case ltSUBSET:
if (start) TexOutput(_T("SUBSET"));
break;
case ltGE:
case ltGEQ:
- if (start) TexOutput(_T(">="));
+ {
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T(">="));
+ else
+ TexOutput(_T(">="));
+ }
break;
+ }
case ltGG:
- if (start) TexOutput(_T(">>"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T(">>"));
+ else
+ TexOutput(_T(">>"));
+ }
break;
case ltSUPSET:
if (start) TexOutput(_T("SUPSET"));
// Arrows
case ltLEFTARROW:
- if (start) TexOutput(_T("<--"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<--"));
+ else
+ TexOutput(_T("<--"));
+ }
break;
case ltLEFTARROW2:
- if (start) TexOutput(_T("<=="));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<=="));
+ else
+ TexOutput(_T("<=="));
+ }
break;
case ltRIGHTARROW:
- if (start) TexOutput(_T("-->"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("-->"));
+ else
+ TexOutput(_T("-->"));
+ }
break;
case ltRIGHTARROW2:
- if (start) TexOutput(_T("==>"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("==>"));
+ else
+ TexOutput(_T("==>"));
+ }
break;
case ltLEFTRIGHTARROW:
- if (start) TexOutput(_T("<-->"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<-->"));
+ else
+ TexOutput(_T("<-->"));
+ }
break;
case ltLEFTRIGHTARROW2:
- if (start) TexOutput(_T("<==>"));
+ if (start)
+ {
+ if (convertMode == TEX_HTML)
+ TexOutput(_T("<==>"));
+ else
+ TexOutput(_T("<==>"));
+ }
break;
case ltUPARROW:
if (start) TexOutput(_T("UPARROW"));
{
wxString informBuf;
informBuf.Printf(_T("Warning: unresolved reference '%s'"), refName);
- OnInform((wxChar *)informBuf.c_str());
+ OnInform(informBuf);
}
}
else TexOutput(_T("??"), true);
{
wxString informBuf;
informBuf.Printf(_T("Warning: unresolved citation %s."), citeKey);
- OnInform((wxChar *)informBuf.c_str());
+ OnInform(informBuf);
}
}
citeKey = ParseMultifieldString(citeKeys, &pos);
{
wxString errBuf;
errBuf.Printf(_T(".bib file %s not found or malformed"), (const wxChar*) actualFile);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
}
else
{
wxString errBuf;
errBuf.Printf(_T(".bib file %s not found"), fileBuf);
- OnError((wxChar *)errBuf.c_str());
+ OnError(errBuf);
}
bibFile = ParseMultifieldString(allFiles, &pos);
}