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"
43 #include "wx/cshelp.h"
44 #include "wx/helphtml.h"
46 #include "wx/msw/helpchm.h"
48 #include "wx/html/helpctrl.h"
67 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
68 #include "tex2rtf.xpm"
71 #if !WXWIN_COMPATIBILITY_2_4
72 static inline wxChar
* copystring(const wxChar
* s
)
73 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
76 const float versionNo
= float(TEX2RTF_VERSION_NUMBER
);
78 TexChunk
*currentMember
= NULL
;
79 bool startedSections
= false;
80 wxChar
*contentsString
= NULL
;
81 bool suppressNameDecoration
= false;
82 bool OkToClose
= true;
84 unsigned long errorCount
= 0;
88 extern wxChar
*BigBuffer
;
89 extern wxChar
*TexFileRoot
;
90 extern wxChar
*TexBibName
; // Bibliography output file name
91 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
92 extern wxList ColourTable
;
93 extern TexChunk
*TopLevel
;
96 wxHelpControllerBase
*HelpInstance
= NULL
;
100 static wxChar
*ipc_buffer
= NULL
;
101 static wxChar Tex2RTFLastStatus
[100];
102 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
107 wxChar
*bulletFile
= NULL
;
109 FILE *Contents
= NULL
; // Contents page
110 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
111 FILE *Sections
= NULL
;
112 FILE *Subsections
= NULL
;
113 FILE *Subsubsections
= NULL
;
115 FILE *WinHelpContentsFile
= NULL
;
117 wxChar
*InputFile
= NULL
;
118 wxChar
*OutputFile
= NULL
;
119 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
121 wxChar
*FileRoot
= NULL
;
122 wxChar
*ContentsName
= NULL
; // Contents page from last time around
123 wxChar
*TmpContentsName
= NULL
; // Current contents page
124 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
125 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
126 wxChar
*RefFileName
= NULL
; // Reference file name
128 wxChar
*RTFCharset
= copystring(_T("ansi"));
131 int BufSize
= 100; // Size of buffer in K
137 void ShowOptions(void);
139 wxChar wxTex2RTFBuffer
[1500];
142 IMPLEMENT_APP_CONSOLE(MyApp
)
144 wxMenuBar
*menuBar
= NULL
;
145 MyFrame
*frame
= NULL
;
146 // DECLARE_APP(MyApp)
150 // `Main program' equivalent, creating windows and returning main app frame
153 // Use default list of macros defined in tex2any.cc
154 DefineDefaultMacros();
155 AddMacroDef(ltHARDY
, _T("hardy"), 0);
157 FileRoot
= new wxChar
[300];
158 ContentsName
= new wxChar
[300];
159 TmpContentsName
= new wxChar
[300];
160 TmpFrameContentsName
= new wxChar
[300];
161 WinHelpContentsFileName
= new wxChar
[300];
162 RefFileName
= new wxChar
[300];
164 WX_CLEAR_LIST(wxList
,ColourTable
);
168 // Read input/output files
171 if (argv
[1][0] != '-')
178 if (argv
[2][0] != '-')
180 OutputFile
= argv
[2];
188 if (!InputFile
|| !OutputFile
)
190 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
198 TexPathList
.EnsureFileAccessible(InputFile
);
200 if (!InputFile
|| !OutputFile
)
201 isInteractive
= true;
204 for (i
= n
; i
< argc
;)
206 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
209 convertMode
= TEX_RTF
;
213 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
216 isInteractive
= true;
219 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
224 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
227 convertMode
= TEX_RTF
;
229 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
232 convertMode
= TEX_HTML
;
234 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
237 convertMode
= TEX_XLP
;
239 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
244 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
249 MacroFile
= copystring(argv
[i
]);
253 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
258 BufSize
= wxAtoi(argv
[i
]);
262 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
269 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
270 wxStrcmp(s
, _T("pca")) == 0)
271 RTFCharset
= copystring(s
);
274 OnError(_T("Incorrect argument for -charset"));
279 else if (wxStrcmp(argv
[i
], _T("-checkcurlybraces")) == 0)
282 checkCurlyBraces
= true;
284 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
286 // Support the old, incorrectly spelled version of -checkcurlybraces
287 // so that old scripts which run tex2rtf -checkcurleybraces still work.
289 checkCurlyBraces
= true;
291 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
299 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
300 OnError((wxChar
*)buf
.c_str());
310 #if defined(__WXMSW__) && !defined(NO_GUI)
312 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
313 TheTex2RTFServer
= new Tex2RTFServer
;
314 TheTex2RTFServer
->Create(_T("TEX2RTF"));
317 TexInitialize(BufSize
);
318 ResetContentsLevels(0);
326 // Create the main frame window
327 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
329 frame
->CreateStatusBar(2);
330 #endif // wxUSE_STATUSBAR
333 // TODO: uncomment this when we have tex2rtf.xpm
334 frame
->SetIcon(wxICON(tex2rtf
));
338 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
339 frame
->SetTitle(buf
);
343 wxMenu
*file_menu
= new wxMenu
;
344 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
345 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
346 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
347 file_menu
->AppendSeparator();
348 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
349 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
350 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
351 file_menu
->AppendSeparator();
352 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
354 wxMenu
*macro_menu
= new wxMenu
;
356 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
357 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
359 wxMenu
*mode_menu
= new wxMenu
;
361 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
362 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
363 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
364 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
366 wxMenu
*options_menu
= new wxMenu
;
368 options_menu
->Append(TEX_OPTIONS_CURLY_BRACE
, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true);
369 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
371 options_menu
->Check(TEX_OPTIONS_CURLY_BRACE
, checkCurlyBraces
);
372 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
374 wxMenu
*help_menu
= new wxMenu
;
376 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
377 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
379 menuBar
= new wxMenuBar
;
380 menuBar
->Append(file_menu
, _T("&File"));
381 menuBar
->Append(macro_menu
, _T("&Macros"));
382 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
383 menuBar
->Append(options_menu
, _T("&Options"));
384 menuBar
->Append(help_menu
, _T("&Help"));
386 frame
->SetMenuBar(menuBar
);
387 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
389 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
393 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
394 HelpInstance
= new wxCHMHelpController
;
396 HelpInstance
= new wxHtmlHelpController
;
398 HelpInstance
->Initialize(_T("tex2rtf"));
402 * Read macro/initialisation file
406 wxString path
= TexPathList
.FindValidPath(MacroFile
);
408 ReadCustomMacros((wxChar
*)path
.c_str());
411 wxStrcpy(buf
, _T("In "));
415 wxStrcat(buf
, (winHelp
) ? _T("WinHelp RTF") : _T("linear RTF"));
418 wxStrcat(buf
, _T("HTML"));
421 wxStrcat(buf
, _T("XLP"));
424 wxStrcat(buf
, _T("unknown"));
427 wxStrcat(buf
, _T(" mode."));
428 frame
->SetStatusText(buf
, 1);
429 #endif // wxUSE_STATUSBAR
438 * Read macro/initialisation file
442 wxString path
= TexPathList
.FindValidPath(MacroFile
);
444 ReadCustomMacros((wxChar
*)path
.c_str());
454 OnExit(); // Do cleanup since OnExit won't be called now
463 wxNode
*node
= CustomMacroList
.GetFirst();
466 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
469 node
= CustomMacroList
.GetFirst();
471 MacroDefs
.BeginFind();
472 wxHashTable::Node
* mNode
= MacroDefs
.Next();
475 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
477 mNode
= MacroDefs
.Next();
481 delete TheTex2RTFServer
;
496 delete currentArgData
;
497 currentArgData
= NULL
;
511 delete TexTmpBibName
;
512 TexTmpBibName
= NULL
;
526 delete TmpContentsName
;
527 TmpContentsName
= NULL
;
529 if (TmpFrameContentsName
)
531 delete TmpFrameContentsName
;
532 TmpFrameContentsName
= NULL
;
534 if (WinHelpContentsFileName
)
536 delete WinHelpContentsFileName
;
537 WinHelpContentsFileName
= NULL
;
561 delete [] BibliographyStyleString
;
562 delete [] DocumentStyleString
;
563 delete [] bitmapMethod
;
564 delete [] backgroundColourString
;
565 delete [] ContentsNameString
;
566 delete [] AbstractNameString
;
567 delete [] GlossaryNameString
;
568 delete [] ReferencesNameString
;
569 delete [] FiguresNameString
;
570 delete [] TablesNameString
;
571 delete [] FigureNameString
;
572 delete [] TableNameString
;
573 delete [] IndexNameString
;
574 delete [] ChapterNameString
;
575 delete [] SectionNameString
;
576 delete [] SubsectionNameString
;
577 delete [] SubsubsectionNameString
;
578 delete [] UpNameString
;
580 delete[] winHelpTitle
;
582 // TODO: this simulates zero-memory leaks!
583 // Otherwise there are just too many...
585 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
586 wxDebugContext::SetCheckpoint();
593 void ShowOptions(void)
596 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
598 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
599 OnInform(_T("where valid switches are"));
601 OnInform(_T(" -interactive"));
603 OnInform(_T(" -bufsize <size in K>"));
604 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
605 OnInform(_T(" -twice"));
606 OnInform(_T(" -sync"));
607 OnInform(_T(" -checkcurlybraces"));
608 OnInform(_T(" -checksyntax"));
609 OnInform(_T(" -macros <filename>"));
610 OnInform(_T(" -winhelp"));
611 OnInform(_T(" -rtf"));
612 OnInform(_T(" -html"));
613 OnInform(_T(" -xlp\n"));
618 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
619 EVT_CLOSE(MyFrame::OnCloseWindow
)
620 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
621 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
622 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
623 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
624 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
625 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
626 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
627 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
628 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
629 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
630 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
631 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
632 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
633 EVT_MENU(TEX_OPTIONS_CURLY_BRACE
, MyFrame::OnOptionsCurlyBrace
)
634 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
635 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
636 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
639 // My frame constructor
640 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
641 wxFrame(frame
, id
, title
, pos
, size
)
644 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
646 if (!stopRunning
&& !OkToClose
)
658 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
664 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
668 menuBar
->EnableTop(0, false);
669 menuBar
->EnableTop(1, false);
670 menuBar
->EnableTop(2, false);
671 menuBar
->EnableTop(3, false);
679 SetStatusText(_T("Build aborted!"));
680 #endif // wxUSE_STATUSBAR
682 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
683 OnInform((wxChar
*)errBuf
.c_str());
687 if (runTwice
&& !stopRunning
)
692 menuBar
->EnableTop(0, true);
693 menuBar
->EnableTop(1, true);
694 menuBar
->EnableTop(2, true);
695 menuBar
->EnableTop(3, true);
698 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
700 ChooseInputFile(true);
703 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
705 ChooseOutputFile(true);
708 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
710 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
713 textWindow
->SaveFile(s
);
716 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
717 frame
->SetStatusText(buf
, 0);
718 #endif // wxUSE_STATUSBAR
722 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
725 if (OutputFile
&& wxFileExists(OutputFile
))
727 textWindow
->LoadFile(OutputFile
);
729 wxString
str(wxFileNameFromPath(OutputFile
));
730 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
731 frame
->SetTitle(buf
);
735 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
738 if (InputFile
&& wxFileExists(InputFile
))
740 textWindow
->LoadFile(InputFile
);
742 wxString
str(wxFileNameFromPath(OutputFile
));
743 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
744 frame
->SetTitle(buf
);
748 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
751 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
752 if (!s
.empty() && wxFileExists(s
))
754 MacroFile
= copystring(s
);
755 ReadCustomMacros((wxChar
*)s
.c_str());
760 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
767 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
769 convertMode
= TEX_RTF
;
774 SetStatusText(_T("In linear RTF mode."), 1);
775 #endif // wxUSE_STATUSBAR
778 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
780 convertMode
= TEX_RTF
;
785 SetStatusText(_T("In WinHelp RTF mode."), 1);
786 #endif // wxUSE_STATUSBAR
789 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
791 convertMode
= TEX_HTML
;
796 SetStatusText(_T("In HTML mode."), 1);
797 #endif // wxUSE_STATUSBAR
800 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
802 convertMode
= TEX_XLP
;
806 SetStatusText(_T("In XLP mode."), 1);
807 #endif // wxUSE_STATUSBAR
810 void MyFrame::OnOptionsCurlyBrace(wxCommandEvent
& WXUNUSED(event
))
812 checkCurlyBraces
= !checkCurlyBraces
;
814 if (checkCurlyBraces
)
816 SetStatusText(_T("Checking curly braces: YES"), 1);
820 SetStatusText(_T("Checking curly braces: NO"), 1);
822 #endif // wxUSE_STATUSBAR
826 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
828 checkSyntax
= !checkSyntax
;
832 SetStatusText(_T("Checking syntax: YES"), 1);
836 SetStatusText(_T("Checking syntax: NO"), 1);
838 #endif // wxUSE_STATUSBAR
842 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
845 HelpInstance
->LoadFile();
846 HelpInstance
->DisplayContents();
850 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
854 wxChar
*platform
= _T(" (32-bit)");
857 wxChar
*platform
= _T(" (16-bit)");
859 wxChar
*platform
= _T("");
862 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
);
863 wxMessageBox(buf
, _T("About Tex2RTF"));
866 void ChooseInputFile(bool force
)
868 if (force
|| !InputFile
)
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);
879 InputFile
= copystring(s
);
880 wxString str
= wxFileNameFromPath(InputFile
);
882 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
883 frame
->SetTitle((wxChar
*)buf
.c_str());
889 void ChooseOutputFile(bool force
)
891 wxChar extensionBuf
[10];
893 wxStrcpy(wildBuf
, _T("*."));
896 path
= wxPathOnly(OutputFile
);
898 path
= wxPathOnly(InputFile
);
904 wxStrcpy(extensionBuf
, _T("rtf"));
905 wxStrcat(wildBuf
, _T("rtf"));
910 wxStrcpy(extensionBuf
, _T("xlp"));
911 wxStrcat(wildBuf
, _T("xlp"));
916 wxStrcpy(extensionBuf
, _T("html"));
917 wxStrcat(wildBuf
, _T("html"));
921 if (force
|| !OutputFile
)
923 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
924 extensionBuf
, wildBuf
);
926 OutputFile
= copystring(s
);
938 if (!InputFile
|| !OutputFile
|| stopRunning
)
945 wxString str
= wxFileNameFromPath(InputFile
);
947 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
948 frame
->SetTitle(buf
);
954 // Find extension-less filename
955 wxStrcpy(FileRoot
, OutputFile
);
956 StripExtension(FileRoot
);
958 if (truncateFilenames
&& convertMode
== TEX_HTML
)
960 // Truncate to five characters. This ensures that
961 // we can generate DOS filenames such as thing999. But 1000 files
962 // may not be enough, of course...
963 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
966 if(wxStrlen( sName
) > 5)
967 sName
[5] = '\0'; // that should do!
970 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
971 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
972 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
973 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
974 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
976 TexPathList
.EnsureFileAccessible(InputFile
);
979 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
982 wxString str
= wxFileNameFromPath(s
);
983 bulletFile
= copystring(str
);
987 if (wxFileExists(RefFileName
))
988 ReadTexReferences(RefFileName
);
990 bool success
= false;
992 if (InputFile
&& OutputFile
)
994 if (!wxFileExists(InputFile
))
996 OnError(_T("Cannot open input file!"));
1000 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1004 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
1005 frame
->SetStatusText((wxChar
*)buf
.c_str());
1009 OnInform(_T("Reading LaTeX file..."));
1010 TexLoadFile(InputFile
);
1018 switch (convertMode
)
1039 OnInform(_T("*** Aborted by user."));
1041 stopRunning
= false;
1047 WriteTexReferences(RefFileName
);
1049 startedSections
= false;
1053 long tim
= wxGetElapsedTime();
1054 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1055 OnInform((wxChar
*)buf
.c_str());
1059 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1060 OnInform((wxChar
*)buf
.c_str());
1066 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1067 frame
->SetStatusText((wxChar
*)buf
.c_str());
1069 #endif // wxUSE_STATUSBAR
1071 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1072 OnInform((wxChar
*)buf
.c_str());
1075 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1076 OnInform((wxChar
*)buf
.c_str());
1086 startedSections
= false;
1088 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1089 frame
->SetStatusText(_T("Aborted by user."));
1092 OnInform(_T("Sorry, unsuccessful."));
1097 void OnError(const wxChar
*msg
)
1099 wxString msg_string
= msg
;
1103 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1106 if (isInteractive
&& frame
)
1108 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1112 #if defined(__UNIX__)
1113 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1115 #elif defined(__WXMSW__)
1124 void OnInform(const wxChar
*msg
)
1126 wxString msg_string
= msg
;
1128 wxSTD cout
<< msg_string
.mb_str() << "\n";
1131 if (isInteractive
&& frame
)
1133 (*frame
->textWindow
) << msg
<< _T("\n");
1137 #if defined(__UNIX__)
1138 wxSTD cout
<< msg_string
.mb_str() << "\n";
1140 #elif defined(__WXMSW__)
1152 void OnMacro(int macroId
, int no_args
, bool start
)
1154 switch (convertMode
)
1158 RTFOnMacro(macroId
, no_args
, start
);
1163 XLPOnMacro(macroId
, no_args
, start
);
1168 HTMLOnMacro(macroId
, no_args
, start
);
1174 bool OnArgument(int macroId
, int arg_no
, bool start
)
1176 switch (convertMode
)
1180 return RTFOnArgument(macroId
, arg_no
, start
);
1185 return XLPOnArgument(macroId
, arg_no
, start
);
1190 return HTMLOnArgument(macroId
, arg_no
, start
);
1200 #if defined(__WXMSW__) && !defined(NO_GUI)
1206 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1208 if (topic
== _T("TEX2RTF"))
1211 ipc_buffer
= new wxChar
[1000];
1213 return new Tex2RTFConnection(ipc_buffer
, 4000);
1223 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1227 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1233 // Find first argument (command name)
1236 if (data
[i
] == ' ' || data
[i
] == 0)
1240 firstArg
[i
] = data
[i
];
1247 // Find second argument
1250 while (data
[i
] != 0)
1252 secondArg
[j
] = data
[i
];
1261 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1263 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1265 wxChar firstArg
[50];
1266 wxChar secondArg
[300];
1267 if (SplitCommand(data
, firstArg
, secondArg
))
1269 bool hasArg
= (wxStrlen(secondArg
) > 0);
1270 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1272 if (InputFile
) delete[] InputFile
;
1273 InputFile
= copystring(secondArg
);
1277 wxString str
= wxFileNameFromPath(InputFile
);
1278 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1279 frame
->SetTitle(buf
);
1282 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1284 if (OutputFile
) delete[] OutputFile
;
1285 OutputFile
= copystring(secondArg
);
1287 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1289 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1291 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1293 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1295 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1297 if (frame
) frame
->Close();
1299 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1302 frame
->Iconize(true);
1304 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1308 frame
->Iconize(false);
1314 // Try for a setting
1315 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1316 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1317 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1320 wxStrcpy(buf
, _T("In "));
1322 if (winHelp
&& (convertMode
== TEX_RTF
))
1323 wxStrcat(buf
, _T("WinHelp RTF"));
1324 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1325 wxStrcat(buf
, _T("linear RTF"));
1326 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1327 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1328 wxStrcat(buf
, _T(" mode."));
1329 frame
->SetStatusText(buf
, 1);
1337 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1339 return Tex2RTFLastStatus
;
1346 //void wxObject::Dump(wxSTD ostream& str)
1348 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1349 // str << GetClassInfo()->GetClassName();
1351 // str << "unknown object class";