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"
36 #include "wx/cshelp.h"
37 #include "wx/helphtml.h"
39 #include "wx/msw/helpchm.h"
41 #include "wx/html/helpctrl.h"
60 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
61 #include "tex2rtf.xpm"
64 #if !WXWIN_COMPATIBILITY_2_4
65 static inline wxChar
* copystring(const wxChar
* s
)
66 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
69 const float versionNo
= (float)TEX2RTF_VERSION_NUMBER
;
71 TexChunk
*currentMember
= NULL
;
72 bool startedSections
= false;
73 wxChar
*contentsString
= NULL
;
74 bool suppressNameDecoration
= false;
75 bool OkToClose
= true;
77 unsigned long errorCount
= 0;
81 extern wxChar
*BigBuffer
;
82 extern wxChar
*TexFileRoot
;
83 extern wxChar
*TexBibName
; // Bibliography output file name
84 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
85 extern wxList ColourTable
;
86 extern TexChunk
*TopLevel
;
89 wxHelpControllerBase
*HelpInstance
= NULL
;
93 static wxChar
*ipc_buffer
= NULL
;
94 static wxChar Tex2RTFLastStatus
[100];
95 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
100 wxChar
*bulletFile
= NULL
;
102 FILE *Contents
= NULL
; // Contents page
103 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
104 FILE *Sections
= NULL
;
105 FILE *Subsections
= NULL
;
106 FILE *Subsubsections
= NULL
;
108 FILE *WinHelpContentsFile
= NULL
;
110 wxChar
*InputFile
= NULL
;
111 wxChar
*OutputFile
= NULL
;
112 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
114 wxChar
*FileRoot
= NULL
;
115 wxChar
*ContentsName
= NULL
; // Contents page from last time around
116 wxChar
*TmpContentsName
= NULL
; // Current contents page
117 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
118 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
119 wxChar
*RefFileName
= NULL
; // Reference file name
121 wxChar
*RTFCharset
= copystring(_T("ansi"));
124 int BufSize
= 100; // Size of buffer in K
130 void ShowOptions(void);
132 wxChar wxTex2RTFBuffer
[1500];
135 IMPLEMENT_APP_CONSOLE(MyApp
)
137 wxMenuBar
*menuBar
= NULL
;
138 MyFrame
*frame
= NULL
;
139 // DECLARE_APP(MyApp)
143 // `Main program' equivalent, creating windows and returning main app frame
146 // Use default list of macros defined in tex2any.cc
147 DefineDefaultMacros();
148 AddMacroDef(ltHARDY
, _T("hardy"), 0);
150 FileRoot
= new wxChar
[300];
151 ContentsName
= new wxChar
[300];
152 TmpContentsName
= new wxChar
[300];
153 TmpFrameContentsName
= new wxChar
[300];
154 WinHelpContentsFileName
= new wxChar
[300];
155 RefFileName
= new wxChar
[300];
157 WX_CLEAR_LIST(wxList
,ColourTable
);
161 // Read input/output files
164 if (argv
[1][0] != '-')
171 if (argv
[2][0] != '-')
173 OutputFile
= argv
[2];
181 if (!InputFile
|| !OutputFile
)
183 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
191 TexPathList
.EnsureFileAccessible(InputFile
);
193 if (!InputFile
|| !OutputFile
)
194 isInteractive
= true;
197 for (i
= n
; i
< argc
;)
199 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
202 convertMode
= TEX_RTF
;
206 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
209 isInteractive
= true;
212 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
217 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
220 convertMode
= TEX_RTF
;
222 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
225 convertMode
= TEX_HTML
;
227 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
230 convertMode
= TEX_XLP
;
232 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
237 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
242 MacroFile
= copystring(argv
[i
]);
246 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
251 BufSize
= wxAtoi(argv
[i
]);
255 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
262 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
263 wxStrcmp(s
, _T("pca")) == 0)
264 RTFCharset
= copystring(s
);
267 OnError(_T("Incorrect argument for -charset"));
272 else if (wxStrcmp(argv
[i
], _T("-checkcurlybraces")) == 0)
275 checkCurlyBraces
= true;
277 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
279 // Support the old, incorrectly spelled version of -checkcurlybraces
280 // so that old scripts which run tex2rtf -checkcurleybraces still work.
282 checkCurlyBraces
= true;
284 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
292 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
293 OnError((wxChar
*)buf
.c_str());
303 #if defined(__WXMSW__) && !defined(NO_GUI)
305 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
306 TheTex2RTFServer
= new Tex2RTFServer
;
307 TheTex2RTFServer
->Create(_T("TEX2RTF"));
310 TexInitialize(BufSize
);
311 ResetContentsLevels(0);
319 // Create the main frame window
320 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
322 frame
->CreateStatusBar(2);
323 #endif // wxUSE_STATUSBAR
326 // TODO: uncomment this when we have tex2rtf.xpm
327 frame
->SetIcon(wxICON(tex2rtf
));
331 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
332 frame
->SetTitle(buf
);
336 wxMenu
*file_menu
= new wxMenu
;
337 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
338 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
339 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
340 file_menu
->AppendSeparator();
341 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
342 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
343 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
344 file_menu
->AppendSeparator();
345 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
347 wxMenu
*macro_menu
= new wxMenu
;
349 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
350 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
352 wxMenu
*mode_menu
= new wxMenu
;
354 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
355 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
356 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
357 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
359 wxMenu
*options_menu
= new wxMenu
;
361 options_menu
->Append(TEX_OPTIONS_CURLY_BRACE
, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true);
362 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
364 options_menu
->Check(TEX_OPTIONS_CURLY_BRACE
, checkCurlyBraces
);
365 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
367 wxMenu
*help_menu
= new wxMenu
;
369 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
370 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
372 menuBar
= new wxMenuBar
;
373 menuBar
->Append(file_menu
, _T("&File"));
374 menuBar
->Append(macro_menu
, _T("&Macros"));
375 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
376 menuBar
->Append(options_menu
, _T("&Options"));
377 menuBar
->Append(help_menu
, _T("&Help"));
379 frame
->SetMenuBar(menuBar
);
380 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
382 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
386 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
387 HelpInstance
= new wxCHMHelpController
;
389 HelpInstance
= new wxHtmlHelpController
;
391 HelpInstance
->Initialize(_T("tex2rtf"));
395 * Read macro/initialisation file
399 wxString path
= TexPathList
.FindValidPath(MacroFile
);
401 ReadCustomMacros((wxChar
*)path
.c_str());
404 wxStrcpy(buf
, _T("In "));
408 wxStrcat(buf
, (winHelp
) ? _T("WinHelp RTF") : _T("linear RTF"));
411 wxStrcat(buf
, _T("HTML"));
414 wxStrcat(buf
, _T("XLP"));
417 wxStrcat(buf
, _T("unknown"));
420 wxStrcat(buf
, _T(" mode."));
421 frame
->SetStatusText(buf
, 1);
422 #endif // wxUSE_STATUSBAR
431 * Read macro/initialisation file
435 wxString path
= TexPathList
.FindValidPath(MacroFile
);
437 ReadCustomMacros((wxChar
*)path
.c_str());
447 OnExit(); // Do cleanup since OnExit won't be called now
456 wxNode
*node
= CustomMacroList
.GetFirst();
459 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
462 node
= CustomMacroList
.GetFirst();
464 MacroDefs
.BeginFind();
465 wxHashTable::Node
* mNode
= MacroDefs
.Next();
468 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
470 mNode
= MacroDefs
.Next();
474 delete TheTex2RTFServer
;
489 delete currentArgData
;
490 currentArgData
= NULL
;
504 delete TexTmpBibName
;
505 TexTmpBibName
= NULL
;
519 delete TmpContentsName
;
520 TmpContentsName
= NULL
;
522 if (TmpFrameContentsName
)
524 delete TmpFrameContentsName
;
525 TmpFrameContentsName
= NULL
;
527 if (WinHelpContentsFileName
)
529 delete WinHelpContentsFileName
;
530 WinHelpContentsFileName
= NULL
;
554 delete [] BibliographyStyleString
;
555 delete [] DocumentStyleString
;
556 delete [] bitmapMethod
;
557 delete [] backgroundColourString
;
558 delete [] ContentsNameString
;
559 delete [] AbstractNameString
;
560 delete [] GlossaryNameString
;
561 delete [] ReferencesNameString
;
562 delete [] FiguresNameString
;
563 delete [] TablesNameString
;
564 delete [] FigureNameString
;
565 delete [] TableNameString
;
566 delete [] IndexNameString
;
567 delete [] ChapterNameString
;
568 delete [] SectionNameString
;
569 delete [] SubsectionNameString
;
570 delete [] SubsubsectionNameString
;
571 delete [] UpNameString
;
573 delete[] winHelpTitle
;
575 // TODO: this simulates zero-memory leaks!
576 // Otherwise there are just too many...
578 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
579 wxDebugContext::SetCheckpoint();
586 void ShowOptions(void)
589 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
591 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
592 OnInform(_T("where valid switches are"));
594 OnInform(_T(" -interactive"));
596 OnInform(_T(" -bufsize <size in K>"));
597 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
598 OnInform(_T(" -twice"));
599 OnInform(_T(" -sync"));
600 OnInform(_T(" -checkcurlybraces"));
601 OnInform(_T(" -checksyntax"));
602 OnInform(_T(" -macros <filename>"));
603 OnInform(_T(" -winhelp"));
604 OnInform(_T(" -rtf"));
605 OnInform(_T(" -html"));
606 OnInform(_T(" -xlp\n"));
611 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
612 EVT_CLOSE(MyFrame::OnCloseWindow
)
613 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
614 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
615 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
616 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
617 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
618 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
619 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
620 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
621 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
622 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
623 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
624 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
625 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
626 EVT_MENU(TEX_OPTIONS_CURLY_BRACE
, MyFrame::OnOptionsCurlyBrace
)
627 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
628 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
629 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
632 // My frame constructor
633 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
634 wxFrame(frame
, id
, title
, pos
, size
)
637 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
639 if (!stopRunning
&& !OkToClose
)
651 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
657 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
661 menuBar
->EnableTop(0, false);
662 menuBar
->EnableTop(1, false);
663 menuBar
->EnableTop(2, false);
664 menuBar
->EnableTop(3, false);
672 SetStatusText(_T("Build aborted!"));
673 #endif // wxUSE_STATUSBAR
675 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
676 OnInform((wxChar
*)errBuf
.c_str());
680 if (runTwice
&& !stopRunning
)
685 menuBar
->EnableTop(0, true);
686 menuBar
->EnableTop(1, true);
687 menuBar
->EnableTop(2, true);
688 menuBar
->EnableTop(3, true);
691 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
693 ChooseInputFile(true);
696 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
698 ChooseOutputFile(true);
701 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
703 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
706 textWindow
->SaveFile(s
);
709 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
710 frame
->SetStatusText(buf
, 0);
711 #endif // wxUSE_STATUSBAR
715 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
718 if (OutputFile
&& wxFileExists(OutputFile
))
720 textWindow
->LoadFile(OutputFile
);
722 wxString
str(wxFileNameFromPath(OutputFile
));
723 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
724 frame
->SetTitle(buf
);
728 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
731 if (InputFile
&& wxFileExists(InputFile
))
733 textWindow
->LoadFile(InputFile
);
735 wxString
str(wxFileNameFromPath(OutputFile
));
736 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
737 frame
->SetTitle(buf
);
741 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
744 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
745 if (s
!= _T("") && wxFileExists(s
))
747 MacroFile
= copystring(s
);
748 ReadCustomMacros((wxChar
*)s
.c_str());
753 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
760 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
762 convertMode
= TEX_RTF
;
767 SetStatusText(_T("In linear RTF mode."), 1);
768 #endif // wxUSE_STATUSBAR
771 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
773 convertMode
= TEX_RTF
;
778 SetStatusText(_T("In WinHelp RTF mode."), 1);
779 #endif // wxUSE_STATUSBAR
782 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
784 convertMode
= TEX_HTML
;
789 SetStatusText(_T("In HTML mode."), 1);
790 #endif // wxUSE_STATUSBAR
793 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
795 convertMode
= TEX_XLP
;
799 SetStatusText(_T("In XLP mode."), 1);
800 #endif // wxUSE_STATUSBAR
803 void MyFrame::OnOptionsCurlyBrace(wxCommandEvent
& WXUNUSED(event
))
805 checkCurlyBraces
= !checkCurlyBraces
;
807 if (checkCurlyBraces
)
809 SetStatusText(_T("Checking curly braces: YES"), 1);
813 SetStatusText(_T("Checking curly braces: NO"), 1);
815 #endif // wxUSE_STATUSBAR
819 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
821 checkSyntax
= !checkSyntax
;
825 SetStatusText(_T("Checking syntax: YES"), 1);
829 SetStatusText(_T("Checking syntax: NO"), 1);
831 #endif // wxUSE_STATUSBAR
835 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
838 HelpInstance
->LoadFile();
839 HelpInstance
->DisplayContents();
843 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
847 wxChar
*platform
= _T(" (32-bit)");
850 wxChar
*platform
= _T(" (16-bit)");
852 wxChar
*platform
= _T("");
855 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
);
856 wxMessageBox(buf
, _T("About Tex2RTF"));
859 void ChooseInputFile(bool force
)
861 if (force
|| !InputFile
)
863 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
866 // Different file, so clear index entries.
868 ResetContentsLevels(0);
872 InputFile
= copystring(s
);
873 wxString str
= wxFileNameFromPath(InputFile
);
875 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
876 frame
->SetTitle((wxChar
*)buf
.c_str());
882 void ChooseOutputFile(bool force
)
884 wxChar extensionBuf
[10];
886 wxStrcpy(wildBuf
, _T("*."));
889 path
= wxPathOnly(OutputFile
);
891 path
= wxPathOnly(InputFile
);
897 wxStrcpy(extensionBuf
, _T("rtf"));
898 wxStrcat(wildBuf
, _T("rtf"));
903 wxStrcpy(extensionBuf
, _T("xlp"));
904 wxStrcat(wildBuf
, _T("xlp"));
909 wxStrcpy(extensionBuf
, _T("html"));
910 wxStrcat(wildBuf
, _T("html"));
914 if (force
|| !OutputFile
)
916 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
917 extensionBuf
, wildBuf
);
919 OutputFile
= copystring(s
);
931 if (!InputFile
|| !OutputFile
|| stopRunning
)
938 wxString str
= wxFileNameFromPath(InputFile
);
940 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
941 frame
->SetTitle(buf
);
947 // Find extension-less filename
948 wxStrcpy(FileRoot
, OutputFile
);
949 StripExtension(FileRoot
);
951 if (truncateFilenames
&& convertMode
== TEX_HTML
)
953 // Truncate to five characters. This ensures that
954 // we can generate DOS filenames such as thing999. But 1000 files
955 // may not be enough, of course...
956 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
959 if(wxStrlen( sName
) > 5)
960 sName
[5] = '\0'; // that should do!
963 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
964 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
965 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
966 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
967 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
969 TexPathList
.EnsureFileAccessible(InputFile
);
972 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
975 wxString str
= wxFileNameFromPath(s
);
976 bulletFile
= copystring(str
);
980 if (wxFileExists(RefFileName
))
981 ReadTexReferences(RefFileName
);
983 bool success
= false;
985 if (InputFile
&& OutputFile
)
987 if (!wxFileExists(InputFile
))
989 OnError(_T("Cannot open input file!"));
993 #if !defined(NO_GUI) && wxUSE_STATUSBAR
997 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
998 frame
->SetStatusText((wxChar
*)buf
.c_str());
1002 OnInform(_T("Reading LaTeX file..."));
1003 TexLoadFile(InputFile
);
1011 switch (convertMode
)
1032 OnInform(_T("*** Aborted by user."));
1034 stopRunning
= false;
1040 WriteTexReferences(RefFileName
);
1042 startedSections
= false;
1046 long tim
= wxGetElapsedTime();
1047 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1048 OnInform((wxChar
*)buf
.c_str());
1052 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1053 OnInform((wxChar
*)buf
.c_str());
1059 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1060 frame
->SetStatusText((wxChar
*)buf
.c_str());
1062 #endif // wxUSE_STATUSBAR
1064 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1065 OnInform((wxChar
*)buf
.c_str());
1068 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1069 OnInform((wxChar
*)buf
.c_str());
1079 startedSections
= false;
1081 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1082 frame
->SetStatusText(_T("Aborted by user."));
1085 OnInform(_T("Sorry, unsuccessful."));
1090 void OnError(const wxChar
*msg
)
1092 wxString msg_string
= msg
;
1096 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1099 if (isInteractive
&& frame
)
1100 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1104 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1116 void OnInform(const wxChar
*msg
)
1118 wxString msg_string
= msg
;
1120 wxSTD cout
<< msg_string
.mb_str() << "\n";
1123 if (isInteractive
&& frame
)
1124 (*frame
->textWindow
) << msg
<< _T("\n");
1125 /* This whole block of code is just wrong I think. It would behave
1126 completely wrong under anything other than MSW due to the ELSE
1127 with no statement, and the cout calls would fail under MSW, as
1128 the code in this block is compiled if !NO_GUI This code has been
1129 here since v1.1 of this file too. - gt
1133 wxSTD cout << msg_string.mb_str() << "\n";
1148 void OnMacro(int macroId
, int no_args
, bool start
)
1150 switch (convertMode
)
1154 RTFOnMacro(macroId
, no_args
, start
);
1159 XLPOnMacro(macroId
, no_args
, start
);
1164 HTMLOnMacro(macroId
, no_args
, start
);
1170 bool OnArgument(int macroId
, int arg_no
, bool start
)
1172 switch (convertMode
)
1176 return RTFOnArgument(macroId
, arg_no
, start
);
1181 return XLPOnArgument(macroId
, arg_no
, start
);
1186 return HTMLOnArgument(macroId
, arg_no
, start
);
1196 #if defined(__WXMSW__) && !defined(NO_GUI)
1202 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1204 if (topic
== _T("TEX2RTF"))
1207 ipc_buffer
= new wxChar
[1000];
1209 return new Tex2RTFConnection(ipc_buffer
, 4000);
1219 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1223 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1229 // Find first argument (command name)
1232 if (data
[i
] == ' ' || data
[i
] == 0)
1236 firstArg
[i
] = data
[i
];
1243 // Find second argument
1246 while (data
[i
] != 0)
1248 secondArg
[j
] = data
[i
];
1257 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1259 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1261 wxChar firstArg
[50];
1262 wxChar secondArg
[300];
1263 if (SplitCommand(data
, firstArg
, secondArg
))
1265 bool hasArg
= (wxStrlen(secondArg
) > 0);
1266 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1268 if (InputFile
) delete[] InputFile
;
1269 InputFile
= copystring(secondArg
);
1273 wxString str
= wxFileNameFromPath(InputFile
);
1274 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1275 frame
->SetTitle(buf
);
1278 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1280 if (OutputFile
) delete[] OutputFile
;
1281 OutputFile
= copystring(secondArg
);
1283 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1285 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1287 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1289 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1291 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1293 if (frame
) frame
->Close();
1295 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1298 frame
->Iconize(true);
1300 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1304 frame
->Iconize(false);
1310 // Try for a setting
1311 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1312 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1313 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1316 wxStrcpy(buf
, _T("In "));
1318 if (winHelp
&& (convertMode
== TEX_RTF
))
1319 wxStrcat(buf
, _T("WinHelp RTF"));
1320 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1321 wxStrcat(buf
, _T("linear RTF"));
1322 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1323 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1324 wxStrcat(buf
, _T(" mode."));
1325 frame
->SetStatusText(buf
, 1);
1333 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1335 return Tex2RTFLastStatus
;
1342 //void wxObject::Dump(wxSTD ostream& str)
1344 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1345 // str << GetClassInfo()->GetClassName();
1347 // str << "unknown object class";