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"
24 #if defined(__WXMSW__)
25 #include "wx/msw/wrapwin.h"
31 #include "wx/textctrl.h"
32 #include "wx/filedlg.h"
33 #include "wx/msgdlg.h"
41 #include "wx/cshelp.h"
42 #include "wx/helphtml.h"
44 #include "wx/msw/helpchm.h"
46 #include "wx/html/helpctrl.h"
65 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
66 #include "tex2rtf.xpm"
69 #if !WXWIN_COMPATIBILITY_2_4
70 static inline wxChar
* copystring(const wxChar
* s
)
71 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
74 const float versionNo
= float(TEX2RTF_VERSION_NUMBER
);
76 TexChunk
*currentMember
= NULL
;
77 bool startedSections
= false;
78 wxChar
*contentsString
= NULL
;
79 bool suppressNameDecoration
= false;
80 bool OkToClose
= true;
82 unsigned long errorCount
= 0;
86 extern wxChar
*BigBuffer
;
87 extern wxChar
*TexFileRoot
;
88 extern wxChar
*TexBibName
; // Bibliography output file name
89 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
90 extern wxList ColourTable
;
91 extern TexChunk
*TopLevel
;
94 wxHelpControllerBase
*HelpInstance
= NULL
;
98 static wxChar
*ipc_buffer
= NULL
;
99 static wxChar Tex2RTFLastStatus
[100];
100 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
105 wxChar
*bulletFile
= NULL
;
107 FILE *Contents
= NULL
; // Contents page
108 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
109 FILE *Sections
= NULL
;
110 FILE *Subsections
= NULL
;
111 FILE *Subsubsections
= NULL
;
113 FILE *WinHelpContentsFile
= NULL
;
115 wxChar
*InputFile
= NULL
;
116 wxChar
*OutputFile
= NULL
;
117 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
119 wxChar
*FileRoot
= NULL
;
120 wxChar
*ContentsName
= NULL
; // Contents page from last time around
121 wxChar
*TmpContentsName
= NULL
; // Current contents page
122 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
123 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
124 wxChar
*RefFileName
= NULL
; // Reference file name
126 wxChar
*RTFCharset
= copystring(_T("ansi"));
129 int BufSize
= 100; // Size of buffer in K
135 void ShowOptions(void);
137 wxChar wxTex2RTFBuffer
[1500];
140 IMPLEMENT_APP_CONSOLE(MyApp
)
142 wxMenuBar
*menuBar
= NULL
;
143 MyFrame
*frame
= NULL
;
144 // DECLARE_APP(MyApp)
148 // `Main program' equivalent, creating windows and returning main app frame
151 // Use default list of macros defined in tex2any.cc
152 DefineDefaultMacros();
153 AddMacroDef(ltHARDY
, _T("hardy"), 0);
155 FileRoot
= new wxChar
[300];
156 ContentsName
= new wxChar
[300];
157 TmpContentsName
= new wxChar
[300];
158 TmpFrameContentsName
= new wxChar
[300];
159 WinHelpContentsFileName
= new wxChar
[300];
160 RefFileName
= new wxChar
[300];
162 WX_CLEAR_LIST(wxList
,ColourTable
);
166 // Read input/output files
169 if (argv
[1][0] != '-')
176 if (argv
[2][0] != '-')
178 OutputFile
= argv
[2];
186 if (!InputFile
|| !OutputFile
)
188 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
196 TexPathList
.EnsureFileAccessible(InputFile
);
198 if (!InputFile
|| !OutputFile
)
199 isInteractive
= true;
202 for (i
= n
; i
< argc
;)
204 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
207 convertMode
= TEX_RTF
;
211 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
214 isInteractive
= true;
217 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
222 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
225 convertMode
= TEX_RTF
;
227 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
230 convertMode
= TEX_HTML
;
232 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
235 convertMode
= TEX_XLP
;
237 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
242 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
247 MacroFile
= copystring(argv
[i
]);
251 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
256 BufSize
= wxAtoi(argv
[i
]);
260 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
267 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
268 wxStrcmp(s
, _T("pca")) == 0)
269 RTFCharset
= copystring(s
);
272 OnError(_T("Incorrect argument for -charset"));
277 else if (wxStrcmp(argv
[i
], _T("-checkcurlybraces")) == 0)
280 checkCurlyBraces
= true;
282 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
284 // Support the old, incorrectly spelled version of -checkcurlybraces
285 // so that old scripts which run tex2rtf -checkcurleybraces still work.
287 checkCurlyBraces
= true;
289 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
297 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
298 OnError((wxChar
*)buf
.c_str());
308 #if defined(__WXMSW__) && !defined(NO_GUI)
310 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
311 TheTex2RTFServer
= new Tex2RTFServer
;
312 TheTex2RTFServer
->Create(_T("TEX2RTF"));
315 TexInitialize(BufSize
);
316 ResetContentsLevels(0);
324 // Create the main frame window
325 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
327 frame
->CreateStatusBar(2);
328 #endif // wxUSE_STATUSBAR
331 // TODO: uncomment this when we have tex2rtf.xpm
332 frame
->SetIcon(wxICON(tex2rtf
));
336 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
337 frame
->SetTitle(buf
);
341 wxMenu
*file_menu
= new wxMenu
;
342 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
343 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
344 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
345 file_menu
->AppendSeparator();
346 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
347 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
348 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
349 file_menu
->AppendSeparator();
350 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
352 wxMenu
*macro_menu
= new wxMenu
;
354 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
355 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
357 wxMenu
*mode_menu
= new wxMenu
;
359 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
360 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
361 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
362 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
364 wxMenu
*options_menu
= new wxMenu
;
366 options_menu
->Append(TEX_OPTIONS_CURLY_BRACE
, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true);
367 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
369 options_menu
->Check(TEX_OPTIONS_CURLY_BRACE
, checkCurlyBraces
);
370 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
372 wxMenu
*help_menu
= new wxMenu
;
374 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
375 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
377 menuBar
= new wxMenuBar
;
378 menuBar
->Append(file_menu
, _T("&File"));
379 menuBar
->Append(macro_menu
, _T("&Macros"));
380 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
381 menuBar
->Append(options_menu
, _T("&Options"));
382 menuBar
->Append(help_menu
, _T("&Help"));
384 frame
->SetMenuBar(menuBar
);
385 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
387 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
391 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
392 HelpInstance
= new wxCHMHelpController
;
394 HelpInstance
= new wxHtmlHelpController
;
396 HelpInstance
->Initialize(_T("tex2rtf"));
400 * Read macro/initialisation file
404 wxString path
= TexPathList
.FindValidPath(MacroFile
);
406 ReadCustomMacros((wxChar
*)path
.c_str());
409 wxStrcpy(buf
, _T("In "));
413 wxStrcat(buf
, (winHelp
) ? _T("WinHelp RTF") : _T("linear RTF"));
416 wxStrcat(buf
, _T("HTML"));
419 wxStrcat(buf
, _T("XLP"));
422 wxStrcat(buf
, _T("unknown"));
425 wxStrcat(buf
, _T(" mode."));
426 frame
->SetStatusText(buf
, 1);
427 #endif // wxUSE_STATUSBAR
436 * Read macro/initialisation file
440 wxString path
= TexPathList
.FindValidPath(MacroFile
);
442 ReadCustomMacros((wxChar
*)path
.c_str());
452 OnExit(); // Do cleanup since OnExit won't be called now
461 wxNode
*node
= CustomMacroList
.GetFirst();
464 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
467 node
= CustomMacroList
.GetFirst();
469 MacroDefs
.BeginFind();
470 wxHashTable::Node
* mNode
= MacroDefs
.Next();
473 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
475 mNode
= MacroDefs
.Next();
479 delete TheTex2RTFServer
;
494 delete currentArgData
;
495 currentArgData
= NULL
;
509 delete TexTmpBibName
;
510 TexTmpBibName
= NULL
;
524 delete TmpContentsName
;
525 TmpContentsName
= NULL
;
527 if (TmpFrameContentsName
)
529 delete TmpFrameContentsName
;
530 TmpFrameContentsName
= NULL
;
532 if (WinHelpContentsFileName
)
534 delete WinHelpContentsFileName
;
535 WinHelpContentsFileName
= NULL
;
559 delete [] BibliographyStyleString
;
560 delete [] DocumentStyleString
;
561 delete [] bitmapMethod
;
562 delete [] backgroundColourString
;
563 delete [] ContentsNameString
;
564 delete [] AbstractNameString
;
565 delete [] GlossaryNameString
;
566 delete [] ReferencesNameString
;
567 delete [] FiguresNameString
;
568 delete [] TablesNameString
;
569 delete [] FigureNameString
;
570 delete [] TableNameString
;
571 delete [] IndexNameString
;
572 delete [] ChapterNameString
;
573 delete [] SectionNameString
;
574 delete [] SubsectionNameString
;
575 delete [] SubsubsectionNameString
;
576 delete [] UpNameString
;
578 delete[] winHelpTitle
;
580 // TODO: this simulates zero-memory leaks!
581 // Otherwise there are just too many...
583 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
584 wxDebugContext::SetCheckpoint();
591 void ShowOptions(void)
594 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
596 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
597 OnInform(_T("where valid switches are"));
599 OnInform(_T(" -interactive"));
601 OnInform(_T(" -bufsize <size in K>"));
602 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
603 OnInform(_T(" -twice"));
604 OnInform(_T(" -sync"));
605 OnInform(_T(" -checkcurlybraces"));
606 OnInform(_T(" -checksyntax"));
607 OnInform(_T(" -macros <filename>"));
608 OnInform(_T(" -winhelp"));
609 OnInform(_T(" -rtf"));
610 OnInform(_T(" -html"));
611 OnInform(_T(" -xlp\n"));
616 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
617 EVT_CLOSE(MyFrame::OnCloseWindow
)
618 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
619 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
620 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
621 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
622 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
623 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
624 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
625 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
626 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
627 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
628 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
629 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
630 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
631 EVT_MENU(TEX_OPTIONS_CURLY_BRACE
, MyFrame::OnOptionsCurlyBrace
)
632 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
633 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
634 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
637 // My frame constructor
638 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
639 wxFrame(frame
, id
, title
, pos
, size
)
642 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
644 if (!stopRunning
&& !OkToClose
)
656 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
662 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
666 menuBar
->EnableTop(0, false);
667 menuBar
->EnableTop(1, false);
668 menuBar
->EnableTop(2, false);
669 menuBar
->EnableTop(3, false);
677 SetStatusText(_T("Build aborted!"));
678 #endif // wxUSE_STATUSBAR
680 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
681 OnInform((wxChar
*)errBuf
.c_str());
685 if (runTwice
&& !stopRunning
)
690 menuBar
->EnableTop(0, true);
691 menuBar
->EnableTop(1, true);
692 menuBar
->EnableTop(2, true);
693 menuBar
->EnableTop(3, true);
696 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
698 ChooseInputFile(true);
701 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
703 ChooseOutputFile(true);
706 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
708 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
711 textWindow
->SaveFile(s
);
714 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
715 frame
->SetStatusText(buf
, 0);
716 #endif // wxUSE_STATUSBAR
720 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
723 if (OutputFile
&& wxFileExists(OutputFile
))
725 textWindow
->LoadFile(OutputFile
);
727 wxString
str(wxFileNameFromPath(OutputFile
));
728 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
729 frame
->SetTitle(buf
);
733 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
736 if (InputFile
&& wxFileExists(InputFile
))
738 textWindow
->LoadFile(InputFile
);
740 wxString
str(wxFileNameFromPath(OutputFile
));
741 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
742 frame
->SetTitle(buf
);
746 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
749 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
750 if (!s
.empty() && wxFileExists(s
))
752 MacroFile
= copystring(s
);
753 ReadCustomMacros((wxChar
*)s
.c_str());
758 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
765 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
767 convertMode
= TEX_RTF
;
772 SetStatusText(_T("In linear RTF mode."), 1);
773 #endif // wxUSE_STATUSBAR
776 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
778 convertMode
= TEX_RTF
;
783 SetStatusText(_T("In WinHelp RTF mode."), 1);
784 #endif // wxUSE_STATUSBAR
787 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
789 convertMode
= TEX_HTML
;
794 SetStatusText(_T("In HTML mode."), 1);
795 #endif // wxUSE_STATUSBAR
798 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
800 convertMode
= TEX_XLP
;
804 SetStatusText(_T("In XLP mode."), 1);
805 #endif // wxUSE_STATUSBAR
808 void MyFrame::OnOptionsCurlyBrace(wxCommandEvent
& WXUNUSED(event
))
810 checkCurlyBraces
= !checkCurlyBraces
;
812 if (checkCurlyBraces
)
814 SetStatusText(_T("Checking curly braces: YES"), 1);
818 SetStatusText(_T("Checking curly braces: NO"), 1);
820 #endif // wxUSE_STATUSBAR
824 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
826 checkSyntax
= !checkSyntax
;
830 SetStatusText(_T("Checking syntax: YES"), 1);
834 SetStatusText(_T("Checking syntax: NO"), 1);
836 #endif // wxUSE_STATUSBAR
840 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
843 HelpInstance
->LoadFile();
844 HelpInstance
->DisplayContents();
848 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
852 wxChar
*platform
= _T(" (32-bit)");
855 wxChar
*platform
= _T(" (16-bit)");
857 wxChar
*platform
= _T("");
860 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
);
861 wxMessageBox(buf
, _T("About Tex2RTF"));
864 void ChooseInputFile(bool force
)
866 if (force
|| !InputFile
)
868 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
871 // Different file, so clear index entries.
873 ResetContentsLevels(0);
877 InputFile
= copystring(s
);
878 wxString str
= wxFileNameFromPath(InputFile
);
880 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
881 frame
->SetTitle((wxChar
*)buf
.c_str());
887 void ChooseOutputFile(bool force
)
889 wxChar extensionBuf
[10];
891 wxStrcpy(wildBuf
, _T("*."));
894 path
= wxPathOnly(OutputFile
);
896 path
= wxPathOnly(InputFile
);
902 wxStrcpy(extensionBuf
, _T("rtf"));
903 wxStrcat(wildBuf
, _T("rtf"));
908 wxStrcpy(extensionBuf
, _T("xlp"));
909 wxStrcat(wildBuf
, _T("xlp"));
914 wxStrcpy(extensionBuf
, _T("html"));
915 wxStrcat(wildBuf
, _T("html"));
919 if (force
|| !OutputFile
)
921 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
922 extensionBuf
, wildBuf
);
924 OutputFile
= copystring(s
);
936 if (!InputFile
|| !OutputFile
|| stopRunning
)
943 wxString str
= wxFileNameFromPath(InputFile
);
945 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
946 frame
->SetTitle(buf
);
952 // Find extension-less filename
953 wxStrcpy(FileRoot
, OutputFile
);
954 StripExtension(FileRoot
);
956 if (truncateFilenames
&& convertMode
== TEX_HTML
)
958 // Truncate to five characters. This ensures that
959 // we can generate DOS filenames such as thing999. But 1000 files
960 // may not be enough, of course...
961 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
964 if(wxStrlen( sName
) > 5)
965 sName
[5] = '\0'; // that should do!
968 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
969 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
970 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
971 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
972 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
974 TexPathList
.EnsureFileAccessible(InputFile
);
977 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
980 wxString str
= wxFileNameFromPath(s
);
981 bulletFile
= copystring(str
);
985 if (wxFileExists(RefFileName
))
986 ReadTexReferences(RefFileName
);
988 bool success
= false;
990 if (InputFile
&& OutputFile
)
992 if (!wxFileExists(InputFile
))
994 OnError(_T("Cannot open input file!"));
998 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1002 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
1003 frame
->SetStatusText((wxChar
*)buf
.c_str());
1007 OnInform(_T("Reading LaTeX file..."));
1008 TexLoadFile(InputFile
);
1016 switch (convertMode
)
1037 OnInform(_T("*** Aborted by user."));
1039 stopRunning
= false;
1045 WriteTexReferences(RefFileName
);
1047 startedSections
= false;
1051 long tim
= wxGetElapsedTime();
1052 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1053 OnInform((wxChar
*)buf
.c_str());
1057 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1058 OnInform((wxChar
*)buf
.c_str());
1064 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1065 frame
->SetStatusText((wxChar
*)buf
.c_str());
1067 #endif // wxUSE_STATUSBAR
1069 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1070 OnInform((wxChar
*)buf
.c_str());
1073 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1074 OnInform((wxChar
*)buf
.c_str());
1084 startedSections
= false;
1086 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1087 frame
->SetStatusText(_T("Aborted by user."));
1090 OnInform(_T("Sorry, unsuccessful."));
1095 void OnError(const wxChar
*msg
)
1097 wxString msg_string
= msg
;
1101 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1104 if (isInteractive
&& frame
)
1105 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1109 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1121 void OnInform(const wxChar
*msg
)
1123 wxString msg_string
= msg
;
1125 wxSTD cout
<< msg_string
.mb_str() << "\n";
1128 if (isInteractive
&& frame
)
1129 (*frame
->textWindow
) << msg
<< _T("\n");
1130 /* This whole block of code is just wrong I think. It would behave
1131 completely wrong under anything other than MSW due to the ELSE
1132 with no statement, and the cout calls would fail under MSW, as
1133 the code in this block is compiled if !NO_GUI This code has been
1134 here since v1.1 of this file too. - gt
1138 wxSTD cout << msg_string.mb_str() << "\n";
1153 void OnMacro(int macroId
, int no_args
, bool start
)
1155 switch (convertMode
)
1159 RTFOnMacro(macroId
, no_args
, start
);
1164 XLPOnMacro(macroId
, no_args
, start
);
1169 HTMLOnMacro(macroId
, no_args
, start
);
1175 bool OnArgument(int macroId
, int arg_no
, bool start
)
1177 switch (convertMode
)
1181 return RTFOnArgument(macroId
, arg_no
, start
);
1186 return XLPOnArgument(macroId
, arg_no
, start
);
1191 return HTMLOnArgument(macroId
, arg_no
, start
);
1201 #if defined(__WXMSW__) && !defined(NO_GUI)
1207 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1209 if (topic
== _T("TEX2RTF"))
1212 ipc_buffer
= new wxChar
[1000];
1214 return new Tex2RTFConnection(ipc_buffer
, 4000);
1224 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1228 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1234 // Find first argument (command name)
1237 if (data
[i
] == ' ' || data
[i
] == 0)
1241 firstArg
[i
] = data
[i
];
1248 // Find second argument
1251 while (data
[i
] != 0)
1253 secondArg
[j
] = data
[i
];
1262 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1264 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1266 wxChar firstArg
[50];
1267 wxChar secondArg
[300];
1268 if (SplitCommand(data
, firstArg
, secondArg
))
1270 bool hasArg
= (wxStrlen(secondArg
) > 0);
1271 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1273 if (InputFile
) delete[] InputFile
;
1274 InputFile
= copystring(secondArg
);
1278 wxString str
= wxFileNameFromPath(InputFile
);
1279 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1280 frame
->SetTitle(buf
);
1283 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1285 if (OutputFile
) delete[] OutputFile
;
1286 OutputFile
= copystring(secondArg
);
1288 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1290 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1292 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1294 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1296 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1298 if (frame
) frame
->Close();
1300 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1303 frame
->Iconize(true);
1305 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1309 frame
->Iconize(false);
1315 // Try for a setting
1316 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1317 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1318 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1321 wxStrcpy(buf
, _T("In "));
1323 if (winHelp
&& (convertMode
== TEX_RTF
))
1324 wxStrcat(buf
, _T("WinHelp RTF"));
1325 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1326 wxStrcat(buf
, _T("linear RTF"));
1327 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1328 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1329 wxStrcat(buf
, _T(" mode."));
1330 frame
->SetStatusText(buf
, 1);
1338 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1340 return Tex2RTFLastStatus
;
1347 //void wxObject::Dump(wxSTD ostream& str)
1349 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1350 // str << GetClassInfo()->GetClassName();
1352 // str << "unknown object class";