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"
37 #include "wx/cshelp.h"
38 #include "wx/helphtml.h"
40 #include "wx/msw/helpchm.h"
42 #include "wx/html/helpctrl.h"
61 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
62 #include "tex2rtf.xpm"
65 #if !WXWIN_COMPATIBILITY_2_4
66 static inline wxChar
* copystring(const wxChar
* s
)
67 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
70 const float versionNo
= (float)TEX2RTF_VERSION_NUMBER
;
72 TexChunk
*currentMember
= NULL
;
73 bool startedSections
= false;
74 wxChar
*contentsString
= NULL
;
75 bool suppressNameDecoration
= false;
76 bool OkToClose
= true;
78 unsigned long errorCount
= 0;
82 extern wxChar
*BigBuffer
;
83 extern wxChar
*TexFileRoot
;
84 extern wxChar
*TexBibName
; // Bibliography output file name
85 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
86 extern wxList ColourTable
;
87 extern TexChunk
*TopLevel
;
90 wxHelpControllerBase
*HelpInstance
= NULL
;
94 static wxChar
*ipc_buffer
= NULL
;
95 static wxChar Tex2RTFLastStatus
[100];
96 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
101 wxChar
*bulletFile
= NULL
;
103 FILE *Contents
= NULL
; // Contents page
104 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
105 FILE *Sections
= NULL
;
106 FILE *Subsections
= NULL
;
107 FILE *Subsubsections
= NULL
;
109 FILE *WinHelpContentsFile
= NULL
;
111 wxChar
*InputFile
= NULL
;
112 wxChar
*OutputFile
= NULL
;
113 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
115 wxChar
*FileRoot
= NULL
;
116 wxChar
*ContentsName
= NULL
; // Contents page from last time around
117 wxChar
*TmpContentsName
= NULL
; // Current contents page
118 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
119 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
120 wxChar
*RefFileName
= NULL
; // Reference file name
122 wxChar
*RTFCharset
= copystring(_T("ansi"));
125 int BufSize
= 100; // Size of buffer in K
131 void ShowOptions(void);
133 wxChar wxTex2RTFBuffer
[1500];
136 IMPLEMENT_APP_CONSOLE(MyApp
)
138 wxMenuBar
*menuBar
= NULL
;
139 MyFrame
*frame
= NULL
;
140 // DECLARE_APP(MyApp)
144 // `Main program' equivalent, creating windows and returning main app frame
147 // Use default list of macros defined in tex2any.cc
148 DefineDefaultMacros();
149 AddMacroDef(ltHARDY
, _T("hardy"), 0);
151 FileRoot
= new wxChar
[300];
152 ContentsName
= new wxChar
[300];
153 TmpContentsName
= new wxChar
[300];
154 TmpFrameContentsName
= new wxChar
[300];
155 WinHelpContentsFileName
= new wxChar
[300];
156 RefFileName
= new wxChar
[300];
158 WX_CLEAR_LIST(wxList
,ColourTable
);
162 // Read input/output files
165 if (argv
[1][0] != '-')
172 if (argv
[2][0] != '-')
174 OutputFile
= argv
[2];
182 if (!InputFile
|| !OutputFile
)
184 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
192 TexPathList
.EnsureFileAccessible(InputFile
);
194 if (!InputFile
|| !OutputFile
)
195 isInteractive
= true;
198 for (i
= n
; i
< argc
;)
200 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
203 convertMode
= TEX_RTF
;
207 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
210 isInteractive
= true;
213 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
218 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
221 convertMode
= TEX_RTF
;
223 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
226 convertMode
= TEX_HTML
;
228 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
231 convertMode
= TEX_XLP
;
233 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
238 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
243 MacroFile
= copystring(argv
[i
]);
247 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
252 BufSize
= wxAtoi(argv
[i
]);
256 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
263 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
264 wxStrcmp(s
, _T("pca")) == 0)
265 RTFCharset
= copystring(s
);
268 OnError(_T("Incorrect argument for -charset"));
273 else if (wxStrcmp(argv
[i
], _T("-checkcurlybraces")) == 0)
276 checkCurlyBraces
= true;
278 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
280 // Support the old, incorrectly spelled version of -checkcurlybraces
281 // so that old scripts which run tex2rtf -checkcurleybraces still work.
283 checkCurlyBraces
= true;
285 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
293 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
294 OnError((wxChar
*)buf
.c_str());
304 #if defined(__WXMSW__) && !defined(NO_GUI)
306 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
307 TheTex2RTFServer
= new Tex2RTFServer
;
308 TheTex2RTFServer
->Create(_T("TEX2RTF"));
311 TexInitialize(BufSize
);
312 ResetContentsLevels(0);
320 // Create the main frame window
321 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
323 frame
->CreateStatusBar(2);
324 #endif // wxUSE_STATUSBAR
327 // TODO: uncomment this when we have tex2rtf.xpm
328 frame
->SetIcon(wxICON(tex2rtf
));
332 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
333 frame
->SetTitle(buf
);
337 wxMenu
*file_menu
= new wxMenu
;
338 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
339 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
340 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
341 file_menu
->AppendSeparator();
342 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
343 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
344 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
345 file_menu
->AppendSeparator();
346 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
348 wxMenu
*macro_menu
= new wxMenu
;
350 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
351 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
353 wxMenu
*mode_menu
= new wxMenu
;
355 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
356 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
357 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
358 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
360 wxMenu
*options_menu
= new wxMenu
;
362 options_menu
->Append(TEX_OPTIONS_CURLY_BRACE
, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true);
363 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
365 options_menu
->Check(TEX_OPTIONS_CURLY_BRACE
, checkCurlyBraces
);
366 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
368 wxMenu
*help_menu
= new wxMenu
;
370 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
371 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
373 menuBar
= new wxMenuBar
;
374 menuBar
->Append(file_menu
, _T("&File"));
375 menuBar
->Append(macro_menu
, _T("&Macros"));
376 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
377 menuBar
->Append(options_menu
, _T("&Options"));
378 menuBar
->Append(help_menu
, _T("&Help"));
380 frame
->SetMenuBar(menuBar
);
381 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
383 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
387 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
388 HelpInstance
= new wxCHMHelpController
;
390 HelpInstance
= new wxHtmlHelpController
;
392 HelpInstance
->Initialize(_T("tex2rtf"));
396 * Read macro/initialisation file
400 wxString path
= TexPathList
.FindValidPath(MacroFile
);
402 ReadCustomMacros((wxChar
*)path
.c_str());
405 wxStrcpy(buf
, _T("In "));
409 wxStrcat(buf
, (winHelp
) ? _T("WinHelp RTF") : _T("linear RTF"));
412 wxStrcat(buf
, _T("HTML"));
415 wxStrcat(buf
, _T("XLP"));
418 wxStrcat(buf
, _T("unknown"));
421 wxStrcat(buf
, _T(" mode."));
422 frame
->SetStatusText(buf
, 1);
423 #endif // wxUSE_STATUSBAR
432 * Read macro/initialisation file
436 wxString path
= TexPathList
.FindValidPath(MacroFile
);
438 ReadCustomMacros((wxChar
*)path
.c_str());
448 OnExit(); // Do cleanup since OnExit won't be called now
457 wxNode
*node
= CustomMacroList
.GetFirst();
460 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
463 node
= CustomMacroList
.GetFirst();
465 MacroDefs
.BeginFind();
466 wxHashTable::Node
* mNode
= MacroDefs
.Next();
469 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
471 mNode
= MacroDefs
.Next();
475 delete TheTex2RTFServer
;
490 delete currentArgData
;
491 currentArgData
= NULL
;
505 delete TexTmpBibName
;
506 TexTmpBibName
= NULL
;
520 delete TmpContentsName
;
521 TmpContentsName
= NULL
;
523 if (TmpFrameContentsName
)
525 delete TmpFrameContentsName
;
526 TmpFrameContentsName
= NULL
;
528 if (WinHelpContentsFileName
)
530 delete WinHelpContentsFileName
;
531 WinHelpContentsFileName
= NULL
;
555 delete [] BibliographyStyleString
;
556 delete [] DocumentStyleString
;
557 delete [] bitmapMethod
;
558 delete [] backgroundColourString
;
559 delete [] ContentsNameString
;
560 delete [] AbstractNameString
;
561 delete [] GlossaryNameString
;
562 delete [] ReferencesNameString
;
563 delete [] FiguresNameString
;
564 delete [] TablesNameString
;
565 delete [] FigureNameString
;
566 delete [] TableNameString
;
567 delete [] IndexNameString
;
568 delete [] ChapterNameString
;
569 delete [] SectionNameString
;
570 delete [] SubsectionNameString
;
571 delete [] SubsubsectionNameString
;
572 delete [] UpNameString
;
574 delete[] winHelpTitle
;
576 // TODO: this simulates zero-memory leaks!
577 // Otherwise there are just too many...
579 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
580 wxDebugContext::SetCheckpoint();
587 void ShowOptions(void)
590 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
592 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
593 OnInform(_T("where valid switches are"));
595 OnInform(_T(" -interactive"));
597 OnInform(_T(" -bufsize <size in K>"));
598 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
599 OnInform(_T(" -twice"));
600 OnInform(_T(" -sync"));
601 OnInform(_T(" -checkcurlybraces"));
602 OnInform(_T(" -checksyntax"));
603 OnInform(_T(" -macros <filename>"));
604 OnInform(_T(" -winhelp"));
605 OnInform(_T(" -rtf"));
606 OnInform(_T(" -html"));
607 OnInform(_T(" -xlp\n"));
612 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
613 EVT_CLOSE(MyFrame::OnCloseWindow
)
614 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
615 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
616 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
617 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
618 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
619 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
620 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
621 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
622 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
623 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
624 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
625 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
626 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
627 EVT_MENU(TEX_OPTIONS_CURLY_BRACE
, MyFrame::OnOptionsCurlyBrace
)
628 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
629 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
630 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
633 // My frame constructor
634 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
635 wxFrame(frame
, id
, title
, pos
, size
)
638 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
640 if (!stopRunning
&& !OkToClose
)
652 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
658 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
662 menuBar
->EnableTop(0, false);
663 menuBar
->EnableTop(1, false);
664 menuBar
->EnableTop(2, false);
665 menuBar
->EnableTop(3, false);
673 SetStatusText(_T("Build aborted!"));
674 #endif // wxUSE_STATUSBAR
676 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
677 OnInform((wxChar
*)errBuf
.c_str());
681 if (runTwice
&& !stopRunning
)
686 menuBar
->EnableTop(0, true);
687 menuBar
->EnableTop(1, true);
688 menuBar
->EnableTop(2, true);
689 menuBar
->EnableTop(3, true);
692 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
694 ChooseInputFile(true);
697 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
699 ChooseOutputFile(true);
702 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
704 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
707 textWindow
->SaveFile(s
);
710 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
711 frame
->SetStatusText(buf
, 0);
712 #endif // wxUSE_STATUSBAR
716 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
719 if (OutputFile
&& wxFileExists(OutputFile
))
721 textWindow
->LoadFile(OutputFile
);
723 wxString
str(wxFileNameFromPath(OutputFile
));
724 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
725 frame
->SetTitle(buf
);
729 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
732 if (InputFile
&& wxFileExists(InputFile
))
734 textWindow
->LoadFile(InputFile
);
736 wxString
str(wxFileNameFromPath(OutputFile
));
737 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
738 frame
->SetTitle(buf
);
742 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
745 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
746 if (s
!= _T("") && wxFileExists(s
))
748 MacroFile
= copystring(s
);
749 ReadCustomMacros((wxChar
*)s
.c_str());
754 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
761 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
763 convertMode
= TEX_RTF
;
768 SetStatusText(_T("In linear RTF mode."), 1);
769 #endif // wxUSE_STATUSBAR
772 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
774 convertMode
= TEX_RTF
;
779 SetStatusText(_T("In WinHelp RTF mode."), 1);
780 #endif // wxUSE_STATUSBAR
783 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
785 convertMode
= TEX_HTML
;
790 SetStatusText(_T("In HTML mode."), 1);
791 #endif // wxUSE_STATUSBAR
794 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
796 convertMode
= TEX_XLP
;
800 SetStatusText(_T("In XLP mode."), 1);
801 #endif // wxUSE_STATUSBAR
804 void MyFrame::OnOptionsCurlyBrace(wxCommandEvent
& WXUNUSED(event
))
806 checkCurlyBraces
= !checkCurlyBraces
;
808 if (checkCurlyBraces
)
810 SetStatusText(_T("Checking curly braces: YES"), 1);
814 SetStatusText(_T("Checking curly braces: NO"), 1);
816 #endif // wxUSE_STATUSBAR
820 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
822 checkSyntax
= !checkSyntax
;
826 SetStatusText(_T("Checking syntax: YES"), 1);
830 SetStatusText(_T("Checking syntax: NO"), 1);
832 #endif // wxUSE_STATUSBAR
836 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
839 HelpInstance
->LoadFile();
840 HelpInstance
->DisplayContents();
844 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
848 wxChar
*platform
= _T(" (32-bit)");
851 wxChar
*platform
= _T(" (16-bit)");
853 wxChar
*platform
= _T("");
856 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
);
857 wxMessageBox(buf
, _T("About Tex2RTF"));
860 void ChooseInputFile(bool force
)
862 if (force
|| !InputFile
)
864 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
867 // Different file, so clear index entries.
869 ResetContentsLevels(0);
873 InputFile
= copystring(s
);
874 wxString str
= wxFileNameFromPath(InputFile
);
876 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
877 frame
->SetTitle((wxChar
*)buf
.c_str());
883 void ChooseOutputFile(bool force
)
885 wxChar extensionBuf
[10];
887 wxStrcpy(wildBuf
, _T("*."));
890 path
= wxPathOnly(OutputFile
);
892 path
= wxPathOnly(InputFile
);
898 wxStrcpy(extensionBuf
, _T("rtf"));
899 wxStrcat(wildBuf
, _T("rtf"));
904 wxStrcpy(extensionBuf
, _T("xlp"));
905 wxStrcat(wildBuf
, _T("xlp"));
910 wxStrcpy(extensionBuf
, _T("html"));
911 wxStrcat(wildBuf
, _T("html"));
915 if (force
|| !OutputFile
)
917 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
918 extensionBuf
, wildBuf
);
920 OutputFile
= copystring(s
);
932 if (!InputFile
|| !OutputFile
|| stopRunning
)
939 wxString str
= wxFileNameFromPath(InputFile
);
941 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
942 frame
->SetTitle(buf
);
948 // Find extension-less filename
949 wxStrcpy(FileRoot
, OutputFile
);
950 StripExtension(FileRoot
);
952 if (truncateFilenames
&& convertMode
== TEX_HTML
)
954 // Truncate to five characters. This ensures that
955 // we can generate DOS filenames such as thing999. But 1000 files
956 // may not be enough, of course...
957 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
960 if(wxStrlen( sName
) > 5)
961 sName
[5] = '\0'; // that should do!
964 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
965 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
966 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
967 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
968 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
970 TexPathList
.EnsureFileAccessible(InputFile
);
973 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
976 wxString str
= wxFileNameFromPath(s
);
977 bulletFile
= copystring(str
);
981 if (wxFileExists(RefFileName
))
982 ReadTexReferences(RefFileName
);
984 bool success
= false;
986 if (InputFile
&& OutputFile
)
988 if (!wxFileExists(InputFile
))
990 OnError(_T("Cannot open input file!"));
994 #if !defined(NO_GUI) && wxUSE_STATUSBAR
998 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
999 frame
->SetStatusText((wxChar
*)buf
.c_str());
1003 OnInform(_T("Reading LaTeX file..."));
1004 TexLoadFile(InputFile
);
1012 switch (convertMode
)
1033 OnInform(_T("*** Aborted by user."));
1035 stopRunning
= false;
1041 WriteTexReferences(RefFileName
);
1043 startedSections
= false;
1047 long tim
= wxGetElapsedTime();
1048 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1049 OnInform((wxChar
*)buf
.c_str());
1053 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1054 OnInform((wxChar
*)buf
.c_str());
1060 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1061 frame
->SetStatusText((wxChar
*)buf
.c_str());
1063 #endif // wxUSE_STATUSBAR
1065 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1066 OnInform((wxChar
*)buf
.c_str());
1069 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1070 OnInform((wxChar
*)buf
.c_str());
1080 startedSections
= false;
1082 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1083 frame
->SetStatusText(_T("Aborted by user."));
1086 OnInform(_T("Sorry, unsuccessful."));
1091 void OnError(const wxChar
*msg
)
1093 wxString msg_string
= msg
;
1097 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1100 if (isInteractive
&& frame
)
1101 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1105 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1117 void OnInform(const wxChar
*msg
)
1119 wxString msg_string
= msg
;
1121 wxSTD cout
<< msg_string
.mb_str() << "\n";
1124 if (isInteractive
&& frame
)
1125 (*frame
->textWindow
) << msg
<< _T("\n");
1126 /* This whole block of code is just wrong I think. It would behave
1127 completely wrong under anything other than MSW due to the ELSE
1128 with no statement, and the cout calls would fail under MSW, as
1129 the code in this block is compiled if !NO_GUI This code has been
1130 here since v1.1 of this file too. - gt
1134 wxSTD cout << msg_string.mb_str() << "\n";
1149 void OnMacro(int macroId
, int no_args
, bool start
)
1151 switch (convertMode
)
1155 RTFOnMacro(macroId
, no_args
, start
);
1160 XLPOnMacro(macroId
, no_args
, start
);
1165 HTMLOnMacro(macroId
, no_args
, start
);
1171 bool OnArgument(int macroId
, int arg_no
, bool start
)
1173 switch (convertMode
)
1177 return RTFOnArgument(macroId
, arg_no
, start
);
1182 return XLPOnArgument(macroId
, arg_no
, start
);
1187 return HTMLOnArgument(macroId
, arg_no
, start
);
1197 #if defined(__WXMSW__) && !defined(NO_GUI)
1203 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1205 if (topic
== _T("TEX2RTF"))
1208 ipc_buffer
= new wxChar
[1000];
1210 return new Tex2RTFConnection(ipc_buffer
, 4000);
1220 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1224 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1230 // Find first argument (command name)
1233 if (data
[i
] == ' ' || data
[i
] == 0)
1237 firstArg
[i
] = data
[i
];
1244 // Find second argument
1247 while (data
[i
] != 0)
1249 secondArg
[j
] = data
[i
];
1258 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1260 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1262 wxChar firstArg
[50];
1263 wxChar secondArg
[300];
1264 if (SplitCommand(data
, firstArg
, secondArg
))
1266 bool hasArg
= (wxStrlen(secondArg
) > 0);
1267 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1269 if (InputFile
) delete[] InputFile
;
1270 InputFile
= copystring(secondArg
);
1274 wxString str
= wxFileNameFromPath(InputFile
);
1275 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1276 frame
->SetTitle(buf
);
1279 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1281 if (OutputFile
) delete[] OutputFile
;
1282 OutputFile
= copystring(secondArg
);
1284 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1286 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1288 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1290 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1292 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1294 if (frame
) frame
->Close();
1296 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1299 frame
->Iconize(true);
1301 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1305 frame
->Iconize(false);
1311 // Try for a setting
1312 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1313 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1314 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1317 wxStrcpy(buf
, _T("In "));
1319 if (winHelp
&& (convertMode
== TEX_RTF
))
1320 wxStrcat(buf
, _T("WinHelp RTF"));
1321 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1322 wxStrcat(buf
, _T("linear RTF"));
1323 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1324 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1325 wxStrcat(buf
, _T(" mode."));
1326 frame
->SetStatusText(buf
, 1);
1334 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1336 return Tex2RTFLastStatus
;
1343 //void wxObject::Dump(wxSTD ostream& str)
1345 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1346 // str << GetClassInfo()->GetClassName();
1348 // str << "unknown object class";