1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to linear/WinHelp RTF, HTML, wxHelp.
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/textctrl.h"
27 #include "wx/filedlg.h"
28 #include "wx/msgdlg.h"
37 #if defined(NO_GUI) || defined(__UNIX__)
54 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
55 #include "tex2rtf.xpm"
58 #if !WXWIN_COMPATIBILITY_2_4
59 static inline wxChar
* copystring(const wxChar
* s
)
60 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
63 const float versionNo
= TEX2RTF_VERSION_NUMBER
;
65 TexChunk
*currentMember
= NULL
;
66 bool startedSections
= FALSE
;
67 wxChar
*contentsString
= NULL
;
68 bool suppressNameDecoration
= FALSE
;
69 bool OkToClose
= TRUE
;
71 unsigned long errorCount
= 0;
75 extern wxChar
*BigBuffer
;
76 extern wxChar
*TexFileRoot
;
77 extern wxChar
*TexBibName
; // Bibliography output file name
78 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
79 extern wxList ColourTable
;
80 extern TexChunk
*TopLevel
;
85 wxHelpController
*HelpInstance
= NULL
;
89 static wxChar
*ipc_buffer
= NULL
;
90 static wxChar Tex2RTFLastStatus
[100];
91 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
95 wxChar
*bulletFile
= NULL
;
97 FILE *Contents
= NULL
; // Contents page
98 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
99 FILE *Sections
= NULL
;
100 FILE *Subsections
= NULL
;
101 FILE *Subsubsections
= NULL
;
103 FILE *WinHelpContentsFile
= NULL
;
105 wxChar
*InputFile
= NULL
;
106 wxChar
*OutputFile
= NULL
;
107 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
109 wxChar
*FileRoot
= NULL
;
110 wxChar
*ContentsName
= NULL
; // Contents page from last time around
111 wxChar
*TmpContentsName
= NULL
; // Current contents page
112 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
113 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
114 wxChar
*RefFileName
= NULL
; // Reference file name
116 wxChar
*RTFCharset
= copystring(_T("ansi"));
119 int BufSize
= 100; // Size of buffer in K
125 void ShowOptions(void);
127 wxChar wxTex2RTFBuffer
[1500];
131 int main(int argc
, char **argv
)
133 wxMenuBar
*menuBar
= NULL
;
134 MyFrame
*frame
= NULL
;
136 // DECLARE_APP(MyApp)
139 // `Main program' equivalent, creating windows and returning main app frame
143 // Use default list of macros defined in tex2any.cc
144 DefineDefaultMacros();
145 AddMacroDef(ltHARDY
, _T("hardy"), 0);
147 FileRoot
= new wxChar
[300];
148 ContentsName
= new wxChar
[300];
149 TmpContentsName
= new wxChar
[300];
150 TmpFrameContentsName
= new wxChar
[300];
151 WinHelpContentsFileName
= new wxChar
[300];
152 RefFileName
= new wxChar
[300];
154 ColourTable
.DeleteContents(TRUE
);
158 // Read input/output files
161 if (argv
[1][0] != '-')
168 if (argv
[2][0] != '-')
170 OutputFile
= argv
[2];
178 if (!InputFile
|| !OutputFile
)
180 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
188 TexPathList
.EnsureFileAccessible(InputFile
);
190 if (!InputFile
|| !OutputFile
)
191 isInteractive
= TRUE
;
194 for (i
= n
; i
< argc
;)
196 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
199 convertMode
= TEX_RTF
;
203 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
206 isInteractive
= TRUE
;
209 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
214 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
217 convertMode
= TEX_RTF
;
219 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
222 convertMode
= TEX_HTML
;
224 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
227 convertMode
= TEX_XLP
;
229 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
234 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
239 MacroFile
= copystring(argv
[i
]);
243 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
248 BufSize
= wxAtoi(argv
[i
]);
252 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
259 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
260 wxStrcmp(s
, _T("pca")) == 0)
261 RTFCharset
= copystring(s
);
264 OnError(_T("Incorrect argument for -charset"));
269 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
272 checkCurleyBraces
= TRUE
;
274 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
282 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
283 OnError((wxChar
*)buf
.c_str());
292 #if defined(__WXMSW__) && !defined(NO_GUI)
294 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
295 TheTex2RTFServer
= new Tex2RTFServer
;
296 TheTex2RTFServer
->Create(_T("TEX2RTF"));
299 #if defined(__WXMSW__) && defined(__WIN16__)
300 // Limit to max Windows array size
301 if (BufSize
> 64) BufSize
= 64;
304 TexInitialize(BufSize
);
305 ResetContentsLevels(0);
313 // Create the main frame window
314 frame
= new MyFrame(NULL
, -1, _T("Tex2RTF"), wxPoint(-1, -1), wxSize(400, 300));
315 frame
->CreateStatusBar(2);
318 // TODO: uncomment this when we have tex2rtf.xpm
319 frame
->SetIcon(wxICON(tex2rtf
));
323 wxSprintf(buf
, _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
324 frame
->SetTitle(buf
);
328 wxMenu
*file_menu
= new wxMenu
;
329 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
330 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
331 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
332 file_menu
->AppendSeparator();
333 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
334 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
335 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
336 file_menu
->AppendSeparator();
337 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
339 wxMenu
*macro_menu
= new wxMenu
;
341 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
342 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
344 wxMenu
*mode_menu
= new wxMenu
;
346 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
347 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
348 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
349 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
351 wxMenu
*options_menu
= new wxMenu
;
353 options_menu
->Append(TEX_OPTIONS_CURELY_BRACE
, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),TRUE
);
354 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),TRUE
);
356 options_menu
->Check(TEX_OPTIONS_CURELY_BRACE
, checkCurleyBraces
);
357 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
359 wxMenu
*help_menu
= new wxMenu
;
361 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
362 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
364 menuBar
= new wxMenuBar
;
365 menuBar
->Append(file_menu
, _T("&File"));
366 menuBar
->Append(macro_menu
, _T("&Macros"));
367 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
368 menuBar
->Append(options_menu
, _T("&Options"));
369 menuBar
->Append(help_menu
, _T("&Help"));
371 frame
->SetMenuBar(menuBar
);
372 frame
->textWindow
= new wxTextCtrl(frame
, -1, _T(""), wxPoint(-1, -1), wxSize(-1, -1), wxTE_READONLY
|wxTE_MULTILINE
);
374 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
378 HelpInstance
= new wxHelpController();
379 HelpInstance
->Initialize(_T("tex2rtf"));
383 * Read macro/initialisation file
387 wxString path
= TexPathList
.FindValidPath(MacroFile
);
389 ReadCustomMacros((wxChar
*)path
.c_str());
391 wxStrcpy(buf
, _T("In "));
393 if (winHelp
&& (convertMode
== TEX_RTF
))
394 wxStrcat(buf
, _T("WinHelp RTF"));
395 else if (!winHelp
&& (convertMode
== TEX_RTF
))
396 wxStrcat(buf
, _T("linear RTF"));
397 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
398 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
399 wxStrcat(buf
, _T(" mode."));
400 frame
->SetStatusText(buf
, 1);
409 * Read macro/initialisation file
413 wxString path
= TexPathList
.FindValidPath(MacroFile
);
415 ReadCustomMacros((wxChar
*)path
.c_str());
430 // it already returned something, no need to cause warning
432 // Return the main frame window
443 wxNode
*node
= CustomMacroList
.GetFirst();
446 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
449 node
= CustomMacroList
.GetFirst();
451 MacroDefs
.BeginFind();
452 node
= MacroDefs
.Next();
455 TexMacroDef
* def
= (TexMacroDef
*) node
->GetData();
457 node
= MacroDefs
.Next();
461 delete TheTex2RTFServer
;
476 delete currentArgData
;
477 currentArgData
= NULL
;
491 delete TexTmpBibName
;
492 TexTmpBibName
= NULL
;
506 delete TmpContentsName
;
507 TmpContentsName
= NULL
;
509 if (TmpFrameContentsName
)
511 delete TmpFrameContentsName
;
512 TmpFrameContentsName
= NULL
;
514 if (WinHelpContentsFileName
)
516 delete WinHelpContentsFileName
;
517 WinHelpContentsFileName
= NULL
;
541 delete [] BibliographyStyleString
;
542 delete [] DocumentStyleString
;
543 delete [] bitmapMethod
;
544 delete [] backgroundColourString
;
545 delete [] ContentsNameString
;
546 delete [] AbstractNameString
;
547 delete [] GlossaryNameString
;
548 delete [] ReferencesNameString
;
549 delete [] FiguresNameString
;
550 delete [] TablesNameString
;
551 delete [] FigureNameString
;
552 delete [] TableNameString
;
553 delete [] IndexNameString
;
554 delete [] ChapterNameString
;
555 delete [] SectionNameString
;
556 delete [] SubsectionNameString
;
557 delete [] SubsubsectionNameString
;
558 delete [] UpNameString
;
560 delete[] winHelpTitle
;
562 // TODO: this simulates zero-memory leaks!
563 // Otherwise there are just too many...
565 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
566 wxDebugContext::SetCheckpoint();
573 void ShowOptions(void)
576 wxSprintf(buf
, _T("Tex2RTF version %.2f"), versionNo
);
578 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
579 OnInform(_T("where valid switches are"));
581 OnInform(_T(" -interactive"));
583 OnInform(_T(" -bufsize <size in K>"));
584 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
585 OnInform(_T(" -twice"));
586 OnInform(_T(" -sync"));
587 OnInform(_T(" -checkcurleybraces"));
588 OnInform(_T(" -checksyntax"));
589 OnInform(_T(" -macros <filename>"));
590 OnInform(_T(" -winhelp"));
591 OnInform(_T(" -rtf"));
592 OnInform(_T(" -html"));
593 OnInform(_T(" -xlp\n"));
598 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
599 EVT_CLOSE(MyFrame::OnCloseWindow
)
600 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
601 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
602 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
603 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
604 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
605 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
606 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
607 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
608 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
609 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
610 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
611 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
612 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
613 EVT_MENU(TEX_OPTIONS_CURELY_BRACE
, MyFrame::OnOptionsCurleyBrace
)
614 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
615 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
616 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
619 // My frame constructor
620 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
621 wxFrame(frame
, id
, title
, pos
, size
)
624 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
626 if (!stopRunning
&& !OkToClose
)
638 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
644 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
648 menuBar
->EnableTop(0, FALSE
);
649 menuBar
->EnableTop(1, FALSE
);
650 menuBar
->EnableTop(2, FALSE
);
651 menuBar
->EnableTop(3, FALSE
);
658 SetStatusText(_T("Build aborted!"));
660 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
661 OnInform((wxChar
*)errBuf
.c_str());
665 if (runTwice
&& !stopRunning
)
670 menuBar
->EnableTop(0, TRUE
);
671 menuBar
->EnableTop(1, TRUE
);
672 menuBar
->EnableTop(2, TRUE
);
673 menuBar
->EnableTop(3, TRUE
);
676 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
678 ChooseInputFile(TRUE
);
681 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
683 ChooseOutputFile(TRUE
);
686 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
688 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
691 textWindow
->SaveFile(s
);
693 wxSprintf(buf
, _T("Saved text to %s"), (const wxChar
*) s
.c_str());
694 frame
->SetStatusText(buf
, 0);
698 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
701 if (OutputFile
&& wxFileExists(OutputFile
))
703 textWindow
->LoadFile(OutputFile
);
705 wxString
str(wxFileNameFromPath(OutputFile
));
706 wxSprintf(buf
, _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
707 frame
->SetTitle(buf
);
711 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
714 if (InputFile
&& wxFileExists(InputFile
))
716 textWindow
->LoadFile(InputFile
);
718 wxString
str(wxFileNameFromPath(OutputFile
));
719 wxSprintf(buf
, _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
720 frame
->SetTitle(buf
);
724 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
727 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
728 if (s
!= _T("") && wxFileExists(s
))
730 MacroFile
= copystring(s
);
731 ReadCustomMacros((wxChar
*)s
.c_str());
736 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
743 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
745 convertMode
= TEX_RTF
;
749 SetStatusText(_T("In linear RTF mode."), 1);
752 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
754 convertMode
= TEX_RTF
;
758 SetStatusText(_T("In WinHelp RTF mode."), 1);
761 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
763 convertMode
= TEX_HTML
;
767 SetStatusText(_T("In HTML mode."), 1);
770 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
772 convertMode
= TEX_XLP
;
775 SetStatusText(_T("In XLP mode."), 1);
778 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& WXUNUSED(event
))
780 checkCurleyBraces
= !checkCurleyBraces
;
781 if (checkCurleyBraces
)
783 SetStatusText(_T("Checking curley braces: YES"), 1);
787 SetStatusText(_T("Checking curley braces: NO"), 1);
792 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
794 checkSyntax
= !checkSyntax
;
797 SetStatusText(_T("Checking syntax: YES"), 1);
801 SetStatusText(_T("Checking syntax: NO"), 1);
806 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
809 HelpInstance
->LoadFile();
810 HelpInstance
->DisplayContents();
814 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
818 wxChar
*platform
= _T(" (32-bit)");
821 wxChar
*platform
= _T(" (16-bit)");
823 wxChar
*platform
= _T("");
826 wxSprintf(buf
, _T("Tex2RTF Version %.2f%s\nLaTeX to RTF, WinHelp, and HTML Conversion\n\n(c) Julian Smart, George Tasker and others, 1999-2002"), versionNo
, platform
);
827 wxMessageBox(buf
, _T("About Tex2RTF"));
830 void ChooseInputFile(bool force
)
832 if (force
|| !InputFile
)
834 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
837 // Different file, so clear index entries.
839 ResetContentsLevels(0);
843 InputFile
= copystring(s
);
844 wxString str
= wxFileNameFromPath(InputFile
);
846 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
847 frame
->SetTitle((wxChar
*)buf
.c_str());
853 void ChooseOutputFile(bool force
)
855 wxChar extensionBuf
[10];
857 wxStrcpy(wildBuf
, _T("*."));
860 path
= wxPathOnly(OutputFile
);
862 path
= wxPathOnly(InputFile
);
868 wxStrcpy(extensionBuf
, _T("rtf"));
869 wxStrcat(wildBuf
, _T("rtf"));
874 wxStrcpy(extensionBuf
, _T("xlp"));
875 wxStrcat(wildBuf
, _T("xlp"));
880 #if defined(__WXMSW__) && defined(__WIN16__)
881 wxStrcpy(extensionBuf
, _T("htm"));
882 wxStrcat(wildBuf
, _T("htm"));
884 wxStrcpy(extensionBuf
, _T("html"));
885 wxStrcat(wildBuf
, _T("html"));
890 if (force
|| !OutputFile
)
892 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
893 extensionBuf
, wildBuf
);
895 OutputFile
= copystring(s
);
907 if (!InputFile
|| !OutputFile
|| stopRunning
)
914 wxString str
= wxFileNameFromPath(InputFile
);
916 wxSprintf(buf
, _T("Tex2RTF [%s]"), (const wxChar
*) str
);
917 frame
->SetTitle(buf
);
923 // Find extension-less filename
924 wxStrcpy(FileRoot
, OutputFile
);
925 StripExtension(FileRoot
);
927 if (truncateFilenames
&& convertMode
== TEX_HTML
)
929 // Truncate to five characters. This ensures that
930 // we can generate DOS filenames such as thing999. But 1000 files
931 // may not be enough, of course...
932 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
935 if(wxStrlen( sName
) > 5)
936 sName
[5] = '\0'; // that should do!
939 wxSprintf(ContentsName
, _T("%s.con"), FileRoot
);
940 wxSprintf(TmpContentsName
, _T("%s.cn1"), FileRoot
);
941 wxSprintf(TmpFrameContentsName
, _T("%s.frc"), FileRoot
);
942 wxSprintf(WinHelpContentsFileName
, _T("%s.cnt"), FileRoot
);
943 wxSprintf(RefFileName
, _T("%s.ref"), FileRoot
);
945 TexPathList
.EnsureFileAccessible(InputFile
);
948 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
951 wxString str
= wxFileNameFromPath(s
);
952 bulletFile
= copystring(str
);
956 if (wxFileExists(RefFileName
))
957 ReadTexReferences(RefFileName
);
959 bool success
= FALSE
;
961 if (InputFile
&& OutputFile
)
963 if (!wxFileExists(InputFile
))
965 OnError(_T("Cannot open input file!"));
973 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
974 frame
->SetStatusText((wxChar
*)buf
.c_str());
978 OnInform(_T("Reading LaTeX file..."));
979 TexLoadFile(InputFile
);
1008 OnInform(_T("*** Aborted by user."));
1010 stopRunning
= FALSE
;
1016 WriteTexReferences(RefFileName
);
1018 startedSections
= FALSE
;
1022 long tim
= wxGetElapsedTime();
1023 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1024 OnInform((wxChar
*)buf
.c_str());
1028 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1029 OnInform((wxChar
*)buf
.c_str());
1034 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1035 frame
->SetStatusText((wxChar
*)buf
.c_str());
1038 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1039 OnInform((wxChar
*)buf
.c_str());
1042 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1043 OnInform((wxChar
*)buf
.c_str());
1053 startedSections
= FALSE
;
1056 frame
->SetStatusText(_T("Aborted by user."));
1059 OnInform(_T("Sorry, unsuccessful."));
1064 void OnError(const wxChar
*msg
)
1069 wxSTD cerr
<< "Error: " << msg
<< "\n";
1072 if (isInteractive
&& frame
)
1073 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1077 wxSTD cerr
<< "Error: " << msg
<< "\n";
1089 void OnInform(const wxChar
*msg
)
1092 wxSTD cout
<< msg
<< "\n";
1095 if (isInteractive
&& frame
)
1096 (*frame
->textWindow
) << msg
<< _T("\n");
1097 /* This whole block of code is just wrong I think. It would behave
1098 completely wrong under anything other than MSW due to the ELSE
1099 with no statement, and the cout calls would fail under MSW, as
1100 the code in this block is compiled if !NO_GUI This code has been
1101 here since v1.1 of this file too. - gt
1105 wxSTD cout << msg << "\n";
1120 void OnMacro(int macroId
, int no_args
, bool start
)
1122 switch (convertMode
)
1126 RTFOnMacro(macroId
, no_args
, start
);
1131 XLPOnMacro(macroId
, no_args
, start
);
1136 HTMLOnMacro(macroId
, no_args
, start
);
1142 bool OnArgument(int macroId
, int arg_no
, bool start
)
1144 switch (convertMode
)
1148 return RTFOnArgument(macroId
, arg_no
, start
);
1153 return XLPOnArgument(macroId
, arg_no
, start
);
1158 return HTMLOnArgument(macroId
, arg_no
, start
);
1168 #if defined(__WXMSW__) && !defined(NO_GUI)
1174 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1176 if (topic
== _T("TEX2RTF"))
1179 ipc_buffer
= new wxChar
[1000];
1181 return new Tex2RTFConnection(ipc_buffer
, 4000);
1191 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1195 Tex2RTFConnection::~Tex2RTFConnection(void)
1199 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1205 // Find first argument (command name)
1208 if (data
[i
] == ' ' || data
[i
] == 0)
1212 firstArg
[i
] = data
[i
];
1219 // Find second argument
1222 while (data
[i
] != 0)
1224 secondArg
[j
] = data
[i
];
1233 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1235 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1237 wxChar firstArg
[50];
1238 wxChar secondArg
[300];
1239 if (SplitCommand(data
, firstArg
, secondArg
))
1241 bool hasArg
= (wxStrlen(secondArg
) > 0);
1242 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1244 if (InputFile
) delete[] InputFile
;
1245 InputFile
= copystring(secondArg
);
1249 wxString str
= wxFileNameFromPath(InputFile
);
1250 wxSprintf(buf
, _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1251 frame
->SetTitle(buf
);
1254 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1256 if (OutputFile
) delete[] OutputFile
;
1257 OutputFile
= copystring(secondArg
);
1259 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1261 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1263 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1265 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1267 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1269 if (frame
) frame
->Close();
1271 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1274 frame
->Iconize(TRUE
);
1276 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1280 frame
->Iconize(FALSE
);
1286 // Try for a setting
1287 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, FALSE
));
1289 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1292 wxStrcpy(buf
, _T("In "));
1294 if (winHelp
&& (convertMode
== TEX_RTF
))
1295 wxStrcat(buf
, _T("WinHelp RTF"));
1296 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1297 wxStrcat(buf
, _T("linear RTF"));
1298 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1299 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1300 wxStrcat(buf
, _T(" mode."));
1301 frame
->SetStatusText(buf
, 1);
1309 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1311 return Tex2RTFLastStatus
;
1318 //void wxObject::Dump(wxSTD ostream& str)
1320 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1321 // str << GetClassInfo()->GetClassName();
1323 // str << "unknown object class";