// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "tex2rtf.xpm"
#endif
-#if !WXWIN_COMPATIBILITY_2_4
static inline wxChar* copystring(const wxChar* s)
{ return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
-#endif
const float versionNo = float(TEX2RTF_VERSION_NUMBER);
bool Go(void);
void ShowOptions(void);
+void ShowVersion(void);
wxChar wxTex2RTFBuffer[1500];
}
}
-#ifdef NO_GUI
- if (InputFile.empty() || OutputFile.empty())
- {
- wxSTD cout << "Tex2RTF: input or output file is missing.\n";
- ShowOptions();
- exit(1);
- }
-#endif
-
- if (!InputFile.empty())
- {
- TexPathList.EnsureFileAccessible(InputFile);
- }
- if (InputFile.empty() || OutputFile.empty())
- isInteractive = true;
+ TexPathList.Add(::wxGetCwd());
int i;
for (i = n; i < argc;)
i ++;
checkSyntax = true;
}
+ else if (wxStrcmp(argv[i], _T("-version")) == 0)
+ {
+ i ++;
+ ShowVersion();
+#ifdef NO_GUI
+ exit(1);
+#else
+ return false;
+#endif
+ }
else
{
wxString buf;
buf.Printf(_T("Invalid switch %s.\n"), argv[i]);
- OnError((wxChar *)buf.c_str());
+ OnError(buf);
#ifdef NO_GUI
ShowOptions();
exit(1);
}
}
+#ifdef NO_GUI
+ if (InputFile.empty() || OutputFile.empty())
+ {
+ wxSTD cout << "Tex2RTF: input or output file is missing.\n";
+ ShowOptions();
+ exit(1);
+ }
+#endif
+
+ if (!InputFile.empty())
+ {
+ TexPathList.EnsureFileAccessible(InputFile);
+ }
+ if (InputFile.empty() || OutputFile.empty())
+ isInteractive = true;
+
#if defined(__WXMSW__) && !defined(NO_GUI)
wxDDEInitialize();
Tex2RTFLastStatus[0] = 0; // DDE connection return value
if (isInteractive)
{
- wxChar buf[100];
-
// Create the main frame window
frame = new MyFrame(NULL, wxID_ANY, _T("Tex2RTF"), wxDefaultPosition, wxSize(400, 300));
#if wxUSE_STATUSBAR
if (!InputFile.empty())
{
- wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile));
- frame->SetTitle(buf);
+ wxString title;
+ title.Printf( _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile).c_str());
+ frame->SetTitle(title);
}
// Make a menubar
wxString path = TexPathList.FindValidPath(MacroFile);
if (!path.empty())
- ReadCustomMacros((wxChar *)path.c_str());
+ ReadCustomMacros(path);
#if wxUSE_STATUSBAR
- wxStrcpy(buf, _T("In "));
+ wxString inStr(_T("In "));
switch (convertMode)
{
- case TEX_RTF:
- wxStrcat(buf, (winHelp) ? _T("WinHelp RTF") : _T("linear RTF"));
- break;
- case TEX_HTML:
- wxStrcat(buf, _T("HTML"));
- break;
- case TEX_XLP:
- wxStrcat(buf, _T("XLP"));
- break;
- default:
- wxStrcat(buf, _T("unknown"));
- break;
+ case TEX_RTF:
+ if(winHelp)
+ inStr += _T("WinHelp RTF");
+ else
+ inStr += _T("linear RTF");
+ break;
+
+ case TEX_HTML:
+ inStr += _T("HTML");
+ break;
+
+ case TEX_XLP:
+ inStr += _T("XLP");
+ break;
+
+ default:
+ inStr += _T("unknown");
+ break;
}
- wxStrcat(buf, _T(" mode."));
- frame->SetStatusText(buf, 1);
+ inStr += _T(" mode.");
+ frame->SetStatusText(inStr, 1);
#endif // wxUSE_STATUSBAR
frame->Show(true);
wxString path = TexPathList.FindValidPath(MacroFile);
if (!path.empty())
- ReadCustomMacros((wxChar*)path.c_str());
+ ReadCustomMacros(path);
- Go();
- if (runTwice)
+ bool rc = Go();
+ if ( rc && runTwice )
{
- Go();
+ rc = Go();
}
#ifdef NO_GUI
- return true;
+ return rc;
#else
OnExit(); // Do cleanup since OnExit won't be called now
return false;
return 0;
}
#endif
-void ShowOptions(void)
+
+void ShowVersion(void)
{
wxChar buf[100];
wxSnprintf(buf, sizeof(buf), _T("Tex2RTF version %.2f"), versionNo);
OnInform(buf);
+}
+
+void ShowOptions(void)
+{
+ ShowVersion();
OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
OnInform(_T("where valid switches are"));
#ifndef NO_GUI
OnInform(_T(" -sync"));
OnInform(_T(" -checkcurlybraces"));
OnInform(_T(" -checksyntax"));
+ OnInform(_T(" -version"));
OnInform(_T(" -macros <filename>"));
OnInform(_T(" -winhelp"));
OnInform(_T(" -rtf"));
#endif // wxUSE_STATUSBAR
wxString errBuf;
errBuf.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount);
- OnInform((wxChar *)errBuf.c_str());
+ OnInform(errBuf);
}
if (!s.empty() && wxFileExists(s))
{
MacroFile = copystring(s);
- ReadCustomMacros((wxChar *)s.c_str());
+ ReadCustomMacros(s);
ShowCustomMacros();
}
#endif // wxUSE_FILEDLG
wxString str = wxFileNameFromPath(InputFile);
wxString buf;
buf.Printf(_T("Tex2RTF [%s]"), str.c_str());
- frame->SetTitle((wxChar *)buf.c_str());
+ frame->SetTitle(buf);
OutputFile = wxEmptyString;
}
}
frame->SetTitle(buf);
}
- wxStartTimer();
+ wxLongLong localTime = wxGetLocalTimeMillis();
#endif
// Find extension-less filename
{
wxString buf;
buf.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber);
- frame->SetStatusText((wxChar *)buf.c_str());
+ frame->SetStatusText(buf);
}
#endif
OkToClose = false;
wxString buf;
#ifndef NO_GUI
- long tim = wxGetElapsedTime();
- buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(tim/1000.0));
- OnInform((wxChar *)buf.c_str());
+ wxLongLong elapsed = wxGetLocalTimeMillis() - localTime;
+ buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(elapsed.GetLo()/1000.0));
+ OnInform(buf);
if (errorCount)
{
buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount);
- OnInform((wxChar *)buf.c_str());
+ OnInform(buf);
}
#if wxUSE_STATUSBAR
if (isInteractive)
{
buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass"));
- frame->SetStatusText((wxChar *)buf.c_str());
+ frame->SetStatusText(buf);
}
#endif // wxUSE_STATUSBAR
#else
buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass"));
- OnInform((wxChar *)buf.c_str());
+ OnInform(buf);
if (errorCount)
{
buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount);
- OnInform((wxChar *)buf.c_str());
+ OnInform(buf.c_str());
}
#endif
passNumber ++;
return false;
}
-void OnError(const wxChar *msg)
+void OnError(const wxString& msg)
{
- wxString msg_string = msg;
errorCount++;
#ifdef NO_GUI
- wxSTD cerr << "Error: " << msg_string.mb_str() << "\n";
+ wxSTD cerr << "Error: " << msg.mb_str() << "\n";
wxSTD cerr.flush();
#else
if (isInteractive && frame)
else
{
#if defined(__UNIX__)
- wxSTD cerr << "Error: " << msg_string.mb_str() << "\n";
+ wxSTD cerr << "Error: " << msg.mb_str() << "\n";
wxSTD cerr.flush();
#elif defined(__WXMSW__)
wxLogError(msg);
#endif // NO_GUI
}
-void OnInform(const wxChar *msg)
+void OnInform(const wxString& msg)
{
- wxString msg_string = msg;
#ifdef NO_GUI
- wxSTD cout << msg_string.mb_str() << "\n";
+ wxSTD cout << msg.mb_str() << "\n";
wxSTD cout.flush();
#else
if (isInteractive && frame)
else
{
#if defined(__UNIX__)
- wxSTD cout << msg_string.mb_str() << "\n";
+ wxSTD cout << msg.mb_str() << "\n";
wxSTD cout.flush();
#elif defined(__WXMSW__)
wxLogInfo(msg);