1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to linear/WinHelp RTF, HTML, wxHelp.
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/textctrl.h"
28 #include "wx/filedlg.h"
29 #include "wx/msgdlg.h"
53 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
54 #include "tex2rtf.xpm"
57 #if !WXWIN_COMPATIBILITY_2_4
58 static inline wxChar
* copystring(const wxChar
* s
)
59 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
62 const float versionNo
= TEX2RTF_VERSION_NUMBER
;
64 TexChunk
*currentMember
= NULL
;
65 bool startedSections
= false;
66 wxChar
*contentsString
= NULL
;
67 bool suppressNameDecoration
= false;
68 bool OkToClose
= true;
70 unsigned long errorCount
= 0;
74 extern wxChar
*BigBuffer
;
75 extern wxChar
*TexFileRoot
;
76 extern wxChar
*TexBibName
; // Bibliography output file name
77 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
78 extern wxList ColourTable
;
79 extern TexChunk
*TopLevel
;
84 wxHelpController
*HelpInstance
= NULL
;
88 static wxChar
*ipc_buffer
= NULL
;
89 static wxChar Tex2RTFLastStatus
[100];
90 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
94 wxChar
*bulletFile
= NULL
;
96 FILE *Contents
= NULL
; // Contents page
97 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
98 FILE *Sections
= NULL
;
99 FILE *Subsections
= NULL
;
100 FILE *Subsubsections
= NULL
;
102 FILE *WinHelpContentsFile
= NULL
;
104 wxChar
*InputFile
= NULL
;
105 wxChar
*OutputFile
= NULL
;
106 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
108 wxChar
*FileRoot
= NULL
;
109 wxChar
*ContentsName
= NULL
; // Contents page from last time around
110 wxChar
*TmpContentsName
= NULL
; // Current contents page
111 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
112 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
113 wxChar
*RefFileName
= NULL
; // Reference file name
115 wxChar
*RTFCharset
= copystring(_T("ansi"));
118 int BufSize
= 100; // Size of buffer in K
124 void ShowOptions(void);
126 wxChar wxTex2RTFBuffer
[1500];
129 IMPLEMENT_APP_CONSOLE(MyApp
)
131 wxMenuBar
*menuBar
= NULL
;
132 MyFrame
*frame
= NULL
;
133 // DECLARE_APP(MyApp)
137 // `Main program' equivalent, creating windows and returning main app frame
140 // Use default list of macros defined in tex2any.cc
141 DefineDefaultMacros();
142 AddMacroDef(ltHARDY
, _T("hardy"), 0);
144 FileRoot
= new wxChar
[300];
145 ContentsName
= new wxChar
[300];
146 TmpContentsName
= new wxChar
[300];
147 TmpFrameContentsName
= new wxChar
[300];
148 WinHelpContentsFileName
= new wxChar
[300];
149 RefFileName
= new wxChar
[300];
151 ColourTable
.DeleteContents(true);
155 // Read input/output files
158 if (argv
[1][0] != '-')
165 if (argv
[2][0] != '-')
167 OutputFile
= argv
[2];
175 if (!InputFile
|| !OutputFile
)
177 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
185 TexPathList
.EnsureFileAccessible(InputFile
);
187 if (!InputFile
|| !OutputFile
)
188 isInteractive
= true;
191 for (i
= n
; i
< argc
;)
193 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
196 convertMode
= TEX_RTF
;
200 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
203 isInteractive
= true;
206 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
211 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
214 convertMode
= TEX_RTF
;
216 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
219 convertMode
= TEX_HTML
;
221 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
224 convertMode
= TEX_XLP
;
226 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
231 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
236 MacroFile
= copystring(argv
[i
]);
240 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
245 BufSize
= wxAtoi(argv
[i
]);
249 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
256 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
257 wxStrcmp(s
, _T("pca")) == 0)
258 RTFCharset
= copystring(s
);
261 OnError(_T("Incorrect argument for -charset"));
266 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
269 checkCurleyBraces
= true;
271 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
279 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
280 OnError((wxChar
*)buf
.c_str());
289 #if defined(__WXMSW__) && !defined(NO_GUI)
291 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
292 TheTex2RTFServer
= new Tex2RTFServer
;
293 TheTex2RTFServer
->Create(_T("TEX2RTF"));
296 TexInitialize(BufSize
);
297 ResetContentsLevels(0);
305 // Create the main frame window
306 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
307 frame
->CreateStatusBar(2);
310 // TODO: uncomment this when we have tex2rtf.xpm
311 frame
->SetIcon(wxICON(tex2rtf
));
315 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
316 frame
->SetTitle(buf
);
320 wxMenu
*file_menu
= new wxMenu
;
321 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
322 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
323 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
324 file_menu
->AppendSeparator();
325 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
326 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
327 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
328 file_menu
->AppendSeparator();
329 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
331 wxMenu
*macro_menu
= new wxMenu
;
333 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
334 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
336 wxMenu
*mode_menu
= new wxMenu
;
338 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
339 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
340 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
341 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
343 wxMenu
*options_menu
= new wxMenu
;
345 options_menu
->Append(TEX_OPTIONS_CURLEY_BRACE
, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),true);
346 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
348 options_menu
->Check(TEX_OPTIONS_CURLEY_BRACE
, checkCurleyBraces
);
349 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
351 wxMenu
*help_menu
= new wxMenu
;
353 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
354 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
356 menuBar
= new wxMenuBar
;
357 menuBar
->Append(file_menu
, _T("&File"));
358 menuBar
->Append(macro_menu
, _T("&Macros"));
359 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
360 menuBar
->Append(options_menu
, _T("&Options"));
361 menuBar
->Append(help_menu
, _T("&Help"));
363 frame
->SetMenuBar(menuBar
);
364 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
366 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
370 HelpInstance
= new wxHelpController();
371 HelpInstance
->Initialize(_T("tex2rtf"));
375 * Read macro/initialisation file
379 wxString path
= TexPathList
.FindValidPath(MacroFile
);
381 ReadCustomMacros((wxChar
*)path
.c_str());
383 wxStrcpy(buf
, _T("In "));
385 if (winHelp
&& (convertMode
== TEX_RTF
))
386 wxStrcat(buf
, _T("WinHelp RTF"));
387 else if (!winHelp
&& (convertMode
== TEX_RTF
))
388 wxStrcat(buf
, _T("linear RTF"));
389 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
390 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
391 wxStrcat(buf
, _T(" mode."));
392 frame
->SetStatusText(buf
, 1);
401 * Read macro/initialisation file
405 wxString path
= TexPathList
.FindValidPath(MacroFile
);
407 ReadCustomMacros((wxChar
*)path
.c_str());
417 OnExit(); // Do cleanup since OnExit won't be called now
426 wxNode
*node
= CustomMacroList
.GetFirst();
429 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
432 node
= CustomMacroList
.GetFirst();
434 MacroDefs
.BeginFind();
435 wxHashTable::Node
* mNode
= MacroDefs
.Next();
438 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
440 mNode
= MacroDefs
.Next();
444 delete TheTex2RTFServer
;
459 delete currentArgData
;
460 currentArgData
= NULL
;
474 delete TexTmpBibName
;
475 TexTmpBibName
= NULL
;
489 delete TmpContentsName
;
490 TmpContentsName
= NULL
;
492 if (TmpFrameContentsName
)
494 delete TmpFrameContentsName
;
495 TmpFrameContentsName
= NULL
;
497 if (WinHelpContentsFileName
)
499 delete WinHelpContentsFileName
;
500 WinHelpContentsFileName
= NULL
;
524 delete [] BibliographyStyleString
;
525 delete [] DocumentStyleString
;
526 delete [] bitmapMethod
;
527 delete [] backgroundColourString
;
528 delete [] ContentsNameString
;
529 delete [] AbstractNameString
;
530 delete [] GlossaryNameString
;
531 delete [] ReferencesNameString
;
532 delete [] FiguresNameString
;
533 delete [] TablesNameString
;
534 delete [] FigureNameString
;
535 delete [] TableNameString
;
536 delete [] IndexNameString
;
537 delete [] ChapterNameString
;
538 delete [] SectionNameString
;
539 delete [] SubsectionNameString
;
540 delete [] SubsubsectionNameString
;
541 delete [] UpNameString
;
543 delete[] winHelpTitle
;
545 // TODO: this simulates zero-memory leaks!
546 // Otherwise there are just too many...
548 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
549 wxDebugContext::SetCheckpoint();
556 void ShowOptions(void)
559 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
561 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
562 OnInform(_T("where valid switches are"));
564 OnInform(_T(" -interactive"));
566 OnInform(_T(" -bufsize <size in K>"));
567 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
568 OnInform(_T(" -twice"));
569 OnInform(_T(" -sync"));
570 OnInform(_T(" -checkcurleybraces"));
571 OnInform(_T(" -checksyntax"));
572 OnInform(_T(" -macros <filename>"));
573 OnInform(_T(" -winhelp"));
574 OnInform(_T(" -rtf"));
575 OnInform(_T(" -html"));
576 OnInform(_T(" -xlp\n"));
581 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
582 EVT_CLOSE(MyFrame::OnCloseWindow
)
583 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
584 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
585 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
586 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
587 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
588 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
589 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
590 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
591 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
592 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
593 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
594 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
595 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
596 EVT_MENU(TEX_OPTIONS_CURLEY_BRACE
, MyFrame::OnOptionsCurleyBrace
)
597 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
598 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
599 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
602 // My frame constructor
603 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
604 wxFrame(frame
, id
, title
, pos
, size
)
607 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
609 if (!stopRunning
&& !OkToClose
)
621 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
627 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
631 menuBar
->EnableTop(0, false);
632 menuBar
->EnableTop(1, false);
633 menuBar
->EnableTop(2, false);
634 menuBar
->EnableTop(3, false);
641 SetStatusText(_T("Build aborted!"));
643 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
644 OnInform((wxChar
*)errBuf
.c_str());
648 if (runTwice
&& !stopRunning
)
653 menuBar
->EnableTop(0, true);
654 menuBar
->EnableTop(1, true);
655 menuBar
->EnableTop(2, true);
656 menuBar
->EnableTop(3, true);
659 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
661 ChooseInputFile(true);
664 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
666 ChooseOutputFile(true);
669 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
671 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
674 textWindow
->SaveFile(s
);
676 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
677 frame
->SetStatusText(buf
, 0);
681 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
684 if (OutputFile
&& wxFileExists(OutputFile
))
686 textWindow
->LoadFile(OutputFile
);
688 wxString
str(wxFileNameFromPath(OutputFile
));
689 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
690 frame
->SetTitle(buf
);
694 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
697 if (InputFile
&& wxFileExists(InputFile
))
699 textWindow
->LoadFile(InputFile
);
701 wxString
str(wxFileNameFromPath(OutputFile
));
702 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
703 frame
->SetTitle(buf
);
707 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
710 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
711 if (s
!= _T("") && wxFileExists(s
))
713 MacroFile
= copystring(s
);
714 ReadCustomMacros((wxChar
*)s
.c_str());
719 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
726 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
728 convertMode
= TEX_RTF
;
732 SetStatusText(_T("In linear RTF mode."), 1);
735 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
737 convertMode
= TEX_RTF
;
741 SetStatusText(_T("In WinHelp RTF mode."), 1);
744 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
746 convertMode
= TEX_HTML
;
750 SetStatusText(_T("In HTML mode."), 1);
753 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
755 convertMode
= TEX_XLP
;
758 SetStatusText(_T("In XLP mode."), 1);
761 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& WXUNUSED(event
))
763 checkCurleyBraces
= !checkCurleyBraces
;
764 if (checkCurleyBraces
)
766 SetStatusText(_T("Checking curley braces: YES"), 1);
770 SetStatusText(_T("Checking curley braces: NO"), 1);
775 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
777 checkSyntax
= !checkSyntax
;
780 SetStatusText(_T("Checking syntax: YES"), 1);
784 SetStatusText(_T("Checking syntax: NO"), 1);
789 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
792 HelpInstance
->LoadFile();
793 HelpInstance
->DisplayContents();
797 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
801 wxChar
*platform
= _T(" (32-bit)");
804 wxChar
*platform
= _T(" (16-bit)");
806 wxChar
*platform
= _T("");
809 wxSnprintf(buf
, sizeof(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
);
810 wxMessageBox(buf
, _T("About Tex2RTF"));
813 void ChooseInputFile(bool force
)
815 if (force
|| !InputFile
)
817 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
820 // Different file, so clear index entries.
822 ResetContentsLevels(0);
826 InputFile
= copystring(s
);
827 wxString str
= wxFileNameFromPath(InputFile
);
829 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
830 frame
->SetTitle((wxChar
*)buf
.c_str());
836 void ChooseOutputFile(bool force
)
838 wxChar extensionBuf
[10];
840 wxStrcpy(wildBuf
, _T("*."));
843 path
= wxPathOnly(OutputFile
);
845 path
= wxPathOnly(InputFile
);
851 wxStrcpy(extensionBuf
, _T("rtf"));
852 wxStrcat(wildBuf
, _T("rtf"));
857 wxStrcpy(extensionBuf
, _T("xlp"));
858 wxStrcat(wildBuf
, _T("xlp"));
863 wxStrcpy(extensionBuf
, _T("html"));
864 wxStrcat(wildBuf
, _T("html"));
868 if (force
|| !OutputFile
)
870 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
871 extensionBuf
, wildBuf
);
873 OutputFile
= copystring(s
);
885 if (!InputFile
|| !OutputFile
|| stopRunning
)
892 wxString str
= wxFileNameFromPath(InputFile
);
894 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
895 frame
->SetTitle(buf
);
901 // Find extension-less filename
902 wxStrcpy(FileRoot
, OutputFile
);
903 StripExtension(FileRoot
);
905 if (truncateFilenames
&& convertMode
== TEX_HTML
)
907 // Truncate to five characters. This ensures that
908 // we can generate DOS filenames such as thing999. But 1000 files
909 // may not be enough, of course...
910 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
913 if(wxStrlen( sName
) > 5)
914 sName
[5] = '\0'; // that should do!
917 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
918 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
919 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
920 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
921 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
923 TexPathList
.EnsureFileAccessible(InputFile
);
926 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
929 wxString str
= wxFileNameFromPath(s
);
930 bulletFile
= copystring(str
);
934 if (wxFileExists(RefFileName
))
935 ReadTexReferences(RefFileName
);
937 bool success
= false;
939 if (InputFile
&& OutputFile
)
941 if (!wxFileExists(InputFile
))
943 OnError(_T("Cannot open input file!"));
951 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
952 frame
->SetStatusText((wxChar
*)buf
.c_str());
956 OnInform(_T("Reading LaTeX file..."));
957 TexLoadFile(InputFile
);
986 OnInform(_T("*** Aborted by user."));
994 WriteTexReferences(RefFileName
);
996 startedSections
= false;
1000 long tim
= wxGetElapsedTime();
1001 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1002 OnInform((wxChar
*)buf
.c_str());
1006 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1007 OnInform((wxChar
*)buf
.c_str());
1012 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1013 frame
->SetStatusText((wxChar
*)buf
.c_str());
1016 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1017 OnInform((wxChar
*)buf
.c_str());
1020 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1021 OnInform((wxChar
*)buf
.c_str());
1031 startedSections
= false;
1034 frame
->SetStatusText(_T("Aborted by user."));
1037 OnInform(_T("Sorry, unsuccessful."));
1042 void OnError(const wxChar
*msg
)
1044 wxString msg_string
= msg
;
1048 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1051 if (isInteractive
&& frame
)
1052 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1056 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1068 void OnInform(const wxChar
*msg
)
1070 wxString msg_string
= msg
;
1072 wxSTD cout
<< msg_string
.mb_str() << "\n";
1075 if (isInteractive
&& frame
)
1076 (*frame
->textWindow
) << msg
<< _T("\n");
1077 /* This whole block of code is just wrong I think. It would behave
1078 completely wrong under anything other than MSW due to the ELSE
1079 with no statement, and the cout calls would fail under MSW, as
1080 the code in this block is compiled if !NO_GUI This code has been
1081 here since v1.1 of this file too. - gt
1085 wxSTD cout << msg_string.mb_str() << "\n";
1100 void OnMacro(int macroId
, int no_args
, bool start
)
1102 switch (convertMode
)
1106 RTFOnMacro(macroId
, no_args
, start
);
1111 XLPOnMacro(macroId
, no_args
, start
);
1116 HTMLOnMacro(macroId
, no_args
, start
);
1122 bool OnArgument(int macroId
, int arg_no
, bool start
)
1124 switch (convertMode
)
1128 return RTFOnArgument(macroId
, arg_no
, start
);
1133 return XLPOnArgument(macroId
, arg_no
, start
);
1138 return HTMLOnArgument(macroId
, arg_no
, start
);
1148 #if defined(__WXMSW__) && !defined(NO_GUI)
1154 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1156 if (topic
== _T("TEX2RTF"))
1159 ipc_buffer
= new wxChar
[1000];
1161 return new Tex2RTFConnection(ipc_buffer
, 4000);
1171 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1175 Tex2RTFConnection::~Tex2RTFConnection(void)
1179 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1185 // Find first argument (command name)
1188 if (data
[i
] == ' ' || data
[i
] == 0)
1192 firstArg
[i
] = data
[i
];
1199 // Find second argument
1202 while (data
[i
] != 0)
1204 secondArg
[j
] = data
[i
];
1213 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1215 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1217 wxChar firstArg
[50];
1218 wxChar secondArg
[300];
1219 if (SplitCommand(data
, firstArg
, secondArg
))
1221 bool hasArg
= (wxStrlen(secondArg
) > 0);
1222 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1224 if (InputFile
) delete[] InputFile
;
1225 InputFile
= copystring(secondArg
);
1229 wxString str
= wxFileNameFromPath(InputFile
);
1230 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1231 frame
->SetTitle(buf
);
1234 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1236 if (OutputFile
) delete[] OutputFile
;
1237 OutputFile
= copystring(secondArg
);
1239 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1241 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1243 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1245 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1247 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1249 if (frame
) frame
->Close();
1251 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1254 frame
->Iconize(true);
1256 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1260 frame
->Iconize(false);
1266 // Try for a setting
1267 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1269 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1272 wxStrcpy(buf
, _T("In "));
1274 if (winHelp
&& (convertMode
== TEX_RTF
))
1275 wxStrcat(buf
, _T("WinHelp RTF"));
1276 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1277 wxStrcat(buf
, _T("linear RTF"));
1278 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1279 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1280 wxStrcat(buf
, _T(" mode."));
1281 frame
->SetStatusText(buf
, 1);
1289 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1291 return Tex2RTFLastStatus
;
1298 //void wxObject::Dump(wxSTD ostream& str)
1300 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1301 // str << GetClassInfo()->GetClassName();
1303 // str << "unknown object class";