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 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
20 #if defined(__WXMSW__)
21 #include "wx/msw/wrapwin.h"
27 #include "wx/textctrl.h"
28 #include "wx/filedlg.h"
29 #include "wx/msgdlg.h"
39 #include "wx/cshelp.h"
40 #include "wx/helphtml.h"
42 #include "wx/msw/helpchm.h"
44 #include "wx/html/helpctrl.h"
65 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__) || defined(__WXMGL__)) && !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
;
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] != _T('-'))
176 if (argv
[2][0] != _T('-'))
178 OutputFile
= argv
[2];
186 if (InputFile
.empty() || OutputFile
.empty())
188 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
194 if (!InputFile
.empty())
196 TexPathList
.EnsureFileAccessible(InputFile
);
198 if (InputFile
.empty() || OutputFile
.empty())
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);
322 // Create the main frame window
323 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
325 frame
->CreateStatusBar(2);
326 #endif // wxUSE_STATUSBAR
329 // TODO: uncomment this when we have tex2rtf.xpm
330 frame
->SetIcon(wxICON(tex2rtf
));
332 if (!InputFile
.empty())
335 title
.Printf( _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
).c_str());
336 frame
->SetTitle(title
);
340 wxMenu
*file_menu
= new wxMenu
;
341 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
342 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
343 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
344 file_menu
->AppendSeparator();
345 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
346 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
347 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
348 file_menu
->AppendSeparator();
349 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
351 wxMenu
*macro_menu
= new wxMenu
;
353 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
354 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
356 wxMenu
*mode_menu
= new wxMenu
;
358 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
359 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
360 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
361 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
363 wxMenu
*options_menu
= new wxMenu
;
365 options_menu
->Append(TEX_OPTIONS_CURLY_BRACE
, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true);
366 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
368 options_menu
->Check(TEX_OPTIONS_CURLY_BRACE
, checkCurlyBraces
);
369 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
371 wxMenu
*help_menu
= new wxMenu
;
373 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
374 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
376 menuBar
= new wxMenuBar
;
377 menuBar
->Append(file_menu
, _T("&File"));
378 menuBar
->Append(macro_menu
, _T("&Macros"));
379 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
380 menuBar
->Append(options_menu
, _T("&Options"));
381 menuBar
->Append(help_menu
, _T("&Help"));
383 frame
->SetMenuBar(menuBar
);
384 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
386 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
390 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
391 HelpInstance
= new wxCHMHelpController
;
393 HelpInstance
= new wxHelpController
;
395 HelpInstance
->Initialize(_T("tex2rtf"));
399 * Read macro/initialisation file
403 wxString path
= TexPathList
.FindValidPath(MacroFile
);
405 ReadCustomMacros(path
);
408 wxString
inStr(_T("In "));
413 inStr
+= _T("WinHelp RTF");
415 inStr
+= _T("linear RTF");
427 inStr
+= _T("unknown");
430 inStr
+= _T(" mode.");
431 frame
->SetStatusText(inStr
, 1);
432 #endif // wxUSE_STATUSBAR
441 * Read macro/initialisation file
445 wxString path
= TexPathList
.FindValidPath(MacroFile
);
447 ReadCustomMacros(path
);
457 OnExit(); // Do cleanup since OnExit won't be called now
466 wxNode
*node
= CustomMacroList
.GetFirst();
469 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
472 node
= CustomMacroList
.GetFirst();
474 MacroDefs
.BeginFind();
475 wxHashTable::Node
* mNode
= MacroDefs
.Next();
478 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
480 mNode
= MacroDefs
.Next();
484 delete TheTex2RTFServer
;
499 delete currentArgData
;
500 currentArgData
= NULL
;
514 delete TexTmpBibName
;
515 TexTmpBibName
= NULL
;
529 delete TmpContentsName
;
530 TmpContentsName
= NULL
;
532 if (TmpFrameContentsName
)
534 delete TmpFrameContentsName
;
535 TmpFrameContentsName
= NULL
;
537 if (WinHelpContentsFileName
)
539 delete WinHelpContentsFileName
;
540 WinHelpContentsFileName
= NULL
;
564 delete [] BibliographyStyleString
;
565 delete [] DocumentStyleString
;
566 delete [] bitmapMethod
;
567 delete [] backgroundColourString
;
568 delete [] ContentsNameString
;
569 delete [] AbstractNameString
;
570 delete [] GlossaryNameString
;
571 delete [] ReferencesNameString
;
572 delete [] FiguresNameString
;
573 delete [] TablesNameString
;
574 delete [] FigureNameString
;
575 delete [] TableNameString
;
576 delete [] IndexNameString
;
577 delete [] ChapterNameString
;
578 delete [] SectionNameString
;
579 delete [] SubsectionNameString
;
580 delete [] SubsubsectionNameString
;
581 delete [] UpNameString
;
583 delete[] winHelpTitle
;
585 // TODO: this simulates zero-memory leaks!
586 // Otherwise there are just too many...
588 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
589 wxDebugContext::SetCheckpoint();
596 void ShowOptions(void)
599 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
601 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
602 OnInform(_T("where valid switches are"));
604 OnInform(_T(" -interactive"));
606 OnInform(_T(" -bufsize <size in K>"));
607 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
608 OnInform(_T(" -twice"));
609 OnInform(_T(" -sync"));
610 OnInform(_T(" -checkcurlybraces"));
611 OnInform(_T(" -checksyntax"));
612 OnInform(_T(" -macros <filename>"));
613 OnInform(_T(" -winhelp"));
614 OnInform(_T(" -rtf"));
615 OnInform(_T(" -html"));
616 OnInform(_T(" -xlp\n"));
621 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
622 EVT_CLOSE(MyFrame::OnCloseWindow
)
623 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
624 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
625 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
626 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
627 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
628 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
629 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
630 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
631 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
632 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
633 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
634 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
635 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
636 EVT_MENU(TEX_OPTIONS_CURLY_BRACE
, MyFrame::OnOptionsCurlyBrace
)
637 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
638 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
639 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
642 // My frame constructor
643 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
644 wxFrame(frame
, id
, title
, pos
, size
)
647 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
649 if (!stopRunning
&& !OkToClose
)
661 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
667 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
671 menuBar
->EnableTop(0, false);
672 menuBar
->EnableTop(1, false);
673 menuBar
->EnableTop(2, false);
674 menuBar
->EnableTop(3, false);
682 SetStatusText(_T("Build aborted!"));
683 #endif // wxUSE_STATUSBAR
685 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
686 OnInform((wxChar
*)errBuf
.c_str());
690 if (runTwice
&& !stopRunning
)
695 menuBar
->EnableTop(0, true);
696 menuBar
->EnableTop(1, true);
697 menuBar
->EnableTop(2, true);
698 menuBar
->EnableTop(3, true);
701 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
703 ChooseInputFile(true);
706 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
708 ChooseOutputFile(true);
711 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
714 wxString s
= wxFileSelector(_T("Save text to file"), wxEmptyString
, wxEmptyString
, _T("txt"), _T("*.txt"));
717 textWindow
->SaveFile(s
);
720 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
721 frame
->SetStatusText(buf
, 0);
722 #endif // wxUSE_STATUSBAR
724 #endif // wxUSE_FILEDLG
727 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
730 if (!OutputFile
.empty() && wxFileExists(OutputFile
))
732 textWindow
->LoadFile(OutputFile
);
734 wxString
str(wxFileNameFromPath(OutputFile
));
735 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
736 frame
->SetTitle(buf
);
740 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
743 if (!InputFile
.empty() && wxFileExists(InputFile
))
745 textWindow
->LoadFile(InputFile
);
747 wxString
str(wxFileNameFromPath(OutputFile
));
748 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
749 frame
->SetTitle(buf
);
753 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
757 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
758 if (!s
.empty() && wxFileExists(s
))
760 MacroFile
= copystring(s
);
764 #endif // wxUSE_FILEDLG
767 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
774 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
776 convertMode
= TEX_RTF
;
778 InputFile
= wxEmptyString
;
779 OutputFile
= wxEmptyString
;
781 SetStatusText(_T("In linear RTF mode."), 1);
782 #endif // wxUSE_STATUSBAR
785 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
787 convertMode
= TEX_RTF
;
789 InputFile
= wxEmptyString
;
790 OutputFile
= wxEmptyString
;
792 SetStatusText(_T("In WinHelp RTF mode."), 1);
793 #endif // wxUSE_STATUSBAR
796 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
798 convertMode
= TEX_HTML
;
800 InputFile
= wxEmptyString
;
801 OutputFile
= wxEmptyString
;
803 SetStatusText(_T("In HTML mode."), 1);
804 #endif // wxUSE_STATUSBAR
807 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
809 convertMode
= TEX_XLP
;
810 InputFile
= wxEmptyString
;
811 OutputFile
= wxEmptyString
;
813 SetStatusText(_T("In XLP mode."), 1);
814 #endif // wxUSE_STATUSBAR
817 void MyFrame::OnOptionsCurlyBrace(wxCommandEvent
& WXUNUSED(event
))
819 checkCurlyBraces
= !checkCurlyBraces
;
821 if (checkCurlyBraces
)
823 SetStatusText(_T("Checking curly braces: YES"), 1);
827 SetStatusText(_T("Checking curly braces: NO"), 1);
829 #endif // wxUSE_STATUSBAR
833 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
835 checkSyntax
= !checkSyntax
;
839 SetStatusText(_T("Checking syntax: YES"), 1);
843 SetStatusText(_T("Checking syntax: NO"), 1);
845 #endif // wxUSE_STATUSBAR
849 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
852 HelpInstance
->LoadFile();
853 HelpInstance
->DisplayContents();
857 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
860 wxString platform
= wxGetOsDescription();
861 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-2005"), versionNo
, platform
.c_str());
862 wxMessageBox(buf
, _T("About Tex2RTF"));
865 void ChooseInputFile(bool force
)
868 if (force
|| InputFile
.empty())
870 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
873 // Different file, so clear index entries.
875 ResetContentsLevels(0);
880 wxString str
= wxFileNameFromPath(InputFile
);
882 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
883 frame
->SetTitle((wxChar
*)buf
.c_str());
884 OutputFile
= wxEmptyString
;
889 #endif // wxUSE_FILEDLG
892 void ChooseOutputFile(bool force
)
894 wxChar extensionBuf
[10];
896 wxStrcpy(wildBuf
, _T("*."));
898 if (!OutputFile
.empty())
899 path
= wxPathOnly(OutputFile
);
900 else if (!InputFile
.empty())
901 path
= wxPathOnly(InputFile
);
907 wxStrcpy(extensionBuf
, _T("rtf"));
908 wxStrcat(wildBuf
, _T("rtf"));
913 wxStrcpy(extensionBuf
, _T("xlp"));
914 wxStrcat(wildBuf
, _T("xlp"));
919 wxStrcpy(extensionBuf
, _T("html"));
920 wxStrcat(wildBuf
, _T("html"));
925 if (force
|| OutputFile
.empty())
927 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
928 extensionBuf
, wildBuf
);
934 #endif // wxUSE_FILEDLG
945 if (InputFile
.empty() || OutputFile
.empty() || stopRunning
)
952 wxString str
= wxFileNameFromPath(InputFile
);
954 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
955 frame
->SetTitle(buf
);
958 wxLongLong localTime
= wxGetLocalTimeMillis();
961 // Find extension-less filename
962 wxStrcpy(FileRoot
, OutputFile
.c_str());
963 StripExtension(FileRoot
);
965 if (truncateFilenames
&& convertMode
== TEX_HTML
)
967 // Truncate to five characters. This ensures that
968 // we can generate DOS filenames such as thing999. But 1000 files
969 // may not be enough, of course...
970 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
973 if(wxStrlen( sName
) > 5)
974 sName
[5] = '\0'; // that should do!
977 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
978 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
979 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
980 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
981 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
983 TexPathList
.EnsureFileAccessible(InputFile
);
986 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
989 wxString str
= wxFileNameFromPath(s
);
990 bulletFile
= copystring(str
);
994 if (wxFileExists(RefFileName
))
995 ReadTexReferences(RefFileName
);
997 bool success
= false;
999 if (!InputFile
.empty() && !OutputFile
.empty())
1001 if (!wxFileExists(InputFile
))
1003 OnError(_T("Cannot open input file!"));
1007 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1011 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
1012 frame
->SetStatusText((wxChar
*)buf
.c_str());
1016 OnInform(_T("Reading LaTeX file..."));
1017 TexLoadFile(InputFile
);
1025 switch (convertMode
)
1046 OnInform(_T("*** Aborted by user."));
1048 stopRunning
= false;
1054 WriteTexReferences(RefFileName
);
1056 startedSections
= false;
1060 wxLongLong elapsed
= wxGetLocalTimeMillis() - localTime
;
1061 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(elapsed
.GetLo()/1000.0));
1062 OnInform((wxChar
*)buf
.c_str());
1066 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1067 OnInform((wxChar
*)buf
.c_str());
1073 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1074 frame
->SetStatusText((wxChar
*)buf
.c_str());
1076 #endif // wxUSE_STATUSBAR
1078 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1079 OnInform((wxChar
*)buf
.c_str());
1082 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1083 OnInform((wxChar
*)buf
.c_str());
1093 startedSections
= false;
1095 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1096 frame
->SetStatusText(_T("Aborted by user."));
1099 OnInform(_T("Sorry, unsuccessful."));
1104 void OnError(const wxChar
*msg
)
1106 wxString msg_string
= msg
;
1110 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1113 if (isInteractive
&& frame
)
1115 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1119 #if defined(__UNIX__)
1120 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1122 #elif defined(__WXMSW__)
1131 void OnInform(const wxChar
*msg
)
1133 wxString msg_string
= msg
;
1135 wxSTD cout
<< msg_string
.mb_str() << "\n";
1138 if (isInteractive
&& frame
)
1140 (*frame
->textWindow
) << msg
<< _T("\n");
1144 #if defined(__UNIX__)
1145 wxSTD cout
<< msg_string
.mb_str() << "\n";
1147 #elif defined(__WXMSW__)
1159 void OnMacro(int macroId
, int no_args
, bool start
)
1161 switch (convertMode
)
1165 RTFOnMacro(macroId
, no_args
, start
);
1170 XLPOnMacro(macroId
, no_args
, start
);
1175 HTMLOnMacro(macroId
, no_args
, start
);
1181 bool OnArgument(int macroId
, int arg_no
, bool start
)
1183 switch (convertMode
)
1187 return RTFOnArgument(macroId
, arg_no
, start
);
1192 return XLPOnArgument(macroId
, arg_no
, start
);
1197 return HTMLOnArgument(macroId
, arg_no
, start
);
1207 #if defined(__WXMSW__) && !defined(NO_GUI)
1213 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1215 if (topic
== _T("TEX2RTF"))
1218 ipc_buffer
= new wxChar
[1000];
1220 return new Tex2RTFConnection(ipc_buffer
, 4000);
1230 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1234 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1240 // Find first argument (command name)
1243 if (data
[i
] == ' ' || data
[i
] == 0)
1247 firstArg
[i
] = data
[i
];
1254 // Find second argument
1257 while (data
[i
] != 0)
1259 secondArg
[j
] = data
[i
];
1268 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1270 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1272 wxChar firstArg
[50];
1273 wxChar secondArg
[300];
1274 if (SplitCommand(data
, firstArg
, secondArg
))
1276 bool hasArg
= (wxStrlen(secondArg
) > 0);
1277 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1279 InputFile
= secondArg
;
1283 wxString str
= wxFileNameFromPath(InputFile
);
1284 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1285 frame
->SetTitle(buf
);
1288 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1290 OutputFile
= secondArg
;
1292 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1294 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1296 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1298 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1300 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1302 if (frame
) frame
->Close();
1304 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1307 frame
->Iconize(true);
1309 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1313 frame
->Iconize(false);
1319 // Try for a setting
1320 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1321 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1322 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1325 wxStrcpy(buf
, _T("In "));
1327 if (winHelp
&& (convertMode
== TEX_RTF
))
1328 wxStrcat(buf
, _T("WinHelp RTF"));
1329 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1330 wxStrcat(buf
, _T("linear RTF"));
1331 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1332 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1333 wxStrcat(buf
, _T(" mode."));
1334 frame
->SetStatusText(buf
, 1);
1342 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1344 return Tex2RTFLastStatus
;
1351 //void wxObject::Dump(wxSTD ostream& str)
1353 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1354 // str << GetClassInfo()->GetClassName();
1356 // str << "unknown object class";